KiCad PCB EDA Suite
eagle_parser.h File Reference
#include <errno.h>
#include <unordered_map>
#include <wx/xml/xml.h>
#include <wx/string.h>
#include <wx/filename.h>
#include <layers_id_colors_and_visibility.h>
#include <convert_to_biu.h>
#include <macros.h>
#include <trigo.h>
#include <kicad_string.h>
#include <common.h>

Go to the source code of this file.

Classes

struct  XML_PARSER_ERROR
 Class XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser. More...
 
struct  TRIPLET
 segment (element) of our XPATH into the Eagle XML document tree in PTREE form. More...
 
class  XPATH
 Class XPATH keeps track of what we are working on within a PTREE. More...
 
class  OPTIONAL_XML_ATTRIBUTE< T >
 Class OPTIONAL_XML_ATTRIBUTE models an optional XML attribute. More...
 
struct  ECOORD
 
struct  ENET
 Eagle net. More...
 
struct  EROT
 Eagle rotation. More...
 
struct  EWIRE
 Eagle wire. More...
 
struct  EJUNCTION
 Eagle Junction. More...
 
struct  ELABEL
 Eagle label. More...
 
struct  EVIA
 Eagle via. More...
 
struct  ECIRCLE
 Eagle circle. More...
 
struct  ERECT
 Eagle XML rectangle in binary. More...
 
struct  EATTR
 Class EATTR parses an Eagle "attribute" XML element. More...
 
struct  EDIMENSION
 Eagle dimension element. More...
 
struct  ETEXT
 Eagle text element. More...
 
struct  EPAD_COMMON
 Structure holding common properties for through-hole and SMD pads. More...
 
struct  EPAD
 Eagle thru hole pad. More...
 
struct  ESMD
 Eagle SMD pad. More...
 
struct  EPIN
 Eagle pin element. More...
 
struct  EVERTEX
 Eagle vertex. More...
 
struct  EPOLYGON
 Eagle polygon, without vertices which are parsed as needed. More...
 
struct  EHOLE
 Eagle hole element. More...
 
struct  EELEMENT
 Eagle element element. More...
 
struct  ELAYER
 
struct  EAGLE_LAYER
 
struct  EPART
 
struct  EINSTANCE
 
struct  EGATE
 
struct  ECONNECT
 
struct  EDEVICE
 
struct  EDEVICE_SET
 

Typedefs

typedef std::unordered_map< wxString, wxXmlNode * > NODE_MAP
 
typedef std::map< wxString, MODULE * > MODULE_MAP
 
typedef std::map< wxString, EINSTANCE * > EINSTANCE_MAP
 
typedef std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
 
typedef OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
 
typedef OPTIONAL_XML_ATTRIBUTE< int > opt_int
 
typedef OPTIONAL_XML_ATTRIBUTE< double > opt_double
 
typedef OPTIONAL_XML_ATTRIBUTE< bool > opt_bool
 
typedef OPTIONAL_XML_ATTRIBUTE< EROTopt_erot
 
typedef OPTIONAL_XML_ATTRIBUTE< ECOORDopt_ecoord
 

Functions

wxString escapeName (const wxString &aNetName)
 

Translates Eagle special characters to their counterparts in KiCad.

More...
 
static wxXmlNode * getChildrenNodes (NODE_MAP &aMap, const wxString &aName)
 
template<typename T >
Convert (const wxString &aValue)
 Function Convert converts a wxString to a generic type T. More...
 
template<>
wxString Convert< wxString > (const wxString &aValue)
 
NODE_MAP MapChildren (wxXmlNode *aCurrentNode)
 Function MapChildren provides an easy access to the children of an XML node via their names. More...
 
timestamp_t EagleTimeStamp (wxXmlNode *aTree)
 

Make a unique time stamp

More...
 
timestamp_t EagleModuleTstamp (const wxString &aName, const wxString &aValue, int aUnit)
 

Computes module timestamp basing on its name, value and unit

