KiCad PCB EDA Suite
eagle_plugin.cpp
Go to the documentation of this file.
1 
2 /*
3  * This program source code file is part of KiCad, a free EDA CAD application.
4  *
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012-2016 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 /*
28 
29 Pcbnew PLUGIN for Eagle 6.x XML *.brd and footprint format.
30 
31 XML parsing and converting:
32 Getting line numbers and byte offsets from the source XML file is not
33 possible using currently available XML libraries within KiCad project:
34 wxXmlDocument and boost::property_tree.
35 
36 property_tree will give line numbers but no byte offsets, and only during
37 document loading. This means that if we have a problem after the document is
38 successfully loaded, there is no way to correlate back to line number and byte
39 offset of the problem. So a different approach is taken, one which relies on the
40 XML elements themselves using an XPATH type of reporting mechanism. The path to
41 the problem is reported in the error messages. This means keeping track of that
42 path as we traverse the XML document for the sole purpose of accurate error
43 reporting.
44 
45 User can load the source XML file into firefox or other xml browser and follow
46 our error message.
47 
48 Load() TODO's
49 
50 *) verify zone fill clearances are correct
51 
52 */
53 
54 #include <errno.h>
55 
56 #include <wx/string.h>
57 #include <boost/property_tree/ptree.hpp>
58 #include <boost/property_tree/xml_parser.hpp>
59 
60 #include <eagle_plugin.h>
61 
62 #include <common.h>
63 #include <macros.h>
64 #include <fctsys.h>
65 #include <trigo.h>
66 #include <macros.h>
67 #include <kicad_string.h>
68 #include <properties.h>
69 #include <wx/filename.h>
70 
71 #include <class_board.h>
72 #include <class_module.h>
73 #include <class_track.h>
74 #include <class_edge_mod.h>
75 #include <class_zone.h>
76 #include <class_pcb_text.h>
77 #include <class_dimension.h>
78 
79 using namespace boost::property_tree;
80 using namespace std;
81 
83 typedef PTREE::const_assoc_iterator CA_ITER;
84 typedef PTREE::const_iterator CITER;
85 typedef std::pair<CA_ITER, CA_ITER> CA_ITER_RANGE;
86 
87 typedef MODULE_MAP::iterator MODULE_ITER;
88 typedef MODULE_MAP::const_iterator MODULE_CITER;
89 
94 
95 
97 struct TRIPLET
98 {
99  const char* element;
100  const char* attribute;
101  const char* value;
102 
103  TRIPLET( const char* aElement, const char* aAttribute = "", const char* aValue = "" ) :
104  element( aElement ),
105  attribute( aAttribute ),
106  value( aValue )
107  {}
108 };
109 
110 
124 class XPATH
125 {
126  std::vector<TRIPLET> p;
127 
128 public:
129  void push( const char* aPathSegment, const char* aAttribute="" )
130  {
131  p.push_back( TRIPLET( aPathSegment, aAttribute ) );
132  }
133 
134  void clear() { p.clear(); }
135 
136  void pop() { p.pop_back(); }
137 
139  void Value( const char* aValue )
140  {
141  p.back().value = aValue;
142  }
143 
145  void Attribute( const char* aAttribute )
146  {
147  p.back().attribute = aAttribute;
148  }
149 
151  string Contents()
152  {
153  typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
154 
155  string ret;
156 
157  for( CITER_TRIPLET it = p.begin(); it != p.end(); ++it )
158  {
159  if( it != p.begin() )
160  ret += '.';
161 
162  ret += it->element;
163 
164  if( it->attribute[0] && it->value[0] )
165  {
166  ret += '[';
167  ret += it->attribute;
168  ret += '=';
169  ret += it->value;
170  ret += ']';
171  }
172  }
173 
174  return ret;
175  }
176 };
177 
178 
184 static opt_bool parseOptionalBool( CPTREE& attribs, const char* aName )
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 }
194 
195 
196 // All of the 'E'STRUCTS below merely hold Eagle XML information verbatim, in binary.
197 // For maintenance and troubleshooting purposes, it was thought that we'd need to
198 // separate the conversion process into distinct steps. There is no intent to have KiCad
199 // forms of information in these 'E'STRUCTS. They are only binary forms
200 // of the Eagle information in the corresponding Eagle XML nodes.
201 
202 
204 struct EROT
205 {
206  bool mirror;
207  bool spin;
208  double degrees;
209 
210  EROT() :
211  mirror( false ),
212  spin( false ),
213  degrees( 0 )
214  {}
215 
216  EROT( double aDegrees ) :
217  mirror( false ),
218  spin( false ),
219  degrees( aDegrees )
220  {}
221 };
222 
224 
227 static EROT erot( const string& aRot )
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 }
240 
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 }
250 
252 struct EWIRE
253 {
254  double x1;
255  double y1;
256  double x2;
257  double y2;
258  double width;
260 
261  // for style: (continuous | longdash | shortdash | dashdot)
262  enum {
267  };
270 
271  // for cap: (flat | round)
272  enum {
275  };
277 
278  EWIRE( CPTREE& aWire );
279 };
280 
288 {
289  CPTREE& attribs = aWire.get_child( "<xmlattr>" );
290 
291  /*
292  <!ELEMENT wire EMPTY>
293  <!ATTLIST wire
294  x1 %Coord; #REQUIRED
295  y1 %Coord; #REQUIRED
296  x2 %Coord; #REQUIRED
297  y2 %Coord; #REQUIRED
298  width %Dimension; #REQUIRED
299  layer %Layer; #REQUIRED
300  extent %Extent; #IMPLIED -- only applicable for airwires --
301  style %WireStyle; "continuous"
302  curve %WireCurve; "0"
303  cap %WireCap; "round" -- only applicable if 'curve' is not zero --
304  >
305  */
306 
307  x1 = attribs.get<double>( "x1" );
308  y1 = attribs.get<double>( "y1" );
309  x2 = attribs.get<double>( "x2" );
310  y2 = attribs.get<double>( "y2" );
311  width = attribs.get<double>( "width" );
312  layer = attribs.get<int>( "layer" );
313 
314  curve = attribs.get_optional<double>( "curve" );
315 
316  opt_string s = attribs.get_optional<string>( "style" );
317  if( s )
318  {
319  if( !s->compare( "continuous" ) )
320  style = EWIRE::CONTINUOUS;
321  else if( !s->compare( "longdash" ) )
322  style = EWIRE::LONGDASH;
323  else if( !s->compare( "shortdash" ) )
324  style = EWIRE::SHORTDASH;
325  else if( !s->compare( "dashdot" ) )
326  style = EWIRE::DASHDOT;
327  }
328 
329  s = attribs.get_optional<string>( "cap" );
330  if( s )
331  {
332  if( !s->compare( "round" ) )
333  cap = EWIRE::ROUND;
334  else if( !s->compare( "flat" ) )
335  cap = EWIRE::FLAT;
336  }
337  // ignoring extent
338 }
339 
340 
342 struct EVIA
343 {
344  double x;
345  double y;
348  double drill;
351  EVIA( CPTREE& aVia );
352 };
353 
355 {
356  CPTREE& attribs = aVia.get_child( "<xmlattr>" );
357 
358  /*
359  <!ELEMENT via EMPTY>
360  <!ATTLIST via
361  x %Coord; #REQUIRED
362  y %Coord; #REQUIRED
363  extent %Extent; #REQUIRED
364  drill %Dimension; #REQUIRED
365  diameter %Dimension; "0"
366  shape %ViaShape; "round"
367  alwaysstop %Bool; "no"
368  >
369  */
370 
371  x = attribs.get<double>( "x" );
372  y = attribs.get<double>( "y" );
373 
374  string ext = attribs.get<string>( "extent" );
375 
376  sscanf( ext.c_str(), "%d-%d", &layer_front_most, &layer_back_most );
377 
378  drill = attribs.get<double>( "drill" );
379  diam = attribs.get_optional<double>( "diameter" );
380  shape = attribs.get_optional<string>( "shape" );
381 }
382 
383 
385 struct ECIRCLE
386 {
387  double x;
388  double y;
389  double radius;
390  double width;
392 
393  ECIRCLE( CPTREE& aCircle );
394 };
395 
397 {
398  CPTREE& attribs = aCircle.get_child( "<xmlattr>" );
399 
400  /*
401  <!ELEMENT circle EMPTY>
402  <!ATTLIST circle
403  x %Coord; #REQUIRED
404  y %Coord; #REQUIRED
405  radius %Coord; #REQUIRED
406  width %Dimension; #REQUIRED
407  layer %Layer; #REQUIRED
408  >
409  */
410 
411  x = attribs.get<double>( "x" );
412  y = attribs.get<double>( "y" );
413  radius = attribs.get<double>( "radius" );
414  width = attribs.get<double>( "width" );
415  layer = attribs.get<int>( "layer" );
416 }
417 
418 
420 struct ERECT
421 {
422  double x1;
423  double y1;
424  double x2;
425  double y2;
426  int layer;
428 
429  ERECT( CPTREE& aRect );
430 };
431 
433 {
434  CPTREE& attribs = aRect.get_child( "<xmlattr>" );
435 
436  /*
437  <!ELEMENT rectangle EMPTY>
438  <!ATTLIST rectangle
439  x1 %Coord; #REQUIRED
440  y1 %Coord; #REQUIRED
441  x2 %Coord; #REQUIRED
442  y2 %Coord; #REQUIRED
443  layer %Layer; #REQUIRED
444  rot %Rotation; "R0"
445  >
446  */
447 
448  x1 = attribs.get<double>( "x1" );
449  y1 = attribs.get<double>( "y1" );
450  x2 = attribs.get<double>( "x2" );
451  y2 = attribs.get<double>( "y2" );
452  layer = attribs.get<int>( "layer" );
453  rot = parseOptionalEROT( attribs );
454 }
455 
456 
458 struct EATTR
459 {
460  string name;
468 
469  enum { // for 'display'
474  };
476 
477  EATTR( CPTREE& aTree );
478  EATTR() {}
479 };
480 
487 EATTR::EATTR( CPTREE& aAttribute )
488 {
489  CPTREE& attribs = aAttribute.get_child( "<xmlattr>" );
490 
491  /*
492  <!ELEMENT attribute EMPTY>
493  <!ATTLIST attribute
494  name %String; #REQUIRED
495  value %String; #IMPLIED
496  x %Coord; #IMPLIED
497  y %Coord; #IMPLIED
498  size %Dimension; #IMPLIED
499  layer %Layer; #IMPLIED
500  font %TextFont; #IMPLIED
501  ratio %Int; #IMPLIED
502  rot %Rotation; "R0"
503  display %AttributeDisplay; "value" -- only in <element> or <instance> context --
504  constant %Bool; "no" -- only in <device> context --
505  >
506  */
507 
508  name = attribs.get<string>( "name" ); // #REQUIRED
509  value = attribs.get_optional<string>( "value" );
510 
511  x = attribs.get_optional<double>( "x" );
512  y = attribs.get_optional<double>( "y" );
513  size = attribs.get_optional<double>( "size" );
514 
515  // KiCad cannot currently put a TEXTE_MODULE on a different layer than the MODULE
516  // Eagle can it seems.
517  layer = attribs.get_optional<int>( "layer" );
518 
519  ratio = attribs.get_optional<double>( "ratio" );
520  rot = parseOptionalEROT( attribs );
521 
522  opt_string stemp = attribs.get_optional<string>( "display" );
523  if( stemp )
524  {
525  // (off | value | name | both)
526  if( !stemp->compare( "off" ) )
527  display = EATTR::Off;
528  else if( !stemp->compare( "value" ) )
529  display = EATTR::VALUE;
530  else if( !stemp->compare( "name" ) )
531  display = EATTR::NAME;
532  else if( !stemp->compare( "both" ) )
533  display = EATTR::BOTH;
534  }
535 }
536 
539 {
540  double x1;
541  double y1;
542  double x2;
543  double y2;
544  double x3;
545  double y3;
546  int layer;
547 
549 
550  EDIMENSION( CPTREE& aDimension );
551 };
552 
554 {
555  CPTREE& attribs = aDimension.get_child( "<xmlattr>" );
556 
557  /*
558  <!ELEMENT dimension EMPTY>
559  <!ATTLIST dimension
560  x1 %Coord; #REQUIRED
561  y1 %Coord; #REQUIRED
562  x2 %Coord; #REQUIRED
563  y2 %Coord; #REQUIRED
564  x3 %Coord; #REQUIRED
565  y3 %Coord; #REQUIRED
566  layer %Layer; #REQUIRED
567  dtype %DimensionType; "parallel"
568  >
569  */
570 
571  x1 = attribs.get<double>( "x1" );
572  y1 = attribs.get<double>( "y1" );
573  x2 = attribs.get<double>( "x2" );
574  y2 = attribs.get<double>( "y2" );
575  x3 = attribs.get<double>( "x3" );
576  y3 = attribs.get<double>( "y3" );
577  layer = attribs.get<int>( "layer" );
578 
579  opt_string dimType = attribs.get_optional<string>( "dtype" );
580 
581  if(!dimType)
582  {
583  // default type is parallel
584  }
585 }
586 
588 struct ETEXT
589 {
590  string text;
591  double x;
592  double y;
593  double size;
594  int layer;
598 
599  enum { // for align
605 
606  // opposites are -1 x above, used by code tricks in here
607  CENTER_RIGHT = -CENTER_LEFT,
608  BOTTOM_CENTER = -TOP_CENTER,
609  BOTTOM_LEFT = -TOP_RIGHT,
610  BOTTOM_RIGHT = -TOP_LEFT,
611  };
612 
614 
615  ETEXT( CPTREE& aText );
616 };
617 
619 {
620  CPTREE& attribs = aText.get_child( "<xmlattr>" );
621 
622  /*
623  <!ELEMENT text (#PCDATA)>
624  <!ATTLIST text
625  x %Coord; #REQUIRED
626  y %Coord; #REQUIRED
627  size %Dimension; #REQUIRED
628  layer %Layer; #REQUIRED
629  font %TextFont; "proportional"
630  ratio %Int; "8"
631  rot %Rotation; "R0"
632  align %Align; "bottom-left"
633  >
634  */
635 
636  text = aText.data();
637  x = attribs.get<double>( "x" );
638  y = attribs.get<double>( "y" );
639  size = attribs.get<double>( "size" );
640  layer = attribs.get<int>( "layer" );
641 
642  font = attribs.get_optional<string>( "font" );
643  ratio = attribs.get_optional<double>( "ratio" );
644  rot = parseOptionalEROT( attribs );
645 
646  opt_string stemp = attribs.get_optional<string>( "align" );
647  if( stemp )
648  {
649  // (bottom-left | bottom-center | bottom-right | center-left |
650  // center | center-right | top-left | top-center | top-right)
651  if( !stemp->compare( "center" ) )
652  align = ETEXT::CENTER;
653  else if( !stemp->compare( "center-right" ) )
654  align = ETEXT::CENTER_RIGHT;
655  else if( !stemp->compare( "top-left" ) )
656  align = ETEXT::TOP_LEFT;
657  else if( !stemp->compare( "top-center" ) )
658  align = ETEXT::TOP_CENTER;
659  else if( !stemp->compare( "top-right" ) )
660  align = ETEXT::TOP_RIGHT;
661  else if( !stemp->compare( "bottom-left" ) )
662  align = ETEXT::BOTTOM_LEFT;
663  else if( !stemp->compare( "bottom-center" ) )
664  align = ETEXT::BOTTOM_CENTER;
665  else if( !stemp->compare( "bottom-right" ) )
666  align = ETEXT::BOTTOM_RIGHT;
667  else if( !stemp->compare( "center-left" ) )
668  align = ETEXT::CENTER_LEFT;
669  }
670 }
671 
672 
674 struct EPAD
675 {
676  string name;
677  double x;
678  double y;
679  double drill;
681 
682  // for shape: (square | round | octagon | long | offset)
683  enum {
689  };
695 
696  EPAD( CPTREE& aPad );
697 };
698 
700 {
701  CPTREE& attribs = aPad.get_child( "<xmlattr>" );
702 
703  /*
704  <!ELEMENT pad EMPTY>
705  <!ATTLIST pad
706  name %String; #REQUIRED
707  x %Coord; #REQUIRED
708  y %Coord; #REQUIRED
709  drill %Dimension; #REQUIRED
710  diameter %Dimension; "0"
711  shape %PadShape; "round"
712  rot %Rotation; "R0"
713  stop %Bool; "yes"
714  thermals %Bool; "yes"
715  first %Bool; "no"
716  >
717  */
718 
719  // #REQUIRED says DTD, throw exception if not found
720  name = attribs.get<string>( "name" );
721  x = attribs.get<double>( "x" );
722  y = attribs.get<double>( "y" );
723  drill = attribs.get<double>( "drill" );
724 
725  diameter = attribs.get_optional<double>( "diameter" );
726 
727  opt_string s = attribs.get_optional<string>( "shape" );
728  if( s )
729  {
730  // (square | round | octagon | long | offset)
731  if( !s->compare( "square" ) )
732  shape = EPAD::SQUARE;
733  else if( !s->compare( "round" ) )
734  shape = EPAD::ROUND;
735  else if( !s->compare( "octagon" ) )
736  shape = EPAD::OCTAGON;
737  else if( !s->compare( "long" ) )
738  shape = EPAD::LONG;
739  else if( !s->compare( "offset" ) )
740  shape = EPAD::OFFSET;
741  }
742 
743  rot = parseOptionalEROT( attribs );
744  stop = parseOptionalBool( attribs, "stop" );
745  thermals = parseOptionalBool( attribs, "thermals" );
746  first = parseOptionalBool( attribs, "first" );
747 }
748 
749 
751 struct ESMD
752 {
753  string name;
754  double x;
755  double y;
756  double dx;
757  double dy;
758  int layer;
764 
765  ESMD( CPTREE& aSMD );
766 };
767 
769 {
770  CPTREE& attribs = aSMD.get_child( "<xmlattr>" );
771 
772  /*
773  <!ATTLIST smd
774  name %String; #REQUIRED
775  x %Coord; #REQUIRED
776  y %Coord; #REQUIRED
777  dx %Dimension; #REQUIRED
778  dy %Dimension; #REQUIRED
779  layer %Layer; #REQUIRED
780  roundness %Int; "0"
781  rot %Rotation; "R0"
782  stop %Bool; "yes"
783  thermals %Bool; "yes"
784  cream %Bool; "yes"
785  >
786  */
787 
788  // DTD #REQUIRED, throw exception if not found
789  name = attribs.get<string>( "name" );
790  x = attribs.get<double>( "x" );
791  y = attribs.get<double>( "y" );
792  dx = attribs.get<double>( "dx" );
793  dy = attribs.get<double>( "dy" );
794  layer = attribs.get<int>( "layer" );
795  rot = parseOptionalEROT( attribs );
796 
797  roundness = attribs.get_optional<int>( "roundness" );
798  thermals = parseOptionalBool( attribs, "thermals" );
799  stop = parseOptionalBool( attribs, "stop" );
800  thermals = parseOptionalBool( attribs, "thermals" );
801  cream = parseOptionalBool( attribs, "cream" );
802 }
803 
804 
805 struct EVERTEX
806 {
807  double x;
808  double y;
809 
810  EVERTEX( CPTREE& aVertex );
811 };
812 
814 {
815  CPTREE& attribs = aVertex.get_child( "<xmlattr>" );
816 
817  /*
818  <!ELEMENT vertex EMPTY>
819  <!ATTLIST vertex
820  x %Coord; #REQUIRED
821  y %Coord; #REQUIRED
822  curve %WireCurve; "0" -- the curvature from this vertex to the next one --
823  >
824  */
825 
826  x = attribs.get<double>( "x" );
827  y = attribs.get<double>( "y" );
828 }
829 
830 
832 struct EPOLYGON
833 {
834  double width;
835  int layer;
837 
838  // KiCad priority is opposite of Eagle rank, that is:
839  // - Eagle Low rank drawn first
840  // - KiCad high priority drawn first
841  // So since Eagle has an upper limit we define this, used for the cases
842  // where no rank is specified.
843  static const int max_priority = 6;
844 
845  enum { // for pour
849  };
850  int pour;
855 
856  EPOLYGON( CPTREE& aPolygon );
857 };
858 
860 {
861  CPTREE& attribs = aPolygon.get_child( "<xmlattr>" );
862 
863  /*
864  <!ATTLIST polygon
865  width %Dimension; #REQUIRED
866  layer %Layer; #REQUIRED
867  spacing %Dimension; #IMPLIED
868  pour %PolygonPour; "solid"
869  isolate %Dimension; #IMPLIED -- only in <signal> or <package> context --
870  orphans %Bool; "no" -- only in <signal> context --
871  thermals %Bool; "yes" -- only in <signal> context --
872  rank %Int; "0" -- 1..6 in <signal> context, 0 or 7 in <package> context --
873  >
874  */
875 
876  width = attribs.get<double>( "width" );
877  layer = attribs.get<int>( "layer" );
878  spacing = attribs.get_optional<double>( "spacing" );
879  isolate = attribs.get_optional<double>( "isolate" );
880  // default pour to solid fill
881  pour = EPOLYGON::SOLID;
882  opt_string s = attribs.get_optional<string>( "pour" );
883 
884  if( s )
885  {
886  // (solid | hatch | cutout)
887  if( !s->compare( "hatch" ) )
888  pour = EPOLYGON::HATCH;
889  else if( !s->compare( "cutout" ) )
890  pour = EPOLYGON::CUTOUT;
891  }
892 
893  orphans = parseOptionalBool( attribs, "orphans" );
894  thermals = parseOptionalBool( attribs, "thermals" );
895  rank = attribs.get_optional<int>( "rank" );
896 }
897 
899 struct EHOLE
900 {
901  double x;
902  double y;
903  double drill;
904 
905  EHOLE( CPTREE& aHole );
906 };
907 
909 {
910  CPTREE& attribs = aHole.get_child( "<xmlattr>" );
911 
912  /*
913  <!ELEMENT hole EMPTY>
914  <!ATTLIST hole
915  x %Coord; #REQUIRED
916  y %Coord; #REQUIRED
917  drill %Dimension; #REQUIRED
918  >
919  */
920 
921  // #REQUIRED:
922  x = attribs.get<double>( "x" );
923  y = attribs.get<double>( "y" );
924  drill = attribs.get<double>( "drill" );
925 }
926 
927 
929 struct EELEMENT
930 {
931  string name;
932  string library;
933  string package;
934  string value;
935  double x;
936  double y;
940 
941  EELEMENT( CPTREE& aElement );
942 };
943 
945 {
946  CPTREE& attribs = aElement.get_child( "<xmlattr>" );
947 
948  /*
949  <!ELEMENT element (attribute*, variant*)>
950  <!ATTLIST element
951  name %String; #REQUIRED
952  library %String; #REQUIRED
953  package %String; #REQUIRED
954  value %String; #REQUIRED
955  x %Coord; #REQUIRED
956  y %Coord; #REQUIRED
957  locked %Bool; "no"
958  smashed %Bool; "no"
959  rot %Rotation; "R0"
960  >
961  */
962 
963  // #REQUIRED
964  name = attribs.get<string>( "name" );
965  library = attribs.get<string>( "library" );
966  value = attribs.get<string>( "value" );
967 
968  package = attribs.get<string>( "package" );
969  ReplaceIllegalFileNameChars( &package );
970 
971  x = attribs.get<double>( "x" );
972  y = attribs.get<double>( "y" );
973 
974  // optional
975  locked = parseOptionalBool( attribs, "locked" );
976  smashed = parseOptionalBool( attribs, "smashed" );
977  rot = parseOptionalEROT( attribs );
978 }
979 
980 
981 struct ELAYER
982 {
983  int number;
984  string name;
985  int color;
986  int fill;
989 
990  ELAYER( CPTREE& aLayer );
991 };
992 
994 {
995  CPTREE& attribs = aLayer.get_child( "<xmlattr>" );
996 
997  /*
998  <!ELEMENT layer EMPTY>
999  <!ATTLIST layer
1000  number %Layer; #REQUIRED
1001  name %String; #REQUIRED
1002  color %Int; #REQUIRED
1003  fill %Int; #REQUIRED
1004  visible %Bool; "yes"
1005  active %Bool; "yes"
1006  >
1007  */
1008 
1009  number = attribs.get<int>( "number" );
1010  name = attribs.get<string>( "name" );
1011  color = attribs.get<int>( "color" );
1012  fill = 1; // Temporary value.
1013  visible = parseOptionalBool( attribs, "visible" );
1014  active = parseOptionalBool( attribs, "active" );
1015 }
1016 
1017 
1020 static double parseEagle( const string& aDistance )
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 }
1030 
1031 
1033 struct ERULES
1034 {
1036 
1039 
1040  double rvPadTop;
1041  // double rvPadBottom; ///< bottom pad size as percent of drill size
1042 
1043  double rlMinPadTop;
1044  double rlMaxPadTop;
1045 
1046  double rvViaOuter;
1047  double rlMinViaOuter;
1048  double rlMaxViaOuter;
1049  double mdWireWire;
1050 
1051 
1053  psElongationLong ( 100 ),
1054  psElongationOffset ( 0 ),
1055  rvPadTop ( 0.25 ),
1056  // rvPadBottom ( 0.25 ),
1057  rlMinPadTop ( Mils2iu( 10 ) ),
1058  rlMaxPadTop ( Mils2iu( 20 ) ),
1059 
1060  rvViaOuter ( 0.25 ),
1061  rlMinViaOuter ( Mils2iu( 10 ) ),
1062  rlMaxViaOuter ( Mils2iu( 20 ) ),
1063  mdWireWire ( 0 )
1064  {}
1065 
1066  void parse( CPTREE& aRules );
1067 };
1068 
1069 void ERULES::parse( CPTREE& aRules )
1070 {
1071  for( CITER it = aRules.begin(); it != aRules.end(); ++it )
1072  {
1073  if( it->first != "param" )
1074  continue;
1075 
1076  CPTREE& attribs = it->second.get_child( "<xmlattr>" );
1077 
1078  const string& name = attribs.get<string>( "name" );
1079 
1080  if( name == "psElongationLong" )
1081  psElongationLong = attribs.get<int>( "value" );
1082  else if( name == "psElongationOffset" )
1083  psElongationOffset = attribs.get<int>( "value" );
1084  else if( name == "rvPadTop" )
1085  rvPadTop = attribs.get<double>( "value" );
1086  else if( name == "rlMinPadTop" )
1087  rlMinPadTop = parseEagle( attribs.get<string>( "value" ) );
1088  else if( name == "rlMaxPadTop" )
1089  rlMaxPadTop = parseEagle( attribs.get<string>( "value" ) );
1090  else if( name == "rvViaOuter" )
1091  rvViaOuter = attribs.get<double>( "value" );
1092  else if( name == "rlMinViaOuter" )
1093  rlMinViaOuter = parseEagle( attribs.get<string>( "value" ) );
1094  else if( name == "rlMaxViaOuter" )
1095  rlMaxViaOuter = parseEagle( attribs.get<string>( "value" ) );
1096  else if( name == "mdWireWire" )
1097  mdWireWire = parseEagle( attribs.get<string>( "value" ) );
1098  }
1099 }
1100 
1101 
1104 static inline string makeKey( const string& aFirst, const string& aSecond )
1105 {
1106  string key = aFirst + '\x02' + aSecond;
1107  return key;
1108 }
1109 
1110 
1112 static inline unsigned long timeStamp( CPTREE& aTree )
1113 {
1114  // in this case from a unique tree memory location
1115  return (unsigned long)(void*) &aTree;
1116 }
1117 
1118 
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 }
1137 
1138 
1140  m_rules( new ERULES() ),
1141  m_xpath( new XPATH() ),
1142  m_mod_time( wxDateTime::Now() )
1143 {
1144  init( NULL );
1145 
1146  clear_cu_map();
1147 }
1148 
1149 
1151 {
1152  delete m_rules;
1153  delete m_xpath;
1154 }
1155 
1156 
1157 const wxString EAGLE_PLUGIN::PluginName() const
1158 {
1159  return wxT( "Eagle" );
1160 }
1161 
1162 
1163 const wxString EAGLE_PLUGIN::GetFileExtension() const
1164 {
1165  return wxT( "brd" );
1166 }
1167 
1168 
1169 int inline EAGLE_PLUGIN::kicad( double d ) const
1170 {
1171  return KiROUND( biu_per_mm * d );
1172 }
1173 
1174 
1175 wxSize inline EAGLE_PLUGIN::kicad_fontz( double d ) const
1176 {
1177  // texts seem to better match eagle when scaled down by 0.95
1178  int kz = kicad( d ) * 95 / 100;
1179  return wxSize( kz, kz );
1180 }
1181 
1182 
1183 BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
1184 {
1185  LOCALE_IO toggle; // toggles on, then off, the C locale.
1186  PTREE doc;
1187 
1188  init( aProperties );
1189 
1190  m_board = aAppendToMe ? aAppendToMe : new BOARD();
1191 
1192  // Give the filename to the board if it's new
1193  if( !aAppendToMe )
1194  m_board->SetFileName( aFileName );
1195 
1196  // delete on exception, if I own m_board, according to aAppendToMe
1197  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
1198 
1199  try
1200  {
1201  // 8 bit "filename" should be encoded according to disk filename encoding,
1202  // (maybe this is current locale, maybe not, its a filesystem issue),
1203  // and is not necessarily utf8.
1204  string filename = (const char*) aFileName.char_str( wxConvFile );
1205 
1206  read_xml( filename, doc, xml_parser::no_comments );
1207 
1208  m_min_trace = INT_MAX;
1209  m_min_via = INT_MAX;
1210  m_min_via_hole = INT_MAX;
1211 
1212  loadAllSections( doc );
1213 
1214  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
1215 
1216  if( m_min_trace < designSettings.m_TrackMinWidth )
1217  designSettings.m_TrackMinWidth = m_min_trace;
1218 
1219  if( m_min_via < designSettings.m_ViasMinSize )
1220  designSettings.m_ViasMinSize = m_min_via;
1221 
1222  if( m_min_via_hole < designSettings.m_ViasMinDrill )
1223  designSettings.m_ViasMinDrill = m_min_via_hole;
1224 
1225  if( m_rules->mdWireWire )
1226  {
1227  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
1228  int clearance = KiROUND( m_rules->mdWireWire );
1229 
1230  if( clearance < defaultNetclass->GetClearance() )
1231  defaultNetclass->SetClearance( clearance );
1232  }
1233 
1234  // should be empty, else missing m_xpath->pop()
1235  wxASSERT( m_xpath->Contents().size() == 0 );
1236  }
1237 
1238  catch( file_parser_error fpe )
1239  {
1240  // for xml_parser_error, what() has the line number in it,
1241  // but no byte offset. That should be an adequate error message.
1242  THROW_IO_ERROR( fpe.what() );
1243  }
1244 
1245  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
1246  // so one catch should be OK for all errors.
1247  catch( ptree_error pte )
1248  {
1249  string errmsg = pte.what();
1250 
1251  errmsg += " @\n";
1252  errmsg += m_xpath->Contents();
1253 
1254  THROW_IO_ERROR( errmsg );
1255  }
1256 
1257  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
1258 
1259  // Ensure the copper layers count is a multiple of 2
1260  // Pcbnew does not like boards with odd layers count
1261  // (these boards cannot exist. they actually have a even layers count)
1262  int lyrcnt = m_board->GetCopperLayerCount();
1263 
1264  if( (lyrcnt % 2) != 0 )
1265  {
1266  lyrcnt++;
1267  m_board->SetCopperLayerCount( lyrcnt );
1268  }
1269 
1270  centerBoard();
1271 
1272  deleter.release();
1273  return m_board;
1274 }
1275 
1276 
1277 void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
1278 {
1279  m_hole_count = 0;
1280  m_min_trace = 0;
1281  m_min_via = 0;
1282  m_min_via_hole = 0;
1283  m_xpath->clear();
1284  m_pads_to_nets.clear();
1285 
1286  // m_templates.clear(); this is the FOOTPRINT cache too
1287 
1288  m_board = NULL;
1289  m_props = aProperties;
1290 
1291  mm_per_biu = 1/IU_PER_MM;
1292  biu_per_mm = IU_PER_MM;
1293 
1294  delete m_rules;
1295  m_rules = new ERULES();
1296 }
1297 
1298 
1300 {
1301  // All cu layers are invalid until we see them in the <layers> section while
1302  // loading either a board or library. See loadLayerDefs().
1303  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
1304  m_cu_map[i] = -1;
1305 }
1306 
1307 
1309 {
1310  CPTREE& drawing = aDoc.get_child( "eagle.drawing" );
1311  CPTREE& board = drawing.get_child( "board" );
1312 
1313  m_xpath->push( "eagle.drawing" );
1314 
1315  {
1316  m_xpath->push( "board" );
1317 
1318  CPTREE& designrules = board.get_child( "designrules" );
1319  loadDesignRules( designrules );
1320 
1321  m_xpath->pop();
1322  }
1323 
1324  {
1325  m_xpath->push( "layers" );
1326 
1327  CPTREE& layers = drawing.get_child( "layers" );
1328  loadLayerDefs( layers );
1329 
1330  m_xpath->pop();
1331  }
1332 
1333  {
1334  m_xpath->push( "board" );
1335 
1336  CPTREE& plain = board.get_child( "plain" );
1337  loadPlain( plain );
1338 
1339  CPTREE& signals = board.get_child( "signals" );
1340  loadSignals( signals );
1341 
1342  CPTREE& libs = board.get_child( "libraries" );
1343  loadLibraries( libs );
1344 
1345  CPTREE& elems = board.get_child( "elements" );
1346  loadElements( elems );
1347 
1348  m_xpath->pop(); // "board"
1349  }
1350 
1351  m_xpath->pop(); // "eagle.drawing"
1352 }
1353 
1354 
1356 {
1357  m_xpath->push( "designrules" );
1358  m_rules->parse( aDesignRules );
1359  m_xpath->pop(); // "designrules"
1360 }
1361 
1362 
1364 {
1365  typedef std::vector<ELAYER> ELAYERS;
1366  typedef ELAYERS::const_iterator EITER;
1367 
1368  ELAYERS cu; // copper layers
1369 
1370  // find the subset of layers that are copper, and active
1371  for( CITER layer = aLayers.begin(); layer != aLayers.end(); ++layer )
1372  {
1373  ELAYER elayer( layer->second );
1374 
1375  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
1376  {
1377  cu.push_back( elayer );
1378  }
1379  }
1380 
1381  // establish cu layer map:
1382  int ki_layer_count = 0;
1383 
1384  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
1385  {
1386  if( ki_layer_count == 0 )
1387  m_cu_map[it->number] = F_Cu;
1388  else if( ki_layer_count == int( cu.size()-1 ) )
1389  m_cu_map[it->number] = B_Cu;
1390  else
1391  {
1392  // some eagle boards do not have contiguous layer number sequences.
1393 
1394 #if 0 // pre PCB_LAYER_ID & LSET:
1395  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
1396 #else
1397  m_cu_map[it->number] = ki_layer_count;
1398 #endif
1399  }
1400  }
1401 
1402 #if 0 && defined(DEBUG)
1403  printf( "m_cu_map:\n" );
1404  for( unsigned i=0; i<DIM(m_cu_map); ++i )
1405  {
1406  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
1407  }
1408 #endif
1409 
1410  // Set the layer names and cu count iff we're loading a board.
1411  if( m_board )
1412  {
1413  m_board->SetCopperLayerCount( cu.size() );
1414 
1415  for( EITER it = cu.begin(); it != cu.end(); ++it )
1416  {
1417  PCB_LAYER_ID layer = kicad_layer( it->number );
1418 
1419  // these function provide their own protection against UNDEFINED_LAYER:
1420  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
1421  m_board->SetLayerType( layer, LT_SIGNAL );
1422 
1423  // could map the colors here
1424  }
1425  }
1426 }
1427 
1428 
1430 {
1431  m_xpath->push( "plain" );
1432 
1433  // (polygon | wire | text | circle | rectangle | frame | hole)*
1434  for( CITER gr = aGraphics.begin(); gr != aGraphics.end(); ++gr )
1435  {
1436  if( gr->first == "wire" )
1437  {
1438  m_xpath->push( "wire" );
1439 
1440  EWIRE w( gr->second );
1441  PCB_LAYER_ID layer = kicad_layer( w.layer );
1442 
1443  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1444  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1445 
1446  if( layer != UNDEFINED_LAYER )
1447  {
1448  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1449  m_board->Add( dseg, ADD_APPEND );
1450 
1451  if( !w.curve )
1452  {
1453  dseg->SetStart( start );
1454  dseg->SetEnd( end );
1455  }
1456  else
1457  {
1458  wxPoint center = kicad_arc_center( start, end, *w.curve);
1459 
1460  dseg->SetShape( S_ARC );
1461  dseg->SetStart( center );
1462  dseg->SetEnd( start );
1463  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1464  }
1465 
1466  dseg->SetTimeStamp( timeStamp( gr->second ) );
1467  dseg->SetLayer( layer );
1468  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
1469  }
1470  m_xpath->pop();
1471  }
1472  else if( gr->first == "text" )
1473  {
1474  m_xpath->push( "text" );
1475 
1476  ETEXT t( gr->second );
1477  PCB_LAYER_ID layer = kicad_layer( t.layer );
1478 
1479  if( layer != UNDEFINED_LAYER )
1480  {
1481  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
1482  m_board->Add( pcbtxt, ADD_APPEND );
1483 
1484  pcbtxt->SetLayer( layer );
1485  pcbtxt->SetTimeStamp( timeStamp( gr->second ) );
1486  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
1487  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
1488 
1489  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
1490 
1491  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1492 
1493  pcbtxt->SetThickness( kicad( t.size * ratio / 100 ) );
1494 
1495  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
1496 
1497  if( t.rot )
1498  {
1499  int sign = t.rot->mirror ? -1 : 1;
1500  pcbtxt->SetMirrored( t.rot->mirror );
1501 
1502  double degrees = t.rot->degrees;
1503 
1504  if( degrees == 90 || t.rot->spin )
1505  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1506  else if( degrees == 180 )
1507  align = ETEXT::TOP_RIGHT;
1508  else if( degrees == 270 )
1509  {
1510  pcbtxt->SetTextAngle( sign * 90 * 10 );
1511  align = ETEXT::TOP_RIGHT;
1512  }
1513  else // Ok so text is not at 90,180 or 270 so do some funny stuf to get placement right
1514  {
1515  if( ( degrees > 0 ) && ( degrees < 90 ) )
1516  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1517  else if( ( degrees > 90 ) && ( degrees < 180 ) )
1518  {
1519  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
1520  align = ETEXT::TOP_RIGHT;
1521  }
1522  else if( ( degrees > 180 ) && ( degrees < 270 ) )
1523  {
1524  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
1525  align = ETEXT::TOP_RIGHT;
1526  }
1527  else if( ( degrees > 270 ) && ( degrees < 360 ) )
1528  {
1529  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1530  align = ETEXT::BOTTOM_LEFT;
1531  }
1532  }
1533  }
1534 
1535  switch( align )
1536  {
1537  case ETEXT::CENTER:
1538  // this was the default in pcbtxt's constructor
1539  break;
1540 
1541  case ETEXT::CENTER_LEFT:
1543  break;
1544 
1545  case ETEXT::CENTER_RIGHT:
1547  break;
1548 
1549  case ETEXT::TOP_CENTER:
1551  break;
1552 
1553  case ETEXT::TOP_LEFT:
1556  break;
1557 
1558  case ETEXT::TOP_RIGHT:
1561  break;
1562 
1563  case ETEXT::BOTTOM_CENTER:
1565  break;
1566 
1567  case ETEXT::BOTTOM_LEFT:
1570  break;
1571 
1572  case ETEXT::BOTTOM_RIGHT:
1575  break;
1576  }
1577  }
1578  m_xpath->pop();
1579  }
1580  else if( gr->first == "circle" )
1581  {
1582  m_xpath->push( "circle" );
1583 
1584  ECIRCLE c( gr->second );
1585  PCB_LAYER_ID layer = kicad_layer( c.layer );
1586 
1587  if( layer != UNDEFINED_LAYER ) // unsupported layer
1588  {
1589  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1590  m_board->Add( dseg, ADD_APPEND );
1591 
1592  dseg->SetShape( S_CIRCLE );
1593  dseg->SetTimeStamp( timeStamp( gr->second ) );
1594  dseg->SetLayer( layer );
1595  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
1596  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
1597  dseg->SetWidth( kicad( c.width ) );
1598  }
1599  m_xpath->pop();
1600  }
1601  else if( gr->first == "rectangle" )
1602  {
1603  // This seems to be a simplified rectangular [copper] zone, cannot find any
1604  // net related info on it from the DTD.
1605  m_xpath->push( "rectangle" );
1606 
1607  ERECT r( gr->second );
1608  PCB_LAYER_ID layer = kicad_layer( r.layer );
1609 
1610  if( IsCopperLayer( layer ) )
1611  {
1612  // use a "netcode = 0" type ZONE:
1613  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
1614  m_board->Add( zone, ADD_APPEND );
1615 
1616  zone->SetTimeStamp( timeStamp( gr->second ) );
1617  zone->SetLayer( layer );
1619 
1621 
1622  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1623  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1624  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1625  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1626 
1627  // this is not my fault:
1628  zone->SetHatch( outline_hatch, Mils2iu( zone->GetDefaultHatchPitchMils() ), true );
1629  }
1630 
1631  m_xpath->pop();
1632  }
1633  else if( gr->first == "hole" )
1634  {
1635  m_xpath->push( "hole" );
1636  EHOLE e( gr->second );
1637 
1638  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
1639  // Use m_hole_count to gen up a unique name.
1640 
1641  MODULE* module = new MODULE( m_board );
1642  m_board->Add( module, ADD_APPEND );
1643 
1644  char temp[40];
1645  sprintf( temp, "@HOLE%d", m_hole_count++ );
1646  module->SetReference( FROM_UTF8( temp ) );
1647  module->Reference().SetVisible( false );
1648 
1649  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
1650 
1651  module->SetPosition( pos );
1652 
1653  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1654  D_PAD* pad = new D_PAD( module );
1655  module->Pads().PushBack( pad );
1656 
1657  pad->SetShape( PAD_SHAPE_CIRCLE );
1659 
1660  /* pad's position is already centered on module at relative (0, 0)
1661  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1662 
1663  pad->SetPos0( padpos );
1664  pad->SetPosition( padpos + module->GetPosition() );
1665  */
1666 
1667  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
1668 
1669  pad->SetDrillSize( sz );
1670  pad->SetSize( sz );
1671 
1672  pad->SetLayerSet( LSET::AllCuMask() );
1673  m_xpath->pop();
1674  }
1675  else if( gr->first == "frame" )
1676  {
1677  // picture this
1678  }
1679  else if( gr->first == "polygon" )
1680  {
1681  // could be on a copper layer, could be on another layer.
1682  // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
1683  }
1684  else if( gr->first == "dimension" )
1685  {
1686  EDIMENSION d( gr->second );
1687 
1688  DIMENSION* dimension = new DIMENSION( m_board );
1689  m_board->Add( dimension, ADD_APPEND );
1690 
1691  dimension->SetLayer( kicad_layer( d.layer ) );
1692  // The origin and end are assumed to always be in this order from eagle
1693  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
1694  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
1696 
1697  int width = m_board->GetDesignSettings().m_PcbTextWidth;
1698  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
1699 
1700  if( width > maxThickness )
1701  width = maxThickness;
1702 
1703  dimension->Text().SetThickness( width );
1704  dimension->SetWidth( width );
1705 
1706  // check which axis the dimension runs in
1707  // because the "height" of the dimension is perpendicular to that axis
1708  // Note the check is just if two axes are close enough to each other
1709  // Eagle appears to have some rounding errors
1710  if( fabs( d.x1 - d.x2 ) < 0.05 )
1711  dimension->SetHeight( kicad_x( d.x1 - d.x3 ) );
1712  else
1713  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
1714 
1715  dimension->AdjustDimensionDetails();
1716  }
1717  }
1718  m_xpath->pop();
1719 }
1720 
1721 
1722 void EAGLE_PLUGIN::loadLibrary( CPTREE& aLib, const string* aLibName )
1723 {
1724  m_xpath->push( "packages" );
1725 
1726  // library will have <xmlattr> node, skip that and get the single packages node
1727  CPTREE& packages = aLib.get_child( "packages" );
1728 
1729  // Create a MODULE for all the eagle packages, for use later via a copy constructor
1730  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
1731  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
1732 
1733  for( CITER package = packages.begin(); package != packages.end(); ++package )
1734  {
1735  m_xpath->push( "package", "name" );
1736 
1737  const string& pack_ref = package->second.get<string>( "<xmlattr>.name" );
1738 
1739  string pack_name( pack_ref );
1740 
1741  ReplaceIllegalFileNameChars( &pack_name );
1742 
1743  m_xpath->Value( pack_name.c_str() );
1744 
1745  string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name;
1746 
1747  MODULE* m = makeModule( package->second, pack_name );
1748 
1749  // add the templating MODULE to the MODULE template factory "m_templates"
1750  std::pair<MODULE_ITER, bool> r = m_templates.insert( key, m );
1751 
1752  if( !r.second
1753  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
1754  )
1755  {
1756  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
1757  wxString pkg = FROM_UTF8( pack_name.c_str() );
1758 
1759  wxString emsg = wxString::Format(
1760  _( "<package> name: '%s' duplicated in eagle <library>: '%s'" ),
1761  GetChars( pkg ),
1762  GetChars( lib )
1763  );
1764  THROW_IO_ERROR( emsg );
1765  }
1766 
1767  m_xpath->pop();
1768  }
1769 
1770  m_xpath->pop(); // "packages"
1771 }
1772 
1773 
1775 {
1776  m_xpath->push( "libraries.library", "name" );
1777 
1778  for( CITER library = aLibs.begin(); library != aLibs.end(); ++library )
1779  {
1780  const string& lib_name = library->second.get<string>( "<xmlattr>.name" );
1781 
1782  m_xpath->Value( lib_name.c_str() );
1783 
1784  loadLibrary( library->second, &lib_name );
1785  }
1786 
1787  m_xpath->pop();
1788 }
1789 
1790 
1792 {
1793  m_xpath->push( "elements.element", "name" );
1794 
1795  EATTR name;
1796  EATTR value;
1797  bool refanceNamePresetInPackageLayout;
1798  bool valueNamePresetInPackageLayout;
1799 
1800 
1801 
1802  for( CITER it = aElements.begin(); it != aElements.end(); ++it )
1803  {
1804  if( it->first != "element" )
1805  continue;
1806 
1807  EELEMENT e( it->second );
1808 
1809  // use "NULL-ness" as an indication of presence of the attribute:
1810  EATTR* nameAttr = 0;
1811  EATTR* valueAttr = 0;
1812 
1813  m_xpath->Value( e.name.c_str() );
1814 
1815  string pkg_key = makeKey( e.library, e.package );
1816 
1817  MODULE_CITER mi = m_templates.find( pkg_key );
1818 
1819  if( mi == m_templates.end() )
1820  {
1821  wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
1822  GetChars( FROM_UTF8( e.package.c_str() ) ),
1823  GetChars( FROM_UTF8( e.library.c_str() ) ) );
1824  THROW_IO_ERROR( emsg );
1825  }
1826 
1827  // copy constructor to clone the template
1828  MODULE* m = new MODULE( *mi->second );
1829  m_board->Add( m, ADD_APPEND );
1830 
1831  // update the nets within the pads of the clone
1832  for( D_PAD* pad = m->Pads(); pad; pad = pad->Next() )
1833  {
1834  string pn_key = makeKey( e.name, TO_UTF8( pad->GetPadName() ) );
1835 
1836  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
1837  if( ni != m_pads_to_nets.end() )
1838  {
1839  const ENET* enet = &ni->second;
1840  pad->SetNetCode( enet->netcode );
1841  }
1842  }
1843 
1844  refanceNamePresetInPackageLayout = true;
1845  valueNamePresetInPackageLayout = true;
1846  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1847  // Is >NAME field set in package layout ?
1848  if( m->GetReference().size() == 0 )
1849  {
1850  m->Reference().SetVisible( false ); // No so no show
1851  refanceNamePresetInPackageLayout = false;
1852  }
1853  // Is >VALUE field set in package layout
1854  if( m->GetValue().size() == 0 )
1855  {
1856  m->Value().SetVisible( false ); // No so no show
1857  valueNamePresetInPackageLayout = false;
1858  }
1859  m->SetReference( FROM_UTF8( e.name.c_str() ) );
1860  m->SetValue( FROM_UTF8( e.value.c_str() ) );
1861 
1862  if( !e.smashed )
1863  { // Not smashed so show NAME & VALUE
1864  if( valueNamePresetInPackageLayout )
1865  m->Value().SetVisible( true ); // Only if place holder in package layout
1866  if( refanceNamePresetInPackageLayout )
1867  m->Reference().SetVisible( true ); // Only if place holder in package layout
1868  }
1869  else if( *e.smashed == true )
1870  { // Smasted so set default to no show for NAME and VALUE
1871  m->Value().SetVisible( false );
1872  m->Reference().SetVisible( false );
1873 
1874  // initalize these to default values incase the <attribute> elements are not present.
1875  m_xpath->push( "attribute", "name" );
1876 
1877  // VALUE and NAME can have something like our text "effects" overrides
1878  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
1879  // There can be one for NAME and/or VALUE both. Features present in the
1880  // EATTR override the ones established in the package only if they are
1881  // present here (except for rot, which if not present means angle zero).
1882  // So the logic is a bit different than in packageText() and in plain text.
1883  for( CITER ait = it->second.begin(); ait != it->second.end(); ++ait )
1884  {
1885 
1886  if( ait->first != "attribute" )
1887  continue;
1888 
1889  EATTR a( ait->second );
1890 
1891  if( a.name == "NAME" )
1892  {
1893  name = a;
1894  nameAttr = &name;
1895 
1896  // do we have a display attribute ?
1897  if( a.display )
1898  {
1899  // Yes!
1900  switch( *a.display )
1901  {
1902  case EATTR::VALUE :
1903  nameAttr->name = e.name;
1904  m->SetReference( e.name );
1905  if( refanceNamePresetInPackageLayout )
1906  m->Reference().SetVisible( true );
1907  break;
1908 
1909  case EATTR::NAME :
1910  if( refanceNamePresetInPackageLayout )
1911  {
1912  m->SetReference( "NAME" );
1913  m->Reference().SetVisible( true );
1914  }
1915  break;
1916 
1917  case EATTR::BOTH :
1918  if( refanceNamePresetInPackageLayout )
1919  m->Reference().SetVisible( true );
1920  nameAttr->name = nameAttr->name + " = " + e.name;
1921  m->SetReference( "NAME = " + e.name );
1922  break;
1923 
1924  case EATTR::Off :
1925  m->Reference().SetVisible( false );
1926  break;
1927 
1928  default:
1929  nameAttr->name = e.name;
1930  if( refanceNamePresetInPackageLayout )
1931  m->Reference().SetVisible( true );
1932  }
1933  }
1934  else
1935  // No display, so default is visable, and show value of NAME
1936  m->Reference().SetVisible( true );
1937  }
1938  else if( a.name == "VALUE" )
1939  {
1940  value = a;
1941  valueAttr = &value;
1942 
1943  if( a.display )
1944  {
1945  // Yes!
1946  switch( *a.display )
1947  {
1948  case EATTR::VALUE :
1949  valueAttr->value = e.value;
1950  m->SetValue( e.value );
1951  if( valueNamePresetInPackageLayout )
1952  m->Value().SetVisible( true );
1953  break;
1954 
1955  case EATTR::NAME :
1956  if( valueNamePresetInPackageLayout )
1957  m->Value().SetVisible( true );
1958  m->SetValue( "VALUE" );
1959  break;
1960 
1961  case EATTR::BOTH :
1962  if( valueNamePresetInPackageLayout )
1963  m->Value().SetVisible( true );
1964  valueAttr->value = "VALUE = " + e.value;
1965  m->SetValue( "VALUE = " + e.value );
1966  break;
1967 
1968  case EATTR::Off :
1969  m->Value().SetVisible( false );
1970  break;
1971 
1972  default:
1973  valueAttr->value = e.value;
1974  if( valueNamePresetInPackageLayout )
1975  m->Value().SetVisible( true );
1976  }
1977  }
1978  else
1979  // No display, so default is visible, and show value of NAME
1980  m->Value().SetVisible( true );
1981 
1982  }
1983  }
1984 
1985  m_xpath->pop(); // "attribute"
1986  }
1987 
1988  orientModuleAndText( m, e, nameAttr, valueAttr );
1989  }
1990 
1991  m_xpath->pop(); // "elements.element"
1992 }
1993 
1994 
1996  const EATTR* nameAttr, const EATTR* valueAttr )
1997 {
1998  if( e.rot )
1999  {
2000  if( e.rot->mirror )
2001  {
2002  double orientation = e.rot->degrees + 180.0;
2003  m->SetOrientation( orientation * 10 );
2004  m->Flip( m->GetPosition() );
2005  }
2006  else
2007  m->SetOrientation( e.rot->degrees * 10 );
2008  }
2009 
2010  orientModuleText( m, e, &m->Reference(), nameAttr );
2011  orientModuleText( m, e, &m->Value(), valueAttr );
2012 }
2013 
2014 
2016  TEXTE_MODULE* txt, const EATTR* aAttr )
2017 {
2018  // Smashed part ?
2019  if( aAttr )
2020  { // Yes
2021  const EATTR& a = *aAttr;
2022 
2023  if( a.value )
2024  {
2025  txt->SetText( FROM_UTF8( a.value->c_str() ) );
2026  }
2027 
2028  if( a.x && a.y ) // boost::optional
2029  {
2030  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
2031  txt->SetTextPos( pos );
2032  }
2033 
2034  // Even though size and ratio are both optional, I am not seeing
2035  // a case where ratio is present but size is not.
2036  double ratio = 8;
2037  wxSize fontz = txt->GetTextSize();
2038 
2039  if( a.size )
2040  {
2041  fontz = kicad_fontz( *a.size );
2042  txt->SetTextSize( fontz );
2043 
2044  if( a.ratio )
2045  ratio = *a.ratio;
2046  }
2047 
2048  int lw = int( fontz.y * ratio / 100.0 );
2049  txt->SetThickness( lw );
2050 
2051  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2052 
2053  // The "rot" in a EATTR seems to be assumed to be zero if it is not
2054  // present, and this zero rotation becomes an override to the
2055  // package's text field. If they did not want zero, they specify
2056  // what they want explicitly.
2057  double degrees = a.rot ? a.rot->degrees : 0;
2058  double orient; // relative to parent
2059 
2060  int sign = 1;
2061  bool spin = false;
2062 
2063  if( a.rot )
2064  {
2065  spin = a.rot->spin;
2066  sign = a.rot->mirror ? -1 : 1;
2067  txt->SetMirrored( a.rot->mirror );
2068  }
2069 
2070  if( degrees == 90 || degrees == 0 || spin )
2071  {
2072  orient = degrees - m->GetOrientation() / 10;
2073  txt->SetTextAngle( sign * orient * 10 );
2074  }
2075  else if( degrees == 180 )
2076  {
2077  orient = 0 - m->GetOrientation() / 10;
2078  txt->SetTextAngle( sign * orient * 10 );
2079  align = ETEXT::TOP_RIGHT;
2080  }
2081  else if( degrees == 270 )
2082  {
2083  orient = 90 - m->GetOrientation() / 10;
2084  align = ETEXT::TOP_RIGHT;
2085  txt->SetTextAngle( sign * orient * 10 );
2086  }
2087  else
2088  {
2089  orient = 90 - degrees - m->GetOrientation() / 10;
2090  txt->SetTextAngle( sign * orient * 10 );
2091  }
2092 
2093  switch( align )
2094  {
2095  case ETEXT::TOP_RIGHT:
2098  break;
2099 
2100  case ETEXT::BOTTOM_LEFT:
2103  break;
2104 
2105  default:
2106  ;
2107  }
2108  }
2109  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
2110  {
2111  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
2112 
2113  // @todo there are a few more cases than these to contend with:
2114  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
2115  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
2116  {
2117  // ETEXT::TOP_RIGHT:
2120  }
2121  }
2122 }
2123 
2124 MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) const
2125 {
2126  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
2127 
2128  m->SetFPID( LIB_ID( aPkgName ) );
2129 
2130  opt_string description = aPackage.get_optional<string>( "description" );
2131  if( description )
2132  m->SetDescription( FROM_UTF8( description->c_str() ) );
2133 
2134  for( CITER it = aPackage.begin(); it != aPackage.end(); ++it )
2135  {
2136  CPTREE& t = it->second;
2137 
2138  if( it->first == "wire" )
2139  packageWire( m.get(), t );
2140 
2141  else if( it->first == "pad" )
2142  packagePad( m.get(), t );
2143 
2144  else if( it->first == "text" )
2145  packageText( m.get(), t );
2146 
2147  else if( it->first == "rectangle" )
2148  packageRectangle( m.get(), t );
2149 
2150  else if( it->first == "polygon" )
2151  packagePolygon( m.get(), t );
2152 
2153  else if( it->first == "circle" )
2154  packageCircle( m.get(), t );
2155 
2156  else if( it->first == "hole" )
2157  packageHole( m.get(), t );
2158 
2159  else if( it->first == "smd" )
2160  packageSMD( m.get(), t );
2161  }
2162 
2163  return m.release();
2164 }
2165 
2166 
2167 void EAGLE_PLUGIN::packageWire( MODULE* aModule, CPTREE& aTree ) const
2168 {
2169  EWIRE w( aTree );
2170  PCB_LAYER_ID layer = kicad_layer( w.layer );
2171 
2172  if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
2173  {
2174  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
2175  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
2176  int width = kicad( w.width );
2177 
2178  // FIXME: the cap attribute is ignored because kicad can't create lines
2179  // with flat ends.
2180  EDGE_MODULE* dwg;
2181  if( !w.curve )
2182  {
2183  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
2184 
2185  dwg->SetStart0( start );
2186  dwg->SetEnd0( end );
2187  }
2188  else
2189  {
2190  dwg = new EDGE_MODULE( aModule, S_ARC );
2191  wxPoint center = kicad_arc_center( start, end, *w.curve);
2192 
2193  dwg->SetStart0( center );
2194  dwg->SetEnd0( start );
2195  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
2196  }
2197 
2198  dwg->SetLayer( layer );
2199  dwg->SetWidth( width );
2200 
2201  aModule->GraphicalItems().PushBack( dwg );
2202  }
2203 }
2204 
2205 
2206 void EAGLE_PLUGIN::packagePad( MODULE* aModule, CPTREE& aTree ) const
2207 {
2208  // this is thru hole technology here, no SMDs
2209  EPAD e( aTree );
2210 
2211  D_PAD* pad = new D_PAD( aModule );
2212  aModule->Pads().PushBack( pad );
2213 
2214  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2215 
2216  // pad's "Position" is not relative to the module's,
2217  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2218 
2219  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2220 
2221  pad->SetPos0( padpos );
2222 
2223  RotatePoint( &padpos, aModule->GetOrientation() );
2224 
2225  pad->SetPosition( padpos + aModule->GetPosition() );
2226 
2227  pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
2228 
2229  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
2230 
2231  if( e.shape )
2232  {
2233  switch( *e.shape )
2234  {
2235  case EPAD::ROUND:
2236  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2237  break;
2238 
2239  case EPAD::OCTAGON:
2240  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
2241  // pad->SetShape( PAD_OCTAGON );
2242  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2243  break;
2244 
2245  case EPAD::LONG:
2246  pad->SetShape( PAD_SHAPE_OVAL );
2247  break;
2248 
2249  case EPAD::SQUARE:
2250  pad->SetShape( PAD_SHAPE_RECT );
2251  break;
2252 
2253  case EPAD::OFFSET:
2254  ; // don't know what to do here.
2255  }
2256  }
2257  else
2258  {
2259  // if shape is not present, our default is circle and that matches their default "round"
2260  }
2261 
2262  if( e.diameter )
2263  {
2264  int diameter = kicad( *e.diameter );
2265  pad->SetSize( wxSize( diameter, diameter ) );
2266  }
2267  else
2268  {
2269  double drillz = pad->GetDrillSize().x;
2270  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
2271  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
2272  int diameter = KiROUND( drillz + 2 * annulus );
2273  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
2274  }
2275 
2276  if( pad->GetShape() == PAD_SHAPE_OVAL )
2277  {
2278  // The Eagle "long" pad is wider than it is tall,
2279  // m_elongation is percent elongation
2280  wxSize sz = pad->GetSize();
2281  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
2282  pad->SetSize( sz );
2283  }
2284 
2285  if( e.rot )
2286  {
2287  pad->SetOrientation( e.rot->degrees * 10 );
2288  }
2289 
2290  // @todo: handle stop and thermal
2291 }
2292 
2293 
2294 void EAGLE_PLUGIN::packageText( MODULE* aModule, CPTREE& aTree ) const
2295 {
2296  ETEXT t( aTree );
2297  PCB_LAYER_ID layer = kicad_layer( t.layer );
2298 
2299  if( layer == UNDEFINED_LAYER )
2300  {
2301  layer = Cmts_User;
2302  }
2303 
2304  TEXTE_MODULE* txt;
2305 
2306  if( t.text == ">NAME" || t.text == ">name" )
2307  txt = &aModule->Reference();
2308  else if( t.text == ">VALUE" || t.text == ">value" )
2309  txt = &aModule->Value();
2310  else
2311  {
2312  // FIXME: graphical text items are rotated for some reason.
2313  txt = new TEXTE_MODULE( aModule );
2314  aModule->GraphicalItems().PushBack( txt );
2315  }
2316 
2317  txt->SetTimeStamp( timeStamp( aTree ) );
2318  txt->SetText( FROM_UTF8( t.text.c_str() ) );
2319 
2320  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
2321 
2322  txt->SetTextPos( pos );
2323  txt->SetPos0( pos - aModule->GetPosition() );
2324 
2325  txt->SetLayer( layer );
2326  txt->SetTextSize( kicad_fontz( t.size ) );
2327 
2328  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
2329 
2330  txt->SetThickness( kicad( t.size * ratio / 100 ) );
2331 
2332  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2333 
2334  // An eagle package is never rotated, the DTD does not allow it.
2335  // angle -= aModule->GetOrienation();
2336 
2337  if( t.rot )
2338  {
2339  int sign = t.rot->mirror ? -1 : 1;
2340  txt->SetMirrored( t.rot->mirror );
2341 
2342  double degrees = t.rot->degrees;
2343 
2344  if( degrees == 90 || t.rot->spin )
2345  txt->SetTextAngle( sign * degrees * 10 );
2346  else if( degrees == 180 )
2347  align = ETEXT::TOP_RIGHT;
2348  else if( degrees == 270 )
2349  {
2350  align = ETEXT::TOP_RIGHT;
2351  txt->SetTextAngle( sign * 90 * 10 );
2352  }
2353  }
2354 
2355  switch( align )
2356  {
2357  case ETEXT::CENTER:
2358  // this was the default in pcbtxt's constructor
2359  break;
2360 
2361  case ETEXT::CENTER_LEFT:
2363  break;
2364 
2365  case ETEXT::CENTER_RIGHT:
2367  break;
2368 
2369  case ETEXT::TOP_CENTER:
2371  break;
2372 
2373  case ETEXT::TOP_LEFT:
2376  break;
2377 
2378  case ETEXT::TOP_RIGHT:
2381  break;
2382 
2383  case ETEXT::BOTTOM_CENTER:
2385  break;
2386 
2387  case ETEXT::BOTTOM_LEFT:
2390  break;
2391 
2392  case ETEXT::BOTTOM_RIGHT:
2395  break;
2396  }
2397 }
2398 
2399 
2400 void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, CPTREE& aTree ) const
2401 {
2402  ERECT r( aTree );
2403  PCB_LAYER_ID layer = kicad_layer( r.layer );
2404 
2405  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2406  {
2407  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2408  aModule->GraphicalItems().PushBack( dwg );
2409 
2410  dwg->SetLayer( layer );
2411  dwg->SetWidth( 0 );
2412 
2413  dwg->SetTimeStamp( timeStamp( aTree ) );
2414 
2415  std::vector<wxPoint> pts;
2416 
2417  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
2418  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
2419 
2420  pts.push_back( start );
2421  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
2422  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
2423  pts.push_back( end );
2424 
2425  dwg->SetPolyPoints( pts );
2426 
2427  dwg->SetStart0( start );
2428  dwg->SetEnd0( end );
2429  }
2430 }
2431 
2432 
2433 void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, CPTREE& aTree ) const
2434 {
2435  EPOLYGON p( aTree );
2436  PCB_LAYER_ID layer = kicad_layer( p.layer );
2437 
2438  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2439  {
2440  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2441  aModule->GraphicalItems().PushBack( dwg );
2442 
2443  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
2444 
2445  /*
2446  switch( layer )
2447  {
2448  case Eco1_User: layer = F_SilkS; break;
2449  case Eco2_User: layer = B_SilkS; break;
2450 
2451  // all MODULE templates (created from eagle packages) are on front layer
2452  // until cloned.
2453  case Cmts_User: layer = F_SilkS; break;
2454  }
2455  */
2456 
2457  dwg->SetLayer( layer );
2458 
2459  dwg->SetTimeStamp( timeStamp( aTree ) );
2460 
2461  std::vector<wxPoint> pts;
2462  pts.reserve( aTree.size() );
2463 
2464  for( CITER vi = aTree.begin(); vi != aTree.end(); ++vi )
2465  {
2466  if( vi->first != "vertex" ) // skip <xmlattr> node
2467  continue;
2468 
2469  EVERTEX v( vi->second );
2470 
2471  pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2472  }
2473 
2474  dwg->SetPolyPoints( pts );
2475 
2476  dwg->SetStart0( *pts.begin() );
2477  dwg->SetEnd0( pts.back() );
2478  }
2479 }
2480 
2481 
2482 void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const
2483 {
2484  ECIRCLE e( aTree );
2485  PCB_LAYER_ID layer = kicad_layer( e.layer );
2486  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
2487 
2488  aModule->GraphicalItems().PushBack( gr );
2489 
2490  gr->SetWidth( kicad( e.width ) );
2491 
2492  switch( (int) layer )
2493  {
2494  case UNDEFINED_LAYER: layer = Cmts_User; break;
2495  /*
2496  case Eco1_User: layer = F_SilkS; break;
2497  case Eco2_User: layer = B_SilkS; break;
2498  */
2499  default:
2500  break;
2501  }
2502 
2503  gr->SetLayer( layer );
2504  gr->SetTimeStamp( timeStamp( aTree ) );
2505 
2506  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
2507  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
2508 }
2509 
2510 
2511 void EAGLE_PLUGIN::packageHole( MODULE* aModule, CPTREE& aTree ) const
2512 {
2513  EHOLE e( aTree );
2514 
2515  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
2516  D_PAD* pad = new D_PAD( aModule );
2517  aModule->Pads().PushBack( pad );
2518 
2519  pad->SetShape( PAD_SHAPE_CIRCLE );
2521 
2522  // Mechanical purpose only:
2523  // no offset, no net name, no pad name allowed
2524  // pad->SetOffset( wxPoint( 0, 0 ) );
2525  // pad->SetPadName( wxEmptyString );
2526 
2527  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2528 
2529  pad->SetPos0( padpos );
2530  pad->SetPosition( padpos + aModule->GetPosition() );
2531 
2532  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
2533 
2534  pad->SetDrillSize( sz );
2535  pad->SetSize( sz );
2536 
2537  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
2538 }
2539 
2540 
2541 void EAGLE_PLUGIN::packageSMD( MODULE* aModule, CPTREE& aTree ) const
2542 {
2543  ESMD e( aTree );
2544  PCB_LAYER_ID layer = kicad_layer( e.layer );
2545 
2546  if( !IsCopperLayer( layer ) )
2547  {
2548  return;
2549  }
2550 
2551  D_PAD* pad = new D_PAD( aModule );
2552  aModule->Pads().PushBack( pad );
2553 
2554  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2555  pad->SetShape( PAD_SHAPE_RECT );
2556  pad->SetAttribute( PAD_ATTRIB_SMD );
2557 
2558  // pad's "Position" is not relative to the module's,
2559  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2560 
2561  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2562 
2563  pad->SetPos0( padpos );
2564 
2565  RotatePoint( &padpos, aModule->GetOrientation() );
2566 
2567  pad->SetPosition( padpos + aModule->GetPosition() );
2568 
2569  pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
2570 
2571  pad->SetLayer( layer );
2572 
2573  static const LSET front( 3, F_Cu, F_Paste, F_Mask );
2574  static const LSET back( 3, B_Cu, B_Paste, B_Mask );
2575 
2576  if( layer == F_Cu )
2577  pad->SetLayerSet( front );
2578  else if( layer == B_Cu )
2579  pad->SetLayerSet( back );
2580 
2581  // Optional according to DTD
2582  if( e.roundness ) // set set shape to PAD_SHAPE_RECT above, in case roundness is not present
2583  {
2584  if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
2585  {
2586  if( e.dy == e.dx )
2587  pad->SetShape( PAD_SHAPE_CIRCLE );
2588  else
2589  pad->SetShape( PAD_SHAPE_OVAL );
2590  }
2591  }
2592 
2593  if( e.rot )
2594  {
2595  pad->SetOrientation( e.rot->degrees * 10 );
2596  }
2597 
2598  // don't know what stop, thermals, and cream should look like now.
2599 }
2600 
2602 typedef std::vector<ZONE_CONTAINER*> ZONES;
2603 
2604 
2606 {
2607  ZONES zones; // per net
2608 
2609  m_xpath->push( "signals.signal", "name" );
2610 
2611  int netCode = 1;
2612 
2613  for( CITER net = aSignals.begin(); net != aSignals.end(); ++net )
2614  {
2615  bool sawPad = false;
2616 
2617  zones.clear();
2618 
2619  const string& nname = net->second.get<string>( "<xmlattr>.name" );
2620  wxString netName = FROM_UTF8( nname.c_str() );
2621  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
2622 
2623  m_xpath->Value( nname.c_str() );
2624 
2625  // (contactref | polygon | wire | via)*
2626  for( CITER it = net->second.begin(); it != net->second.end(); ++it )
2627  {
2628  if( it->first == "wire" )
2629  {
2630  m_xpath->push( "wire" );
2631  EWIRE w( it->second );
2632  PCB_LAYER_ID layer = kicad_layer( w.layer );
2633 
2634  if( IsCopperLayer( layer ) )
2635  {
2636  TRACK* t = new TRACK( m_board );
2637 
2638  t->SetTimeStamp( timeStamp( it->second ) );
2639 
2640  t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
2641  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2642 
2643  int width = kicad( w.width );
2644  if( width < m_min_trace )
2645  m_min_trace = width;
2646 
2647  t->SetWidth( width );
2648  t->SetLayer( layer );
2649  t->SetNetCode( netCode );
2650 
2651  m_board->m_Track.Insert( t, NULL );
2652  }
2653  else
2654  {
2655  // put non copper wires where the sun don't shine.
2656  }
2657 
2658  m_xpath->pop();
2659  }
2660 
2661  else if( it->first == "via" )
2662  {
2663  m_xpath->push( "via" );
2664  EVIA v( it->second );
2665 
2666  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2667  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2668 
2669  if( IsCopperLayer( layer_front_most ) &&
2670  IsCopperLayer( layer_back_most ) )
2671  {
2672  int kidiam;
2673  int drillz = kicad( v.drill );
2674  VIA* via = new VIA( m_board );
2675  m_board->m_Track.Insert( via, NULL );
2676 
2677  via->SetLayerPair( layer_front_most, layer_back_most );
2678 
2679  if( v.diam )
2680  {
2681  kidiam = kicad( *v.diam );
2682  via->SetWidth( kidiam );
2683  }
2684  else
2685  {
2686  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2687  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
2688  kidiam = KiROUND( drillz + 2 * annulus );
2689  via->SetWidth( kidiam );
2690  }
2691 
2692  via->SetDrill( drillz );
2693 
2694  if( kidiam < m_min_via )
2695  m_min_via = kidiam;
2696 
2697  if( drillz < m_min_via_hole )
2698  m_min_via_hole = drillz;
2699 
2700  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2701  via->SetViaType( VIA_THROUGH );
2702  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2703  via->SetViaType( VIA_MICROVIA );
2704  else
2705  via->SetViaType( VIA_BLIND_BURIED );
2706 
2707  via->SetTimeStamp( timeStamp( it->second ) );
2708 
2709  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2710 
2711  via->SetPosition( pos );
2712  via->SetEnd( pos );
2713 
2714  via->SetNetCode( netCode );
2715  }
2716  m_xpath->pop();
2717  }
2718 
2719  else if( it->first == "contactref" )
2720  {
2721  m_xpath->push( "contactref" );
2722  // <contactref element="RN1" pad="7"/>
2723  CPTREE& attribs = it->second.get_child( "<xmlattr>" );
2724 
2725  const string& reference = attribs.get<string>( "element" );
2726  const string& pad = attribs.get<string>( "pad" );
2727 
2728  string key = makeKey( reference, pad ) ;
2729 
2730  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
2731 
2732  m_pads_to_nets[ key ] = ENET( netCode, nname );
2733 
2734  m_xpath->pop();
2735 
2736  sawPad = true;
2737  }
2738 
2739  else if( it->first == "polygon" )
2740  {
2741  m_xpath->push( "polygon" );
2742 
2743  EPOLYGON p( it->second );
2744  PCB_LAYER_ID layer = kicad_layer( p.layer );
2745 
2746  if( IsCopperLayer( layer ) )
2747  {
2748  // use a "netcode = 0" type ZONE:
2749  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
2750  m_board->Add( zone, ADD_APPEND );
2751  zones.push_back( zone );
2752 
2753  zone->SetTimeStamp( timeStamp( it->second ) );
2754  zone->SetLayer( layer );
2755  zone->SetNetCode( netCode );
2756 
2757  for( CITER vi = it->second.begin(); vi != it->second.end(); ++vi )
2758  {
2759  if( vi->first != "vertex" ) // skip <xmlattr> node
2760  continue;
2761 
2762  EVERTEX v( vi->second );
2763 
2764  // Append the corner
2765  zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2766  }
2767 
2768  // If the pour is a cutout it needs to be set to a keepout
2769  if( p.pour == EPOLYGON::CUTOUT )
2770  {
2771  zone->SetIsKeepout( true );
2772  zone->SetDoNotAllowCopperPour( true );
2774  }
2775 
2776  // if spacing is set the zone should be hatched
2777  if( p.spacing )
2778  zone->SetHatch( ZONE_CONTAINER::DIAGONAL_EDGE, *p.spacing, true );
2779 
2780  // clearances, etc.
2781  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
2782  zone->SetMinThickness( kicad( p.width ) );
2783 
2784  // FIXME: KiCad zones have very rounded corners compared to eagle.
2785  // This means that isolation amounts that work well in eagle
2786  // tend to make copper intrude in soldermask free areas around pads.
2787  if( p.isolate )
2788  {
2789  zone->SetZoneClearance( kicad( *p.isolate ) );
2790  }
2791 
2792  // missing == yes per DTD.
2793  bool thermals = !p.thermals || *p.thermals;
2795  if( thermals )
2796  {
2797  // FIXME: eagle calculates dimensions for thermal spokes
2798  // based on what the zone is connecting to.
2799  // (i.e. width of spoke is half of the smaller side of an smd pad)
2800  // This is a basic workaround
2801  zone->SetThermalReliefGap( kicad( p.width + 0.05 ) );
2802  zone->SetThermalReliefCopperBridge( kicad( p.width + 0.05 ) );
2803  }
2804 
2805  int rank = p.rank ? *p.rank : p.max_priority;
2806  zone->SetPriority( rank );
2807  }
2808 
2809  m_xpath->pop(); // "polygon"
2810  }
2811  }
2812 
2813  if( zones.size() && !sawPad )
2814  {
2815  // KiCad does not support an unconnected zone with its own non-zero netcode,
2816  // but only when assigned netcode = 0 w/o a name...
2817  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2818  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2819 
2820  // therefore omit this signal/net.
2821  }
2822  else
2823  netCode++;
2824  }
2825 
2826  m_xpath->pop(); // "signals.signal"
2827 }
2828 
2829 
2830 PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
2831 {
2832  /* will assume this is a valid mapping for all eagle boards until I get paid more:
2833 
2834  <layers>
2835  <layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
2836  <layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
2837  <layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
2838  <layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
2839  <layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
2840  <layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
2841  <layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
2842  <layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
2843  <layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
2844  <layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
2845  <layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
2846  <layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
2847  <layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
2848  <layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
2849  <layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
2850  <layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
2851  <layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
2852  <layer number="18" name="Vias" color="14" fill="1" visible="yes" active="yes"/>
2853  <layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
2854  <layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
2855  <layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
2856  <layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
2857  <layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
2858  <layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
2859  <layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
2860  <layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
2861  <layer number="27" name="tValues" color="7" fill="1" visible="no" active="yes"/>
2862  <layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
2863  <layer number="29" name="tStop" color="2" fill="3" visible="no" active="yes"/>
2864  <layer number="30" name="bStop" color="5" fill="6" visible="no" active="yes"/>
2865  <layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
2866  <layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
2867  <layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
2868  <layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
2869  <layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
2870  <layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
2871  <layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
2872  <layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
2873  <layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
2874  <layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
2875  <layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
2876  <layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
2877  <layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
2878  <layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
2879  <layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
2880  <layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
2881  <layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
2882  <layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
2883  <layer number="49" name="ReferenceLC" color="13" fill="1" visible="yes" active="yes"/>
2884  <layer number="50" name="ReferenceLS" color="12" fill="1" visible="yes" active="yes"/>
2885  <layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
2886  <layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
2887 
2888  * These layers are used only in eagle schematic.
2889  * They should not be found in board files.
2890  * They are listed for info only.
2891  <layer number="91" name="Nets" color="2" fill="1" visible="no" active="no"/>
2892  <layer number="92" name="Busses" color="1" fill="1" visible="no" active="no"/>
2893  <layer number="93" name="Pins" color="2" fill="1" visible="no" active="no"/>
2894  <layer number="94" name="Symbols" color="4" fill="1" visible="no" active="no"/>
2895  <layer number="95" name="Names" color="7" fill="1" visible="no" active="no"/>
2896  <layer number="96" name="Values" color="7" fill="1" visible="no" active="no"/>
2897  <layer number="97" name="Info" color="7" fill="1" visible="no" active="no"/>
2898  <layer number="98" name="Guide" color="6" fill="1" visible="no" active="no"/>
2899 
2900  * These layers are user layers
2901  <layer number="160" name="???" color="7" fill="1" visible="yes" active="yes"/>
2902  <layer number="161" name="???" color="7" fill="1" visible="yes" active="yes"/>
2903 
2904  </layers>
2905 
2906  */
2907 
2908  int kiLayer;
2909 
2910  // eagle copper layer:
2911  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
2912  {
2913  kiLayer = m_cu_map[aEagleLayer];
2914  }
2915 
2916  else
2917  {
2918  // translate non-copper eagle layer to pcbnew layer
2919  switch( aEagleLayer )
2920  {
2921  case 20: kiLayer = Edge_Cuts; break; // eagle says "Dimension" layer, but it's for board perimeter
2922  case 21: kiLayer = F_SilkS; break;
2923  case 22: kiLayer = B_SilkS; break;
2924  case 25: kiLayer = F_SilkS; break;
2925  case 26: kiLayer = B_SilkS; break;
2926  case 27: kiLayer = F_SilkS; break;
2927  case 28: kiLayer = B_SilkS; break;
2928  case 29: kiLayer = F_Mask; break;
2929  case 30: kiLayer = B_Mask; break;
2930  case 31: kiLayer = F_Paste; break;
2931  case 32: kiLayer = B_Paste; break;
2932  case 33: kiLayer = F_Mask; break;
2933  case 34: kiLayer = B_Mask; break;
2934  case 35: kiLayer = F_Adhes; break;
2935  case 36: kiLayer = B_Adhes; break;
2936  case 48: kiLayer = Cmts_User; break;
2937  case 49: kiLayer = Cmts_User; break;
2938  case 50: kiLayer = Cmts_User; break;
2939 
2940  // Packages show the future chip pins on SMD parts using layer 51.
2941  // This is an area slightly smaller than the PAD/SMD copper area.
2942  // Carry those visual aids into the MODULE on the fabrication layer,
2943  // not silkscreen. This is perhaps not perfect, but there is not a lot
2944  // of other suitable paired layers
2945  case 51: kiLayer = F_Fab; break;
2946  case 52: kiLayer = B_Fab; break;
2947 
2948  // thes layers are defined as user layers. put them on ECO layers
2949  case 160: kiLayer = Eco1_User; break;
2950  case 161: kiLayer = Eco2_User; break;
2951  default:
2952  // some layers do not map to KiCad
2953  // DBG( printf( "unsupported eagle layer: %d\n", aEagleLayer );)
2954  kiLayer = UNDEFINED_LAYER; break;
2955  }
2956  }
2957 
2958  return PCB_LAYER_ID( kiLayer );
2959 }
2960 
2961 
2963 {
2964  if( m_props )
2965  {
2966  UTF8 page_width;
2967  UTF8 page_height;
2968 
2969  if( m_props->Value( "page_width", &page_width ) &&
2970  m_props->Value( "page_height", &page_height ) )
2971  {
2973 
2974  int w = atoi( page_width.c_str() );
2975  int h = atoi( page_height.c_str() );
2976 
2977  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2978  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2979 
2980  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2981  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2982 
2983  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2984  }
2985  }
2986 }
2987 
2988 
2989 wxDateTime EAGLE_PLUGIN::getModificationTime( const wxString& aPath )
2990 {
2991  wxFileName fn( aPath );
2992 
2993  // Do not call wxFileName::GetModificationTime() on a non-existent file, because
2994  // if it fails, wx's implementation calls the crap wxLogSysError() which
2995  // eventually infects our UI with an unwanted popup window, so don't let it fail.
2996  if( !fn.IsFileReadable() )
2997  {
2998  wxString msg = wxString::Format(
2999  _( "File '%s' is not readable." ),
3000  GetChars( aPath ) );
3001 
3002  THROW_IO_ERROR( msg );
3003  }
3004 
3005  /*
3006  // update the writable flag while we have a wxFileName, in a network this
3007  // is possibly quite dynamic anyway.
3008  m_writable = fn.IsFileWritable();
3009  */
3010 
3011  wxDateTime modTime = fn.GetModificationTime();
3012 
3013  if( !modTime.IsValid() )
3014  modTime.Now();
3015 
3016  return modTime;
3017 }
3018 
3019 
3020 void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
3021 {
3022  try
3023  {
3024  wxDateTime modtime = getModificationTime( aLibPath );
3025 
3026  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
3027  // cache if either of the wxDateTime objects are invalid or the last file modification
3028  // time differs from the current file modification time.
3029  bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
3030  m_mod_time != modtime;
3031 
3032  if( aLibPath != m_lib_path || load )
3033  {
3034  PTREE doc;
3035  LOCALE_IO toggle; // toggles on, then off, the C locale.
3036 
3037  m_templates.clear();
3038 
3039  // Set this before completion of loading, since we rely on it for
3040  // text of an exception. Delay setting m_mod_time until after successful load
3041  // however.
3042  m_lib_path = aLibPath;
3043 
3044  // 8 bit "filename" should be encoded according to disk filename encoding,
3045  // (maybe this is current locale, maybe not, its a filesystem issue),
3046  // and is not necessarily utf8.
3047  string filename = (const char*) aLibPath.char_str( wxConvFile );
3048 
3049  read_xml( filename, doc, xml_parser::no_comments );
3050 
3051  // clear the cu map and then rebuild it.
3052  clear_cu_map();
3053 
3054  m_xpath->push( "eagle.drawing.layers" );
3055  CPTREE& layers = doc.get_child( "eagle.drawing.layers" );
3056  loadLayerDefs( layers );
3057  m_xpath->pop();
3058 
3059  m_xpath->push( "eagle.drawing.library" );
3060  CPTREE& library = doc.get_child( "eagle.drawing.library" );
3061  loadLibrary( library, NULL );
3062  m_xpath->pop();
3063 
3064  m_mod_time = modtime;
3065  }
3066  }
3067  catch( file_parser_error fpe )
3068  {
3069  // for xml_parser_error, what() has the line number in it,
3070  // but no byte offset. That should be an adequate error message.
3071  THROW_IO_ERROR( fpe.what() );
3072  }
3073 
3074  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
3075  // so one catch should be OK for all errors.
3076  catch( ptree_error pte )
3077  {
3078  string errmsg = pte.what();
3079 
3080  errmsg += " @\n";
3081  errmsg += m_xpath->Contents();
3082 
3083  THROW_IO_ERROR( errmsg );
3084  }
3085 }
3086 
3087 
3088 wxArrayString EAGLE_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
3089 {
3090  init( aProperties );
3091 
3092  cacheLib( aLibraryPath );
3093 
3094  wxArrayString ret;
3095 
3096  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
3097  ret.Add( FROM_UTF8( it->first.c_str() ) );
3098 
3099  return ret;
3100 }
3101 
3102 
3103 MODULE* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
3104  const PROPERTIES* aProperties )
3105 {
3106  init( aProperties );
3107 
3108  cacheLib( aLibraryPath );
3109 
3110  string key = TO_UTF8( aFootprintName );
3111 
3112  MODULE_CITER mi = m_templates.find( key );
3113 
3114  if( mi == m_templates.end() )
3115  return NULL;
3116 
3117  // copy constructor to clone the template
3118  MODULE* ret = new MODULE( *mi->second );
3119 
3120  return ret;
3121 }
3122 
3123 
3124 void EAGLE_PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
3125 {
3126  PLUGIN::FootprintLibOptions( aListToAppendTo );
3127 
3128  /*
3129  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
3130  "Ignore duplicately named footprints within the same Eagle library. "
3131  "Only the first similarly named footprint will be loaded."
3132  ));
3133  */
3134 }
3135 
3136 
3137 /*
3138 void EAGLE_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
3139 {
3140  // Eagle lovers apply here.
3141 }
3142 
3143 
3144 void EAGLE_PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties )
3145 {
3146 }
3147 
3148 
3149 void EAGLE_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName )
3150 {
3151 }
3152 
3153 
3154 void EAGLE_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
3155 {
3156 }
3157 
3158 
3159 bool EAGLE_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
3160 {
3161 }
3162 
3163 
3164 bool EAGLE_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
3165 {
3166  return true;
3167 }
3168 
3169 */
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
void packageCircle(MODULE *aModule, CPTREE &aTree) const
opt_double diameter
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
Eagle rotation.
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
#define DIM(x)
of elements in an array
Definition: macros.h:98
MODULE_MAP::iterator MODULE_ITER
void SetEnd0(const wxPoint &aPoint)
double width
boost::optional< double > opt_double
ESMD(CPTREE &aSMD)
string package
double rlMaxViaOuter
maximum copper annulus on via
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
bool mirror
opt_double curve
range is -359.9..359.9
MODULE * makeModule(CPTREE &aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
double radius
void SetTextAngle(double aAngle)
double size
TEXTE_MODULE & Reference()
Definition: class_module.h:455
opt_double isolate
void SetShape(STROKE_T aShape)
opt_bool stop
NETCLASSPTR GetDefault() const
Function GetDefault.
opt_int rank
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
ERECT(CPTREE &aRect)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void centerBoard()
move the BOARD into the center of the page
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
TEXTE_PCB class definition.
string name
double y
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:447
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
EELEMENT(CPTREE &aElement)
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
void packagePolygon(MODULE *aModule, CPTREE &aTree) const
string name
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:417
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
void clear()
static double parseEagle(const string &aDistance)
Parse an eagle distance which is either mm, or mils if there is "mil" suffix.
void loadAllSections(CPTREE &aDocument)
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
opt_int cap
double y
void packageText(MODULE *aModule, CPTREE &aTree) const
int m_PcbTextWidth
current Pcb (not module) Text width
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...
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Class BOARD to handle a board.
const wxPoint & GetPosition() const override
Definition: class_module.h:143
const PTREE CPTREE
Definition: eagle_plugin.h:63
double x
void push(const char *aPathSegment, const char *aAttribute="")
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
Eagle element element.
static opt_erot parseOptionalEROT(CPTREE &attribs)
Eagle "rot" fields are optional, handle that by returning opt_erot.
polygon (not yet used for tracks, but could be in microwave apps)
Class XPATH keeps track of what we are working on within a PTREE.
void parse(CPTREE &aRules)
static const int max_priority
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
double rlMaxPadTop
maximum copper annulus on through hole pads
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
static const int dist[10][10]
Definition: dist.cpp:57
void SetVisible(bool aVisible)
Definition: eda_text.h:175
opt_double ratio
opt_bool visible
void Attribute(const char *aAttribute)
modify the last path node's attribute
int GetHeight() const
double y
void SetCopperLayerCount(int aCount)
ELAYER(CPTREE &aLayer)
opt_erot rot
opt_bool thermals
double x1
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:483
opt_bool smashed
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
Classes to handle copper zones.
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:439
wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
usual segment : line with rounded ends
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:197
const char * element
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:60
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:889
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
opt_erot rot
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
double degrees
opt_double size
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
boost::optional< int > opt_int
Eagle SMD pad.
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
opt_double spacing
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
double y2
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
Class LIB_ID.
Definition: lib_id.h:56
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
double rvViaOuter
copper annulus is this percent of via hole
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
#define cu(a)
Definition: auxiliary.h:88
Eagle hole element.
Eagle text element.
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
#define abs(a)
Definition: auxiliary.h:84
opt_bool thermals
double x2
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
opt_erot rot
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
double GetTextAngle() const
Definition: eda_text.h:164
Functions relatives to tracks, vias and segments used to fill zones.
#define DEFAULT_PCB_EDGE_THICKNESS
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
This file contains miscellaneous commonly used macros and functions.
void SetWidth(int aWidth)
Definition: class_track.h:114
double dx
EHOLE(CPTREE &aHole)
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
int layer_back_most
< extent
segment (element) of our XPATH into the Eagle XML document tree in PTREE form.
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:839
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:113
boost::optional< EROT > opt_erot
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
DIMENSION class definition.
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 an...
EVIA(CPTREE &aVia)
void loadDesignRules(CPTREE &aDesignRules)
opt_string dimensionType
EAGLE_PLUGIN::BIU BIU
opt_bool stop
PCB_LAYER_ID
A quick note on layer IDs:
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
string text
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
Class LSET is a set of PCB_LAYER_IDs.
double y
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:136
void packagePad(MODULE *aModule, CPTREE &aTree) const
opt_int style
LAYER_NUM layer
ECIRCLE(CPTREE &aCircle)
double x1
Eagle thru hol pad.
opt_bool thermals
double GetOrientation() const
Definition: class_module.h:147
static EROT erot(const string &aRot)
parse an Eagle XML "rot" field.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
wxSize m_PcbTextSize
current Pcb (not module) Text size
int m_TrackMinWidth
track min value for width ((min copper size value
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
void AppendCorner(wxPoint position, bool aAllowDuplication=false)
Function AppendCorner.
Definition: class_zone.h:546
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
string name
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
Arcs (with rounded ends)
int m_ViasMinSize
vias (not micro vias) min diameter
Eagle circle.
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
opt_double diam
double y1
wxString m_lib_path
Definition: eagle_plugin.h:146
std::vector< TRIPLET > p
int m_ViasMinDrill
vias (not micro vias) min drill diameter
D_PAD * Next() const
Definition: class_pad.h:106
int psElongationOffset
the offset of the hole within the "long" pad.
const wxSize & GetSize() const
Definition: class_pad.h:182
EWIRE(CPTREE &aWire)
Constructor EWIRE converts a "wire"'s xml attributes ( <wire> ) to binary without additional conv...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
double x
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void packageRectangle(MODULE *aModule, CPTREE &aTree) const
subset of eagle.drawing.board.designrules in the XML document
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
EDIMENSION(CPTREE &aDimension)
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:421
void packageSMD(MODULE *aModule, CPTREE &aTree) const
opt_string value
int kicad_x(double x) const
Definition: eagle_plugin.h:157
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void loadSignals(CPTREE &aSignals)
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:85
void SetFileName(const wxString &aFileName)
Definition: class_board.h:235
double y1
void SetPosition(const wxPoint &aPos) override
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:204
std::pair< CA_ITER, CA_ITER > CA_ITER_RANGE
int layer
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
double mdWireWire
wire to wire spacing I presume.
std::vector< ZONE_CONTAINER * > ZONES
non-owning container
double x
double width
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
string value
double dy
wxPoint kicad_arc_center(wxPoint start, wxPoint end, double angle)
Convert an Eagle curve end to a KiCad center for S_ARC.
opt_int roundness
string name
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:143
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
LAYER_NUM layer
Eagle XML rectangle in binary.
opt_erot rot
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
opt_int align
void SetPos0(const wxPoint &aPos)
int psElongationLong
percent over 100%.
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:191
void packageHole(MODULE *aModule, CPTREE &aTree) const
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
opt_double x
EPOLYGON(CPTREE &aPolygon)
string name
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
PTREE::const_iterator CITER
string Contents()
return the contents of the XPATH as a single string
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:660
Eagle "attribute" XML element, no foolin'.
void loadLibraries(CPTREE &aLibs)
opt_string shape
opt_int layer
Eagle via.
EPAD(CPTREE &aPad)
double width
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
Class NETINFO_ITEM handles the data for a net.
void packageWire(MODULE *aModule, CPTREE &aTree) const
MODULE_MAP::const_iterator MODULE_CITER
ETEXT(CPTREE &aText)
string library
opt_erot rot
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
int netcode
Definition: eagle_plugin.h:46
double x2
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
double drill
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:191
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
TRIPLET(const char *aElement, const char *aAttribute="", const char *aValue="")
void loadPlain(CPTREE &aPlain)
double x
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:411
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
bool IsMirrored() const
Definition: eda_text.h:179
void SetOrientation(double newangle)
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:111
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
TEXTE_PCB & Text()
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
Class EDA_RECT handles the component boundary box.
PTREE::const_assoc_iterator CA_ITER
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:454
void SetStart0(const wxPoint &aPoint)
double drill
< inclusive
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:448
opt_double ratio
int GetX() const
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:559
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
The common library.
int GetWidth() const
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
opt_bool first
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:404
const char * name
int GetY() const
void SetEnd(const wxPoint &aEnd)
Eagle wire.
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:306
opt_bool orphans
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
double x
double y
double x
opt_int shape
static int GetDefaultHatchPitchMils()
Function GetDefaultHatchPitchMils.
Definition: class_zone.h:680
opt_erot rot
#define DBG(x)
Definition: fctsys.h:33
Eagle dimension element.
double rvPadTop
top pad size as percent of drill size
boost::optional< string > opt_string
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
void SetTextAngle(double aAngle)
DLIST< TRACK > m_Track
Definition: class_board.h:244
bool spin
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
Module description (excepted pads)
const wxSize & GetTextSize() const
Definition: eda_text.h:215
double drill
EROT(double aDegrees)
Eagle polygon, without vertices which are parsed as needed.
opt_int display
void pop()
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:659
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:207
opt_string font
boost::optional< bool > opt_bool
void SetWidth(int aWidth)
EDGE_MODULE class definition.
const char * value
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
const char * attribute
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:210
void loadElements(CPTREE &aElements)
opt_double y
double rlMinPadTop
minimum copper annulus on through hole pads
double rlMinViaOuter
minimum copper annulus on via
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:122
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
Use thermal relief for pads.
Definition: zones.h:58
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:188
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Class DIMENSION.
opt_bool active
double x
double y
double y2
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
void loadLayerDefs(CPTREE &aLayers)
EVERTEX(CPTREE &aVertex)
pads are covered by copper
Definition: zones.h:59
void Value(const char *aValue)
modify the last path node's value
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
int layer_front_most
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
double y
opt_bool cream
opt_bool locked
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
void SetWidth(int aWidth)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.