29#include <unordered_map>
30#include <unordered_set>
67 DB_REF(
const DB_OBJ* aParent, uint32_t aTargetKey,
const char* aDebugName ) :
110 void Visit( std::function<
void(
const DB_OBJ& aObj )> aVisitor )
const;
111 void Visit( std::function<
void(
DB_OBJ& aObj )> aVisitor );
160 virtual bool IsSentinel( uint32_t aKey )
const {
return false; }
178 DB_OBJ( uint32_t aKey, uint32_t aNextKey ) :
255 void AddObject( std::unique_ptr<DB_OBJ> aObject );
278 const wxString*
ResolveString( uint32_t aRef )
const override;
291 virtual void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock ) = 0;
295 std::function<
const DB_REF&(
const DB_OBJ& aObj )> aVisitor )
const;
307 std::unordered_map<uint32_t, std::unique_ptr<DB_OBJ>>
m_Objects;
400 const char*
TypeName()
const override {
return "ARC"; }
415 const char*
TypeName()
const override {
return "FIELD"; }
455 std::optional<std::variant<wxString, uint32_t>>
GetOptField( uint16_t aFieldCode )
const;
471 const char*
TypeName()
const override {
return "NET_ASSIGN"; }
505 const char*
TypeName()
const override {
return "COMPONENT"; }
530 const char*
TypeName()
const override {
return "COMPONENT_INST"; }
557 const char*
TypeName()
const override {
return "PIN_NUMBER"; }
576 const char*
TypeName()
const override {
return "RECT_OBJ"; }
591 const char*
TypeName()
const override {
return "FUNCTION_SLOT"; }
599 const wxString*
GetName()
const;
613 const char*
TypeName()
const override {
return "FUNCTION_INSTANCE"; }
620 const wxString*
GetName()
const;
635 const char*
TypeName()
const override {
return "PIN_NAME"; }
640 const wxString*
GetName()
const;
654 const char*
TypeName()
const override {
return "XREF_OBJ"; }
671 const char*
TypeName()
const override {
return "GRAPHIC_SEG"; }
691 const char*
TypeName()
const override {
return "LINE"; }
717 const char*
TypeName()
const override {
return "NET"; }
728 const wxString*
GetName()
const;
750 const char*
TypeName()
const override {
return "UNKNOWN_0x20"; }
764 const char*
TypeName()
const override {
return "SHAPE"; }
784 const char*
TypeName()
const override {
return "FOOTPRINT_DEF"; }
806 const char*
TypeName()
const override {
return "FOOTPRINT_INSTANCE"; }
824 const wxString*
GetName()
const;
837 const char*
TypeName()
const override {
return "CONNECTION_OBJ"; }
855 const char*
TypeName()
const override {
return "PLACED_PAD"; }
882 const char*
TypeName()
const override {
return "VIA"; }
898 const char*
TypeName()
const override {
return "PTR_ARRAY"; }
975 void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock )
override;
1051 static const wxString
empty;
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...
std::unique_ptr< DB_OBJ > CreateObject(const BLOCK_BASE &aBlock) const
OBJ_FACTORY(const BRD_DB &aBrdDb)
An Allegro database that represents a .brd file (amd presumably .dra)
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,...
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
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
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.
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.
virtual const wxString * ResolveString(uint32_t aKey) const =0
virtual ~DB_OBJ_RESOLVER()
const wxString * ResolveString(uint32_t aRef) const override
std::unordered_map< uint32_t, wxString > m_StringTable
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
void AddSentinelKey(uint32_t aKey)
void AddString(uint32_t aKey, wxString &&aStr)
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.
void ResolveObjectLinks()
Iterate the database and resolve links.
std::unordered_set< uint32_t > m_SentinelKeys
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
void reserveObjects(size_t aCount)
A field list is a linked list of 0x03.
std::optional< int > GetOptFieldExpectInt(uint16_t aFieldCode) const
Get the integer value of the field with the given code, if in the list.
FIELD_LIST(DB_REF_CHAIN &aChain)
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.
const char * TypeName() const override
SHAPE(const BRD_DB &aBrd, const BLK_0x28_SHAPE &aBlk)
const char * TypeName() const override
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
static const DB_STR_REF DB_STRNULLREF
FMT_VER
The format of an Allego file.
@ 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)
const char * TypeName() const override
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.
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:
Polygon shape defined by a linked list of segments starting at m_FirstSegmentPtr (0x15/0x16/0x17 line...
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.
BRD_DB_OBJ(BRD_TYPE aType, uint32_t aKey, uint32_t aNextKey)
BRD_TYPE GetBrdType() const
COMPONENT_INST 0x07 objects.
const wxString * GetRefDesStr() const
COMPONENT * m_ParentComponent
const COMPONENT_INST * GetNextInstance() const
const char * TypeName() const override
COMPONENT_INST(const BLK_0x07_COMPONENT_INST &aBlk)
const COMPONENT * GetParentComponent() 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 PLACED_PAD & GetFirstPad() const
const FUNCTION_INSTANCE & GetFunctionInstance() const
const wxString * GetComponentDeviceType() 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.
DB_STR_REF m_CompDeviceType
COMPONENT(const BRD_DB &aBrd, const BLK_0x06_COMPONENT &aBlk)
const char * TypeName() const override
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
A DB_OBJ represents one object in an Allegro database.
DB_OBJ(uint32_t aKey, uint32_t aNextKey)
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
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.
Chain of DB references that lead from the head to the tail.
std::vector< DB_OBJ * > m_Chain
DB_REF_CHAIN(const DB_OBJ *aParent, uint32_t aHead, uint32_t aTail, const char *aDebugName)
DB_REF_CHAIN(const DB_OBJ *aParent)
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
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
DB_REF(const DB_OBJ *aParent, uint32_t aTargetKey, const char *aDebugName)
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
const wxString * m_String
bool Resolve(const DB_OBJ_RESOLVER &aResolver) override
DB_STR_REF(const DB_OBJ *aParent, uint32_t aTargetKey, const char *aDebugName)
const wxString & ExpectString() const
const char * TypeName() const override
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.
std::variant< wxString, uint32_t > m_FieldValue
FIELD(const BLK_0x03_FIELD &aBlk)
A FUNCTION (0x10) object represents a logical function, which is an instance of a single function slo...
const FUNCTION_SLOT & GetFunctionSlot() const
const COMPONENT_INST & GetComponentInstance() const
const char * TypeName() const override
FUNCTION_INSTANCE(const BLK_0x10_FUNCTION_INST &aBlk)
const wxString * GetName() const
DB_REF m_ComponentInstance
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_FunctionName
A FUNCTION_SLOT (0x0F) object represents a single function slot within a symbol.
FUNCTION_SLOT(const BLK_0x0F_FUNCTION_SLOT &aBlk)
const wxString * GetName() const
wxString m_CompDeviceType
const char * TypeName() const override
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
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
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.
LINE(const BLK_0x15_16_17_SEGMENT &aBlk)
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.
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.
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
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
DB_REF_CHAIN m_FieldsChain
DB_REF_CHAIN m_NetAssignments
std::optional< int > GetNetMinNeckWidth() const
const char * TypeName() const override
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)
const wxString * GetName() const
DB_STR_REF m_PinNumberStr
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
const NET * GetNet() const
PLACED_PAD(const BRD_DB &aBrd, const BLK_0x32_PLACED_PAD &aBlk)
const char * TypeName() const override
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
const DB_REF & GetNext() const override
Return the reference to the next object in the default chain for this object.
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
RECT_OBJ(const BRD_DB &aBrd, const BLK_0x0E_RECT &aBlk)
const char * TypeName() const override
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)
virtual ~RESOLVABLE()=default
virtual bool Resolve(const DB_OBJ_RESOLVER &aResolver)=0
virtual std::string DebugString() const
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.
const char * TypeName() const override
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.
const FOOTPRINT_INSTANCE * m_FootprintInstance
const FUNCTION_INSTANCE * m_Function
const COMPONENT * m_Component
const COMPONENT_INST * m_ComponentInstance
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
VECTOR2< int32_t > VECTOR2I