KiCad PCB EDA Suite
eagle_parser.h File Reference
#include <map>
#include <memory>
#include <unordered_map>
#include <wx/xml/xml.h>
#include <wx/string.h>
#include <wx/filename.h>
#include <layer_ids.h>
#include <trigo.h>
#include <core/wx_stl_compat.h>

Go to the source code of this file.


 Implement 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
 Keep track of what we are working on within a PTREE. More...
 Model an optional XML attribute. More...
struct  ECOORD
struct  ENET
 Eagle net. More...
struct  EROT
 Eagle rotation. More...
struct  EWIRE
 Eagle wire. More...
 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
 Parse an Eagle "attribute" XML element. More...
 Eagle dimension element. More...
struct  ETEXT
 Eagle text element. More...
struct  EFRAME
 Parse an Eagle frame element. More...
 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  EPART
struct  EGATE
struct  ECONNECT
struct  EDEVICE
struct  ECLASS


typedef std::unordered_map< wxString, wxXmlNode * > NODE_MAP
typedef std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
typedef std::map< wxString, EINSTANCE * > EINSTANCE_MAP
typedef std::map< wxString, std::unique_ptr< EPART > > EPART_MAP
 Translates Eagle special characters to their counterparts in KiCad. More...
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


wxString escapeName (const wxString &aNetName)
static wxXmlNode * getChildrenNodes (NODE_MAP &aMap, const wxString &aName)
template<typename T >
Convert (const wxString &aValue)
 Convert a wxString to a generic type T. More...
wxString Convert< wxString > (const wxString &aValue)
NODE_MAP MapChildren (wxXmlNode *aCurrentNode)
 Provide an easy access to the children of an XML node via their names. More...
wxPoint ConvertArcCenter (const wxPoint &aStart, const wxPoint &aEnd, double aAngle)

Typedef Documentation


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

Definition at line 51 of file eagle_parser.h.


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

Translates Eagle special characters to their counterparts in KiCad.

Definition at line 52 of file eagle_parser.h.


typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP

Definition at line 50 of file eagle_parser.h.


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

Definition at line 47 of file eagle_parser.h.

◆ opt_bool

Definition at line 369 of file eagle_parser.h.

◆ opt_double

Definition at line 368 of file eagle_parser.h.

◆ opt_ecoord

Definition at line 371 of file eagle_parser.h.

◆ opt_erot

Definition at line 370 of file eagle_parser.h.

◆ opt_int

Definition at line 367 of file eagle_parser.h.

◆ opt_wxString

Definition at line 365 of file eagle_parser.h.

Function Documentation

◆ Convert()

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

Convert a wxString to a generic type T.

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

Definition at line 173 of file eagle_parser.h.

174 {
175  throw XML_PARSER_ERROR( "Conversion failed. Unknown type." );
176 }
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
Definition: eagle_parser.h:68

◆ Convert< wxString >()

wxString Convert< wxString > ( const wxString &  aValue)

Definition at line 136 of file eagle_parser.cpp.

137 {
138  return aValue;
139 }

◆ ConvertArcCenter()

wxPoint ConvertArcCenter ( const wxPoint &  aStart,
const wxPoint &  aEnd,
double  aAngle 

Definition at line 270 of file eagle_parser.cpp.

271 {
272  // Eagle give us start and end.
273  // S_ARC wants start to give the center, and end to give the start.
274  double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y;
275  wxPoint mid = ( aStart + aEnd ) / 2;
277  double dlen = sqrt( dx*dx + dy*dy );
279  if( !std::isnormal( dlen ) || !std::isnormal( aAngle ) )
280  {
281  THROW_IO_ERROR( wxString::Format( _( "Invalid Arc with radius %f and angle %f" ),
282  dlen,
283  aAngle ) );
284  }
286  double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) );
288  wxPoint center(
289  mid.x + dist * ( dy / dlen ),
290  mid.y - dist * ( dx / dlen )
291  );
293  return center;
294 }
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
double DEG2RAD(double deg)
Definition: trigo.h:229
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, DEG2RAD(), 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().

◆ escapeName()

wxString escapeName ( const wxString &  aNetName)

Definition at line 40 of file eagle_parser.cpp.

41 {
42  wxString ret( aNetName );
44  ret.Replace( wxT( "!" ), wxT( "~" ) );
46  return ConvertToNewOverbarNotation( ret );
47 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.

References ConvertToNewOverbarNotation().

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 

Definition at line 57 of file eagle_parser.h.

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

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)

Provide an easy access to the children of an XML node via their names.

currentNodeis a pointer to a wxXmlNode, whose children will be mapped.
NODE_MAP is a map linking the name of each children to the children itself (via a wxXmlNode*)Convert an Eagle curve end to a KiCad center for S_ARC

Definition at line 246 of file eagle_parser.cpp.

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

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