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 (C) 1992-2023 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 ), via->GetDrillValue(),
558 fmt_mask( mask ).c_str(),
559 via->GetDrillValue() / SCALE_FACTOR );
560
561 for( PCB_LAYER_ID layer : mask.Seq( gc_seq ) )
562 {
563 fprintf( m_file, "PAD V%d.%d.%s %s 0 0\n",
564 via->GetWidth( PADSTACK::ALL_LAYERS ), 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( PCB_FIELD* i : aFootprint->Fields() )
616 ret += hash_fp_item( i, flags );
617
618 for( BOARD_ITEM* i : aFootprint->GraphicalItems() )
619 ret += hash_fp_item( i, flags );
620
621 for( PAD* i : aFootprint->Pads() )
622 ret += hash_fp_item( i, flags );
623
624 return ret;
625}
626
627
628/* Creates the footprint shape list.
629 * Since module shape is customizable after the placement we cannot share them;
630 * instead we opt for the one-module-one-shape-one-component-one-device approach
631 */
633{
634 const char* layer;
635 wxString pinname;
636 const char* mirror = "0";
637 std::map<wxString, size_t> shapes;
638
639 fputs( "$SHAPES\n", m_file );
640
641 for( FOOTPRINT* footprint : m_board->Footprints() )
642 {
644 {
645 // Check if such shape has been already generated, and if so - reuse it
646 // It is necessary to compute hash (i.e. check all children objects) as
647 // certain components instances might have been modified on the board.
648 // In such case the shape will be different despite the same LIB_ID.
649 wxString shapeName = footprint->GetFPID().Format();
650
651 auto shapeIt = shapes.find( shapeName );
652 size_t modHash = hashFootprint( footprint );
653
654 if( shapeIt != shapes.end() )
655 {
656 if( modHash != shapeIt->second )
657 {
658 // there is an entry for this footprint, but it has a modified shape,
659 // so we need to create a new entry
660 wxString newShapeName;
661 int suffix = 0;
662
663 // find an unused name or matching entry
664 do
665 {
666 newShapeName = wxString::Format( wxT( "%s_%d" ), shapeName, suffix );
667 shapeIt = shapes.find( newShapeName );
668 ++suffix;
669 }
670 while( shapeIt != shapes.end() && shapeIt->second != modHash );
671
672 shapeName = newShapeName;
673 }
674
675 if( shapeIt != shapes.end() && modHash == shapeIt->second )
676 {
677 // shape found, so reuse it
678 componentShapes[footprint] = modHash;
679 continue;
680 }
681 }
682
683 // new shape
684 componentShapes[footprint] = modHash;
685 shapeNames[modHash] = shapeName;
686 shapes[shapeName] = modHash;
687 FootprintWriteShape( footprint, shapeName );
688 }
689 else // individual shape for each component
690 {
691 FootprintWriteShape( footprint, footprint->GetReference() );
692 }
693
694 // set of already emitted pins to check for duplicates
695 std::set<wxString> pins;
696
697 for( PAD* pad : footprint->Pads() )
698 {
699 /* Padstacks are defined using the correct layers for the pads, therefore to
700 * all pads need to be marked as TOP to use the padstack information correctly.
701 */
702 layer = "TOP";
703 pinname = pad->GetNumber();
704
705 if( pinname.IsEmpty() )
706 pinname = wxT( "none" );
707
708 if( m_useUniquePins )
709 {
710 int suffix = 0;
711 wxString origPinname( pinname );
712
713 auto it = pins.find( pinname );
714
715 while( it != pins.end() )
716 {
717 pinname = wxString::Format( wxT( "%s_%d" ), origPinname, suffix );
718 ++suffix;
719 it = pins.find( pinname );
720 }
721
722 pins.insert( pinname );
723 }
724
725 EDA_ANGLE orient = pad->GetOrientation() - footprint->GetOrientation();
726 orient.Normalize();
727
728 VECTOR2I padPos = pad->GetFPRelativePosition();
729
730 // Bottom side footprints use the flipped padstack
731 fprintf( m_file, ( m_flipBottomPads && footprint->GetFlag() ) ?
732 "PIN \"%s\" PAD%dF %g %g %s %g %s\n" :
733 "PIN \"%s\" PAD%d %g %g %s %g %s\n",
734 TO_UTF8( escapeString( pinname ) ), pad->GetSubRatsnest(),
735 padPos.x / SCALE_FACTOR,
736 -padPos.y / SCALE_FACTOR,
737 layer, orient.AsDegrees(), mirror );
738 }
739 }
740
741 fputs( "$ENDSHAPES\n\n", m_file );
742}
743
744
745/* Creates the section $COMPONENTS (Footprints placement)
746 * Bottom side components are difficult to handle: shapes must be mirrored or
747 * flipped, silk layers need to be handled correctly and so on. Also it seems
748 * that *no one* follows the specs...
749 */
751{
752 fputs( "$COMPONENTS\n", m_file );
753
754 int cu_count = m_board->GetCopperLayerCount();
755
756 for( FOOTPRINT* footprint : m_board->Footprints() )
757 {
758 const char* mirror;
759 const char* flip;
760 EDA_ANGLE fp_orient = footprint->GetOrientation();
761
762 if( footprint->GetFlag() )
763 {
764 mirror = "MIRRORX";
765 flip = "FLIP";
766 fp_orient = fp_orient.Invert().Normalize();
767 }
768 else
769 {
770 mirror = "0";
771 flip = "0";
772 }
773
774 fprintf( m_file, "\nCOMPONENT \"%s\"\n",
775 TO_UTF8( escapeString( footprint->GetReference() ) ) );
776 fprintf( m_file, "DEVICE \"DEV_%s\"\n",
777 TO_UTF8( escapeString( getShapeName( footprint ) ) ) );
778 fprintf( m_file, "PLACE %g %g\n",
779 MapXTo( footprint->GetPosition().x ),
780 MapYTo( footprint->GetPosition().y ) );
781 fprintf( m_file, "LAYER %s\n",
782 footprint->GetFlag() ? "BOTTOM" : "TOP" );
783 fprintf( m_file, "ROTATION %g\n",
784 fp_orient.AsDegrees() );
785 fprintf( m_file, "SHAPE \"%s\" %s %s\n",
786 TO_UTF8( escapeString( getShapeName( footprint ) ) ),
787 mirror, flip );
788
789 // Text on silk layer: RefDes and value (are they actually useful?)
790 for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } )
791 {
792 std::string layer = GenCADLayerName( cu_count,
793 footprint->GetFlag() ? B_SilkS : F_SilkS );
794
795 fprintf( m_file, "TEXT %g %g %g %g %s %s \"%s\"",
796 textItem->GetFPRelativePosition().x / SCALE_FACTOR,
797 -textItem->GetFPRelativePosition().y / SCALE_FACTOR,
798 textItem->GetTextWidth() / SCALE_FACTOR,
799 textItem->GetTextAngle().AsDegrees(),
800 mirror,
801 layer.c_str(),
802 TO_UTF8( escapeString( textItem->GetText() ) ) );
803
804 BOX2I textBox = textItem->GetTextBox();
805
806 fprintf( m_file, " 0 0 %g %g\n",
807 textBox.GetWidth() / SCALE_FACTOR,
808 textBox.GetHeight() / SCALE_FACTOR );
809 }
810
811 // The SHEET is a 'generic description' for referencing the component
812 fprintf( m_file, "SHEET \"RefDes: %s, Value: %s\"\n",
813 TO_UTF8( footprint->GetReference() ),
814 TO_UTF8( footprint->GetValue() ) );
815 }
816
817 fputs( "$ENDCOMPONENTS\n\n", m_file );
818}
819
820
822{
823 // Emit the netlist (which is actually the thing for which GenCAD is used these
824 // days!); tracks are handled later
825
826 wxString msg;
827 NETINFO_ITEM* net;
828 int NbNoConn = 1;
829
830 fputs( "$SIGNALS\n", m_file );
831
832 for( unsigned ii = 0; ii < m_board->GetNetCount(); ii++ )
833 {
834 net = m_board->FindNet( ii );
835
836 if( net )
837 {
838 if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
839 {
840 msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
841 }
842
843 if( net->GetNetCode() <= 0 ) // dummy netlist (no connection)
844 continue;
845
846 msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
847
848 fputs( TO_UTF8( msg ), m_file );
849 fputs( "\n", m_file );
850
851 for( FOOTPRINT* footprint : m_board->Footprints() )
852 {
853 for( PAD* pad : footprint->Pads() )
854 {
855 if( pad->GetNetCode() != net->GetNetCode() )
856 continue;
857
858 msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
859 escapeString( footprint->GetReference() ),
860 escapeString( pad->GetNumber() ) );
861
862 fputs( TO_UTF8( msg ), m_file );
863 fputs( "\n", m_file );
864 }
865 }
866 }
867 }
868
869 fputs( "$ENDSIGNALS\n\n", m_file );
870}
871
872
874{
875 wxString msg;
876
877 fputs( "$HEADER\n", m_file );
878 fputs( "GENCAD 1.4\n", m_file );
879
880 // Please note: GenCAD syntax requires quoted strings if they can contain spaces
881 msg.Printf( wxT( "USER \"KiCad %s\"\n" ), GetBuildVersion() );
882 fputs( TO_UTF8( msg ), m_file );
883
884 msg = wxT( "DRAWING \"" ) + m_board->GetFileName() + wxT( "\"\n" );
885 fputs( TO_UTF8( msg ), m_file );
886
888 wxString date = ExpandTextVars( m_board->GetTitleBlock().GetDate(), m_board->GetProject() );
889 msg = wxT( "REVISION \"" ) + rev + wxT( " " ) + date + wxT( "\"\n" );
890
891 fputs( TO_UTF8( msg ), m_file );
892 fputs( "UNITS INCH\n", m_file );
893
894 // giving 0 as the argument to Map{X,Y}To returns the scaled origin point
895 msg.Printf( wxT( "ORIGIN %g %g\n" ),
896 m_storeOriginCoords ? MapXTo( 0 ) : 0,
897 m_storeOriginCoords ? MapYTo( 0 ) : 0 );
898 fputs( TO_UTF8( msg ), m_file );
899
900 fputs( "INTERTRACK 0\n", m_file );
901 fputs( "$ENDHEADER\n\n", m_file );
902
903 return true;
904}
905
906
908{
909 /* Creates the section ROUTES
910 * that handles tracks, vias
911 * TODO: add zones
912 * section:
913 * $ROUTE
914 * ...
915 * $ENROUTE
916 * Track segments must be sorted by nets
917 */
918
919 int vianum = 1;
920 int old_netcode, old_width, old_layer;
921 LSET master_layermask = m_board->GetDesignSettings().GetEnabledLayers();
922
923 int cu_count = m_board->GetCopperLayerCount();
924
925 TRACKS tracks( m_board->Tracks() );
926 std::sort( tracks.begin(), tracks.end(),
927 []( const PCB_TRACK* a, const PCB_TRACK* b )
928 {
929 if( a->GetNetCode() == b->GetNetCode() )
930 {
931 if( a->GetWidth() == b->GetWidth() )
932 return ( a->GetLayer() < b->GetLayer() );
933
934 return ( a->GetWidth() < b->GetWidth() );
935 }
936
937 return ( a->GetNetCode() < b->GetNetCode() );
938 } );
939
940 fputs( "$ROUTES\n", m_file );
941
942 old_netcode = -1; old_width = -1; old_layer = -1;
943
944 for( PCB_TRACK* track : tracks )
945 {
946 if( old_netcode != track->GetNetCode() )
947 {
948 old_netcode = track->GetNetCode();
949 NETINFO_ITEM* net = track->GetNet();
950 wxString netname;
951
952 if( net && (net->GetNetname() != wxEmptyString) )
953 netname = net->GetNetname();
954 else
955 netname = wxT( "_noname_" );
956
957 fprintf( m_file, "ROUTE \"%s\"\n", TO_UTF8( escapeString( netname ) ) );
958 }
959
960 if( old_width != track->GetWidth() )
961 {
962 old_width = track->GetWidth();
963 fprintf( m_file, "TRACK TRACK%d\n", track->GetWidth() );
964 }
965
966 if( track->Type() == PCB_TRACE_T )
967 {
968 if( old_layer != track->GetLayer() )
969 {
970 old_layer = track->GetLayer();
971 fprintf( m_file, "LAYER %s\n",
972 GenCADLayerName( cu_count, track->GetLayer() ).c_str() );
973 }
974
975 fprintf( m_file, "LINE %g %g %g %g\n",
976 MapXTo( track->GetStart().x ), MapYTo( track->GetStart().y ),
977 MapXTo( track->GetEnd().x ), MapYTo( track->GetEnd().y ) );
978 }
979
980 if( track->Type() == PCB_VIA_T )
981 {
982 const PCB_VIA* via = static_cast<const PCB_VIA*>(track);
983
984 LSET vset = via->GetLayerSet() & master_layermask;
985
986 fprintf( m_file, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
987 via->GetWidth( PADSTACK::ALL_LAYERS ), via->GetDrillValue(),
988 fmt_mask( vset ).c_str(),
989 MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
990 via->GetDrillValue() / SCALE_FACTOR, vianum++ );
991 }
992 }
993
994 fputs( "$ENDROUTES\n\n", m_file );
995}
996
997
999{
1000 /* Creates the section $DEVICES
1001 * This is a list of footprints properties
1002 * ( Shapes are in section $SHAPE )
1003 */
1004 std::set<wxString> emitted;
1005
1006 fputs( "$DEVICES\n", m_file );
1007
1008 // componentShapes (as a std::map<>) does not give the same order for items between 2 runs.
1009 // This is annoying when one want to compare 2 similar files.
1010 // Therefore we store the strings in a wxArrayString, and after created, strings will be sorted.
1011 // This is not perfect, because the selected footprint used to create the DEVICE section is
1012 // not always the same between runs, but this is much better than no sort
1013 wxArrayString data;
1014
1015 for( const auto& componentShape : componentShapes )
1016 {
1017 const wxString& shapeName = shapeNames[componentShape.second];
1018 bool newDevice;
1019 std::tie( std::ignore, newDevice ) = emitted.insert( shapeName );
1020
1021 if( !newDevice ) // do not repeat device definitions
1022 continue;
1023
1024 const FOOTPRINT* footprint = componentShape.first;
1025
1026 wxString txt;
1027 txt.Printf( "\nDEVICE \"DEV_%s\"\n", escapeString( shapeName ) );
1028 txt += wxString::Format( "PART \"%s\"\n", escapeString( footprint->GetValue() ) );
1029 txt += wxString::Format( "PACKAGE \"%s\"\n", escapeString( footprint->GetFPID().Format() ) );
1030
1031 data.Add( txt );
1032 }
1033
1034 data.Sort();
1035
1036 for( wxString& item : data )
1037 fprintf( m_file, "%s", TO_UTF8( item ) );
1038
1039 fputs( "$ENDDEVICES\n\n", m_file );
1040}
1041
1042
1044{
1045 // Creates the section $BOARD.
1046 // We output here only the board perimeter
1047
1048 fputs( "$BOARD\n", m_file );
1049
1050 // Extract the board edges
1051 SHAPE_POLY_SET outline;
1052 m_board->GetBoardPolygonOutlines( outline );
1053
1054 for( auto seg1 = outline.IterateSegmentsWithHoles(); seg1; seg1++ )
1055 {
1056 SEG seg = *seg1;
1057 fprintf( m_file, "LINE %g %g %g %g\n",
1058 MapXTo( seg.A.x ), MapYTo( seg.A.y ),
1059 MapXTo( seg.B.x ), MapYTo( seg.B.y ) );
1060 }
1061
1062 fputs( "$ENDBOARD\n\n", m_file );
1063}
1064
1065
1066/* Creates the section "$TRACKS"
1067 * This sections give the list of widths (tools) used in tracks and vias
1068 * format:
1069 * $TRACK
1070 * TRACK <name> <width>
1071 * $ENDTRACK
1072 *
1073 * Each tool name is build like this: "TRACK" + track width.
1074 * For instance for a width = 120 : name = "TRACK120".
1075 */
1077{
1078 // Find thickness used for traces
1079 std::set<int> trackinfo;
1080
1081 for( PCB_TRACK* track : m_board->Tracks() )
1082 trackinfo.insert( track->GetWidth() );
1083
1084 // Write data
1085 fputs( "$TRACKS\n", m_file );
1086
1087 for( int size : trackinfo )
1088 fprintf( m_file, "TRACK TRACK%d %g\n", size, size / SCALE_FACTOR );
1089
1090 fputs( "$ENDTRACKS\n\n", m_file );
1091}
1092
1093
1094/* Creates the shape of a footprint (section SHAPE)
1095 * The shape is always given "normal" (Orient 0, not mirrored)
1096 * It's almost guaranteed that the silk layer will be imported wrong but
1097 * the shape also contains the pads!
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
1116 && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) )
1117 {
1118 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1119 VECTOR2I start = shape->GetStart() - aFootprint->GetPosition();
1120 VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition();
1121 VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition();
1122
1123 RotatePoint( start, -aFootprint->GetOrientation() );
1124 RotatePoint( end, -aFootprint->GetOrientation() );
1125 RotatePoint( center, -aFootprint->GetOrientation() );
1126
1127 switch( shape->GetShape() )
1128 {
1129 case SHAPE_T::SEGMENT:
1130 fprintf( m_file, "LINE %g %g %g %g\n",
1131 start.x / SCALE_FACTOR,
1132 -start.y / SCALE_FACTOR,
1133 end.x / SCALE_FACTOR,
1134 -end.y / SCALE_FACTOR );
1135 break;
1136
1137 case SHAPE_T::RECTANGLE:
1138 fprintf( m_file, "LINE %g %g %g %g\n",
1139 start.x / SCALE_FACTOR,
1140 -start.y / SCALE_FACTOR,
1141 end.x / SCALE_FACTOR,
1142 -end.y / SCALE_FACTOR );
1143 fprintf( m_file, "LINE %g %g %g %g\n",
1144 end.x / SCALE_FACTOR,
1145 -start.y / SCALE_FACTOR,
1146 end.x / SCALE_FACTOR,
1147 -end.y / SCALE_FACTOR );
1148 fprintf( m_file, "LINE %g %g %g %g\n",
1149 end.x / SCALE_FACTOR,
1150 -end.y / SCALE_FACTOR,
1151 start.x / SCALE_FACTOR,
1152 -end.y / SCALE_FACTOR );
1153 fprintf( m_file, "LINE %g %g %g %g\n",
1154 start.x / SCALE_FACTOR,
1155 -end.y / SCALE_FACTOR,
1156 start.x / SCALE_FACTOR,
1157 -start.y / SCALE_FACTOR );
1158 break;
1159
1160 case SHAPE_T::CIRCLE:
1161 {
1162 int radius = KiROUND( end.Distance( start ) );
1163
1164 fprintf( m_file, "CIRCLE %g %g %g\n",
1165 start.x / SCALE_FACTOR,
1166 -start.y / SCALE_FACTOR,
1167 radius / SCALE_FACTOR );
1168 break;
1169 }
1170
1171 case SHAPE_T::ARC:
1172 if( shape->GetArcAngle() > ANGLE_0 )
1173 std::swap( start, end );
1174
1175 fprintf( m_file, "ARC %g %g %g %g %g %g\n",
1176 start.x / SCALE_FACTOR,
1177 -start.y / SCALE_FACTOR,
1178 end.x / SCALE_FACTOR,
1179 -end.y / SCALE_FACTOR,
1180 center.x / SCALE_FACTOR,
1181 -center.y / SCALE_FACTOR );
1182 break;
1183
1184 case SHAPE_T::POLY:
1185 // Not exported (TODO)
1186 break;
1187
1188 default:
1189 wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) );
1190 break;
1191 }
1192 }
1193 }
1194}
@ 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.
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:290
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:2497
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:778
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1922
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:2600
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:695
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1674
int GetCopperLayerCount() const
Definition: board.cpp:741
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
const wxString & GetFileName() const
Definition: board.h:327
PROJECT * GetProject() const
Definition: board.h:491
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
unsigned GetNetCount() const
Definition: board.h:902
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:896
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:227
std::deque< PAD * > & Pads()
Definition: footprint.h:206
int GetAttributes() const
Definition: footprint.h:290
const LIB_ID & GetFPID() const
Definition: footprint.h:248
PCB_FIELDS & Fields()
Definition: footprint.h:203
const wxString & GetValue() const
Definition: footprint.h:644
const wxString & GetReference() const
Definition: footprint.h:622
VECTOR2I GetPosition() const override
Definition: footprint.h:224
DRAWINGS & GraphicalItems()
Definition: footprint.h:209
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:36
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:250
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:420
std::string FmtBin() const
Return a binary string showing contents of this LSEQ.
Definition: lset.cpp:300
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:1444
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:557
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:75
size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags)
Calculate hash of an EDA_ITEM.
Definition: hash_eda.cpp:55
@ HASH_POS
use coordinates relative to the parent object
Definition: hash_eda.h:43
@ REL_COORD
use coordinates relative to the shape position
Definition: hash_eda.h:46
@ HASH_LAYER
Definition: hash_eda.h:50
@ HASH_ROT
Definition: hash_eda.h:49
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:531
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:126
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:68
#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:82
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:691