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