25#ifndef _EAGLE_PARSER_H_
26#define _EAGLE_PARSER_H_
31#include <unordered_map>
33#include <wx/xml/xml.h>
35#include <wx/filename.h>
50typedef std::unordered_map<wxString, wxXmlNode*>
NODE_MAP;
52typedef std::map<wxString, std::unique_ptr<EPART>>
EPART_MAP;
55wxString
escapeName(
const wxString& aNetName );
68 auto it = aMap.find( aName );
69 return it == aMap.end() ? nullptr : it->second->GetChildren();
86 std::runtime_error(
"XML parser failed - " + aMessage.ToStdString() )
98 TRIPLET(
const char* aElement,
const char* aAttribute =
"",
const char* aValue =
"" ) :
121 std::vector<TRIPLET>
p;
124 void push(
const char* aPathSegment,
const char* aAttribute=
"" )
126 p.emplace_back( aPathSegment, aAttribute );
136 p.back().value = aValue;
142 p.back().attribute = aAttribute;
148 typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
152 for( CITER_TRIPLET it =
p.begin(); it !=
p.end(); ++it )
154 if( it !=
p.begin() )
159 if( it->attribute[0] && it->value[0] )
162 ret += it->attribute;
260 EURN(
const wxString& aUrn );
262 void Parse(
const wxString& aUrn );
334 return value / 25400;
349 return value / 1000000.0;
390 ENET(
int aNetCode,
const wxString& aNetName ) :
680 std::optional<ECOORD>
x;
681 std::optional<ECOORD>
y;
1150 std::map<wxString, std::unique_ptr<EVARIANT>>
variants;
1333 std::map<wxString, std::unique_ptr<EVARIANT>>
variants;
1479 std::map<wxString, std::unique_ptr<EGATE>>
gates;
1480 std::map<wxString, std::unique_ptr<EDEVICE>>
devices;
1591 std::vector<std::unique_ptr<EWIRE>>
wires;
1592 std::vector<std::unique_ptr<ETEXT>>
texts;
1598 std::vector<std::unique_ptr<EHOLE>>
holes;
1709 std::vector<std::unique_ptr<EWIRE>>
wires;
1745 std::vector<std::unique_ptr<ENET>>
nets;
1768 std::map<wxString, std::unique_ptr<EPORT>>
ports;
1770 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
1771 std::map<wxString, std::unique_ptr<EPART>>
parts;
1801 std::vector<std::unique_ptr<ENOTE>>
notes;
1894 std::vector<std::unique_ptr<EWIRE>>
wires;
1895 std::vector<std::unique_ptr<ETEXT>>
texts;
1900 std::vector<std::unique_ptr<EHOLE>>
holes;
1973 std::vector<std::unique_ptr<EWIRE>>
wires;
1974 std::vector<std::unique_ptr<ETEXT>>
texts;
1976 std::vector<std::unique_ptr<EPIN>>
pins;
2000 std::map<wxString, std::unique_ptr<EPACKAGE>>
packages;
2002 std::map<wxString, std::unique_ptr<ESYMBOL>>
symbols;
2046 std::map<wxString, std::unique_ptr<ECLASS>>
classes;
2047 std::map<wxString, std::unique_ptr<EMODULE>>
modules;
2048 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
2049 std::map<wxString, std::unique_ptr<EPART>>
parts;
2051 std::vector<std::unique_ptr<EAPPROVED>>
errors;
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.
T Convert(const wxString &aValue)
Convert a wxString to a generic type T.
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.
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.
std::map< wxString, EINSTANCE * > EINSTANCE_MAP
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
VECTOR2I ConvertEagleTextSize(const std::optional< wxString > &font, const ECOORD &size)
Converts Eagle's text size to KiCad text size depending on the font used.
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)
std::optional< int > layer
std::optional< ECOORD > y
std::optional< wxString > value
std::optional< bool > constant
std::optional< wxString > font
std::optional< ECOORD > size
std::optional< int > align
std::optional< EROT > rot
std::optional< double > ratio
std::optional< int > display
EATTR(wxXmlNode *aTree, IO_BASE *aIo=nullptr)
std::optional< ECOORD > x
EBUS(wxXmlNode *aBus, IO_BASE *aIo=nullptr)
std::vector< std::unique_ptr< ESEGMENT > > segments
ECIRCLE(wxXmlNode *aCircle, IO_BASE *aIo=nullptr)
std::optional< ECOORD > width
std::map< wxString, ECOORD > clearanceMap
std::optional< ECOORD > drill
ECLASS(wxXmlNode *aClass, IO_BASE *aIo=nullptr)
std::vector< std::unique_ptr< ENOTE > > notes
ECOMPATIBILITY(wxXmlNode *aCompatibility, IO_BASE *aIo=nullptr)
std::optional< 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.
std::optional< wxString > language
EDESCRIPTION(wxXmlNode *aDescription, IO_BASE *aIo=nullptr)
std::map< wxString, std::unique_ptr< EDEVICE > > devices
std::optional< wxString > prefix
std::optional< EURN > urn
std::optional< EDESCRIPTION > description
EDEVICE_SET(wxXmlNode *aDeviceSet, IO_BASE *aIo=nullptr)
std::optional< bool > locally_modified
std::map< wxString, std::unique_ptr< EGATE > > gates
std::optional< int > library_version
std::optional< ESPICE > spice
std::optional< bool > uservalue
std::optional< bool > library_locally_modified
std::optional< wxString > package
std::vector< std::unique_ptr< EPACKAGE3DINST > > package3dinstances
std::vector< std::unique_ptr< ECONNECT > > connects
EDEVICE(wxXmlNode *aDevice, IO_BASE *aIo=nullptr)
std::map< wxString, std::unique_ptr< ETECHNOLOGY > > technologies
std::optional< wxString > unit
std::optional< wxString > dimensionType
std::optional< double > extlength
std::optional< ECOORD > textsize
std::optional< bool > visible
std::optional< int > textratio
std::optional< int > precision
EDIMENSION(wxXmlNode *aDimension, IO_BASE *aIo=nullptr)
std::optional< double > width
std::optional< double > extoffset
std::optional< double > extwidth
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)
std::optional< wxString > override_package3d_urn
std::optional< bool > locked
std::optional< bool > smashed
std::optional< wxString > package3d_urn
std::optional< bool > override_locally_modified
std::optional< EROT > rot
std::optional< EURN > library_urn
std::map< wxString, std::unique_ptr< EATTR > > attributes
std::map< wxString, std::unique_ptr< EVARIANT > > variants
EFILTER(wxXmlNode *aGrid, IO_BASE *aIo=nullptr)
std::optional< bool > border_bottom
std::optional< bool > border_top
EFRAME(wxXmlNode *aFrameNode, IO_BASE *aIo=nullptr)
std::optional< bool > border_left
std::optional< bool > border_right
std::optional< int > addlevel
std::optional< int > swaplevel
EGATE(wxXmlNode *aGate, IO_BASE *aIo=nullptr)
std::optional< double > distance
std::optional< int > multiple
std::optional< bool > display
std::optional< wxString > altunitdist
EGRID(wxXmlNode *aGrid, IO_BASE *aIo=nullptr)
std::optional< wxString > unit
std::optional< wxString > altunit
std::optional< double > altdistance
std::optional< wxString > unitdist
std::optional< wxString > style
EHOLE(wxXmlNode *aHole, IO_BASE *aIo=nullptr)
std::optional< EROT > rot
std::map< wxString, std::unique_ptr< EATTR > > attributes
std::optional< bool > smashed
EINSTANCE(wxXmlNode *aInstance, IO_BASE *aIo=nullptr)
EJUNCTION(wxXmlNode *aJunction, IO_BASE *aIo=nullptr)
std::optional< EROT > rot
std::optional< int > ratio
std::optional< bool > xref
ELABEL(wxXmlNode *aLabel, IO_BASE *aIo=nullptr)
std::optional< wxString > font
std::optional< wxString > align
std::optional< bool > active
std::optional< bool > visible
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::optional< EURN > urn
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)
std::optional< wxString > moduleVariant
std::optional< int > offset
std::optional< EROT > rotation
std::optional< bool > smashed
std::map< wxString, std::unique_ptr< EPART > > parts
std::optional< wxString > prefix
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)
std::optional< bool > library_locally_modified
std::optional< EDESCRIPTION > description
std::vector< std::unique_ptr< EPACKAGEINSTANCE > > packageinstances
std::optional< int > library_version
EPACKAGE3D(wxXmlNode *aPackage3d, IO_BASE *aIo=nullptr)
EPACKAGEINSTANCE(wxXmlNode *aPackageInstance, IO_BASE *aIo=nullptr)
std::vector< std::unique_ptr< EPOLYGON > > polygons
std::optional< int > library_version
std::vector< std::unique_ptr< EPAD > > thtpads
std::vector< std::unique_ptr< ECIRCLE > > circles
std::vector< std::unique_ptr< ESMD > > smdpads
std::optional< bool > library_locally_modified
std::vector< std::unique_ptr< EDIMENSION > > dimensions
std::optional< EURN > urn
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)
std::optional< bool > locally_modified
EPAD_COMMON(wxXmlNode *aPad, IO_BASE *aIo=nullptr)
std::optional< bool > thermals
std::optional< EROT > rot
std::optional< bool > stop
std::optional< bool > first
std::optional< ECOORD > diameter
std::optional< int > shape
EPAD(wxXmlNode *aPad, IO_BASE *aIo=nullptr)
std::optional< ECOORD > drill
std::optional< wxString > technology
std::optional< wxString > value
std::unique_ptr< ESPICE > spice
std::optional< bool > override_locally_modified
std::map< wxString, std::unique_ptr< EATTR > > attributes
std::optional< EURN > libraryUrn
EPART(wxXmlNode *aPart, IO_BASE *aIo=nullptr)
std::optional< wxString > override_package_urn
std::optional< wxString > override_package3d_urn
std::optional< wxString > package3d_urn
std::map< wxString, std::unique_ptr< EVARIANT > > variants
EPINMAPPING(wxXmlNode *aPinMap, IO_BASE *aIo=nullptr)
std::optional< bool > iddevicewide
std::optional< wxString > spiceprefix
std::vector< std::unique_ptr< EPINMAP > > pinmaps
std::optional< bool > isusermap
EPINMAP(wxXmlNode *aPinMap, IO_BASE *aIo=nullptr)
EPINREF(wxXmlNode *aPinRef, IO_BASE *aIo=nullptr)
std::optional< wxString > length
std::optional< wxString > function
std::optional< wxString > visible
EPIN(wxXmlNode *aPin, IO_BASE *aIo=nullptr)
std::optional< int > swaplevel
std::optional< EROT > rot
std::optional< wxString > direction
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
std::optional< ECOORD > isolate
static const int max_priority
std::vector< std::unique_ptr< EVERTEX > > vertices
bool IsValidOutline() const
Fewer than three vertices cannot bound an area; such polygons (which pre-v6 binary files can carry) w...
EPOLYGON(wxXmlNode *aPolygon, IO_BASE *aIo=nullptr)
std::optional< int > rank
std::optional< ECOORD > spacing
std::optional< bool > thermals
std::optional< bool > orphans
EPORTREF(wxXmlNode *aPortRef, IO_BASE *aIo=nullptr)
std::optional< wxString > direction
EPORT(wxXmlNode *aPort, IO_BASE *aIo=nullptr)
std::optional< int > ratio
std::optional< EROT > rot
std::optional< bool > xref
std::optional< wxString > font
EPROBE(wxXmlNode *aProbe, IO_BASE *aIo=nullptr)
std::optional< EROT > rot
ERECT(wxXmlNode *aRect, IO_BASE *aIo=nullptr)
std::optional< ECOORD > width
std::vector< std::unique_ptr< EATTR > > attributes
ESCHEMATIC_GROUP(wxXmlNode *aSchematicGroup, IO_BASE *aIo=nullptr)
std::optional< ECOORD > titleSize
std::optional< bool > selectable
std::optional< EDESCRIPTION > description
std::optional< wxString > wireStyle
std::optional< int > layer
std::optional< bool > showAnnotations
std::optional< wxString > grouprefs
std::optional< wxString > titleFont
std::optional< wxString > xreflabel
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::optional< wxString > xrefpart
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
std::optional< bool > alwaysvectorfont
std::optional< bool > keepoldvectorfont
std::optional< 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
std::optional< bool > cream
ESMD(wxXmlNode *aSMD, IO_BASE *aIo=nullptr)
std::optional< int > roundness
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::optional< bool > locally_modified
std::optional< bool > library_locally_modified
std::optional< int > library_version
std::vector< std::unique_ptr< EPIN > > pins
std::vector< std::unique_ptr< ECIRCLE > > circles
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)
std::optional< EURN > urn
std::vector< std::unique_ptr< EDIMENSION > > dimensions
std::vector< std::unique_ptr< EATTR > > attributes
ETECHNOLOGY(wxXmlNode *aTechnology, IO_BASE *aIo=nullptr)
std::optional< wxString > font
std::optional< int > distance
ETEXT(wxXmlNode *aText, IO_BASE *aIo=nullptr)
std::optional< EROT > rot
std::optional< int > align
VECTOR2I ConvertSize() const
Calculate text size based on font type and size.
std::optional< double > ratio
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)
std::optional< bool > current
EVARIANT(wxXmlNode *aVariant, IO_BASE *aIo=nullptr)
std::optional< bool > populate
std::optional< wxString > technology
std::optional< wxString > value
EVERTEX(wxXmlNode *aVertex, IO_BASE *aIo=nullptr)
std::optional< double > curve
range is -359.9..359.9
std::optional< wxString > shape
std::optional< bool > alwaysStop
EVIA(wxXmlNode *aVia, IO_BASE *aIo=nullptr)
std::optional< ECOORD > diam
int layer_back_most
< extent
std::optional< wxString > extent
EWIRE(wxXmlNode *aWire, IO_BASE *aIo=nullptr)
std::optional< int > style
std::optional< 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