KiCad PCB EDA Suite
export_gencad.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) 2016 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #include <build_version.h>
33 #include <class_board.h>
34 #include <class_edge_mod.h>
35 #include <class_module.h>
36 #include <class_track.h>
37 #include <confirm.h>
39 #include <fctsys.h>
40 #include <hash_eda.h>
41 #include <pcb_edit_frame.h>
42 #include <pcbnew_settings.h>
43 #include <pgm_base.h>
44 #include <project/project_file.h> // LAST_PATH_TYPE
45 
46 static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* frame );
47 static void CreateArtworksSection( FILE* aFile );
48 static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb );
49 static void CreateBoardSection( FILE* aFile, BOARD* aPcb );
50 static void CreateComponentsSection( FILE* aFile, BOARD* aPcb );
51 static void CreateDevicesSection( FILE* aFile, BOARD* aPcb );
52 static void CreateRoutesSection( FILE* aFile, BOARD* aPcb );
53 static void CreateSignalsSection( FILE* aFile, BOARD* aPcb );
54 static void CreateShapesSection( FILE* aFile, BOARD* aPcb );
55 static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb );
56 static void FootprintWriteShape( FILE* File, MODULE* module, const wxString& aShapeName );
57 
58 // layer names for Gencad export
59 
60 static std::string GenCADLayerName( int aCuCount, PCB_LAYER_ID aId )
61 {
62  if( IsCopperLayer( aId ) )
63  {
64  if( aId == F_Cu )
65  return "TOP";
66  else if( aId == B_Cu )
67  return "BOTTOM";
68  else if( aId <= 14 )
69  return StrPrintf( "INNER%d", aCuCount - aId - 1 );
70  else
71  return StrPrintf( "LAYER%d", aId );
72  }
73 
74  else
75  {
76  const char* txt;
77 
78  // using a switch to clearly show mapping & catch out of bounds index.
79  switch( aId )
80  {
81  // Technicals
82  case B_Adhes: txt = "B.Adhes"; break;
83  case F_Adhes: txt = "F.Adhes"; break;
84  case B_Paste: txt = "SOLDERPASTE_BOTTOM"; break;
85  case F_Paste: txt = "SOLDERPASTE_TOP"; break;
86  case B_SilkS: txt = "SILKSCREEN_BOTTOM"; break;
87  case F_SilkS: txt = "SILKSCREEN_TOP"; break;
88  case B_Mask: txt = "SOLDERMASK_BOTTOM"; break;
89  case F_Mask: txt = "SOLDERMASK_TOP"; break;
90 
91  // Users
92  case Dwgs_User: txt = "Dwgs.User"; break;
93  case Cmts_User: txt = "Cmts.User"; break;
94  case Eco1_User: txt = "Eco1.User"; break;
95  case Eco2_User: txt = "Eco2.User"; break;
96  case Edge_Cuts: txt = "Edge.Cuts"; break;
97  case Margin: txt = "Margin"; break;
98 
99  // Footprint
100  case F_CrtYd: txt = "F_CrtYd"; break;
101  case B_CrtYd: txt = "B_CrtYd"; break;
102  case F_Fab: txt = "F_Fab"; break;
103  case B_Fab: txt = "B_Fab"; break;
104 
105  default:
106  wxASSERT_MSG( 0, wxT( "aId UNEXPECTED" ) );
107  txt = "BAD-INDEX!"; break;
108  }
109 
110  return txt;
111  }
112 }
113 
114 
115 static const PCB_LAYER_ID gc_seq[] = {
116  B_Cu,
117  In30_Cu,
118  In29_Cu,
119  In28_Cu,
120  In27_Cu,
121  In26_Cu,
122  In25_Cu,
123  In24_Cu,
124  In23_Cu,
125  In22_Cu,
126  In21_Cu,
127  In20_Cu,
128  In19_Cu,
129  In18_Cu,
130  In17_Cu,
131  In16_Cu,
132  In15_Cu,
133  In14_Cu,
134  In13_Cu,
135  In12_Cu,
136  In11_Cu,
137  In10_Cu,
138  In9_Cu,
139  In8_Cu,
140  In7_Cu,
141  In6_Cu,
142  In5_Cu,
143  In4_Cu,
144  In3_Cu,
145  In2_Cu,
146  In1_Cu,
147  F_Cu,
148 };
149 
150 
151 // flipped layer name for Gencad export (to make CAM350 imports correct)
152 static std::string GenCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
153 {
154  if( 1<= aId && aId <= 14 )
155  return StrPrintf( "INNER%d", 14 - aId );
156 
157  return GenCADLayerName( aCuCount, aId );
158 }
159 
160 
161 static wxString escapeString( const wxString& aString )
162 {
163  wxString copy( aString );
164  copy.Replace( "\"", "\\\"" );
165  return copy;
166 }
167 
168 
169 static std::string fmt_mask( LSET aSet )
170 {
171  return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
172 }
173 
174 // Export options
175 static bool flipBottomPads;
176 static bool uniquePins;
177 static bool individualShapes;
178 static bool storeOriginCoords;
179 
180 // These are the export origin (the auxiliary axis)
182 
183 // Association between shape names (using shapeName index) and components
184 static std::map<MODULE*, int> componentShapes;
185 static std::map<int, wxString> shapeNames;
186 
187 static const wxString getShapeName( MODULE* aModule )
188 {
189  static const wxString invalid( "invalid" );
190 
191  if( individualShapes )
192  return aModule->GetReference();
193 
194  auto itShape = componentShapes.find( aModule );
195  wxCHECK( itShape != componentShapes.end(), invalid );
196 
197  auto itName = shapeNames.find( itShape->second );
198  wxCHECK( itName != shapeNames.end(), invalid );
199 
200  return itName->second;
201 }
202 
203 // GerbTool chokes on units different than INCH so this is the conversion factor
204 const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS;
205 
206 /* Two helper functions to calculate coordinates of modules in gencad values
207  * (GenCAD Y axis from bottom to top)
208  */
209 static double MapXTo( int aX )
210 {
211  return (aX - GencadOffsetX) / SCALE_FACTOR;
212 }
213 
214 
215 static double MapYTo( int aY )
216 {
217  return (GencadOffsetY - aY) / SCALE_FACTOR;
218 }
219 
220 
221 /* Driver function: processing starts here */
222 void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
223 {
224  // Build default output file name
225  wxString path = GetLastPath( LAST_PATH_GENCAD );
226 
227  if( path.IsEmpty() )
228  {
229  wxFileName brdFile = GetBoard()->GetFileName();
230  brdFile.SetExt( "cad" );
231  path = brdFile.GetFullPath();
232  }
233 
234  DIALOG_GENCAD_EXPORT_OPTIONS optionsDialog( this, path );
235 
236  if( optionsDialog.ShowModal() == wxID_CANCEL )
237  return;
238 
239  path = optionsDialog.GetFileName();
240  SetLastPath( LAST_PATH_GENCAD, path );
241  FILE* file = wxFopen( path, "wt" );
242 
243  if( !file )
244  {
245  DisplayError( this, wxString::Format( _( "Unable to create \"%s\"" ),
246  optionsDialog.GetFileName() ) );
247  return;
248  }
249 
250  // Get options
251  flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
252  uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
253  individualShapes = optionsDialog.GetOption( INDIVIDUAL_SHAPES );
255 
256  // Switch the locale to standard C (needed to print floating point numbers)
257  LOCALE_IO toggle;
258 
259  // Update some board data, to ensure a reliable gencad export
261 
262  // Save the auxiliary origin for the rest of the module
264  GencadOffsetX = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.x : 0;
265  GencadOffsetY = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.y : 0;
266 
267  // No idea on *why* this should be needed... maybe to fix net names?
268  Compile_Ratsnest( true );
269 
270  /* Temporary modification of footprints that are flipped (i.e. on bottom
271  * layer) to convert them to non flipped footprints.
272  * This is necessary to easily export shapes to GenCAD,
273  * that are given as normal orientation (non flipped, rotation = 0))
274  * these changes will be undone later
275  */
276  BOARD* pcb = GetBoard();
277 
278  for( MODULE* module : pcb->Modules() )
279  {
280  module->SetFlag( 0 );
281 
282  if( module->GetLayer() == B_Cu )
283  {
284  module->Flip( module->GetPosition(), Settings().m_FlipLeftRight );
285  module->SetFlag( 1 );
286  }
287  }
288 
289  /* Gencad has some mandatory and some optional sections: some importer
290  * need the padstack section (which is optional) anyway. Also the
291  * order of the section *is* important */
292 
293  CreateHeaderInfoData( file, this ); // Gencad header
294  CreateBoardSection( file, pcb ); // Board perimeter
295 
296  CreatePadsShapesSection( file, pcb ); // Pads and padstacks
297  CreateArtworksSection( file ); // Empty but mandatory
298 
299  /* Gencad splits a component info in shape, component and device.
300  * We don't do any sharing (it would be difficult since each module is
301  * customizable after placement) */
302  CreateShapesSection( file, pcb );
303  CreateComponentsSection( file, pcb );
304  CreateDevicesSection( file, pcb );
305 
306  // In a similar way the netlist is split in net, track and route
307  CreateSignalsSection( file, pcb );
308  CreateTracksInfoData( file, pcb );
309  CreateRoutesSection( file, pcb );
310 
311  fclose( file );
312 
313  // Undo the footprints modifications (flipped footprints)
314  for( auto module : pcb->Modules() )
315  {
316  if( module->GetFlag() )
317  {
318  module->Flip( module->GetPosition(), Settings().m_FlipLeftRight );
319  module->SetFlag( 0 );
320  }
321  }
322 
323  componentShapes.clear();
324  shapeNames.clear();
325 }
326 
327 
328 // Sort vias for uniqueness
329 static bool ViaSort( const VIA* aPadref, const VIA* aPadcmp )
330 {
331  if( aPadref->GetWidth() != aPadcmp->GetWidth() )
332  return aPadref->GetWidth() < aPadcmp->GetWidth();
333 
334  if( aPadref->GetDrillValue() != aPadcmp->GetDrillValue() )
335  return aPadref->GetDrillValue() < aPadcmp->GetDrillValue();
336 
337  if( aPadref->GetLayerSet() != aPadcmp->GetLayerSet() )
338  return aPadref->GetLayerSet().FmtBin().compare( aPadcmp->GetLayerSet().FmtBin() ) < 0;
339 
340  return false;
341 }
342 
343 
344 // The ARTWORKS section is empty but (officially) mandatory
345 static void CreateArtworksSection( FILE* aFile )
346 {
347  /* The artworks section is empty */
348  fputs( "$ARTWORKS\n", aFile );
349  fputs( "$ENDARTWORKS\n\n", aFile );
350 }
351 
352 
353 // Emit PADS and PADSTACKS. They are sorted and emitted uniquely.
354 // Via name is synthesized from their attributes, pads are numbered
355 static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
356 {
357  std::vector<D_PAD*> padstacks;
358  std::vector<VIA*> vias;
359  std::vector<VIA*> viastacks;
360 
361  padstacks.resize( 1 ); // We count pads from 1
362 
363  // The master layermask (i.e. the enabled layers) for padstack generation
364  LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
365  int cu_count = aPcb->GetCopperLayerCount();
366 
367  fputs( "$PADS\n", aFile );
368 
369  // Enumerate and sort the pads
370 
371  std::vector<D_PAD*> pads = aPcb->GetPads();
372  std::sort( pads.begin(), pads.end(), []( const D_PAD* a, const D_PAD* b )
373  {
374  return D_PAD::Compare( a, b ) < 0;
375  } );
376 
377 
378  // The same for vias
379  for( TRACK* track : aPcb->Tracks() )
380  {
381  if( VIA* via = dyn_cast<VIA*>( track ) )
382  vias.push_back( via );
383  }
384 
385  std::sort( vias.begin(), vias.end(), ViaSort );
386  vias.erase( std::unique( vias.begin(), vias.end(), []( const VIA* a, const VIA* b )
387  {
388  return ViaSort( a, b ) == false;
389  } ),
390  vias.end() );
391 
392  // Emit vias pads
393 
394  for( VIA* via : vias )
395  {
396  viastacks.push_back( via );
397  fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
398  via->GetWidth(), via->GetDrillValue(),
399  fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
400  via->GetDrillValue() / SCALE_FACTOR,
401  via->GetWidth() / (SCALE_FACTOR * 2) );
402  }
403 
404  // Emit component pads
405  D_PAD* old_pad = 0;
406  int pad_name_number = 0;
407 
408  for( unsigned i = 0; i<pads.size(); ++i )
409  {
410  D_PAD* pad = pads[i];
411  const wxPoint& off = pad->GetOffset();
412 
413  pad->SetSubRatsnest( pad_name_number );
414 
415  if( old_pad && 0==D_PAD::Compare( old_pad, pad ) )
416  continue; // already created
417 
418  old_pad = pad;
419 
420  pad_name_number++;
421  pad->SetSubRatsnest( pad_name_number );
422 
423  fprintf( aFile, "PAD P%d", pad->GetSubRatsnest() );
424 
425  padstacks.push_back( pad ); // Will have its own padstack later
426  int dx = pad->GetSize().x / 2;
427  int dy = pad->GetSize().y / 2;
428 
429  switch( pad->GetShape() )
430  {
431  default:
432  wxASSERT_MSG( false, "Pad type not implemented" );
434 
435  case PAD_SHAPE_CIRCLE:
436  fprintf( aFile, " ROUND %g\n",
437  pad->GetDrillSize().x / SCALE_FACTOR );
438  /* Circle is center, radius */
439  fprintf( aFile, "CIRCLE %g %g %g\n",
440  off.x / SCALE_FACTOR,
441  -off.y / SCALE_FACTOR,
442  pad->GetSize().x / (SCALE_FACTOR * 2) );
443  break;
444 
445  case PAD_SHAPE_RECT:
446  fprintf( aFile, " RECTANGULAR %g\n",
447  pad->GetDrillSize().x / SCALE_FACTOR );
448 
449  // Rectangle is begin, size *not* begin, end!
450  fprintf( aFile, "RECTANGLE %g %g %g %g\n",
451  (-dx + off.x ) / SCALE_FACTOR,
452  (-dy - off.y ) / SCALE_FACTOR,
453  dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
454  break;
455 
456  case PAD_SHAPE_ROUNDRECT:
457  case PAD_SHAPE_OVAL:
458  {
459  const wxSize& size = pad->GetSize();
460  int radius;
461 
462  if( pad->GetShape() == PAD_SHAPE_ROUNDRECT )
463  radius = pad->GetRoundRectCornerRadius();
464  else
465  radius = std::min( size.x, size.y ) / 2;
466 
467  int lineX = size.x / 2 - radius;
468  int lineY = size.y / 2 - radius;
469 
470  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
471 
472  // bottom left arc
473  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
474  ( off.x - lineX - radius ) / SCALE_FACTOR,
475  ( -off.y - lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
476  ( -off.y - lineY - radius ) / SCALE_FACTOR,
477  ( off.x - lineX ) / SCALE_FACTOR, ( -off.y - lineY ) / SCALE_FACTOR );
478 
479  // bottom line
480  if( lineX > 0 )
481  {
482  fprintf( aFile, "LINE %g %g %g %g\n",
483  ( off.x - lineX ) / SCALE_FACTOR,
484  ( -off.y - lineY - radius ) / SCALE_FACTOR,
485  ( off.x + lineX ) / SCALE_FACTOR,
486  ( -off.y - lineY - radius ) / SCALE_FACTOR );
487  }
488 
489  // bottom right arc
490  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
491  ( off.x + lineX ) / SCALE_FACTOR,
492  ( -off.y - lineY - radius ) / SCALE_FACTOR,
493  ( off.x + lineX + radius ) / SCALE_FACTOR,
494  ( -off.y - lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
495  ( -off.y - lineY ) / SCALE_FACTOR );
496 
497  // right line
498  if( lineY > 0 )
499  {
500  fprintf( aFile, "LINE %g %g %g %g\n",
501  ( off.x + lineX + radius ) / SCALE_FACTOR,
502  ( -off.y + lineY ) / SCALE_FACTOR,
503  ( off.x + lineX + radius ) / SCALE_FACTOR,
504  ( -off.y - lineY ) / SCALE_FACTOR );
505  }
506 
507  // top right arc
508  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
509  ( off.x + lineX + radius ) / SCALE_FACTOR,
510  ( -off.y + lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
511  ( -off.y + lineY + radius ) / SCALE_FACTOR,
512  ( off.x + lineX ) / SCALE_FACTOR, ( -off.y + lineY ) / SCALE_FACTOR );
513 
514  // top line
515  if( lineX > 0 )
516  {
517  fprintf( aFile, "LINE %g %g %g %g\n"
518  , ( off.x - lineX ) / SCALE_FACTOR,
519  ( -off.y + lineY + radius ) / SCALE_FACTOR,
520  ( off.x + lineX ) / SCALE_FACTOR,
521  ( -off.y + lineY + radius ) / SCALE_FACTOR );
522  }
523 
524  // top left arc
525  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
526  ( off.x - lineX ) / SCALE_FACTOR,
527  ( -off.y + lineY + radius ) / SCALE_FACTOR,
528  ( off.x - lineX - radius ) / SCALE_FACTOR,
529  ( -off.y + lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
530  ( -off.y + lineY ) / SCALE_FACTOR );
531 
532  // left line
533  if( lineY > 0 )
534  {
535  fprintf( aFile, "LINE %g %g %g %g\n",
536  ( off.x - lineX - radius ) / SCALE_FACTOR,
537  ( -off.y - lineY ) / SCALE_FACTOR,
538  ( off.x - lineX - radius ) / SCALE_FACTOR,
539  ( -off.y + lineY ) / SCALE_FACTOR );
540  }
541  }
542  break;
543 
544  case PAD_SHAPE_TRAPEZOID:
545  {
546  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
547 
548  int ddx = pad->GetDelta().x / 2;
549  int ddy = pad->GetDelta().y / 2;
550 
551  wxPoint poly[4];
552  poly[0] = wxPoint( -dx + ddy, dy + ddx );
553  poly[1] = wxPoint( dx - ddy, dy - ddx );
554  poly[2] = wxPoint( dx + ddy, -dy + ddx );
555  poly[3] = wxPoint( -dx - ddy, -dy - ddx );
556 
557  for( int cur = 0; cur < 4; ++cur )
558  {
559  int next = ( cur + 1 ) % 4;
560  fprintf( aFile, "LINE %g %g %g %g\n",
561  ( off.x + poly[cur].x ) / SCALE_FACTOR,
562  ( -off.y - poly[cur].y ) / SCALE_FACTOR,
563  ( off.x + poly[next].x ) / SCALE_FACTOR,
564  ( -off.y - poly[next].y ) / SCALE_FACTOR );
565  }
566  }
567  break;
568 
569  case PAD_SHAPE_CUSTOM:
570  {
571  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
572 
573  SHAPE_POLY_SET outline;
574  pad->MergePrimitivesAsPolygon( &outline, UNDEFINED_LAYER );
575 
576  for( int jj = 0; jj < outline.OutlineCount(); ++jj )
577  {
578  const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
579  int pointCount = poly.PointCount();
580 
581  for( int ii = 0; ii < pointCount; ii++ )
582  {
583  int next = ( ii + 1 ) % pointCount;
584  fprintf( aFile, "LINE %g %g %g %g\n",
585  ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
586  ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
587  ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
588  ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
589  }
590  }
591  }
592  break;
593  }
594  }
595 
596  fputs( "\n$ENDPADS\n\n", aFile );
597 
598  // Now emit the padstacks definitions, using the combined layer masks
599  fputs( "$PADSTACKS\n", aFile );
600 
601  // Via padstacks
602  for( unsigned i = 0; i < viastacks.size(); i++ )
603  {
604  VIA* via = viastacks[i];
605 
606  LSET mask = via->GetLayerSet() & master_layermask;
607 
608  fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
609  via->GetWidth(), via->GetDrillValue(),
610  fmt_mask( mask ).c_str(),
611  via->GetDrillValue() / SCALE_FACTOR );
612 
613  for( LSEQ seq = mask.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
614  {
615  PCB_LAYER_ID layer = *seq;
616 
617  fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
618  via->GetWidth(), via->GetDrillValue(),
619  fmt_mask( mask ).c_str(),
620  GenCADLayerName( cu_count, layer ).c_str()
621  );
622  }
623  }
624 
625  /* Component padstacks
626  * Older versions of CAM350 don't apply correctly the FLIP semantics for
627  * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
628  * define the shape as MIRRORX and define a separate 'flipped' padstack...
629  * until it appears yet another noncompliant importer */
630  for( unsigned i = 1; i < padstacks.size(); i++ )
631  {
632  D_PAD* pad = padstacks[i];
633 
634  // Straight padstack
635  fprintf( aFile, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
636 
637  LSET pad_set = pad->GetLayerSet() & master_layermask;
638 
639  // the special gc_seq
640  for( LSEQ seq = pad_set.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
641  {
642  PCB_LAYER_ID layer = *seq;
643 
644  fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
645  }
646 
647  // Flipped padstack
648  if( flipBottomPads )
649  {
650  fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
651 
652  // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
653  for( LSEQ seq = pad_set.Seq(); seq; ++seq )
654  {
655  PCB_LAYER_ID layer = *seq;
656 
657  fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerNameFlipped( cu_count, layer ).c_str() );
658  }
659  }
660  }
661 
662  fputs( "$ENDPADSTACKS\n\n", aFile );
663 }
664 
665 
667 static size_t hashModule( const MODULE* aModule )
668 {
669  size_t ret = 0x11223344;
670  constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
672 
673 
674  for( auto i : aModule->GraphicalItems() )
675  ret += hash_eda( i, flags );
676 
677  for( auto i : aModule->Pads() )
678  ret += hash_eda( i, flags );
679 
680  return ret;
681 }
682 
683 
684 /* Creates the footprint shape list.
685  * Since module shape is customizable after the placement we cannot share them;
686  * instead we opt for the one-module-one-shape-one-component-one-device approach
687  */
688 static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
689 {
690  const char* layer;
691  wxString pinname;
692  const char* mirror = "0";
693  std::map<wxString, size_t> shapes;
694 
695  fputs( "$SHAPES\n", aFile );
696 
697  for( MODULE* module : aPcb->Modules() )
698  {
699  if( !individualShapes )
700  {
701  // Check if such shape has been already generated, and if so - reuse it
702  // It is necessary to compute hash (i.e. check all children objects) as
703  // certain components instances might have been modified on the board.
704  // In such case the shape will be different despite the same LIB_ID.
705  wxString shapeName = module->GetFPID().Format();
706 
707  auto shapeIt = shapes.find( shapeName );
708  size_t modHash = hashModule( module );
709 
710  if( shapeIt != shapes.end() )
711  {
712  if( modHash != shapeIt->second )
713  {
714  // there is an entry for this footprint, but it has a modified shape,
715  // so we need to create a new entry
716  wxString newShapeName;
717  int suffix = 0;
718 
719  // find an unused name or matching entry
720  do
721  {
722  newShapeName = wxString::Format( "%s_%d", shapeName, suffix );
723  shapeIt = shapes.find( newShapeName );
724  ++suffix;
725  }
726  while( shapeIt != shapes.end() && shapeIt->second != modHash );
727 
728  shapeName = newShapeName;
729  }
730 
731  if( shapeIt != shapes.end() && modHash == shapeIt->second )
732  {
733  // shape found, so reuse it
734  componentShapes[module] = modHash;
735  continue;
736  }
737  }
738 
739  // new shape
740  componentShapes[module] = modHash;
741  shapeNames[modHash] = shapeName;
742  shapes[shapeName] = modHash;
743  FootprintWriteShape( aFile, module, shapeName );
744  }
745  else // individual shape for each component
746  {
747  FootprintWriteShape( aFile, module, module->GetReference() );
748  }
749 
750  // set of already emitted pins to check for duplicates
751  std::set<wxString> pins;
752 
753  for( D_PAD* pad : module->Pads() )
754  {
755  /* Padstacks are defined using the correct layers for the pads, therefore to
756  * all pads need to be marked as TOP to use the padstack information correctly.
757  */
758  layer = "TOP";
759  pinname = pad->GetName();
760 
761  if( pinname.IsEmpty() )
762  pinname = wxT( "none" );
763 
764  if( uniquePins )
765  {
766  int suffix = 0;
767  wxString origPinname( pinname );
768 
769  auto it = pins.find( pinname );
770 
771  while( it != pins.end() )
772  {
773  pinname = wxString::Format( "%s_%d", origPinname, suffix );
774  ++suffix;
775  it = pins.find( pinname );
776  }
777 
778  pins.insert( pinname );
779  }
780 
781  double orient = pad->GetOrientation() - module->GetOrientation();
782  NORMALIZE_ANGLE_POS( orient );
783 
784  // Bottom side modules use the flipped padstack
785  fprintf( aFile, ( flipBottomPads && module->GetFlag() ) ?
786  "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
787  "PIN \"%s\" PAD%d %g %g %s %g %s\n",
788  TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
789  pad->GetPos0().x / SCALE_FACTOR,
790  -pad->GetPos0().y / SCALE_FACTOR,
791  layer, orient / 10.0, mirror );
792  }
793  }
794 
795  fputs( "$ENDSHAPES\n\n", aFile );
796 }
797 
798 
799 /* Creates the section $COMPONENTS (Footprints placement)
800  * Bottom side components are difficult to handle: shapes must be mirrored or
801  * flipped, silk layers need to be handled correctly and so on. Also it seems
802  * that *noone* follows the specs...
803  */
804 static void CreateComponentsSection( FILE* aFile, BOARD* aPcb )
805 {
806  fputs( "$COMPONENTS\n", aFile );
807 
808  int cu_count = aPcb->GetCopperLayerCount();
809 
810  for( MODULE* module : aPcb->Modules() )
811  {
812  const char* mirror;
813  const char* flip;
814  double fp_orient = module->GetOrientation();
815 
816  if( module->GetFlag() )
817  {
818  mirror = "MIRRORX";
819  flip = "FLIP";
820  NEGATE_AND_NORMALIZE_ANGLE_POS( fp_orient );
821  }
822  else
823  {
824  mirror = "0";
825  flip = "0";
826  }
827 
828  fprintf( aFile, "\nCOMPONENT \"%s\"\n",
829  TO_UTF8( escapeString( module->GetReference() ) ) );
830  fprintf( aFile, "DEVICE \"DEV_%s\"\n",
831  TO_UTF8( escapeString( getShapeName( module ) ) ) );
832  fprintf( aFile, "PLACE %g %g\n",
833  MapXTo( module->GetPosition().x ),
834  MapYTo( module->GetPosition().y ) );
835  fprintf( aFile, "LAYER %s\n",
836  module->GetFlag() ? "BOTTOM" : "TOP" );
837  fprintf( aFile, "ROTATION %g\n",
838  fp_orient / 10.0 );
839  fprintf( aFile, "SHAPE \"%s\" %s %s\n",
840  TO_UTF8( escapeString( getShapeName( module ) ) ),
841  mirror, flip );
842 
843  // Text on silk layer: RefDes and value (are they actually useful?)
844  TEXTE_MODULE *textmod = &module->Reference();
845 
846  for( int ii = 0; ii < 2; ii++ )
847  {
848  double txt_orient = textmod->GetTextAngle();
849  std::string layer = GenCADLayerName( cu_count, module->GetFlag() ? B_SilkS : F_SilkS );
850 
851  fprintf( aFile, "TEXT %g %g %g %g %s %s \"%s\"",
852  textmod->GetPos0().x / SCALE_FACTOR,
853  -textmod->GetPos0().y / SCALE_FACTOR,
854  textmod->GetTextWidth() / SCALE_FACTOR,
855  txt_orient / 10.0,
856  mirror,
857  layer.c_str(),
858  TO_UTF8( escapeString( textmod->GetText() ) ) );
859 
860  // Please note, the width is approx
861  fprintf( aFile, " 0 0 %g %g\n",
862  ( textmod->GetTextWidth() * textmod->GetLength() ) / SCALE_FACTOR,
863  textmod->GetTextHeight() / SCALE_FACTOR );
864 
865  textmod = &module->Value(); // Dirty trick for the second iteration
866  }
867 
868  // The SHEET is a 'generic description' for referencing the component
869  fprintf( aFile, "SHEET \"RefDes: %s, Value: %s\"\n",
870  TO_UTF8( module->GetReference() ),
871  TO_UTF8( module->GetValue() ) );
872  }
873 
874  fputs( "$ENDCOMPONENTS\n\n", aFile );
875 }
876 
877 
878 /* Emit the netlist (which is actually the thing for which GenCAD is used these
879  * days!); tracks are handled later */
880 static void CreateSignalsSection( FILE* aFile, BOARD* aPcb )
881 {
882  wxString msg;
883  NETINFO_ITEM* net;
884  int NbNoConn = 1;
885 
886  fputs( "$SIGNALS\n", aFile );
887 
888  for( unsigned ii = 0; ii < aPcb->GetNetCount(); ii++ )
889  {
890  net = aPcb->FindNet( ii );
891 
892  if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
893  {
894  msg.Printf( "NoConnection%d", NbNoConn++ );
895  }
896 
897  if( net->GetNet() <= 0 ) // dummy netlist (no connection)
898  continue;
899 
900  msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + "\"";
901 
902  fputs( TO_UTF8( msg ), aFile );
903  fputs( "\n", aFile );
904 
905  for( MODULE* module : aPcb->Modules() )
906  {
907  for( D_PAD* pad : module->Pads() )
908  {
909  if( pad->GetNetCode() != net->GetNet() )
910  continue;
911 
912  msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
913  escapeString( module->GetReference() ),
914  escapeString( pad->GetName() ) );
915 
916  fputs( TO_UTF8( msg ), aFile );
917  fputs( "\n", aFile );
918  }
919  }
920  }
921 
922  fputs( "$ENDSIGNALS\n\n", aFile );
923 }
924 
925 
926 // Creates the header section
927 static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* aFrame )
928 {
929  wxString msg;
930  BOARD *board = aFrame->GetBoard();
931 
932  fputs( "$HEADER\n", aFile );
933  fputs( "GENCAD 1.4\n", aFile );
934 
935  // Please note: GenCAD syntax requires quoted strings if they can contain spaces
936  msg.Printf( wxT( "USER \"%s %s\"\n" ),
937  Pgm().App().GetAppName(),
938  GetBuildVersion() );
939  fputs( TO_UTF8( msg ), aFile );
940 
941  msg = wxT( "DRAWING \"" ) + board->GetFileName() + wxT( "\"\n" );
942  fputs( TO_UTF8( msg ), aFile );
943 
944  const TITLE_BLOCK& tb = aFrame->GetTitleBlock();
945 
946  msg = wxT( "REVISION \"" ) + tb.GetRevision() + wxT( " " ) + tb.GetDate() + wxT( "\"\n" );
947 
948  fputs( TO_UTF8( msg ), aFile );
949  fputs( "UNITS INCH\n", aFile );
950 
951  // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
952  msg.Printf( wxT( "ORIGIN %g %g\n" ),
953  storeOriginCoords ? MapXTo( 0 ) : 0,
954  storeOriginCoords ? MapYTo( 0 ) : 0 );
955  fputs( TO_UTF8( msg ), aFile );
956 
957  fputs( "INTERTRACK 0\n", aFile );
958  fputs( "$ENDHEADER\n\n", aFile );
959 
960  return true;
961 }
962 
963 
964 /* Creates the section ROUTES
965  * that handles tracks, vias
966  * TODO: add zones
967  * section:
968  * $ROUTE
969  * ...
970  * $ENROUTE
971  * Track segments must be sorted by nets
972  */
973 static void CreateRoutesSection( FILE* aFile, BOARD* aPcb )
974 {
975  int vianum = 1;
976  int old_netcode, old_width, old_layer;
977  LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
978 
979  int cu_count = aPcb->GetCopperLayerCount();
980 
981  TRACKS tracks( aPcb->Tracks() );
982  std::sort( tracks.begin(), tracks.end(),
983  []( const TRACK* a, const TRACK* b )
984  {
985  if( a->GetNetCode() == b->GetNetCode() )
986  {
987  if( a->GetWidth() == b->GetWidth() )
988  return ( a->GetLayer() < b->GetLayer() );
989 
990  return ( a->GetWidth() < b->GetWidth() );
991  }
992 
993  return ( a->GetNetCode() < b->GetNetCode() );
994  } );
995 
996  fputs( "$ROUTES\n", aFile );
997 
998  old_netcode = -1; old_width = -1; old_layer = -1;
999 
1000  for( TRACK* track : tracks )
1001  {
1002  if( old_netcode != track->GetNetCode() )
1003  {
1004  old_netcode = track->GetNetCode();
1005  NETINFO_ITEM* net = track->GetNet();
1006  wxString netname;
1007 
1008  if( net && (net->GetNetname() != wxEmptyString) )
1009  netname = net->GetNetname();
1010  else
1011  netname = wxT( "_noname_" );
1012 
1013  fprintf( aFile, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
1014  }
1015 
1016  if( old_width != track->GetWidth() )
1017  {
1018  old_width = track->GetWidth();
1019  fprintf( aFile, "TRACK TRACK%d\n", track->GetWidth() );
1020  }
1021 
1022  if( track->Type() == PCB_TRACE_T )
1023  {
1024  if( old_layer != track->GetLayer() )
1025  {
1026  old_layer = track->GetLayer();
1027  fprintf( aFile, "LAYER %s\n",
1028  GenCADLayerName( cu_count, track->GetLayer() ).c_str() );
1029  }
1030 
1031  fprintf( aFile, "LINE %g %g %g %g\n",
1032  MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
1033  MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
1034  }
1035 
1036  if( track->Type() == PCB_VIA_T )
1037  {
1038  const VIA* via = static_cast<const VIA*>(track);
1039 
1040  LSET vset = via->GetLayerSet() & master_layermask;
1041 
1042  fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
1043  via->GetWidth(), via->GetDrillValue(),
1044  fmt_mask( vset ).c_str(),
1045  MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
1046  via->GetDrillValue() / SCALE_FACTOR, vianum++ );
1047  }
1048  }
1049 
1050  fputs( "$ENDROUTES\n\n", aFile );
1051 }
1052 
1053 
1054 /* Creates the section $DEVICES
1055  * This is a list of footprints properties
1056  * ( Shapes are in section $SHAPE )
1057  */
1058 static void CreateDevicesSection( FILE* aFile, BOARD* aPcb )
1059 {
1060  std::set<wxString> emitted;
1061  fputs( "$DEVICES\n", aFile );
1062 
1063  for( const auto& componentShape : componentShapes )
1064  {
1065  const wxString& shapeName = shapeNames[componentShape.second];
1066  bool newDevice;
1067  std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1068 
1069  if( !newDevice ) // do not repeat device definitions
1070  continue;
1071 
1072  const MODULE* module = componentShape.first;
1073  fprintf( aFile, "\nDEVICE \"DEV_%s\"\n", TO_UTF8( escapeString( shapeName ) ) );
1074  fprintf( aFile, "PART \"%s\"\n", TO_UTF8( escapeString( module->GetValue() ) ) );
1075  fprintf( aFile, "PACKAGE \"%s\"\n", TO_UTF8( escapeString( module->GetFPID().Format() ) ) );
1076  }
1077 
1078  fputs( "$ENDDEVICES\n\n", aFile );
1079 }
1080 
1081 
1082 /* Creates the section $BOARD.
1083  * We output here only the board perimeter
1084  */
1085 static void CreateBoardSection( FILE* aFile, BOARD* aPcb )
1086 {
1087  fputs( "$BOARD\n", aFile );
1088 
1089  // Extract the board edges
1090  for( BOARD_ITEM* drawing : aPcb->Drawings() )
1091  {
1092  if( drawing->Type() == PCB_LINE_T )
1093  {
1094  DRAWSEGMENT* drawseg = static_cast<DRAWSEGMENT*>( drawing );
1095 
1096  if( drawseg->GetLayer() == Edge_Cuts )
1097  {
1098  // XXX GenCAD supports arc boundaries but I've seen nothing that reads them
1099  fprintf( aFile, "LINE %g %g %g %g\n",
1100  MapXTo( drawseg->GetStart().x ), MapYTo( drawseg->GetStart().y ),
1101  MapXTo( drawseg->GetEnd().x ), MapYTo( drawseg->GetEnd().y ) );
1102  }
1103  }
1104  }
1105 
1106  fputs( "$ENDBOARD\n\n", aFile );
1107 }
1108 
1109 
1110 /* Creates the section "$TRACKS"
1111  * This sections give the list of widths (tools) used in tracks and vias
1112  * format:
1113  * $TRACK
1114  * TRACK <name> <width>
1115  * $ENDTRACK
1116  *
1117  * Each tool name is build like this: "TRACK" + track width.
1118  * For instance for a width = 120 : name = "TRACK120".
1119  */
1120 static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb )
1121 {
1122  // Find thickness used for traces
1123 
1124  std::set<int> trackinfo;
1125 
1126  for( TRACK* track : aPcb->Tracks() )
1127  trackinfo.insert( track->GetWidth() );
1128 
1129  // Write data
1130  fputs( "$TRACKS\n", aFile );
1131 
1132  for( int size : trackinfo )
1133  fprintf( aFile, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1134 
1135  fputs( "$ENDTRACKS\n\n", aFile );
1136 }
1137 
1138 
1139 /* Creates the shape of a footprint (section SHAPE)
1140  * The shape is always given "normal" (Orient 0, not mirrored)
1141  * It's almost guaranteed that the silk layer will be imported wrong but
1142  * the shape also contains the pads!
1143  */
1144 static void FootprintWriteShape( FILE* aFile, MODULE* module, const wxString& aShapeName )
1145 {
1146  EDGE_MODULE* PtEdge;
1147 
1148  /* creates header: */
1149  fprintf( aFile, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1150 
1151  if( module->GetAttributes() & MOD_THROUGH_HOLE )
1152  fprintf( aFile, "INSERT TH\n" );
1153  else
1154  fprintf( aFile, "INSERT SMD\n" );
1155 
1156  // Silk outline; wildly interpreted by various importers:
1157  // CAM350 read it right but only closed shapes
1158  // ProntoPlace double-flip it (at least the pads are correct)
1159  // GerberTool usually get it right...
1160  for( BOARD_ITEM* PtStruct : module->GraphicalItems() )
1161  {
1162  switch( PtStruct->Type() )
1163  {
1164  case PCB_MODULE_TEXT_T:
1165 
1166  // If we wanted to export text, this is not the correct section
1167  break;
1168 
1169  case PCB_MODULE_EDGE_T:
1170  PtEdge = (EDGE_MODULE*) PtStruct;
1171  if( PtEdge->GetLayer() == F_SilkS || PtEdge->GetLayer() == B_SilkS )
1172  {
1173  switch( PtEdge->GetShape() )
1174  {
1175  case S_SEGMENT:
1176  fprintf( aFile, "LINE %g %g %g %g\n",
1177  PtEdge->m_Start0.x / SCALE_FACTOR,
1178  -PtEdge->m_Start0.y / SCALE_FACTOR,
1179  PtEdge->m_End0.x / SCALE_FACTOR,
1180  -PtEdge->m_End0.y / SCALE_FACTOR );
1181  break;
1182 
1183  case S_RECT:
1184  {
1185  fprintf( aFile, "LINE %g %g %g %g\n",
1186  PtEdge->m_Start0.x / SCALE_FACTOR,
1187  -PtEdge->m_Start0.y / SCALE_FACTOR,
1188  PtEdge->m_End0.x / SCALE_FACTOR,
1189  -PtEdge->m_Start0.y / SCALE_FACTOR );
1190  fprintf( aFile, "LINE %g %g %g %g\n",
1191  PtEdge->m_End0.x / SCALE_FACTOR,
1192  -PtEdge->m_Start0.y / SCALE_FACTOR,
1193  PtEdge->m_End0.x / SCALE_FACTOR,
1194  -PtEdge->m_End0.y / SCALE_FACTOR );
1195  fprintf( aFile, "LINE %g %g %g %g\n",
1196  PtEdge->m_End0.x / SCALE_FACTOR,
1197  -PtEdge->m_End0.y / SCALE_FACTOR,
1198  PtEdge->m_Start0.x / SCALE_FACTOR,
1199  -PtEdge->m_End0.y / SCALE_FACTOR );
1200  fprintf( aFile, "LINE %g %g %g %g\n",
1201  PtEdge->m_Start0.x / SCALE_FACTOR,
1202  -PtEdge->m_End0.y / SCALE_FACTOR,
1203  PtEdge->m_Start0.x / SCALE_FACTOR,
1204  -PtEdge->m_Start0.y / SCALE_FACTOR );
1205  }
1206  break;
1207 
1208  case S_CIRCLE:
1209  {
1210  int radius = KiROUND( GetLineLength( PtEdge->m_End0,
1211  PtEdge->m_Start0 ) );
1212  fprintf( aFile, "CIRCLE %g %g %g\n",
1213  PtEdge->m_Start0.x / SCALE_FACTOR,
1214  -PtEdge->m_Start0.y / SCALE_FACTOR,
1215  radius / SCALE_FACTOR );
1216  break;
1217  }
1218 
1219  case S_ARC:
1220  {
1221  int arcendx, arcendy;
1222  arcendx = PtEdge->m_End0.x - PtEdge->m_Start0.x;
1223  arcendy = PtEdge->m_End0.y - PtEdge->m_Start0.y;
1224  RotatePoint( &arcendx, &arcendy, -PtEdge->GetAngle() );
1225  arcendx += PtEdge->GetStart0().x;
1226  arcendy += PtEdge->GetStart0().y;
1227 
1228  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
1229  PtEdge->m_End0.x / SCALE_FACTOR,
1230  -PtEdge->GetEnd0().y / SCALE_FACTOR,
1231  arcendx / SCALE_FACTOR,
1232  -arcendy / SCALE_FACTOR,
1233  PtEdge->GetStart0().x / SCALE_FACTOR,
1234  -PtEdge->GetStart0().y / SCALE_FACTOR );
1235  break;
1236  }
1237 
1238  case S_POLYGON:
1239  // Not exported (TODO)
1240  break;
1241 
1242  default:
1243  wxFAIL_MSG( wxString::Format( "Type Edge Module %d invalid.",
1244  PtStruct->Type() ) );
1245  break;
1246  }
1247  }
1248  break;
1249 
1250  default:
1251  break;
1252  }
1253  }
1254 }
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Checks whether an option has been selected
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:719
static void CreateBoardSection(FILE *aFile, BOARD *aPcb)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
CITER next(CITER it)
Definition: ptree.cpp:126
void MergePrimitivesAsPolygon(SHAPE_POLY_SET *aMergedPolygon, PCB_LAYER_ID aLayer) const
Merge all basic shapes to a SHAPE_POLY_SET Note: The results are relative to the pad position,...
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
int GetAttributes() const
Definition: class_module.h:262
static const wxString getShapeName(MODULE *aModule)
int GetNetCode() const
Function GetNetCode.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
use coordinates relative to the parent object
Definition: hash_eda.h:44
static void CreateShapesSection(FILE *aFile, BOARD *aPcb)
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:211
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
This file is part of the common library.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
const wxPoint & GetStart() const
Definition: class_track.h:116
STROKE_T GetShape() const
static void CreateRoutesSection(FILE *aFile, BOARD *aPcb)
static void CreateSignalsSection(FILE *aFile, BOARD *aPcb)
polygon (not yet used for tracks, but could be in microwave apps)
static double MapYTo(int aY)
PADS & Pads()
Definition: class_module.h:174
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:469
double GetTextAngle() const
Definition: eda_text.h:174
static bool uniquePins
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
void ExportToGenCAD(wxCommandEvent &event)
Function ExportToGenCAD creates a file in GenCAD 1.4 format from the current board.
usual segment : line with rounded ends
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:88
const LIB_ID & GetFPID() const
Definition: class_module.h:221
void SetSubRatsnest(int aSubRatsnest)
Definition: class_pad.h:509
static wxString escapeString(const wxString &aString)
static int GencadOffsetY
DRAWINGS & GraphicalItems()
Definition: class_module.h:184
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:276
static bool flipBottomPads
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
int PointCount() const
Function PointCount()
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:380
const wxString & GetFileName() const
Definition: class_board.h:244
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
static void CreateTracksInfoData(FILE *aFile, BOARD *aPcb)
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
static void CreateArtworksSection(FILE *aFile)
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
wxString GetFileName() const
Returns the selected file path
wxPoint m_End0
End point, relative to module origin, orient 0.
void vset(double *v, double x, double y, double z)
Definition: trackball.cpp:82
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
int GetTextHeight() const
Definition: eda_text.h:245
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
const wxPoint & GetStart0() const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
const VECTOR2I & CPoint(int aIndex) const
Function Point()
static std::string GenCADLayerNameFlipped(int aCuCount, PCB_LAYER_ID aId)
segment with non rounded ends
static void CreateComponentsSection(FILE *aFile, BOARD *aPcb)
PCB_LAYER_ID
A quick note on layer IDs:
static bool individualShapes
LSET is a set of PCB_LAYER_IDs.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:741
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
MODULES & Modules()
Definition: class_board.h:249
wxString GetBuildVersion()
Get the full KiCad version string.
const wxString & GetRevision() const
Definition: title_block.h:89
static void CreatePadsShapesSection(FILE *aFile, BOARD *aPcb)
SHAPE_POLY_SET.
Arcs (with rounded ends)
static int Compare(const D_PAD *padref, const D_PAD *padcmp)
Function Compare compares two pads and return 0 if they are equal.
Definition: class_pad.cpp:964
const wxPoint & GetOffset() const
Definition: class_pad.h:233
static const PCB_LAYER_ID gc_seq[]
LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_pad.h:331
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
const wxSize & GetDelta() const
Definition: class_pad.h:227
static bool storeOriginCoords
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
UTF8 Format() const
Definition: lib_id.cpp:237
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
const wxPoint & GetPos0() const
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
static std::string GenCADLayerName(int aCuCount, PCB_LAYER_ID aId)
void NEGATE_AND_NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:341
const wxString & GetDate() const
Definition: title_block.h:79
const TITLE_BLOCK & GetTitleBlock() const override
double GetAngle() const
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetLength() const
int GetTextWidth() const
Definition: eda_text.h:242
see class PGM_BASE
int GetWidth() const
Definition: class_track.h:110
static bool ViaSort(const VIA *aPadref, const VIA *aPadcmp)
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:267
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:201
static size_t hashModule(const MODULE *aModule)
Compute hashes for modules without taking into account their position, rotation or layer.
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
static bool CreateHeaderInfoData(FILE *aFile, PCB_EDIT_FRAME *frame)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
static void CreateDevicesSection(FILE *aFile, BOARD *aPcb)
LSET GetEnabledLayers() const
Function GetEnabledLayers returns a bit-mask of all the layers that are enabled.
static void FootprintWriteShape(FILE *File, MODULE *module, const wxString &aShapeName)
#define _(s)
Definition: 3d_actions.cpp:33
SHAPE_LINE_CHAIN.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
const wxSize & GetDrillSize() const
Definition: class_pad.h:230
PCB_EDIT_FRAME is the main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
#define IU_PER_MILS
Definition: plotter.cpp:138
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
int GetSubRatsnest() const
Function GetSubRatsnest.
Definition: class_pad.h:508
static const double SCALE_FACTOR
int GetRoundRectCornerRadius() const
Definition: class_pad.cpp:224
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
static int GencadOffsetX
const wxPoint & GetEnd0() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
static std::string fmt_mask(LSET aSet)
PAD_SHAPE_T GetShape() const
Definition: class_pad.h:157
BOARD * GetBoard() const
wxPoint m_Start0
Start point or center, relative to module origin, orient 0.
static std::map< MODULE *, int > componentShapes
const wxSize & GetSize() const
Definition: class_pad.h:224
static std::map< int, wxString > shapeNames
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
size_t hash_eda(const EDA_ITEM *aItem, int aFlags)
Calculates hash of an EDA_ITEM.
Definition: hash_eda.cpp:49
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
DRAWINGS & Drawings()
Definition: class_board.h:252
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
wxPoint m_AuxOrigin
origin for plot exports
TRACKS & Tracks()
Definition: class_board.h:246
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
static double MapXTo(int aX)