More...
 
wxPoint ConvertArcCenter (const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
 

Convert an Eagle curve end to a KiCad center for S_ARC

More...
 

Typedef Documentation

typedef std::map<wxString, EINSTANCE*> EINSTANCE_MAP

Definition at line 52 of file eagle_parser.h.

typedef std::map<wxString, std::unique_ptr<EPART> > EPART_MAP

Definition at line 53 of file eagle_parser.h.

typedef std::map<wxString, MODULE*> MODULE_MAP

Definition at line 51 of file eagle_parser.h.

typedef std::unordered_map<wxString, wxXmlNode*> NODE_MAP

Definition at line 48 of file eagle_parser.h.

Definition at line 383 of file eagle_parser.h.

Definition at line 382 of file eagle_parser.h.

Definition at line 385 of file eagle_parser.h.

Definition at line 384 of file eagle_parser.h.

Definition at line 381 of file eagle_parser.h.

Definition at line 379 of file eagle_parser.h.

Function Documentation

template<typename T >
T Convert ( const wxString &  aValue)

Function Convert converts a wxString to a generic type T.

Parameters
aValueis a wxString containing the value that will be converted to type T.
Exceptions
XML_PARSER_ERROR- an exception is thrown if the parsing fails or if the conversion to type T is unknown.

Definition at line 175 of file eagle_parser.h.

References Convert< wxString >(), and XML_PARSER_ERROR::XML_PARSER_ERROR().

176 {
177  throw XML_PARSER_ERROR( "Conversion failed. Unknown type." );
178 }
Class XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown ...
Definition: eagle_parser.h:70
template<>
wxString Convert< wxString > ( const wxString &  aValue)

Definition at line 127 of file eagle_parser.cpp.

Referenced by Convert().

128 {
129  return aValue;
130 }
wxPoint ConvertArcCenter ( const wxPoint aStart,
const wxPoint aEnd,
double  aAngle 
)

Convert an Eagle curve end to a KiCad center for S_ARC

Definition at line 278 of file eagle_parser.cpp.

References DEG2RAD(), dist, wxPoint::x, and wxPoint::y.

Referenced by EAGLE_PLUGIN::loadPlain(), EAGLE_PLUGIN::loadPolygon(), EAGLE_PLUGIN::loadSignals(), SCH_EAGLE_PLUGIN::loadSymbolWire(), OPTIONAL_XML_ATTRIBUTE< bool >::operator->(), EAGLE_PLUGIN::packagePolygon(), and EAGLE_PLUGIN::packageWire().

279 {
280  // Eagle give us start and end.
281  // S_ARC wants start to give the center, and end to give the start.
282  double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y;
283  wxPoint mid = ( aStart + aEnd ) / 2;
284 
285  double dlen = sqrt( dx*dx + dy*dy );
286  wxASSERT( dlen != 0 );
287  wxASSERT( aAngle != 0 );
288  double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) );
289 
290  wxPoint center(
291  mid.x + dist * ( dy / dlen ),
292  mid.y - dist * ( dx / dlen )
293  );
294 
295  return center;
296 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
double DEG2RAD(double deg)
Definition: trigo.h:199
timestamp_t EagleModuleTstamp ( const wxString &  aName,
const wxString &  aValue,
int  aUnit 
)

Computes module timestamp basing on its name, value and unit

Definition at line 268 of file eagle_parser.cpp.

Referenced by SCH_EAGLE_PLUGIN::loadInstance(), SCH_EAGLE_PLUGIN::loadSchematic(), and OPTIONAL_XML_ATTRIBUTE< bool >::operator->().

269 {
270  std::size_t h1 = std::hash<wxString>{}( aName );
271  std::size_t h2 = std::hash<wxString>{}( aValue );
272  std::size_t h3 = std::hash<int>{}( aUnit );
273 
274  return (timestamp_t)( h1 ^ (h2 << 1) ^ (h3 << 2) );
275 }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
timestamp_t EagleTimeStamp ( wxXmlNode *  aTree)

