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