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 */
19
20#include <build_version.h>
21#include <board.h>
24#include <pcb_shape.h>
25#include <footprint.h>
26#include <pad.h>
27#include <pcb_track.h>
28#include <richio.h>
29#include <locale_io.h>
30#include <macros.h>
31#include <hash_eda.h>
32
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 StrPrintf( "INNER%d", aCuCount - aId - 1 );
47 else
48 return StrPrintf( "LAYER%d", 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 StrPrintf( "INNER%d", 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 // Switch the locale to standard C (needed to print floating point numbers)
167 LOCALE_IO toggle;
168
169 BOARD* pcb = m_board;
170
171 // Update some board data, to ensure a reliable GenCAD export.
172 pcb->ComputeBoundingBox( false );
173
174 /* Temporary modification of footprints that are flipped (i.e. on bottom
175 * layer) to convert them to non flipped footprints.
176 * This is necessary to easily export shapes to GenCAD,
177 * that are given as normal orientation (non flipped, rotation = 0))
178 * these changes will be undone later
179 */
180
181 for( FOOTPRINT* footprint : pcb->Footprints() )
182 {
183 footprint->SetFlag( 0 );
184
185 if( footprint->GetLayer() == B_Cu )
186 {
187 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
188 footprint->SetFlag( 1 );
189 }
190 }
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 fclose( m_file );
215
216 // Undo the footprints modifications (flipped footprints)
217 for( FOOTPRINT* footprint : pcb->Footprints() )
218 {
219 if( footprint->GetFlag() )
220 {
221 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
222 footprint->SetFlag( 0 );
223 }
224 }
225
226 componentShapes.clear();
227 shapeNames.clear();
228
229 return true;
230}
231
232
234static bool viaSort( const PCB_VIA* aPadref, const PCB_VIA* aPadcmp )
235{
236 if( aPadref->GetWidth( PADSTACK::ALL_LAYERS ) != aPadcmp->GetWidth( PADSTACK::ALL_LAYERS ) )
237 return aPadref->GetWidth( PADSTACK::ALL_LAYERS ) < aPadcmp->GetWidth( PADSTACK::ALL_LAYERS );
238
239 if( aPadref->GetDrillValue() != aPadcmp->GetDrillValue() )
240 return aPadref->GetDrillValue() < aPadcmp->GetDrillValue();
241
242 if( aPadref->GetLayerSet() != aPadcmp->GetLayerSet() )
243 return aPadref->GetLayerSet().FmtBin().compare( aPadcmp->GetLayerSet().FmtBin() ) < 0;
244
245 return false;
246}
247
248
250{
251 // The ARTWORKS section is empty but (officially) mandatory
252 fputs( "$ARTWORKS\n", m_file );
253 fputs( "$ENDARTWORKS\n\n", m_file );
254}
255
256
258{
259 // Emit PADS and PADSTACKS. They are sorted and emitted uniquely.
260 // Via name is synthesized from their attributes, pads are numbered
261
262 std::vector<PAD*> padstacks;
263 std::vector<PCB_VIA*> vias;
264 std::vector<PCB_VIA*> viastacks;
265
266 padstacks.resize( 1 ); // We count pads from 1
267
268 LSEQ gc_seq = m_board->GetEnabledLayers().CuStack();
269 std::reverse(gc_seq.begin(), gc_seq.end());
270
271 // The master layermask (i.e. the enabled layers) for padstack generation
272 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
273 int cu_count = m_board->GetCopperLayerCount();
274
275 fputs( "$PADS\n", m_file );
276
277 // Enumerate and sort the pads
278 std::vector<PAD*> pads = m_board->GetPads();
279 std::sort( pads.begin(), pads.end(), []( const PAD* a, const PAD* b )
280 {
281 return PAD::Compare( a, b ) < 0;
282 } );
283
284 // The same for vias
285 for( PCB_TRACK* track : m_board->Tracks() )
286 {
287 if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
288 vias.push_back( via );
289 }
290
291 std::sort( vias.begin(), vias.end(), viaSort );
292 vias.erase( std::unique( vias.begin(), vias.end(), []( const PCB_VIA* a, const PCB_VIA* b )
293 {
294 return viaSort( a, b ) == false;
295 } ),
296 vias.end() );
297
298 // Emit vias pads
299 for( PCB_VIA* via : vias )
300 {
301 viastacks.push_back( via );
302 fprintf( m_file, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
303 via->GetWidth( PADSTACK::ALL_LAYERS ), via->GetDrillValue(),
304 fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
305 via->GetDrillValue() / SCALE_FACTOR,
306 via->GetWidth( PADSTACK::ALL_LAYERS ) / (SCALE_FACTOR * 2) );
307 }
308
309 // Emit component pads
310 PAD* old_pad = nullptr;
311 int pad_name_number = 0;
312
313 for( unsigned i = 0; i<pads.size(); ++i )
314 {
315 PAD* pad = pads[i];
316 const VECTOR2I& off = pad->GetOffset( PADSTACK::ALL_LAYERS );
317
318 pad->SetSubRatsnest( pad_name_number );
319
320 // @warning: This code is not 100% correct. The #PAD::Compare function does not test
321 // custom pad primitives so there may be duplicate custom pads in the export.
322 if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
323 continue;
324
325 old_pad = pad;
326
327 pad_name_number++;
328 pad->SetSubRatsnest( pad_name_number );
329
330 fprintf( m_file, "PAD P%d", pad->GetSubRatsnest() );
331
332 padstacks.push_back( pad ); // Will have its own padstack later
333 int dx = pad->GetSize( PADSTACK::ALL_LAYERS ).x / 2;
334 int dy = pad->GetSize( PADSTACK::ALL_LAYERS ).y / 2;
335
336 switch( pad->GetShape( PADSTACK::ALL_LAYERS ) )
337 {
338 default:
339 UNIMPLEMENTED_FOR( pad->ShowPadShape( PADSTACK::ALL_LAYERS ) );
341
342 case PAD_SHAPE::CIRCLE:
343 fprintf( m_file, " ROUND %g\n",
344 pad->GetDrillSize().x / SCALE_FACTOR );
345
346 /* Circle is center, radius */
347 fprintf( m_file, "CIRCLE %g %g %g\n",
348 off.x / SCALE_FACTOR,
349 -off.y / SCALE_FACTOR,
350 pad->GetSize( PADSTACK::ALL_LAYERS ).x / (SCALE_FACTOR * 2) );
351 break;
352
353 case PAD_SHAPE::RECTANGLE:
354 fprintf( m_file, " RECTANGULAR %g\n",
355 pad->GetDrillSize().x / SCALE_FACTOR );
356
357 // Rectangle is begin, size *not* begin, end!
358 fprintf( m_file, "RECTANGLE %g %g %g %g\n",
359 (-dx + off.x ) / SCALE_FACTOR,
360 (-dy - off.y ) / SCALE_FACTOR,
361 dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
362 break;
363
364 case PAD_SHAPE::ROUNDRECT:
365 case PAD_SHAPE::OVAL:
366 {
367 const VECTOR2I& size = pad->GetSize( PADSTACK::ALL_LAYERS );
368 int radius = std::min( size.x, size.y ) / 2;
369
370 if( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::ROUNDRECT )
371 {
372 radius = pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS );
373 }
374
375 int lineX = size.x / 2 - radius;
376 int lineY = size.y / 2 - radius;
377
378 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
379
380 // bottom left arc
381 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
382 ( off.x - lineX - radius ) / SCALE_FACTOR,
383 ( -off.y - lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
384 ( -off.y - lineY - radius ) / SCALE_FACTOR,
385 ( off.x - lineX ) / SCALE_FACTOR, ( -off.y - lineY ) / SCALE_FACTOR );
386
387 // bottom line
388 if( lineX > 0 )
389 {
390 fprintf( m_file, "LINE %g %g %g %g\n",
391 ( off.x - lineX ) / SCALE_FACTOR,
392 ( -off.y - lineY - radius ) / SCALE_FACTOR,
393 ( off.x + lineX ) / SCALE_FACTOR,
394 ( -off.y - lineY - radius ) / SCALE_FACTOR );
395 }
396
397 // bottom right arc
398 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
399 ( off.x + lineX ) / SCALE_FACTOR,
400 ( -off.y - lineY - radius ) / SCALE_FACTOR,
401 ( off.x + lineX + radius ) / SCALE_FACTOR,
402 ( -off.y - lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
403 ( -off.y - lineY ) / SCALE_FACTOR );
404
405 // right line
406 if( lineY > 0 )
407 {
408 fprintf( m_file, "LINE %g %g %g %g\n",
409 ( off.x + lineX + radius ) / SCALE_FACTOR,
410 ( -off.y + lineY ) / SCALE_FACTOR,
411 ( off.x + lineX + radius ) / SCALE_FACTOR,
412 ( -off.y - lineY ) / SCALE_FACTOR );
413 }
414
415 // top right arc
416 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
417 ( off.x + lineX + radius ) / SCALE_FACTOR,
418 ( -off.y + lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
419 ( -off.y + lineY + radius ) / SCALE_FACTOR,
420 ( off.x + lineX ) / SCALE_FACTOR, ( -off.y + lineY ) / SCALE_FACTOR );
421
422 // top line
423 if( lineX > 0 )
424 {
425 fprintf( m_file, "LINE %g %g %g %g\n",
426 ( off.x - lineX ) / SCALE_FACTOR,
427 ( -off.y + lineY + radius ) / SCALE_FACTOR,
428 ( off.x + lineX ) / SCALE_FACTOR,
429 ( -off.y + lineY + radius ) / SCALE_FACTOR );
430 }
431
432 // top left arc
433 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
434 ( off.x - lineX ) / SCALE_FACTOR,
435 ( -off.y + lineY + radius ) / SCALE_FACTOR,
436 ( off.x - lineX - radius ) / SCALE_FACTOR,
437 ( -off.y + lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
438 ( -off.y + lineY ) / SCALE_FACTOR );
439
440 // left line
441 if( lineY > 0 )
442 {
443 fprintf( m_file, "LINE %g %g %g %g\n",
444 ( off.x - lineX - radius ) / SCALE_FACTOR,
445 ( -off.y - lineY ) / SCALE_FACTOR,
446 ( off.x - lineX - radius ) / SCALE_FACTOR,
447 ( -off.y + lineY ) / SCALE_FACTOR );
448 }
449
450 break;
451 }
452
453 case PAD_SHAPE::TRAPEZOID:
454 {
455 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
456
457 int ddx = pad->GetDelta( PADSTACK::ALL_LAYERS ).x / 2;
458 int ddy = pad->GetDelta( PADSTACK::ALL_LAYERS ).y / 2;
459
460 VECTOR2I poly[4];
461 poly[0] = VECTOR2I( -dx + ddy, dy + ddx );
462 poly[1] = VECTOR2I( dx - ddy, dy - ddx );
463 poly[2] = VECTOR2I( dx + ddy, -dy + ddx );
464 poly[3] = VECTOR2I( -dx - ddy, -dy - ddx );
465
466 for( int cur = 0; cur < 4; ++cur )
467 {
468 int next = ( cur + 1 ) % 4;
469 fprintf( m_file, "LINE %g %g %g %g\n",
470 ( off.x + poly[cur].x ) / SCALE_FACTOR,
471 ( -off.y - poly[cur].y ) / SCALE_FACTOR,
472 ( off.x + poly[next].x ) / SCALE_FACTOR,
473 ( -off.y - poly[next].y ) / SCALE_FACTOR );
474 }
475
476 break;
477 }
478
479 case PAD_SHAPE::CHAMFERED_RECT:
480 {
481 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
482
483 SHAPE_POLY_SET outline;
484 int maxError = m_board->GetDesignSettings().m_MaxError;
485 VECTOR2I padOffset( 0, 0 );
486
487 TransformRoundChamferedRectToPolygon( outline, padOffset,
488 pad->GetSize( PADSTACK::ALL_LAYERS ),
489 pad->GetOrientation(),
490 pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS ),
491 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
492 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ),
493 0, maxError, ERROR_INSIDE );
494
495 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
496 {
497 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
498 int pointCount = poly.PointCount();
499
500 for( int ii = 0; ii < pointCount; ii++ )
501 {
502 int next = ( ii + 1 ) % pointCount;
503 fprintf( m_file, "LINE %g %g %g %g\n",
504 poly.CPoint( ii ).x / SCALE_FACTOR,
505 -poly.CPoint( ii ).y / SCALE_FACTOR,
506 poly.CPoint( next ).x / SCALE_FACTOR,
507 -poly.CPoint( next ).y / SCALE_FACTOR );
508 }
509 }
510
511 break;
512 }
513
514 case PAD_SHAPE::CUSTOM:
515 {
516 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
517
518 SHAPE_POLY_SET outline;
519 pad->MergePrimitivesAsPolygon( F_Cu, &outline );
520
521 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
522 {
523 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
524 int pointCount = poly.PointCount();
525
526 for( int ii = 0; ii < pointCount; ii++ )
527 {
528 int next = ( ii + 1 ) % pointCount;
529 fprintf( m_file, "LINE %g %g %g %g\n",
530 ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
531 ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
532 ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
533 ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
534 }
535 }
536
537 break;
538 }
539 }
540 }
541
542 fputs( "\n$ENDPADS\n\n", m_file );
543
544 // Now emit the padstacks definitions, using the combined layer masks
545 fputs( "$PADSTACKS\n", m_file );
546
547 // Via padstacks
548 for( unsigned i = 0; i < viastacks.size(); i++ )
549 {
550 PCB_VIA* via = viastacks[i];
551
552 LSET mask = via->GetLayerSet() & master_layermask;
553
554 fprintf( m_file, "PADSTACK VIA%d.%d.%s %g\n",
555 via->GetWidth( PADSTACK::ALL_LAYERS ),
556 via->GetDrillValue(),
557 fmt_mask( mask ).c_str(),
558 via->GetDrillValue() / SCALE_FACTOR );
559
560 for( PCB_LAYER_ID layer : mask.Seq( gc_seq ) )
561 {
562 fprintf( m_file, "PAD V%d.%d.%s %s 0 0\n",
563 via->GetWidth( PADSTACK::ALL_LAYERS ),
564 via->GetDrillValue(),
565 fmt_mask( mask ).c_str(),
566 genCADLayerName( cu_count, layer ).c_str() );
567 }
568 }
569
570 /* Component padstacks
571 * Older versions of CAM350 don't apply correctly the FLIP semantics for
572 * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
573 * define the shape as MIRRORX and define a separate 'flipped' padstack...
574 * until it appears yet another non-compliant importer */
575 for( unsigned i = 1; i < padstacks.size(); i++ )
576 {
577 PAD* pad = padstacks[i];
578
579 // Straight padstack
580 fprintf( m_file, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
581
582 LSET pad_set = pad->GetLayerSet() & master_layermask;
583
584 // the special gc_seq
585 for( PCB_LAYER_ID layer : pad_set.Seq( gc_seq ) )
586 {
587 fprintf( m_file, "PAD P%u %s 0 0\n", i, genCADLayerName( cu_count, layer ).c_str() );
588 }
589
590 // Flipped padstack
591 if( m_flipBottomPads )
592 {
593 fprintf( m_file, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
594
595 // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
596 for( PCB_LAYER_ID layer : pad_set.Seq() )
597 {
598 fprintf( m_file, "PAD P%u %s 0 0\n", i,
599 genCADLayerNameFlipped( cu_count, layer ).c_str() );
600 }
601 }
602 }
603
604 fputs( "$ENDPADSTACKS\n\n", m_file );
605}
606
607
609static size_t hashFootprint( const FOOTPRINT* aFootprint )
610{
611 size_t ret = 0x11223344;
612 constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
614
615 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
616 ret += hash_fp_item( i, flags );
617
618 for( PAD* i : aFootprint->Pads() )
619 ret += hash_fp_item( i, flags );
620
621 return ret;
622}
623
624
626{
627 const char* layer;
628 wxString pinname;
629 const char* mirror = "0";
630 std::map<wxString, size_t> shapes;
631
632 fputs( "$SHAPES\n", m_file );
633
634 for( FOOTPRINT* footprint : m_board->Footprints() )
635 {
637 {
638 // Check if such shape has been already generated, and if so - reuse it
639 // It is necessary to compute hash (i.e. check all children objects) as
640 // certain components instances might have been modified on the board.
641 // In such case the shape will be different despite the same LIB_ID.
642 wxString shapeName = footprint->GetFPID().Format();
643
644 auto shapeIt = shapes.find( shapeName );
645 size_t modHash = hashFootprint( footprint );
646
647 if( shapeIt != shapes.end() )
648 {
649 if( modHash != shapeIt->second )
650 {
651 // there is an entry for this footprint, but it has a modified shape,
652 // so we need to create a new entry
653 wxString newShapeName;
654 int suffix = 0;
655
656 // find an unused name or matching entry
657 do
658 {
659 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
660 shapeIt = shapes.find( newShapeName );
661 ++suffix;
662 }
663 while( shapeIt != shapes.end() && shapeIt->second != modHash );
664
665 shapeName = newShapeName;
666 }
667
668 if( shapeIt != shapes.end() && modHash == shapeIt->second )
669 {
670 // shape found, so reuse it
671 componentShapes[footprint] = modHash;
672 continue;
673 }
674 }
675
676 // new shape
677 componentShapes[footprint] = modHash;
678 shapeNames[modHash] = shapeName;
679 shapes[shapeName] = modHash;
680 footprintWriteShape( footprint, shapeName );
681 }
682 else // individual shape for each component
683 {
684 footprintWriteShape( footprint, footprint->GetReference() );
685 }
686
687 // set of already emitted pins to check for duplicates
688 std::set<wxString> pins;
689
690 for( PAD* pad : footprint->Pads() )
691 {
692 /* Padstacks are defined using the correct layers for the pads, therefore to
693 * all pads need to be marked as TOP to use the padstack information correctly.
694 */
695 layer = "TOP";
696 pinname = pad->GetNumber();
697
698 if( pinname.IsEmpty() )
699 pinname = wxT( "none" );
700
701 if( m_useUniquePins )
702 {
703 int suffix = 0;
704 wxString origPinname( pinname );
705
706 auto it = pins.find( pinname );
707
708 while( it != pins.end() )
709 {
710 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
711 ++suffix;
712 it = pins.find( pinname );
713 }
714
715 pins.insert( pinname );
716 }
717
718 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
719 orient.Normalize();
720
721 VECTOR2I padPos = pad->GetFPRelativePosition();
722
723 // Bottom side footprints use the flipped padstack
724 fprintf( m_file, ( m_flipBottomPads && footprint->GetFlag() ) ?
725 "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
726 "PIN \"%s\" PAD%d %g %g %s %g %s\n",
727 TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
728 padPos.x / SCALE_FACTOR,
729 -padPos.y / SCALE_FACTOR,
730 layer, orient.AsDegrees(), mirror );
731 }
732 }
733
734 fputs( "$ENDSHAPES\n\n", m_file );
735}
736
737
739{
740 fputs( "$COMPONENTS\n", m_file );
741
742 int cu_count = m_board->GetCopperLayerCount();
743
744 for( FOOTPRINT* footprint : m_board->Footprints() )
745 {
746 const char* mirror;
747 const char* flip;
748 EDA_ANGLE fp_orient = footprint->GetOrientation();
749
750 if( footprint->GetFlag() )
751 {
752 mirror = "MIRRORX";
753 flip = "FLIP";
754 fp_orient = fp_orient.Invert().Normalize();
755 }
756 else
757 {
758 mirror = "0";
759 flip = "0";
760 }
761
762 fprintf( m_file, "\nCOMPONENT \"%s\"\n",
763 TO_UTF8( escapeString( footprint->GetReference() ) ) );
764 fprintf( m_file, "DEVICE \"DEV_%s\"\n",
765 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
766 fprintf( m_file, "PLACE %g %g\n",
767 mapXTo( footprint->GetPosition().x ),
768 mapYTo( footprint->GetPosition().y ) );
769 fprintf( m_file, "LAYER %s\n",
770 footprint->GetFlag() ? "BOTTOM" : "TOP" );
771 fprintf( m_file, "ROTATION %g\n",
772 fp_orient.AsDegrees() );
773 fprintf( m_file, "SHAPE \"%s\" %s %s\n",
774 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
775 mirror, flip );
776
777 // Text on silk layer: RefDes and value (are they actually useful?)
778 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
779 {
780 std::string layer = genCADLayerName( cu_count, footprint->GetFlag() ? B_SilkS : F_SilkS );
781
782 fprintf( m_file, "TEXT %g %g %g %g %s %s \"%s\"",
783 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
784 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
785 textItem->GetTextWidth() / SCALE_FACTOR,
786 textItem->GetTextAngle().AsDegrees(),
787 mirror,
788 layer.c_str(),
789 TO_UTF8( escapeString( textItem->GetText() ) ) );
790
791 BOX2I textBox = textItem->GetTextBox();
792
793 fprintf( m_file, " 0 0 %g %g\n",
794 textBox.GetWidth() / SCALE_FACTOR,
795 textBox.GetHeight() / SCALE_FACTOR );
796 }
797
798 // The SHEET is a 'generic description' for referencing the component
799 fprintf( m_file, "SHEET \"RefDes: %s, Value: %s\"\n",
800 TO_UTF8( footprint->GetReference() ),
801 TO_UTF8( footprint->GetValue() ) );
802 }
803
804 fputs( "$ENDCOMPONENTS\n\n", m_file );
805}
806
807
809{
810 // Emit the netlist (which is actually the thing for which GenCAD is used these
811 // days!); tracks are handled later
812
813 wxString msg;
814 NETINFO_ITEM* net;
815 int NbNoConn = 1;
816
817 fputs( "$SIGNALS\n", m_file );
818
819 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
820 {
821 net = m_board->FindNet( ii );
822
823 if( net )
824 {
825 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
826 {
827 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
828 }
829
830 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
831 continue;
832
833 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
834
835 fputs( TO_UTF8( msg ), m_file );
836 fputs( "\n", m_file );
837
838 for( FOOTPRINT* footprint : m_board->Footprints() )
839 {
840 for( PAD* pad : footprint->Pads() )
841 {
842 if( pad->GetNetCode() != net->GetNetCode() )
843 continue;
844
845 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
846 escapeString( footprint->GetReference() ),
847 escapeString( pad->GetNumber() ) );
848
849 fputs( TO_UTF8( msg ), m_file );
850 fputs( "\n", m_file );
851 }
852 }
853 }
854 }
855
856 fputs( "$ENDSIGNALS\n\n", m_file );
857}
858
859
861{
862 wxString msg;
863
864 fputs( "$HEADER\n", m_file );
865 fputs( "GENCAD 1.4\n", m_file );
866
867 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
868 msg.Printf( wxT( "USER \"KiCad %s\"\n" ), GetBuildVersion() );
869 fputs( TO_UTF8( msg ), m_file );
870
871 msg = wxT( "DRAWING \"" ) + m_board->GetFileName() + wxT( "\"\n" );
872 fputs( TO_UTF8( msg ), m_file );
873
875 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
876 msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
877
878 fputs( TO_UTF8( msg ), m_file );
879 fputs( "UNITS INCH\n", m_file );
880
881 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
882 msg.Printf( wxT( "ORIGIN %g %g\n" ),
883 m_storeOriginCoords ? mapXTo( 0 ) : 0,
884 m_storeOriginCoords ? mapYTo( 0 ) : 0 );
885 fputs( TO_UTF8( msg ), m_file );
886
887 fputs( "INTERTRACK 0\n", m_file );
888 fputs( "$ENDHEADER\n\n", m_file );
889
890 return true;
891}
892
893
895{
896 int vianum = 1;
897 int old_netcode, old_width, old_layer;
898 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
899 int cu_count = m_board->GetCopperLayerCount();
900 TRACKS tracks( m_board->Tracks() );
901
902 std::sort( tracks.begin(), tracks.end(),
903 []( const PCB_TRACK* a, const PCB_TRACK* b )
904 {
905 int widthA = 0;
906 int widthB = 0;
907
908 if( a->Type() == PCB_VIA_T )
909 widthA = static_cast<const PCB_VIA*>( a )->GetWidth( PADSTACK::ALL_LAYERS );
910 else
911 widthA = a->GetWidth();
912
913 if( b->Type() == PCB_VIA_T )
914 widthB = static_cast<const PCB_VIA*>( b )->GetWidth( PADSTACK::ALL_LAYERS );
915 else
916 widthB = b->GetWidth();
917
918 if( a->GetNetCode() == b->GetNetCode() )
919 {
920 if( widthA == widthB )
921 return ( a->GetLayer() < b->GetLayer() );
922
923 return ( widthA < widthB );
924 }
925
926 return ( a->GetNetCode() < b->GetNetCode() );
927 } );
928
929 fputs( "$ROUTES\n", m_file );
930
931 old_netcode = -1;
932 old_width = -1;
933 old_layer = -1;
934
935 for( PCB_TRACK* track : tracks )
936 {
937 if( old_netcode != track->GetNetCode() )
938 {
939 old_netcode = track->GetNetCode();
940 NETINFO_ITEM* net = track->GetNet();
941 wxString netname;
942
943 if( net && (net->GetNetname() != wxEmptyString) )
944 netname = net->GetNetname();
945 else
946 netname = wxT( "_noname_" );
947
948 fprintf( m_file, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
949 }
950
951 int currentWidth = 0;
952
953 if( track->Type() == PCB_VIA_T )
954 currentWidth = static_cast<const PCB_VIA*>( track )->GetWidth( PADSTACK::ALL_LAYERS );
955 else
956 currentWidth = track->GetWidth();
957
958 if( old_width != currentWidth )
959 {
960 old_width = currentWidth;
961 fprintf( m_file, "TRACK TRACK%d\n", currentWidth );
962 }
963
964 if( track->Type() == PCB_TRACE_T )
965 {
966 if( old_layer != track->GetLayer() )
967 {
968 old_layer = track->GetLayer();
969 fprintf( m_file, "LAYER %s\n",
970 genCADLayerName( cu_count, track->GetLayer() ).c_str() );
971 }
972
973 fprintf( m_file, "LINE %g %g %g %g\n",
974 mapXTo( track->GetStart().x ), mapYTo( track->GetStart().y ),
975 mapXTo( track->GetEnd().x ), mapYTo( track->GetEnd().y ) );
976 }
977 else if( track->Type() == PCB_ARC_T )
978 {
979 VECTOR2I start = track->GetStart();
980 VECTOR2I end = track->GetEnd();
981
982 const PCB_ARC* arc = static_cast<const PCB_ARC*>( track );
983
984 // GenCAD arcs are always drawn counter-clockwise.
985 if( arc->GetAngle() > ANGLE_0 )
986 std::swap( start, end );
987
988 VECTOR2I center = arc->GetCenter();
989
990 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
991 mapXTo( start.x ), mapYTo( start.y ),
992 mapXTo( end.x ), mapYTo( end.y ),
993 mapXTo( center.x ), mapYTo( center.y ) );
994 }
995 else if( track->Type() == PCB_VIA_T )
996 {
997 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
998
999 LSET vset = via->GetLayerSet() & master_layermask;
1000
1001 fprintf( m_file, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
1002 via->GetWidth( PADSTACK::ALL_LAYERS ), via->GetDrillValue(),
1003 fmt_mask( vset ).c_str(),
1004 mapXTo( via->GetStart().x ), mapYTo( via->GetStart().y ),
1005 via->GetDrillValue() / SCALE_FACTOR, vianum++ );
1006 }
1007 }
1008
1009 fputs( "$ENDROUTES\n\n", m_file );
1010}
1011
1012
1014{
1015 std::set<wxString> emitted;
1016
1017 fputs( "$DEVICES\n", m_file );
1018
1019 // componentShapes (as a std::map<>) does not give the same order for items between 2 runs.
1020 // This is annoying when one want to compare 2 similar files.
1021 // Therefore we store the strings in a wxArrayString, and after created, strings will be sorted.
1022 // This is not perfect, because the selected footprint used to create the DEVICE section is
1023 // not always the same between runs, but this is much better than no sort
1024 wxArrayString data;
1025
1026 for( const auto& componentShape : componentShapes )
1027 {
1028 const wxString& shapeName = shapeNames[componentShape.second];
1029 bool newDevice;
1030 std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1031
1032 if( !newDevice ) // do not repeat device definitions
1033 continue;
1034
1035 const FOOTPRINT* footprint = componentShape.first;
1036
1037 wxString txt;
1038 txt.Printf( "\nDEVICE \"DEV_%s\"\n", escapeString( shapeName ) );
1039 txt += wxString::Format( "PART \"%s\"\n", escapeString( footprint->GetValue() ) );
1040 txt += wxString::Format( "PACKAGE \"%s\"\n", escapeString( footprint->GetFPID().Format() ) );
1041
1042 data.Add( txt );
1043 }
1044
1045 data.Sort();
1046
1047 for( wxString& item : data )
1048 fprintf( m_file, "%s", TO_UTF8( item ) );
1049
1050 fputs( "$ENDDEVICES\n\n", m_file );
1051}
1052
1053
1055{
1056 // Creates the section $BOARD.
1057 // We output here only the board perimeter
1058 fputs( "$BOARD\n", m_file );
1059
1060 // Extract the board edges
1061 SHAPE_POLY_SET outline;
1062 m_board->GetBoardPolygonOutlines( outline );
1063
1064 for( auto seg1 = outline.IterateSegmentsWithHoles(); seg1; seg1++ )
1065 {
1066 SEG seg = *seg1;
1067 fprintf( m_file, "LINE %g %g %g %g\n",
1068 mapXTo( seg.A.x ), mapYTo( seg.A.y ),
1069 mapXTo( seg.B.x ), mapYTo( seg.B.y ) );
1070 }
1071
1072 fputs( "$ENDBOARD\n\n", m_file );
1073}
1074
1075
1077{
1078 // Find thickness used for traces
1079 std::set<int> trackinfo;
1080
1081 for( PCB_TRACK* track : m_board->Tracks() )
1082 {
1083 if( track->Type() == PCB_VIA_T )
1084 continue;
1085
1086 trackinfo.insert( track->GetWidth() );
1087 }
1088
1089 // Write data
1090 fputs( "$TRACKS\n", m_file );
1091
1092 for( int size : trackinfo )
1093 fprintf( m_file, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1094
1095 fputs( "$ENDTRACKS\n\n", m_file );
1096}
1097
1098
1099void GENCAD_EXPORTER::footprintWriteShape( FOOTPRINT* aFootprint, const wxString& aShapeName )
1100{
1101 /* creates header: */
1102 fprintf( m_file, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1103
1104 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1105 fprintf( m_file, "INSERT TH\n" );
1106 else
1107 fprintf( m_file, "INSERT SMD\n" );
1108
1109 // Silk outline; wildly interpreted by various importers:
1110 // CAM350 read it right but only closed shapes
1111 // ProntoPlace double-flip it (at least the pads are correct)
1112 // GerberTool usually get it right...
1113 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1114 {
1115 if( item->Type() == PCB_SHAPE_T && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) )
1116 {
1117 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1118 VECTOR2I start = shape->GetStart() - aFootprint->GetPosition();
1119 VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition();
1120 VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition();
1121
1122 RotatePoint( start, -aFootprint->GetOrientation() );
1123 RotatePoint( end, -aFootprint->GetOrientation() );
1124 RotatePoint( center, -aFootprint->GetOrientation() );
1125
1126 switch( shape->GetShape() )
1127 {
1128 case SHAPE_T::SEGMENT:
1129 fprintf( m_file, "LINE %g %g %g %g\n",
1130 start.x / SCALE_FACTOR,
1131 -start.y / SCALE_FACTOR,
1132 end.x / SCALE_FACTOR,
1133 -end.y / SCALE_FACTOR );
1134 break;
1135
1136 case SHAPE_T::RECTANGLE:
1137 fprintf( m_file, "LINE %g %g %g %g\n",
1138 start.x / SCALE_FACTOR,
1139 -start.y / SCALE_FACTOR,
1140 end.x / SCALE_FACTOR,
1141 -end.y / SCALE_FACTOR );
1142 fprintf( m_file, "LINE %g %g %g %g\n",
1143 end.x / SCALE_FACTOR,
1144 -start.y / SCALE_FACTOR,
1145 end.x / SCALE_FACTOR,
1146 -end.y / SCALE_FACTOR );
1147 fprintf( m_file, "LINE %g %g %g %g\n",
1148 end.x / SCALE_FACTOR,
1149 -end.y / SCALE_FACTOR,
1150 start.x / SCALE_FACTOR,
1151 -end.y / SCALE_FACTOR );
1152 fprintf( m_file, "LINE %g %g %g %g\n",
1153 start.x / SCALE_FACTOR,
1154 -end.y / SCALE_FACTOR,
1155 start.x / SCALE_FACTOR,
1156 -start.y / SCALE_FACTOR );
1157 break;
1158
1159 case SHAPE_T::CIRCLE:
1160 {
1161 int radius = KiROUND( end.Distance( start ) );
1162
1163 fprintf( m_file, "CIRCLE %g %g %g\n",
1164 start.x / SCALE_FACTOR,
1165 -start.y / SCALE_FACTOR,
1166 radius / SCALE_FACTOR );
1167 break;
1168 }
1169
1170 case SHAPE_T::ARC:
1171 if( shape->GetArcAngle() > ANGLE_0 )
1172 std::swap( start, end );
1173
1174 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
1175 start.x / SCALE_FACTOR,
1176 -start.y / SCALE_FACTOR,
1177 end.x / SCALE_FACTOR,
1178 -end.y / SCALE_FACTOR,
1180 -center.y / SCALE_FACTOR );
1181 break;
1182
1183 case SHAPE_T::POLY:
1184 // Not exported (TODO)
1185 break;
1186
1187 default:
1188 wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) );
1189 break;
1190 }
1191 }
1192 }
1193}
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:110
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
const LSET & GetEnabledLayers() const
Return a bit-mask of all the layers that are enabled.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2521
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2011
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:2632
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:721
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1763
int GetCopperLayerCount() const
Definition: board.cpp:781
const FOOTPRINTS & Footprints() const
Definition: board.h:338
const TRACKS & Tracks() const
Definition: board.h:336
const wxString & GetFileName() const
Definition: board.h:334
PROJECT * GetProject() const
Definition: board.h:511
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:946
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:829
unsigned GetNetCount() const
Definition: board.h:928
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:224
double AsDegrees() const
Definition: eda_angle.h:116
EDA_ANGLE Invert() const
Definition: eda_angle.h:168
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:1074
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:232
std::deque< PAD * > & Pads()
Definition: footprint.h:211
int GetAttributes() const
Definition: footprint.h:295
const LIB_ID & GetFPID() const
Definition: footprint.h:253
const wxString & GetValue() const
Definition: footprint.h:643
const wxString & GetReference() const
Definition: footprint.h:621
VECTOR2I GetPosition() const override
Definition: footprint.h:229
DRAWINGS & GraphicalItems()
Definition: footprint.h:214
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
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:247
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:583
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:297
Handle the data for a net.
Definition: netinfo.h:56
const wxString & GetNetname() const
Definition: netinfo.h:114
int GetNetCode() const
Definition: netinfo.h:108
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
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:1523
EDA_ANGLE GetAngle() const
Definition: pcb_track.cpp:2102
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:351
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
Definition: pcb_track.cpp:380
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:634
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:1259
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
const wxString & GetRevision() const
Definition: title_block.h:86
const wxString & GetDate() const
Definition: title_block.h:76
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:561
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:404
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 const double SCALE_FACTOR
static size_t hashFootprint(const FOOTPRINT *aFootprint)
Compute hashes for footprints without taking into account their position, rotation or layer.
static std::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:80
size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags)
Calculate hash of an EDA_ITEM.
Definition: hash_eda.cpp:55
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:663
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
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.
Definition: string_utils.h:408
const double IU_PER_MILS
Definition: base_units.h:77
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
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695