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 <macros.h>
42 #include <hash_eda.h>
43 #include <pcb_edit_frame.h>
44 #include <pcbnew_settings.h>
45 #include <pgm_base.h>
46 #include <project/project_file.h> // LAST_PATH_TYPE
47 
48 #include <wx/app.h>
49 #include <wx/filedlg.h>
50 
51 static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* frame );
52 static void CreateArtworksSection( FILE* aFile );
53 static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb );
54 static void CreateBoardSection( FILE* aFile, BOARD* aPcb );
55 static void CreateComponentsSection( FILE* aFile, BOARD* aPcb );
56 static void CreateDevicesSection( FILE* aFile, BOARD* aPcb );
57 static void CreateRoutesSection( FILE* aFile, BOARD* aPcb );
58 static void CreateSignalsSection( FILE* aFile, BOARD* aPcb );
59 static void CreateShapesSection( FILE* aFile, BOARD* aPcb );
60 static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb );
61 static void FootprintWriteShape( FILE* File, FOOTPRINT* aFootprint, const wxString& aShapeName );
62 
63 // layer names for Gencad export
64 
65 static std::string GenCADLayerName( int aCuCount, PCB_LAYER_ID aId )
66 {
67  if( IsCopperLayer( aId ) )
68  {
69  if( aId == F_Cu )
70  return "TOP";
71  else if( aId == B_Cu )
72  return "BOTTOM";
73  else if( aId <= 14 )
74  return StrPrintf( "INNER%d", aCuCount - aId - 1 );
75  else
76  return StrPrintf( "LAYER%d", aId );
77  }
78 
79  else
80  {
81  const char* txt;
82 
83  // using a switch to clearly show mapping & catch out of bounds index.
84  switch( aId )
85  {
86  // Technicals
87  case B_Adhes: txt = "B.Adhes"; break;
88  case F_Adhes: txt = "F.Adhes"; break;
89  case B_Paste: txt = "SOLDERPASTE_BOTTOM"; break;
90  case F_Paste: txt = "SOLDERPASTE_TOP"; break;
91  case B_SilkS: txt = "SILKSCREEN_BOTTOM"; break;
92  case F_SilkS: txt = "SILKSCREEN_TOP"; break;
93  case B_Mask: txt = "SOLDERMASK_BOTTOM"; break;
94  case F_Mask: txt = "SOLDERMASK_TOP"; break;
95 
96  // Users
97  case Dwgs_User: txt = "Dwgs.User"; break;
98  case Cmts_User: txt = "Cmts.User"; break;
99  case Eco1_User: txt = "Eco1.User"; break;
100  case Eco2_User: txt = "Eco2.User"; break;
101  case Edge_Cuts: txt = "Edge.Cuts"; break;
102  case Margin: txt = "Margin"; break;
103 
104  // Footprint
105  case F_CrtYd: txt = "F_CrtYd"; break;
106  case B_CrtYd: txt = "B_CrtYd"; break;
107  case F_Fab: txt = "F_Fab"; break;
108  case B_Fab: txt = "B_Fab"; break;
109 
110  default:
111  wxASSERT_MSG( 0, wxT( "aId UNEXPECTED" ) );
112  txt = "BAD-INDEX!"; break;
113  }
114 
115  return txt;
116  }
117 }
118 
119 
120 static const PCB_LAYER_ID gc_seq[] = {
121  B_Cu,
122  In30_Cu,
123  In29_Cu,
124  In28_Cu,
125  In27_Cu,
126  In26_Cu,
127  In25_Cu,
128  In24_Cu,
129  In23_Cu,
130  In22_Cu,
131  In21_Cu,
132  In20_Cu,
133  In19_Cu,
134  In18_Cu,
135  In17_Cu,
136  In16_Cu,
137  In15_Cu,
138  In14_Cu,
139  In13_Cu,
140  In12_Cu,
141  In11_Cu,
142  In10_Cu,
143  In9_Cu,
144  In8_Cu,
145  In7_Cu,
146  In6_Cu,
147  In5_Cu,
148  In4_Cu,
149  In3_Cu,
150  In2_Cu,
151  In1_Cu,
152  F_Cu,
153 };
154 
155 
156 // flipped layer name for Gencad export (to make CAM350 imports correct)
157 static std::string GenCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
158 {
159  if( 1<= aId && aId <= 14 )
160  return StrPrintf( "INNER%d", 14 - aId );
161 
162  return GenCADLayerName( aCuCount, aId );
163 }
164 
165 
166 static wxString escapeString( const wxString& aString )
167 {
168  wxString copy( aString );
169  copy.Replace( "\"", "\\\"" );
170  return copy;
171 }
172 
173 
174 static std::string fmt_mask( LSET aSet )
175 {
176  return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
177 }
178 
179 // Export options
180 static bool flipBottomPads;
181 static bool uniquePins;
182 static bool individualShapes;
183 static bool storeOriginCoords;
184 
185 // These are the export origin (the auxiliary axis)
187 
188 // Association between shape names (using shapeName index) and components
189 static std::map<FOOTPRINT*, int> componentShapes;
190 static std::map<int, wxString> shapeNames;
191 
192 static const wxString getShapeName( FOOTPRINT* aFootprint )
193 {
194  static const wxString invalid( "invalid" );
195 
196  if( individualShapes )
197  return aFootprint->GetReference();
198 
199  auto itShape = componentShapes.find( aFootprint );
200  wxCHECK( itShape != componentShapes.end(), invalid );
201 
202  auto itName = shapeNames.find( itShape->second );
203  wxCHECK( itName != shapeNames.end(), invalid );
204 
205  return itName->second;
206 }
207 
208 // GerbTool chokes on units different than INCH so this is the conversion factor
209 const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS;
210 
211 /* Two helper functions to calculate coordinates of footprints in gencad values
212  * (GenCAD Y axis from bottom to top)
213  */
214 static double MapXTo( int aX )
215 {
216  return (aX - GencadOffsetX) / SCALE_FACTOR;
217 }
218 
219 
220 static double MapYTo( int aY )
221 {
222  return (GencadOffsetY - aY) / SCALE_FACTOR;
223 }
224 
225 
226 /* Driver function: processing starts here */
227 void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
228 {
229  // Build default output file name
230  wxString path = GetLastPath( LAST_PATH_GENCAD );
231 
232  if( path.IsEmpty() )
233  {
234  wxFileName brdFile = GetBoard()->GetFileName();
235  brdFile.SetExt( "cad" );
236  path = brdFile.GetFullPath();
237  }
238 
239  DIALOG_GENCAD_EXPORT_OPTIONS optionsDialog( this, path );
240 
241  if( optionsDialog.ShowModal() == wxID_CANCEL )
242  return;
243 
244  path = optionsDialog.GetFileName();
246  FILE* file = wxFopen( path, "wt" );
247 
248  if( !file )
249  {
250  DisplayError( this, wxString::Format( _( "Unable to create \"%s\"" ),
251  optionsDialog.GetFileName() ) );
252  return;
253  }
254 
255  // Get options
256  flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
257  uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
258  individualShapes = optionsDialog.GetOption( INDIVIDUAL_SHAPES );
260 
261  // Switch the locale to standard C (needed to print floating point numbers)
262  LOCALE_IO toggle;
263 
264  // Update some board data, to ensure a reliable gencad export
266 
267  // Save the auxiliary origin for the rest of the footprint
268  wxPoint auxOrigin = m_pcb->GetDesignSettings().m_AuxOrigin;
269  GencadOffsetX = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.x : 0;
270  GencadOffsetY = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.y : 0;
271 
272  // No idea on *why* this should be needed... maybe to fix net names?
273  Compile_Ratsnest( true );
274 
275  /* Temporary modification of footprints that are flipped (i.e. on bottom
276  * layer) to convert them to non flipped footprints.
277  * This is necessary to easily export shapes to GenCAD,
278  * that are given as normal orientation (non flipped, rotation = 0))
279  * these changes will be undone later
280  */
281  BOARD* pcb = GetBoard();
282 
283  for( FOOTPRINT* footprint : pcb->Footprints() )
284  {
285  footprint->SetFlag( 0 );
286 
287  if( footprint->GetLayer() == B_Cu )
288  {
289  footprint->Flip( footprint->GetPosition(), Settings().m_FlipLeftRight );
290  footprint->SetFlag( 1 );
291  }
292  }
293 
294  /* Gencad has some mandatory and some optional sections: some importer
295  * need the padstack section (which is optional) anyway. Also the
296  * order of the section *is* important */
297 
298  CreateHeaderInfoData( file, this ); // Gencad header
299  CreateBoardSection( file, pcb ); // Board perimeter
300 
301  CreatePadsShapesSection( file, pcb ); // Pads and padstacks
302  CreateArtworksSection( file ); // Empty but mandatory
303 
304  /* Gencad splits a component info in shape, component and device.
305  * We don't do any sharing (it would be difficult since each module is
306  * customizable after placement) */
307  CreateShapesSection( file, pcb );
308  CreateComponentsSection( file, pcb );
309  CreateDevicesSection( file, pcb );
310 
311  // In a similar way the netlist is split in net, track and route
312  CreateSignalsSection( file, pcb );
313  CreateTracksInfoData( file, pcb );
314  CreateRoutesSection( file, pcb );
315 
316  fclose( file );
317 
318  // Undo the footprints modifications (flipped footprints)
319  for( FOOTPRINT* footprint : pcb->Footprints() )
320  {
321  if( footprint->GetFlag() )
322  {
323  footprint->Flip( footprint->GetPosition(), Settings().m_FlipLeftRight );
324  footprint->SetFlag( 0 );
325  }
326  }
327 
328  componentShapes.clear();
329  shapeNames.clear();
330 }
331 
332 
333 // Sort vias for uniqueness
334 static bool ViaSort( const VIA* aPadref, const VIA* aPadcmp )
335 {
336  if( aPadref->GetWidth() != aPadcmp->GetWidth() )
337  return aPadref->GetWidth() < aPadcmp->GetWidth();
338 
339  if( aPadref->GetDrillValue() != aPadcmp->GetDrillValue() )
340  return aPadref->GetDrillValue() < aPadcmp->GetDrillValue();
341 
342  if( aPadref->GetLayerSet() != aPadcmp->GetLayerSet() )
343  return aPadref->GetLayerSet().FmtBin().compare( aPadcmp->GetLayerSet().FmtBin() ) < 0;
344 
345  return false;
346 }
347 
348 
349 // The ARTWORKS section is empty but (officially) mandatory
350 static void CreateArtworksSection( FILE* aFile )
351 {
352  /* The artworks section is empty */
353  fputs( "$ARTWORKS\n", aFile );
354  fputs( "$ENDARTWORKS\n\n", aFile );
355 }
356 
357 
358 // Emit PADS and PADSTACKS. They are sorted and emitted uniquely.
359 // Via name is synthesized from their attributes, pads are numbered
360 static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
361 {
362  std::vector<PAD*> padstacks;
363  std::vector<VIA*> vias;
364  std::vector<VIA*> viastacks;
365 
366  padstacks.resize( 1 ); // We count pads from 1
367 
368  // The master layermask (i.e. the enabled layers) for padstack generation
369  LSET master_layermask = aPcb->GetDesignSettings().GetEnabledLayers();
370  int cu_count = aPcb->GetCopperLayerCount();
371 
372  fputs( "$PADS\n", aFile );
373 
374  // Enumerate and sort the pads
375 
376  std::vector<PAD*> pads = aPcb->GetPads();
377  std::sort( pads.begin(), pads.end(), []( const PAD* a, const PAD* b )
378  {
379  return PAD::Compare( a, b ) < 0;
380  } );
381 
382 
383  // The same for vias
384  for( TRACK* track : aPcb->Tracks() )
385  {
386  if( VIA* via = dyn_cast<VIA*>( track ) )
387  vias.push_back( via );
388  }
389 
390  std::sort( vias.begin(), vias.end(), ViaSort );
391  vias.erase( std::unique( vias.begin(), vias.end(), []( const VIA* a, const VIA* b )
392  {
393  return ViaSort( a, b ) == false;
394  } ),
395  vias.end() );
396 
397  // Emit vias pads
398 
399  for( VIA* via : vias )
400  {
401  viastacks.push_back( via );
402  fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
403  via->GetWidth(), via->GetDrillValue(),
404  fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
405  via->GetDrillValue() / SCALE_FACTOR,
406  via->GetWidth() / (SCALE_FACTOR * 2) );
407  }
408 
409  // Emit component pads
410  PAD* old_pad = nullptr;
411  int pad_name_number = 0;
412 
413  for( unsigned i = 0; i<pads.size(); ++i )
414  {
415  PAD* pad = pads[i];
416  const wxPoint& off = pad->GetOffset();
417 
418  pad->SetSubRatsnest( pad_name_number );
419 
420  if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
421  continue; // already created
422 
423  old_pad = pad;
424 
425  pad_name_number++;
426  pad->SetSubRatsnest( pad_name_number );
427 
428  fprintf( aFile, "PAD P%d", pad->GetSubRatsnest() );
429 
430  padstacks.push_back( pad ); // Will have its own padstack later
431  int dx = pad->GetSize().x / 2;
432  int dy = pad->GetSize().y / 2;
433 
434  switch( pad->GetShape() )
435  {
436  default:
437  wxASSERT_MSG( false, "Pad type not implemented" );
439 
440  case PAD_SHAPE::CIRCLE:
441  fprintf( aFile, " ROUND %g\n",
442  pad->GetDrillSize().x / SCALE_FACTOR );
443  /* Circle is center, radius */
444  fprintf( aFile, "CIRCLE %g %g %g\n",
445  off.x / SCALE_FACTOR,
446  -off.y / SCALE_FACTOR,
447  pad->GetSize().x / (SCALE_FACTOR * 2) );
448  break;
449 
450  case PAD_SHAPE::RECT:
451  fprintf( aFile, " RECTANGULAR %g\n",
452  pad->GetDrillSize().x / SCALE_FACTOR );
453 
454  // Rectangle is begin, size *not* begin, end!
455  fprintf( aFile, "RECTANGLE %g %g %g %g\n",
456  (-dx + off.x ) / SCALE_FACTOR,
457  (-dy - off.y ) / SCALE_FACTOR,
458  dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
459  break;
460 
462  case PAD_SHAPE::OVAL:
463  {
464  const wxSize& size = pad->GetSize();
465  int radius;
466 
467  if( pad->GetShape() == PAD_SHAPE::ROUNDRECT )
468  radius = pad->GetRoundRectCornerRadius();
469  else
470  radius = std::min( size.x, size.y ) / 2;
471 
472  int lineX = size.x / 2 - radius;
473  int lineY = size.y / 2 - radius;
474 
475  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
476 
477  // bottom left arc
478  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
479  ( off.x - lineX - radius ) / SCALE_FACTOR,
480  ( -off.y - lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
481  ( -off.y - lineY - radius ) / SCALE_FACTOR,
482  ( off.x - lineX ) / SCALE_FACTOR, ( -off.y - lineY ) / SCALE_FACTOR );
483 
484  // bottom line
485  if( lineX > 0 )
486  {
487  fprintf( aFile, "LINE %g %g %g %g\n",
488  ( off.x - lineX ) / SCALE_FACTOR,
489  ( -off.y - lineY - radius ) / SCALE_FACTOR,
490  ( off.x + lineX ) / SCALE_FACTOR,
491  ( -off.y - lineY - radius ) / SCALE_FACTOR );
492  }
493 
494  // bottom right arc
495  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
496  ( off.x + lineX ) / SCALE_FACTOR,
497  ( -off.y - lineY - radius ) / SCALE_FACTOR,
498  ( off.x + lineX + radius ) / SCALE_FACTOR,
499  ( -off.y - lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
500  ( -off.y - lineY ) / SCALE_FACTOR );
501 
502  // right line
503  if( lineY > 0 )
504  {
505  fprintf( aFile, "LINE %g %g %g %g\n",
506  ( off.x + lineX + radius ) / SCALE_FACTOR,
507  ( -off.y + lineY ) / SCALE_FACTOR,
508  ( off.x + lineX + radius ) / SCALE_FACTOR,
509  ( -off.y - lineY ) / SCALE_FACTOR );
510  }
511 
512  // top right arc
513  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
514  ( off.x + lineX + radius ) / SCALE_FACTOR,
515  ( -off.y + lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
516  ( -off.y + lineY + radius ) / SCALE_FACTOR,
517  ( off.x + lineX ) / SCALE_FACTOR, ( -off.y + lineY ) / SCALE_FACTOR );
518 
519  // top line
520  if( lineX > 0 )
521  {
522  fprintf( aFile, "LINE %g %g %g %g\n"
523  , ( off.x - lineX ) / SCALE_FACTOR,
524  ( -off.y + lineY + radius ) / SCALE_FACTOR,
525  ( off.x + lineX ) / SCALE_FACTOR,
526  ( -off.y + lineY + radius ) / SCALE_FACTOR );
527  }
528 
529  // top left arc
530  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
531  ( off.x - lineX ) / SCALE_FACTOR,
532  ( -off.y + lineY + radius ) / SCALE_FACTOR,
533  ( off.x - lineX - radius ) / SCALE_FACTOR,
534  ( -off.y + lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
535  ( -off.y + lineY ) / SCALE_FACTOR );
536 
537  // left line
538  if( lineY > 0 )
539  {
540  fprintf( aFile, "LINE %g %g %g %g\n",
541  ( off.x - lineX - radius ) / SCALE_FACTOR,
542  ( -off.y - lineY ) / SCALE_FACTOR,
543  ( off.x - lineX - radius ) / SCALE_FACTOR,
544  ( -off.y + lineY ) / SCALE_FACTOR );
545  }
546  }
547  break;
548 
550  {
551  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
552 
553  int ddx = pad->GetDelta().x / 2;
554  int ddy = pad->GetDelta().y / 2;
555 
556  wxPoint poly[4];
557  poly[0] = wxPoint( -dx + ddy, dy + ddx );
558  poly[1] = wxPoint( dx - ddy, dy - ddx );
559  poly[2] = wxPoint( dx + ddy, -dy + ddx );
560  poly[3] = wxPoint( -dx - ddy, -dy - ddx );
561 
562  for( int cur = 0; cur < 4; ++cur )
563  {
564  int next = ( cur + 1 ) % 4;
565  fprintf( aFile, "LINE %g %g %g %g\n",
566  ( off.x + poly[cur].x ) / SCALE_FACTOR,
567  ( -off.y - poly[cur].y ) / SCALE_FACTOR,
568  ( off.x + poly[next].x ) / SCALE_FACTOR,
569  ( -off.y - poly[next].y ) / SCALE_FACTOR );
570  }
571  }
572  break;
573 
574  case PAD_SHAPE::CUSTOM:
575  {
576  fprintf( aFile, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
577 
578  SHAPE_POLY_SET outline;
579  pad->MergePrimitivesAsPolygon( &outline, UNDEFINED_LAYER );
580 
581  for( int jj = 0; jj < outline.OutlineCount(); ++jj )
582  {
583  const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
584  int pointCount = poly.PointCount();
585 
586  for( int ii = 0; ii < pointCount; ii++ )
587  {
588  int next = ( ii + 1 ) % pointCount;
589  fprintf( aFile, "LINE %g %g %g %g\n",
590  ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
591  ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
592  ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
593  ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
594  }
595  }
596  }
597  break;
598  }
599  }
600 
601  fputs( "\n$ENDPADS\n\n", aFile );
602 
603  // Now emit the padstacks definitions, using the combined layer masks
604  fputs( "$PADSTACKS\n", aFile );
605 
606  // Via padstacks
607  for( unsigned i = 0; i < viastacks.size(); i++ )
608  {
609  VIA* via = viastacks[i];
610 
611  LSET mask = via->GetLayerSet() & master_layermask;
612 
613  fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
614  via->GetWidth(), via->GetDrillValue(),
615  fmt_mask( mask ).c_str(),
616  via->GetDrillValue() / SCALE_FACTOR );
617 
618  for( LSEQ seq = mask.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
619  {
620  PCB_LAYER_ID layer = *seq;
621 
622  fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
623  via->GetWidth(), via->GetDrillValue(),
624  fmt_mask( mask ).c_str(),
625  GenCADLayerName( cu_count, layer ).c_str()
626  );
627  }
628  }
629 
630  /* Component padstacks
631  * Older versions of CAM350 don't apply correctly the FLIP semantics for
632  * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
633  * define the shape as MIRRORX and define a separate 'flipped' padstack...
634  * until it appears yet another noncompliant importer */
635  for( unsigned i = 1; i < padstacks.size(); i++ )
636  {
637  PAD* pad = padstacks[i];
638 
639  // Straight padstack
640  fprintf( aFile, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
641 
642  LSET pad_set = pad->GetLayerSet() & master_layermask;
643 
644  // the special gc_seq
645  for( LSEQ seq = pad_set.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
646  {
647  PCB_LAYER_ID layer = *seq;
648 
649  fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
650  }
651 
652  // Flipped padstack
653  if( flipBottomPads )
654  {
655  fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
656 
657  // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
658  for( LSEQ seq = pad_set.Seq(); seq; ++seq )
659  {
660  PCB_LAYER_ID layer = *seq;
661 
662  fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerNameFlipped( cu_count, layer ).c_str() );
663  }
664  }
665  }
666 
667  fputs( "$ENDPADSTACKS\n\n", aFile );
668 }
669 
670 
672 static size_t hashFootprint( const FOOTPRINT* aFootprint )
673 {
674  size_t ret = 0x11223344;
675  constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
677 
678  for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
679  ret += hash_fp_item( i, flags );
680 
681  for( PAD* i : aFootprint->Pads() )
682  ret += hash_fp_item( i, flags );
683 
684  return ret;
685 }
686 
687 
688 /* Creates the footprint shape list.
689  * Since module shape is customizable after the placement we cannot share them;
690  * instead we opt for the one-module-one-shape-one-component-one-device approach
691  */
692 static void CreateShapesSection( FILE* aFile, BOARD* aPcb )
693 {
694  const char* layer;
695  wxString pinname;
696  const char* mirror = "0";
697  std::map<wxString, size_t> shapes;
698 
699  fputs( "$SHAPES\n", aFile );
700 
701  for( FOOTPRINT* footprint : aPcb->Footprints() )
702  {
703  if( !individualShapes )
704  {
705  // Check if such shape has been already generated, and if so - reuse it
706  // It is necessary to compute hash (i.e. check all children objects) as
707  // certain components instances might have been modified on the board.
708  // In such case the shape will be different despite the same LIB_ID.
709  wxString shapeName = footprint->GetFPID().Format();
710 
711  auto shapeIt = shapes.find( shapeName );
712  size_t modHash = hashFootprint( footprint );
713 
714  if( shapeIt != shapes.end() )
715  {
716  if( modHash != shapeIt->second )
717  {
718  // there is an entry for this footprint, but it has a modified shape,
719  // so we need to create a new entry
720  wxString newShapeName;
721  int suffix = 0;
722 
723  // find an unused name or matching entry
724  do
725  {
726  newShapeName = wxString::Format( "%s_%d", shapeName, suffix );
727  shapeIt = shapes.find( newShapeName );
728  ++suffix;
729  }
730  while( shapeIt != shapes.end() && shapeIt->second != modHash );
731 
732  shapeName = newShapeName;
733  }
734 
735  if( shapeIt != shapes.end() && modHash == shapeIt->second )
736  {
737  // shape found, so reuse it
738  componentShapes[footprint] = modHash;
739  continue;
740  }
741  }
742 
743  // new shape
744  componentShapes[footprint] = modHash;
745  shapeNames[modHash] = shapeName;
746  shapes[shapeName] = modHash;
747  FootprintWriteShape( aFile, footprint, shapeName );
748  }
749  else // individual shape for each component
750  {
751  FootprintWriteShape( aFile, footprint, footprint->GetReference() );
752  }
753 
754  // set of already emitted pins to check for duplicates
755  std::set<wxString> pins;
756 
757  for( PAD* pad : footprint->Pads() )
758  {
759  /* Padstacks are defined using the correct layers for the pads, therefore to
760  * all pads need to be marked as TOP to use the padstack information correctly.
761  */
762  layer = "TOP";
763  pinname = pad->GetName();
764 
765  if( pinname.IsEmpty() )
766  pinname = wxT( "none" );
767 
768  if( uniquePins )
769  {
770  int suffix = 0;
771  wxString origPinname( pinname );
772 
773  auto it = pins.find( pinname );
774 
775  while( it != pins.end() )
776  {
777  pinname = wxString::Format( "%s_%d", origPinname, suffix );
778  ++suffix;
779  it = pins.find( pinname );
780  }
781 
782  pins.insert( pinname );
783  }
784 
785  double orient = pad->GetOrientation() - footprint->GetOrientation();
786  NORMALIZE_ANGLE_POS( orient );
787 
788  // Bottom side footprints use the flipped padstack
789  fprintf( aFile, ( flipBottomPads && footprint->GetFlag() ) ?
790  "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
791  "PIN \"%s\" PAD%d %g %g %s %g %s\n",
792  TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
793  pad->GetPos0().x / SCALE_FACTOR,
794  -pad->GetPos0().y / SCALE_FACTOR,
795  layer, orient / 10.0, mirror );
796  }
797  }
798 
799  fputs( "$ENDSHAPES\n\n", aFile );
800 }
801 
802 
803 /* Creates the section $COMPONENTS (Footprints placement)
804  * Bottom side components are difficult to handle: shapes must be mirrored or
805  * flipped, silk layers need to be handled correctly and so on. Also it seems
806  * that *noone* follows the specs...
807  */
808 static void CreateComponentsSection( FILE* aFile, BOARD* aPcb )
809 {
810  fputs( "$COMPONENTS\n", aFile );
811 
812  int cu_count = aPcb->GetCopperLayerCount();
813 
814  for( FOOTPRINT* footprint : aPcb->Footprints() )
815  {
816  const char* mirror;
817  const char* flip;
818  double fp_orient = footprint->GetOrientation();
819 
820  if( footprint->GetFlag() )
821  {
822  mirror = "MIRRORX";
823  flip = "FLIP";
824  NEGATE_AND_NORMALIZE_ANGLE_POS( fp_orient );
825  }
826  else
827  {
828  mirror = "0";
829  flip = "0";
830  }
831 
832  fprintf( aFile, "\nCOMPONENT \"%s\"\n",
833  TO_UTF8( escapeString( footprint->GetReference() ) ) );
834  fprintf( aFile, "DEVICE \"DEV_%s\"\n",
835  TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
836  fprintf( aFile, "PLACE %g %g\n",
837  MapXTo( footprint->GetPosition().x ),
838  MapYTo( footprint->GetPosition().y ) );
839  fprintf( aFile, "LAYER %s\n",
840  footprint->GetFlag() ? "BOTTOM" : "TOP" );
841  fprintf( aFile, "ROTATION %g\n",
842  fp_orient / 10.0 );
843  fprintf( aFile, "SHAPE \"%s\" %s %s\n",
844  TO_UTF8( escapeString( getShapeName( footprint ) ) ),
845  mirror, flip );
846 
847  // Text on silk layer: RefDes and value (are they actually useful?)
848  for( FP_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
849  {
850  double txt_orient = textItem->GetTextAngle();
851  std::string layer = GenCADLayerName( cu_count, footprint->GetFlag() ? B_SilkS : F_SilkS );
852 
853  fprintf( aFile, "TEXT %g %g %g %g %s %s \"%s\"",
854  textItem->GetPos0().x / SCALE_FACTOR,
855  -textItem->GetPos0().y / SCALE_FACTOR,
856  textItem->GetTextWidth() / SCALE_FACTOR,
857  txt_orient / 10.0,
858  mirror,
859  layer.c_str(),
860  TO_UTF8( escapeString( textItem->GetText() ) ) );
861 
862  // Please note, the width is approx
863  fprintf( aFile, " 0 0 %g %g\n",
864  ( textItem->GetTextWidth() * textItem->GetLength() ) / SCALE_FACTOR,
865  textItem->GetTextHeight() / SCALE_FACTOR );
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( footprint->GetReference() ),
871  TO_UTF8( footprint->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->GetNetCode() <= 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( FOOTPRINT* footprint : aPcb->Footprints() )
906  {
907  for( PAD* pad : footprint->Pads() )
908  {
909  if( pad->GetNetCode() != net->GetNetCode() )
910  continue;
911 
912  msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
913  escapeString( footprint->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 FOOTPRINT* footprint = componentShape.first;
1073 
1074  fprintf( aFile, "\nDEVICE \"DEV_%s\"\n", TO_UTF8( escapeString( shapeName ) ) );
1075 
1076  fprintf( aFile, "PART \"%s\"\n",
1077  TO_UTF8( escapeString( footprint->GetValue() ) ) );
1078 
1079  fprintf( aFile, "PACKAGE \"%s\"\n",
1080  TO_UTF8( escapeString( footprint->GetFPID().Format() ) ) );
1081  }
1082 
1083  fputs( "$ENDDEVICES\n\n", aFile );
1084 }
1085 
1086 
1087 /* Creates the section $BOARD.
1088  * We output here only the board perimeter
1089  */
1090 static void CreateBoardSection( FILE* aFile, BOARD* aPcb )
1091 {
1092  fputs( "$BOARD\n", aFile );
1093 
1094  // Extract the board edges
1095  for( BOARD_ITEM* drawing : aPcb->Drawings() )
1096  {
1097  if( drawing->Type() == PCB_SHAPE_T )
1098  {
1099  PCB_SHAPE* drawseg = static_cast<PCB_SHAPE*>( drawing );
1100 
1101  if( drawseg->GetLayer() == Edge_Cuts )
1102  {
1103  // XXX GenCAD supports arc boundaries but I've seen nothing that reads them
1104  fprintf( aFile, "LINE %g %g %g %g\n",
1105  MapXTo( drawseg->GetStart().x ), MapYTo( drawseg->GetStart().y ),
1106  MapXTo( drawseg->GetEnd().x ), MapYTo( drawseg->GetEnd().y ) );
1107  }
1108  }
1109  }
1110 
1111  fputs( "$ENDBOARD\n\n", aFile );
1112 }
1113 
1114 
1115 /* Creates the section "$TRACKS"
1116  * This sections give the list of widths (tools) used in tracks and vias
1117  * format:
1118  * $TRACK
1119  * TRACK <name> <width>
1120  * $ENDTRACK
1121  *
1122  * Each tool name is build like this: "TRACK" + track width.
1123  * For instance for a width = 120 : name = "TRACK120".
1124  */
1125 static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb )
1126 {
1127  // Find thickness used for traces
1128 
1129  std::set<int> trackinfo;
1130 
1131  for( TRACK* track : aPcb->Tracks() )
1132  trackinfo.insert( track->GetWidth() );
1133 
1134  // Write data
1135  fputs( "$TRACKS\n", aFile );
1136 
1137  for( int size : trackinfo )
1138  fprintf( aFile, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1139 
1140  fputs( "$ENDTRACKS\n\n", aFile );
1141 }
1142 
1143 
1144 /* Creates the shape of a footprint (section SHAPE)
1145  * The shape is always given "normal" (Orient 0, not mirrored)
1146  * It's almost guaranteed that the silk layer will be imported wrong but
1147  * the shape also contains the pads!
1148  */
1149 static void FootprintWriteShape( FILE* aFile, FOOTPRINT* aFootprint, const wxString& aShapeName )
1150 {
1151  FP_SHAPE* shape;
1152 
1153  /* creates header: */
1154  fprintf( aFile, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1155 
1156  if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1157  fprintf( aFile, "INSERT TH\n" );
1158  else
1159  fprintf( aFile, "INSERT SMD\n" );
1160 
1161  // Silk outline; wildly interpreted by various importers:
1162  // CAM350 read it right but only closed shapes
1163  // ProntoPlace double-flip it (at least the pads are correct)
1164  // GerberTool usually get it right...
1165  for( BOARD_ITEM* PtStruct : aFootprint->GraphicalItems() )
1166  {
1167  switch( PtStruct->Type() )
1168  {
1169  case PCB_FP_TEXT_T:
1170 
1171  // If we wanted to export text, this is not the correct section
1172  break;
1173 
1174  case PCB_FP_SHAPE_T:
1175  shape = (FP_SHAPE*) PtStruct;
1176  if( shape->GetLayer() == F_SilkS || shape->GetLayer() == B_SilkS )
1177  {
1178  switch( shape->GetShape() )
1179  {
1181  fprintf( aFile, "LINE %g %g %g %g\n",
1182  shape->m_Start0.x / SCALE_FACTOR,
1183  -shape->m_Start0.y / SCALE_FACTOR,
1184  shape->m_End0.x / SCALE_FACTOR,
1185  -shape->m_End0.y / SCALE_FACTOR );
1186  break;
1187 
1188  case PCB_SHAPE_TYPE::RECT:
1189  {
1190  fprintf( aFile, "LINE %g %g %g %g\n",
1191  shape->m_Start0.x / SCALE_FACTOR,
1192  -shape->m_Start0.y / SCALE_FACTOR,
1193  shape->m_End0.x / SCALE_FACTOR,
1194  -shape->m_Start0.y / SCALE_FACTOR );
1195  fprintf( aFile, "LINE %g %g %g %g\n",
1196  shape->m_End0.x / SCALE_FACTOR,
1197  -shape->m_Start0.y / SCALE_FACTOR,
1198  shape->m_End0.x / SCALE_FACTOR,
1199  -shape->m_End0.y / SCALE_FACTOR );
1200  fprintf( aFile, "LINE %g %g %g %g\n",
1201  shape->m_End0.x / SCALE_FACTOR,
1202  -shape->m_End0.y / SCALE_FACTOR,
1203  shape->m_Start0.x / SCALE_FACTOR,
1204  -shape->m_End0.y / SCALE_FACTOR );
1205  fprintf( aFile, "LINE %g %g %g %g\n",
1206  shape->m_Start0.x / SCALE_FACTOR,
1207  -shape->m_End0.y / SCALE_FACTOR,
1208  shape->m_Start0.x / SCALE_FACTOR,
1209  -shape->m_Start0.y / SCALE_FACTOR );
1210  }
1211  break;
1212 
1214  {
1215  int radius = KiROUND( GetLineLength( shape->m_End0, shape->m_Start0 ) );
1216  fprintf( aFile, "CIRCLE %g %g %g\n",
1217  shape->m_Start0.x / SCALE_FACTOR,
1218  -shape->m_Start0.y / SCALE_FACTOR,
1219  radius / SCALE_FACTOR );
1220  break;
1221  }
1222 
1223  case PCB_SHAPE_TYPE::ARC:
1224  {
1225  int arcendx, arcendy;
1226  arcendx = shape->m_End0.x - shape->m_Start0.x;
1227  arcendy = shape->m_End0.y - shape->m_Start0.y;
1228  RotatePoint( &arcendx, &arcendy, -shape->GetAngle() );
1229  arcendx += shape->GetStart0().x;
1230  arcendy += shape->GetStart0().y;
1231 
1232  fprintf( aFile, "ARC %g %g %g %g %g %g\n",
1233  shape->m_End0.x / SCALE_FACTOR,
1234  -shape->GetEnd0().y / SCALE_FACTOR,
1235  arcendx / SCALE_FACTOR,
1236  -arcendy / SCALE_FACTOR,
1237  shape->GetStart0().x / SCALE_FACTOR,
1238  -shape->GetStart0().y / SCALE_FACTOR );
1239  break;
1240  }
1241 
1243  // Not exported (TODO)
1244  break;
1245 
1246  default:
1247  wxFAIL_MSG( wxString::Format( "Type Edge Module %d invalid.",
1248  PtStruct->Type() ) );
1249  break;
1250  }
1251  }
1252  break;
1253 
1254  default:
1255  break;
1256  }
1257  }
1258 }
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:252
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:1291
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:448
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
static void CreateRoutesSection(FILE *aFile, BOARD *aPcb)
PCB_SHAPE_TYPE GetShape() const
Definition: pcb_shape.h:130
static int Compare(const PAD *padref, const PAD *padcmp)
Compare two pads and return 0 if they are equal.
Definition: pad.cpp:1004
static void CreateSignalsSection(FILE *aFile, BOARD *aPcb)
static double MapYTo(int aY)
static bool uniquePins
const wxPoint & GetStart0() const
Definition: fp_shape.h:112
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
void ExportToGenCAD(wxCommandEvent &event)
Create a file in GenCAD 1.4 format from the current board.
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
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
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:300
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
This file contains miscellaneous commonly used macros and functions.
polygon (not yet used for tracks, but could be in microwave apps)
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)
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
Definition: board.h:785
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:1940
segment with non rounded ends
FOOTPRINTS & Footprints()
Definition: board.h:305
static const PCB_LAYER_ID gc_seq[]
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:426
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
static bool storeOriginCoords
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
UTF8 Format() const
Definition: lib_id.cpp:233
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
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()
usual segment : line with rounded ends
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:1052
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
static int GencadOffsetX
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
static std::string fmt_mask(LSET aSet)
BOARD * GetBoard() const
Definition: pad.h:60
static std::map< int, wxString > shapeNames
Arcs (with rounded ends)
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:308
wxPoint m_AuxOrigin
origin for plot exports
TRACKS & Tracks()
Definition: board.h:302
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