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 ( aSet & LSET::AllCuMask() ).to_string();
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( false, false );
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( PCB_LAYER_ID layer : mask.Seq( gc_seq, arrayDim( gc_seq ) ) )
593 {
594 fprintf( m_file, "PAD V%d.%d.%s %s 0 0\n",
595 via->GetWidth(), via->GetDrillValue(),
596 fmt_mask( mask ).c_str(),
597 GenCADLayerName( cu_count, layer ).c_str() );
598 }
599 }
600
601 /* Component padstacks
602 * Older versions of CAM350 don't apply correctly the FLIP semantics for
603 * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
604 * define the shape as MIRRORX and define a separate 'flipped' padstack...
605 * until it appears yet another non-compliant importer */
606 for( unsigned i = 1; i < padstacks.size(); i++ )
607 {
608 PAD* pad = padstacks[i];
609
610 // Straight padstack
611 fprintf( m_file, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
612
613 LSET pad_set = pad->GetLayerSet() & master_layermask;
614
615 // the special gc_seq
616 for( PCB_LAYER_ID layer : pad_set.Seq( gc_seq, arrayDim( gc_seq ) ) )
617 {
618 fprintf( m_file, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
619 }
620
621 // Flipped padstack
622 if( m_flipBottomPads )
623 {
624 fprintf( m_file, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
625
626 // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
627 for( PCB_LAYER_ID layer : pad_set.Seq() )
628 {
629 fprintf( m_file, "PAD P%u %s 0 0\n", i,
630 GenCADLayerNameFlipped( cu_count, layer ).c_str() );
631 }
632 }
633 }
634
635 fputs( "$ENDPADSTACKS\n\n", m_file );
636}
637
638
640static size_t hashFootprint( const FOOTPRINT* aFootprint )
641{
642 size_t ret = 0x11223344;
643 constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
645
646 for( PCB_FIELD* i : aFootprint->Fields() )
647 ret += hash_fp_item( i, flags );
648
649 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
650 ret += hash_fp_item( i, flags );
651
652 for( PAD* i : aFootprint->Pads() )
653 ret += hash_fp_item( i, flags );
654
655 return ret;
656}
657
658
659/* Creates the footprint shape list.
660 * Since module shape is customizable after the placement we cannot share them;
661 * instead we opt for the one-module-one-shape-one-component-one-device approach
662 */
664{
665 const char* layer;
666 wxString pinname;
667 const char* mirror = "0";
668 std::map<wxString, size_t> shapes;
669
670 fputs( "$SHAPES\n", m_file );
671
672 for( FOOTPRINT* footprint : m_board->Footprints() )
673 {
675 {
676 // Check if such shape has been already generated, and if so - reuse it
677 // It is necessary to compute hash (i.e. check all children objects) as
678 // certain components instances might have been modified on the board.
679 // In such case the shape will be different despite the same LIB_ID.
680 wxString shapeName = footprint->GetFPID().Format();
681
682 auto shapeIt = shapes.find( shapeName );
683 size_t modHash = hashFootprint( footprint );
684
685 if( shapeIt != shapes.end() )
686 {
687 if( modHash != shapeIt->second )
688 {
689 // there is an entry for this footprint, but it has a modified shape,
690 // so we need to create a new entry
691 wxString newShapeName;
692 int suffix = 0;
693
694 // find an unused name or matching entry
695 do
696 {
697 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
698 shapeIt = shapes.find( newShapeName );
699 ++suffix;
700 }
701 while( shapeIt != shapes.end() && shapeIt->second != modHash );
702
703 shapeName = newShapeName;
704 }
705
706 if( shapeIt != shapes.end() && modHash == shapeIt->second )
707 {
708 // shape found, so reuse it
709 componentShapes[footprint] = modHash;
710 continue;
711 }
712 }
713
714 // new shape
715 componentShapes[footprint] = modHash;
716 shapeNames[modHash] = shapeName;
717 shapes[shapeName] = modHash;
718 FootprintWriteShape( footprint, shapeName );
719 }
720 else // individual shape for each component
721 {
722 FootprintWriteShape( footprint, footprint->GetReference() );
723 }
724
725 // set of already emitted pins to check for duplicates
726 std::set<wxString> pins;
727
728 for( PAD* pad : footprint->Pads() )
729 {
730 /* Padstacks are defined using the correct layers for the pads, therefore to
731 * all pads need to be marked as TOP to use the padstack information correctly.
732 */
733 layer = "TOP";
734 pinname = pad->GetNumber();
735
736 if( pinname.IsEmpty() )
737 pinname = wxT( "none" );
738
739 if( m_useUniquePins )
740 {
741 int suffix = 0;
742 wxString origPinname( pinname );
743
744 auto it = pins.find( pinname );
745
746 while( it != pins.end() )
747 {
748 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
749 ++suffix;
750 it = pins.find( pinname );
751 }
752
753 pins.insert( pinname );
754 }
755
756 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
757 orient.Normalize();
758
759 VECTOR2I padPos = pad->GetFPRelativePosition();
760
761 // Bottom side footprints use the flipped padstack
762 fprintf( m_file, ( m_flipBottomPads && footprint->GetFlag() ) ?
763 "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
764 "PIN \"%s\" PAD%d %g %g %s %g %s\n",
765 TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
766 padPos.x / SCALE_FACTOR,
767 -padPos.y / SCALE_FACTOR,
768 layer, orient.AsDegrees(), mirror );
769 }
770 }
771
772 fputs( "$ENDSHAPES\n\n", m_file );
773}
774
775
776/* Creates the section $COMPONENTS (Footprints placement)
777 * Bottom side components are difficult to handle: shapes must be mirrored or
778 * flipped, silk layers need to be handled correctly and so on. Also it seems
779 * that *no one* follows the specs...
780 */
782{
783 fputs( "$COMPONENTS\n", m_file );
784
785 int cu_count = m_board->GetCopperLayerCount();
786
787 for( FOOTPRINT* footprint : m_board->Footprints() )
788 {
789 const char* mirror;
790 const char* flip;
791 EDA_ANGLE fp_orient = footprint->GetOrientation();
792
793 if( footprint->GetFlag() )
794 {
795 mirror = "MIRRORX";
796 flip = "FLIP";
797 fp_orient = fp_orient.Invert().Normalize();
798 }
799 else
800 {
801 mirror = "0";
802 flip = "0";
803 }
804
805 fprintf( m_file, "\nCOMPONENT \"%s\"\n",
806 TO_UTF8( escapeString( footprint->GetReference() ) ) );
807 fprintf( m_file, "DEVICE \"DEV_%s\"\n",
808 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
809 fprintf( m_file, "PLACE %g %g\n",
810 MapXTo( footprint->GetPosition().x ),
811 MapYTo( footprint->GetPosition().y ) );
812 fprintf( m_file, "LAYER %s\n",
813 footprint->GetFlag() ? "BOTTOM" : "TOP" );
814 fprintf( m_file, "ROTATION %g\n",
815 fp_orient.AsDegrees() );
816 fprintf( m_file, "SHAPE \"%s\" %s %s\n",
817 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
818 mirror, flip );
819
820 // Text on silk layer: RefDes and value (are they actually useful?)
821 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
822 {
823 std::string layer = GenCADLayerName( cu_count,
824 footprint->GetFlag() ? B_SilkS : F_SilkS );
825
826 fprintf( m_file, "TEXT %g %g %g %g %s %s \"%s\"",
827 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
828 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
829 textItem->GetTextWidth() / SCALE_FACTOR,
830 textItem->GetTextAngle().AsDegrees(),
831 mirror,
832 layer.c_str(),
833 TO_UTF8( escapeString( textItem->GetText() ) ) );
834
835 BOX2I textBox = textItem->GetTextBox();
836
837 fprintf( m_file, " 0 0 %g %g\n",
838 textBox.GetWidth() / SCALE_FACTOR,
839 textBox.GetHeight() / SCALE_FACTOR );
840 }
841
842 // The SHEET is a 'generic description' for referencing the component
843 fprintf( m_file, "SHEET \"RefDes: %s, Value: %s\"\n",
844 TO_UTF8( footprint->GetReference() ),
845 TO_UTF8( footprint->GetValue() ) );
846 }
847
848 fputs( "$ENDCOMPONENTS\n\n", m_file );
849}
850
851
853{
854 // Emit the netlist (which is actually the thing for which GenCAD is used these
855 // days!); tracks are handled later
856
857 wxString msg;
858 NETINFO_ITEM* net;
859 int NbNoConn = 1;
860
861 fputs( "$SIGNALS\n", m_file );
862
863 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
864 {
865 net = m_board->FindNet( ii );
866
867 if( net )
868 {
869 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
870 {
871 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
872 }
873
874 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
875 continue;
876
877 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
878
879 fputs( TO_UTF8( msg ), m_file );
880 fputs( "\n", m_file );
881
882 for( FOOTPRINT* footprint : m_board->Footprints() )
883 {
884 for( PAD* pad : footprint->Pads() )
885 {
886 if( pad->GetNetCode() != net->GetNetCode() )
887 continue;
888
889 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
890 escapeString( footprint->GetReference() ),
891 escapeString( pad->GetNumber() ) );
892
893 fputs( TO_UTF8( msg ), m_file );
894 fputs( "\n", m_file );
895 }
896 }
897 }
898 }
899
900 fputs( "$ENDSIGNALS\n\n", m_file );
901}
902
903
905{
906 wxString msg;
907
908 fputs( "$HEADER\n", m_file );
909 fputs( "GENCAD 1.4\n", m_file );
910
911 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
912 msg.Printf( wxT( "USER \"KiCad %s\"\n" ), GetBuildVersion() );
913 fputs( TO_UTF8( msg ), m_file );
914
915 msg = wxT( "DRAWING \"" ) + m_board->GetFileName() + wxT( "\"\n" );
916 fputs( TO_UTF8( msg ), m_file );
917
919 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
920 msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
921
922 fputs( TO_UTF8( msg ), m_file );
923 fputs( "UNITS INCH\n", m_file );
924
925 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
926 msg.Printf( wxT( "ORIGIN %g %g\n" ),
927 m_storeOriginCoords ? MapXTo( 0 ) : 0,
928 m_storeOriginCoords ? MapYTo( 0 ) : 0 );
929 fputs( TO_UTF8( msg ), m_file );
930
931 fputs( "INTERTRACK 0\n", m_file );
932 fputs( "$ENDHEADER\n\n", m_file );
933
934 return true;
935}
936
937
939{
940 /* Creates the section ROUTES
941 * that handles tracks, vias
942 * TODO: add zones
943 * section:
944 * $ROUTE
945 * ...
946 * $ENROUTE
947 * Track segments must be sorted by nets
948 */
949
950 int vianum = 1;
951 int old_netcode, old_width, old_layer;
952 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
953
954 int cu_count = m_board->GetCopperLayerCount();
955
956 TRACKS tracks( m_board->Tracks() );
957 std::sort( tracks.begin(), tracks.end(),
958 []( const PCB_TRACK* a, const PCB_TRACK* b )
959 {
960 if( a->GetNetCode() == b->GetNetCode() )
961 {
962 if( a->GetWidth() == b->GetWidth() )
963 return ( a->GetLayer() < b->GetLayer() );
964
965 return ( a->GetWidth() < b->GetWidth() );
966 }
967
968 return ( a->GetNetCode() < b->GetNetCode() );
969 } );
970
971 fputs( "$ROUTES\n", m_file );
972
973 old_netcode = -1; old_width = -1; old_layer = -1;
974
975 for( PCB_TRACK* track : tracks )
976 {
977 if( old_netcode != track->GetNetCode() )
978 {
979 old_netcode = track->GetNetCode();
980 NETINFO_ITEM* net = track->GetNet();
981 wxString netname;
982
983 if( net && (net->GetNetname() != wxEmptyString) )
984 netname = net->GetNetname();
985 else
986 netname = wxT( "_noname_" );
987
988 fprintf( m_file, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
989 }
990
991 if( old_width != track->GetWidth() )
992 {
993 old_width = track->GetWidth();
994 fprintf( m_file, "TRACK TRACK%d\n", track->GetWidth() );
995 }
996
997 if( track->Type() == PCB_TRACE_T )
998 {
999 if( old_layer != track->GetLayer() )
1000 {
1001 old_layer = track->GetLayer();
1002 fprintf( m_file, "LAYER %s\n",
1003 GenCADLayerName( cu_count, track->GetLayer() ).c_str() );
1004 }
1005
1006 fprintf( m_file, "LINE %g %g %g %g\n",
1007 MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
1008 MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
1009 }
1010
1011 if( track->Type() == PCB_VIA_T )
1012 {
1013 const PCB_VIA* via = static_cast<const PCB_VIA*>(track);
1014
1015 LSET vset = via->GetLayerSet() & master_layermask;
1016
1017 fprintf( m_file, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
1018 via->GetWidth(), via->GetDrillValue(),
1019 fmt_mask( vset ).c_str(),
1020 MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
1021 via->GetDrillValue() / SCALE_FACTOR, vianum++ );
1022 }
1023 }
1024
1025 fputs( "$ENDROUTES\n\n", m_file );
1026}
1027
1028
1030{
1031 /* Creates the section $DEVICES
1032 * This is a list of footprints properties
1033 * ( Shapes are in section $SHAPE )
1034 */
1035 std::set<wxString> emitted;
1036
1037 fputs( "$DEVICES\n", m_file );
1038
1039 // componentShapes (as a std::map<>) does not give the same order for items between 2 runs.
1040 // This is annoying when one want to compare 2 similar files.
1041 // Therefore we store the strings in a wxArrayString, and after created, strings will be sorted.
1042 // This is not perfect, because the selected footprint used to create the DEVICE section is
1043 // not always the same between runs, but this is much better than no sort
1044 wxArrayString data;
1045
1046 for( const auto& componentShape : componentShapes )
1047 {
1048 const wxString& shapeName = shapeNames[componentShape.second];
1049 bool newDevice;
1050 std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1051
1052 if( !newDevice ) // do not repeat device definitions
1053 continue;
1054
1055 const FOOTPRINT* footprint = componentShape.first;
1056
1057 wxString txt;
1058 txt.Printf( "\nDEVICE \"DEV_%s\"\n", escapeString( shapeName ) );
1059 txt += wxString::Format( "PART \"%s\"\n", escapeString( footprint->GetValue() ) );
1060 txt += wxString::Format( "PACKAGE \"%s\"\n", escapeString( footprint->GetFPID().Format() ) );
1061
1062 data.Add( txt );
1063 }
1064
1065 data.Sort();
1066
1067 for( wxString& item : data )
1068 fprintf( m_file, "%s", TO_UTF8( item ) );
1069
1070 fputs( "$ENDDEVICES\n\n", m_file );
1071}
1072
1073
1075{
1076 // Creates the section $BOARD.
1077 // We output here only the board perimeter
1078
1079 fputs( "$BOARD\n", m_file );
1080
1081 // Extract the board edges
1082 SHAPE_POLY_SET outline;
1083 m_board->GetBoardPolygonOutlines( outline );
1084
1085 for( auto seg1 = outline.IterateSegmentsWithHoles(); seg1; seg1++ )
1086 {
1087 SEG seg = *seg1;
1088 fprintf( m_file, "LINE %g %g %g %g\n",
1089 MapXTo( seg.A.x ), MapYTo( seg.A.y ),
1090 MapXTo( seg.B.x ), MapYTo( seg.B.y ) );
1091 }
1092
1093 fputs( "$ENDBOARD\n\n", m_file );
1094}
1095
1096
1097/* Creates the section "$TRACKS"
1098 * This sections give the list of widths (tools) used in tracks and vias
1099 * format:
1100 * $TRACK
1101 * TRACK <name> <width>
1102 * $ENDTRACK
1103 *
1104 * Each tool name is build like this: "TRACK" + track width.
1105 * For instance for a width = 120 : name = "TRACK120".
1106 */
1108{
1109 // Find thickness used for traces
1110 std::set<int> trackinfo;
1111
1112 for( PCB_TRACK* track : m_board->Tracks() )
1113 trackinfo.insert( track->GetWidth() );
1114
1115 // Write data
1116 fputs( "$TRACKS\n", m_file );
1117
1118 for( int size : trackinfo )
1119 fprintf( m_file, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1120
1121 fputs( "$ENDTRACKS\n\n", m_file );
1122}
1123
1124
1125/* Creates the shape of a footprint (section SHAPE)
1126 * The shape is always given "normal" (Orient 0, not mirrored)
1127 * It's almost guaranteed that the silk layer will be imported wrong but
1128 * the shape also contains the pads!
1129 */
1130void GENCAD_EXPORTER::FootprintWriteShape( FOOTPRINT* aFootprint, const wxString& aShapeName )
1131{
1132 /* creates header: */
1133 fprintf( m_file, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1134
1135 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1136 fprintf( m_file, "INSERT TH\n" );
1137 else
1138 fprintf( m_file, "INSERT SMD\n" );
1139
1140 // Silk outline; wildly interpreted by various importers:
1141 // CAM350 read it right but only closed shapes
1142 // ProntoPlace double-flip it (at least the pads are correct)
1143 // GerberTool usually get it right...
1144 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1145 {
1146 if( item->Type() == PCB_SHAPE_T
1147 && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) )
1148 {
1149 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1150 VECTOR2I start = shape->GetStart() - aFootprint->GetPosition();
1151 VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition();
1152 VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition();
1153
1154 RotatePoint( start, -aFootprint->GetOrientation() );
1155 RotatePoint( end, -aFootprint->GetOrientation() );
1156 RotatePoint( center, -aFootprint->GetOrientation() );
1157
1158 switch( shape->GetShape() )
1159 {
1160 case SHAPE_T::SEGMENT:
1161 fprintf( m_file, "LINE %g %g %g %g\n",
1162 start.x / SCALE_FACTOR,
1163 -start.y / SCALE_FACTOR,
1164 end.x / SCALE_FACTOR,
1165 -end.y / SCALE_FACTOR );
1166 break;
1167
1168 case SHAPE_T::RECTANGLE:
1169 fprintf( m_file, "LINE %g %g %g %g\n",
1170 start.x / SCALE_FACTOR,
1171 -start.y / SCALE_FACTOR,
1172 end.x / SCALE_FACTOR,
1173 -end.y / SCALE_FACTOR );
1174 fprintf( m_file, "LINE %g %g %g %g\n",
1175 end.x / SCALE_FACTOR,
1176 -start.y / SCALE_FACTOR,
1177 end.x / SCALE_FACTOR,
1178 -end.y / SCALE_FACTOR );
1179 fprintf( m_file, "LINE %g %g %g %g\n",
1180 end.x / SCALE_FACTOR,
1181 -end.y / SCALE_FACTOR,
1182 start.x / SCALE_FACTOR,
1183 -end.y / SCALE_FACTOR );
1184 fprintf( m_file, "LINE %g %g %g %g\n",
1185 start.x / SCALE_FACTOR,
1186 -end.y / SCALE_FACTOR,
1187 start.x / SCALE_FACTOR,
1188 -start.y / SCALE_FACTOR );
1189 break;
1190
1191 case SHAPE_T::CIRCLE:
1192 {
1193 int radius = KiROUND( end.Distance( start ) );
1194
1195 fprintf( m_file, "CIRCLE %g %g %g\n",
1196 start.x / SCALE_FACTOR,
1197 -start.y / SCALE_FACTOR,
1198 radius / SCALE_FACTOR );
1199 break;
1200 }
1201
1202 case SHAPE_T::ARC:
1203 if( shape->GetArcAngle() > ANGLE_0 )
1204 std::swap( start, end );
1205
1206 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
1207 start.x / SCALE_FACTOR,
1208 -start.y / SCALE_FACTOR,
1209 end.x / SCALE_FACTOR,
1210 -end.y / SCALE_FACTOR,
1211 center.x / SCALE_FACTOR,
1212 -center.y / SCALE_FACTOR );
1213 break;
1214
1215 case SHAPE_T::POLY:
1216 // Not exported (TODO)
1217 break;
1218
1219 default:
1220 wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) );
1221 break;
1222 }
1223 }
1224 }
1225}
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:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
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:2473
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1900
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aIncludeHiddenText=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1652
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:2573
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:688
int GetCopperLayerCount() const
Definition: board.cpp:733
const FOOTPRINTS & Footprints() const
Definition: board.h:330
const TRACKS & Tracks() const
Definition: board.h:328
const wxString & GetFileName() const
Definition: board.h:326
PROJECT * GetProject() const
Definition: board.h:490
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:874
unsigned GetNetCount() const
Definition: board.h:895
size_type GetHeight() const
Definition: box2.h:205
size_type GetWidth() const
Definition: box2.h:204
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Invert() const
Definition: eda_angle.h:165
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:682
SHAPE_T GetShape() const
Definition: eda_shape.h:125
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:167
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:130
EDA_ANGLE GetOrientation() const
Definition: footprint.h:216
int GetAttributes() const
Definition: footprint.h:279
PADS & Pads()
Definition: footprint.h:195
const LIB_ID & GetFPID() const
Definition: footprint.h:237
PCB_FIELDS & Fields()
Definition: footprint.h:192
const wxString & GetValue() const
Definition: footprint.h:613
const wxString & GetReference() const
Definition: footprint.h:591
VECTOR2I GetPosition() const override
Definition: footprint.h:213
DRAWINGS & GraphicalItems()
Definition: footprint.h:198
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
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
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:392
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:732
std::string FmtBin() const
Return a binary string showing contents of this LSEQ.
Definition: lset.cpp:278
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:54
static int Compare(const PAD *aPadRef, const PAD *aPadCmp)
Compare two pads and return 0 if they are equal.
Definition: pad.cpp:1307
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:116
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:544
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:891
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
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:550
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:59
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:401
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:74
@ 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:531
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
@ 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:121
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:673