29 #ifndef _EAGLE_PARSER_H_ 30 #define _EAGLE_PARSER_H_ 34 #include <unordered_map> 36 #include <wx/xml/xml.h> 37 #include <wx/string.h> 38 #include <wx/filename.h> 51 typedef std::unordered_map<wxString, wxXmlNode*>
NODE_MAP;
54 typedef std::map<wxString, std::unique_ptr<EPART>>
EPART_MAP;
57 wxString
escapeName(
const wxString& aNetName );
61 auto it = aMap.find( aName );
62 return it == aMap.end() ? nullptr : it->second->GetChildren();
79 std::runtime_error(
"XML parser failed - " + aMessage.ToStdString() )
91 TRIPLET(
const char* aElement,
const char* aAttribute =
"",
const char* aValue =
"" ) :
114 std::vector<TRIPLET>
p;
117 void push(
const char* aPathSegment,
const char* aAttribute=
"" )
119 p.emplace_back( aPathSegment, aAttribute );
129 p.back().value = aValue;
135 p.back().attribute = aAttribute;
141 typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
145 for( CITER_TRIPLET it =
p.begin(); it !=
p.end(); ++it )
147 if( it !=
p.begin() )
152 if( it->attribute[0] && it->value[0] )
155 ret += it->attribute;
189 template <
typename T>
226 template<
typename V = T>
235 operator bool()
const 283 void Set(
const wxString& aString )
285 m_data = Convert<T>( aString );
363 wxPoint
ConvertArcCenter(
const wxPoint& aStart,
const wxPoint& aEnd,
double aAngle );
413 return value / 25400;
428 return value / 1000000.0;
460 ENET(
int aNetCode,
const wxString& aNetName ) :
519 EWIRE( wxXmlNode* aWire );
544 ELABEL( wxXmlNode* aLabel,
const wxString& aNetName );
559 EVIA( wxXmlNode* aVia );
586 ERECT( wxXmlNode* aRect );
616 EATTR( wxXmlNode* aTree );
666 ETEXT( wxXmlNode* aText );
690 EFRAME( wxXmlNode* aFrameNode );
725 EPAD( wxXmlNode* aPad );
738 ESMD( wxXmlNode* aSMD );
756 EPIN( wxXmlNode* aPin );
807 EHOLE( wxXmlNode* aHole );
837 ELAYER( wxXmlNode* aLayer );
934 EPART( wxXmlNode* aPart );
995 EGATE( wxXmlNode* aGate );
1033 EDEVICE( wxXmlNode* aDevice );
1059 #endif // _EAGLE_PARSER_H_ void Set(const wxString &aString)
Attempt to convert a string to the base type.
wxString Contents()
return the contents of the XPATH as a single string
int To100NanoMeters() const
opt_double curve
range is -359.9..359.9
wxString Convert< wxString >(const wxString &aValue)
OPTIONAL_XML_ATTRIBUTE< T > & operator=(const wxString &aData)
Assign to a string (optionally) containing the data.
ECOORD operator-(const ECOORD &aOther) const
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
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.
void push(const char *aPathSegment, const char *aAttribute="")
Keep track of what we are working on within a PTREE.
static const int max_priority
void Attribute(const char *aAttribute)
modify the last path node's attribute
OPTIONAL_XML_ATTRIBUTE()
Construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.
bool operator==(const ECOORD &aOther) const
Converts a size expressed in a certain unit to nanometers.
std::map< std::string, std::string > variant
OPTIONAL_XML_ATTRIBUTE(T aData)
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
ECOORD operator+(const ECOORD &aOther) const
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
OPTIONAL_XML_ATTRIBUTE< int > opt_int
ELAYER(wxXmlNode *aLayer)
Parse an Eagle frame element.
EDEVICE(wxXmlNode *aDevice)
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
int layer_back_most
< extent
segment (element) of our XPATH into the Eagle XML document tree in PTREE form.
ECONNECT(wxXmlNode *aConnect)
EVERTEX(wxXmlNode *aVertex)
T * operator->()
Return a pointer to the value of the attribute assuming it is available.
EJUNCTION(wxXmlNode *aJunction)
OPTIONAL_XML_ATTRIBUTE< double > opt_double
wxString escapeName(const wxString &aNetName)
OPTIONAL_XML_ATTRIBUTE< bool > opt_bool
EDIMENSION(wxXmlNode *aDimension)
ELABEL(wxXmlNode *aLabel, const wxString &aNetName)
const T * operator->() const
Return a constant pointer to the value of the attribute assuming it is available.
static constexpr EAGLE_UNIT ECOORD_UNIT
EPOLYGON(wxXmlNode *aPolygon)
bool m_isAvailable
A boolean indicating if the data is present or not.
std::map< std::string, std::string > attribute
wxSize ConvertSize() const
Calculate text size based on font type and size.
Model an optional XML attribute.
EDEVICE_SET(wxXmlNode *aDeviceSet)
std::map< wxString, EINSTANCE * > EINSTANCE_MAP
Eagle XML rectangle in binary.
opt_double curve
range is -359.9..359.9
int LAYER_NUM
This can be replaced with int and removed.
Parse an Eagle "attribute" XML element.
bool operator==(const T &aOther) const
opt_wxString dimensionType
EPAD_COMMON(wxXmlNode *aPad)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
Board layer functions and definitions.
std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
Translates Eagle special characters to their counterparts in KiCad.
TRIPLET(const char *aElement, const char *aAttribute="", const char *aValue="")
Structure holding common properties for through-hole and SMD pads.
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
OPTIONAL_XML_ATTRIBUTE(const wxString &aData)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
std::vector< ECONNECT > connects
EFRAME(wxXmlNode *aFrameNode)
ECOORD(int aValue, enum EAGLE_UNIT aUnit)
T Convert(const wxString &aValue)
Convert a wxString to a generic type T.
Eagle polygon, without vertices which are parsed as needed.
ENET(int aNetCode, const wxString &aNetName)
XML_PARSER_ERROR(const wxString &aMessage) noexcept
Build an XML error by just calling its parent class constructor, std::runtime_error,...
ECIRCLE(wxXmlNode *aCircle)
EELEMENT(wxXmlNode *aElement)
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
OPTIONAL_XML_ATTRIBUTE< ECOORD > opt_ecoord
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
long long int value
Unit used for the value field.
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
OPTIONAL_XML_ATTRIBUTE< EROT > opt_erot
EINSTANCE(wxXmlNode *aInstance)
void Value(const char *aValue)
modify the last path node's value