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, you may find one here:
19 * http://www.gnu.org/licenses/gpl-3.0.html
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "convert/allegro_db.h"
25
26#include <set>
27
28#include <wx/log.h>
29
30#include <ki_exception.h>
31
33
34using namespace ALLEGRO;
35
36
37void BRD_DB::ReserveCapacity( size_t aObjectCount, size_t aStringCount )
38{
39 // The object and strings count come from user input directly
40 // clamp them in case we get a gigantic number
41 aObjectCount = std::min( aObjectCount, static_cast<size_t>( 1e6 ) );
42 aStringCount = std::min( aStringCount, static_cast<size_t>( 1e6 ) );
43
44 m_Blocks.reserve( aObjectCount );
45 m_ObjectKeyMap.reserve( aObjectCount );
46 m_StringTable.reserve( aStringCount );
47}
48
49
50void BRD_DB::InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock )
51{
52 if( aBlock->GetKey() != 0 )
53 m_ObjectKeyMap[aBlock->GetKey()] = aBlock.get();
54
55 m_Blocks.push_back( std::move( aBlock ) );
56}
57
58
59static void collectSentinelKeys( const FILE_HEADER& aHeader, BRD_DB& aDb )
60{
61 auto addTail = [&]( const FILE_HEADER::LINKED_LIST& aLL )
62 {
63 aDb.AddSentinelKey( aLL.m_Tail );
64 };
65
66 addTail( aHeader.m_LL_0x04 );
67 addTail( aHeader.m_LL_0x06 );
68 addTail( aHeader.m_LL_0x0C );
69 addTail( aHeader.m_LL_Shapes );
70 addTail( aHeader.m_LL_0x14 );
71 addTail( aHeader.m_LL_0x1B_Nets );
72 addTail( aHeader.m_LL_0x1C );
73 addTail( aHeader.m_LL_0x24_0x28 );
74 addTail( aHeader.m_LL_Unknown1 );
75 addTail( aHeader.m_LL_0x2B );
76 addTail( aHeader.m_LL_0x03_0x30 );
77 addTail( aHeader.m_LL_0x0A );
78 addTail( aHeader.m_LL_0x1D_0x1E_0x1F );
79 addTail( aHeader.m_LL_Unknown2 );
80 addTail( aHeader.m_LL_0x38 );
81 addTail( aHeader.m_LL_0x2C );
82 addTail( aHeader.m_LL_0x0C_2 );
83 addTail( aHeader.m_LL_Unknown3 );
84 addTail( aHeader.m_LL_0x36 );
85 addTail( aHeader.GetUnknown5() );
86 addTail( aHeader.m_LL_Unknown6 );
87 addTail( aHeader.m_LL_0x0A_2 );
88
89 if( aHeader.m_LL_V18_1.has_value() )
90 {
91 addTail( aHeader.m_LL_V18_1.value() );
92 addTail( aHeader.m_LL_V18_2.value() );
93 addTail( aHeader.m_LL_V18_3.value() );
94 addTail( aHeader.m_LL_V18_4.value() );
95 addTail( aHeader.m_LL_V18_5.value() );
96 addTail( aHeader.m_LL_V18_6.value() );
97 }
98}
99
100
105
106
108{
109 if( m_FmtVer >= FMT_VER::V_180 )
110 collectSentinelKeys( *m_Header, *this );
111
112 return true;
113}
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:47
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:106
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:105
std::unique_ptr< FILE_HEADER > m_Header
Definition allegro_db.h:102
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:104
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:63
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