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 ),
304 via->GetDrillValue(),
305 fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
306 via->GetDrillValue() / SCALE_FACTOR,
307 via->GetWidth( PADSTACK::ALL_LAYERS ) / (SCALE_FACTOR * 2) );
308 }
309
310 // Emit component pads
311 PAD* old_pad = nullptr;
312 int pad_name_number = 0;
313
314 for( unsigned i = 0; i<pads.size(); ++i )
315 {
316 PAD* pad = pads[i];
317 const VECTOR2I& off = pad->GetOffset( PADSTACK::ALL_LAYERS );
318
319 pad->SetSubRatsnest( pad_name_number );
320
321 // @warning: This code is not 100% correct. The #PAD::Compare function does not test
322 // custom pad primitives so there may be duplicate custom pads in the export.
323 if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
324 continue;
325
326 old_pad = pad;
327
328 pad_name_number++;
329 pad->SetSubRatsnest( pad_name_number );
330
331 fprintf( m_file, "PAD P%d", pad->GetSubRatsnest() );
332
333 padstacks.push_back( pad ); // Will have its own padstack later
334 int dx = pad->GetSize( PADSTACK::ALL_LAYERS ).x / 2;
335 int dy = pad->GetSize( PADSTACK::ALL_LAYERS ).y / 2;
336
337 switch( pad->GetShape( PADSTACK::ALL_LAYERS ) )
338 {
339 default:
340 UNIMPLEMENTED_FOR( pad->ShowPadShape( PADSTACK::ALL_LAYERS ) );
342
343 case PAD_SHAPE::CIRCLE:
344 fprintf( m_file, " ROUND %g\n",
345 pad->GetDrillSize().x / SCALE_FACTOR );
346
347 /* Circle is center, radius */
348 fprintf( m_file, "CIRCLE %g %g %g\n",
349 off.x / SCALE_FACTOR,
350 -off.y / SCALE_FACTOR,
351 pad->GetSize( PADSTACK::ALL_LAYERS ).x / (SCALE_FACTOR * 2) );
352 break;
353
354 case PAD_SHAPE::RECTANGLE:
355 fprintf( m_file, " RECTANGULAR %g\n",
356 pad->GetDrillSize().x / SCALE_FACTOR );
357
358 // Rectangle is begin, size *not* begin, end!
359 fprintf( m_file, "RECTANGLE %g %g %g %g\n",
360 (-dx + off.x ) / SCALE_FACTOR,
361 (-dy - off.y ) / SCALE_FACTOR,
362 dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
363 break;
364
365 case PAD_SHAPE::ROUNDRECT:
366 case PAD_SHAPE::OVAL:
367 {
368 const VECTOR2I& size = pad->GetSize( PADSTACK::ALL_LAYERS );
369 int radius = std::min( size.x, size.y ) / 2;
370
371 if( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::ROUNDRECT )
372 {
373 radius = pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS );
374 }
375
376 int lineX = size.x / 2 - radius;
377 int lineY = size.y / 2 - radius;
378
379 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
380
381 // bottom left arc
382 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
383 ( off.x - lineX - radius ) / SCALE_FACTOR,
384 ( -off.y - lineY ) / SCALE_FACTOR,
385 ( off.x - lineX ) / SCALE_FACTOR,
386 ( -off.y - lineY - radius ) / SCALE_FACTOR,
387 ( off.x - lineX ) / SCALE_FACTOR,
388 ( -off.y - lineY ) / SCALE_FACTOR );
389
390 // bottom line
391 if( lineX > 0 )
392 {
393 fprintf( m_file, "LINE %g %g %g %g\n",
394 ( off.x - lineX ) / SCALE_FACTOR,
395 ( -off.y - lineY - radius ) / SCALE_FACTOR,
396 ( off.x + lineX ) / SCALE_FACTOR,
397 ( -off.y - lineY - radius ) / SCALE_FACTOR );
398 }
399
400 // bottom right arc
401 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
402 ( off.x + lineX ) / SCALE_FACTOR,
403 ( -off.y - lineY - radius ) / SCALE_FACTOR,
404 ( off.x + lineX + radius ) / SCALE_FACTOR,
405 ( -off.y - lineY ) / SCALE_FACTOR,
406 ( off.x + lineX ) / SCALE_FACTOR,
407 ( -off.y - lineY ) / SCALE_FACTOR );
408
409 // right line
410 if( lineY > 0 )
411 {
412 fprintf( m_file, "LINE %g %g %g %g\n",
413 ( off.x + lineX + radius ) / SCALE_FACTOR,
414 ( -off.y + lineY ) / SCALE_FACTOR,
415 ( off.x + lineX + radius ) / SCALE_FACTOR,
416 ( -off.y - lineY ) / SCALE_FACTOR );
417 }
418
419 // top right arc
420 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
421 ( off.x + lineX + radius ) / SCALE_FACTOR,
422 ( -off.y + lineY ) / SCALE_FACTOR,
423 ( off.x + lineX ) / SCALE_FACTOR,
424 ( -off.y + lineY + radius ) / SCALE_FACTOR,
425 ( off.x + lineX ) / SCALE_FACTOR,
426 ( -off.y + lineY ) / SCALE_FACTOR );
427
428 // top line
429 if( lineX > 0 )
430 {
431 fprintf( m_file, "LINE %g %g %g %g\n",
432 ( off.x - lineX ) / SCALE_FACTOR,
433 ( -off.y + lineY + radius ) / SCALE_FACTOR,
434 ( off.x + lineX ) / SCALE_FACTOR,
435 ( -off.y + lineY + radius ) / SCALE_FACTOR );
436 }
437
438 // top left arc
439 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
440 ( off.x - lineX ) / SCALE_FACTOR,
441 ( -off.y + lineY + radius ) / SCALE_FACTOR,
442 ( off.x - lineX - radius ) / SCALE_FACTOR,
443 ( -off.y + lineY ) / SCALE_FACTOR,
444 ( off.x - lineX ) / SCALE_FACTOR,
445 ( -off.y + lineY ) / SCALE_FACTOR );
446
447 // left line
448 if( lineY > 0 )
449 {
450 fprintf( m_file, "LINE %g %g %g %g\n",
451 ( off.x - lineX - radius ) / SCALE_FACTOR,
452 ( -off.y - lineY ) / SCALE_FACTOR,
453 ( off.x - lineX - radius ) / SCALE_FACTOR,
454 ( -off.y + lineY ) / SCALE_FACTOR );
455 }
456
457 break;
458 }
459
460 case PAD_SHAPE::TRAPEZOID:
461 {
462 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
463
464 int ddx = pad->GetDelta( PADSTACK::ALL_LAYERS ).x / 2;
465 int ddy = pad->GetDelta( PADSTACK::ALL_LAYERS ).y / 2;
466
467 VECTOR2I poly[4];
468 poly[0] = VECTOR2I( -dx + ddy, dy + ddx );
469 poly[1] = VECTOR2I( dx - ddy, dy - ddx );
470 poly[2] = VECTOR2I( dx + ddy, -dy + ddx );
471 poly[3] = VECTOR2I( -dx - ddy, -dy - ddx );
472
473 for( int cur = 0; cur < 4; ++cur )
474 {
475 int next = ( cur + 1 ) % 4;
476 fprintf( m_file, "LINE %g %g %g %g\n",
477 ( off.x + poly[cur].x ) / SCALE_FACTOR,
478 ( -off.y - poly[cur].y ) / SCALE_FACTOR,
479 ( off.x + poly[next].x ) / SCALE_FACTOR,
480 ( -off.y - poly[next].y ) / SCALE_FACTOR );
481 }
482
483 break;
484 }
485
486 case PAD_SHAPE::CHAMFERED_RECT:
487 {
488 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
489
490 SHAPE_POLY_SET outline;
491 VECTOR2I padOffset( 0, 0 );
492
493 TransformRoundChamferedRectToPolygon( outline, padOffset,
494 pad->GetSize( PADSTACK::ALL_LAYERS ),
495 pad->GetOrientation(),
496 pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS ),
497 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
498 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ),
499 0, pad->GetMaxError(), ERROR_INSIDE );
500
501 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
502 {
503 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
504 int pointCount = poly.PointCount();
505
506 for( int ii = 0; ii < pointCount; ii++ )
507 {
508 int next = ( ii + 1 ) % pointCount;
509 fprintf( m_file, "LINE %g %g %g %g\n",
510 poly.CPoint( ii ).x / SCALE_FACTOR,
511 -poly.CPoint( ii ).y / SCALE_FACTOR,
512 poly.CPoint( next ).x / SCALE_FACTOR,
513 -poly.CPoint( next ).y / SCALE_FACTOR );
514 }
515 }
516
517 break;
518 }
519
520 case PAD_SHAPE::CUSTOM:
521 {
522 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
523
524 SHAPE_POLY_SET outline;
525 pad->MergePrimitivesAsPolygon( F_Cu, &outline );
526
527 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
528 {
529 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
530 int pointCount = poly.PointCount();
531
532 for( int ii = 0; ii < pointCount; ii++ )
533 {
534 int next = ( ii + 1 ) % pointCount;
535 fprintf( m_file, "LINE %g %g %g %g\n",
536 ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
537 ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
538 ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
539 ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
540 }
541 }
542
543 break;
544 }
545 }
546 }
547
548 fputs( "\n$ENDPADS\n\n", m_file );
549
550 // Now emit the padstacks definitions, using the combined layer masks
551 fputs( "$PADSTACKS\n", m_file );
552
553 // Via padstacks
554 for( unsigned i = 0; i < viastacks.size(); i++ )
555 {
556 PCB_VIA* via = viastacks[i];
557
558 LSET mask = via->GetLayerSet() & master_layermask;
559
560 fprintf( m_file, "PADSTACK VIA%d.%d.%s %g\n",
561 via->GetWidth( PADSTACK::ALL_LAYERS ),
562 via->GetDrillValue(),
563 fmt_mask( mask ).c_str(),
564 via->GetDrillValue() / SCALE_FACTOR );
565
566 for( PCB_LAYER_ID layer : mask.Seq( gc_seq ) )
567 {
568 fprintf( m_file, "PAD V%d.%d.%s %s 0 0\n",
569 via->GetWidth( PADSTACK::ALL_LAYERS ),
570 via->GetDrillValue(),
571 fmt_mask( mask ).c_str(),
572 genCADLayerName( cu_count, layer ).c_str() );
573 }
574 }
575
576 /* Component padstacks
577 * Older versions of CAM350 don't apply correctly the FLIP semantics for
578 * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
579 * define the shape as MIRRORX and define a separate 'flipped' padstack...
580 * until it appears yet another non-compliant importer */
581 for( unsigned i = 1; i < padstacks.size(); i++ )
582 {
583 PAD* pad = padstacks[i];
584
585 // Straight padstack
586 fprintf( m_file, "PADSTACK PAD%u %g\n",
587 i,
588 pad->GetDrillSize().x / SCALE_FACTOR );
589
590 LSET pad_set = pad->GetLayerSet() & master_layermask;
591
592 // the special gc_seq
593 for( PCB_LAYER_ID layer : pad_set.Seq( gc_seq ) )
594 {
595 fprintf( m_file, "PAD P%u %s 0 0\n",
596 i,
597 genCADLayerName( cu_count, layer ).c_str() );
598 }
599
600 // Flipped padstack
601 if( m_flipBottomPads )
602 {
603 fprintf( m_file, "PADSTACK PAD%uF %g\n",
604 i,
605 pad->GetDrillSize().x / SCALE_FACTOR );
606
607 // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
608 for( PCB_LAYER_ID layer : pad_set.Seq() )
609 {
610 fprintf( m_file, "PAD P%u %s 0 0\n",
611 i,
612 genCADLayerNameFlipped( cu_count, layer ).c_str() );
613 }
614 }
615 }
616
617 fputs( "$ENDPADSTACKS\n\n", m_file );
618}
619
620
622static size_t hashFootprint( const FOOTPRINT* aFootprint )
623{
624 size_t ret = 0x11223344;
625 constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
627
628 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
629 ret += hash_fp_item( i, flags );
630
631 for( PAD* i : aFootprint->Pads() )
632 ret += hash_fp_item( i, flags );
633
634 return ret;
635}
636
637
639{
640 const char* layer;
641 wxString pinname;
642 const char* mirror = "0";
643 std::map<wxString, size_t> shapes;
644
645 fputs( "$SHAPES\n", m_file );
646
647 for( FOOTPRINT* footprint : m_board->Footprints() )
648 {
650 {
651 // Check if such shape has been already generated, and if so - reuse it
652 // It is necessary to compute hash (i.e. check all children objects) as
653 // certain components instances might have been modified on the board.
654 // In such case the shape will be different despite the same LIB_ID.
655 wxString shapeName = footprint->GetFPID().Format();
656
657 auto shapeIt = shapes.find( shapeName );
658 size_t modHash = hashFootprint( footprint );
659
660 if( shapeIt != shapes.end() )
661 {
662 if( modHash != shapeIt->second )
663 {
664 // there is an entry for this footprint, but it has a modified shape,
665 // so we need to create a new entry
666 wxString newShapeName;
667 int suffix = 0;
668
669 // find an unused name or matching entry
670 do
671 {
672 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
673 shapeIt = shapes.find( newShapeName );
674 ++suffix;
675 }
676 while( shapeIt != shapes.end() && shapeIt->second != modHash );
677
678 shapeName = newShapeName;
679 }
680
681 if( shapeIt != shapes.end() && modHash == shapeIt->second )
682 {
683 // shape found, so reuse it
684 componentShapes[footprint] = modHash;
685 continue;
686 }
687 }
688
689 // new shape
690 componentShapes[footprint] = modHash;
691 shapeNames[modHash] = shapeName;
692 shapes[shapeName] = modHash;
693 footprintWriteShape( footprint, shapeName );
694 }
695 else // individual shape for each component
696 {
697 footprintWriteShape( footprint, footprint->GetReference() );
698 }
699
700 // set of already emitted pins to check for duplicates
701 std::set<wxString> pins;
702
703 for( PAD* pad : footprint->Pads() )
704 {
705 /* Padstacks are defined using the correct layers for the pads, therefore to
706 * all pads need to be marked as TOP to use the padstack information correctly.
707 */
708 layer = "TOP";
709 pinname = pad->GetNumber();
710
711 if( pinname.IsEmpty() )
712 pinname = wxT( "none" );
713
714 if( m_useUniquePins )
715 {
716 int suffix = 0;
717 wxString origPinname( pinname );
718
719 auto it = pins.find( pinname );
720
721 while( it != pins.end() )
722 {
723 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
724 ++suffix;
725 it = pins.find( pinname );
726 }
727
728 pins.insert( pinname );
729 }
730
731 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
732 orient.Normalize();
733
734 VECTOR2I padPos = pad->GetFPRelativePosition();
735
736 // Bottom side footprints use the flipped padstack
737 fprintf( m_file,
738 ( m_flipBottomPads && footprint->GetFlag() ) ? "PIN \"%s\" PAD%dF %g %g %s %g %s\n"
739 : "PIN \"%s\" PAD%d %g %g %s %g %s\n",
740 TO_UTF8( escapeString( pinname ) ),
741 pad->GetSubRatsnest(),
742 padPos.x / SCALE_FACTOR,
743 -padPos.y / SCALE_FACTOR,
744 layer,
745 orient.AsDegrees(),
746 mirror );
747 }
748 }
749
750 fputs( "$ENDSHAPES\n\n", m_file );
751}
752
753
755{
756 fputs( "$COMPONENTS\n", m_file );
757
758 int cu_count = m_board->GetCopperLayerCount();
759
760 for( FOOTPRINT* footprint : m_board->Footprints() )
761 {
762 const char* mirror;
763 const char* flip;
764 EDA_ANGLE fp_orient = footprint->GetOrientation();
765
766 if( footprint->GetFlag() )
767 {
768 mirror = "MIRRORX";
769 flip = "FLIP";
770 fp_orient = fp_orient.Invert().Normalize();
771 }
772 else
773 {
774 mirror = "0";
775 flip = "0";
776 }
777
778 fprintf( m_file, "\nCOMPONENT \"%s\"\n",
779 TO_UTF8( escapeString( footprint->GetReference() ) ) );
780 fprintf( m_file, "DEVICE \"DEV_%s\"\n",
781 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
782 fprintf( m_file, "PLACE %g %g\n",
783 mapXTo( footprint->GetPosition().x ),
784 mapYTo( footprint->GetPosition().y ) );
785 fprintf( m_file, "LAYER %s\n",
786 footprint->GetFlag() ? "BOTTOM" : "TOP" );
787 fprintf( m_file, "ROTATION %g\n",
788 fp_orient.AsDegrees() );
789 fprintf( m_file, "SHAPE \"%s\" %s %s\n",
790 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
791 mirror, flip );
792
793 // Text on silk layer: RefDes and value (are they actually useful?)
794 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
795 {
796 std::string layer = genCADLayerName( cu_count, footprint->GetFlag() ? B_SilkS : F_SilkS );
797
798 fprintf( m_file, "TEXT %g %g %g %g %s %s \"%s\"",
799 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
800 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
801 textItem->GetTextWidth() / SCALE_FACTOR,
802 textItem->GetTextAngle().AsDegrees(),
803 mirror,
804 layer.c_str(),
805 TO_UTF8( escapeString( textItem->GetText() ) ) );
806
807 BOX2I textBox = textItem->GetTextBox( nullptr );
808
809 fprintf( m_file, " 0 0 %g %g\n",
810 textBox.GetWidth() / SCALE_FACTOR,
811 textBox.GetHeight() / SCALE_FACTOR );
812 }
813
814 // The SHEET is a 'generic description' for referencing the component
815 fprintf( m_file, "SHEET \"RefDes: %s, Value: %s\"\n",
816 TO_UTF8( footprint->GetReference() ),
817 TO_UTF8( footprint->GetValue() ) );
818 }
819
820 fputs( "$ENDCOMPONENTS\n\n", m_file );
821}
822
823
825{
826 // Emit the netlist (which is actually the thing for which GenCAD is used these
827 // days!); tracks are handled later
828
829 wxString msg;
830 NETINFO_ITEM* net;
831 int NbNoConn = 1;
832
833 fputs( "$SIGNALS\n", m_file );
834
835 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
836 {
837 net = m_board->FindNet( ii );
838
839 if( net )
840 {
841 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
842 {
843 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
844 }
845
846 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
847 continue;
848
849 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
850
851 fputs( TO_UTF8( msg ), m_file );
852 fputs( "\n", m_file );
853
854 for( FOOTPRINT* footprint : m_board->Footprints() )
855 {
856 for( PAD* pad : footprint->Pads() )
857 {
858 if( pad->GetNetCode() != net->GetNetCode() )
859 continue;
860
861 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
862 escapeString( footprint->GetReference() ),
863 escapeString( pad->GetNumber() ) );
864
865 fputs( TO_UTF8( msg ), m_file );
866 fputs( "\n", m_file );
867 }
868 }
869 }
870 }
871
872 fputs( "$ENDSIGNALS\n\n", m_file );
873}
874
875
877{
878 wxString msg;
879
880 fputs( "$HEADER\n", m_file );
881 fputs( "GENCAD 1.4\n", m_file );
882
883 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
884 msg.Printf( wxT( "USER \"KiCad %s\"\n" ), GetBuildVersion() );
885 fputs( TO_UTF8( msg ), m_file );
886
887 msg = wxT( "DRAWING \"" ) + m_board->GetFileName() + wxT( "\"\n" );
888 fputs( TO_UTF8( msg ), m_file );
889
891 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
892 msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
893
894 fputs( TO_UTF8( msg ), m_file );
895 fputs( "UNITS INCH\n", m_file );
896
897 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
898 msg.Printf( wxT( "ORIGIN %g %g\n" ),
899 m_storeOriginCoords ? mapXTo( 0 ) : 0,
900 m_storeOriginCoords ? mapYTo( 0 ) : 0 );
901 fputs( TO_UTF8( msg ), m_file );
902
903 fputs( "INTERTRACK 0\n", m_file );
904 fputs( "$ENDHEADER\n\n", m_file );
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 fputs( "$ROUTES\n", m_file );
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 fprintf( m_file, "ROUTE \"%s\"\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 fprintf( m_file, "TRACK TRACK%d\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 fprintf( m_file, "LAYER %s\n",
986 genCADLayerName( cu_count, track->GetLayer() ).c_str() );
987 }
988
989 fprintf( m_file, "LINE %g %g %g %g\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 fprintf( m_file, "LAYER %s\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 fprintf( m_file, "ARC %g %g %g %g %g %g\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 fprintf( m_file, "VIA VIA%d.%d.%s %g %g ALL %g via%d\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 fputs( "$ENDROUTES\n\n", m_file );
1035}
1036
1037
1039{
1040 std::set<wxString> emitted;
1041
1042 fputs( "$DEVICES\n", m_file );
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 fprintf( m_file, "%s", TO_UTF8( item ) );
1074
1075 fputs( "$ENDDEVICES\n\n", m_file );
1076}
1077
1078
1080{
1081 // Creates the section $BOARD.
1082 // We output here only the board perimeter
1083 fputs( "$BOARD\n", m_file );
1084
1085 // Extract the board edges
1086 SHAPE_POLY_SET outline;
1087 m_board->GetBoardPolygonOutlines( outline );
1088
1089 for( auto seg1 = outline.IterateSegmentsWithHoles(); seg1; seg1++ )
1090 {
1091 SEG seg = *seg1;
1092 fprintf( m_file, "LINE %g %g %g %g\n",
1093 mapXTo( seg.A.x ), mapYTo( seg.A.y ),
1094 mapXTo( seg.B.x ), mapYTo( seg.B.y ) );
1095 }
1096
1097 fputs( "$ENDBOARD\n\n", m_file );
1098}
1099
1100
1102{
1103 // Find thickness used for traces
1104 std::set<int> trackinfo;
1105
1106 for( PCB_TRACK* track : m_board->Tracks() )
1107 {
1108 if( track->Type() == PCB_VIA_T )
1109 continue;
1110
1111 trackinfo.insert( track->GetWidth() );
1112 }
1113
1114 // Write data
1115 fputs( "$TRACKS\n", m_file );
1116
1117 for( int size : trackinfo )
1118 fprintf( m_file, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1119
1120 fputs( "$ENDTRACKS\n\n", m_file );
1121}
1122
1123
1124void GENCAD_EXPORTER::footprintWriteShape( FOOTPRINT* aFootprint, const wxString& aShapeName )
1125{
1126 /* creates header: */
1127 fprintf( m_file, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1128
1129 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1130 fprintf( m_file, "INSERT TH\n" );
1131 else
1132 fprintf( m_file, "INSERT SMD\n" );
1133
1134 // Silk outline; wildly interpreted by various importers:
1135 // CAM350 read it right but only closed shapes
1136 // ProntoPlace double-flip it (at least the pads are correct)
1137 // GerberTool usually get it right...
1138 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1139 {
1140 if( item->Type() == PCB_SHAPE_T && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) )
1141 {
1142 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1143 VECTOR2I start = shape->GetStart() - aFootprint->GetPosition();
1144 VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition();
1145 VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition();
1146
1147 RotatePoint( start, -aFootprint->GetOrientation() );
1148 RotatePoint( end, -aFootprint->GetOrientation() );
1149 RotatePoint( center, -aFootprint->GetOrientation() );
1150
1151 switch( shape->GetShape() )
1152 {
1153 case SHAPE_T::SEGMENT:
1154 fprintf( m_file, "LINE %g %g %g %g\n",
1155 start.x / SCALE_FACTOR,
1156 -start.y / SCALE_FACTOR,
1157 end.x / SCALE_FACTOR,
1158 -end.y / SCALE_FACTOR );
1159 break;
1160
1161 case SHAPE_T::RECTANGLE:
1162 fprintf( m_file, "LINE %g %g %g %g\n",
1163 start.x / SCALE_FACTOR,
1164 -start.y / SCALE_FACTOR,
1165 end.x / SCALE_FACTOR,
1166 -end.y / SCALE_FACTOR );
1167 fprintf( m_file, "LINE %g %g %g %g\n",
1168 end.x / SCALE_FACTOR,
1169 -start.y / SCALE_FACTOR,
1170 end.x / SCALE_FACTOR,
1171 -end.y / SCALE_FACTOR );
1172 fprintf( m_file, "LINE %g %g %g %g\n",
1173 end.x / SCALE_FACTOR,
1174 -end.y / SCALE_FACTOR,
1175 start.x / SCALE_FACTOR,
1176 -end.y / SCALE_FACTOR );
1177 fprintf( m_file, "LINE %g %g %g %g\n",
1178 start.x / SCALE_FACTOR,
1179 -end.y / SCALE_FACTOR,
1180 start.x / SCALE_FACTOR,
1181 -start.y / SCALE_FACTOR );
1182 break;
1183
1184 case SHAPE_T::CIRCLE:
1185 {
1186 int radius = KiROUND( end.Distance( start ) );
1187
1188 fprintf( m_file, "CIRCLE %g %g %g\n",
1189 start.x / SCALE_FACTOR,
1190 -start.y / SCALE_FACTOR,
1191 radius / SCALE_FACTOR );
1192 break;
1193 }
1194
1195 case SHAPE_T::ARC:
1196 if( shape->GetArcAngle() > ANGLE_0 )
1197 std::swap( start, end );
1198
1199 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
1200 start.x / SCALE_FACTOR,
1201 -start.y / SCALE_FACTOR,
1202 end.x / SCALE_FACTOR,
1203 -end.y / SCALE_FACTOR,
1205 -center.y / SCALE_FACTOR );
1206 break;
1207
1208 case SHAPE_T::POLY:
1209 // Not exported (TODO)
1210 break;
1211
1212 default:
1213 wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) );
1214 break;
1215 }
1216 }
1217 }
1218}
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
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:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
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:2604
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2099
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:2712
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:748
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1851
int GetCopperLayerCount() const
Definition: board.cpp:859
const FOOTPRINTS & Footprints() const
Definition: board.h:358
const TRACKS & Tracks() const
Definition: board.h:356
const wxString & GetFileName() const
Definition: board.h:354
PROJECT * GetProject() const
Definition: board.h:538
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:1024
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:907
unsigned GetNetCount() const
Definition: board.h:965
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
Definition: eda_shape.cpp:1080
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:230
std::deque< PAD * > & Pads()
Definition: footprint.h:209
int GetAttributes() const
Definition: footprint.h:293
const LIB_ID & GetFPID() const
Definition: footprint.h:251
const wxString & GetValue() const
Definition: footprint.h:649
const wxString & GetReference() const
Definition: footprint.h:627
VECTOR2I GetPosition() const override
Definition: footprint.h:227
DRAWINGS & GraphicalItems()
Definition: footprint.h:212
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:41
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:246
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: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:145
Definition: pad.h:54
static int Compare(const PAD *aPadRef, const PAD *aPadCmp)
Compare two pads and return 0 if they are equal.
Definition: pad.cpp:1583
bool IsCCW() const
Definition: pcb_track.cpp:855
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:352
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:81
int GetWidth() const override
Definition: pcb_track.cpp:379
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:628
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:411
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:665
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:429
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