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