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
36// layer names for Gencad export
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
92// flipped layer name for Gencad export (to make CAM350 imports correct)
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( LSET aSet )
111{
112 return ( aSet & LSET::AllCuMask() ).to_string();
113}
114
115
116// Association between shape names (using shapeName index) and components
117static std::map<FOOTPRINT*, int> componentShapes;
118static std::map<int, wxString> shapeNames;
119
120
121const wxString GENCAD_EXPORTER::getShapeName( FOOTPRINT* aFootprint )
122{
123 static const wxString invalid( "invalid" );
124
126 return aFootprint->GetReference();
127
128 auto itShape = componentShapes.find( aFootprint );
129 wxCHECK( itShape != componentShapes.end(), invalid );
130
131 auto itName = shapeNames.find( itShape->second );
132 wxCHECK( itName != shapeNames.end(), invalid );
133
134 return itName->second;
135}
136
137
138// GerbTool chokes on units different than INCH so this is the conversion factor
139const static double SCALE_FACTOR = 1000.0 * pcbIUScale.IU_PER_MILS;
140
141
142/* Two helper functions to calculate coordinates of footprints in gencad values
143 * (GenCAD Y axis from bottom to top)
144 */
146{
147 return (aX - GencadOffset.x) / SCALE_FACTOR;
148}
149
150
152{
153 return (GencadOffset.y - aY) / SCALE_FACTOR;
154}
155
156
157bool GENCAD_EXPORTER::WriteFile( const wxString& aFullFileName )
158{
159 componentShapes.clear();
160 shapeNames.clear();
161
162 m_file = wxFopen( aFullFileName, wxT( "wt" ) );
163
164 if( !m_file )
165 return false;
166
167 // Switch the locale to standard C (needed to print floating point numbers)
168 LOCALE_IO toggle;
169
170 BOARD* pcb = m_board;
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 component info 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
233// Sort vias for uniqueness
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
279 std::vector<PAD*> pads = m_board->GetPads();
280 std::sort( pads.begin(), pads.end(), []( const PAD* a, const PAD* b )
281 {
282 return PAD::Compare( a, b ) < 0;
283 } );
284
285
286 // The same for vias
287 for( PCB_TRACK* track : m_board->Tracks() )
288 {
289 if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
290 vias.push_back( via );
291 }
292
293 std::sort( vias.begin(), vias.end(), ViaSort );
294 vias.erase( std::unique( vias.begin(), vias.end(), []( const PCB_VIA* a, const PCB_VIA* b )
295 {
296 return ViaSort( a, b ) == false;
297 } ),
298 vias.end() );
299
300 // Emit vias pads
301 for( PCB_VIA* via : vias )
302 {
303 viastacks.push_back( via );
304 fprintf( m_file, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
305 via->GetWidth( PADSTACK::ALL_LAYERS ), via->GetDrillValue(),
306 fmt_mask( via->GetLayerSet() & master_layermask ).c_str(),
307 via->GetDrillValue() / SCALE_FACTOR,
308 via->GetWidth( PADSTACK::ALL_LAYERS ) / (SCALE_FACTOR * 2) );
309 }
310
311 // Emit component pads
312 PAD* old_pad = nullptr;
313 int pad_name_number = 0;
314
315 for( unsigned i = 0; i<pads.size(); ++i )
316 {
317 PAD* pad = pads[i];
318 const VECTOR2I& off = pad->GetOffset( PADSTACK::ALL_LAYERS );
319
320 pad->SetSubRatsnest( pad_name_number );
321
322 // @warning: This code is not 100% correct. The #PAD::Compare function does not test
323 // custom pad primitives so there may be duplicate custom pads in the export.
324 if( old_pad && 0 == PAD::Compare( old_pad, pad ) )
325 continue;
326
327 old_pad = pad;
328
329 pad_name_number++;
330 pad->SetSubRatsnest( pad_name_number );
331
332 fprintf( m_file, "PAD P%d", pad->GetSubRatsnest() );
333
334 padstacks.push_back( pad ); // Will have its own padstack later
335 int dx = pad->GetSize( PADSTACK::ALL_LAYERS ).x / 2;
336 int dy = pad->GetSize( PADSTACK::ALL_LAYERS ).y / 2;
337
338 switch( pad->GetShape( PADSTACK::ALL_LAYERS ) )
339 {
340 default:
341 UNIMPLEMENTED_FOR( pad->ShowPadShape( PADSTACK::ALL_LAYERS ) );
343
344 case PAD_SHAPE::CIRCLE:
345 fprintf( m_file, " ROUND %g\n",
346 pad->GetDrillSize().x / SCALE_FACTOR );
347
348 /* Circle is center, radius */
349 fprintf( m_file, "CIRCLE %g %g %g\n",
350 off.x / SCALE_FACTOR,
351 -off.y / SCALE_FACTOR,
352 pad->GetSize( PADSTACK::ALL_LAYERS ).x / (SCALE_FACTOR * 2) );
353 break;
354
355 case PAD_SHAPE::RECTANGLE:
356 fprintf( m_file, " RECTANGULAR %g\n",
357 pad->GetDrillSize().x / SCALE_FACTOR );
358
359 // Rectangle is begin, size *not* begin, end!
360 fprintf( m_file, "RECTANGLE %g %g %g %g\n",
361 (-dx + off.x ) / SCALE_FACTOR,
362 (-dy - off.y ) / SCALE_FACTOR,
363 dx / (SCALE_FACTOR / 2), dy / (SCALE_FACTOR / 2) );
364 break;
365
366 case PAD_SHAPE::ROUNDRECT:
367 case PAD_SHAPE::OVAL:
368 {
369 const VECTOR2I& size = pad->GetSize( PADSTACK::ALL_LAYERS );
370 int radius = std::min( size.x, size.y ) / 2;
371
372 if( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::ROUNDRECT )
373 {
374 radius = pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS );
375 }
376
377 int lineX = size.x / 2 - radius;
378 int lineY = size.y / 2 - radius;
379
380 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
381
382 // bottom left arc
383 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
384 ( off.x - lineX - radius ) / SCALE_FACTOR,
385 ( -off.y - lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
386 ( -off.y - lineY - radius ) / SCALE_FACTOR,
387 ( off.x - lineX ) / SCALE_FACTOR, ( -off.y - lineY ) / SCALE_FACTOR );
388
389 // bottom line
390 if( lineX > 0 )
391 {
392 fprintf( m_file, "LINE %g %g %g %g\n",
393 ( off.x - lineX ) / SCALE_FACTOR,
394 ( -off.y - lineY - radius ) / SCALE_FACTOR,
395 ( off.x + lineX ) / SCALE_FACTOR,
396 ( -off.y - lineY - radius ) / SCALE_FACTOR );
397 }
398
399 // bottom right arc
400 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
401 ( off.x + lineX ) / SCALE_FACTOR,
402 ( -off.y - lineY - radius ) / SCALE_FACTOR,
403 ( off.x + lineX + radius ) / SCALE_FACTOR,
404 ( -off.y - lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
405 ( -off.y - lineY ) / SCALE_FACTOR );
406
407 // right line
408 if( lineY > 0 )
409 {
410 fprintf( m_file, "LINE %g %g %g %g\n",
411 ( off.x + lineX + radius ) / SCALE_FACTOR,
412 ( -off.y + lineY ) / SCALE_FACTOR,
413 ( off.x + lineX + radius ) / SCALE_FACTOR,
414 ( -off.y - lineY ) / SCALE_FACTOR );
415 }
416
417 // top right arc
418 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
419 ( off.x + lineX + radius ) / SCALE_FACTOR,
420 ( -off.y + lineY ) / SCALE_FACTOR, ( off.x + lineX ) / SCALE_FACTOR,
421 ( -off.y + lineY + radius ) / SCALE_FACTOR,
422 ( off.x + lineX ) / SCALE_FACTOR, ( -off.y + lineY ) / SCALE_FACTOR );
423
424 // top line
425 if( lineX > 0 )
426 {
427 fprintf( m_file, "LINE %g %g %g %g\n"
428 , ( off.x - lineX ) / SCALE_FACTOR,
429 ( -off.y + lineY + radius ) / SCALE_FACTOR,
430 ( off.x + lineX ) / SCALE_FACTOR,
431 ( -off.y + lineY + radius ) / SCALE_FACTOR );
432 }
433
434 // top left arc
435 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
436 ( off.x - lineX ) / SCALE_FACTOR,
437 ( -off.y + lineY + radius ) / SCALE_FACTOR,
438 ( off.x - lineX - radius ) / SCALE_FACTOR,
439 ( -off.y + lineY ) / SCALE_FACTOR, ( off.x - lineX ) / SCALE_FACTOR,
440 ( -off.y + lineY ) / SCALE_FACTOR );
441
442 // left line
443 if( lineY > 0 )
444 {
445 fprintf( m_file, "LINE %g %g %g %g\n",
446 ( off.x - lineX - radius ) / SCALE_FACTOR,
447 ( -off.y - lineY ) / SCALE_FACTOR,
448 ( off.x - lineX - radius ) / SCALE_FACTOR,
449 ( -off.y + lineY ) / SCALE_FACTOR );
450 }
451
452 break;
453 }
454
455 case PAD_SHAPE::TRAPEZOID:
456 {
457 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
458
459 int ddx = pad->GetDelta( PADSTACK::ALL_LAYERS ).x / 2;
460 int ddy = pad->GetDelta( PADSTACK::ALL_LAYERS ).y / 2;
461
462 VECTOR2I poly[4];
463 poly[0] = VECTOR2I( -dx + ddy, dy + ddx );
464 poly[1] = VECTOR2I( dx - ddy, dy - ddx );
465 poly[2] = VECTOR2I( dx + ddy, -dy + ddx );
466 poly[3] = VECTOR2I( -dx - ddy, -dy - ddx );
467
468 for( int cur = 0; cur < 4; ++cur )
469 {
470 int next = ( cur + 1 ) % 4;
471 fprintf( m_file, "LINE %g %g %g %g\n",
472 ( off.x + poly[cur].x ) / SCALE_FACTOR,
473 ( -off.y - poly[cur].y ) / SCALE_FACTOR,
474 ( off.x + poly[next].x ) / SCALE_FACTOR,
475 ( -off.y - poly[next].y ) / SCALE_FACTOR );
476 }
477
478 break;
479 }
480
481 case PAD_SHAPE::CHAMFERED_RECT:
482 {
483 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
484
485 SHAPE_POLY_SET outline;
486 int maxError = m_board->GetDesignSettings().m_MaxError;
487 VECTOR2I padOffset( 0, 0 );
488
489 TransformRoundChamferedRectToPolygon( outline, padOffset,
490 pad->GetSize( PADSTACK::ALL_LAYERS ),
491 pad->GetOrientation(),
492 pad->GetRoundRectCornerRadius( PADSTACK::ALL_LAYERS ),
493 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
494 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ),
495 0, maxError, ERROR_INSIDE );
496
497 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
498 {
499 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
500 int pointCount = poly.PointCount();
501
502 for( int ii = 0; ii < pointCount; ii++ )
503 {
504 int next = ( ii + 1 ) % pointCount;
505 fprintf( m_file, "LINE %g %g %g %g\n",
506 poly.CPoint( ii ).x / SCALE_FACTOR,
507 -poly.CPoint( ii ).y / SCALE_FACTOR,
508 poly.CPoint( next ).x / SCALE_FACTOR,
509 -poly.CPoint( next ).y / SCALE_FACTOR );
510 }
511 }
512
513 break;
514 }
515
516 case PAD_SHAPE::CUSTOM:
517 {
518 fprintf( m_file, " POLYGON %g\n", pad->GetDrillSize().x / SCALE_FACTOR );
519
520 SHAPE_POLY_SET outline;
521 pad->MergePrimitivesAsPolygon( F_Cu, &outline );
522
523 for( int jj = 0; jj < outline.OutlineCount(); ++jj )
524 {
525 const SHAPE_LINE_CHAIN& poly = outline.COutline( jj );
526 int pointCount = poly.PointCount();
527
528 for( int ii = 0; ii < pointCount; ii++ )
529 {
530 int next = ( ii + 1 ) % pointCount;
531 fprintf( m_file, "LINE %g %g %g %g\n",
532 ( off.x + poly.CPoint( ii ).x ) / SCALE_FACTOR,
533 ( -off.y - poly.CPoint( ii ).y ) / SCALE_FACTOR,
534 ( off.x + poly.CPoint( next ).x ) / SCALE_FACTOR,
535 ( -off.y - poly.CPoint( next ).y ) / SCALE_FACTOR );
536 }
537 }
538
539 break;
540 }
541 }
542 }
543
544 fputs( "\n$ENDPADS\n\n", m_file );
545
546 // Now emit the padstacks definitions, using the combined layer masks
547 fputs( "$PADSTACKS\n", m_file );
548
549 // Via padstacks
550 for( unsigned i = 0; i < viastacks.size(); i++ )
551 {
552 PCB_VIA* via = viastacks[i];
553
554 LSET mask = via->GetLayerSet() & master_layermask;
555
556 fprintf( m_file, "PADSTACK VIA%d.%d.%s %g\n",
557 via->GetWidth( PADSTACK::ALL_LAYERS ),
558 via->GetDrillValue(),
559 fmt_mask( mask ).c_str(),
560 via->GetDrillValue() / SCALE_FACTOR );
561
562 for( PCB_LAYER_ID layer : mask.Seq( gc_seq ) )
563 {
564 fprintf( m_file, "PAD V%d.%d.%s %s 0 0\n",
565 via->GetWidth( PADSTACK::ALL_LAYERS ),
566 via->GetDrillValue(),
567 fmt_mask( mask ).c_str(),
568 GenCADLayerName( cu_count, layer ).c_str() );
569 }
570 }
571
572 /* Component padstacks
573 * Older versions of CAM350 don't apply correctly the FLIP semantics for
574 * padstacks, i.e. doesn't swap the top and bottom layers... so I need to
575 * define the shape as MIRRORX and define a separate 'flipped' padstack...
576 * until it appears yet another non-compliant importer */
577 for( unsigned i = 1; i < padstacks.size(); i++ )
578 {
579 PAD* pad = padstacks[i];
580
581 // Straight padstack
582 fprintf( m_file, "PADSTACK PAD%u %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
583
584 LSET pad_set = pad->GetLayerSet() & master_layermask;
585
586 // the special gc_seq
587 for( PCB_LAYER_ID layer : pad_set.Seq( gc_seq ) )
588 {
589 fprintf( m_file, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
590 }
591
592 // Flipped padstack
593 if( m_flipBottomPads )
594 {
595 fprintf( m_file, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
596
597 // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
598 for( PCB_LAYER_ID layer : pad_set.Seq() )
599 {
600 fprintf( m_file, "PAD P%u %s 0 0\n", i,
601 GenCADLayerNameFlipped( cu_count, layer ).c_str() );
602 }
603 }
604 }
605
606 fputs( "$ENDPADSTACKS\n\n", m_file );
607}
608
609
611static size_t hashFootprint( const FOOTPRINT* aFootprint )
612{
613 size_t ret = 0x11223344;
614 constexpr int flags = HASH_FLAGS::HASH_POS | HASH_FLAGS::REL_COORD
616
617 for( PCB_FIELD* i : aFootprint->GetFields() )
618 ret += hash_fp_item( i, flags );
619
620 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
621 ret += hash_fp_item( i, flags );
622
623 for( PAD* i : aFootprint->Pads() )
624 ret += hash_fp_item( i, flags );
625
626 return ret;
627}
628
629
630/* Creates the footprint shape list.
631 * Since module shape is customizable after the placement we cannot share them;
632 * instead we opt for the one-module-one-shape-one-component-one-device approach
633 */
635{
636 const char* layer;
637 wxString pinname;
638 const char* mirror = "0";
639 std::map<wxString, size_t> shapes;
640
641 fputs( "$SHAPES\n", m_file );
642
643 for( FOOTPRINT* footprint : m_board->Footprints() )
644 {
646 {
647 // Check if such shape has been already generated, and if so - reuse it
648 // It is necessary to compute hash (i.e. check all children objects) as
649 // certain components instances might have been modified on the board.
650 // In such case the shape will be different despite the same LIB_ID.
651 wxString shapeName = footprint->GetFPID().Format();
652
653 auto shapeIt = shapes.find( shapeName );
654 size_t modHash = hashFootprint( footprint );
655
656 if( shapeIt != shapes.end() )
657 {
658 if( modHash != shapeIt->second )
659 {
660 // there is an entry for this footprint, but it has a modified shape,
661 // so we need to create a new entry
662 wxString newShapeName;
663 int suffix = 0;
664
665 // find an unused name or matching entry
666 do
667 {
668 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
669 shapeIt = shapes.find( newShapeName );
670 ++suffix;
671 }
672 while( shapeIt != shapes.end() && shapeIt->second != modHash );
673
674 shapeName = newShapeName;
675 }
676
677 if( shapeIt != shapes.end() && modHash == shapeIt->second )
678 {
679 // shape found, so reuse it
680 componentShapes[footprint] = modHash;
681 continue;
682 }
683 }
684
685 // new shape
686 componentShapes[footprint] = modHash;
687 shapeNames[modHash] = shapeName;
688 shapes[shapeName] = modHash;
689 FootprintWriteShape( footprint, shapeName );
690 }
691 else // individual shape for each component
692 {
693 FootprintWriteShape( footprint, footprint->GetReference() );
694 }
695
696 // set of already emitted pins to check for duplicates
697 std::set<wxString> pins;
698
699 for( PAD* pad : footprint->Pads() )
700 {
701 /* Padstacks are defined using the correct layers for the pads, therefore to
702 * all pads need to be marked as TOP to use the padstack information correctly.
703 */
704 layer = "TOP";
705 pinname = pad->GetNumber();
706
707 if( pinname.IsEmpty() )
708 pinname = wxT( "none" );
709
710 if( m_useUniquePins )
711 {
712 int suffix = 0;
713 wxString origPinname( pinname );
714
715 auto it = pins.find( pinname );
716
717 while( it != pins.end() )
718 {
719 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
720 ++suffix;
721 it = pins.find( pinname );
722 }
723
724 pins.insert( pinname );
725 }
726
727 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
728 orient.Normalize();
729
730 VECTOR2I padPos = pad->GetFPRelativePosition();
731
732 // Bottom side footprints use the flipped padstack
733 fprintf( m_file, ( m_flipBottomPads && footprint->GetFlag() ) ?
734 "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
735 "PIN \"%s\" PAD%d %g %g %s %g %s\n",
736 TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
737 padPos.x / SCALE_FACTOR,
738 -padPos.y / SCALE_FACTOR,
739 layer, orient.AsDegrees(), mirror );
740 }
741 }
742
743 fputs( "$ENDSHAPES\n\n", m_file );
744}
745
746
747/* Creates the section $COMPONENTS (Footprints placement)
748 * Bottom side components are difficult to handle: shapes must be mirrored or
749 * flipped, silk layers need to be handled correctly and so on. Also it seems
750 * that *no one* follows the specs...
751 */
753{
754 fputs( "$COMPONENTS\n", m_file );
755
756 int cu_count = m_board->GetCopperLayerCount();
757
758 for( FOOTPRINT* footprint : m_board->Footprints() )
759 {
760 const char* mirror;
761 const char* flip;
762 EDA_ANGLE fp_orient = footprint->GetOrientation();
763
764 if( footprint->GetFlag() )
765 {
766 mirror = "MIRRORX";
767 flip = "FLIP";
768 fp_orient = fp_orient.Invert().Normalize();
769 }
770 else
771 {
772 mirror = "0";
773 flip = "0";
774 }
775
776 fprintf( m_file, "\nCOMPONENT \"%s\"\n",
777 TO_UTF8( escapeString( footprint->GetReference() ) ) );
778 fprintf( m_file, "DEVICE \"DEV_%s\"\n",
779 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
780 fprintf( m_file, "PLACE %g %g\n",
781 MapXTo( footprint->GetPosition().x ),
782 MapYTo( footprint->GetPosition().y ) );
783 fprintf( m_file, "LAYER %s\n",
784 footprint->GetFlag() ? "BOTTOM" : "TOP" );
785 fprintf( m_file, "ROTATION %g\n",
786 fp_orient.AsDegrees() );
787 fprintf( m_file, "SHAPE \"%s\" %s %s\n",
788 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
789 mirror, flip );
790
791 // Text on silk layer: RefDes and value (are they actually useful?)
792 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
793 {
794 std::string layer = GenCADLayerName( cu_count,
795 footprint->GetFlag() ? B_SilkS : F_SilkS );
796
797 fprintf( m_file, "TEXT %g %g %g %g %s %s \"%s\"",
798 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
799 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
800 textItem->GetTextWidth() / SCALE_FACTOR,
801 textItem->GetTextAngle().AsDegrees(),
802 mirror,
803 layer.c_str(),
804 TO_UTF8( escapeString( textItem->GetText() ) ) );
805
806 BOX2I textBox = textItem->GetTextBox();
807
808 fprintf( m_file, " 0 0 %g %g\n",
809 textBox.GetWidth() / SCALE_FACTOR,
810 textBox.GetHeight() / SCALE_FACTOR );
811 }
812
813 // The SHEET is a 'generic description' for referencing the component
814 fprintf( m_file, "SHEET \"RefDes: %s, Value: %s\"\n",
815 TO_UTF8( footprint->GetReference() ),
816 TO_UTF8( footprint->GetValue() ) );
817 }
818
819 fputs( "$ENDCOMPONENTS\n\n", m_file );
820}
821
822
824{
825 // Emit the netlist (which is actually the thing for which GenCAD is used these
826 // days!); tracks are handled later
827
828 wxString msg;
829 NETINFO_ITEM* net;
830 int NbNoConn = 1;
831
832 fputs( "$SIGNALS\n", m_file );
833
834 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
835 {
836 net = m_board->FindNet( ii );
837
838 if( net )
839 {
840 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
841 {
842 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
843 }
844
845 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
846 continue;
847
848 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
849
850 fputs( TO_UTF8( msg ), m_file );
851 fputs( "\n", m_file );
852
853 for( FOOTPRINT* footprint : m_board->Footprints() )
854 {
855 for( PAD* pad : footprint->Pads() )
856 {
857 if( pad->GetNetCode() != net->GetNetCode() )
858 continue;
859
860 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
861 escapeString( footprint->GetReference() ),
862 escapeString( pad->GetNumber() ) );
863
864 fputs( TO_UTF8( msg ), m_file );
865 fputs( "\n", m_file );
866 }
867 }
868 }
869 }
870
871 fputs( "$ENDSIGNALS\n\n", m_file );
872}
873
874
876{
877 wxString msg;
878
879 fputs( "$HEADER\n", m_file );
880 fputs( "GENCAD 1.4\n", m_file );
881
882 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
883 msg.Printf( wxT( "USER \"KiCad %s\"\n" ), GetBuildVersion() );
884 fputs( TO_UTF8( msg ), m_file );
885
886 msg = wxT( "DRAWING \"" ) + m_board->GetFileName() + wxT( "\"\n" );
887 fputs( TO_UTF8( msg ), m_file );
888
890 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
891 msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
892
893 fputs( TO_UTF8( msg ), m_file );
894 fputs( "UNITS INCH\n", m_file );
895
896 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
897 msg.Printf( wxT( "ORIGIN %g %g\n" ),
898 m_storeOriginCoords ? MapXTo( 0 ) : 0,
899 m_storeOriginCoords ? MapYTo( 0 ) : 0 );
900 fputs( TO_UTF8( msg ), m_file );
901
902 fputs( "INTERTRACK 0\n", m_file );
903 fputs( "$ENDHEADER\n\n", m_file );
904
905 return true;
906}
907
908
910{
911 /* Creates the section ROUTES
912 * that handles tracks, vias
913 * TODO: add zones
914 * section:
915 * $ROUTE
916 * ...
917 * $ENROUTE
918 * Track segments must be sorted by nets
919 */
920
921 int vianum = 1;
922 int old_netcode, old_width, old_layer;
923 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
924
925 int cu_count = m_board->GetCopperLayerCount();
926
927 TRACKS tracks( m_board->Tracks() );
928 std::sort( tracks.begin(), tracks.end(),
929 []( const PCB_TRACK* a, const PCB_TRACK* b )
930 {
931 if( a->GetNetCode() == b->GetNetCode() )
932 {
933 if( a->GetWidth() == b->GetWidth() )
934 return ( a->GetLayer() < b->GetLayer() );
935
936 return ( a->GetWidth() < b->GetWidth() );
937 }
938
939 return ( a->GetNetCode() < b->GetNetCode() );
940 } );
941
942 fputs( "$ROUTES\n", m_file );
943
944 old_netcode = -1; old_width = -1; old_layer = -1;
945
946 for( PCB_TRACK* track : tracks )
947 {
948 if( old_netcode != track->GetNetCode() )
949 {
950 old_netcode = track->GetNetCode();
951 NETINFO_ITEM* net = track->GetNet();
952 wxString netname;
953
954 if( net && (net->GetNetname() != wxEmptyString) )
955 netname = net->GetNetname();
956 else
957 netname = wxT( "_noname_" );
958
959 fprintf( m_file, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
960 }
961
962 if( old_width != track->GetWidth() )
963 {
964 old_width = track->GetWidth();
965 fprintf( m_file, "TRACK TRACK%d\n", track->GetWidth() );
966 }
967
968 if( track->Type() == PCB_TRACE_T )
969 {
970 if( old_layer != track->GetLayer() )
971 {
972 old_layer = track->GetLayer();
973 fprintf( m_file, "LAYER %s\n",
974 GenCADLayerName( cu_count, track->GetLayer() ).c_str() );
975 }
976
977 fprintf( m_file, "LINE %g %g %g %g\n",
978 MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
979 MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
980 }
981
982 if( track->Type() == PCB_VIA_T )
983 {
984 const PCB_VIA* via = static_cast<const PCB_VIA*>(track);
985
986 LSET vset = via->GetLayerSet() & master_layermask;
987
988 fprintf( m_file, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
989 via->GetWidth( PADSTACK::ALL_LAYERS ), via->GetDrillValue(),
990 fmt_mask( vset ).c_str(),
991 MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
992 via->GetDrillValue() / SCALE_FACTOR, vianum++ );
993 }
994 }
995
996 fputs( "$ENDROUTES\n\n", m_file );
997}
998
999
1001{
1002 /* Creates the section $DEVICES
1003 * This is a list of footprints properties
1004 * ( Shapes are in section $SHAPE )
1005 */
1006 std::set<wxString> emitted;
1007
1008 fputs( "$DEVICES\n", m_file );
1009
1010 // componentShapes (as a std::map<>) does not give the same order for items between 2 runs.
1011 // This is annoying when one want to compare 2 similar files.
1012 // Therefore we store the strings in a wxArrayString, and after created, strings will be sorted.
1013 // This is not perfect, because the selected footprint used to create the DEVICE section is
1014 // not always the same between runs, but this is much better than no sort
1015 wxArrayString data;
1016
1017 for( const auto& componentShape : componentShapes )
1018 {
1019 const wxString& shapeName = shapeNames[componentShape.second];
1020 bool newDevice;
1021 std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1022
1023 if( !newDevice ) // do not repeat device definitions
1024 continue;
1025
1026 const FOOTPRINT* footprint = componentShape.first;
1027
1028 wxString txt;
1029 txt.Printf( "\nDEVICE \"DEV_%s\"\n", escapeString( shapeName ) );
1030 txt += wxString::Format( "PART \"%s\"\n", escapeString( footprint->GetValue() ) );
1031 txt += wxString::Format( "PACKAGE \"%s\"\n", escapeString( footprint->GetFPID().Format() ) );
1032
1033 data.Add( txt );
1034 }
1035
1036 data.Sort();
1037
1038 for( wxString& item : data )
1039 fprintf( m_file, "%s", TO_UTF8( item ) );
1040
1041 fputs( "$ENDDEVICES\n\n", m_file );
1042}
1043
1044
1046{
1047 // Creates the section $BOARD.
1048 // We output here only the board perimeter
1049
1050 fputs( "$BOARD\n", m_file );
1051
1052 // Extract the board edges
1053 SHAPE_POLY_SET outline;
1054 m_board->GetBoardPolygonOutlines( outline );
1055
1056 for( auto seg1 = outline.IterateSegmentsWithHoles(); seg1; seg1++ )
1057 {
1058 SEG seg = *seg1;
1059 fprintf( m_file, "LINE %g %g %g %g\n",
1060 MapXTo( seg.A.x ), MapYTo( seg.A.y ),
1061 MapXTo( seg.B.x ), MapYTo( seg.B.y ) );
1062 }
1063
1064 fputs( "$ENDBOARD\n\n", m_file );
1065}
1066
1067
1068/* Creates the section "$TRACKS"
1069 * This sections give the list of widths (tools) used in tracks and vias
1070 * format:
1071 * $TRACK
1072 * TRACK <name> <width>
1073 * $ENDTRACK
1074 *
1075 * Each tool name is build like this: "TRACK" + track width.
1076 * For instance for a width = 120 : name = "TRACK120".
1077 */
1079{
1080 // Find thickness used for traces
1081 std::set<int> trackinfo;
1082
1083 for( PCB_TRACK* track : m_board->Tracks() )
1084 trackinfo.insert( track->GetWidth() );
1085
1086 // Write data
1087 fputs( "$TRACKS\n", m_file );
1088
1089 for( int size : trackinfo )
1090 fprintf( m_file, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1091
1092 fputs( "$ENDTRACKS\n\n", m_file );
1093}
1094
1095
1096/* Creates the shape of a footprint (section SHAPE)
1097 * The shape is always given "normal" (Orient 0, not mirrored)
1098 * It's almost guaranteed that the silk layer will be imported wrong but
1099 * the shape also contains the pads!
1100 */
1101void GENCAD_EXPORTER::FootprintWriteShape( FOOTPRINT* aFootprint, const wxString& aShapeName )
1102{
1103 /* creates header: */
1104 fprintf( m_file, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) );
1105
1106 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1107 fprintf( m_file, "INSERT TH\n" );
1108 else
1109 fprintf( m_file, "INSERT SMD\n" );
1110
1111 // Silk outline; wildly interpreted by various importers:
1112 // CAM350 read it right but only closed shapes
1113 // ProntoPlace double-flip it (at least the pads are correct)
1114 // GerberTool usually get it right...
1115 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1116 {
1117 if( item->Type() == PCB_SHAPE_T
1118 && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) )
1119 {
1120 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1121 VECTOR2I start = shape->GetStart() - aFootprint->GetPosition();
1122 VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition();
1123 VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition();
1124
1125 RotatePoint( start, -aFootprint->GetOrientation() );
1126 RotatePoint( end, -aFootprint->GetOrientation() );
1127 RotatePoint( center, -aFootprint->GetOrientation() );
1128
1129 switch( shape->GetShape() )
1130 {
1131 case SHAPE_T::SEGMENT:
1132 fprintf( m_file, "LINE %g %g %g %g\n",
1133 start.x / SCALE_FACTOR,
1134 -start.y / SCALE_FACTOR,
1135 end.x / SCALE_FACTOR,
1136 -end.y / SCALE_FACTOR );
1137 break;
1138
1139 case SHAPE_T::RECTANGLE:
1140 fprintf( m_file, "LINE %g %g %g %g\n",
1141 start.x / SCALE_FACTOR,
1142 -start.y / SCALE_FACTOR,
1143 end.x / SCALE_FACTOR,
1144 -end.y / SCALE_FACTOR );
1145 fprintf( m_file, "LINE %g %g %g %g\n",
1146 end.x / SCALE_FACTOR,
1147 -start.y / SCALE_FACTOR,
1148 end.x / SCALE_FACTOR,
1149 -end.y / SCALE_FACTOR );
1150 fprintf( m_file, "LINE %g %g %g %g\n",
1151 end.x / SCALE_FACTOR,
1152 -end.y / SCALE_FACTOR,
1153 start.x / SCALE_FACTOR,
1154 -end.y / SCALE_FACTOR );
1155 fprintf( m_file, "LINE %g %g %g %g\n",
1156 start.x / SCALE_FACTOR,
1157 -end.y / SCALE_FACTOR,
1158 start.x / SCALE_FACTOR,
1159 -start.y / SCALE_FACTOR );
1160 break;
1161
1162 case SHAPE_T::CIRCLE:
1163 {
1164 int radius = KiROUND( end.Distance( start ) );
1165
1166 fprintf( m_file, "CIRCLE %g %g %g\n",
1167 start.x / SCALE_FACTOR,
1168 -start.y / SCALE_FACTOR,
1169 radius / SCALE_FACTOR );
1170 break;
1171 }
1172
1173 case SHAPE_T::ARC:
1174 if( shape->GetArcAngle() > ANGLE_0 )
1175 std::swap( start, end );
1176
1177 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
1178 start.x / SCALE_FACTOR,
1179 -start.y / SCALE_FACTOR,
1180 end.x / SCALE_FACTOR,
1181 -end.y / SCALE_FACTOR,
1182 center.x / SCALE_FACTOR,
1183 -center.y / SCALE_FACTOR );
1184 break;
1185
1186 case SHAPE_T::POLY:
1187 // Not exported (TODO)
1188 break;
1189
1190 default:
1191 wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) );
1192 break;
1193 }
1194 }
1195 }
1196}
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
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:222
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:295
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:2536
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:817
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1961
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:2647
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:703
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1713
int GetCopperLayerCount() const
Definition: board.cpp:780
const FOOTPRINTS & Footprints() const
Definition: board.h:336
const TRACKS & Tracks() const
Definition: board.h:334
const wxString & GetFileName() const
Definition: board.h:332
PROJECT * GetProject() const
Definition: board.h:499
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:934
unsigned GetNetCount() const
Definition: board.h:910
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:221
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Invert() const
Definition: eda_angle.h:165
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:912
SHAPE_T GetShape() const
Definition: eda_shape.h:132
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
EDA_ANGLE GetOrientation() const
Definition: footprint.h:225
std::deque< PAD * > & Pads()
Definition: footprint.h:204
int GetAttributes() const
Definition: footprint.h:288
const LIB_ID & GetFPID() const
Definition: footprint.h:246
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
Definition: footprint.cpp:667
const wxString & GetValue() const
Definition: footprint.h:642
const wxString & GetReference() const
Definition: footprint.h:620
VECTOR2I GetPosition() const override
Definition: footprint.h:222
DRAWINGS & GraphicalItems()
Definition: footprint.h:207
const wxString getShapeName(FOOTPRINT *aFootprint)
bool CreateHeaderInfoData()
Creates the header section.
bool WriteFile(const wxString &aFullFileName)
Export a genCAD file.
void FootprintWriteShape(FOOTPRINT *aFootprint, const wxString &aShapeName)
UTF8 Format() const
Definition: lib_id.cpp:118
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:245
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:562
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:295
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:1487
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:79
int GetWidth() const override
Definition: pcb_track.cpp:359
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:613
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:1062
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:401
static std::map< int, wxString > shapeNames
static bool ViaSort(const PCB_VIA *aPadref, const PCB_VIA *aPadcmp)
static std::string GenCADLayerName(int aCuCount, PCB_LAYER_ID aId)
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::string fmt_mask(LSET aSet)
static std::map< FOOTPRINT *, int > componentShapes
static std::string GenCADLayerNameFlipped(int aCuCount, PCB_LAYER_ID aId)
static wxString escapeString(const wxString &aString)
@ FP_THROUGH_HOLE
Definition: footprint.h:79
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:581
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:70
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
const double IU_PER_MILS
Definition: base_units.h:77
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_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