KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_db.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright Quilter
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "convert/allegro_db.h"
22
23#include <set>
24
25#include <wx/log.h>
26
27#include <ki_exception.h>
28
30
31using namespace ALLEGRO;
32
33
34void BRD_DB::ReserveCapacity( size_t aObjectCount, size_t aStringCount )
35{
36 // The object and strings count come from user input directly
37 // clamp them in case we get a gigantic number
38 aObjectCount = std::min( aObjectCount, static_cast<size_t>( 1e6 ) );
39 aStringCount = std::min( aStringCount, static_cast<size_t>( 1e6 ) );
40
41 m_Blocks.reserve( aObjectCount );
42 m_ObjectKeyMap.reserve( aObjectCount );
43 m_StringTable.reserve( aStringCount );
44}
45
46
47void BRD_DB::InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock )
48{
49 if( aBlock->GetKey() != 0 )
50 m_ObjectKeyMap[aBlock->GetKey()] = aBlock.get();
51
52 m_Blocks.push_back( std::move( aBlock ) );
53}
54
55
56static void collectSentinelKeys( const FILE_HEADER& aHeader, BRD_DB& aDb )
57{
58 auto addTail = [&]( const FILE_HEADER::LINKED_LIST& aLL )
59 {
60 aDb.AddSentinelKey( aLL.m_Tail );
61 };
62
63 addTail( aHeader.m_LL_0x04 );
64 addTail( aHeader.m_LL_0x06 );
65 addTail( aHeader.m_LL_0x0C );
66 addTail( aHeader.m_LL_Shapes );
67 addTail( aHeader.m_LL_0x14 );
68 addTail( aHeader.m_LL_0x1B_Nets );
69 addTail( aHeader.m_LL_0x1C );
70 addTail( aHeader.m_LL_0x24_0x28 );
71 addTail( aHeader.m_LL_Unknown1 );
72 addTail( aHeader.m_LL_0x2B );
73 addTail( aHeader.m_LL_0x03_0x30 );
74 addTail( aHeader.m_LL_0x0A );
75 addTail( aHeader.m_LL_0x1D_0x1E_0x1F );
76 addTail( aHeader.m_LL_Unknown2 );
77 addTail( aHeader.m_LL_0x38 );
78 addTail( aHeader.m_LL_0x2C );
79 addTail( aHeader.m_LL_0x0C_2 );
80 addTail( aHeader.m_LL_Unknown3 );
81 addTail( aHeader.m_LL_0x36 );
82 addTail( aHeader.GetUnknown5() );
83 addTail( aHeader.m_LL_Unknown6 );
84 addTail( aHeader.m_LL_0x0A_2 );
85
86 if( aHeader.m_LL_V18_1.has_value() )
87 {
88 addTail( aHeader.m_LL_V18_1.value() );
89 addTail( aHeader.m_LL_V18_2.value() );
90 addTail( aHeader.m_LL_V18_3.value() );
91 addTail( aHeader.m_LL_V18_4.value() );
92 addTail( aHeader.m_LL_V18_5.value() );
93 addTail( aHeader.m_LL_V18_6.value() );
94 }
95}
96
97
102
103
105{
106 if( m_FmtVer >= FMT_VER::V_180 )
107 collectSentinelKeys( *m_Header, *this );
108
109 return true;
110}
static void collectSentinelKeys(const FILE_HEADER &aHeader, BRD_DB &aDb)
An Allegro board database representing the contents of a .brd (and presumably .dra) file.
Definition allegro_db.h:43
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:102
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:101
FMT_VER m_FmtVer
Definition allegro_db.h:97
std::unique_ptr< FILE_HEADER > m_Header
Definition allegro_db.h:98
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:100
void ReserveCapacity(size_t aObjectCount, size_t aStringCount)
Pre-allocate storage for the expected number of objects and strings.
bool ResolveAndValidate()
Populate sentinel keys from the file header linked lists.
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)
void AddSentinelKey(uint32_t aKey)
Definition allegro_db.h:59
FMT_VER
The format of an Allegro file.
This is apparently some kind of linked list that chains though subsets objects in the file.
Allegro files start with this header.
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_4
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_5
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_3
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_6
const LINKED_LIST & GetUnknown5() const
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_1
COND_GE< FMT_VER::V_180, LINKED_LIST > m_LL_V18_2