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

◆ EINSTANCE_MAP

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

Definition at line 52 of file eagle_parser.h.

◆ EPART_MAP

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

Definition at line 53 of file eagle_parser.h.

◆ MODULE_MAP

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

Definition at line 51 of file eagle_parser.h.

◆ NODE_MAP

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

Definition at line 48 of file eagle_parser.h.

◆ opt_bool

Definition at line 383 of file eagle_parser.h.

◆ opt_double

Definition at line 382 of file eagle_parser.h.

◆ opt_ecoord

Definition at line 385 of file eagle_parser.h.

◆ opt_erot

Definition at line 384 of file eagle_parser.h.

◆ opt_int

Definition at line 381 of file eagle_parser.h.

◆ opt_wxString

Definition at line 379 of file eagle_parser.h.

Function Documentation

◆ Convert()

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.

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

◆ Convert< wxString >()

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

Definition at line 129 of file eagle_parser.cpp.

130 {
131  return aValue;
132 }

◆ ConvertArcCenter()

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 280 of file eagle_parser.cpp.

281 {
282  // Eagle give us start and end.
283  // S_ARC wants start to give the center, and end to give the start.
284  double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y;
285  wxPoint mid = ( aStart + aEnd ) / 2;
286 
287  double dlen = sqrt( dx*dx + dy*dy );
288 
289  if( !std::isnormal( dlen ) || !std::isnormal( aAngle ) )
290  {
292  wxString::Format( _( "Invalid Arc with radius %f and angle %f" ), dlen, aAngle ) );
293  }
294 
295  double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) );
296 
297  wxPoint center(
298  mid.x + dist * ( dy / dlen ),
299  mid.y - dist * ( dx / dlen )
300  );
301 
302  return center;
303 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
#define THROW_IO_ERROR(msg)
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
double DEG2RAD(double deg)
Definition: trigo.h:210

References _, DEG2RAD(), dist, Format(), and THROW_IO_ERROR.

Referenced by EAGLE_PLUGIN::loadPlain(), EAGLE_PLUGIN::loadPolygon(), EAGLE_PLUGIN::loadSignals(), SCH_EAGLE_PLUGIN::loadSymbolWire(), EAGLE_PLUGIN::packagePolygon(), and EAGLE_PLUGIN::packageWire().

◆ EagleModuleTstamp()

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

Computes module timestamp basing on its name, value and unit

Definition at line 270 of file eagle_parser.cpp.

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

Referenced by SCH_EAGLE_PLUGIN::loadInstance(), and SCH_EAGLE_PLUGIN::loadSchematic().

◆ EagleTimeStamp()

timestamp_t EagleTimeStamp ( wxXmlNode *  aTree)

Make a unique time stamp

Definition at line 263 of file eagle_parser.cpp.

264 {
265  // in this case from a unique tree memory location
266  return (timestamp_t) reinterpret_cast<uintptr_t>( aTree );
267 }
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53

Referenced by EAGLE_PLUGIN::loadPlain(), EAGLE_PLUGIN::loadPolygon(), EAGLE_PLUGIN::loadSignals(), EAGLE_PLUGIN::packageCircle(), EAGLE_PLUGIN::packagePolygon(), EAGLE_PLUGIN::packageRectangle(), and EAGLE_PLUGIN::packageText().

◆ escapeName()

wxString escapeName ( const wxString &  aNetName)

Translates Eagle special characters to their counterparts in KiCad.

Definition at line 37 of file eagle_parser.cpp.

38 {
39  wxString ret( aNetName );
40 
41  ret.Replace( "~", "~~" );
42  ret.Replace( "!", "~" );
43 
44  return ret;
45 }

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

◆ getChildrenNodes()

static wxXmlNode* getChildrenNodes ( NODE_MAP aMap,
const wxString &  aName 
)
inlinestatic

Definition at line 58 of file eagle_parser.h.

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

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

◆ MapChildren()

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 239 of file eagle_parser.cpp.

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

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(), and SCH_EAGLE_PLUGIN::loadSheet().