29#ifndef _EAGLE_PARSER_H_
30#define _EAGLE_PARSER_H_
34#include <unordered_map>
36#include <wx/xml/xml.h>
38#include <wx/filename.h>
49typedef std::unordered_map<wxString, wxXmlNode*>
NODE_MAP;
51typedef std::map<wxString, std::unique_ptr<EPART>>
EPART_MAP;
54wxString
escapeName(
const wxString& aNetName );
67 auto it = aMap.find( aName );
68 return it == aMap.end() ? nullptr : it->second->GetChildren();
85 std::runtime_error(
"XML parser failed - " + aMessage.ToStdString() )
97 TRIPLET(
const char* aElement,
const char* aAttribute =
"",
const char* aValue =
"" ) :
120 std::vector<TRIPLET>
p;
123 void push(
const char* aPathSegment,
const char* aAttribute=
"" )
125 p.emplace_back( aPathSegment, aAttribute );
135 p.back().value = aValue;
141 p.back().attribute = aAttribute;
147 typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
151 for( CITER_TRIPLET it =
p.begin(); it !=
p.end(); ++it )
153 if( it !=
p.begin() )
158 if( it->attribute[0] && it->value[0] )
161 ret += it->attribute;
232 template<
typename V = T>
241 operator bool()
const
289 void Set(
const wxString& aString )
291 m_data = Convert<T>( aString );
419 return value / 25400;
434 return value / 1000000.0;
466 ENET(
int aNetCode,
const wxString& aNetName ) :
523 EWIRE( wxXmlNode* aWire );
548 ELABEL( wxXmlNode* aLabel,
const wxString& aNetName );
563 EVIA( wxXmlNode* aVia );
590 ERECT( wxXmlNode* aRect );
620 EATTR( wxXmlNode* aTree );
670 ETEXT( wxXmlNode* aText );
694 EFRAME( wxXmlNode* aFrameNode );
729 EPAD( wxXmlNode* aPad );
742 ESMD( wxXmlNode* aSMD );
760 EPIN( wxXmlNode* aPin );
811 EHOLE( wxXmlNode* aHole );
841 ELAYER( wxXmlNode* aLayer );
938 EPART( wxXmlNode* aPart );
999 EGATE( wxXmlNode* aGate );
1037 EDEVICE( wxXmlNode* aDevice );
1069 ECLASS( wxXmlNode* aClass );
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)
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.
Parse an Eagle "attribute" XML element.
std::map< wxString, ECOORD > clearanceMap
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
std::vector< ECONNECT > connects
opt_wxString dimensionType
Parse an Eagle frame element.
ENET(int aNetCode, const wxString &aNetName)
Structure holding common properties for through-hole and SMD pads.
std::map< std::string, std::string > variant
std::map< std::string, std::string > attribute
Eagle polygon, without vertices which are parsed as needed.
static const int max_priority
Eagle XML rectangle in binary.
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,...