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