KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_builder.h
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 2
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/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#pragma once
26
27#include <functional>
28#include <memory>
29#include <unordered_map>
30
32#include <convert/allegro_db.h>
33
34#include <board.h>
36#include <reporter.h>
37#include <progress_reporter.h>
39
40
41class BOARD;
42class FOOTPRINT;
43class NETINFO_ITEM;
44class PCB_TEXT;
45
46namespace ALLEGRO
47{
48
49class LAYER_MAPPER;
50
56{
57public:
58 BOARD_BUILDER( const BRD_DB& aBrdDb, BOARD& aBoard, REPORTER& aReporter,
59 PROGRESS_REPORTER* aProgressReporter,
60 const LAYER_MAPPING_HANDLER& aLayerMappingHandler );
62
63 bool BuildBoard();
64
65private:
66 VECTOR2I scale( const VECTOR2I& aVector ) const;
67 VECTOR2I scaleSize( const VECTOR2I& aSize ) const;
68 int scale( int aVal ) const;
69
70 template <typename T>
71 const T* expectBlockByKey( uint32_t aKey, uint8_t aType ) const
72 {
73 if( aKey == 0 )
74 return nullptr;
75
76 const BLOCK_BASE* block = m_brdDb.GetObjectByKey( aKey );
77
78 if( !block )
79 {
80 reportMissingBlock( aKey, aType );
81 return nullptr;
82 }
83
84 if( block->GetBlockType() != aType )
85 {
86 reportUnexpectedBlockType( block->GetBlockType(), aType, aKey, block->GetOffset() );
87 return nullptr;
88 }
89
90 return &static_cast<const BLOCK<T>&>( *block ).GetData();
91 }
92
93 void reportMissingBlock( uint32_t aKey, uint8_t aType ) const;
94 void reportUnexpectedBlockType( uint8_t aGot, uint8_t aExpected, uint32_t aKey = 0, size_t aOffset = 0,
95 const wxString& aName = wxEmptyString ) const;
96
97 PCB_LAYER_ID getLayer( const LAYER_INFO& aLayerInfo ) const;
98
104 wxString get0x30StringValue( uint32_t a0x30Key ) const;
105
109 std::vector<std::unique_ptr<PCB_SHAPE>> buildShapes( const BLK_0x14_GRAPHIC& aGraphicList, BOARD_ITEM_CONTAINER& aParent );
110 std::unique_ptr<PCB_TEXT> buildPcbText( const BLK_0x30_STR_WRAPPER& aStrWrapper, BOARD_ITEM_CONTAINER& aParent );
111
115 std::unique_ptr<PCB_SHAPE> buildRect( const BLK_0x24_RECT& aRect, BOARD_ITEM_CONTAINER& aParent );
116
120 std::unique_ptr<PCB_SHAPE> buildPolygon( const BLK_0x28_SHAPE& aShape, BOARD_ITEM_CONTAINER& aParent );
121
125 std::vector<std::unique_ptr<BOARD_ITEM>> buildPadItems( const BLK_0x1C_PADSTACK& aPadstack, FOOTPRINT& aFp,
126 const wxString& aPadName, int aNetcode );
127 std::unique_ptr<FOOTPRINT> buildFootprint( const BLK_0x2D_FOOTPRINT_INST& aFpInstance );
128 std::vector<std::unique_ptr<BOARD_ITEM>> buildTrack( const BLK_0x05_TRACK& aBlock, int aNetcode );
129 std::unique_ptr<BOARD_ITEM> buildVia( const BLK_0x33_VIA& aBlock, int aNetcode );
130 std::unique_ptr<ZONE> buildZone( const BLK_0x28_SHAPE& aShape, int aNetcode );
131 const SHAPE_LINE_CHAIN& buildOutline( const BLK_0x28_SHAPE& aShape ) const;
132
137 const SHAPE_LINE_CHAIN& buildSegmentChain( uint32_t aStartKey ) const;
138
143 int resolveShapeNet( const BLK_0x28_SHAPE& aShape ) const;
144
154 wxString resolveMatchGroupName( const BLK_0x1B_NET& aNet ) const;
155
163 wxString resolveConstraintSetNameFromField( uint32_t aFieldKey ) const;
164
165 void cacheFontDefs();
166 void setupLayers();
167 void createNets();
168 void createTracks();
169 void createBoardOutline();
170 void createBoardText();
171 void createZones();
172 void applyZoneFills();
173 void enablePadTeardrops();
174 void applyConstraintSets();
175 void applyNetConstraints();
176 void applyMatchGroups();
177
184 const BLK_0x36_DEF_TABLE::FontDef_X08* getFontDef( unsigned aIndex ) const;
185
189 const BLK_0x07_COMPONENT_INST* getFpInstRef( const BLK_0x2D_FOOTPRINT_INST& aFpInstance ) const;
190
196
197 // Cached list of font defs in the 0x36 node
198 std::vector<const BLK_0x36_DEF_TABLE::FontDef_X08*> m_fontDefList;
199
200 // Cached list of KiCad nets corresponding to Allegro 0x1B NET keys
201 std::unordered_map<uint32_t, NETINFO_ITEM*> m_netCache;
202
209
210 std::vector<ZoneFillEntry> m_zoneFillShapes;
211
212 std::unique_ptr<LAYER_MAPPER> m_layerMapper;
213
214 // Cache of computed outlines keyed by shape block key, avoiding redundant geometry rebuilds
215 mutable std::unordered_map<uint32_t, SHAPE_LINE_CHAIN> m_outlineCache;
216
217 // Cache of segment chains keyed by start key, avoiding redundant hole geometry rebuilds
218 mutable std::unordered_map<uint32_t, SHAPE_LINE_CHAIN> m_segChainCache;
219
220 // Conversion factor from internal units to nanometers.
221 // Internal coordinates are in mils / divisor, so scale = 25400 / divisor.
222 double m_scale;
223};
224
225} // namespace ALLEGRO
The base class for all blocks in the main body of an Allegro file.
uint8_t GetBlockType() const
const T & GetData() const
wxString resolveMatchGroupName(const BLK_0x1B_NET &aNet) const
Follow m_MatchGroupPtr through the 0x26/0x2C pointer chain to get the match group name for a NET.
const SHAPE_LINE_CHAIN & buildSegmentChain(uint32_t aStartKey) const
Walk a geometry chain (0x01 arcs and 0x15-17 segments) starting from the given key,...
LAYER_MAPPING_HANDLER m_layerMappingHandler
PROGRESS_REPORTER * m_progressReporter
void reportUnexpectedBlockType(uint8_t aGot, uint8_t aExpected, uint32_t aKey=0, size_t aOffset=0, const wxString &aName=wxEmptyString) const
const BLK_0x07_COMPONENT_INST * getFpInstRef(const BLK_0x2D_FOOTPRINT_INST &aFpInstance) const
Look up 0x07 FP instance data (0x07) for a given 0x2D FP instance.
VECTOR2I scaleSize(const VECTOR2I &aSize) const
PCB_LAYER_ID getLayer(const LAYER_INFO &aLayerInfo) const
std::unordered_map< uint32_t, SHAPE_LINE_CHAIN > m_segChainCache
std::vector< std::unique_ptr< PCB_SHAPE > > buildShapes(const BLK_0x14_GRAPHIC &aGraphicList, BOARD_ITEM_CONTAINER &aParent)
Build the shapes from an 0x14 shape list.
int resolveShapeNet(const BLK_0x28_SHAPE &aShape) const
Resolve the net code for a BOUNDARY shape by following the pointer chain: BOUNDARY....
BOARD_BUILDER(const BRD_DB &aBrdDb, BOARD &aBoard, REPORTER &aReporter, PROGRESS_REPORTER *aProgressReporter, const LAYER_MAPPING_HANDLER &aLayerMappingHandler)
std::unique_ptr< LAYER_MAPPER > m_layerMapper
std::unique_ptr< PCB_SHAPE > buildRect(const BLK_0x24_RECT &aRect, BOARD_ITEM_CONTAINER &aParent)
Build a rectangular shape from a 0x24 RECT block.
const SHAPE_LINE_CHAIN & buildOutline(const BLK_0x28_SHAPE &aShape) const
const T * expectBlockByKey(uint32_t aKey, uint8_t aType) const
std::unique_ptr< PCB_TEXT > buildPcbText(const BLK_0x30_STR_WRAPPER &aStrWrapper, BOARD_ITEM_CONTAINER &aParent)
std::unique_ptr< FOOTPRINT > buildFootprint(const BLK_0x2D_FOOTPRINT_INST &aFpInstance)
void reportMissingBlock(uint32_t aKey, uint8_t aType) const
std::unordered_map< uint32_t, NETINFO_ITEM * > m_netCache
std::vector< ZoneFillEntry > m_zoneFillShapes
std::vector< std::unique_ptr< BOARD_ITEM > > buildTrack(const BLK_0x05_TRACK &aBlock, int aNetcode)
std::vector< const BLK_0x36_DEF_TABLE::FontDef_X08 * > m_fontDefList
std::unordered_map< uint32_t, SHAPE_LINE_CHAIN > m_outlineCache
wxString get0x30StringValue(uint32_t a0x30Key) const
Get just the string value from a 0x31 STRING WRAPPER -> 0x30 STRING GRAPHIC pair.
const BLK_0x36_DEF_TABLE::FontDef_X08 * getFontDef(unsigned aIndex) const
Get the font definition for a given index in a 0x30, etc.
std::unique_ptr< BOARD_ITEM > buildVia(const BLK_0x33_VIA &aBlock, int aNetcode)
std::unique_ptr< ZONE > buildZone(const BLK_0x28_SHAPE &aShape, int aNetcode)
std::unique_ptr< PCB_SHAPE > buildPolygon(const BLK_0x28_SHAPE &aShape, BOARD_ITEM_CONTAINER &aParent)
Build a graphic polygon from a 0x28 SHAPE block.
wxString resolveConstraintSetNameFromField(uint32_t aFieldKey) const
Extract constraint set name from a 0x03 FIELD block pointer.
std::vector< std::unique_ptr< BOARD_ITEM > > buildPadItems(const BLK_0x1C_PADSTACK &aPadstack, FOOTPRINT &aFp, const wxString &aPadName, int aNetcode)
Construct "pad" items for a given 0x1C PADSTACK block.
An Allegro database that represents a .brd file (amd presumably .dra)
Definition allegro_db.h:849
Class to handle the mapping for Allegro CLASS/SUBCLASS idiom to KiCad layers.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
Handle the data for a net.
Definition netinfo.h:54
A progress reporter interface for use in multi-threaded environments.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
std::function< std::map< wxString, PCB_LAYER_ID >(const std::vector< INPUT_LAYER_DESC > &)> LAYER_MAPPING_HANDLER
Pointer to a function that takes a map of source and KiCad layers and returns a re-mapped version.
const int scale
Track segment container.
Component instance reference data.
Graphics container holding a chain of line segments and arcs.
0x1B objects are nets.
Padstack definition containing drill dimensions and a table of per-layer pad/antipad/thermal componen...
Rectangle defined by four coordinates.
Polygon shape defined by a linked list of segments starting at m_FirstSegmentPtr (0x15/0x16/0x17 line...
Placed footprint instance on the board.
Text object with position, rotation, layer, font properties, and alignment.
Via instance with board position, padstack reference (m_Padstack for drill/annular ring definitions),...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695