KiCad PCB EDA Suite
eagle_parser.h File Reference
#include <cerrno>
#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
 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
 XPATH keeps track of what we are working on within a PTREE. More...
 
class  OPTIONAL_XML_ATTRIBUTE< T >
 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
 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...
 
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 377 of file eagle_parser.h.

◆ opt_double

Definition at line 376 of file eagle_parser.h.

◆ opt_ecoord

Definition at line 379 of file eagle_parser.h.

◆ opt_erot

Definition at line 378 of file eagle_parser.h.

◆ opt_int

Definition at line 375 of file eagle_parser.h.

◆ opt_wxString

Definition at line 373 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 }
XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown by the...
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 263 of file eagle_parser.cpp.

264 {
265  // Eagle give us start and end.
266  // S_ARC wants start to give the center, and end to give the start.
267  double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y;
268  wxPoint mid = ( aStart + aEnd ) / 2;
269 
270  double dlen = sqrt( dx*dx + dy*dy );
271 
272  if( !std::isnormal( dlen ) || !std::isnormal( aAngle ) )
273  {
275  wxString::Format( _( "Invalid Arc with radius %f and angle %f" ), dlen, aAngle ) );
276  }
277 
278  double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) );
279 
280  wxPoint center(
281  mid.x + dist * ( dy / dlen ),
282  mid.y - dist * ( dx / dlen )
283  );
284 
285  return center;
286 }
static const int dist[10][10]
Definition: ar_matrix.cpp:326
#define THROW_IO_ERROR(msg)
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:214
#define _(s)
Definition: 3d_actions.cpp:33

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

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

◆ 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().