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