KiCad PCB EDA Suite
eagle_plugin.cpp File Reference
#include <errno.h>
#include <wx/string.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <eagle_plugin.h>
#include <common.h>
#include <macros.h>
#include <fctsys.h>
#include <trigo.h>
#include <kicad_string.h>
#include <properties.h>
#include <wx/filename.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_edge_mod.h>
#include <class_zone.h>
#include <class_pcb_text.h>
#include <class_dimension.h>

Go to the source code of this file.

Classes

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...
 
struct  EROT
 Eagle rotation. More...
 
struct  EWIRE
 Eagle wire. More...
 
struct  EVIA
 Eagle via. More...
 
struct  ECIRCLE
 Eagle circle. More...
 
struct  ERECT
 Eagle XML rectangle in binary. More...
 
struct  EATTR
 Eagle "attribute" XML element, no foolin'. More...
 
struct  EDIMENSION
 Eagle dimension element. More...
 
struct  ETEXT
 Eagle text element. More...
 
struct  EPAD
 Eagle thru hol pad. More...
 
struct  ESMD
 Eagle SMD pad. More...
 
struct  EVERTEX
 
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  ERULES
 subset of eagle.drawing.board.designrules in the XML document More...
 

Typedefs

typedef EAGLE_PLUGIN::BIU BIU
 
typedef PTREE::const_assoc_iterator CA_ITER
 
typedef PTREE::const_iterator CITER
 
typedef std::pair< CA_ITER, CA_ITERCA_ITER_RANGE
 
typedef MODULE_MAP::iterator MODULE_ITER
 
typedef MODULE_MAP::const_iterator MODULE_CITER
 
typedef boost::optional< string > opt_string
 
typedef boost::optional< int > opt_int
 
typedef boost::optional< double > opt_double
 
typedef boost::optional< bool > opt_bool
 
typedef boost::optional< EROTopt_erot
 
typedef std::vector< ZONE_CONTAINER * > ZONES
 non-owning container More...
 

Functions

static opt_bool parseOptionalBool (CPTREE &attribs, const char *aName)
 Function parseOptionalBool returns an opt_bool and sets it true or false according to the presence and value of an attribute within the CPTREE element. More...
 
static EROT erot (const string &aRot)
 parse an Eagle XML "rot" field. More...
 
static opt_erot parseOptionalEROT (CPTREE &attribs)
 Eagle "rot" fields are optional, handle that by returning opt_erot. More...
 
static double parseEagle (const string &aDistance)
 Parse an eagle distance which is either mm, or mils if there is "mil" suffix. More...
 
static string makeKey (const string &aFirst, const string &aSecond)
 Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator. More...
 
static unsigned long timeStamp (CPTREE &aTree)
 Make a unique time stamp. More...
 
wxPoint kicad_arc_center (wxPoint start, wxPoint end, double angle)
 Convert an Eagle curve end to a KiCad center for S_ARC. More...
 

Typedef Documentation

Definition at line 82 of file eagle_plugin.cpp.

typedef PTREE::const_assoc_iterator CA_ITER

Definition at line 83 of file eagle_plugin.cpp.

typedef std::pair<CA_ITER, CA_ITER> CA_ITER_RANGE

Definition at line 85 of file eagle_plugin.cpp.

typedef PTREE::const_iterator CITER

Definition at line 84 of file eagle_plugin.cpp.

typedef MODULE_MAP::const_iterator MODULE_CITER

Definition at line 88 of file eagle_plugin.cpp.

typedef MODULE_MAP::iterator MODULE_ITER

Definition at line 87 of file eagle_plugin.cpp.

typedef boost::optional<bool> opt_bool

Definition at line 93 of file eagle_plugin.cpp.

typedef boost::optional<double> opt_double

Definition at line 92 of file eagle_plugin.cpp.

Definition at line 223 of file eagle_plugin.cpp.

typedef boost::optional<int> opt_int

Definition at line 91 of file eagle_plugin.cpp.

typedef boost::optional<string> opt_string

Definition at line 90 of file eagle_plugin.cpp.

typedef std::vector<ZONE_CONTAINER*> ZONES

non-owning container

Definition at line 2602 of file eagle_plugin.cpp.

Function Documentation

static EROT erot ( const string &  aRot)
static

parse an Eagle XML "rot" field.

