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 );
470 return value / 25400;
485 return value / 1000000.0;
526 ENET(
int aNetCode,
const wxString& aNetName ) :
1281 std::map<wxString, std::unique_ptr<EVARIANT>>
variants;
1453 std::map<wxString, std::unique_ptr<EVARIANT>>
variants;
1599 std::map<wxString, std::unique_ptr<EGATE>>
gates;
1711 std::vector<std::unique_ptr<EWIRE>>
wires;
1712 std::vector<std::unique_ptr<ETEXT>>
texts;
1718 std::vector<std::unique_ptr<EHOLE>>
holes;
1829 std::vector<std::unique_ptr<EWIRE>>
wires;
1865 std::vector<std::unique_ptr<ENET>>
nets;
1889 std::map<wxString, std::unique_ptr<EPORT>>
ports;
1891 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
1892 std::map<wxString, std::unique_ptr<EPART>>
parts;
1922 std::vector<std::unique_ptr<ENOTE>>
notes;
2015 std::vector<std::unique_ptr<EWIRE>>
wires;
2016 std::vector<std::unique_ptr<ETEXT>>
texts;
2021 std::vector<std::unique_ptr<EHOLE>>
holes;
2094 std::vector<std::unique_ptr<EWIRE>>
wires;
2095 std::vector<std::unique_ptr<ETEXT>>
texts;
2097 std::vector<std::unique_ptr<EPIN>>
pins;
2121 std::map<wxString, std::unique_ptr<EPACKAGE>>
packages;
2123 std::map<wxString, std::unique_ptr<ESYMBOL>>
symbols;
2161 std::map<wxString, std::unique_ptr<ECLASS>>
classes;
2162 std::map<wxString, std::unique_ptr<EMODULE>>
modules;
2163 std::map<wxString, std::unique_ptr<ESCHEMATIC_GROUP>>
groups;
2164 std::map<wxString, std::unique_ptr<EPART>>
parts;
2166 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< 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)
Interprets special characters in Eagle text and converts them to KiCAD notation.
wxString interpretText(const wxString &aText)
Translates Eagle special text reference to a KiCad variable reference.
bool substituteVariable(wxString *aText)
Converts Eagle's HTML description into KiCad description format.
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)
wxString convertDescription(wxString aDescr)
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Translates Eagle special characters to their counterparts in KiCad.
EAGLE_BASE(IO_BASE *aIo=nullptr)
void AdvanceProgressPhase()
void Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
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
Unit used for the value field.
bool operator==(const ECOORD &aOther) const
Converts a size expressed in a certain unit to nanometers.
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
static constexpr EAGLE_UNIT ECOORD_UNIT
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
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.
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,...