Make a unique time stamp

Definition at line 261 of file eagle_parser.cpp.

Referenced by EAGLE_PLUGIN::loadPlain(), EAGLE_PLUGIN::loadPolygon(), EAGLE_PLUGIN::loadSignals(), OPTIONAL_XML_ATTRIBUTE< bool >::operator->(), EAGLE_PLUGIN::packageCircle(), EAGLE_PLUGIN::packagePolygon(), EAGLE_PLUGIN::packageRectangle(), and EAGLE_PLUGIN::packageText().

262 {
263  // in this case from a unique tree memory location
264  return (timestamp_t) reinterpret_cast<uintptr_t>( aTree );
265 }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
wxString escapeName ( const wxString &  aNetName)

Translates Eagle special characters to their counterparts in KiCad.

Definition at line 37 of file eagle_parser.cpp.

References OPTIONAL_XML_ATTRIBUTE< T >::m_isAvailable, OPTIONAL_XML_ATTRIBUTE< T >::OPTIONAL_XML_ATTRIBUTE(), and OPTIONAL_XML_ATTRIBUTE< T >::Set().

Referenced by SCH_EAGLE_PLUGIN::loadLabel(), SCH_EAGLE_PLUGIN::loadPlainText(), SCH_EAGLE_PLUGIN::loadSegments(), EAGLE_PLUGIN::loadSignals(), and SCH_EAGLE_PLUGIN::loadSymbol().

38 {
39  wxString ret( aNetName );
40 
41  ret.Replace( "~", "~~" );
42  ret.Replace( "!", "~" );
43 
44  return ret;
45 }
static wxXmlNode* getChildrenNodes ( NODE_MAP aMap,
const wxString &  aName 
)
inlinestatic

Definition at line 58 of file eagle_parser.h.

Referenced by SCH_EAGLE_PLUGIN::countNets(), EDEVICE::EDEVICE(), SCH_EAGLE_PLUGIN::loadLibrary(), SCH_EAGLE_PLUGIN::loadSchematic(), and SCH_EAGLE_PLUGIN::loadSheet().

59 {
60  auto it = aMap.find( aName );
61  return it == aMap.end() ? nullptr : it->second->GetChildren();
62 }
NODE_MAP MapChildren ( wxXmlNode *  aCurrentNode)

Function MapChildren provides an easy access to the children of an XML node via their names.

Parameters
currentNodeis a pointer to a wxXmlNode, whose children will be mapped.
Returns
NODE_MAP - a map linking the name of each children to the children itself (via a wxXmlNode*)

Definition at line 237 of file eagle_parser.cpp.

Referenced by EAGLE_PLUGIN::cacheLib(), SCH_EAGLE_PLUGIN::countNets(), EDEVICE::EDEVICE(), SCH_EAGLE_PLUGIN::Load(), EAGLE_PLUGIN::loadAllSections(), SCH_EAGLE_PLUGIN::loadDrawing(), SCH_EAGLE_PLUGIN::loadLibrary(), EAGLE_PLUGIN::loadLibrary(), SCH_EAGLE_PLUGIN::loadSchematic(), SCH_EAGLE_PLUGIN::loadSegments(), SCH_EAGLE_PLUGIN::loadSheet(), and OPTIONAL_XML_ATTRIBUTE< bool >::operator->().

238 {
239  // Map node_name -> node_pointer
240  NODE_MAP nodesMap;
241 
242  // Loop through all children mapping them in nodesMap
243  if( aCurrentNode )
244  aCurrentNode = aCurrentNode->GetChildren();
245 
246  while( aCurrentNode )
247  {
248  // Create a new pair in the map
249  // key: current node name
250  // value: current node pointer
251  nodesMap[aCurrentNode->GetName()] = aCurrentNode;
252 
253  // Get next child
254  aCurrentNode = aCurrentNode->GetNext();
255  }
256 
257  return nodesMap;
258 }
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48