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 <string_utils.h>
30#include <macros.h>
31#include <hash_eda.h>
32#include <fmt.h>
33
34
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 fmt::format( "INNER{}", aCuCount - aId - 1 );
46 else
47 return fmt::format( "LAYER{}", static_cast<int>( 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
92static std::string genCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
93{
94 if( 1<= aId && aId <= 14 )
95 return fmt::format( "INNER{}", 14 - aId );
96
97 return genCADLayerName( aCuCount, aId );
98}
99
100
101static wxString escapeString( const wxString& aString )
102{
103 wxString copy( aString );
104 copy.Replace( wxT( "\"" ), wxT( "\\\"" ) );
105 return copy;
106}
107
108
109static std::string fmt_mask( const LSET& aSet )
110{
111 std::string retv = ( aSet & LSET::AllCuMask() ).to_string();
112 retv.erase( 0, retv.find_first_not_of( '0' ) );
113 return retv;
114}
115
116
118static std::map<FOOTPRINT*, int> componentShapes;
119static std::map<int, wxString> shapeNames;
120
121
122const wxString GENCAD_EXPORTER::getShapeName( FOOTPRINT* aFootprint )
123{
124 static const wxString invalid( "invalid" );
125
127 return aFootprint->GetReference();
128
129 auto itShape = componentShapes.find( aFootprint );
130 wxCHECK( itShape != componentShapes.end(), invalid );
131
132 auto itName = shapeNames.find( itShape->second );
133 wxCHECK( itName != shapeNames.end(), invalid );
134
135 return itName->second;
136}
137
138
139// GerbTool chokes on units different than INCH so this is the conversion factor
140const static double SCALE_FACTOR = 1000.0 * pcbIUScale.IU_PER_MILS;
141
142
144{
145 return ( aX - m_gencadOffset.x ) / SCALE_FACTOR;
146}
147
148
150{
151 return ( m_gencadOffset.y - aY ) / SCALE_FACTOR;
152}
153
154
155bool GENCAD_EXPORTER::WriteFile( const wxString& aFullFileName )
156{
157 componentShapes.clear();
158 shapeNames.clear();
159
160 m_file = wxFopen( aFullFileName, wxT( "wt" ) );
161
162 if( !m_file )
163 return false;
164
165 BOARD* pcb = m_board;
166
167 // Update some board data, to ensure a reliable GenCAD export.
168 pcb->ComputeBoundingBox( false );
169
170 /* Temporary modification of footprints that are flipped (i.e. on bottom
171 * layer) to convert them to non flipped footprints.
172 * This is necessary to easily export shapes to GenCAD,
173 * that are given as normal orientation (non flipped, rotation = 0))
174 * these changes will be undone later
175 */
176
177 for( FOOTPRINT* footprint : pcb->Footprints() )
178 {
179 footprint->SetFlag( 0 );
180
181 if( footprint->GetLayer() == B_Cu )
182 {
183 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
184 footprint->SetFlag( 1 );
185 }
186 }
187
188 bool success = true;
189 try
190 {
191 /* GenCAD has some mandatory and some optional sections: some importer
192 * need the padstack section (which is optional) anyway. Also the
193 * order of the section *is* important */
194
195 createHeaderInfoData(); // GenCAD header
196 createBoardSection(); // Board perimeter
197
198 createPadsShapesSection(); // Pads and padstacks
199 createArtworksSection(); // Empty but mandatory
200
201 /* GenCAD splits a footprint information in shape, component and device.
202 * We don't do any sharing (it would be difficult since each module is
203 * customizable after placement) */
207
208 // In a similar way the netlist is split in net, track and route
212 }
213 catch( ... )
214 {
215 success = false;
216 }
217
218 fclose( m_file );
219
220 // Undo the footprints modifications (flipped footprints)
221 for( FOOTPRINT* footprint : pcb->Footprints() )
222 {
223 if( footprint->GetFlag() )
224 {
225 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
226 footprint->SetFlag( 0 );
227 }
228 }
229
230 componentShapes.clear();
231 shapeNames.clear();
232
233 return success;
234}
235
236
238static bool viaSort( const PCB_VIA* aPadref, const PCB_VIA* aPadcmp )
239{
240 if( aPadref->GetWidth( PADSTACK::ALL_LAYERS ) != aPadcmp->GetWidth( PADSTACK::ALL_LAYERS ) )
241 return aPadref->GetWidth( PADSTACK::ALL_LAYERS ) < aPadcmp->GetWidth( PADSTACK::ALL_LAYERS );
242
243 if( aPadref->GetDrillValue() != aPadcmp->GetDrillValue() )
244 return aPadref->GetDrillValue() < aPadcmp->GetDrillValue();
245
246 if( aPadref->GetLayerSet() != aPadcmp->GetLayerSet() )
247 return aPadref->GetLayerSet().FmtBin().compare( aPadcmp->GetLayerSet().FmtBin() ) < 0;
248
249 return false;
250}
251
252
254{
255 // The ARTWORKS section is empty but (officially) mandatory
256 fmt::print( m_file, "$ARTWORKS\n" );
257 fmt::print( m_file, "$ENDARTWORKS\n\n" );
258}
259
260
262{
263 // Emit PADS and PADSTACKS. They are sorted and emitted uniquely.
264 // Via name is synthesized from their attributes, pads are numbered
265
266 std::vector<PAD*> padstacks;
267 std::vector<PCB_VIA*> vias;
268 std::vector<PCB_VIA*> viastacks;
269
270 padstacks.resize( 1 ); // We count pads from 1
271
272 LSEQ gc_seq = m_board->GetEnabledLayers().CuStack();
273 std::reverse(gc_seq.begin(), gc_seq.end());
274
275 // The master layermask (i.e. the enabled layers) for padstack generation
276 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
277 int cu_count = m_board->GetCopperLayerCount();
278
279 fmt::print( m_file, "$PADS\n" );
280
281 // Enumerate and sort the pads
282 std::vector<PAD*> pads = m_board->GetPads();
283 std::sort( pads.begin(), pads.end(), []( const PAD* a, const PAD* b )
284 {
285 return PAD::Compare( a, b ) < 0;
286 } );
287
288 // The same for vias
289 for( PCB_TRACK* track : m_board->Tracks() )
290 {
291 if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
292 vias.push_back( via );
293 }
294
295 std::sort( vias.begin(), vias.end(), viaSort );
296 vias.erase( std::unique( vias.begin(), vias.end(), []( const PCB_VIA* a, const PCB_VIA* b )
297 {
298 return viaSort( a, b ) == false;
299 } ),
300 vias.end() );
301
302 // Emit vias pads
303 for( PCB_VIA* via : vias )
304 {
305 viastacks.push_back( via );
306 fmt::print( m_file, "PAD V{}.{}.{} ROUND {}\nCIRCLE 0 0 {}\n",
307 via->GetWidth( PADSTACK::ALL_LAYERS ),
308 via->GetDrillValue(),
309 fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
310 via->GetDrillValue() / SCALE_FACTOR,
311 via->GetWidth( PADSTACK::ALL_LAYERS ) / (SCALE_FACTOR * 2) );
312 }
313
314 // Emit component pads
315 PAD* old_pad = nullptr;
316 int pad_name_number = 0;
317
318 for( unsigned i = 0; i<pads.size(); ++i )
319 {
320 PAD* pad = pads[i];
321 const VECTOR2I& off = pad->GetOffset( PADSTACK::ALL_LAYERS );
322
323 pad->SetSubRatsnest( pad_name_number );
324
325 // @warning: This code is not 100% correct. The #PAD::Compare function does not test
326 // custom pad primitives so there may be duplicate custom pads in the export.
327 if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
328 continue;
329
330 old_pad = pad;
331
332 pad_name_number++;
333 pad->SetSubRatsnest( pad_name_number );
334
335 fmt::print( m_file, "PAD P{}", pad->GetSubRatsnest() );
336
337 padstacks.push_back( pad ); // Will have its own padstack later
338 int dx = pad->GetSize( PADSTACK::ALL_LAYERS ).x / 2;
339 int dy = pad->GetSize( PADSTACK::ALL_LAYERS ).y / 2;
340
341 switch( pad->GetShape( PADSTACK::ALL_LAYERS ) )
342 {
343 default:
344 UNIMPLEMENTED_FOR( pad->ShowPadShape( PADSTACK::ALL_LAYERS ) );
346
348 fmt::print( m_file, " ROUND {}\n",
349 pad->GetDrillSize().x / SCALE_FACTOR );
350
351 /* Circle is center, radius */
352 fmt::print( m_file, "CIRCLE {} {} {}\n",
353 off.x / SCALE_FACTOR,
354 -off.y / SCALE_FACTOR,
355 pad->GetSize( PADSTACK::ALL_LAYERS ).x / (SCALE_FACTOR * 2) );
356 break;
357
359 fmt::print( m_file, " RECTANGULAR {}\n",
360 pad->GetDrillSize().x / SCALE_FACTOR );
361
362 // Rectangle is begin, size *not* begin, end!
363 fmt::print( m_file, "RECTANGLE {} {} {} {}\n",
364 (-dx + off.x ) / SCALE_FACTOR,
365 (-dy - off.y ) / SCALE_FACTOR,
366 dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
367 break;
368
370 case PAD_SHAPE::OVAL:
371 {
372 const VECTOR2I& size = pad->GetSize( PADSTACK::ALL_LAYERS );
373 int radius = std::min( size.x, size.y ) / 2;
374
375 if( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::ROUNDRECT )
376 {
377 radius = pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS );
378 }
379
380 int lineX = size.x / 2 - radius;
381 int lineY = size.y / 2 - radius;
382
383 fmt::print( m_file, " POLYGON {}\n", pad->GetDrillSize().x / SCALE_FACTOR );
384
385 // bottom left arc
386 fmt::print( m_file, "ARC {} {} {} {} {} {}\n",
387 ( off.x - lineX - radius ) / SCALE_FACTOR,
388 ( -off.y - lineY ) / SCALE_FACTOR,
389 ( off.x - lineX ) / SCALE_FACTOR,
390 ( -off.y - lineY - radius ) / SCALE_FACTOR,
391 ( off.x - lineX ) / SCALE_FACTOR,
392 ( -off.y - lineY ) / SCALE_FACTOR );
393
394 // bottom line
395 if( lineX > 0 )
396 {
397 fmt::print( m_file, "LINE {} {} {} {}\n",
398 ( off.x - lineX ) / SCALE_FACTOR,
399 ( -off.y - lineY - radius ) / SCALE_FACTOR,
400 ( off.x + lineX ) / SCALE_FACTOR,
401 ( -off.y - lineY - radius ) / SCALE_FACTOR );
402 }
403
404 // bottom right arc
405 fmt::print( m_file, "ARC {} {} {} {} {} {}\n",
406 ( off.x + lineX ) / SCALE_FACTOR,
407 ( -off.y - lineY - radius ) / SCALE_FACTOR,
408 ( off.x + lineX + radius ) / SCALE_FACTOR,
409 ( -off.y - lineY ) / SCALE_FACTOR,
410 ( off.x + lineX ) / SCALE_FACTOR,
411 ( -off.y - lineY ) / SCALE_FACTOR );
412
413 // right line
414 if( lineY > 0 )
415 {
416 fmt::print( m_file, "LINE {} {} {} {}\n",
417 ( off.x + lineX + radius ) / SCALE_FACTOR,
418 ( -off.y + lineY ) / SCALE_FACTOR,
419 ( off.x + lineX + radius ) / SCALE_FACTOR,
420 ( -off.y - lineY ) / SCALE_FACTOR );
421 }
422
423 // top right arc
424 fmt::print( m_file, "ARC {} {} {} {} {} {}\n",
425 ( off.x + lineX + radius ) / SCALE_FACTOR,
426 ( -off.y + lineY ) / SCALE_FACTOR,
427 ( off.x + lineX ) / SCALE_FACTOR,
428 ( -off.y + lineY + radius ) / SCALE_FACTOR,
429 ( off.x + lineX ) / SCALE_FACTOR,
430 ( -off.y + lineY ) / SCALE_FACTOR );
431
432 // top line
433 if( lineX > 0 )
434 {
435 fmt::print( m_file, "LINE {} {} {} {}\n",
436 ( off.x - lineX ) / SCALE_FACTOR,
437 ( -off.y + lineY + radius ) / SCALE_FACTOR,
438 ( off.x + lineX ) / SCALE_FACTOR,
439 ( -off.y + lineY + radius ) / SCALE_FACTOR );
440 }
441
442 // top left arc
443 fmt::print( m_file, "ARC {} {} {} {} {} {}\n",
444 ( off.x - lineX ) / SCALE_FACTOR,
445 ( -off.y + lineY + radius ) / SCALE_FACTOR,
446 ( off.x - lineX - radius ) / SCALE_FACTOR,
447 ( -off.y + lineY ) / SCALE_FACTOR,
448 ( off.x - lineX ) / SCALE_FACTOR,
449 ( -off.y + lineY ) / SCALE_FACTOR );
450
451 // left line
452 if( lineY > 0 )
453 {
454 fmt::print( m_file, "LINE {} {} {} {}\n",
455 ( off.x - lineX - radius ) / SCALE_FACTOR,
456 ( -off.y - lineY ) / SCALE_FACTOR,
457 ( off.x - lineX - radius ) / SCALE_FACTOR,
458 ( -off.y + lineY ) / SCALE_FACTOR );
459 }
460
461 break;
462 }
463
465 {
466 fmt::print( m_file, " POLYGON {}\n", pad->GetDrillSize().x / SCALE_FACTOR );
467
468 int ddx = pad->GetDelta( PADSTACK::ALL_LAYERS ).x / 2;
469 int ddy = pad->GetDelta( PADSTACK::ALL_LAYERS ).y / 2;
470
471 VECTOR2I poly[4];
472 poly[0] = VECTOR2I( -dx + ddy, dy + ddx );
473 poly[1] = VECTOR2I( dx - ddy, dy - ddx );
474 poly[2] = VECTOR2I( dx + ddy, -dy + ddx );
475 poly[3] = VECTOR2I( -dx - ddy, -dy - ddx );
476
477 for( int cur = 0; cur < 4; ++cur )
478 {
479 int next = ( cur + 1 ) % 4;
480 fmt::print( m_file, "LINE {} {} {} {}\n",
481 ( off.x + poly[cur].x ) / SCALE_FACTOR,
482 ( -off.y - poly[cur].y ) / SCALE_FACTOR,
483 ( off.x + poly[next].x ) / SCALE_FACTOR,
484 ( -off.y - poly[next].y ) / SCALE_FACTOR );
485 }
486
487 break;
488 }
489
491 {
492 fmt::print( m_file, " POLYGON {}\n", pad->GetDrillSize().x / SCALE_FACTOR );
493
494 SHAPE_POLY_SET outline;
495 VECTOR2I padOffset( 0, 0 );
496
497 TransformRoundChamferedRectToPolygon( outline, padOffset,
498 pad->GetSize( PADSTACK::ALL_LAYERS ),
499 pad->GetOrientation(),
500 pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS ),
501 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
502 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ),
503 0, pad->GetMaxError(), ERROR_INSIDE );
504
505 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
506 {
507 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
508 int pointCount = poly.PointCount();
509
510 for( int ii = 0; ii < pointCount; ii++ )
511 {
512 int next = ( ii + 1 ) % pointCount;
513 fmt::print( m_file, "LINE {} {} {} {}\n",
514 poly.CPoint( ii ).x / SCALE_FACTOR,
515 -poly.CPoint( ii ).y / SCALE_FACTOR,
516 poly.CPoint( next ).x / SCALE_FACTOR,
517 -poly.CPoint( next ).y / SCALE_FACTOR );
518 }
519 }
520
521 break;
522 }
523
525 {
526 fmt::print( m_file, " POLYGON {}\n", pad->GetDrillSize().x / SCALE_FACTOR );
527
528 SHAPE_POLY_SET outline;
529 pad->MergePrimitivesAsPolygon( F_Cu, &outline );
530
531 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
532 {
533 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
534 int pointCount = poly.PointCount();
535
536 for( int ii = 0; ii < pointCount; ii++ )
537 {
538 int next = ( ii + 1 ) % pointCount;
539 fmt::print( m_file, "LINE {} {} {} {}\n",
540 ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
541 ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
542 ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
543 ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
544 }
545 }
546
547 break;
548 }
549 }
550 }
551
552 fmt::print( m_file, "\n$ENDPADS\n\n" );
553
554 // Now emit the padstacks definitions, using the combined layer masks
555 fmt::print( m_file, "$PADSTACKS\n" );
556
557 // Via padstacks
558 for( unsigned i = 0; i < viastacks.size(); i++ )
559 {
560 PCB_VIA* via = viastacks[i];
561
562 LSET mask = via->GetLayerSet() & master_layermask;
563
564 fmt::print( m_file, "PADSTACK VIA{}.{}.{} {}\n",
565 via->GetWidth( PADSTACK::ALL_LAYERS ),
566 via->GetDrillValue(),
567 fmt_mask( mask ).c_str(),
568 via->GetDrillValue() / SCALE_FACTOR );
569
570 for( PCB_LAYER_ID layer : mask.Seq( gc_seq ) )
571 {
572 fmt::print( m_file, "PAD V{}.{}.{} {} 0 0\n",
573 via->GetWidth( PADSTACK::ALL_LAYERS ),
574 via->GetDrillValue(),
575 fmt_mask( mask ).c_str(),
576 genCADLayerName( cu_count, layer ).c_str() );
577 }
578 }
579
580 /* Component padstacks
581 * Older versions of CAM350 don't apply correctly the FLIP semantics for
582 * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
583 * define the shape as MIRRORX and define a separate 'flipped' padstack...
584 * until it appears yet another non-compliant importer */
585 for( unsigned i = 1; i < padstacks.size(); i++ )
586 {
587 PAD* pad = padstacks[i];
588
589 // Straight padstack
590 fmt::print( m_file, "PADSTACK PAD{} {}\n",
591 i,
592 pad->GetDrillSize().x / SCALE_FACTOR );
593
594 LSET pad_set = pad->GetLayerSet() & master_layermask;
595
596 // the special gc_seq
597 for( PCB_LAYER_ID layer : pad_set.Seq( gc_seq ) )
598 {
599 fmt::print( m_file, "PAD P{} {} 0 0\n",
600 i,
601 genCADLayerName( cu_count, layer ).c_str() );
602 }
603
604 // Flipped padstack
605 if( m_flipBottomPads )
606 {
607 fmt::print( m_file, "PADSTACK PAD{}F {}\n",
608 i,
609 pad->GetDrillSize().x / SCALE_FACTOR );
610
611 // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
612 for( PCB_LAYER_ID layer : pad_set.Seq() )
613 {
614 fmt::print( m_file, "PAD P{} {} 0 0\n",
615 i,
616 genCADLayerNameFlipped( cu_count, layer ).c_str() );
617 }
618 }
619 }
620
621 fputs( "$ENDPADSTACKS\n\n", m_file );
622}
623
624
626static size_t hashFootprint( const FOOTPRINT* aFootprint )
627{
628 size_t ret = 0x11223344;
629 constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
631
632 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
633 ret += hash_fp_item( i, flags );
634
635 for( PAD* i : aFootprint->Pads() )
636 ret += hash_fp_item( i, flags );
637
638 return ret;
639}
640
641
643{
644 const char* layer;
645 wxString pinname;
646 const char* mirror = "0";
647 std::map<wxString, size_t> shapes;
648
649 fmt::print( m_file, "$SHAPES\n" );
650
651 for( FOOTPRINT* footprint : m_board->Footprints() )
652 {
654 {
655 // Check if such shape has been already generated, and if so - reuse it
656 // It is necessary to compute hash (i.e. check all children objects) as
657 // certain components instances might have been modified on the board.
658 // In such case the shape will be different despite the same LIB_ID.
659 wxString shapeName = footprint->GetFPID().Format();
660
661 auto shapeIt = shapes.find( shapeName );
662 size_t modHash = hashFootprint( footprint );
663
664 if( shapeIt != shapes.end() )
665 {
666 if( modHash != shapeIt->second )
667 {
668 // there is an entry for this footprint, but it has a modified shape,
669 // so we need to create a new entry
670 wxString newShapeName;
671 int suffix = 0;
672
673 // find an unused name or matching entry
674 do
675 {
676 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
677 shapeIt = shapes.find( newShapeName );
678 ++suffix;
679 }
680 while( shapeIt != shapes.end() && shapeIt->second != modHash );
681
682 shapeName = newShapeName;
683 }
684
685 if( shapeIt != shapes.end() && modHash == shapeIt->second )
686 {
687 // shape found, so reuse it
688 componentShapes[footprint] = modHash;
689 continue;
690 }
691 }
692
693 // new shape
694 componentShapes[footprint] = modHash;
695 shapeNames[modHash] = shapeName;
696 shapes[shapeName] = modHash;
697 footprintWriteShape( footprint, shapeName );
698 }
699 else // individual shape for each component
700 {
701 footprintWriteShape( footprint, footprint->GetReference() );
702 }
703
704 // set of already emitted pins to check for duplicates
705 std::set<wxString> pins;
706
707 for( PAD* pad : footprint->Pads() )
708 {
709 /* Padstacks are defined using the correct layers for the pads, therefore to
710 * all pads need to be marked as TOP to use the padstack information correctly.
711 */
712 layer = "TOP";
713 pinname = pad->GetNumber();
714
715 if( pinname.IsEmpty() )
716 pinname = wxT( "none" );
717
718 if( m_useUniquePins )
719 {
720 int suffix = 0;
721 wxString origPinname( pinname );
722
723 auto it = pins.find( pinname );
724
725 while( it != pins.end() )
726 {
727 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
728 ++suffix;
729 it = pins.find( pinname );
730 }
731
732 pins.insert( pinname );
733 }
734
735 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
736 orient.Normalize();
737
738 VECTOR2I padPos = pad->GetFPRelativePosition();
739
740 std::string flipStr = ( m_flipBottomPads && footprint->GetFlag() ) ? "F" : "";
741
742 // Bottom side footprints use the flipped padstack
743 fmt::print( m_file,
744 "PIN \"{}\" PAD{}{} {} {} {} {} {}\n",
745 TO_UTF8( escapeString( pinname ) ),
746 pad->GetSubRatsnest(),
747 flipStr,
748 padPos.x / SCALE_FACTOR,
749 -padPos.y / SCALE_FACTOR,
750 layer,
751 orient.AsDegrees(),
752 mirror );
753 }
754 }
755
756 fmt::print( m_file, "$ENDSHAPES\n\n" );
757}
758
759
761{
762 fmt::print( m_file, "$COMPONENTS\n" );
763
764 int cu_count = m_board->GetCopperLayerCount();
765
766 for( FOOTPRINT* footprint : m_board->Footprints() )
767 {
768 const char* mirror;
769 const char* flip;
770 EDA_ANGLE fp_orient = footprint->GetOrientation();
771
772 if( footprint->GetFlag() )
773 {
774 mirror = "MIRRORX";
775 flip = "FLIP";
776 fp_orient = fp_orient.Invert().Normalize();
777 }
778 else
779 {
780 mirror = "0";
781 flip = "0";
782 }
783
784 fmt::print( m_file, "\nCOMPONENT \"{}\"\n",
785 TO_UTF8( escapeString( footprint->GetReference() ) ) );
786 fmt::print( m_file, "DEVICE \"DEV_{}\"\n",
787 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
788 fmt::print( m_file, "PLACE {} {}\n",
789 mapXTo( footprint->GetPosition().x ),
790 mapYTo( footprint->GetPosition().y ) );
791 fmt::print( m_file, "LAYER {}\n",
792 footprint->GetFlag() ? "BOTTOM" : "TOP" );
793 fmt::print( m_file, "ROTATION {}\n",
794 fp_orient.AsDegrees() );
795 fmt::print( m_file, "SHAPE \"{}\" {} {}\n",
796 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
797 mirror, flip );
798
799 // Text on silk layer: RefDes and value (are they actually useful?)
800 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
801 {
802 std::string layer = genCADLayerName( cu_count, footprint->GetFlag() ? B_SilkS : F_SilkS );
803
804 fmt::print( m_file, "TEXT {} {} {} {} {} {} \"{}\"",
805 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
806 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
807 textItem->GetTextWidth() / SCALE_FACTOR,
808 textItem->GetTextAngle().AsDegrees(),
809 mirror,
810 layer.c_str(),
811 TO_UTF8( escapeString( textItem->GetText() ) ) );
812
813 BOX2I textBox = textItem->GetTextBox( nullptr );
814
815 fmt::print( m_file, " 0 0 {} {}\n",
816 textBox.GetWidth() / SCALE_FACTOR,
817 textBox.GetHeight() / SCALE_FACTOR );
818 }
819
820 // The SHEET is a 'generic description' for referencing the component
821 fmt::print( m_file, "SHEET \"RefDes: {}, Value: {}\"\n",
822 TO_UTF8( footprint->GetReference() ),
823 TO_UTF8( footprint->GetValue() ) );
824 }
825
826 fmt::print( m_file, "$ENDCOMPONENTS\n\n" );
827}
828
829
831{
832 // Emit the netlist (which is actually the thing for which GenCAD is used these
833 // days!); tracks are handled later
834
835 wxString msg;
836 NETINFO_ITEM* net;
837 int NbNoConn = 1;
838
839 fmt::print( m_file, "$SIGNALS\n" );
840
841 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
842 {
843 net = m_board->FindNet( ii );
844
845 if( net )
846 {
847 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
848 {
849 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
850 }
851
852 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
853 continue;
854
855 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
856
857 fmt::print( m_file, "{}", TO_UTF8( msg ) );
858 fmt::print( m_file, "\n" );
859
860 for( FOOTPRINT* footprint : m_board->Footprints() )
861 {
862 for( PAD* pad : footprint->Pads() )
863 {
864 if( pad->GetNetCode() != net->GetNetCode() )
865 continue;
866
867 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
868 escapeString( footprint->GetReference() ),
869 escapeString( pad->GetNumber() ) );
870
871 fmt::print( m_file, "{}", TO_UTF8( msg ) );
872 fmt::print( m_file, "\n" );
873 }
874 }
875 }
876 }
877
878 fmt::print( m_file, "$ENDSIGNALS\n\n" );
879}
880
881
883{
884 fmt::print( m_file, "$HEADER\n" );
885 fmt::print( m_file, "GENCAD 1.4\n" );
886
887 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
888 fmt::print( m_file, "USER \"KiCad {}\"\n", GetBuildVersion() );
889
890 fmt::print( m_file, "DRAWING \"{}\"\n", m_board->GetFileName() );
891
892 wxString rev = ExpandTextVars( m_board->GetTitleBlock().GetRevision(), m_board->GetProject() );
893 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
894
895 fmt::print( m_file, "REVISION \"{} {}\"\n", rev, date );
896 fmt::print( m_file, "UNITS INCH\n" );
897
898 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
899 fmt::print( m_file, "ORIGIN {} {}\n", m_storeOriginCoords ? mapXTo( 0 ) : 0,
900 m_storeOriginCoords ? mapYTo( 0 ) : 0 );
901
902 fmt::print( m_file, "INTERTRACK 0\n" );
903 fmt::print( m_file, "$ENDHEADER\n\n" );
904
905 return true;
906}
907
908
910{
911 int vianum = 1;
912 int old_netcode, old_width, old_layer;
913 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
914 int cu_count = m_board->GetCopperLayerCount();
915 TRACKS tracks( m_board->Tracks() );
916
917 std::sort( tracks.begin(), tracks.end(),
918 []( const PCB_TRACK* a, const PCB_TRACK* b )
919 {
920 int widthA = 0;
921 int widthB = 0;
922
923 if( a->Type() == PCB_VIA_T )
924 widthA = static_cast<const PCB_VIA*>( a )->GetWidth( PADSTACK::ALL_LAYERS );
925 else
926 widthA = a->GetWidth();
927
928 if( b->Type() == PCB_VIA_T )
929 widthB = static_cast<const PCB_VIA*>( b )->GetWidth( PADSTACK::ALL_LAYERS );
930 else
931 widthB = b->GetWidth();
932
933 if( a->GetNetCode() == b->GetNetCode() )
934 {
935 if( widthA == widthB )
936 return ( a->GetLayer() < b->GetLayer() );
937
938 return ( widthA < widthB );
939 }
940
941 return ( a->GetNetCode() < b->GetNetCode() );
942 } );
943
944 fmt::print( m_file, "$ROUTES\n" );
945
946 old_netcode = -1;
947 old_width = -1;
948 old_layer = -1;
949
950 for( PCB_TRACK* track : tracks )
951 {
952 if( old_netcode != track->GetNetCode() )
953 {
954 old_netcode = track->GetNetCode();
955 NETINFO_ITEM* net = track->GetNet();
956 wxString netname;
957
958 if( net && (net->GetNetname() != wxEmptyString) )
959 netname = net->GetNetname();
960 else
961 netname = wxT( "_noname_" );
962
963 fmt::print( m_file, "ROUTE \"{}\"\n", TO_UTF8( escapeString( netname ) ) );
964 }
965
966 int currentWidth = 0;
967
968 if( track->Type() == PCB_VIA_T )
969 currentWidth = static_cast<const PCB_VIA*>( track )->GetWidth( PADSTACK::ALL_LAYERS );
970 else
971 currentWidth = track->GetWidth();
972
973 if( old_width != currentWidth )
974 {
975 old_width = currentWidth;
976 fmt::print( m_file, "TRACK TRACK{}\n", currentWidth );
977 }
978
979 if( track->Type() == PCB_TRACE_T )
980 {
981 if( old_layer != track->GetLayer() )
982 {
983 old_layer = track->GetLayer();
984 fmt::print( m_file, "LAYER {}\n",
985 genCADLayerName( cu_count, track->GetLayer() ).c_str() );
986 }
987
988 fmt::print( m_file, "LINE {} {} {} {}\n",
989 mapXTo( track->GetStart().x ), mapYTo( track->GetStart().y ),
990 mapXTo( track->GetEnd().x ), mapYTo( track->GetEnd().y ) );
991 }
992 else if( track->Type() == PCB_ARC_T )
993 {
994 if( old_layer != track->GetLayer() )
995 {
996 old_layer = track->GetLayer();
997 fmt::print( m_file, "LAYER {}\n",
998 genCADLayerName( cu_count, track->GetLayer() ).c_str() );
999 }
1000
1001 VECTOR2I start = track->GetStart();
1002 VECTOR2I end = track->GetEnd();
1003
1004 const PCB_ARC* arc = static_cast<const PCB_ARC*>( track );
1005
1006 // GenCAD arcs are always drawn counter-clockwise (IsCCW works backwards because Y-axis is up in GenCAD).
1007 if( arc->IsCCW() )
1008 std::swap( start, end );
1009
1010 VECTOR2I center = arc->GetCenter();
1011
1012 fmt::print( m_file, "ARC {} {} {} {} {} {}\n",
1013 mapXTo( start.x ), mapYTo( start.y ),
1014 mapXTo( end.x ), mapYTo( end.y ),
1015 mapXTo( center.x ), mapYTo( center.y ) );
1016 }
1017 else 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 fmt::print( m_file, "VIA VIA{}.{}.{} {} {} ALL {} via{}\n",
1024 via->GetWidth( PADSTACK::ALL_LAYERS ),
1025 via->GetDrillValue(),
1026 fmt_mask( vset ).c_str(),
1027 mapXTo( via->GetStart().x ), mapYTo( via->GetStart().y ),
1028 via->GetDrillValue() / SCALE_FACTOR,
1029 vianum++ );
1030 }
1031 }
1032
1033 fmt::print( m_file, "$ENDROUTES\n\n" );
1034}
1035
1036
1038{
1039 std::set<wxString> emitted;
1040
1041 fmt::print( m_file, "$DEVICES\n" );
1042
1043 // componentShapes (as a std::map<>) does not give the same order for items between 2 runs.
1044 // This is annoying when one want to compare 2 similar files.
1045 // Therefore we store the strings in a wxArrayString, and after created, strings will be sorted.
1046 // This is not perfect, because the selected footprint used to create the DEVICE section is
1047 // not always the same between runs, but this is much better than no sort
1048 wxArrayString data;
1049
1050 for( const auto& componentShape : componentShapes )
1051 {
1052 const wxString& shapeName = shapeNames[componentShape.second];
1053 bool newDevice;
1054 std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1055
1056 if( !newDevice ) // do not repeat device definitions
1057 continue;
1058
1059 const FOOTPRINT* footprint = componentShape.first;
1060
1061 wxString txt;
1062 txt.Printf( "\nDEVICE \"DEV_%s\"\n", escapeString( shapeName ) );
1063 txt += wxString::Format( "PART \"%s\"\n", escapeString( footprint->GetValue() ) );
1064 txt += wxString::Format( "PACKAGE \"%s\"\n", escapeString( footprint->GetFPID().Format() ) );
1065
1066 data.Add( txt );
1067 }
1068
1069 data.Sort();
1070
1071 for( wxString& item : data )
1072 fmt::print( m_file, "{}", TO_UTF8( item ) );
1073
1074 fmt::print( m_file, "$ENDDEVICES\n\n" );
1075}
1076
1077
1079{
1080 // Creates the section $BOARD.
1081 // We output here only the board perimeter
1082 fmt::print( m_file, "$BOARD\n" );
1083
1084 // Extract the board edges
1085 SHAPE_POLY_SET outline;
1086
1087 if( !m_board->GetBoardPolygonOutlines( outline, true ) )
1088 wxLogError( _( "Board outline is malformed. Run DRC for a full analysis." ) );
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:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition board.cpp:2076
const FOOTPRINTS & Footprints() const
Definition board.h:363
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:177
Definition pad.h:55
static int Compare(const PAD *aPadRef, const PAD *aPadCmp)
Compare two pads and return 0 if they are equal.
Definition pad.cpp:2035
bool IsCCW() const
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_track.h:354
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:61
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)
#define _(s)
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:58
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:677
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
#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