29#ifndef _EAGLE_PARSER_H_ 
   30#define _EAGLE_PARSER_H_ 
   35#include <unordered_map> 
   37#include <wx/xml/xml.h> 
   39#include <wx/filename.h> 
   54typedef std::unordered_map<wxString, wxXmlNode*> 
NODE_MAP;
 
   56typedef std::map<wxString, std::unique_ptr<EPART>> 
EPART_MAP;
 
   59wxString 
escapeName( 
const wxString& aNetName );
 
   72    auto it = aMap.find( aName );
 
   73    return it == aMap.end() ? nullptr : it->second->GetChildren();
 
 
   90        std::runtime_error( 
"XML parser failed - " + aMessage.ToStdString() )
 
 
 
  102    TRIPLET( 
const char* aElement, 
const char* aAttribute = 
"", 
const char* aValue = 
"" ) :
 
 
 
  125    std::vector<TRIPLET> 
p;
 
  128    void push( 
const char* aPathSegment, 
const char* aAttribute=
"" )
 
  130        p.emplace_back( aPathSegment, aAttribute );
 
 
  140        p.back().value = aValue;
 
 
  146        p.back().attribute = aAttribute;
 
 
  152        typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
 
  156        for( CITER_TRIPLET it = 
p.begin();  it != 
p.end();  ++it )
 
  158            if( it != 
p.begin() )
 
  163            if( it->attribute[0] && it->value[0] )
 
  166                ret += it->attribute;
 
 
 
  237    template<
typename V = T>
 
  246    operator bool()
 const 
 
  294    void Set( 
const wxString& aString )
 
 
 
  437    EURN( 
const wxString& aUrn );
 
  439    void Parse( 
const wxString& aUrn );
 
 
  511        return value / 25400;
 
 
  526        return value / 1000000.0;
 
 
 
  567    ENET( 
int aNetCode, 
const wxString& aNetName ) :
 
 
 
 1322    std::map<wxString, std::unique_ptr<EVARIANT>> 
variants;
 
 
 1494    std::map<wxString, std::unique_ptr<EVARIANT>> 
variants;
 
 
 1640    std::map<wxString, std::unique_ptr<EGATE>> 
gates;
 
 
 1752    std::vector<std::unique_ptr<EWIRE>>      
wires;
 
 1753    std::vector<std::unique_ptr<ETEXT>>      
texts;
 
 1759    std::vector<std::unique_ptr<EHOLE>>      
holes;
 
 
 1870    std::vector<std::unique_ptr<EWIRE>>     
wires;
 
 
 1906    std::vector<std::unique_ptr<ENET>>               
nets;
 
 
 1929    std::map<wxString, std::unique_ptr<EPORT>>            
ports;
 
 1931    std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>> 
groups;
 
 1932    std::map<wxString, std::unique_ptr<EPART>>            
parts;
 
 
 1962    std::vector<std::unique_ptr<ENOTE>> 
notes;
 
 
 2055    std::vector<std::unique_ptr<EWIRE>>      
wires;
 
 2056    std::vector<std::unique_ptr<ETEXT>>      
texts;
 
 2061    std::vector<std::unique_ptr<EHOLE>>      
holes;
 
 
 2134    std::vector<std::unique_ptr<EWIRE>>      
wires;
 
 2135    std::vector<std::unique_ptr<ETEXT>>      
texts;
 
 2137    std::vector<std::unique_ptr<EPIN>>       
pins;
 
 
 2161    std::map<wxString, std::unique_ptr<EPACKAGE>>    
packages;
 
 2163    std::map<wxString, std::unique_ptr<ESYMBOL>>     
symbols;
 
 
 2207    std::map<wxString, std::unique_ptr<ECLASS>>           
classes;
 
 2208    std::map<wxString, std::unique_ptr<EMODULE>>          
modules;
 
 2209    std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>> 
groups;
 
 2210    std::map<wxString, std::unique_ptr<EPART>>            
parts;
 
 2212    std::vector<std::unique_ptr<EAPPROVED>>               
errors;
 
 
Model an optional XML attribute.
 
bool operator==(const T &aOther) const
 
const T * operator->() const
Return a constant pointer to the value of the attribute assuming it is available.
 
