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 )
296 m_data = Convert<T>( 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;
1930 std::map<wxString, std::unique_ptr<EPORT>>
ports;
1932 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
1933 std::map<wxString, std::unique_ptr<EPART>>
parts;
1963 std::vector<std::unique_ptr<ENOTE>>
notes;
2056 std::vector<std::unique_ptr<EWIRE>>
wires;
2057 std::vector<std::unique_ptr<ETEXT>>
texts;
2062 std::vector<std::unique_ptr<EHOLE>>
holes;
2135 std::vector<std::unique_ptr<EWIRE>>
wires;
2136 std::vector<std::unique_ptr<ETEXT>>
texts;
2138 std::vector<std::unique_ptr<EPIN>>
pins;
2162 std::map<wxString, std::unique_ptr<EPACKAGE>>
packages;
2164 std::map<wxString, std::unique_ptr<ESYMBOL>>
symbols;
2208 std::map<wxString, std::unique_ptr<ECLASS>>
classes;
2209 std::map<wxString, std::unique_ptr<EMODULE>>
modules;
2210 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
2211 std::map<wxString, std::unique_ptr<EPART>>
parts;
2213 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)
bool m_isAvailable
A boolean indicating if the data is present or not.
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
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.
std::optional< ECOMPATIBILITY > compatibility
wxString version
The Eagle XML file version.
std::unique_ptr< EDRAWING > drawing
Parse an Eagle "attribute" XML element.
std::vector< std::unique_ptr< ESEGMENT > > segments
std::map< wxString, ECOORD > clearanceMap
std::vector< std::unique_ptr< ENOTE > > notes
opt_wxString contactroute
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.
opt_bool library_locally_modified
std::vector< std::unique_ptr< EDEVICE > > devices
opt_bool locally_modified
std::optional< EDESCRIPTION > description
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
std::vector< std::unique_ptr< ETECHNOLOGY > > technologies
opt_wxString dimensionType
std::optional< ESCHEMATIC > schematic
std::optional< ELIBRARY > library
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
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
Parse an Eagle frame element.
std::map< wxString, std::unique_ptr< EATTR > > attributes
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
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
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)
opt_bool library_locally_modified
std::optional< EDESCRIPTION > description
std::vector< std::unique_ptr< EPACKAGEINSTANCE > > packageinstances
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
opt_bool locally_modified
Structure holding common properties for through-hole and SMD pads.
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
opt_wxString package3d_urn
std::map< wxString, std::unique_ptr< EVARIANT > > variants
std::vector< std::unique_ptr< EPINMAP > > pinmaps
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
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
Eagle polygon, without vertices which are parsed as needed.
static const int max_priority
std::vector< std::unique_ptr< EVERTEX > > vertices
Eagle XML rectangle in binary.
std::vector< std::unique_ptr< EATTR > > attributes
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
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
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
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::map< wxString, std::unique_ptr< EMODULEINST > > moduleinsts
std::unique_ptr< EMODEL > model
std::unique_ptr< EPINMAPPING > pinmapping
std::vector< std::unique_ptr< EVERTEX > > vertices
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
opt_bool locally_modified
std::vector< std::unique_ptr< EDIMENSION > > dimensions
std::vector< std::unique_ptr< EATTR > > attributes
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.
opt_double curve
range is -359.9..359.9
int layer_back_most
< extent
opt_double curve
range is -359.9..359.9
segment (element) of our XPATH into the Eagle XML document tree in PTREE form.
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,...