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