OPTIONAL_XML_ATTRIBUTE< T > & operator=(const wxString &aData)
Assign to a string (optionally) containing the data.
 
T * operator->()
Return a pointer to the value of the attribute assuming it is available.
 
const T & operator*() const
Return a constant reference to the value of the attribute assuming it is available.
 
OPTIONAL_XML_ATTRIBUTE(const wxString &aData)
 
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
 
void Set(const wxString &aString)
Attempt to convert a string to the base type.
 
T & operator*()
Return a reference to the value of the attribute assuming it is available.
 
T & Get()
Return a reference to the value of the attribute assuming it is available.
 
OPTIONAL_XML_ATTRIBUTE(T aData)
 
OPTIONAL_XML_ATTRIBUTE()
Construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.
 
Keep track of what we are working on within a PTREE.
 
void Value(const char *aValue)
modify the last path node's value
 
void Attribute(const char *aAttribute)
Modify the last path node's attribute.
 
void push(const char *aPathSegment, const char *aAttribute="")
 
wxString Contents()
Return the contents of the XPATH as a single string.
 
OPTIONAL_XML_ATTRIBUTE< EURN > opt_eurn
 
OPTIONAL_XML_ATTRIBUTE< ECOORD > opt_ecoord
 
T Convert(const wxString &aValue)
Convert a wxString to a generic type T.
 
OPTIONAL_XML_ATTRIBUTE< int > opt_int
 
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
 
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
 
OPTIONAL_XML_ATTRIBUTE< EROT > opt_erot
 
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
 
wxString interpretText(const wxString &aText)
Interprets special characters in Eagle text and converts them to KiCAD notation.
 
bool substituteVariable(wxString *aText)
Translates Eagle special text reference to a KiCad variable reference.
 
wxString Convert< wxString >(const wxString &aValue)
 
size_t GetNodeCount(const wxXmlNode *aNode)
Fetch the number of XML nodes within aNode.
 
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
 
std::map< wxString, EINSTANCE * > EINSTANCE_MAP
 
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
 
OPTIONAL_XML_ATTRIBUTE< bool > opt_bool
 
OPTIONAL_XML_ATTRIBUTE< double > opt_double
 
VECTOR2I ConvertArcCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC.
 
wxString convertDescription(wxString aDescr)
Converts Eagle's HTML description into KiCad description format.
 
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
 
EAGLE_BASE(IO_BASE *aIo=nullptr)
 
void AdvanceProgressPhase()
 
void Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Send a message to the IO_BASE REPORTER object if one exists.
 
EAGLE_DOC(wxXmlNode *aEagleDoc, IO_BASE *aIo=nullptr)
 
std::optional< ECOMPATIBILITY > compatibility
 
wxString version
The Eagle XML file version.
 
std::unique_ptr< EDRAWING > drawing
 
EAPPROVED(wxXmlNode *aApproved, IO_BASE *aIo=nullptr)
 
EATTR(wxXmlNode *aTree, IO_BASE *aIo=nullptr)
 
