KiCad PCB EDA Suite
eagle_plugin.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 /*
27 
28 Pcbnew PLUGIN for Eagle 6.x XML *.brd and footprint format.
29 
30 XML parsing and converting:
31 Getting line numbers and byte offsets from the source XML file is not
32 possible using currently available XML libraries within KiCad project:
33 wxXmlDocument and boost::property_tree.
34 
35 property_tree will give line numbers but no byte offsets, and only during
36 document loading. This means that if we have a problem after the document is
37 successfully loaded, there is no way to correlate back to line number and byte
38 offset of the problem. So a different approach is taken, one which relies on the
39 XML elements themselves using an XPATH type of reporting mechanism. The path to
40 the problem is reported in the error messages. This means keeping track of that
41 path as we traverse the XML document for the sole purpose of accurate error
42 reporting.
43 
44 User can load the source XML file into firefox or other xml browser and follow
45 our error message.
46 
47 Load() TODO's
48 
49 *) verify zone fill clearances are correct
50 
51 */
52 
53 #include <errno.h>
54 
55 #include <wx/string.h>
56 #include <wx/xml/xml.h>
57 
58 #include <common.h>
59 #include <macros.h>
60 #include <fctsys.h>
61 #include <trigo.h>
62 #include <macros.h>
64 #include <kicad_string.h>
65 #include <properties.h>
66 #include <wx/filename.h>
67 
68 #include <class_board.h>
69 #include <class_module.h>
70 #include <class_track.h>
71 #include <class_edge_mod.h>
72 #include <class_zone.h>
73 #include <class_pcb_text.h>
74 #include <class_dimension.h>
75 
76 #include <eagle_plugin.h>
77 
78 using namespace std;
79 
80 
81 typedef MODULE_MAP::iterator MODULE_ITER;
82 typedef MODULE_MAP::const_iterator MODULE_CITER;
83 
84 
87 static int parseEagle( const wxString& aDistance )
88 {
89  ECOORD::EAGLE_UNIT unit = ( aDistance.npos != aDistance.find( "mil" ) )
90  ? ECOORD::EAGLE_UNIT::EU_MIL : ECOORD::EAGLE_UNIT::EU_MM;
91 
92  ECOORD coord( aDistance, unit );
93 
94  return coord.ToPcbUnits();
95 }
96 
97 
100 static wxString makeKey( const wxString& aFirst, const wxString& aSecond )
101 {
102  wxString key = aFirst + '\x02' + aSecond;
103  return key;
104 }
105 
106 
107 void ERULES::parse( wxXmlNode* aRules )
108 {
109  wxXmlNode* child = aRules->GetChildren();
110 
111  while( child )
112  {
113  if( child->GetName() == "param" )
114  {
115  const wxString& name = child->GetAttribute( "name" );
116  const wxString& value = child->GetAttribute( "value" );
117 
118  if( name == "psElongationLong" )
119  psElongationLong = wxAtoi( value );
120  else if( name == "psElongationOffset" )
121  psElongationOffset = wxAtoi( value );
122 
123  else if( name == "mvStopFrame" )
124  value.ToDouble( &mvStopFrame );
125  else if( name == "mvCreamFrame" )
126  value.ToDouble( &mvCreamFrame );
127  else if( name == "mlMinStopFrame" )
128  mlMinStopFrame = parseEagle( value );
129  else if( name == "mlMaxStopFrame" )
130  mlMaxStopFrame = parseEagle( value );
131  else if( name == "mlMinCreamFrame" )
132  mlMinCreamFrame = parseEagle( value );
133  else if( name == "mlMaxCreamFrame" )
134  mlMaxCreamFrame = parseEagle( value );
135 
136  else if( name == "srRoundness" )
137  value.ToDouble( &srRoundness );
138  else if( name == "srMinRoundness" )
139  srMinRoundness = parseEagle( value );
140  else if( name == "srMaxRoundness" )
141  srMaxRoundness = parseEagle( value );
142 
143  else if( name == "rvPadTop" )
144  value.ToDouble( &rvPadTop );
145  else if( name == "rlMinPadTop" )
146  rlMinPadTop = parseEagle( value );
147  else if( name == "rlMaxPadTop" )
148  rlMaxPadTop = parseEagle( value );
149 
150  else if( name == "rvViaOuter" )
151  value.ToDouble( &rvViaOuter );
152  else if( name == "rlMinViaOuter" )
153  rlMinViaOuter = parseEagle( value );
154  else if( name == "rlMaxViaOuter" )
155  rlMaxViaOuter = parseEagle( value );
156  else if( name == "mdWireWire" )
157  mdWireWire = parseEagle( value );
158  }
159 
160  child = child->GetNext();
161  }
162 }
163 
164 
166  m_rules( new ERULES() ),
167  m_xpath( new XPATH() ),
168  m_mod_time( wxDateTime::Now() )
169 {
170  init( NULL );
171  clear_cu_map();
172 }
173 
174 
176 {
177  deleteTemplates();
178  delete m_rules;
179  delete m_xpath;
180 }
181 
182 
183 const wxString EAGLE_PLUGIN::PluginName() const
184 {
185  return wxT( "Eagle" );
186 }
187 
188 
189 const wxString EAGLE_PLUGIN::GetFileExtension() const
190 {
191  return wxT( "brd" );
192 }
193 
194 
195 wxSize inline EAGLE_PLUGIN::kicad_fontz( const ECOORD& d ) const
196 {
197  // texts seem to better match eagle when scaled down by 0.95
198  int kz = d.ToPcbUnits() * 95 / 100;
199  return wxSize( kz, kz );
200 }
201 
202 
203 BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
204 {
205  LOCALE_IO toggle; // toggles on, then off, the C locale.
206  wxXmlNode* doc;
207 
208  init( aProperties );
209 
210  m_board = aAppendToMe ? aAppendToMe : new BOARD();
211 
212  // Give the filename to the board if it's new
213  if( !aAppendToMe )
214  m_board->SetFileName( aFileName );
215 
216  // delete on exception, if I own m_board, according to aAppendToMe
217  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
218 
219  try
220  {
221  // Load the document
222  wxXmlDocument xmlDocument;
223  wxFileName fn = aFileName;
224 
225  if( !xmlDocument.Load( fn.GetFullPath() ) )
226  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
227  fn.GetFullPath() ) );
228 
229  doc = xmlDocument.GetRoot();
230 
231  m_min_trace = INT_MAX;
232  m_min_via = INT_MAX;
233  m_min_via_hole = INT_MAX;
234 
235  loadAllSections( doc );
236 
237  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
238 
239  if( m_min_trace < designSettings.m_TrackMinWidth )
240  designSettings.m_TrackMinWidth = m_min_trace;
241 
242  if( m_min_via < designSettings.m_ViasMinSize )
243  designSettings.m_ViasMinSize = m_min_via;
244 
245  if( m_min_via_hole < designSettings.m_ViasMinDrill )
246  designSettings.m_ViasMinDrill = m_min_via_hole;
247 
248  if( m_rules->mdWireWire )
249  {
250  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
251  int clearance = KiROUND( m_rules->mdWireWire );
252 
253  if( clearance < defaultNetclass->GetClearance() )
254  defaultNetclass->SetClearance( clearance );
255  }
256 
257  // should be empty, else missing m_xpath->pop()
258  wxASSERT( m_xpath->Contents().size() == 0 );
259  }
260  // Catch all exceptions thrown from the parser.
261  catch( const XML_PARSER_ERROR &exc )
262  {
263  wxString errmsg = exc.what();
264 
265  errmsg += "\n@ ";
266  errmsg += m_xpath->Contents();
267 
268  THROW_IO_ERROR( errmsg );
269  }
270 
271  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
272 
273  // Ensure the copper layers count is a multiple of 2
274  // Pcbnew does not like boards with odd layers count
275  // (these boards cannot exist. they actually have a even layers count)
276  int lyrcnt = m_board->GetCopperLayerCount();
277 
278  if( (lyrcnt % 2) != 0 )
279  {
280  lyrcnt++;
281  m_board->SetCopperLayerCount( lyrcnt );
282  }
283 
284  centerBoard();
285 
286  deleter.release();
287  return m_board;
288 }
289 
290 
291 void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
292 {
293  m_hole_count = 0;
294  m_min_trace = 0;
295  m_min_via = 0;
296  m_min_via_hole = 0;
297  m_xpath->clear();
298  m_pads_to_nets.clear();
299 
300  m_board = NULL;
301  m_props = aProperties;
302 
303 
304  delete m_rules;
305  m_rules = new ERULES();
306 }
307 
308 
310 {
311  // All cu layers are invalid until we see them in the <layers> section while
312  // loading either a board or library. See loadLayerDefs().
313  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
314  m_cu_map[i] = -1;
315 }
316 
317 
318 void EAGLE_PLUGIN::loadAllSections( wxXmlNode* aDoc )
319 {
320  wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
321  NODE_MAP drawingChildren = MapChildren( drawing );
322 
323  wxXmlNode* board = drawingChildren["board"];
324  NODE_MAP boardChildren = MapChildren( board );
325 
326  m_xpath->push( "eagle.drawing" );
327 
328  {
329  m_xpath->push( "board" );
330 
331  wxXmlNode* designrules = boardChildren["designrules"];
332  loadDesignRules( designrules );
333 
334  m_xpath->pop();
335  }
336 
337  {
338  m_xpath->push( "layers" );
339 
340  wxXmlNode* layers = drawingChildren["layers"];
341  loadLayerDefs( layers );
342 
343  m_xpath->pop();
344  }
345 
346  {
347  m_xpath->push( "board" );
348 
349  wxXmlNode* plain = boardChildren["plain"];
350  loadPlain( plain );
351 
352  wxXmlNode* signals = boardChildren["signals"];
353  loadSignals( signals );
354 
355  wxXmlNode* libs = boardChildren["libraries"];
356  loadLibraries( libs );
357 
358  wxXmlNode* elems = boardChildren["elements"];
359  loadElements( elems );
360 
361  m_xpath->pop(); // "board"
362  }
363 
364  m_xpath->pop(); // "eagle.drawing"
365 }
366 
367 
368 void EAGLE_PLUGIN::loadDesignRules( wxXmlNode* aDesignRules )
369 {
370  m_xpath->push( "designrules" );
371  m_rules->parse( aDesignRules );
372  m_xpath->pop(); // "designrules"
373 }
374 
375 
376 void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
377 {
378  ELAYERS cu; // copper layers
379 
380  // Get the first layer and iterate
381  wxXmlNode* layerNode = aLayers->GetChildren();
382 
383  m_eagleLayers.clear();
384 
385  while( layerNode )
386  {
387  ELAYER elayer( layerNode );
388  m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
389 
390  // find the subset of layers that are copper and active
391  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
392  {
393  cu.push_back( elayer );
394  }
395 
396  layerNode = layerNode->GetNext();
397  }
398 
399  // establish cu layer map:
400  int ki_layer_count = 0;
401 
402  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
403  {
404  if( ki_layer_count == 0 )
405  m_cu_map[it->number] = F_Cu;
406  else if( ki_layer_count == int( cu.size()-1 ) )
407  m_cu_map[it->number] = B_Cu;
408  else
409  {
410  // some eagle boards do not have contiguous layer number sequences.
411 
412 #if 0 // pre PCB_LAYER_ID & LSET:
413  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
414 #else
415  m_cu_map[it->number] = ki_layer_count;
416 #endif
417  }
418  }
419 
420 #if 0 && defined(DEBUG)
421  printf( "m_cu_map:\n" );
422  for( unsigned i=0; i<DIM(m_cu_map); ++i )
423  {
424  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
425  }
426 #endif
427 
428  // Set the layer names and cu count iff we're loading a board.
429  if( m_board )
430  {
431  m_board->SetCopperLayerCount( cu.size() );
432 
433  for( EITER it = cu.begin(); it != cu.end(); ++it )
434  {
435  PCB_LAYER_ID layer = kicad_layer( it->number );
436 
437  // these function provide their own protection against UNDEFINED_LAYER:
438  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
439  m_board->SetLayerType( layer, LT_SIGNAL );
440 
441  // could map the colors here
442  }
443  }
444 }
445 
446 
447 void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
448 {
449  m_xpath->push( "plain" );
450 
451  // Get the first graphic and iterate
452  wxXmlNode* gr = aGraphics->GetChildren();
453 
454  // (polygon | wire | text | circle | rectangle | frame | hole)*
455  while( gr )
456  {
457  wxString grName = gr->GetName();
458 
459  if( grName == "wire" )
460  {
461  m_xpath->push( "wire" );
462 
463  EWIRE w( gr );
464  PCB_LAYER_ID layer = kicad_layer( w.layer );
465 
466  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
467  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
468 
469  if( layer != UNDEFINED_LAYER )
470  {
471  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
472  m_board->Add( dseg, ADD_APPEND );
473 
474  if( !w.curve )
475  {
476  dseg->SetStart( start );
477  dseg->SetEnd( end );
478  }
479  else
480  {
481  wxPoint center = ConvertArcCenter( start, end, *w.curve );
482 
483  dseg->SetShape( S_ARC );
484  dseg->SetStart( center );
485  dseg->SetEnd( start );
486  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
487  }
488 
489  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
490  dseg->SetLayer( layer );
491  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
492  }
493  m_xpath->pop();
494  }
495  else if( grName == "text" )
496  {
497  m_xpath->push( "text" );
498 
499  ETEXT t( gr );
500  PCB_LAYER_ID layer = kicad_layer( t.layer );
501 
502  if( layer != UNDEFINED_LAYER )
503  {
504  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
505  m_board->Add( pcbtxt, ADD_APPEND );
506 
507  pcbtxt->SetLayer( layer );
508  pcbtxt->SetTimeStamp( EagleTimeStamp( gr ) );
509  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
510  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
511 
512  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
513 
514  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
515 
516  pcbtxt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
517 
518  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
519 
520  if( t.rot )
521  {
522  int sign = t.rot->mirror ? -1 : 1;
523  pcbtxt->SetMirrored( t.rot->mirror );
524 
525  double degrees = t.rot->degrees;
526 
527  if( degrees == 90 || t.rot->spin )
528  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
529  else if( degrees == 180 )
530  align = ETEXT::TOP_RIGHT;
531  else if( degrees == 270 )
532  {
533  pcbtxt->SetTextAngle( sign * 90 * 10 );
534  align = ETEXT::TOP_RIGHT;
535  }
536  else // Ok so text is not at 90,180 or 270 so do some funny stuf to get placement right
537  {
538  if( ( degrees > 0 ) && ( degrees < 90 ) )
539  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
540  else if( ( degrees > 90 ) && ( degrees < 180 ) )
541  {
542  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
543  align = ETEXT::TOP_RIGHT;
544  }
545  else if( ( degrees > 180 ) && ( degrees < 270 ) )
546  {
547  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
548  align = ETEXT::TOP_RIGHT;
549  }
550  else if( ( degrees > 270 ) && ( degrees < 360 ) )
551  {
552  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
553  align = ETEXT::BOTTOM_LEFT;
554  }
555  }
556  }
557 
558  switch( align )
559  {
560  case ETEXT::CENTER:
561  // this was the default in pcbtxt's constructor
562  break;
563 
564  case ETEXT::CENTER_LEFT:
566  break;
567 
568  case ETEXT::CENTER_RIGHT:
570  break;
571 
572  case ETEXT::TOP_CENTER:
574  break;
575 
576  case ETEXT::TOP_LEFT:
579  break;
580 
581  case ETEXT::TOP_RIGHT:
584  break;
585 
588  break;
589 
590  case ETEXT::BOTTOM_LEFT:
593  break;
594 
595  case ETEXT::BOTTOM_RIGHT:
598  break;
599  }
600  }
601  m_xpath->pop();
602  }
603  else if( grName == "circle" )
604  {
605  m_xpath->push( "circle" );
606 
607  ECIRCLE c( gr );
608  PCB_LAYER_ID layer = kicad_layer( c.layer );
609 
610  if( layer != UNDEFINED_LAYER ) // unsupported layer
611  {
612  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
613  m_board->Add( dseg, ADD_APPEND );
614 
615  dseg->SetShape( S_CIRCLE );
616  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
617  dseg->SetLayer( layer );
618  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
619  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
620  dseg->SetWidth( c.width.ToPcbUnits() );
621  }
622  m_xpath->pop();
623  }
624  else if( grName == "rectangle" )
625  {
626  // This seems to be a simplified rectangular [copper] zone, cannot find any
627  // net related info on it from the DTD.
628  m_xpath->push( "rectangle" );
629 
630  ERECT r( gr );
631  PCB_LAYER_ID layer = kicad_layer( r.layer );
632 
633  if( IsCopperLayer( layer ) )
634  {
635  // use a "netcode = 0" type ZONE:
636  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
637  m_board->Add( zone, ADD_APPEND );
638 
639  zone->SetTimeStamp( EagleTimeStamp( gr ) );
640  zone->SetLayer( layer );
642 
644 
645  const int outlineIdx = -1; // this is the id of the copper zone main outline
646  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
647  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
648  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
649  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
650 
651  if( r.rot )
652  {
653  zone->Rotate( zone->GetPosition(), r.rot->degrees * 10 );
654  }
655  // this is not my fault:
656  zone->SetHatch( outline_hatch, zone->GetDefaultHatchPitch(), true );
657  }
658 
659  m_xpath->pop();
660  }
661  else if( grName == "hole" )
662  {
663  m_xpath->push( "hole" );
664  EHOLE e( gr );
665 
666  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
667  // Use m_hole_count to gen up a unique name.
668 
669  MODULE* module = new MODULE( m_board );
670  m_board->Add( module, ADD_APPEND );
671 
672  char temp[40];
673  snprintf( temp, sizeof( temp ), "@HOLE%d", m_hole_count++ );
674  module->SetReference( FROM_UTF8( temp ) );
675  module->Reference().SetVisible( false );
676 
677  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
678 
679  module->SetPosition( pos );
680 
681  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
682  D_PAD* pad = new D_PAD( module );
683  module->PadsList().PushBack( pad );
684 
685  pad->SetShape( PAD_SHAPE_CIRCLE );
687 
688  /* pad's position is already centered on module at relative (0, 0)
689  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
690 
691  pad->SetPos0( padpos );
692  pad->SetPosition( padpos + module->GetPosition() );
693  */
694 
695  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
696 
697  pad->SetDrillSize( sz );
698  pad->SetSize( sz );
699 
700  pad->SetLayerSet( LSET::AllCuMask() );
701  m_xpath->pop();
702  }
703  else if( grName == "frame" )
704  {
705  // picture this
706  }
707  else if( grName == "polygon" )
708  {
709  m_xpath->push( "polygon" );
710  loadPolygon( gr );
711  m_xpath->pop(); // "polygon"
712  }
713  else if( grName == "dimension" )
714  {
715  EDIMENSION d( gr );
716  PCB_LAYER_ID layer = kicad_layer( d.layer );
717 
718  if( layer != UNDEFINED_LAYER )
719  {
720  DIMENSION* dimension = new DIMENSION( m_board );
721  m_board->Add( dimension, ADD_APPEND );
722 
723  if( d.dimensionType )
724  {
725  // Eagle dimension graphic arms may have different lengths, but they look
726  // incorrect in KiCad (the graphic is tilted). Make them even lenght in such case.
727  if( *d.dimensionType == "horizontal" )
728  {
729  int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
730  d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
731  d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
732  }
733  else if( *d.dimensionType == "vertical" )
734  {
735  int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
736  d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
737  d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
738  }
739  }
740 
741  dimension->SetLayer( layer );
742  // The origin and end are assumed to always be in this order from eagle
743  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
744  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
746 
748  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
749 
750  if( width > maxThickness )
751  width = maxThickness;
752 
753  dimension->Text().SetThickness( width );
754  dimension->SetWidth( width );
755 
756  // check which axis the dimension runs in
757  // because the "height" of the dimension is perpendicular to that axis
758  // Note the check is just if two axes are close enough to each other
759  // Eagle appears to have some rounding errors
760  if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm
761  dimension->SetHeight( kicad_x( d.x3 - d.x1 ) );
762  else
763  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
764 
765  dimension->AdjustDimensionDetails();
766  }
767  }
768 
769  // Get next graphic
770  gr = gr->GetNext();
771  }
772  m_xpath->pop();
773 }
774 
775 
776 void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const wxString* aLibName )
777 {
778  m_xpath->push( "packages" );
779 
780  // library will have <xmlattr> node, skip that and get the single packages node
781  wxXmlNode* packages = MapChildren( aLib )["packages"];
782 
783 
784  // Create a MODULE for all the eagle packages, for use later via a copy constructor
785  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
786  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
787 
788  // Get the first package and iterate
789  wxXmlNode* package = packages->GetChildren();
790 
791  while( package )
792  {
793  m_xpath->push( "package", "name" );
794 
795  const wxString& pack_ref = package->GetAttribute( "name" );
796  std::string pack_name( pack_ref );
797  ReplaceIllegalFileNameChars( &pack_name, '_' );
798 
799  m_xpath->Value( pack_name.c_str() );
800 
801  wxString key = aLibName ? makeKey( *aLibName, pack_name ) : wxString( pack_name );
802 
803  MODULE* m = makeModule( package, pack_name );
804 
805  // add the templating MODULE to the MODULE template factory "m_templates"
806  std::pair<MODULE_ITER, bool> r = m_templates.insert( {key, m} );
807 
808  if( !r.second
809  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
810  )
811  {
812  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
813  wxString pkg = FROM_UTF8( pack_name.c_str() );
814 
815  wxString emsg = wxString::Format(
816  _( "<package> name: \"%s\" duplicated in eagle <library>: \"%s\"" ),
817  GetChars( pkg ),
818  GetChars( lib )
819  );
820  THROW_IO_ERROR( emsg );
821  }
822 
823  m_xpath->pop();
824 
825  package = package->GetNext();
826  }
827 
828  m_xpath->pop(); // "packages"
829 }
830 
831 
832 void EAGLE_PLUGIN::loadLibraries( wxXmlNode* aLibs )
833 {
834  m_xpath->push( "libraries.library", "name" );
835 
836  // Get the first library and iterate
837  wxXmlNode* library = aLibs->GetChildren();
838 
839  while( library )
840  {
841  const wxString& lib_name = library->GetAttribute( "name" );
842 
843  m_xpath->Value( lib_name.c_str() );
844  loadLibrary( library, &lib_name );
845  library = library->GetNext();
846  }
847 
848  m_xpath->pop();
849 }
850 
851 
852 void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
853 {
854  m_xpath->push( "elements.element", "name" );
855 
856  EATTR name;
857  EATTR value;
858  bool refanceNamePresetInPackageLayout;
859  bool valueNamePresetInPackageLayout;
860 
861  // Get the first element and iterate
862  wxXmlNode* element = aElements->GetChildren();
863 
864  while( element )
865  {
866  if( element->GetName() != "element" )
867  {
868  wxLogMessage( "expected: <element> read <%s>. Skip it", element->GetName() );
869  // Get next item
870  element = element->GetNext();
871  continue;
872  }
873 
874  EELEMENT e( element );
875 
876  // use "NULL-ness" as an indication of presence of the attribute:
877  EATTR* nameAttr = 0;
878  EATTR* valueAttr = 0;
879 
880  m_xpath->Value( e.name.c_str() );
881 
882  wxString pkg_key = makeKey( e.library, e.package );
883 
884  MODULE_CITER mi = m_templates.find( pkg_key );
885 
886  if( mi == m_templates.end() )
887  {
888  wxString emsg = wxString::Format( _( "No \"%s\" package in library \"%s\"" ),
889  GetChars( FROM_UTF8( e.package.c_str() ) ),
890  GetChars( FROM_UTF8( e.library.c_str() ) ) );
891  THROW_IO_ERROR( emsg );
892  }
893 
894  // copy constructor to clone the template
895  MODULE* m = new MODULE( *mi->second );
896  m_board->Add( m, ADD_APPEND );
897 
898  // update the nets within the pads of the clone
899  for( D_PAD* pad = m->PadsList(); pad; pad = pad->Next() )
900  {
901  wxString pn_key = makeKey( e.name, pad->GetName() );
902 
903  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
904  if( ni != m_pads_to_nets.end() )
905  {
906  const ENET* enet = &ni->second;
907  pad->SetNetCode( enet->netcode );
908  }
909  }
910 
911  refanceNamePresetInPackageLayout = true;
912  valueNamePresetInPackageLayout = true;
913  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
914 
915  // Is >NAME field set in package layout ?
916  if( m->GetReference().size() == 0 )
917  {
918  m->Reference().SetVisible( false ); // No so no show
919  refanceNamePresetInPackageLayout = false;
920  }
921 
922  // Is >VALUE field set in package layout
923  if( m->GetValue().size() == 0 )
924  {
925  m->Value().SetVisible( false ); // No so no show
926  valueNamePresetInPackageLayout = false;
927  }
928 
929  m->SetReference( FROM_UTF8( e.name.c_str() ) );
930  m->SetValue( FROM_UTF8( e.value.c_str() ) );
931 
932  if( !e.smashed )
933  { // Not smashed so show NAME & VALUE
934  if( valueNamePresetInPackageLayout )
935  m->Value().SetVisible( true ); // Only if place holder in package layout
936 
937  if( refanceNamePresetInPackageLayout )
938  m->Reference().SetVisible( true ); // Only if place holder in package layout
939  }
940  else if( *e.smashed == true )
941  { // Smasted so set default to no show for NAME and VALUE
942  m->Value().SetVisible( false );
943  m->Reference().SetVisible( false );
944 
945  // initalize these to default values incase the <attribute> elements are not present.
946  m_xpath->push( "attribute", "name" );
947 
948  // VALUE and NAME can have something like our text "effects" overrides
949  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
950  // There can be one for NAME and/or VALUE both. Features present in the
951  // EATTR override the ones established in the package only if they are
952  // present here (except for rot, which if not present means angle zero).
953  // So the logic is a bit different than in packageText() and in plain text.
954 
955  // Get the first attribute and iterate
956  wxXmlNode* attribute = element->GetChildren();
957 
958  while( attribute )
959  {
960  if( attribute->GetName() != "attribute" )
961  {
962  wxLogMessage( "expected: <attribute> read <%s>. Skip it", attribute->GetName() );
963  attribute = attribute->GetNext();
964  continue;
965  }
966 
967  EATTR a( attribute );
968 
969  if( a.name == "NAME" )
970  {
971  name = a;
972  nameAttr = &name;
973 
974  // do we have a display attribute ?
975  if( a.display )
976  {
977  // Yes!
978  switch( *a.display )
979  {
980  case EATTR::VALUE :
981  nameAttr->name = e.name;
982  m->SetReference( e.name );
983  if( refanceNamePresetInPackageLayout )
984  m->Reference().SetVisible( true );
985  break;
986 
987  case EATTR::NAME :
988  if( refanceNamePresetInPackageLayout )
989  {
990  m->SetReference( "NAME" );
991  m->Reference().SetVisible( true );
992  }
993  break;
994 
995  case EATTR::BOTH :
996  if( refanceNamePresetInPackageLayout )
997  m->Reference().SetVisible( true );
998  nameAttr->name = nameAttr->name + " = " + e.name;
999  m->SetReference( "NAME = " + e.name );
1000  break;
1001 
1002  case EATTR::Off :
1003  m->Reference().SetVisible( false );
1004  break;
1005 
1006  default:
1007  nameAttr->name = e.name;
1008  if( refanceNamePresetInPackageLayout )
1009  m->Reference().SetVisible( true );
1010  }
1011  }
1012  else
1013  // No display, so default is visable, and show value of NAME
1014  m->Reference().SetVisible( true );
1015  }
1016  else if( a.name == "VALUE" )
1017  {
1018  value = a;
1019  valueAttr = &value;
1020 
1021  if( a.display )
1022  {
1023  // Yes!
1024  switch( *a.display )
1025  {
1026  case EATTR::VALUE :
1027  valueAttr->value = opt_wxString( e.value );
1028  m->SetValue( e.value );
1029  if( valueNamePresetInPackageLayout )
1030  m->Value().SetVisible( true );
1031  break;
1032 
1033  case EATTR::NAME :
1034  if( valueNamePresetInPackageLayout )
1035  m->Value().SetVisible( true );
1036  m->SetValue( "VALUE" );
1037  break;
1038 
1039  case EATTR::BOTH :
1040  if( valueNamePresetInPackageLayout )
1041  m->Value().SetVisible( true );
1042  valueAttr->value = opt_wxString( "VALUE = " + e.value );
1043  m->SetValue( "VALUE = " + e.value );
1044  break;
1045 
1046  case EATTR::Off :
1047  m->Value().SetVisible( false );
1048  break;
1049 
1050  default:
1051  valueAttr->value = opt_wxString( e.value );
1052  if( valueNamePresetInPackageLayout )
1053  m->Value().SetVisible( true );
1054  }
1055  }
1056  else
1057  // No display, so default is visible, and show value of NAME
1058  m->Value().SetVisible( true );
1059 
1060  }
1061 
1062  attribute = attribute->GetNext();
1063  }
1064 
1065  m_xpath->pop(); // "attribute"
1066  }
1067 
1068  orientModuleAndText( m, e, nameAttr, valueAttr );
1069 
1070  // Get next element
1071  element = element->GetNext();
1072  }
1073 
1074  m_xpath->pop(); // "elements.element"
1075 }
1076 
1077 
1079 {
1080  EPOLYGON p( aPolyNode );
1081  PCB_LAYER_ID layer = kicad_layer( p.layer );
1082  ZONE_CONTAINER* zone = nullptr;
1083  bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT || p.layer == EAGLE_LAYER::BRESTRICT );
1084 
1085  if( !IsCopperLayer( layer ) && !keepout )
1086  return nullptr;
1087 
1088  // use a "netcode = 0" type ZONE:
1089  zone = new ZONE_CONTAINER( m_board );
1090  zone->SetTimeStamp( EagleTimeStamp( aPolyNode ) );
1091  m_board->Add( zone, ADD_APPEND );
1092 
1093  if( p.layer == EAGLE_LAYER::TRESTRICT ) // front layer keepout
1094  zone->SetLayer( F_Cu );
1095  else if( p.layer == EAGLE_LAYER::BRESTRICT ) // bottom layer keepout
1096  zone->SetLayer( B_Cu );
1097  else
1098  zone->SetLayer( layer );
1099 
1100  if( keepout )
1101  {
1102  zone->SetIsKeepout( true );
1103  zone->SetDoNotAllowVias( true );
1104  zone->SetDoNotAllowTracks( true );
1105  zone->SetDoNotAllowCopperPour( true );
1106  }
1107 
1108  // Get the first vertex and iterate
1109  wxXmlNode* vertex = aPolyNode->GetChildren();
1110  std::vector<EVERTEX> vertices;
1111 
1112  // Create a circular vector of vertices
1113  // The "curve" parameter indicates a curve from the current
1114  // to the next vertex, so we keep the first at the end as well
1115  // to allow the curve to link back
1116  while( vertex )
1117  {
1118  if( vertex->GetName() == "vertex" )
1119  vertices.push_back( EVERTEX( vertex ) );
1120 
1121  vertex = vertex->GetNext();
1122  }
1123 
1124  vertices.push_back( vertices[0] );
1125 
1126  for( size_t i = 0; i < vertices.size() - 1; i++ )
1127  {
1128  EVERTEX v1 = vertices[i];
1129 
1130  // Append the corner
1131  zone->AppendCorner( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ), -1 );
1132 
1133  if( v1.curve )
1134  {
1135  EVERTEX v2 = vertices[i + 1];
1136  wxPoint center = ConvertArcCenter(
1137  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1138  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1139  double angle = DEG2RAD( *v1.curve );
1140  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1141  kicad_x( v2.x ) - center.x );
1142  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1143  + pow( center.y - kicad_y( v1.y ), 2 ) );
1144 
1145  // If we are curving, we need at least 2 segments otherwise
1146  // delta_angle == angle
1147  double delta_angle = angle / std::max(
1148  2, GetArcToSegmentCount( KiROUND( radius ),
1149  ARC_HIGH_DEF, *v1.curve ) - 1 );
1150 
1151  for( double a = end_angle + angle;
1152  fabs( a - end_angle ) > fabs( delta_angle );
1153  a -= delta_angle )
1154  {
1155  zone->AppendCorner(
1156  wxPoint( KiROUND( radius * cos( a ) ),
1157  KiROUND( radius * sin( a ) ) ) + center,
1158  -1 );
1159  }
1160  }
1161  }
1162 
1163  // If the pour is a cutout it needs to be set to a keepout
1164  if( p.pour == EPOLYGON::CUTOUT )
1165  {
1166  zone->SetIsKeepout( true );
1167  zone->SetDoNotAllowCopperPour( true );
1169  }
1170 
1171  // if spacing is set the zone should be hatched
1172  // However, use the default hatch step, p.spacing value has no meaning for Kicad
1173  // TODO: see if this parameter is related to a grid fill option.
1174  if( p.spacing )
1176 
1177  // clearances, etc.
1178  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
1179  zone->SetMinThickness( p.width.ToPcbUnits() );
1180 
1181  // FIXME: KiCad zones have very rounded corners compared to eagle.
1182  // This means that isolation amounts that work well in eagle
1183  // tend to make copper intrude in soldermask free areas around pads.
1184  if( p.isolate )
1185  zone->SetZoneClearance( p.isolate->ToPcbUnits() );
1186  else
1187  zone->SetZoneClearance( 0 );
1188 
1189  // missing == yes per DTD.
1190  bool thermals = !p.thermals || *p.thermals;
1192 
1193  if( thermals )
1194  {
1195  // FIXME: eagle calculates dimensions for thermal spokes
1196  // based on what the zone is connecting to.
1197  // (i.e. width of spoke is half of the smaller side of an smd pad)
1198  // This is a basic workaround
1199  zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
1200  zone->SetThermalReliefCopperBridge( p.width.ToPcbUnits() + 50000 );
1201  }
1202 
1203  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
1204  zone->SetPriority( rank );
1205 
1206  return zone;
1207 }
1208 
1209 
1211  const EATTR* nameAttr, const EATTR* valueAttr )
1212 {
1213  if( e.rot )
1214  {
1215  if( e.rot->mirror )
1216  {
1217  double orientation = e.rot->degrees + 180.0;
1218  m->SetOrientation( orientation * 10 );
1219  m->Flip( m->GetPosition() );
1220  }
1221  else
1222  m->SetOrientation( e.rot->degrees * 10 );
1223  }
1224 
1225  orientModuleText( m, e, &m->Reference(), nameAttr );
1226  orientModuleText( m, e, &m->Value(), valueAttr );
1227 }
1228 
1229 
1231  TEXTE_MODULE* txt, const EATTR* aAttr )
1232 {
1233  // Smashed part ?
1234  if( aAttr )
1235  { // Yes
1236  const EATTR& a = *aAttr;
1237 
1238  if( a.value )
1239  {
1240  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1241  }
1242 
1243  if( a.x && a.y ) // OPT
1244  {
1245  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1246  txt->SetTextPos( pos );
1247  }
1248 
1249  // Even though size and ratio are both optional, I am not seeing
1250  // a case where ratio is present but size is not.
1251  double ratio = 8;
1252  wxSize fontz = txt->GetTextSize();
1253 
1254  if( a.size )
1255  {
1256  fontz = kicad_fontz( *a.size );
1257  txt->SetTextSize( fontz );
1258 
1259  if( a.ratio )
1260  ratio = *a.ratio;
1261  }
1262 
1263  int lw = int( fontz.y * ratio / 100 );
1264  txt->SetThickness( lw );
1265 
1266  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1267 
1268  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1269  // present, and this zero rotation becomes an override to the
1270  // package's text field. If they did not want zero, they specify
1271  // what they want explicitly.
1272  double degrees = a.rot ? a.rot->degrees : 0;
1273  double orient; // relative to parent
1274 
1275  int sign = 1;
1276  bool spin = false;
1277 
1278  if( a.rot )
1279  {
1280  spin = a.rot->spin;
1281  sign = a.rot->mirror ? -1 : 1;
1282  txt->SetMirrored( a.rot->mirror );
1283  }
1284 
1285  if( degrees == 90 || degrees == 0 || spin )
1286  {
1287  orient = degrees - m->GetOrientation() / 10;
1288  txt->SetTextAngle( sign * orient * 10 );
1289  }
1290  else if( degrees == 180 )
1291  {
1292  orient = 0 - m->GetOrientation() / 10;
1293  txt->SetTextAngle( sign * orient * 10 );
1294  align = ETEXT::TOP_RIGHT;
1295  }
1296  else if( degrees == 270 )
1297  {
1298  orient = 90 - m->GetOrientation() / 10;
1299  align = ETEXT::TOP_RIGHT;
1300  txt->SetTextAngle( sign * orient * 10 );
1301  }
1302  else
1303  {
1304  orient = 90 - degrees - m->GetOrientation() / 10;
1305  txt->SetTextAngle( sign * orient * 10 );
1306  }
1307 
1308  switch( align )
1309  {
1310  case ETEXT::TOP_RIGHT:
1313  break;
1314 
1315  case ETEXT::BOTTOM_LEFT:
1318  break;
1319 
1320  default:
1321  ;
1322  }
1323  }
1324  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1325  {
1326  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1327 
1328  // @todo there are a few more cases than these to contend with:
1329  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1330  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1331  {
1332  // ETEXT::TOP_RIGHT:
1335  }
1336  }
1337 }
1338 
1339 
1340 MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const
1341 {
1342  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1343 
1344  m->SetFPID( LIB_ID( UTF8( aPkgName ) ) );
1345 
1346  // Get the first package item and iterate
1347  wxXmlNode* packageItem = aPackage->GetChildren();
1348 
1349  while( packageItem )
1350  {
1351  const wxString& itemName = packageItem->GetName();
1352 
1353  if( itemName == "description" )
1354  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1355 
1356  else if( itemName == "wire" )
1357  packageWire( m.get(), packageItem );
1358 
1359  else if( itemName == "pad" )
1360  packagePad( m.get(), packageItem );
1361 
1362  else if( itemName == "text" )
1363  packageText( m.get(), packageItem );
1364 
1365  else if( itemName == "rectangle" )
1366  packageRectangle( m.get(), packageItem );
1367 
1368  else if( itemName == "polygon" )
1369  packagePolygon( m.get(), packageItem );
1370 
1371  else if( itemName == "circle" )
1372  packageCircle( m.get(), packageItem );
1373 
1374  else if( itemName == "hole" )
1375  packageHole( m.get(), packageItem );
1376 
1377  else if( itemName == "smd" )
1378  packageSMD( m.get(), packageItem );
1379 
1380  packageItem = packageItem->GetNext();
1381  }
1382 
1383  return m.release();
1384 }
1385 
1386 
1387 void EAGLE_PLUGIN::packageWire( MODULE* aModule, wxXmlNode* aTree ) const
1388 {
1389  EWIRE w( aTree );
1390  PCB_LAYER_ID layer = kicad_layer( w.layer );
1391 
1392  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1393  {
1394  wxLogMessage( wxString::Format(
1395  "Line on copper layer in package %s (%f mm, %f mm) (%f mm, %f mm)."
1396  "\nMoving to Dwgs.User layer",
1397  aModule->GetFPID().GetLibItemName().c_str(), w.x1.ToMm(), w.y1.ToMm(),
1398  w.x2.ToMm(), w.y2.ToMm() ) );
1399  layer = Dwgs_User;
1400  }
1401 
1402  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1403  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1404  int width = w.width.ToPcbUnits();
1405 
1406  // FIXME: the cap attribute is ignored because kicad can't create lines
1407  // with flat ends.
1408  EDGE_MODULE* dwg;
1409 
1410  if( !w.curve )
1411  {
1412  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1413 
1414  dwg->SetStart0( start );
1415  dwg->SetEnd0( end );
1416  }
1417  else
1418  {
1419  dwg = new EDGE_MODULE( aModule, S_ARC );
1420  wxPoint center = ConvertArcCenter( start, end, *w.curve );
1421 
1422  dwg->SetStart0( center );
1423  dwg->SetEnd0( start );
1424  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1425  }
1426 
1427  dwg->SetLayer( layer );
1428  dwg->SetWidth( width );
1429  dwg->SetDrawCoord();
1430 
1431  aModule->GraphicalItemsList().PushBack( dwg );
1432 }
1433 
1434 
1435 void EAGLE_PLUGIN::packagePad( MODULE* aModule, wxXmlNode* aTree ) const
1436 {
1437  // this is thru hole technology here, no SMDs
1438  EPAD e( aTree );
1439 
1440  D_PAD* pad = new D_PAD( aModule );
1441  aModule->PadsList().PushBack( pad );
1442  transferPad( e, pad );
1443 
1444  pad->SetDrillSize( wxSize( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() ) );
1445  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1446 
1447  if( e.shape )
1448  {
1449  switch( *e.shape )
1450  {
1451  case EPAD::ROUND:
1452  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1453  break;
1454 
1455  case EPAD::OCTAGON:
1456  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1457  // pad->SetShape( PAD_OCTAGON );
1458  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1459  break;
1460 
1461  case EPAD::LONG:
1462  pad->SetShape( PAD_SHAPE_OVAL );
1463  break;
1464 
1465  case EPAD::SQUARE:
1466  pad->SetShape( PAD_SHAPE_RECT );
1467  break;
1468 
1469  case EPAD::OFFSET:
1470  ; // don't know what to do here.
1471  }
1472  }
1473  else
1474  {
1475  // if shape is not present, our default is circle and that matches their default "round"
1476  }
1477 
1478  if( e.diameter )
1479  {
1480  int diameter = e.diameter->ToPcbUnits();
1481  pad->SetSize( wxSize( diameter, diameter ) );
1482  }
1483  else
1484  {
1485  double drillz = pad->GetDrillSize().x;
1486  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1487  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1488  int diameter = KiROUND( drillz + 2 * annulus );
1489  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1490  }
1491 
1492  if( pad->GetShape() == PAD_SHAPE_OVAL )
1493  {
1494  // The Eagle "long" pad is wider than it is tall,
1495  // m_elongation is percent elongation
1496  wxSize sz = pad->GetSize();
1497  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1498  pad->SetSize( sz );
1499  }
1500 
1501  if( e.rot )
1502  {
1503  pad->SetOrientation( e.rot->degrees * 10 );
1504  }
1505 }
1506 
1507 
1508 void EAGLE_PLUGIN::packageText( MODULE* aModule, wxXmlNode* aTree ) const
1509 {
1510  ETEXT t( aTree );
1511  PCB_LAYER_ID layer = kicad_layer( t.layer );
1512 
1513  if( IsCopperLayer( layer ) ) // skip copper texts
1514  {
1515  wxLogMessage( wxString::Format(
1516  "Unsupported text on copper layer in package %s.\nMoving to Dwgs.User layer.",
1517  aModule->GetFPID().GetLibItemName().c_str() ) );
1518  layer = Dwgs_User;
1519  }
1520 
1521  if( layer == UNDEFINED_LAYER )
1522  {
1523  layer = Cmts_User;
1524  }
1525 
1526  TEXTE_MODULE* txt;
1527 
1528  if( t.text == ">NAME" || t.text == ">name" )
1529  txt = &aModule->Reference();
1530  else if( t.text == ">VALUE" || t.text == ">value" )
1531  txt = &aModule->Value();
1532  else
1533  {
1534  // FIXME: graphical text items are rotated for some reason.
1535  txt = new TEXTE_MODULE( aModule );
1536  aModule->GraphicalItemsList().PushBack( txt );
1537  }
1538 
1539  txt->SetTimeStamp( EagleTimeStamp( aTree ) );
1540  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1541 
1542  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1543 
1544  txt->SetTextPos( pos );
1545  txt->SetPos0( pos - aModule->GetPosition() );
1546 
1547  txt->SetLayer( layer );
1548  txt->SetTextSize( kicad_fontz( t.size ) );
1549 
1550  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1551 
1552  txt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
1553 
1554  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1555 
1556  // An eagle package is never rotated, the DTD does not allow it.
1557  // angle -= aModule->GetOrienation();
1558 
1559  if( t.rot )
1560  {
1561  int sign = t.rot->mirror ? -1 : 1;
1562  txt->SetMirrored( t.rot->mirror );
1563 
1564  double degrees = t.rot->degrees;
1565 
1566  if( degrees == 90 || t.rot->spin )
1567  txt->SetTextAngle( sign * degrees * 10 );
1568  else if( degrees == 180 )
1569  align = ETEXT::TOP_RIGHT;
1570  else if( degrees == 270 )
1571  {
1572  align = ETEXT::TOP_RIGHT;
1573  txt->SetTextAngle( sign * 90 * 10 );
1574  }
1575  }
1576 
1577  switch( align )
1578  {
1579  case ETEXT::CENTER:
1580  // this was the default in pcbtxt's constructor
1581  break;
1582 
1583  case ETEXT::CENTER_LEFT:
1585  break;
1586 
1587  case ETEXT::CENTER_RIGHT:
1589  break;
1590 
1591  case ETEXT::TOP_CENTER:
1593  break;
1594 
1595  case ETEXT::TOP_LEFT:
1598  break;
1599 
1600  case ETEXT::TOP_RIGHT:
1603  break;
1604 
1605  case ETEXT::BOTTOM_CENTER:
1607  break;
1608 
1609  case ETEXT::BOTTOM_LEFT:
1612  break;
1613 
1614  case ETEXT::BOTTOM_RIGHT:
1617  break;
1618  }
1619 }
1620 
1621 
1622 void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const
1623 {
1624  ERECT r( aTree );
1625  PCB_LAYER_ID layer = kicad_layer( r.layer );
1626 
1627  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1628  {
1629  wxLogMessage( wxString::Format(
1630  "Unsupported rectangle on copper layer in package %s.\nMoving to Dwgs.User layer.",
1631  aModule->GetFPID().GetLibItemName().c_str() ) );
1632  layer = Dwgs_User;
1633  }
1634 
1635  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1636  aModule->GraphicalItemsList().PushBack( dwg );
1637 
1638  dwg->SetLayer( layer );
1639  dwg->SetWidth( 0 );
1640 
1641  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1642 
1643  std::vector<wxPoint> pts;
1644 
1645  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1646  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1647 
1648  pts.push_back( start );
1649  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1650  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1651  pts.push_back( end );
1652 
1653  dwg->SetPolyPoints( pts );
1654 
1655  dwg->SetStart0( start );
1656  dwg->SetEnd0( end );
1657 
1658  if( r.rot )
1659  {
1660  dwg->Rotate( dwg->GetCenter(), r.rot->degrees * 10 );
1661  }
1662 }
1663 
1664 
1665 void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const
1666 {
1667  EPOLYGON p( aTree );
1668  PCB_LAYER_ID layer = kicad_layer( p.layer );
1669 
1670  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1671  {
1672  wxLogMessage( wxString::Format(
1673  "Unsupported polygon on copper layer in package %s.\nMoving to Dwgs.User layer.",
1674  aModule->GetFPID().GetLibItemName().c_str() ) );
1675  layer = Dwgs_User;
1676  }
1677 
1678  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1679  aModule->GraphicalItemsList().PushBack( dwg );
1680 
1681  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1682  dwg->SetLayer( layer );
1683  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1684 
1685  std::vector<wxPoint> pts;
1686  // TODO: I think there's no way to know a priori the number of children in wxXmlNode :()
1687  // pts.reserve( aTree.size() );
1688 
1689  // Get the first vertex and iterate
1690  wxXmlNode* vertex = aTree->GetChildren();
1691  std::vector<EVERTEX> vertices;
1692 
1693  // Create a circular vector of vertices
1694  // The "curve" parameter indicates a curve from the current
1695  // to the next vertex, so we keep the first at the end as well
1696  // to allow the curve to link back
1697  while( vertex )
1698  {
1699  if( vertex->GetName() == "vertex" )
1700  vertices.push_back( EVERTEX( vertex ) );
1701 
1702  vertex = vertex->GetNext();
1703  }
1704 
1705  vertices.push_back( vertices[0] );
1706 
1707  for( size_t i = 0; i < vertices.size() - 1; i++ )
1708  {
1709  EVERTEX v1 = vertices[i];
1710 
1711  // Append the corner
1712  pts.push_back( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ) );
1713 
1714  if( v1.curve )
1715  {
1716  EVERTEX v2 = vertices[i + 1];
1717  wxPoint center = ConvertArcCenter(
1718  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1719  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1720  double angle = DEG2RAD( *v1.curve );
1721  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1722  kicad_x( v2.x ) - center.x );
1723  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1724  + pow( center.y - kicad_y( v1.y ), 2 ) );
1725 
1726  // If we are curving, we need at least 2 segments otherwise
1727  // delta_angle == angle
1728  double delta_angle = angle / std::max(
1729  2, GetArcToSegmentCount( KiROUND( radius ),
1730  ARC_HIGH_DEF, *v1.curve ) - 1 );
1731 
1732  for( double a = end_angle + angle;
1733  fabs( a - end_angle ) > fabs( delta_angle );
1734  a -= delta_angle )
1735  {
1736  pts.push_back(
1737  wxPoint( KiROUND( radius * cos( a ) ),
1738  KiROUND( radius * sin( a ) ) ) + center );
1739  }
1740  }
1741  }
1742 
1743  dwg->SetPolyPoints( pts );
1744  dwg->SetStart0( *pts.begin() );
1745  dwg->SetEnd0( pts.back() );
1746  dwg->SetDrawCoord();
1747 }
1748 
1749 
1750 void EAGLE_PLUGIN::packageCircle( MODULE* aModule, wxXmlNode* aTree ) const
1751 {
1752  ECIRCLE e( aTree );
1753  PCB_LAYER_ID layer = kicad_layer( e.layer );
1754 
1755  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1756  {
1757  wxLogMessage( wxString::Format(
1758  "Unsupported circle on copper layer in package %s.\nMoving to Dwgs.User layer.",
1759  aModule->GetFPID().GetLibItemName().c_str() ) );
1760  layer = Dwgs_User;
1761  }
1762 
1763  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1764 
1765  aModule->GraphicalItemsList().PushBack( gr );
1766 
1767  gr->SetWidth( e.width.ToPcbUnits() );
1768 
1769  switch( (int) layer )
1770  {
1771  case UNDEFINED_LAYER: layer = Cmts_User; break;
1772  /*
1773  case Eco1_User: layer = F_SilkS; break;
1774  case Eco2_User: layer = B_SilkS; break;
1775  */
1776  default:
1777  break;
1778  }
1779 
1780  gr->SetLayer( layer );
1781  gr->SetTimeStamp( EagleTimeStamp( aTree ) );
1782  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1783  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
1784  gr->SetDrawCoord();
1785 }
1786 
1787 
1788 void EAGLE_PLUGIN::packageHole( MODULE* aModule, wxXmlNode* aTree ) const
1789 {
1790  EHOLE e( aTree );
1791 
1792  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1793  D_PAD* pad = new D_PAD( aModule );
1794  aModule->PadsList().PushBack( pad );
1795 
1796  pad->SetShape( PAD_SHAPE_CIRCLE );
1798 
1799  // Mechanical purpose only:
1800  // no offset, no net name, no pad name allowed
1801  // pad->SetOffset( wxPoint( 0, 0 ) );
1802  // pad->SetName( wxEmptyString );
1803 
1804  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1805 
1806  pad->SetPos0( padpos );
1807  pad->SetPosition( padpos + aModule->GetPosition() );
1808 
1809  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
1810 
1811  pad->SetDrillSize( sz );
1812  pad->SetSize( sz );
1813 
1814  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
1815 }
1816 
1817 
1818 void EAGLE_PLUGIN::packageSMD( MODULE* aModule, wxXmlNode* aTree ) const
1819 {
1820  ESMD e( aTree );
1821  PCB_LAYER_ID layer = kicad_layer( e.layer );
1822 
1823  if( !IsCopperLayer( layer ) )
1824  return;
1825 
1826  D_PAD* pad = new D_PAD( aModule );
1827  aModule->PadsList().PushBack( pad );
1828  transferPad( e, pad );
1829 
1830  pad->SetShape( PAD_SHAPE_RECT );
1831  pad->SetAttribute( PAD_ATTRIB_SMD );
1832 
1833  wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
1834  pad->SetSize( padSize );
1835  pad->SetLayer( layer );
1836 
1837  const LSET front( 3, F_Cu, F_Paste, F_Mask );
1838  const LSET back( 3, B_Cu, B_Paste, B_Mask );
1839 
1840  if( layer == F_Cu )
1841  pad->SetLayerSet( front );
1842  else if( layer == B_Cu )
1843  pad->SetLayerSet( back );
1844 
1845  int minPadSize = std::min( padSize.x, padSize.y );
1846 
1847  // Rounded rectangle pads
1848  int roundRadius = Clamp( m_rules->srMinRoundness * 2,
1849  (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
1850 
1851  if( e.roundness || roundRadius > 0 )
1852  {
1853  double roundRatio = (double) roundRadius / minPadSize / 2.0;
1854 
1855  // Eagle uses a different definition of roundness, hence division by 200
1856  if( e.roundness )
1857  roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
1858 
1859  pad->SetShape( PAD_SHAPE_ROUNDRECT );
1860  pad->SetRoundRectRadiusRatio( roundRatio );
1861  }
1862 
1863  if( e.rot )
1864  {
1865  pad->SetOrientation( e.rot->degrees * 10 );
1866  }
1867 
1869  (int) ( m_rules->mvCreamFrame * minPadSize ),
1870  m_rules->mlMaxCreamFrame ) );
1871 
1872  // Solder paste (only for SMD pads)
1873  if( e.cream && *e.cream == false ) // enabled by default
1874  {
1875  if( layer == F_Cu )
1876  pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
1877  else if( layer == B_Cu )
1878  pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
1879  }
1880 }
1881 
1882 
1883 void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const
1884 {
1885  aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) );
1886 
1887  // pad's "Position" is not relative to the module's,
1888  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1889  wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
1890  aPad->SetPos0( padPos );
1891 
1892  // Solder mask
1893  const wxSize& padSize( aPad->GetSize() );
1894 
1895  if( !aEaglePad.stop || !*aEaglePad.stop ) // enabled by default
1896  {
1898  (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
1899  m_rules->mlMaxStopFrame ) );
1900  }
1901 
1902  // Solid connection to copper zones
1903  if( aEaglePad.thermals && !*aEaglePad.thermals )
1905 
1906  MODULE* module = aPad->GetParent();
1907  wxCHECK( module, /* void */ );
1908  RotatePoint( &padPos, module->GetOrientation() );
1909  aPad->SetPosition( padPos + module->GetPosition() );
1910 }
1911 
1912 
1914 {
1915  for( auto& t : m_templates )
1916  delete t.second;
1917 
1918  m_templates.clear();
1919 }
1920 
1921 
1922 void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
1923 {
1924  ZONES zones; // per net
1925 
1926  m_xpath->push( "signals.signal", "name" );
1927 
1928  int netCode = 1;
1929 
1930  // Get the first signal and iterate
1931  wxXmlNode* net = aSignals->GetChildren();
1932 
1933  while( net )
1934  {
1935  bool sawPad = false;
1936 
1937  zones.clear();
1938 
1939  const wxString& netName = escapeName( net->GetAttribute( "name" ) );
1940  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
1941 
1942  m_xpath->Value( netName.c_str() );
1943 
1944  // Get the first net item and iterate
1945  wxXmlNode* netItem = net->GetChildren();
1946 
1947  // (contactref | polygon | wire | via)*
1948  while( netItem )
1949  {
1950  const wxString& itemName = netItem->GetName();
1951 
1952  if( itemName == "wire" )
1953  {
1954  m_xpath->push( "wire" );
1955 
1956  EWIRE w( netItem );
1957  PCB_LAYER_ID layer = kicad_layer( w.layer );
1958 
1959  if( IsCopperLayer( layer ) )
1960  {
1961  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1962  double angle = 0.0;
1963  double end_angle = 0.0;
1964  double radius = 0.0;
1965  double delta_angle = 0.0;
1966  wxPoint center;
1967 
1968  int width = w.width.ToPcbUnits();
1969  if( width < m_min_trace )
1970  m_min_trace = width;
1971 
1972  if( w.curve )
1973  {
1974  center = ConvertArcCenter(
1975  wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
1976  wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
1977  *w.curve );
1978 
1979  angle = DEG2RAD( *w.curve );
1980 
1981  end_angle = atan2( kicad_y( w.y2 ) - center.y,
1982  kicad_x( w.x2 ) - center.x );
1983 
1984  radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
1985  pow( center.y - kicad_y( w.y1 ), 2 ) );
1986 
1987  // If we are curving, we need at least 2 segments otherwise
1988  // delta_angle == angle
1989  int segments = std::max( 2, GetArcToSegmentCount( KiROUND( radius ),
1990  ARC_HIGH_DEF, *w.curve ) - 1 );
1991  delta_angle = angle / segments;
1992  }
1993 
1994  while( fabs( angle ) > fabs( delta_angle ) )
1995  {
1996  wxASSERT( radius > 0.0 );
1997  wxPoint end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
1998  KiROUND( radius * sin( end_angle + angle ) + center.y ) );
1999 
2000  TRACK* t = new TRACK( m_board );
2001 
2002  t->SetTimeStamp( EagleTimeStamp( netItem ) + int( RAD2DEG( angle ) ) );
2003  t->SetPosition( start );
2004  t->SetEnd( end );
2005  t->SetWidth( width );
2006  t->SetLayer( layer );
2007  t->SetNetCode( netCode );
2008 
2009  m_board->m_Track.PushBack( t );
2010 
2011  start = end;
2012  angle -= delta_angle;
2013  }
2014 
2015  TRACK* t = new TRACK( m_board );
2016 
2017  t->SetTimeStamp( EagleTimeStamp( netItem ) );
2018  t->SetPosition( start );
2019  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2020  t->SetWidth( width );
2021  t->SetLayer( layer );
2022  t->SetNetCode( netCode );
2023 
2024  m_board->m_Track.PushBack( t );
2025  }
2026  else
2027  {
2028  // put non copper wires where the sun don't shine.
2029  }
2030 
2031  m_xpath->pop();
2032  }
2033 
2034  else if( itemName == "via" )
2035  {
2036  m_xpath->push( "via" );
2037  EVIA v( netItem );
2038 
2039  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2040  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2041 
2042  if( IsCopperLayer( layer_front_most ) &&
2043  IsCopperLayer( layer_back_most ) )
2044  {
2045  int kidiam;
2046  int drillz = v.drill.ToPcbUnits();
2047  VIA* via = new VIA( m_board );
2048  m_board->m_Track.PushBack( via );
2049 
2050  via->SetLayerPair( layer_front_most, layer_back_most );
2051 
2052  if( v.diam )
2053  {
2054  kidiam = v.diam->ToPcbUnits();
2055  via->SetWidth( kidiam );
2056  }
2057  else
2058  {
2059  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2060  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
2061  kidiam = KiROUND( drillz + 2 * annulus );
2062  via->SetWidth( kidiam );
2063  }
2064 
2065  via->SetDrill( drillz );
2066 
2067  // make sure the via diameter respects the restring rules
2068 
2069  if( !v.diam || via->GetWidth() <= via->GetDrill() )
2070  {
2071  double annulus = Clamp( m_rules->rlMinViaOuter,
2072  (double)( via->GetWidth() / 2 - via->GetDrill() ), m_rules->rlMaxViaOuter );
2073  via->SetWidth( drillz + 2 * annulus );
2074  }
2075 
2076  if( kidiam < m_min_via )
2077  m_min_via = kidiam;
2078 
2079  if( drillz < m_min_via_hole )
2080  m_min_via_hole = drillz;
2081 
2082  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2083  via->SetViaType( VIA_THROUGH );
2084  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2085  via->SetViaType( VIA_MICROVIA );
2086  else
2087  via->SetViaType( VIA_BLIND_BURIED );
2088 
2089  via->SetTimeStamp( EagleTimeStamp( netItem ) );
2090 
2091  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2092 
2093  via->SetPosition( pos );
2094  via->SetEnd( pos );
2095 
2096  via->SetNetCode( netCode );
2097  }
2098 
2099  m_xpath->pop();
2100  }
2101 
2102  else if( itemName == "contactref" )
2103  {
2104  m_xpath->push( "contactref" );
2105  // <contactref element="RN1" pad="7"/>
2106 
2107  const wxString& reference = netItem->GetAttribute( "element" );
2108  const wxString& pad = netItem->GetAttribute( "pad" );
2109  wxString key = makeKey( reference, pad ) ;
2110 
2111  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, netName.c_str() );)
2112 
2113  m_pads_to_nets[ key ] = ENET( netCode, netName );
2114 
2115  m_xpath->pop();
2116 
2117  sawPad = true;
2118  }
2119 
2120  else if( itemName == "polygon" )
2121  {
2122  m_xpath->push( "polygon" );
2123  auto* zone = loadPolygon( netItem );
2124 
2125  if( zone )
2126  {
2127  zones.push_back( zone );
2128 
2129  if( !zone->GetIsKeepout() )
2130  zone->SetNetCode( netCode );
2131  }
2132 
2133  m_xpath->pop(); // "polygon"
2134  }
2135 
2136  netItem = netItem->GetNext();
2137  }
2138 
2139  if( zones.size() && !sawPad )
2140  {
2141  // KiCad does not support an unconnected zone with its own non-zero netcode,
2142  // but only when assigned netcode = 0 w/o a name...
2143  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2144  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2145 
2146  // therefore omit this signal/net.
2147  }
2148  else
2149  netCode++;
2150 
2151  // Get next signal
2152  net = net->GetNext();
2153  }
2154 
2155  m_xpath->pop(); // "signals.signal"
2156 }
2157 
2158 
2159 PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
2160 {
2161  int kiLayer;
2162 
2163  // eagle copper layer:
2164  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
2165  {
2166  kiLayer = m_cu_map[aEagleLayer];
2167  }
2168 
2169  else
2170  {
2171  // translate non-copper eagle layer to pcbnew layer
2172  switch( aEagleLayer )
2173  {
2174  // Eagle says "Dimension" layer, but it's for board perimeter
2175  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
2176  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
2177  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
2178  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
2179  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
2180  case EAGLE_LAYER::TVALUES: kiLayer = F_SilkS; break;
2181  case EAGLE_LAYER::BVALUES: kiLayer = B_SilkS; break;
2182  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
2183  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
2184  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
2185  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
2186  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
2187  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
2188  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
2189  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
2190  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
2191  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
2192  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
2193 
2194  // Packages show the future chip pins on SMD parts using layer 51.
2195  // This is an area slightly smaller than the PAD/SMD copper area.
2196  // Carry those visual aids into the MODULE on the fabrication layer,
2197  // not silkscreen. This is perhaps not perfect, but there is not a lot
2198  // of other suitable paired layers
2199  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
2200  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
2201 
2202  // thes layers are defined as user layers. put them on ECO layers
2203  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
2204  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
2205 
2206  case EAGLE_LAYER::UNROUTED:
2207  case EAGLE_LAYER::TKEEPOUT:
2208  case EAGLE_LAYER::BKEEPOUT:
2209  case EAGLE_LAYER::TTEST:
2210  case EAGLE_LAYER::BTEST:
2211  case EAGLE_LAYER::MILLING:
2212  case EAGLE_LAYER::HOLES:
2213  default:
2214  // some layers do not map to KiCad
2215  wxLogMessage( wxString::Format( "Unsupported Eagle layer '%s' (%d), converted to Dwgs.User layer",
2216  eagle_layer_name( aEagleLayer ), aEagleLayer ) );
2217 
2218  kiLayer = Dwgs_User;
2219  break;
2220  }
2221  }
2222 
2223  return PCB_LAYER_ID( kiLayer );
2224 }
2225 
2226 
2227 const wxString& EAGLE_PLUGIN::eagle_layer_name( int aLayer ) const
2228 {
2229  static const wxString unknown( "unknown" );
2230  auto it = m_eagleLayers.find( aLayer );
2231  return it == m_eagleLayers.end() ? unknown : it->second.name;
2232 }
2233 
2234 
2236 {
2237  if( m_props )
2238  {
2239  UTF8 page_width;
2240  UTF8 page_height;
2241 
2242  if( m_props->Value( "page_width", &page_width ) &&
2243  m_props->Value( "page_height", &page_height ) )
2244  {
2246 
2247  int w = atoi( page_width.c_str() );
2248  int h = atoi( page_height.c_str() );
2249 
2250  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2251  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2252 
2253  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2254  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2255 
2256  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2257  }
2258  }
2259 }
2260 
2261 
2262 wxDateTime EAGLE_PLUGIN::getModificationTime( const wxString& aPath )
2263 {
2264  // File hasn't been loaded yet.
2265  if( aPath.IsEmpty() )
2266  return wxDateTime::Now();
2267 
2268  wxFileName fn( aPath );
2269 
2270  if( fn.IsFileReadable() )
2271  return fn.GetModificationTime();
2272  else
2273  return wxDateTime( 0.0 );
2274 }
2275 
2276 
2277 void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
2278 {
2279  try
2280  {
2281  wxDateTime modtime = getModificationTime( aLibPath );
2282 
2283  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2284  // cache if either of the wxDateTime objects are invalid or the last file modification
2285  // time differs from the current file modification time.
2286  bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
2287 
2288  if( aLibPath != m_lib_path || load )
2289  {
2290  wxXmlNode* doc;
2291  LOCALE_IO toggle; // toggles on, then off, the C locale.
2292 
2293  deleteTemplates();
2294 
2295  // Set this before completion of loading, since we rely on it for
2296  // text of an exception. Delay setting m_mod_time until after successful load
2297  // however.
2298  m_lib_path = aLibPath;
2299 
2300  // 8 bit "filename" should be encoded according to disk filename encoding,
2301  // (maybe this is current locale, maybe not, its a filesystem issue),
2302  // and is not necessarily utf8.
2303  string filename = (const char*) aLibPath.char_str( wxConvFile );
2304 
2305  // Load the document
2306  wxXmlDocument xmlDocument;
2307  wxFileName fn( filename );
2308 
2309  if( !xmlDocument.Load( fn.GetFullPath() ) )
2310  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
2311  fn.GetFullPath() ) );
2312 
2313  doc = xmlDocument.GetRoot();
2314 
2315  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2316  NODE_MAP drawingChildren = MapChildren( drawing );
2317 
2318  // clear the cu map and then rebuild it.
2319  clear_cu_map();
2320 
2321  m_xpath->push( "eagle.drawing.layers" );
2322  wxXmlNode* layers = drawingChildren["layers"];
2323  loadLayerDefs( layers );
2324  m_xpath->pop();
2325 
2326  m_xpath->push( "eagle.drawing.library" );
2327  wxXmlNode* library = drawingChildren["library"];
2328  loadLibrary( library, NULL );
2329  m_xpath->pop();
2330 
2331  m_mod_time = modtime;
2332  }
2333  }
2334  catch(...){}
2335  // TODO: Handle exceptions
2336  // catch( file_parser_error fpe )
2337  // {
2338  // // for xml_parser_error, what() has the line number in it,
2339  // // but no byte offset. That should be an adequate error message.
2340  // THROW_IO_ERROR( fpe.what() );
2341  // }
2342  //
2343  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2344  // // so one catch should be OK for all errors.
2345  // catch( ptree_error pte )
2346  // {
2347  // string errmsg = pte.what();
2348  //
2349  // errmsg += " @\n";
2350  // errmsg += m_xpath->Contents();
2351  //
2352  // THROW_IO_ERROR( errmsg );
2353  // }
2354 }
2355 
2356 
2357 void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
2358  const PROPERTIES* aProperties )
2359 {
2360  init( aProperties );
2361 
2362  cacheLib( aLibraryPath );
2363 
2364  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2365  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2366 }
2367 
2368 
2369 MODULE* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
2370  const PROPERTIES* aProperties )
2371 {
2372  init( aProperties );
2373  cacheLib( aLibraryPath );
2374  MODULE_CITER mi = m_templates.find( aFootprintName );
2375 
2376  if( mi == m_templates.end() )
2377  return NULL;
2378 
2379  // copy constructor to clone the template
2380  MODULE* ret = new MODULE( *mi->second );
2381 
2382  return ret;
2383 }
2384 
2385 
2386 void EAGLE_PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
2387 {
2388  PLUGIN::FootprintLibOptions( aListToAppendTo );
2389 
2390  /*
2391  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2392  "Ignore duplicately named footprints within the same Eagle library. "
2393  "Only the first similarly named footprint will be loaded."
2394  ));
2395  */
2396 }
2397 
2398 
2399 /*
2400 void EAGLE_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
2401 {
2402  // Eagle lovers apply here.
2403 }
2404 
2405 
2406 void EAGLE_PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties )
2407 {
2408 }
2409 
2410 
2411 void EAGLE_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName )
2412 {
2413 }
2414 
2415 
2416 void EAGLE_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
2417 {
2418 }
2419 
2420 
2421 bool EAGLE_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
2422 {
2423 }
2424 
2425 
2426 bool EAGLE_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
2427 {
2428  return true;
2429 }
2430 
2431 */
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:610
wxString Contents()
return the contents of the XPATH as a single string
Definition: eagle_parser.h:139
Eagle vertex.
Definition: eagle_parser.h:745
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:673
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
#define DIM(x)
of elements in an array
Definition: macros.h:98
MODULE_MAP::iterator MODULE_ITER
void SetEnd0(const wxPoint &aPoint)
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:71
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool mirror
Definition: eagle_parser.h:480
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:516
void SetTextAngle(double aAngle)
TEXTE_MODULE & Reference()
Definition: class_module.h:502
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...
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
void SetShape(STROKE_T aShape)
NETCLASSPTR GetDefault() const
Function GetDefault.
opt_int rank
Definition: eagle_parser.h:778
void clear_cu_map()
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
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:179
TEXTE_PCB class definition.
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:459
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:106
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
opt_ecoord diam
Definition: eagle_parser.h:562
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:431
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void packageHole(MODULE *aModule, wxXmlNode *aTree) const
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:118
void clear()
Definition: eagle_parser.h:122
const wxPoint GetCenter() const override
Function GetCenter()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
int m_PcbTextWidth
current Pcb (not module) Text width
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
float ToMm() const
Definition: eagle_parser.h:432
ECOORD drill
< inclusive
Definition: eagle_parser.h:561
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Class BOARD to handle a board.
ECOORD y
Definition: eagle_parser.h:748
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
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.
Definition: eagle_parser.h:796
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.
Definition: eagle_parser.h:112
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
double RAD2DEG(double rad)
Definition: trigo.h:200
ECOORD x2
Definition: eagle_parser.h:587
MODULE * GetParent() const
Definition: class_pad.h:162
static const int max_priority
Definition: eagle_parser.h:767
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:67
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
void SetVisible(bool aVisible)
Definition: eda_text.h:173
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
opt_double ratio
Definition: eagle_parser.h:653
int GetHeight() const
Definition: eda_rect.h:118
int number
Definition: eagle_parser.h:814
void SetCopperLayerCount(int aCount)
opt_erot rot
Definition: eagle_parser.h:806
static int parseEagle(const wxString &aDistance)
Parse an eagle distance which is either mm, or mils if there is "mil" suffix.
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:60
ECOORD width
Definition: eagle_parser.h:505
opt_bool thermals
Definition: eagle_parser.h:777
void packageText(MODULE *aModule, wxXmlNode *aTree) const
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:570
opt_bool smashed
Definition: eagle_parser.h:805
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
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...
Template specialization to enable wxStrings for certain containers (e.g. unordered_map) ...
Definition: bitmap.cpp:54
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:486
usual segment : line with rounded ends
void parse(wxXmlNode *aRules)
wxString name
Definition: eagle_parser.h:682
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:186
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:41
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
opt_erot rot
Definition: eagle_parser.h:590
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
double degrees
Definition: eagle_parser.h:482
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
ECOORD width
Definition: eagle_parser.h:758
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
Eagle SMD pad.
Definition: eagle_parser.h:714
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
ECOORD y
Definition: eagle_parser.h:573
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
void SetRoundRectRadiusRatio(double aRadiusScale)
has meaning only for rounded rect pads Set the scaling factor between the smaller Y or Y size and the...
Definition: class_pad.h:633
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:182
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:69
ECOORD y
Definition: eagle_parser.h:803
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.
Definition: eagle_parser.h:785
Class XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown ...
Definition: eagle_parser.h:70
const wxPoint GetPosition() const override
Function GetPosition.
Definition: class_zone.cpp:169
Eagle text element.
Definition: eagle_parser.h:645
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
#define abs(a)
Definition: auxiliary.h:84
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:473
void loadLayerDefs(wxXmlNode *aLayers)
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
opt_erot rot
Definition: eagle_parser.h:611
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
opt_bool thermals
Definition: eagle_parser.h:686
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
ECOORD width
Definition: eagle_parser.h:575
ECOORD x
Definition: eagle_parser.h:572
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:166
double GetTextAngle() const
Definition: eda_text.h:162
Functions relatives to tracks, vias and segments used to fill zones.
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:162
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:609
This file contains miscellaneous commonly used macros and functions.
void SetWidth(int aWidth)
Definition: class_track.h:115
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
Definition: eagle_parser.h:378
int layer_back_most
< extent
Definition: eagle_parser.h:560
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:798
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:95
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
ECOORD dy
Definition: eagle_parser.h:717
const LIB_ID & GetFPID() const
Definition: class_module.h:191
opt_ecoord isolate
Definition: eagle_parser.h:775
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
DIMENSION class definition.
wxString name
Definition: eagle_parser.h:604
PCB_LAYER_ID
A quick note on layer IDs:
ECOORD y1
Definition: eagle_parser.h:502
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:183
static wxString makeKey(const wxString &aFirst, const wxString &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
wxString value
Definition: eagle_parser.h:801
Class LSET is a set of PCB_LAYER_IDs.
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:178
ECOORD x
Definition: eagle_parser.h:787
LAYER_NUM layer
Definition: eagle_parser.h:506
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:163
opt_ecoord y
Definition: eagle_parser.h:607
void SetZoneConnection(ZoneConnection aType)
Definition: class_pad.h:482
int layer
Definition: eagle_parser.h:589
Eagle thru hole pad.
Definition: eagle_parser.h:693
opt_ecoord spacing
Definition: eagle_parser.h:760
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
double GetOrientation() const
Definition: class_module.h:187
wxString name
Definition: eagle_parser.h:798
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
wxSize m_PcbTextSize
current Pcb (not module) Text size
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
int m_TrackMinWidth
track min value for width ((min copper size value
ECOORD y1
Definition: eagle_parser.h:586
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
Arcs (with rounded ends)
int m_ViasMinSize
vias (not micro vias) min diameter
Eagle circle.
Definition: eagle_parser.h:570
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
ECOORD dx
Definition: eagle_parser.h:716
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
wxString m_lib_path
Definition: eagle_plugin.h:185
int m_ViasMinDrill
vias (not micro vias) min drill diameter
D_PAD * Next() const
Definition: class_pad.h:160
void Rotate(const wxPoint &centre, double angle) override
Function Rotate Move the outlines.
Definition: class_zone.cpp:927
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:202
ECOORD x
Definition: eagle_parser.h:648
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
const wxSize & GetSize() const
Definition: class_pad.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:533
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
a few functions useful in geometry calculations.
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
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...
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:468
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:67
void SetFileName(const wxString &aFileName)
Definition: class_board.h:232
ECOORD size
Definition: eagle_parser.h:650
void SetPosition(const wxPoint &aPos) override
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:193
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
int layer
Definition: eagle_parser.h:718
static wxDateTime getModificationTime(const wxString &aPath)
get a file&#39;s or dir&#39;s modification time.
opt_wxString value
Definition: eagle_parser.h:605
int ToPcbUnits() const
Definition: eagle_parser.h:438
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:72
wxString text
Definition: eagle_parser.h:647
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:181
ECOORD x
Definition: eagle_parser.h:802
opt_int roundness
Definition: eagle_parser.h:719
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:169
LAYER_NUM layer
Definition: eagle_parser.h:576
Eagle XML rectangle in binary.
Definition: eagle_parser.h:583
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:59
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
opt_int align
Definition: eagle_parser.h:670
Eagle net.
Definition: eagle_parser.h:461
void SetPos0(const wxPoint &aPos)
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:47
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:749
#define DEFAULT_PCB_EDGE_THICKNESS
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:180
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
ECOORD y2
Definition: eagle_parser.h:504
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:608
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:602
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
opt_ecoord x
Definition: eagle_parser.h:606
Eagle via.
Definition: eagle_parser.h:555
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:159
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
ECOORD x1
Definition: eagle_parser.h:585
opt_wxString dimensionType
Definition: eagle_parser.h:638
MODULE_MAP::const_iterator MODULE_CITER
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:56
opt_erot rot
Definition: eagle_parser.h:654
int netcode
Definition: eagle_parser.h:463
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
void loadElements(wxXmlNode *aElements)
const char * name
Definition: DXF_plotter.cpp:61
ECOORD x
Definition: eagle_parser.h:747
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
opt_ecoord diameter
Definition: eagle_parser.h:696
double DEG2RAD(double deg)
Definition: trigo.h:199
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:458
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_pad.h:411
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:680
bool IsMirrored() const
Definition: eda_text.h:177
int GetWidth() const
Definition: class_track.h:116
void SetOrientation(double newangle)
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:112
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
const char * c_str() const
Definition: utf8.h:107
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:173
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
TEXTE_PCB & Text()
size_t i
Definition: json11.cpp:597
ECOORD radius
Definition: eagle_parser.h:574
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:160
wxDateTime m_mod_time
Definition: eagle_plugin.h:186
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:466
void SetStart0(const wxPoint &aPoint)
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:495
opt_double ratio
Definition: eagle_parser.h:610
opt_erot rot
Definition: eagle_parser.h:684
int GetX() const
Definition: eda_rect.h:109
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:52
ECOORD y
Definition: eagle_parser.h:558
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:503
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:171
The common library.
int GetWidth() const
Definition: eda_rect.h:117
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
int GetY() const
Definition: eda_rect.h:110
void SetEnd(const wxPoint &aEnd)
Eagle wire.
Definition: eagle_parser.h:499
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:401
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.
ECOORD x
Definition: eagle_parser.h:557
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_pad.h:417
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
opt_int shape
Definition: eagle_parser.h:706
#define DBG(x)
Definition: fctsys.h:33
Eagle dimension element.
Definition: eagle_parser.h:628
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:63
wxString package
Definition: eagle_parser.h:800
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
void deleteTemplates()
Deletes the footprint templates list
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
void SetTextAngle(double aAngle)
DLIST< TRACK > m_Track
Definition: class_board.h:246
bool spin
Definition: eagle_parser.h:481
Module description (excepted pads)
const wxSize & GetTextSize() const
Definition: eda_text.h:213
ECOORD y2
Definition: eagle_parser.h:588
ECOORD y
Definition: eagle_parser.h:649
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:756
opt_int display
Definition: eagle_parser.h:619
void pop()
Definition: eagle_parser.h:124
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:607
std::vector< ZONE_CONTAINER * > ZONES
Definition: eagle_plugin.h:39
void loadDesignRules(wxXmlNode *aDesignRules)
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:196
ECOORD drill
Definition: eagle_parser.h:695
void SetWidth(int aWidth)
ECOORD y
Definition: eagle_parser.h:788
EDGE_MODULE class definition.
opt_bool stop
Definition: eagle_parser.h:685
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
int layer
Definition: eagle_parser.h:651
ECOORD x1
Definition: eagle_parser.h:501
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:199
wxString library
Definition: eagle_parser.h:799
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:66
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:70
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:131
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
ECOORD drill
Definition: eagle_parser.h:789
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
const wxPoint GetPosition() const override
Definition: class_module.h:182
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:57
Use thermal relief for pads.
Definition: zones.h:58
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:177
MODULE * makeModule(wxXmlNode *aPackage, const wxString &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
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...
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:61
Class DIMENSION.
opt_bool active
Definition: eagle_parser.h:819
ECOORD x2
Definition: eagle_parser.h:503
void loadSignals(wxXmlNode *aSignals)
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
opt_ecoord size
Definition: eagle_parser.h:608
#define min(a, b)
Definition: auxiliary.h:85
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
pads are covered by copper
Definition: zones.h:59
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
int layer_front_most
Definition: eagle_parser.h:559
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:53
opt_bool cream
Definition: eagle_parser.h:720
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
void SetWidth(int aWidth)