Unfortunately the DTD seems not to explain this format very well. [S][M]R<degrees>. Examples: "R90", "MR180", "SR180"

Definition at line 227 of file eagle_plugin.cpp.

References EROT::degrees, EROT::mirror, and EROT::spin.

Referenced by parseOptionalEROT().

228 {
229  EROT rot;
230 
231  rot.spin = aRot.find( 'S' ) != aRot.npos;
232  rot.mirror = aRot.find( 'M' ) != aRot.npos;
233  rot.degrees = strtod( aRot.c_str()
234  + 1 // skip leading 'R'
235  + int( rot.spin ) // skip optional leading 'S'
236  + int( rot.mirror ), // skip optional leading 'M'
237  NULL );
238  return rot;
239 }
Eagle rotation.
bool mirror
double degrees
bool spin
wxPoint kicad_arc_center ( wxPoint  start,
wxPoint  end,
double  angle 
)

Convert an Eagle curve end to a KiCad center for S_ARC.

Definition at line 1120 of file eagle_plugin.cpp.

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

Referenced by EAGLE_PLUGIN::loadPlain(), and EAGLE_PLUGIN::packageWire().

1121 {
1122  // Eagle give us start and end.
1123  // S_ARC wants start to give the center, and end to give the start.
1124  double dx = end.x - start.x, dy = end.y - start.y;
1125  wxPoint mid = (start + end) / 2;
1126 
1127  double dlen = sqrt( dx*dx + dy*dy );
1128  double dist = dlen / ( 2 * tan( DEG2RAD( angle ) / 2 ) );
1129 
1130  wxPoint center(
1131  mid.x + dist * ( dy / dlen ),
1132  mid.y - dist * ( dx / dlen )
1133  );
1134 
1135  return center;
1136 }
static const int dist[10][10]
Definition: dist.cpp:57
double DEG2RAD(double deg)
Definition: trigo.h:191
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static string makeKey ( const string &  aFirst,
const string &  aSecond 
)
inlinestatic

Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator.

Definition at line 1104 of file eagle_plugin.cpp.

Referenced by EAGLE_PLUGIN::loadElements(), EAGLE_PLUGIN::loadLibrary(), and EAGLE_PLUGIN::loadSignals().

1105 {
1106  string key = aFirst + '\x02' + aSecond;
1107  return key;
1108 }
static double parseEagle ( const string &  aDistance)
static

Parse an eagle distance which is either mm, or mils if there is "mil" suffix.

Return is in BIU.

Definition at line 1020 of file eagle_plugin.cpp.

Referenced by ERULES::parse().

1021 {
1022  double ret = strtod( aDistance.c_str(), NULL );
1023  if( aDistance.npos != aDistance.find( "mil" ) )
1024  ret = IU_PER_MILS * ret;
1025  else
1026  ret = IU_PER_MM * ret;
1027 
1028  return ret;
1029 }
static opt_bool parseOptionalBool ( CPTREE attribs,
const char *  aName 
)
static

Function parseOptionalBool returns an opt_bool and sets it true or false according to the presence and value of an attribute within the CPTREE element.

Definition at line 184 of file eagle_plugin.cpp.

Referenced by EELEMENT::EELEMENT(), ELAYER::ELAYER(), EPAD::EPAD(), EPOLYGON::EPOLYGON(), and ESMD::ESMD().

185 {
186  opt_bool ret;
187  opt_string stemp = attribs.get_optional<string>( aName );
188 
189  if( stemp )
190  ret = !stemp->compare( "yes" );
191 
192  return ret;
193 }
static opt_erot parseOptionalEROT ( CPTREE attribs)
static

Eagle "rot" fields are optional, handle that by returning opt_erot.

Definition at line 242 of file eagle_plugin.cpp.

References erot().

Referenced by EATTR::EATTR(), EELEMENT::EELEMENT(), EPAD::EPAD(), ERECT::ERECT(), ESMD::ESMD(), and ETEXT::ETEXT().

243 {
244  opt_erot ret;
245  opt_string stemp = attribs.get_optional<string>( "rot" );
246  if( stemp )
247  ret = erot( *stemp );
248  return ret;
249 }
static EROT erot(const string &aRot)
parse an Eagle XML "rot" field.
static unsigned long timeStamp ( CPTREE aTree)
inlinestatic