EBUS(wxXmlNode *aBus, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< ESEGMENT > > segments
 
ECIRCLE(wxXmlNode *aCircle, IO_BASE *aIo=nullptr)
 
std::map< wxString, ECOORD > clearanceMap
 
ECLASS(wxXmlNode *aClass, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< ENOTE > > notes
 
ECOMPATIBILITY(wxXmlNode *aCompatibility, IO_BASE *aIo=nullptr)
 
opt_wxString contactroute
 
ECONNECT(wxXmlNode *aConnect, IO_BASE *aIo=nullptr)
 
ECOORD operator+(const ECOORD &aOther) const
 
ECOORD operator-(const ECOORD &aOther) const
 
int To100NanoMeters() const
 
ECOORD(int aValue, enum EAGLE_UNIT aUnit)
 
long long int value
Value expressed in nanometers.
 
bool operator==(const ECOORD &aOther) const
 
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
Converts a size expressed in a certain unit to nanometers.
 
static constexpr EAGLE_UNIT ECOORD_UNIT
Unit used for the value field.
 
EDESCRIPTION(wxXmlNode *aDescription, IO_BASE *aIo=nullptr)
 
opt_bool library_locally_modified
 
std::vector< std::unique_ptr< EDEVICE > > devices
 
opt_bool locally_modified
 
std::optional< EDESCRIPTION > description
 
EDEVICE_SET(wxXmlNode *aDeviceSet, IO_BASE *aIo=nullptr)
 
std::map< wxString, std::unique_ptr< EGATE > > gates
 
std::optional< ESPICE > spice
 
std::vector< std::unique_ptr< EPACKAGE3DINST > > package3dinstances
 
std::vector< std::unique_ptr< ECONNECT > > connects
 
EDEVICE(wxXmlNode *aDevice, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< ETECHNOLOGY > > technologies
 
opt_wxString dimensionType
 
EDIMENSION(wxXmlNode *aDimension, IO_BASE *aIo=nullptr)
 
std::optional< ESCHEMATIC > schematic
 
std::optional< ELIBRARY > library
 
EDRAWING(wxXmlNode *aDrawing, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< ESETTING > > settings
 
std::vector< std::unique_ptr< ELAYER > > layers
 
std::optional< EGRID > grid
 
std::vector< std::unique_ptr< EFILTER > > filters
 
EELEMENT(wxXmlNode *aElement, IO_BASE *aIo=nullptr)
 
opt_wxString package3d_urn
 
opt_wxString override_package3d_urn
 
opt_bool override_locally_modified
 
std::map< wxString, std::unique_ptr< EATTR > > attributes
 
std::map< wxString, std::unique_ptr< EVARIANT > > variants
 
EFILTER(wxXmlNode *aGrid, IO_BASE *aIo=nullptr)
 
EFRAME(wxXmlNode *aFrameNode, IO_BASE *aIo=nullptr)
 
EGATE(wxXmlNode *aGate, IO_BASE *aIo=nullptr)
 
EGRID(wxXmlNode *aGrid, IO_BASE *aIo=nullptr)
 
EHOLE(wxXmlNode *aHole, IO_BASE *aIo=nullptr)
 
std::map< wxString, std::unique_ptr< EATTR > > attributes
 
EINSTANCE(wxXmlNode *aInstance, IO_BASE *aIo=nullptr)
 
EJUNCTION(wxXmlNode *aJunction, IO_BASE *aIo=nullptr)
 
ELABEL(wxXmlNode *aLabel, IO_BASE *aIo=nullptr)
 
ELAYER(wxXmlNode *aLayer, IO_BASE *aIo=nullptr)
 
std::map< wxString, std::unique_ptr< EDEVICE_SET > > devicesets
 
wxString GetName() const
Fetch the fully unique library name.
 
std::map< wxString, std::unique_ptr< EPACKAGE3D > > packages3d
 
std::map< wxString, std::unique_ptr< EPACKAGE > > packages
 
std::optional< EDESCRIPTION > description
 
std::map< wxString, std::unique_ptr< ESYMBOL > > symbols
 
ELIBRARY(wxXmlNode *aLibrary, IO_BASE *aIo=nullptr)
 
EMODEL(wxXmlNode *aModel, IO_BASE *aIo=nullptr)
 
EMODULEINST(wxXmlNode *aModuleInst, IO_BASE *aIo=nullptr)
 
opt_wxString moduleVariant
 
std::map< wxString, std::unique_ptr< EPART > > parts
 
std::map< wxString, std::unique_ptr< ESCHEMATIC_GROUP > > groups
 
std::vector< std::unique_ptr< ESHEET > > sheets
 
std::optional< EDESCRIPTION > description
 
EMODULE(wxXmlNode *aModule, IO_BASE *aIo=nullptr)
 
std::map< wxString, std::unique_ptr< EVARIANTDEF > > variantdefs
 
std::map< wxString, std::unique_ptr< EPORT > > ports
 
std::vector< std::unique_ptr< ESEGMENT > > segments
 
ENET(int aNetCode, const wxString &aNetName)
 
ENOTE(wxXmlNode *aNote, IO_BASE *aIo=nullptr)
 
EPACKAGE3DINST(wxXmlNode *aPackage3dInst, IO_BASE *aIo=nullptr)
 
opt_bool library_locally_modified
 
std::optional< EDESCRIPTION > description
 
std::vector< std::unique_ptr< EPACKAGEINSTANCE > > packageinstances
 
EPACKAGE3D(wxXmlNode *aPackage3d, IO_BASE *aIo=nullptr)
 
EPACKAGEINSTANCE(wxXmlNode *aPackageInstance, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EPOLYGON > > polygons
 
std::vector< std::unique_ptr< EPAD > > thtpads
 
std::vector< std::unique_ptr< ECIRCLE > > circles
 
std::vector< std::unique_ptr< ESMD > > smdpads
 
std::vector< std::unique_ptr< EDIMENSION > > dimensions
 
opt_bool library_locally_modified
 
std::vector< std::unique_ptr< EHOLE > > holes
 
std::vector< std::unique_ptr< EFRAME > > frames
 
std::vector< std::unique_ptr< ERECT > > rectangles
 
std::vector< std::unique_ptr< ETEXT > > texts
 
std::vector< std::unique_ptr< EWIRE > > wires
 
std::optional< EDESCRIPTION > description
 
EPACKAGE(wxXmlNode *aPackage, IO_BASE *aIo=nullptr)
 
opt_bool locally_modified
 
EPAD_COMMON(wxXmlNode *aPad, IO_BASE *aIo=nullptr)
 
EPAD(wxXmlNode *aPad, IO_BASE *aIo=nullptr)
 
std::unique_ptr< ESPICE > spice
 
opt_bool override_locally_modified
 
opt_wxString override_package_urn
 
std::map< wxString, std::unique_ptr< EATTR > > attributes
 
opt_wxString override_package3d_urn
 
EPART(wxXmlNode *aPart, IO_BASE *aIo=nullptr)
 
opt_wxString package3d_urn
 
std::map< wxString, std::unique_ptr< EVARIANT > > variants
 
EPINMAPPING(wxXmlNode *aPinMap, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EPINMAP > > pinmaps
 
EPINMAP(wxXmlNode *aPinMap, IO_BASE *aIo=nullptr)
 
EPINREF(wxXmlNode *aPinRef, IO_BASE *aIo=nullptr)
 
EPIN(wxXmlNode *aPin, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EWIRE > > wires
 
std::vector< std::unique_ptr< EPOLYGON > > polygons
 
std::vector< std::unique_ptr< ETEXT > > texts
 
std::vector< std::unique_ptr< ECIRCLE > > circles
 
EPLAIN(wxXmlNode *aPlain, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EFRAME > > frames
 
std::vector< std::unique_ptr< ESPLINE > > splines
 
std::vector< std::unique_ptr< ERECT > > rectangles
 
std::vector< std::unique_ptr< EDIMENSION > > dimensions
 
std::vector< std::unique_ptr< EHOLE > > holes
 
static const int max_priority
 
std::vector< std::unique_ptr< EVERTEX > > vertices
 
EPOLYGON(wxXmlNode *aPolygon, IO_BASE *aIo=nullptr)
 
EPORTREF(wxXmlNode *aPortRef, IO_BASE *aIo=nullptr)
 
EPORT(wxXmlNode *aPort, IO_BASE *aIo=nullptr)
 
EPROBE(wxXmlNode *aProbe, IO_BASE *aIo=nullptr)
 
ERECT(wxXmlNode *aRect, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EATTR > > attributes
 
ESCHEMATIC_GROUP(wxXmlNode *aSchematicGroup, IO_BASE *aIo=nullptr)
 
std::optional< EDESCRIPTION > description
 
std::map< wxString, std::unique_ptr< EMODULE > > modules
 
std::map< wxString, std::unique_ptr< EATTR > > attributes
 
std::vector< std::unique_ptr< EAPPROVED > > errors
 
std::optional< EDESCRIPTION > description
 
std::map< wxString, std::unique_ptr< ECLASS > > classes
 
std::vector< std::unique_ptr< ESHEET > > sheets
 
std::map< wxString, std::unique_ptr< EPART > > parts
 
ESCHEMATIC(wxXmlNode *aSchematic, IO_BASE *aIo=nullptr)
 
std::map< wxString, std::unique_ptr< ELIBRARY > > libraries
 
std::map< wxString, std::unique_ptr< EVARIANTDEF > > variantdefs
 
std::map< wxString, std::unique_ptr< ESCHEMATIC_GROUP > > groups
 
std::vector< std::unique_ptr< EPORTREF > > portRefs
 
std::vector< std::unique_ptr< EPROBE > > probes
 
std::vector< std::unique_ptr< EPINREF > > pinRefs
 
ESEGMENT(wxXmlNode *aSegment, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EWIRE > > wires
 
std::vector< std::unique_ptr< EJUNCTION > > junctions
 
std::vector< std::unique_ptr< ELABEL > > labels
 
opt_bool alwaysvectorfont
 
opt_bool keepoldvectorfont
 
opt_wxString verticaltext
 
ESETTING(wxXmlNode *aSetting, IO_BASE *aIo=nullptr)
 
ESHEET(wxXmlNode *aSheet, IO_BASE *aIo=nullptr)
 
std::unique_ptr< EPLAIN > plain
 
std::vector< std::unique_ptr< ENET > > nets
 
std::vector< std::unique_ptr< EBUS > > busses
 
std::vector< std::unique_ptr< EINSTANCE > > instances
 
std::optional< EDESCRIPTION > description
 
std::map< wxString, std::unique_ptr< EMODULEINST > > moduleinsts
 
ESMD(wxXmlNode *aSMD, IO_BASE *aIo=nullptr)
 
ESPICE(wxXmlNode *aSpice, IO_BASE *aIo=nullptr)
 
std::unique_ptr< EMODEL > model
 
std::unique_ptr< EPINMAPPING > pinmapping
 
std::vector< std::unique_ptr< EVERTEX > > vertices
 
ESPLINE(wxXmlNode *aSpline, IO_BASE *aIo=nullptr)
 
std::vector< std::unique_ptr< EFRAME > > frames
 
std::optional< EDESCRIPTION > description
 
std::vector< std::unique_ptr< EPIN > > pins
 
std::vector< std::unique_ptr< ECIRCLE > > circles
 
opt_bool library_locally_modified
 
std::vector< std::unique_ptr< ETEXT > > texts
 
std::vector< std::unique_ptr< EPOLYGON > > polygons
 
std::vector< std::unique_ptr< ERECT > > rectangles
 
std::vector< std::unique_ptr< EWIRE > > wires
 
ESYMBOL(wxXmlNode *aSymbol, IO_BASE *aIo=nullptr)
 
opt_bool locally_modified
 
std::vector< std::unique_ptr< EDIMENSION > > dimensions
 
std::vector< std::unique_ptr< EATTR > > attributes
 
ETECHNOLOGY(wxXmlNode *aTechnology, IO_BASE *aIo=nullptr)
 
ETEXT(wxXmlNode *aText, IO_BASE *aIo=nullptr)
 
VECTOR2I ConvertSize() const
Calculate text size based on font type and size.
 
Container that parses Eagle library file "urn" definitions.
 
bool IsValid() const
Check if the string passed to the ctor was a valid Eagle urn.
 
wxString host
Should always be "urn".
 
void Parse(const wxString &aUrn)
 
wxString assetVersion
May be empty depending on the asset type.
 
wxString assetId
The unique asset identifier for the asset type.
 
wxString assetType
Must be "symbol", "footprint", "package", "component", or "library".
 
wxString path
Path to the asset type below.
 
EVARIANTDEF(wxXmlNode *aVariantDef, IO_BASE *aIo=nullptr)
 
EVARIANT(wxXmlNode *aVariant, IO_BASE *aIo=nullptr)
 
EVERTEX(wxXmlNode *aVertex, IO_BASE *aIo=nullptr)
 
opt_double curve
range is -359.9..359.9
 
EVIA(wxXmlNode *aVia, IO_BASE *aIo=nullptr)
 
int layer_back_most
< extent
 
EWIRE(wxXmlNode *aWire, IO_BASE *aIo=nullptr)
 
opt_double curve
range is -359.9..359.9
 
TRIPLET(const char *aElement, const char *aAttribute="", const char *aValue="")
 
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
 
XML_PARSER_ERROR(const wxString &aMessage) noexcept
Build an XML error by just calling its parent class constructor, std::runtime_error,...
 
VECTOR2< int32_t > VECTOR2I