KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_db.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 <cstdint>
28#include <memory>
29#include <unordered_map>
30#include <unordered_set>
31
32#include <math/vector2d.h>
33#include <math/box2.h>
34
36
37
38namespace ALLEGRO
39{
40
41class BLOCK_BASE;
42struct DB_OBJ;
43class DB_OBJ_RESOLVER;
44
45
47{
48 RESOLVABLE( const DB_OBJ* aParent, const char* aDebugName = nullptr ) :
49 m_Parent( aParent ),
50 m_DebugName( aDebugName )
51 {
52 }
53
54 virtual ~RESOLVABLE() = default;
55
56 virtual bool Resolve( const DB_OBJ_RESOLVER& aResolver ) = 0;
57
58 virtual std::string DebugString() const;
59
61 const char* m_DebugName;
62};
63
64
65struct DB_REF : public RESOLVABLE
66{
67 DB_REF( const DB_OBJ* aParent, uint32_t aTargetKey, const char* aDebugName ) :
68 RESOLVABLE( aParent, aDebugName ),
69 m_TargetKey( aTargetKey ),
70 m_Target( nullptr )
71 {
72 }
73
74 bool Resolve( const DB_OBJ_RESOLVER& aResolver ) override;
75
76 uint32_t m_TargetKey;
77 // If the ref points to the next item, eventually this will be equal to EndKey
78 // which may not be a resolvable object (e.g. a header LinkedList tail pointer, which is
79 // an artificial value).
80 // This is not a resolution failure, but it also means the reference is null.
81 uint32_t m_EndKey;
83};
84
85static DB_REF DB_NULLREF{ nullptr, 0, "<NULL>" };
86
90struct DB_REF_CHAIN : public RESOLVABLE
91{
92 DB_REF_CHAIN( const DB_OBJ* aParent, uint32_t aHead, uint32_t aTail, const char* aDebugName ) :
93 RESOLVABLE( aParent ),
94 m_Head( aHead ),
95 m_Tail( aTail )
96 {
97 m_DebugName = aDebugName;
98 }
99
100 DB_REF_CHAIN( const DB_OBJ* aParent ) :
101 DB_REF_CHAIN( aParent, 0, 0, "<unknown>" )
102 {
103 }
104
105 bool Resolve( const DB_OBJ_RESOLVER& aResolver ) override;
106
110 void Visit( std::function<void( const DB_OBJ& aObj )> aVisitor ) const;
111 void Visit( std::function<void( DB_OBJ& aObj )> aVisitor );
112
113 std::function<const DB_REF&( const DB_OBJ& )> m_NextRefGetter;
114
115 // The head/tail key values
116 uint32_t m_Head;
117 uint32_t m_Tail;
118
119 // The objects in the chain
120 std::vector<DB_OBJ*> m_Chain;
121};
122
123
124struct DB_STR_REF : public RESOLVABLE
125{
126 DB_STR_REF( const DB_OBJ* aParent, uint32_t aTargetKey, const char* aDebugName ) :
127 RESOLVABLE( aParent, aDebugName ),
128 m_StringKey( aTargetKey ),
129 m_String( nullptr )
130 {
131 }
132
133 bool Resolve( const DB_OBJ_RESOLVER& aResolver ) override;
134
135 uint32_t m_StringKey;
136 const wxString* m_String;
137};
138
139static const DB_STR_REF DB_STRNULLREF{ nullptr, 0, "<NULL>" };
140
145{
146public:
147 virtual ~DB_OBJ_RESOLVER() {}
148
152 virtual DB_OBJ* Resolve( uint32_t aKey ) const = 0;
153
154 virtual const wxString* ResolveString( uint32_t aKey ) const = 0;
155
160 virtual bool IsSentinel( uint32_t aKey ) const { return false; }
161};
162
163
167struct DB_OBJ
168{
169 using TYPE_ID = uint8_t;
170
171 // Where this block was in the file (for debugging)
172 struct FILE_LOC
173 {
174 size_t m_Offset;
175 uint8_t m_BlockType;
176 };
177
178 DB_OBJ( uint32_t aKey, uint32_t aNextKey ) :
179 m_Valid( false ),
180 m_Key( aKey ),
181 m_Loc( 0, 0 ),
182 m_Next( aNextKey ? DB_REF( this, aNextKey, "m_Next" ) : DB_NULLREF )
183 {
184 }
185
187 DB_OBJ( 0, 0 )
188 {
189 }
190
191 virtual ~DB_OBJ() {}
192
196 virtual TYPE_ID GetType() const = 0;
197
198 /*
199 * A type name for debugging/tracing purposes.
200 */
201 virtual const char* TypeName() const
202 {
203 return "<UNNAMED>";
204 }
205
217 virtual bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) = 0;
218
219 uint32_t GetKey() const { return m_Key; }
220
227 virtual const DB_REF& GetNext() const
228 {
229 return m_Next;
230 }
231
232 // Set to true when the object is fully resolved and valid
234 // The unique key of this object in the DB
235 uint32_t m_Key;
236 // Location in the file (for debugging)
238 // The default next reference for this object, used for default iteration methods
240};
241
242
248class DB : public DB_OBJ_RESOLVER
249{
250public:
251 DB();
252
253 ~DB();
254
255 void AddObject( std::unique_ptr<DB_OBJ> aObject );
256
257 void AddString( uint32_t aKey, wxString&& aStr ) { m_StringTable.emplace( aKey, std::move( aStr ) ); }
258
259 size_t GetObjectCount() const { return m_Objects.size(); }
260
271 void ResolveObjectLinks();
272
276 DB_OBJ* Resolve( uint32_t aRef ) const override;
277
278 const wxString* ResolveString( uint32_t aRef ) const override;
279
280 bool IsSentinel( uint32_t aKey ) const override
281 {
282 return m_SentinelKeys.count( aKey ) > 0;
283 }
284
285 void AddSentinelKey( uint32_t aKey )
286 {
287 if( aKey != 0 )
288 m_SentinelKeys.insert( aKey );
289 }
290
291 virtual void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock ) = 0;
292
293protected:
294 void visitLinkedList( const FILE_HEADER::LINKED_LIST aLList,
295 std::function<const DB_REF&( const DB_OBJ& aObj )> aVisitor ) const;
296
297 void reserveObjects( size_t aCount ) { m_Objects.reserve( aCount ); }
298
304
305private:
306 // Main store of DB objects.
307 std::unordered_map<uint32_t, std::unique_ptr<DB_OBJ>> m_Objects;
308
309 // V18+ linked list sentinel keys. References to these are null (end-of-chain).
310 std::unordered_set<uint32_t> m_SentinelKeys;
311
312public:
313 std::unordered_map<uint32_t, wxString> m_StringTable;
314};
315
316
318{
319 BRD_ARC, // 0x01
320 BRD_FIELD, // 0x03 subtype 0x68...
321 BRD_TRACK, // 0x05
330 BRD_XREF, // 0x12
332 BRD_LINE, // 0x15, 0x16, 0x17
333 BRD_NET, // 0x1B
334 BRD_x20, // 0x20
335 BRD_SHAPE, // 0x28
336 BRD_FP_DEF, // 0x2B
337 BRD_FP_INST, // 0x2D
340 BRD_VIA, // 0x33
341 BRD_KEEPOUT, // 0x34
346 BRD_FILM, // 0x3a
349};
350
351struct BRD_DB_OBJ : public DB_OBJ
352{
353 BRD_DB_OBJ( BRD_TYPE aType, uint32_t aKey, uint32_t aNextKey ) :
354 DB_OBJ( aKey, aNextKey ),
355 m_Type( aType )
356 {
357 }
358
360 DB_OBJ()
361 {
362 }
363
364 TYPE_ID GetType() const override
365 {
366 return static_cast<TYPE_ID>( m_Type );
367 }
368
369 BRD_TYPE GetBrdType() const { return m_Type; }
370
371private:
373};
374
375
376class BRD_DB;
377struct COMPONENT;
378struct COMPONENT_INST;
379struct FOOTPRINT_INSTANCE;
380struct FUNCTION_INSTANCE;
381struct NET;
382struct NET_ASSIGN;
383struct PLACED_PAD;
384struct PIN_NAME;
385struct PIN_NUMBER;
386struct TRACK;
387
388
392struct ARC : public BRD_DB_OBJ
393{
394 ARC( const BLK_0x01_ARC& aBlk );
395
397
398 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
399
400 const char* TypeName() const override { return "ARC"; }
401};
402
403
409struct FIELD : public BRD_DB_OBJ
410{
411 FIELD( const BLK_0x03_FIELD& aBlk );
412
413 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override { return true; }
414
415 const char* TypeName() const override { return "FIELD"; }
416
417 uint8_t m_SubType;
418
419 // Unclear if just hdr1 or both are needed for a complete field type determination
420 uint32_t m_Hdr1;
421 uint32_t m_Hdr2;
422
423 std::variant<wxString, uint32_t> m_FieldValue;
424
425 // Expects that the field contains a string and returns it
426 const wxString& ExpectString() const;
427};
428
429
435{
436public:
438 m_Chain( aChain )
439 {
440 }
441
447 std::optional<int> GetOptFieldExpectInt( uint16_t aFieldCode ) const;
448
449 const wxString* GetOptFieldExpectString( uint16_t aFieldCode ) const;
450
455 std::optional<std::variant<wxString, uint32_t>> GetOptField( uint16_t aFieldCode ) const;
456
457private:
459};
460
461
465struct NET_ASSIGN : public BRD_DB_OBJ
466{
467 NET_ASSIGN( const BRD_DB& aBrd, const BLK_0x04_NET_ASSIGNMENT& aBlk );
468
469 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
470
471 const char* TypeName() const override { return "NET_ASSIGN"; }
472
477
478 const ALLEGRO::NET& GetNet() const;
479};
480
481
485struct TRACK : public BRD_DB_OBJ
486{
487 TRACK( const BRD_DB& aBrd, const BLK_0x05_TRACK& aBlk );
488
489 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
490};
491
492struct COMPONENT_INST;
493
499struct COMPONENT : public BRD_DB_OBJ
500{
501 COMPONENT( const BRD_DB& aBrd, const BLK_0x06_COMPONENT& aBlk );
502
503 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
504
505 const char* TypeName() const override { return "COMPONENT"; }
506
513
515 const wxString* GetComponentDeviceType() const;
516};
517
518
525{
527
528 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
529
530 const char* TypeName() const override { return "COMPONENT_INST"; }
531
536
538
540
541 const wxString* GetRefDesStr() const;
542 const COMPONENT_INST* GetNextInstance() const;
544 const PLACED_PAD& GetFirstPad() const;
545};
546
547
551struct PIN_NUMBER : public BRD_DB_OBJ
552{
553 PIN_NUMBER( const BLK_0x08_PIN_NUMBER& aBlk );
554
555 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
556
557 const char* TypeName() const override { return "PIN_NUMBER"; }
558
561
562 const wxString* GetNumber() const;
563 const PIN_NAME* GetPinName() const;
564};
565
566
570struct RECT_OBJ : public BRD_DB_OBJ
571{
572 RECT_OBJ( const BRD_DB& aBrd, const BLK_0x0E_RECT& aBlk );
573
574 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
575
576 const char* TypeName() const override { return "RECT_OBJ"; }
577
579};
580
581
586{
588
589 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
590
591 const char* TypeName() const override { return "FUNCTION_SLOT"; }
592
595
598
599 const wxString* GetName() const;
600};
601
602
608{
610
611 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
612
613 const char* TypeName() const override { return "FUNCTION_INSTANCE"; }
614
619
620 const wxString* GetName() const;
622 const FUNCTION_SLOT& GetFunctionSlot() const;
623};
624
625
629struct PIN_NAME : public BRD_DB_OBJ
630{
631 PIN_NAME( const BLK_0x11_PIN_NAME& aBlk );
632
633 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
634
635 const char* TypeName() const override { return "PIN_NAME"; }
636
639
640 const wxString* GetName() const;
641 const PIN_NUMBER* GetPinNumber() const;
642};
643
644
648struct XREF_OBJ : public BRD_DB_OBJ
649{
650 XREF_OBJ( const BLK_0x12_XREF& aBlk );
651
652 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
653
654 const char* TypeName() const override { return "XREF_OBJ"; }
655
659};
660
661
665struct GRAPHIC_SEG : public BRD_DB_OBJ
666{
667 GRAPHIC_SEG( const BRD_DB& aBrd, const BLK_0x14_GRAPHIC& aBlk );
668
669 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
670
671 const char* TypeName() const override { return "GRAPHIC_SEG"; }
672
674 DB_REF m_Segment; // ARC or LINE
675
676 // 0x03?
677 // DB_REF m_Ptr0x03;
678 // 0x26?
679};
680
681
685struct LINE : public BRD_DB_OBJ
686{
687 LINE( const BLK_0x15_16_17_SEGMENT& aBlk );
688
689 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
690
691 const char* TypeName() const override { return "LINE"; }
692
694
698};
699
700
704struct NET : public BRD_DB_OBJ
705{
706 enum class STATUS
707 {
711 };
712
713 NET( const BRD_DB& aBrd, const BLK_0x1B_NET& aBlk );
714
715 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
716
717 const char* TypeName() const override { return "NET"; }
718
720 // Not clear if this is ever not 1 entry, but 0x04s have a next field
722
725
727
728 const wxString* GetName() const;
729 STATUS GetStatus() const;
730
731 const wxString* GetLogicalPath() const;
732
733 std::optional<int> GetNetMinLineWidth() const;
734 std::optional<int> GetNetMaxLineWidth() const;
735 std::optional<int> GetNetMinNeckWidth() const;
736 std::optional<int> GetNetMaxNeckLength() const;
737};
738
739
744{
745public:
746 UNKNOWN_0x20( const BRD_DB& aBrd, const BLK_0x20_UNKNOWN& aBlk );
747
748 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
749
750 const char* TypeName() const override { return "UNKNOWN_0x20"; }
751};
752
753
757class SHAPE : public BRD_DB_OBJ
758{
759public:
760 SHAPE( const BRD_DB& aBrd, const BLK_0x28_SHAPE& aBlk );
761
762 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
763
764 const char* TypeName() const override { return "SHAPE"; }
765
767};
768
769
774{
775 FOOTPRINT_DEF( const BRD_DB& aBrd, const BLK_0x2B_FOOTPRINT_DEF& aBlk );
776
779
781
782 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
783
784 const char* TypeName() const override { return "FOOTPRINT_DEF"; }
785
793 const wxString* GetLibPath() const;
794};
795
796
801{
803
804 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
805
806 const char* TypeName() const override { return "FOOTPRINT_INSTANCE"; }
807
809 double m_X;
810 double m_Y;
813
814 // Chain of PLACED_PADs
816
817 // Chain of graphic segments (SEGMENT, ARC)
819
820 // Backlink to the parent footprint definition
822
824 const wxString* GetName() const;
825};
826
827
832{
833 CONNECTION_OBJ( const BRD_DB& aBrd, const BLK_0x2E_CONNECTION& aBlk );
834
835 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
836
837 const char* TypeName() const override { return "CONNECTION_OBJ"; }
838
842
843};
844
845
849struct PLACED_PAD : public BRD_DB_OBJ
850{
851 PLACED_PAD( const BRD_DB& aBrd, const BLK_0x32_PLACED_PAD& aBlk );
852
853 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
854
855 const char* TypeName() const override { return "PLACED_PAD"; }
856
859 // DB_REF m_Ratline; // 0x23;
863 uint32_t m_Flags;
865
866 const wxString* GetPinName() const;
867 const wxString* GetPinNumber() const;
868
869 const NET* GetNet() const;
870};
871
872
876struct VIA : public BRD_DB_OBJ
877{
878 VIA( const BRD_DB& aBrd, const BLK_0x33_VIA& aBlk );
879
880 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
881
882 const char* TypeName() const override { return "VIA"; }
883
886};
887
888
892struct PTR_ARRAY : public BRD_DB_OBJ
893{
894 PTR_ARRAY( const BRD_DB& aBrd, const BLK_0x37_PTR_ARRAY& aBlk );
895
896 bool ResolveRefs( const DB_OBJ_RESOLVER& aResolver ) override;
897
898 const char* TypeName() const override { return "PTR_ARRAY"; }
899
900 const DB_REF& GetNext() const override { return m_Next; }
901
903
904 std::vector<DB_REF> m_Ptrs;
905};
906
914{
916 m_Board( nullptr ),
917 m_Component( nullptr ),
918 m_Function( nullptr ),
919 m_FootprintInstance( nullptr )
920 {
921 }
922
923 // All views
925 // COMPONENT, COMPONENT_PIN, SYMBOL, FUNCTION
927
929 // FUNCTION
931 //
933
934 // COMPONENT_PIN, LOGICAL_PIN have these
936
937 const NET* m_Net;
938};
939
940
941using VIEW_OBJS_VISITOR = std::function<void( const VIEW_OBJS& aViewObjs )>;
942
943
947class BRD_DB : public DB
948{
949public:
960 {
961 public:
962 OBJ_FACTORY( const BRD_DB& aBrdDb ) :
963 m_brdDb( aBrdDb )
964 {
965 }
966
967 std::unique_ptr<DB_OBJ> CreateObject( const BLOCK_BASE& aBlock ) const;
968
969 private:
971 };
972
973 BRD_DB();
974
975 void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock ) override;
976
981 void ReserveCapacity( size_t aObjectCount, size_t aStringCount );
982
989 void SetLeanMode( bool aLean ) { m_leanMode = aLean; }
990
997 bool ResolveAndValidate();
998
999 using FP_DEF_VISITOR = std::function<void( const FOOTPRINT_DEF& aFpDef )>;
1000
1006 void VisitFootprintDefs( FP_DEF_VISITOR aFpDef ) const;
1007
1013 void VisitFootprintInstances( VIEW_OBJS_VISITOR aVisitor ) const;
1014 void visitFootprintInstances( const FOOTPRINT_DEF& aFpDef, VIEW_OBJS_VISITOR aVisitor ) const;
1015
1024 void VisitFunctionInstances( VIEW_OBJS_VISITOR aVisitor ) const;
1025
1026 void VisitComponents( VIEW_OBJS_VISITOR aVisitor ) const;
1027
1031 void VisitComponentPins( VIEW_OBJS_VISITOR aVisitor ) const;
1032
1033 void VisitNets( VIEW_OBJS_VISITOR aVisitor ) const;
1034
1035 void VisitConnectedGeometry( VIEW_OBJS_VISITOR aVisitor ) const;
1036
1040 const BLOCK_BASE* GetObjectByKey( uint32_t aKey ) const
1041 {
1042 auto it = m_ObjectKeyMap.find( aKey );
1043 return it != m_ObjectKeyMap.end() ? it->second : nullptr;
1044 }
1045
1049 const wxString& GetString( uint32_t aKey ) const
1050 {
1051 static const wxString empty;
1052 auto it = m_StringTable.find( aKey );
1053 return it != m_StringTable.end() ? it->second : empty;
1054 }
1055
1056 // It's not fully clear how much of the header is brd specific or is a more general
1057 // DB format (or is there is a more general format). Clearly much of it (linked lists,
1058 // for example) is very board-related.
1059 // For now, keep it up here, but generalities can push down to DB.
1061 std::unique_ptr<FILE_HEADER> m_Header;
1062
1063 // Raw block storage for backward compatibility with BOARD_BUILDER
1064 std::vector<std::unique_ptr<BLOCK_BASE>> m_Blocks;
1065 std::unordered_map<uint32_t, BLOCK_BASE*> m_ObjectKeyMap;
1066
1067private:
1068 // The factory that will turn BLOCKs into DB_OBJs
1070
1072};
1073
1074} // namespace ALLEGRO
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
The base class for all blocks in the main body of an Allegro file.
Converts blocks of "raw" binary-ish data into a DB_OBJ of the appropriate type to be stored in the DB...
Definition allegro_db.h:960
std::unique_ptr< DB_OBJ > CreateObject(const BLOCK_BASE &aBlock) const
OBJ_FACTORY(const BRD_DB &aBrdDb)
Definition allegro_db.h:962
An Allegro database that represents a .brd file (amd presumably .dra)
Definition allegro_db.h:948
void VisitConnectedGeometry(VIEW_OBJS_VISITOR aVisitor) const
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
std::unique_ptr< FILE_HEADER > m_Header
void SetLeanMode(bool aLean)
When true, InsertBlock skips DB_OBJ creation for high-volume block types (segments,...
Definition allegro_db.h:989
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
void visitFootprintInstances(const FOOTPRINT_DEF &aFpDef, VIEW_OBJS_VISITOR aVisitor) const
void VisitNets(VIEW_OBJS_VISITOR aVisitor) const
void VisitFunctionInstances(VIEW_OBJS_VISITOR aVisitor) const
Access the function instances in the database.
std::function< void(const FOOTPRINT_DEF &aFpDef)> FP_DEF_VISITOR
Definition allegro_db.h:999
const wxString & GetString(uint32_t aKey) const
Get a string from the string table by key.
void VisitFootprintDefs(FP_DEF_VISITOR aFpDef) const
Access the footprint defs in the database.
void ReserveCapacity(size_t aObjectCount, size_t aStringCount)
Pre-allocate storage for the expected number of objects and strings.
bool ResolveAndValidate()
Iterate all the links we know about and fill in the object links.
void VisitComponents(VIEW_OBJS_VISITOR aVisitor) const
OBJ_FACTORY m_ObjFactory
void VisitFootprintInstances(VIEW_OBJS_VISITOR aVisitor) const
Access the footprint instances in the database.
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock) override
const BLOCK_BASE * GetObjectByKey(uint32_t aKey) const
Get a raw block by its key (for compatibility with BOARD_BUILDER).
void VisitComponentPins(VIEW_OBJS_VISITOR aVisitor) const
Visit all component pins in the database.
Some interface that can yield DB_OBJs for keys.
Definition allegro_db.h:145
virtual DB_OBJ * Resolve(uint32_t aKey) const =0
Resolve the given reference.
virtual bool IsSentinel(uint32_t aKey) const
In v18+ files, linked list sentinel nodes are real blocks with small keys.
Definition allegro_db.h:160
virtual const wxString * ResolveString(uint32_t aKey) const =0
const wxString * ResolveString(uint32_t aRef) const override
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:313
void AddObject(std::unique_ptr< DB_OBJ > aObject)
void ResolveObjectLinksBestEffort()
Resolve all DB_OBJ references without throwing on failure.
std::unordered_map< uint32_t, std::unique_ptr< DB_OBJ > > m_Objects
Definition allegro_db.h:307
void AddSentinelKey(uint32_t aKey)
Definition allegro_db.h:285
void AddString(uint32_t aKey, wxString &&aStr)
Definition allegro_db.h:257
void visitLinkedList(const FILE_HEADER::LINKED_LIST aLList, std::function< const DB_REF &(const DB_OBJ &aObj)> aVisitor) const
bool IsSentinel(uint32_t aKey) const override
In v18+ files, linked list sentinel nodes are real blocks with small keys.
Definition allegro_db.h:280
void ResolveObjectLinks()
Iterate the database and resolve links.
std::unordered_set< uint32_t > m_SentinelKeys
Definition allegro_db.h:310
virtual void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)=0
DB_OBJ * Resolve(uint32_t aRef) const override
Implement the object resolver interface.
size_t GetObjectCount() const
Definition allegro_db.h:259
void reserveObjects(size_t aCount)
Definition allegro_db.h:297
A field list is a linked list of 0x03.
Definition allegro_db.h:435
std::optional< int > GetOptFieldExpectInt(uint16_t aFieldCode) const
Get the integer value of the field with the given code, if in the list.
DB_REF_CHAIN & m_Chain
Definition allegro_db.h:458
FIELD_LIST(DB_REF_CHAIN &aChain)
Definition allegro_db.h:437
const wxString * GetOptFieldExpectString(uint16_t aFieldCode) const
std::optional< std::variant< wxString, uint32_t > > GetOptField(uint16_t aFieldCode) const
Get the raw variant value of the field with the given code, if present.
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
DB_REF_CHAIN m_Segments
Definition allegro_db.h:766
const char * TypeName() const override
Definition allegro_db.h:764
SHAPE(const BRD_DB &aBrd, const BLK_0x28_SHAPE &aBlk)
const char * TypeName() const override
Definition allegro_db.h:750
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
UNKNOWN_0x20(const BRD_DB &aBrd, const BLK_0x20_UNKNOWN &aBlk)
static bool empty(const wxTextEntryBase *aCtrl)
std::function< void(const VIEW_OBJS &aViewObjs)> VIEW_OBJS_VISITOR
Definition allegro_db.h:941
static DB_REF DB_NULLREF
Definition allegro_db.h:85
static const DB_STR_REF DB_STRNULLREF
Definition allegro_db.h:139
FMT_VER
The format of an Allego file.
@ BRD_FP_INST
Definition allegro_db.h:337
@ BRD_FUNCTION_SLOT
Definition allegro_db.h:327
@ BRD_PLACED_PAD
Definition allegro_db.h:339
@ BRD_NET_ASSIGN
Definition allegro_db.h:322
@ BRD_GRAPHIC_SEG
Definition allegro_db.h:331
@ BRD_COMPONENT
Definition allegro_db.h:323
@ BRD_FUNCTION_INST
Definition allegro_db.h:328
@ BRD_x0e_RECT
Definition allegro_db.h:326
@ BRD_COMPONENT_INST
Definition allegro_db.h:324
@ BRD_PIN_NAME
Definition allegro_db.h:329
@ BRD_PTR_ARRAY
Definition allegro_db.h:344
@ BRD_PIN_NUMBER
Definition allegro_db.h:325
@ BRD_KEEPOUT
Definition allegro_db.h:341
@ BRD_FILM_LAYER_LIST
Definition allegro_db.h:345
@ BRD_CONNECTION
Definition allegro_db.h:338
@ NET
This item represents a net.
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
ARC(const BLK_0x01_ARC &aBlk)
DB_REF m_Parent
Definition allegro_db.h:396
const char * TypeName() const override
Definition allegro_db.h:400
Arc segment used in tracks, zone outlines, and shape boundaries.
Field/property references with variable-typed substructs.
Net assignment linking a net (0x1B) to its member objects.
Track segment container.
Component/symbol definitions.
Component instance reference data.
Pin number within a component.
Function slot in a multi-slot component (e.g.
Function instance linking a component instance (0x07) to its schematic function, pin cross-references...
Pin name within a component, linked from function slots (0x0F).
Cross-reference between objects.
Graphics container holding a chain of line segments and arcs.
0x15 , 0x16, 0x17 are segments:
0x1B objects are nets.
Polygon shape defined by a linked list of segments starting at m_FirstSegmentPtr (0x15/0x16/0x17 line...
Footprint definition (template) shared by multiple placed instances.
Placed footprint instance on the board.
Connection point at a track junction or pad-to-track transition.
Placed pad instance linking a pad definition (0x0D via m_PadPtr) to its parent footprint (m_ParentFp)...
Via instance with board position, padstack reference (m_Padstack for drill/annular ring definitions),...
Fixed-capacity pointer array (100 entries).
TYPE_ID GetType() const override
All blocks are denoted by a type which allows dispatch to the appropriate subclass.
Definition allegro_db.h:364
BRD_DB_OBJ(BRD_TYPE aType, uint32_t aKey, uint32_t aNextKey)
Definition allegro_db.h:353
BRD_TYPE GetBrdType() const
Definition allegro_db.h:369
COMPONENT_INST 0x07 objects.
Definition allegro_db.h:525
const wxString * GetRefDesStr() const
COMPONENT * m_ParentComponent
Definition allegro_db.h:537
const COMPONENT_INST * GetNextInstance() const
const char * TypeName() const override
Definition allegro_db.h:530
COMPONENT_INST(const BLK_0x07_COMPONENT_INST &aBlk)
const COMPONENT * GetParentComponent() const
Definition allegro_db.h:539
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const PLACED_PAD & GetFirstPad() const
const FUNCTION_INSTANCE & GetFunctionInstance() const
DB_REF_CHAIN m_X03Chain
Definition allegro_db.h:534
COMPONENT 0x06 objects.
Definition allegro_db.h:500
const wxString * GetComponentDeviceType() const
DB_REF_CHAIN m_Instances
Definition allegro_db.h:509
DB_STR_REF m_SymbolName
Definition allegro_db.h:508
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
DB_STR_REF m_CompDeviceType
Definition allegro_db.h:507
COMPONENT(const BRD_DB &aBrd, const BLK_0x06_COMPONENT &aBlk)
const char * TypeName() const override
Definition allegro_db.h:505
const COMPONENT_INST & GetComponentInstance() const
CONNECTION_OBJ(const BRD_DB &aBrd, const BLK_0x2E_CONNECTION &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const char * TypeName() const override
Definition allegro_db.h:837
A DB_OBJ represents one object in an Allegro database.
Definition allegro_db.h:168
uint32_t GetKey() const
Definition allegro_db.h:219
DB_OBJ(uint32_t aKey, uint32_t aNextKey)
Definition allegro_db.h:178
virtual ~DB_OBJ()
Definition allegro_db.h:191
virtual bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver)=0
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
virtual const char * TypeName() const
Definition allegro_db.h:201
virtual TYPE_ID GetType() const =0
All blocks are denoted by a type which allows dispatch to the appropriate subclass.
virtual const DB_REF & GetNext() const
Return the reference to the next object in the default chain for this object.
Definition allegro_db.h:227
Chain of DB references that lead from the head to the tail.
Definition allegro_db.h:91
std::vector< DB_OBJ * > m_Chain
Definition allegro_db.h:120
DB_REF_CHAIN(const DB_OBJ *aParent, uint32_t aHead, uint32_t aTail, const char *aDebugName)
Definition allegro_db.h:92
DB_REF_CHAIN(const DB_OBJ *aParent)
Definition allegro_db.h:100
void Visit(std::function< void(const DB_OBJ &aObj)> aVisitor) const
Visit all objects in the chain.
std::function< const DB_REF &(const DB_OBJ &)> m_NextRefGetter
Definition allegro_db.h:113
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
uint32_t m_EndKey
Definition allegro_db.h:81
DB_REF(const DB_OBJ *aParent, uint32_t aTargetKey, const char *aDebugName)
Definition allegro_db.h:67
uint32_t m_TargetKey
Definition allegro_db.h:76
DB_OBJ * m_Target
Definition allegro_db.h:82
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
const wxString * m_String
Definition allegro_db.h:136
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
DB_STR_REF(const DB_OBJ *aParent, uint32_t aTargetKey, const char *aDebugName)
Definition allegro_db.h:126
uint32_t m_Hdr2
Definition allegro_db.h:421
uint8_t m_SubType
Definition allegro_db.h:417
const wxString & ExpectString() const
uint32_t m_Hdr1
Definition allegro_db.h:420
const char * TypeName() const override
Definition allegro_db.h:415
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
Definition allegro_db.h:413
std::variant< wxString, uint32_t > m_FieldValue
Definition allegro_db.h:423
FIELD(const BLK_0x03_FIELD &aBlk)
This is apparently some kind of linked list that chains though subsets objects in the file.
const char * TypeName() const override
Definition allegro_db.h:784
FOOTPRINT_DEF(const BRD_DB &aBrd, const BLK_0x2B_FOOTPRINT_DEF &aBlk)
const wxString * GetLibPath() const
Get the library path for this footprint definition.
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
DB_REF_CHAIN m_Instances
Definition allegro_db.h:780
const char * TypeName() const override
Definition allegro_db.h:806
const wxString * GetName() const
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
FOOTPRINT_INSTANCE(const BLK_0x2D_FOOTPRINT_INST &aBlk)
const COMPONENT_INST * GetComponentInstance() const
A FUNCTION (0x10) object represents a logical function, which is an instance of a single function slo...
Definition allegro_db.h:608
const FUNCTION_SLOT & GetFunctionSlot() const
const COMPONENT_INST & GetComponentInstance() const
const char * TypeName() const override
Definition allegro_db.h:613
FUNCTION_INSTANCE(const BLK_0x10_FUNCTION_INST &aBlk)
const wxString * GetName() const
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
A FUNCTION_SLOT (0x0F) object represents a single function slot within a symbol.
Definition allegro_db.h:586
FUNCTION_SLOT(const BLK_0x0F_FUNCTION_SLOT &aBlk)
const wxString * GetName() const
const char * TypeName() const override
Definition allegro_db.h:591
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
GRAPHIC_SEG(const BRD_DB &aBrd, const BLK_0x14_GRAPHIC &aBlk)
const char * TypeName() const override
Definition allegro_db.h:671
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const char * TypeName() const override
Definition allegro_db.h:691
DB_REF m_Parent
Definition allegro_db.h:693
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
VECTOR2I m_End
Definition allegro_db.h:696
VECTOR2I m_Start
Definition allegro_db.h:695
LINE(const BLK_0x15_16_17_SEGMENT &aBlk)
0x04 NET_ASSIGN objects
Definition allegro_db.h:466
const ALLEGRO::NET & GetNet() const
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const char * TypeName() const override
Reference to an 0x1B NET object.
Definition allegro_db.h:471
NET_ASSIGN(const BRD_DB &aBrd, const BLK_0x04_NET_ASSIGNMENT &aBlk)
DB_REF m_Net
Reference to an 0x05 TRACK or 0x32 PLACED_PAD object.
Definition allegro_db.h:474
0x1B NET objects
Definition allegro_db.h:705
DB_STR_REF m_NetNameStr
Definition allegro_db.h:719
const wxString * GetLogicalPath() const
std::optional< int > GetNetMaxNeckLength() const
NET(const BRD_DB &aBrd, const BLK_0x1B_NET &aBlk)
std::optional< int > GetNetMinLineWidth() const
std::optional< int > GetNetMaxLineWidth() const
const char * TypeName() const override
Definition allegro_db.h:717
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const wxString * GetName() const
STATUS GetStatus() const
FIELD_LIST m_Fields
Definition allegro_db.h:724
DB_REF_CHAIN m_FieldsChain
Definition allegro_db.h:723
STATUS m_Status
Definition allegro_db.h:726
DB_REF_CHAIN m_NetAssignments
Definition allegro_db.h:721
std::optional< int > GetNetMinNeckWidth() const
0x11 objects.
Definition allegro_db.h:630
const char * TypeName() const override
Definition allegro_db.h:635
const PIN_NUMBER * GetPinNumber() const
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
PIN_NAME(const BLK_0x11_PIN_NAME &aBlk)
DB_STR_REF m_PinNameStr
Definition allegro_db.h:637
const wxString * GetName() const
0x08 objects.
Definition allegro_db.h:552
DB_STR_REF m_PinNumberStr
Definition allegro_db.h:559
const wxString * GetNumber() const
PIN_NUMBER(const BLK_0x08_PIN_NUMBER &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const PIN_NAME * GetPinName() const
const char * TypeName() const override
Definition allegro_db.h:557
0x32 Placed Pad objects.
Definition allegro_db.h:850
const NET * GetNet() const
PLACED_PAD(const BRD_DB &aBrd, const BLK_0x32_PLACED_PAD &aBlk)
const char * TypeName() const override
Definition allegro_db.h:855
const wxString * GetPinName() const
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const wxString * GetPinNumber() const
std::vector< DB_REF > m_Ptrs
Definition allegro_db.h:904
const DB_REF & GetNext() const override
Return the reference to the next object in the default chain for this object.
Definition allegro_db.h:900
PTR_ARRAY(const BRD_DB &aBrd, const BLK_0x37_PTR_ARRAY &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const char * TypeName() const override
Definition allegro_db.h:898
EDA_ANGLE m_Rotation
Definition allegro_db.h:578
RECT_OBJ(const BRD_DB &aBrd, const BLK_0x0E_RECT &aBlk)
const char * TypeName() const override
Definition allegro_db.h:576
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
RESOLVABLE(const DB_OBJ *aParent, const char *aDebugName=nullptr)
Definition allegro_db.h:48
const char * m_DebugName
Definition allegro_db.h:61
virtual ~RESOLVABLE()=default
const DB_OBJ * m_Parent
Definition allegro_db.h:60
virtual bool Resolve(const DB_OBJ_RESOLVER &aResolver)=0
virtual std::string DebugString() const
0x05 TRACK
Definition allegro_db.h:486
TRACK(const BRD_DB &aBrd, const BLK_0x05_TRACK &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
DB_REF m_NetAssign
Definition allegro_db.h:884
const char * TypeName() const override
Definition allegro_db.h:882
VIA(const BRD_DB &aBrd, const BLK_0x33_VIA &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
When processing a view, some objects are available and some are not.
Definition allegro_db.h:914
const FOOTPRINT_INSTANCE * m_FootprintInstance
Definition allegro_db.h:932
const FUNCTION_INSTANCE * m_Function
Definition allegro_db.h:930
const NET * m_Net
Definition allegro_db.h:937
const COMPONENT * m_Component
Definition allegro_db.h:926
const COMPONENT_INST * m_ComponentInstance
Definition allegro_db.h:928
const BRD_DB * m_Board
Definition allegro_db.h:924
const PLACED_PAD * m_Pad
Definition allegro_db.h:935
XREF_OBJ(const BLK_0x12_XREF &aBlk)
bool ResolveRefs(const DB_OBJ_RESOLVER &aResolver) override
Called when all objects in the DB are read and can be resolved by their IDs by other objects.
const char * TypeName() const override
Definition allegro_db.h:654
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695