KiCad PCB EDA Suite
Loading...
Searching...
No Matches
specctra_export.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) 2007-2015 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22/* This source is a complement to specctra.cpp and implements the export to
23 specctra dsn file format. The specification for the grammar of the specctra
24 dsn file used to develop this code is given here:
25 http://tech.groups.yahoo.com/group/kicad-users/files/ then file "specctra.pdf"
26
27 Also see the comments at the top of the specctra.cpp file itself.
28*/
29
30#include "specctra.h"
31
33#include <set>
34#include <map>
35
36#include <wx/log.h>
37
38#include <pcb_edit_frame.h>
39#include <confirm.h> // DisplayErrorMessage()
40#include <gestfich.h> // EDA_FileSelector()
41#include <locale_io.h>
42#include <macros.h>
43#include <math/util.h> // for KiROUND
44#include <string_utils.h>
45
46#include <board.h>
48#include <footprint.h>
49#include <pcb_shape.h>
50#include <pcb_track.h>
51#include <pad.h>
52#include <zone.h>
53#include <base_units.h>
54#include <collectors.h>
59#include <mmh3_hash.h>
60#include <pcbnew_settings.h>
61
62#include "fmt/xchar.h"
63
64
65using namespace DSN;
66
67// comment the line #define EXPORT_CUSTOM_PADS_CONVEX_HULL to export CUSTOM pads exact shapes.
68// Shapes can be non convex polygons with holes (linked to outline) that can create issues.
69// Especially Freerouter does not handle them very well:
70// - too complex shapes are not accepted, especially shapes with holes (dsn files are not loaded).
71// - and Freerouter actually uses something like a convex hull of the shape (that works poorly).
72// I am guessing non convex polygons with holes linked could create issues with any Router.
73#define EXPORT_CUSTOM_PADS_CONVEX_HULL
74
75
76bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename )
77{
78 BASE_SCREEN* screen = GetScreen();
79 bool wasModified = screen->IsContentModified();
80 wxString errorText;
81 bool ok = true;
82
83 try
84 {
85 DSN::ExportBoardToSpecctraFile( GetBoard(), aFullFilename );
86 }
87 catch( const IO_ERROR& ioe )
88 {
89 ok = false;
90
91 // copy the error string to safe place, ioe is in this scope only.
92 errorText = ioe.What();
93 }
94
95 // The two calls to FOOTPRINT::Flip() in ExportBoardToSpecctraFile both set the modified flag,
96 // yet their actions cancel each other out, so it should be ok to clear the flag.
97 if( !wasModified )
98 screen->SetContentModified( false );
99
100 if( ok )
101 SetStatusText( wxString( _( "BOARD exported OK." ) ) );
102 else
103 DisplayErrorMessage( this, _( "Unable to export, please fix and try again" ), errorText );
104
105 return ok;
106}
107
108namespace DSN
109{
110
111
112void ExportBoardToSpecctraFile( BOARD* aBoard, const wxString& aFullFilename, REPORTER* aReporter )
113{
114 SPECCTRA_DB db;
115
117
118 LOCALE_IO toggle; // Switch the locale to standard C
119
120 // Build the board outlines *before* flipping footprints
121 if( !db.BuiltBoardOutlines( aBoard ) )
122 ReportWarning( aReporter, _( "Board outline is malformed. Run DRC for a full analysis." ) );
123
124 // DSN Images (=KiCad FOOTPRINTs and PADs) must be presented from the top view. So we
125 // temporarily flip any footprints which are on the back side of the board to the front,
126 // and record this in the FOOTPRINT's flag field.
127 db.FlipFOOTPRINTs( aBoard );
128
129 try
130 {
131 aBoard->SynchronizeNetsAndNetClasses( false );
132 db.FromBOARD( aBoard );
133 db.ExportPCB( aFullFilename, true );
134 db.RevertFOOTPRINTs( aBoard );
135
136 // if an exception is thrown by FromBOARD() or ExportPCB(), then ~SPECCTRA_DB() will
137 // close the file.
138 }
139 catch( ... )
140 {
141 db.RevertFOOTPRINTs( aBoard );
142 throw;
143 }
144}
145
146
147// "specctra reported units" are what we tell the external router that our exported lengths are in
148
153static inline double scale( int kicadDist )
154{
155 // nanometers to um
156 return kicadDist / ( pcbIUScale.IU_PER_MM / 1000.0 );
157}
158
159
161static inline double IU2um( int kicadDist )
162{
163 return kicadDist * ( 1000.0 / pcbIUScale.IU_PER_MM );
164}
165
166
167static inline double mapX( int x )
168{
169 return scale( x );
170}
171
172
173static inline double mapY( int y )
174{
175 return -scale( y ); // make y negative, since it is increasing going down.
176}
177
178
185static POINT mapPt( const VECTOR2I& pt )
186{
187 POINT ret;
188
189 ret.x = mapX( pt.x );
190 ret.y = mapY( pt.y );
191 ret.FixNegativeZero();
192 return ret;
193}
194
195
196static POINT mapPt( const VECTOR2I& pt, FOOTPRINT* aFootprint )
197{
198 VECTOR2I fpRelative = pt - aFootprint->GetPosition();
199 RotatePoint( fpRelative, -aFootprint->GetOrientation() );
200 return mapPt( fpRelative );
201}
202
203
207static bool isRoundKeepout( PAD* aPad )
208{
209 std::vector<PCB_LAYER_ID> layers = aPad->Padstack().UniqueLayers();
210
211 // Any layer with real copper makes this a pad, not a keepout. An empty padstack passes
212 // that test vacuously, so it does not count.
213 bool swallowedByHole = !layers.empty();
214
215 for( PCB_LAYER_ID layer : layers )
216 {
217 if( aPad->GetShape( layer ) != PAD_SHAPE::CIRCLE
218 || aPad->GetDrillSize().x < aPad->GetSize( layer ).x )
219 {
220 swallowedByHole = false;
221 }
222 }
223
224 if( swallowedByHole )
225 return true;
226
227 return aPad->GetShape( aPad->Padstack().EffectiveLayerFor( F_Cu ) ) == PAD_SHAPE::CIRCLE
228 && !( aPad->GetLayerSet() & LSET::AllCuMask() ).any();
229}
230
231
235static PATH* makePath( const POINT& aStart, const POINT& aEnd, const std::string& aLayerName )
236{
237 PATH* path = new PATH( nullptr, T_path );
238
239 path->AppendPoint( aStart );
240 path->AppendPoint( aEnd );
241 path->SetLayerId( aLayerName );
242 return path;
243}
244
245
247{
248 return aBoard->GetBoardPolygonOutlines( m_brd_outlines, true );
249}
250
251
257{
258 std::string m_family;
259 std::string m_dims;
260 std::string m_offset;
261
262 bool operator==( const SPECCTRA_SHAPE_ID& aOther ) const = default;
263};
264
265
270static SPECCTRA_SHAPE_ID appendPadstackShape( PADSTACK* aPadstack, PAD* aPad, PCB_LAYER_ID aPadLayer,
271 const std::vector<std::string>& aLayerNames )
272{
274 const VECTOR2I& padSize = aPad->GetSize( aPadLayer );
275 const VECTOR2I& offset = aPad->GetOffset( aPadLayer );
276 POINT dsnOffset;
277
278 if( offset.x || offset.y )
279 {
280 dsnOffset = mapPt( offset );
281
282 // Using () would cause padstack name to be quoted, and {} locks freerouter, so use [].
283 std::ostringstream oss;
284 oss.imbue( std::locale::classic() );
285 oss << std::fixed << std::setprecision( 6 )
286 << '[' << dsnOffset.x << ',' << dsnOffset.y << ']';
287 id.m_offset = oss.str();
288 }
289
290 std::ostringstream dims;
291 dims << std::fixed << std::setprecision( 6 );
292
293 switch( aPad->GetShape( aPadLayer ) )
294 {
296 {
297 for( const std::string& layerName : aLayerNames )
298 {
299 SHAPE* shape = new SHAPE( aPadstack );
300
301 aPadstack->Append( shape );
302
303 CIRCLE* circle = new CIRCLE( shape );
304
305 shape->SetShape( circle );
306
307 circle->SetLayerId( layerName );
308 circle->SetDiameter( scale( padSize.x ) );
309 circle->SetVertex( dsnOffset );
310 }
311
312 id.m_family = "Round";
313 dims << IU2um( padSize.x ) << "_um";
314 break;
315 }
316
318 {
319 double dx = scale( padSize.x ) / 2.0;
320 double dy = scale( padSize.y ) / 2.0;
321
322 POINT lowerLeft( -dx, -dy );
323 POINT upperRight( dx, dy );
324
325 lowerLeft += dsnOffset;
326 upperRight += dsnOffset;
327
328 for( const std::string& layerName : aLayerNames )
329 {
330 SHAPE* shape = new SHAPE( aPadstack );
331
332 aPadstack->Append( shape );
333
334 RECTANGLE* rect = new RECTANGLE( shape );
335
336 shape->SetShape( rect );
337
338 rect->SetLayerId( layerName );
339 rect->SetCorners( lowerLeft, upperRight );
340 }
341
342 id.m_family = "Rect";
343 dims << IU2um( padSize.x ) << "x" << IU2um( padSize.y ) << "_um";
344 break;
345 }
346
347 case PAD_SHAPE::OVAL:
348 {
349 double dx = scale( padSize.x ) / 2.0;
350 double dy = scale( padSize.y ) / 2.0;
351 double dr = dx - dy;
352 double radius;
353 POINT pstart;
354 POINT pstop;
355
356 if( dr >= 0 ) // oval is horizontal
357 {
358 radius = dy;
359
360 pstart = POINT( -dr, 0.0 );
361 pstop = POINT( dr, 0.0 );
362 }
363 else // oval is vertical
364 {
365 radius = dx;
366 dr = -dr;
367
368 pstart = POINT( 0.0, -dr );
369 pstop = POINT( 0.0, dr );
370 }
371
372 pstart += dsnOffset;
373 pstop += dsnOffset;
374
375 for( const std::string& layerName : aLayerNames )
376 {
377 // see http://www.freerouting.net/usren/viewtopic.php?f=3&t=317#p408
378 SHAPE* shape = new SHAPE( aPadstack );
379
380 aPadstack->Append( shape );
381
382 PATH* path = makePath( pstart, pstop, layerName );
383
384 shape->SetShape( path );
385 path->SetAperture( 2.0 * radius );
386 }
387
388 id.m_family = "Oval";
389 dims << IU2um( padSize.x ) << "x" << IU2um( padSize.y ) << "_um";
390 break;
391 }
392
394 {
395 double dx = scale( padSize.x ) / 2.0;
396 double dy = scale( padSize.y ) / 2.0;
397
398 const VECTOR2I& delta = aPad->GetDelta( aPadLayer );
399
400 double ddx = scale( delta.x ) / 2.0;
401 double ddy = scale( delta.y ) / 2.0;
402
403 // see class_pad_draw_functions.cpp which draws the trapezoid pad
404 POINT lowerLeft( -dx - ddy, -dy - ddx );
405 POINT upperLeft( -dx + ddy, +dy + ddx );
406 POINT upperRight( +dx - ddy, +dy - ddx );
407 POINT lowerRight( +dx + ddy, -dy + ddx );
408
409 lowerLeft += dsnOffset;
410 upperLeft += dsnOffset;
411 upperRight += dsnOffset;
412 lowerRight += dsnOffset;
413
414 for( const std::string& layerName : aLayerNames )
415 {
416 SHAPE* shape = new SHAPE( aPadstack );
417
418 aPadstack->Append( shape );
419
420 // a T_polygon exists as a PATH
421 PATH* polygon = new PATH( shape, T_polygon );
422
423 shape->SetShape( polygon );
424
425 polygon->SetLayerId( layerName );
426
427 polygon->AppendPoint( lowerLeft );
428 polygon->AppendPoint( upperLeft );
429 polygon->AppendPoint( upperRight );
430 polygon->AppendPoint( lowerRight );
431 }
432
433 id.m_family = "Trapz";
434 dims << IU2um( padSize.x ) << "x" << IU2um( padSize.y ) << "_"
435 << ( delta.x < 0 ? "n" : "p" ) << std::abs( IU2um( delta.x ) ) << "x"
436 << ( delta.y < 0 ? "n" : "p" ) << std::abs( IU2um( delta.y ) ) << "_um";
437 break;
438 }
439
442 {
443 // Export the shape as as polygon, round rect does not exist as primitive
444 int rradius = aPad->GetRoundRectCornerRadius( aPadLayer );
445 SHAPE_POLY_SET cornerBuffer;
446 bool doChamfer = aPad->GetShape( aPadLayer ) == PAD_SHAPE::CHAMFERED_RECT;
447
448 TransformRoundChamferedRectToPolygon( cornerBuffer, VECTOR2I( 0, 0 ), padSize, ANGLE_0, rradius,
449 aPad->GetChamferRectRatio( aPadLayer ),
450 doChamfer ? aPad->GetChamferPositions( aPadLayer ) : 0,
451 0, aPad->GetMaxError(), ERROR_OUTSIDE );
452
453 SHAPE_LINE_CHAIN& polygonal_shape = cornerBuffer.Outline( 0 );
454
455 for( const std::string& layerName : aLayerNames )
456 {
457 SHAPE* shape = new SHAPE( aPadstack );
458
459 aPadstack->Append( shape );
460
461 // a T_polygon exists as a PATH
462 PATH* polygon = new PATH( shape, T_polygon );
463
464 shape->SetShape( polygon );
465
466 polygon->SetLayerId( layerName );
467
468 // append a closed polygon
469 POINT first_corner;
470
471 for( int idx = 0; idx < polygonal_shape.PointCount(); idx++ )
472 {
473 POINT corner( scale( polygonal_shape.CPoint( idx ).x ), scale( -polygonal_shape.CPoint( idx ).y ) );
474 corner += dsnOffset;
475 polygon->AppendPoint( corner );
476
477 if( idx == 0 )
478 first_corner = corner;
479 }
480
481 polygon->AppendPoint( first_corner ); // Close polygon
482 }
483
484 id.m_family = "RoundRect";
485 dims << IU2um( padSize.x ) << 'x'
486 << IU2um( padSize.y ) << '_'
487 << IU2um( rradius ) << "_um_"
488 << ( doChamfer ? aPad->GetChamferRectRatio( aPadLayer ) : 0.0 ) << '_'
489 << std::hex << std::uppercase
490 << ( doChamfer ? aPad->GetChamferPositions( aPadLayer ) : 0 );
491 break;
492 }
493
495 {
496 std::vector<VECTOR2I> polygonal_shape;
497 SHAPE_POLY_SET pad_shape;
498 aPad->MergePrimitivesAsPolygon( aPadLayer, &pad_shape );
499
500#ifdef EXPORT_CUSTOM_PADS_CONVEX_HULL
501 BuildConvexHull( polygonal_shape, pad_shape );
502#else
503 const SHAPE_LINE_CHAIN& p_outline = pad_shape.COutline( 0 );
504
505 for( int ii = 0; ii < p_outline.PointCount(); ++ii )
506 polygonal_shape.push_back( wxPoint( p_outline.CPoint( ii ) ) );
507#endif
508
509 // The polygon must be closed
510 if( polygonal_shape.front() != polygonal_shape.back() )
511 polygonal_shape.push_back( polygonal_shape.front() );
512
513 for( const std::string& layerName : aLayerNames )
514 {
515 SHAPE* shape = new SHAPE( aPadstack );
516
517 aPadstack->Append( shape );
518
519 // a T_polygon exists as a PATH
520 PATH* polygon = new PATH( shape, T_polygon );
521
522 shape->SetShape( polygon );
523
524 polygon->SetLayerId( layerName );
525
526 for( const VECTOR2I& pt : polygonal_shape )
527 {
528 POINT corner( scale( pt.x ), scale( -pt.y ) );
529 corner += dsnOffset;
530 polygon->AppendPoint( corner );
531 }
532 }
533
534 const HASH_128 hash = pad_shape.GetHash();
535 const BOX2I rect = aPad->GetBoundingBox();
536
537 id.m_family = "Cust";
538 dims << IU2um( padSize.x ) << 'x' << IU2um( padSize.y ) << '_'
539 << IU2um( rect.GetWidth() ) << 'x' << IU2um( rect.GetHeight() ) << '_'
540 << polygonal_shape.size() << "_um_"
541 << hash.ToString();
542 break;
543 }
544 }
545
546 id.m_dims = dims.str();
547
548 return id;
549}
550
551
553{
554 std::string uniqifier;
555
556 // caller must do these checks before calling here.
557 wxASSERT( !isRoundKeepout( aPad ) );
558
559 PADSTACK* padstack = new PADSTACK();
560
561 uniqifier = '[';
562
563 const int copperCount = aBoard->GetCopperLayerCount();
564 const LSET all_cu = LSET::AllCuMask( copperCount );
565
566 // Board layers grouped by the padstack layer they resolve to, so one geometry build serves
567 // every layer that shares it
568 std::vector<std::pair<PCB_LAYER_ID, std::vector<std::string>>> layerGroups;
569
570 bool onAllCopperLayers = ( (aPad->GetLayerSet() & all_cu) == all_cu );
571
572 if( onAllCopperLayers )
573 uniqifier += 'A'; // A for all layers
574
575 for( int layer=0; layer < copperCount; ++layer )
576 {
577 PCB_LAYER_ID kilayer = m_pcbLayer2kicad[layer];
578
579 if( onAllCopperLayers || aPad->IsOnLayer( kilayer ) )
580 {
581 PCB_LAYER_ID padLayer = aPad->Padstack().EffectiveLayerFor( kilayer );
582 auto group = std::find_if( layerGroups.begin(), layerGroups.end(),
583 [&]( const auto& aGroup )
584 {
585 return aGroup.first == padLayer;
586 } );
587
588 if( group == layerGroups.end() )
589 layerGroups.emplace_back( padLayer, std::vector<std::string>{ m_layerIds[layer] } );
590 else
591 group->second.push_back( m_layerIds[layer] );
592
593 if( !onAllCopperLayers )
594 {
595 if( layer == 0 )
596 uniqifier += 'T';
597 else if( layer == copperCount - 1 )
598 uniqifier += 'B';
599 else
600 uniqifier += fmt::format( "0{}", layer );
601 }
602 }
603 }
604
605 uniqifier += ']';
606
607 if( layerGroups.empty() )
608 {
609 padstack->SetPadstackId( ( "Empty" + uniqifier + "Pad" ).c_str() );
610 return padstack;
611 }
612
613 // Every Specctra shape carries its own layer id, so emit each group's geometry in turn
614 std::vector<SPECCTRA_SHAPE_ID> shapeIds;
615
616 for( const auto& [padLayer, names] : layerGroups )
617 shapeIds.push_back( appendPadstackShape( padstack, aPad, padLayer, names ) );
618
619 bool uniform = std::all_of( shapeIds.begin(), shapeIds.end(),
620 [&]( const SPECCTRA_SHAPE_ID& aId )
621 {
622 return aId == shapeIds.front();
623 } );
624
625 // This string _must_ be unique for a given physical shape
626 std::ostringstream oss;
627
628 if( uniform )
629 {
630 oss << shapeIds.front().m_family << uniqifier << shapeIds.front().m_offset << "Pad_"
631 << shapeIds.front().m_dims;
632 }
633 else
634 {
635 // Spelling out every layer grows the id without bound on a deep stackup, so fold the
636 // layers past the first into a digest
637 MMH3_HASH hash( 0 );
638
639 for( size_t ndx = 0; ndx < shapeIds.size(); ++ndx )
640 {
641 for( const std::string& name : layerGroups[ndx].second )
642 hash.add( name );
643
644 hash.add( shapeIds[ndx].m_family );
645 hash.add( shapeIds[ndx].m_offset );
646 hash.add( shapeIds[ndx].m_dims );
647 }
648
649 oss << "Complex" << uniqifier << shapeIds.front().m_offset << "Pad_"
650 << shapeIds.front().m_family << '_' << shapeIds.front().m_dims << '_'
651 << hash.digest().ToString();
652 }
653
654 padstack->SetPadstackId( oss.str().c_str() );
655
656 return padstack;
657}
658
659
661typedef std::map<wxString, int> PINMAP;
662
663
665{
666 PINMAP pinmap;
667 wxString padNumber;
668
669 PCB_TYPE_COLLECTOR fpItems;
670
671 // get all the FOOTPRINT's pads.
672 fpItems.Collect( aFootprint, { PCB_PAD_T } );
673
674 IMAGE* image = new IMAGE( nullptr );
675
676 image->m_image_id = aFootprint->GetFPID().Format().c_str();
677
678 // from the pads, and make an IMAGE using collated padstacks.
679 for( int p = 0; p < fpItems.GetCount(); ++p )
680 {
681 PAD* pad = (PAD*) fpItems[p];
682
683 // see if this pad is a through hole with no copper on its perimeter
684 if( isRoundKeepout( pad ) )
685 {
686 double diameter = scale( pad->GetDrillSize().x );
687 POINT vertex = mapPt( pad->GetFPRelativePosition() );
688
689 diameter += scale( aBoard->GetDesignSettings().m_HoleClearance * 2 );
690
691 int layerCount = aBoard->GetCopperLayerCount();
692
693 for( int layer=0; layer<layerCount; ++layer )
694 {
695 KEEPOUT* keepout = new KEEPOUT( image, T_keepout );
696
697 image->m_keepouts.push_back( keepout );
698
699 CIRCLE* circle = new CIRCLE( keepout );
700
701 keepout->SetShape( circle );
702
703 circle->SetDiameter( diameter );
704 circle->SetVertex( vertex );
705 circle->SetLayerId( m_layerIds[layer] );
706 }
707 }
708 else // else if() could there be a square keepout here?
709 {
710 // Pads not on copper layers (i.e. only on tech layers) are ignored
711 // because they create invalid pads in .dsn file for freeroute
712 LSET mask_copper_layers = pad->GetLayerSet() & LSET::AllCuMask();
713
714 if( !mask_copper_layers.any() )
715 continue;
716
717 PADSTACK* padstack = makePADSTACK( aBoard, pad );
718 auto iter = m_padstackset.find( *padstack );
719
720 if( iter != m_padstackset.end() )
721 {
722 // padstack is a duplicate, delete it and use the original
723 delete padstack;
724 padstack = (PADSTACK*) *iter.base(); // folklore, be careful here
725 }
726 else
727 {
728 m_padstackset.insert( padstack );
729 }
730
731 PIN* pin = new PIN( image );
732
733 padNumber = pad->GetNumber();
734 pin->m_pin_id = TO_UTF8( padNumber );
735
736 if( padNumber != wxEmptyString && pinmap.find( padNumber ) == pinmap.end() )
737 {
738 pinmap[ padNumber ] = 0;
739 }
740 else // pad name is a duplicate within this footprint
741 {
742 int duplicates = ++pinmap[ padNumber ];
743
744 pin->m_pin_id +=
745 "@" + std::to_string( duplicates ); // append "@1" or "@2", etc. to pin name
746 }
747
748 pin->m_kiNetCode = pad->GetNetCode();
749
750 image->m_pins.push_back( pin );
751
752 pin->m_padstack_id = padstack->m_padstack_id;
753
754 EDA_ANGLE angle = pad->GetOrientation() - aFootprint->GetOrientation();
755 pin->SetRotation( angle.Normalize().AsDegrees() );
756
757 VECTOR2I pos( pad->GetFPRelativePosition() );
758
759 pin->SetVertex( mapPt( pos ) );
760 }
761 }
762
763 SHAPE_POLY_SET crtYd = aFootprint->GetCourtyard( F_CrtYd );
764 crtYd.Append( aFootprint->GetCourtyard( B_CrtYd ) );
765 crtYd.Simplify();
766
767 // Specctra only supports the first outline, so add courtyard first
768 for( const SHAPE_POLY_SET::POLYGON& polygon : crtYd.CPolygons() )
769 {
770 for( const SHAPE_LINE_CHAIN& chain : polygon )
771 {
772 SHAPE* outline = new SHAPE( image, T_outline );
773 image->Append( outline );
774
775 PATH* path = new PATH( outline, T_polygon );
776
777 outline->SetShape( path );
778 path->SetAperture( 0 );
779 path->SetLayerId( "signal" );
780
781 for( int ii = 0; ii < chain.PointCount(); ++ii )
782 {
783 VECTOR2I corner( chain.CPoint( ii ).x, chain.CPoint( ii ).y );
784 path->AppendPoint( mapPt( corner, aFootprint ) );
785 }
786 }
787 }
788
789 // get all the FOOTPRINT's SHAPEs and convert those to DSN outlines.
790 fpItems.Collect( aFootprint, { PCB_SHAPE_T } );
791
792 for( int i = 0; i < fpItems.GetCount(); ++i )
793 {
794 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( fpItems[i] );
795 SHAPE* outline;
796 PATH* path;
797
798 if( graphic->IsOnLayer( F_CrtYd ) || graphic->IsOnLayer( B_CrtYd ) )
799 continue; // Courtyard already handled above
800
801 switch( graphic->GetShape() )
802 {
803 case SHAPE_T::SEGMENT:
804 outline = new SHAPE( image, T_outline );
805
806 image->Append( outline );
807 path = new PATH( outline );
808
809 outline->SetShape( path );
810 path->SetAperture( scale( graphic->GetWidth() ) );
811 path->SetLayerId( "signal" );
812 path->AppendPoint( mapPt( graphic->GetStart(), aFootprint ) );
813 path->AppendPoint( mapPt( graphic->GetEnd(), aFootprint ) );
814 break;
815
816 case SHAPE_T::CIRCLE:
817 {
818 // this is best done by 4 QARC's but freerouter does not yet support QARCs.
819 // for now, support by using line segments.
820 outline = new SHAPE( image, T_outline );
821 image->Append( outline );
822
823 path = new PATH( outline );
824
825 outline->SetShape( path );
826 path->SetAperture( scale( graphic->GetWidth() ) );
827 path->SetLayerId( "signal" );
828
829 double radius = graphic->GetRadius();
830 VECTOR2I circle_centre = graphic->GetStart();
831
832 SHAPE_LINE_CHAIN polyline;
833 ConvertArcToPolyline( polyline, VECTOR2I( circle_centre ), radius, ANGLE_0, ANGLE_360,
835
836 for( int ii = 0; ii < polyline.PointCount(); ++ii )
837 {
838 VECTOR2I corner( polyline.CPoint( ii ).x, polyline.CPoint( ii ).y );
839 path->AppendPoint( mapPt( corner, aFootprint ) );
840 }
841
842 break;
843 }
844
846 {
847 outline = new SHAPE( image, T_outline );
848
849 image->Append( outline );
850 path = new PATH( outline );
851
852 outline->SetShape( path );
853 path->SetAperture( scale( graphic->GetWidth() ) );
854 path->SetLayerId( "signal" );
855 VECTOR2I corner = graphic->GetStart();
856 path->AppendPoint( mapPt( corner, aFootprint ) );
857
858 corner.x = graphic->GetEnd().x;
859 path->AppendPoint( mapPt( corner, aFootprint ) );
860
861 corner.y = graphic->GetEnd().y;
862 path->AppendPoint( mapPt( corner, aFootprint ) );
863
864 corner.x = graphic->GetStart().x;
865 path->AppendPoint( mapPt( corner, aFootprint ) );
866
867 corner = graphic->GetStart();
868 path->AppendPoint( mapPt( corner, aFootprint ) );
869 break;
870 }
871
872 case SHAPE_T::ARC:
873 {
874 // this is best done by QARC's but freerouter does not yet support QARCs.
875 // for now, support by using line segments.
876 // So we use a "polygon" (PATH) to create a approximate arc shape
877 // Note we can't use "path" with aperture width because FreeRouting converts it to a convex polygon
878 outline = new SHAPE( image, T_outline );
879
880 image->Append( outline );
881 path = new PATH( outline, T_polygon );
882
883 outline->SetShape( path );
884 path->SetAperture( 0 );
885 path->SetLayerId( "signal" );
886
887 SHAPE_POLY_SET polyBuffer;
888 graphic->TransformShapeToPolygon( polyBuffer, graphic->GetLayer(), 0, ARC_HIGH_DEF,
889 ERROR_INSIDE, false );
890
891 const SHAPE_LINE_CHAIN& poly = polyBuffer.COutline( 0 );
892
893 for( int ii = 0; ii < poly.PointCount(); ++ii )
894 {
895 VECTOR2I corner( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
896 path->AppendPoint( mapPt( corner, aFootprint ) );
897 }
898
899 break;
900 }
901
902 default:
903 continue;
904 }
905 }
906
907 for( ZONE* zone : aFootprint->Zones() )
908 {
909 if( !zone->GetIsRuleArea() )
910 continue;
911
912 // IMAGE object coordinates are relative to the IMAGE not absolute board coordinates.
913 SHAPE_POLY_SET boardOutline = zone->GetBoardOutline();
914
915 // keepout areas have a type. types are
916 // T_place_keepout, T_via_keepout, T_wire_keepout,
917 // T_bend_keepout, T_elongate_keepout, T_keepout.
918 // Pcbnew knows only T_keepout, T_via_keepout and T_wire_keepout
919 // Rule areas that allow tracks and vias mean nothing to the router
920 if( !zone->GetDoNotAllowVias() && !zone->GetDoNotAllowTracks() )
921 continue;
922
923 DSN_T keepout_type;
924
925 if( zone->GetDoNotAllowVias() && zone->GetDoNotAllowTracks() )
926 keepout_type = T_keepout;
927 else if( zone->GetDoNotAllowVias() )
928 keepout_type = T_via_keepout;
929 else
930 keepout_type = T_wire_keepout;
931
932 // Now, build keepout polygon on each copper layer where the zone
933 // keepout is living (keepout zones can live on many copper layers)
934 LSET layerset = zone->GetLayerSet() & LSET::AllCuMask( aBoard->GetCopperLayerCount() );
935
936 for( PCB_LAYER_ID layer : layerset.CuStack() )
937 {
938 KEEPOUT* keepout = new KEEPOUT( m_pcb->m_structure, keepout_type );
939 image->m_keepouts.push_back( keepout );
940
941 PATH* mainPolygon = new PATH( keepout, T_polygon );
942 keepout->SetShape( mainPolygon );
943
944 mainPolygon->layer_id = m_layerIds[ m_kicadLayer2pcb[ layer ] ];
945
946 // Handle the main outlines
948 bool is_first_point = true;
949 VECTOR2I startpoint;
950
951 for( iterator = boardOutline.IterateWithHoles(); iterator; iterator++ )
952 {
953 VECTOR2I point = aFootprint->GetTransform().InverseApply( VECTOR2I( iterator->x, iterator->y ) );
954
955 if( is_first_point )
956 {
957 startpoint = point;
958 is_first_point = false;
959 }
960
961 mainPolygon->AppendPoint( mapPt( point ) );
962
963 // this was the end of the main polygon
964 if( iterator.IsEndContour() )
965 {
966 mainPolygon->AppendPoint( mapPt( startpoint ) );
967 break;
968 }
969 }
970
971 WINDOW* window = nullptr;
972 PATH* cutout = nullptr;
973 bool isStartContour = true;
974
975 // handle the cutouts
976 for( iterator++; iterator; iterator++ )
977 {
978 if( isStartContour )
979 {
980 is_first_point = true;
981 window = new WINDOW( keepout );
982 keepout->AddWindow( window );
983
984 cutout = new PATH( window, T_polygon );
985
986 window->SetShape( cutout );
987
988 cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ layer ] ];
989 }
990
991 isStartContour = iterator.IsEndContour();
992
993 wxASSERT( window );
994 wxASSERT( cutout );
995
996 VECTOR2I point( iterator->x, iterator->y );
997
998 point -= aFootprint->GetPosition();
999
1000 if( is_first_point )
1001 {
1002 startpoint = point;
1003 is_first_point = false;
1004 }
1005
1006 cutout->AppendPoint( mapPt( point ) );
1007
1008 // Close the polygon
1009 if( iterator.IsEndContour() )
1010 cutout->AppendPoint( mapPt( startpoint ) );
1011 }
1012 }
1013 }
1014
1015 return image;
1016}
1017
1018
1019PADSTACK* SPECCTRA_DB::makeVia( int aCopperDiameter, int aDrillDiameter,
1020 int aTopLayer, int aBotLayer )
1021{
1022 char name[48];
1023 PADSTACK* padstack = new PADSTACK();
1024 double dsnDiameter = scale( aCopperDiameter );
1025
1026 for( int layer=aTopLayer; layer<=aBotLayer; ++layer )
1027 {
1028 SHAPE* shape = new SHAPE( padstack );
1029
1030 padstack->Append( shape );
1031
1032 CIRCLE* circle = new CIRCLE( shape );
1033
1034 shape->SetShape( circle );
1035
1036 circle->SetDiameter( dsnDiameter );
1037 circle->SetLayerId( m_layerIds[layer] );
1038 }
1039
1040 snprintf( name, sizeof( name ), "Via[%d-%d]_%.6g:%.6g_um",
1041 aTopLayer, aBotLayer, dsnDiameter,
1042 // encode the drill value into the name for later import
1043 IU2um( aDrillDiameter ) );
1044
1045 name[ sizeof(name) - 1 ] = 0;
1046 padstack->SetPadstackId( name );
1047
1048 return padstack;
1049}
1050
1051
1053{
1054 PCB_LAYER_ID topLayerNum;
1055 PCB_LAYER_ID botLayerNum;
1056
1057 aVia->LayerPair( &topLayerNum, &botLayerNum );
1058
1059 int topLayer = m_kicadLayer2pcb[topLayerNum];
1060 int botLayer = m_kicadLayer2pcb[botLayerNum];
1061
1062 if( topLayer > botLayer )
1063 std::swap( topLayer, botLayer );
1064
1065 if( aVia->Padstack().Mode() == ::PADSTACK::MODE::NORMAL )
1066 {
1067 return makeVia( aVia->GetWidth( ::PADSTACK::ALL_LAYERS ), aVia->GetDrillValue(), topLayer,
1068 botLayer );
1069 }
1070
1071 PADSTACK* padstack = new PADSTACK();
1072 std::ostringstream oss;
1073
1074 oss << "Via[" << topLayer << '-' << botLayer << ']' << std::fixed << std::setprecision( 6 );
1075
1076 for( int layer = topLayer; layer <= botLayer; ++layer )
1077 {
1078 ::PCB_LAYER_ID viaLayer = aVia->Padstack().EffectiveLayerFor( m_pcbLayer2kicad[layer] );
1079 double dsnDiameter = scale( aVia->GetWidth( viaLayer ) );
1080
1081 SHAPE* shape = new SHAPE( padstack );
1082
1083 padstack->Append( shape );
1084
1085 CIRCLE* circle = new CIRCLE( shape );
1086
1087 shape->SetShape( circle );
1088
1089 circle->SetDiameter( dsnDiameter );
1090 circle->SetLayerId( m_layerIds[layer] );
1091
1092 oss << '_' << dsnDiameter;
1093 }
1094
1095 // encode the drill value into the name for later import
1096 oss << ':' << IU2um( aVia->GetDrillValue() ) << "_um";
1097
1098 padstack->SetPadstackId( oss.str().c_str() );
1099
1100 return padstack;
1101}
1102
1103
1104void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary )
1105{
1106 for( int cnt = 0; cnt < m_brd_outlines.OutlineCount(); cnt++ ) // Should be one outline
1107 {
1108 PATH* path = new PATH( boundary );
1109 boundary->paths.push_back( path );
1110 path->layer_id = "pcb";
1111
1112 SHAPE_LINE_CHAIN& outline = m_brd_outlines.Outline( cnt );
1113
1114 for( int ii = 0; ii < outline.PointCount(); ii++ )
1115 {
1116 VECTOR2I pos( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
1117 path->AppendPoint( mapPt( pos ) );
1118 }
1119
1120 // Close polygon:
1121 VECTOR2I pos0( outline.CPoint( 0 ).x, outline.CPoint( 0 ).y );
1122 path->AppendPoint( mapPt( pos0 ) );
1123
1124 // Generate holes as keepout:
1125 for( int ii = 0; ii < m_brd_outlines.HoleCount( cnt ); ii++ )
1126 {
1127 // emit a signal layers keepout for every interior polygon left...
1128 KEEPOUT* keepout = new KEEPOUT( nullptr, T_keepout );
1129 PATH* poly_ko = new PATH( nullptr, T_polygon );
1130
1131 keepout->SetShape( poly_ko );
1132 poly_ko->SetLayerId( "signal" );
1133 m_pcb->m_structure->m_keepouts.push_back( keepout );
1134
1135 SHAPE_LINE_CHAIN& hole = m_brd_outlines.Hole( cnt, ii );
1136
1137 for( int jj = 0; jj < hole.PointCount(); jj++ )
1138 {
1139 VECTOR2I pos( hole.CPoint( jj ).x, hole.CPoint( jj ).y );
1140 poly_ko->AppendPoint( mapPt( pos ) );
1141 }
1142
1143 // Close polygon:
1144 VECTOR2I pos( hole.CPoint( 0 ).x, hole.CPoint( 0 ).y );
1145 poly_ko->AppendPoint( mapPt( pos ) );
1146 }
1147 }
1148}
1149
1150
1151// Specctra strings have no in-string escape, so a payload holding the quote delimiter would end
1152// the token early and desync the reader. Only fold free-text fields that need no round-trip
1153static std::string sanitizeForDSNString( const wxString& aValue )
1154{
1155 wxString ret = aValue;
1156 ret.Replace( wxT( "\"" ), wxT( "''" ) );
1157 return TO_UTF8( ret );
1158}
1159
1160
1162{
1163 std::shared_ptr<NET_SETTINGS>& netSettings = aBoard->GetDesignSettings().m_NetSettings;
1164
1165 // Component ids must be unique for the session file to round-trip, but empty and duplicate
1166 // references (unannotated REF** fiducials, intentional duplicates) are common, so uniquify
1167 // rather than refuse the export. Exported DSN defaults to case-insensitive ids, so fold case
1168 // when checking for collisions.
1169 std::map<FOOTPRINT*, std::string> componentIds;
1170 {
1171 std::set<wxString> used;
1172
1173 for( FOOTPRINT* footprint : aBoard->Footprints() )
1174 {
1175 wxString ref = footprint->GetReference();
1176
1177 if( ref.IsEmpty() )
1178 ref = wxT( "REF**" );
1179
1180 wxString unique = ref;
1181
1182 for( int suffix = 1; !used.insert( unique.Lower() ).second; ++suffix )
1183 unique = wxString::Format( wxT( "%s_%d" ), ref, suffix );
1184
1185 componentIds[footprint] = TO_UTF8( unique );
1186 }
1187 }
1188
1189 if( !m_pcb )
1191
1192 //-----<layer_descriptor>-----------------------------------------------
1193 {
1194 // Specctra wants top physical layer first, then going down to the bottom most physical
1195 // layer in physical sequence.
1196
1197 buildLayerMaps( aBoard );
1198
1199 int layerCount = aBoard->GetCopperLayerCount();
1200
1201 for( int pcbNdx=0; pcbNdx<layerCount; ++pcbNdx )
1202 {
1203 LAYER* layer = new LAYER( m_pcb->m_structure );
1204
1205 m_pcb->m_structure->m_layers.push_back( layer );
1206
1207 layer->name = m_layerIds[pcbNdx];
1208
1209 DSN_T layerType;
1210
1211 switch( aBoard->GetLayerType( m_pcbLayer2kicad[pcbNdx] ) )
1212 {
1213 default:
1214 case LT_SIGNAL: layerType = T_signal; break;
1215 case LT_POWER: layerType = T_power; break;
1216
1217 // Freerouter does not support type "mixed", only signal and power.
1218 // Remap "mixed" to "signal".
1219 case LT_MIXED: layerType = T_signal; break;
1220 case LT_JUMPER: layerType = T_jumper; break;
1221 }
1222
1223 layer->layer_type = layerType;
1224
1225 layer->properties.push_back( PROPERTY() );
1226 PROPERTY* property = &layer->properties.back();
1227 property->name = "index";
1228 property->value = std::to_string( pcbNdx );
1229 }
1230 }
1231
1232 // a space in a quoted token is NOT a terminator, true establishes this.
1233 m_pcb->m_parser->space_in_quoted_tokens = true;
1234
1235 //-----<unit_descriptor> & <resolution_descriptor>--------------------
1236 {
1237 // Tell freerouter to use "tenths of micrometers", which is 100 nm resolution. Possibly
1238 // more resolution is possible in freerouter, but it would need testing.
1239
1240 m_pcb->m_unit->units = T_um;
1241 m_pcb->m_resolution->units = T_um;
1242 m_pcb->m_resolution->value = 10; // tenths of a um
1243 }
1244
1245 //-----<boundary_descriptor>------------------------------------------
1246 {
1247 // Because fillBOUNDARY() can throw an exception, we link in an empty boundary so the
1248 // BOUNDARY does not get lost in the event of of an exception.
1249 BOUNDARY* boundary = new BOUNDARY( nullptr );
1250
1251 m_pcb->m_structure->SetBOUNDARY( boundary );
1252 fillBOUNDARY( aBoard, boundary );
1253 }
1254
1255 //-----<rules>--------------------------------------------------------
1256 {
1257 char rule[80];
1258 int defaultTrackWidth = netSettings->GetDefaultNetclass()->GetTrackWidth();
1259 int defaultClearance = netSettings->GetDefaultNetclass()->GetClearance();
1260 double clearance = scale( defaultClearance );
1261
1262 std::vector<std::string>& rules = m_pcb->m_structure->m_rules->m_rules;
1263
1264 std::snprintf( rule, sizeof( rule ), "(width %.6g)", scale( defaultTrackWidth ) );
1265 rules.push_back( rule );
1266
1267 std::snprintf( rule, sizeof( rule ), "(clearance %.6g)", clearance );
1268 rules.push_back( rule );
1269
1270 // Pad to pad spacing on a single SMT part can be closer than our clearance. We don't want
1271 // freerouter complaining about that, so output a significantly smaller pad to pad
1272 // clearance to freerouter.
1273 clearance = scale( defaultClearance ) / 4;
1274
1275 std::snprintf( rule, sizeof( rule ), "(clearance %.6g (type smd_smd))", clearance );
1276 rules.push_back( rule );
1277 }
1278
1279 //-----<zones (not keepout areas) become wiring polygons>-----------------------
1280 // Specctra treats (plane ...) as pins; export copper zones as (wire (polygon ...))
1281 // instead. Top-level polygon = fractured zone outline; windows = outline − fill.
1282 {
1283 int netlessZones = 0;
1284 WIRING* wiring = m_pcb->m_wiring;
1285
1286 auto appendClosedChain = [&]( PATH* aPath, const SHAPE_LINE_CHAIN& aChain )
1287 {
1288 if( aChain.PointCount() < 3 )
1289 return;
1290
1291 for( int v = 0; v < aChain.PointCount(); v++ )
1292 aPath->AppendPoint( mapPt( aChain.CPoint( v ) ) );
1293
1294 aPath->AppendPoint( mapPt( aChain.CPoint( 0 ) ) );
1295 };
1296
1297 for( ZONE* zone : aBoard->Zones() )
1298 {
1299 if( zone->GetIsRuleArea() || !zone->IsOnCopperLayer() )
1300 continue;
1301
1302 const SHAPE_POLY_SET* zoneOutline = zone->Outline();
1303 wxCHECK2( zoneOutline && zoneOutline->OutlineCount() > 0, continue );
1304
1305 // Fracture the zone outline with potential cutouts to fit as top-level wire polygon.
1306 SHAPE_POLY_SET zoneOutlineFractured( *zoneOutline );
1307 zoneOutlineFractured.Fracture();
1308 wxCHECK2( zoneOutlineFractured.OutlineCount() == 1, continue );
1309
1310 if( zoneOutlineFractured.FullPointCount() < 3 )
1311 continue;
1312
1313 std::string netId = zone->GetNetname().utf8_string();
1314
1315 if( netId.empty() )
1316 {
1317 NET* no_net = new NET( m_pcb->m_network );
1318 no_net->m_net_id = "@:no_net_" + std::to_string( netlessZones++ );
1319 m_pcb->m_network->m_nets.push_back( no_net );
1320 netId = no_net->m_net_id;
1321 }
1322
1323 LSET layerset = zone->GetLayerSet() & LSET::AllCuMask( aBoard->GetCopperLayerCount() );
1324
1325 for( PCB_LAYER_ID layer : layerset )
1326 {
1327 const std::string& layerId = m_layerIds[m_kicadLayer2pcb[layer]];
1328
1329 WIRE* wire = new WIRE( wiring );
1330 wiring->wires.push_back( wire );
1331 wire->m_net_id = netId;
1332 wire->m_wire_type = T_protect;
1333
1334 PATH* mainPolygon = new PATH( wire, T_polygon );
1335 wire->SetShape( mainPolygon );
1336 mainPolygon->layer_id = layerId;
1337 appendClosedChain( mainPolygon, zoneOutlineFractured.COutline( 0 ) );
1338
1339 SHAPE_POLY_SET* zoneFill = zone->GetFill( layer );
1340
1341 if( !zoneFill || zoneFill->IsEmpty() )
1342 continue;
1343
1344 SHAPE_POLY_SET fill( *zoneFill );
1345 fill.Unfracture();
1346
1347 SHAPE_POLY_SET cutouts( *zoneOutline );
1348 cutouts.BooleanSubtract( fill );
1349
1350 for( int c = 0; c < cutouts.OutlineCount(); c++ )
1351 {
1352 const SHAPE_LINE_CHAIN& hole = cutouts.COutline( c );
1353
1354 if( hole.PointCount() < 3 )
1355 continue;
1356
1357 WINDOW* window = new WINDOW( wire );
1358 wire->AddWindow( window );
1359
1360 PATH* cutout = new PATH( window, T_polygon );
1361 window->SetShape( cutout );
1362 cutout->layer_id = layerId;
1363 appendClosedChain( cutout, hole );
1364 }
1365 }
1366 }
1367 }
1368
1369 //-----<zones flagged keepout areas become keepout>--------------------------------
1370 {
1371 for( ZONE* zone : aBoard->Zones() )
1372 {
1373 if( !zone->GetIsRuleArea() )
1374 continue;
1375
1376 // Keepout areas have a type: T_place_keepout, T_via_keepout, T_wire_keepout,
1377 // T_bend_keepout, T_elongate_keepout, T_keepout.
1378 // Pcbnew knows only T_keepout, T_via_keepout and T_wire_keepout
1379 // Rule areas that allow tracks and vias mean nothing to the router
1380 if( !zone->GetDoNotAllowVias() && !zone->GetDoNotAllowTracks() )
1381 continue;
1382
1383 DSN_T keepout_type;
1384
1385 if( zone->GetDoNotAllowVias() && zone->GetDoNotAllowTracks() )
1386 keepout_type = T_keepout;
1387 else if( zone->GetDoNotAllowVias() )
1388 keepout_type = T_via_keepout;
1389 else
1390 keepout_type = T_wire_keepout;
1391
1392 // Now, build keepout polygon on each copper layer where the zone
1393 // keepout is living (keepout zones can live on many copper layers)
1394 LSET layerset = zone->GetLayerSet() & LSET::AllCuMask( aBoard->GetCopperLayerCount() );
1395
1396 for( PCB_LAYER_ID layer : layerset )
1397 {
1398 KEEPOUT* keepout = new KEEPOUT( m_pcb->m_structure, keepout_type );
1399 m_pcb->m_structure->m_keepouts.push_back( keepout );
1400
1401 PATH* mainPolygon = new PATH( keepout, T_polygon );
1402 keepout->SetShape( mainPolygon );
1403
1404 mainPolygon->layer_id = m_layerIds[ m_kicadLayer2pcb[ layer ] ];
1405
1406 // Handle the main outlines
1407 SHAPE_POLY_SET::ITERATOR iterator;
1408 bool is_first_point = true;
1409 VECTOR2I startpoint;
1410
1411 for( iterator = zone->IterateWithHoles(); iterator; iterator++ )
1412 {
1413 VECTOR2I point( iterator->x, iterator->y );
1414
1415 if( is_first_point )
1416 {
1417 startpoint = point;
1418 is_first_point = false;
1419 }
1420
1421 mainPolygon->AppendPoint( mapPt( point ) );
1422
1423 // this was the end of the main polygon
1424 if( iterator.IsEndContour() )
1425 {
1426 mainPolygon->AppendPoint( mapPt( startpoint ) );
1427 break;
1428 }
1429 }
1430
1431 WINDOW* window = nullptr;
1432 PATH* cutout = nullptr;
1433
1434 bool isStartContour = true;
1435
1436 // handle the cutouts
1437 for( iterator++; iterator; iterator++ )
1438 {
1439 if( isStartContour )
1440 {
1441 is_first_point = true;
1442 window = new WINDOW( keepout );
1443 keepout->AddWindow( window );
1444
1445 cutout = new PATH( window, T_polygon );
1446 window->SetShape( cutout );
1447 cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ layer ] ];
1448 }
1449
1450 isStartContour = iterator.IsEndContour();
1451
1452 wxASSERT( window );
1453 wxASSERT( cutout );
1454
1455 VECTOR2I point( iterator->x, iterator->y );
1456
1457 if( is_first_point )
1458 {
1459 startpoint = point;
1460 is_first_point = false;
1461 }
1462
1463 cutout->AppendPoint( mapPt(point) );
1464
1465 // Close the polygon
1466 if( iterator.IsEndContour() )
1467 cutout->AppendPoint( mapPt( startpoint ) );
1468 }
1469 }
1470 }
1471 }
1472
1473 //-----<build the images, components, and netlist>-----------------------
1474 {
1475 PIN_REF empty( m_pcb->m_network );
1476 std::string componentId;
1477 int highestNetCode = 0;
1478 const NETINFO_LIST& netInfo = aBoard->GetNetInfo();
1479
1480 // find the highest numbered netCode within the board.
1481 for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
1482 highestNetCode = std::max( highestNetCode, i->GetNetCode() );
1483
1484 deleteNETs();
1485
1486 // expand the net vector to highestNetCode+1, setting empty to NULL
1487 m_nets.resize( highestNetCode + 1, nullptr );
1488
1489 for( unsigned i = 1 /* skip "No Net" at [0] */; i < m_nets.size(); ++i )
1490 m_nets[i] = new NET( m_pcb->m_network );
1491
1492 for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
1493 {
1494 if( i->GetNetCode() > 0 )
1495 m_nets[i->GetNetCode()]->m_net_id = sanitizeForDSNString( i->GetNetname() );
1496 }
1497
1498 m_padstackset.clear();
1499
1500 for( FOOTPRINT* footprint : aBoard->Footprints() )
1501 {
1502 IMAGE* image = makeIMAGE( aBoard, footprint );
1503
1504 componentId = componentIds[footprint];
1505
1506 // Create a net list entry for all the actual pins in the current footprint.
1507 // Location of this code is critical because we fabricated some pin names to ensure
1508 // unique-ness within a footprint, and the life of this 'IMAGE* image' is not
1509 // necessarily long. The exported netlist will have some fabricated pin names in it.
1510 // If you don't like fabricated pin names, then make sure all pads within your
1511 // FOOTPRINTs are uniquely named!
1512 for( PIN& pin : image->m_pins )
1513 {
1514 int netcode = pin.m_kiNetCode;
1515
1516 if( netcode > 0 )
1517 {
1518 NET* net = m_nets[netcode];
1519
1520 net->m_pins.push_back( empty );
1521
1522 PIN_REF& pin_ref = net->m_pins.back();
1523
1524 pin_ref.component_id = componentId;
1525 pin_ref.pin_id = pin.m_pin_id;
1526 }
1527 }
1528
1529 IMAGE* registered = m_pcb->m_library->LookupIMAGE( image );
1530
1531 if( registered != image )
1532 {
1533 // If our new 'image' is not a unique IMAGE, delete it.
1534 // and use the registered one, known as 'image' after this.
1535 delete image;
1536 image = registered;
1537 }
1538
1539 COMPONENT* comp = m_pcb->m_placement->LookupCOMPONENT( image->GetImageId() );
1540 PLACE* place = new PLACE( comp );
1541
1542 comp->m_places.push_back( place );
1543
1544 place->SetRotation( footprint->GetOrientationDegrees() );
1545 place->SetVertex( mapPt( footprint->GetPosition() ) );
1546 place->m_component_id = componentId;
1547 place->m_part_number = sanitizeForDSNString( footprint->GetValue() );
1548
1549 // footprint is flipped from bottom side, set side to T_back
1550 if( footprint->GetFlag() )
1551 {
1552 EDA_ANGLE angle = ANGLE_180 - footprint->GetOrientation();
1553 place->SetRotation( angle.Normalize().AsDegrees() );
1554
1555 place->m_side = T_back;
1556 }
1557 }
1558
1559 // copy the SPECCTRA_DB::padstackset to the LIBRARY. Since we are
1560 // removing, do not increment the iterator
1561 for( auto i = m_padstackset.begin(); i != m_padstackset.end(); i = m_padstackset.begin() )
1562 {
1563 boost::ptr_set<PADSTACK>::auto_type ps = m_padstackset.release( i );
1564 PADSTACK* padstack = ps.release();
1565
1566 m_pcb->m_library->AddPadstack( padstack );
1567 }
1568
1569 // copy our SPECCTRA_DB::nets to the pcb->network
1570 for( unsigned n = 1; n < m_nets.size(); ++n )
1571 {
1572 NET* net = m_nets[n];
1573
1574 if( net->m_pins.size() )
1575 {
1576 // give ownership to pcb->network
1577 m_pcb->m_network->m_nets.push_back( net );
1578 m_nets[n] = nullptr;
1579 }
1580 }
1581 }
1582
1583 // Create a list of all in-use non-default netclasses
1584 std::unordered_map<wxString, NETCLASS*> netclassesInUse;
1585
1586 for( NETINFO_ITEM* net : aBoard->GetNetInfo() )
1587 {
1588 NETCLASS* netclass = net->GetNetClass();
1589 const wxString& name = netclass->GetName();
1590
1591 // Don't add the default netclass
1592 if( name == NETCLASS::Default )
1593 continue;
1594
1595 if( !netclassesInUse.contains( name ) )
1596 netclassesInUse[name] = netclass;
1597 }
1598
1599 //-----< output vias used in netclasses >-----------------------------------
1600 {
1601 // Assume the netclass vias are all the same kind of thru, blind, or buried vias.
1602 // This is in lieu of either having each netclass via have its own layer pair in
1603 // the netclass dialog, or such control in the specctra export dialog.
1604
1605 m_top_via_layer = 0; // first specctra cu layer is number zero.
1607
1608 // Add the via from the Default netclass first. The via container
1609 // in pcb->library preserves the sequence of addition.
1610
1611 PADSTACK* via = makeVia( netSettings->GetDefaultNetclass()->GetViaDiameter(),
1612 netSettings->GetDefaultNetclass()->GetViaDrill(), m_top_via_layer,
1614
1615 // we AppendVia() this first one, there is no way it can be a duplicate,
1616 // the pcb->library via container is empty at this point. After this,
1617 // we'll have to use LookupVia().
1618 wxASSERT( m_pcb->m_library->m_vias.size() == 0 );
1619 m_pcb->m_library->AppendVia( via );
1620
1621 // set the "spare via" index at the start of the
1622 // pcb->library->spareViaIndex = pcb->library->vias.size();
1623
1624 // output the non-Default netclass vias
1625 for( const auto& [name, netclass] : netclassesInUse )
1626 {
1627 via = makeVia( netclass->GetViaDiameter(), netclass->GetViaDrill(), m_top_via_layer, m_bot_via_layer );
1628
1629 // maybe add 'via' to the library, but only if unique.
1630 PADSTACK* registered = m_pcb->m_library->LookupVia( via );
1631
1632 if( registered != via )
1633 delete via;
1634 }
1635 }
1636
1637 //-----<create the wires from tracks>-----------------------------------
1638 {
1639 // One Specctra wire per KiCad track/arc segment, always exactly two path points.
1640 // FreeRouting may have issues normalizing multi-point (polyline) wires
1641 // that share endpoints
1642 WIRING* wiring = m_pcb->m_wiring;
1643
1644 for( PCB_TRACK* track : aBoard->Tracks() )
1645 {
1646 if( !track->IsType( { PCB_TRACE_T, PCB_ARC_T } ) )
1647 continue;
1648
1649 int netcode = track->GetNetCode();
1650
1651 if( netcode == 0 )
1652 continue;
1653
1654 NETINFO_ITEM* net = aBoard->FindNet( netcode );
1655 wxASSERT( net );
1656
1657 WIRE* wire = new WIRE( wiring );
1658
1659 wiring->wires.push_back( wire );
1660 wire->m_net_id = TO_UTF8( net->GetNetname() );
1661
1662 if( track->IsLocked() )
1663 wire->m_wire_type = T_fix; // tracks with fix property are not returned in .ses files
1664 else
1665 wire->m_wire_type = T_protect;
1666
1667 PCB_LAYER_ID kiLayer = track->GetLayer();
1668 int pcbLayer = m_kicadLayer2pcb[kiLayer];
1669
1670 PATH* path = new PATH( wire );
1671 wire->SetShape( path );
1672 path->layer_id = m_layerIds[pcbLayer];
1673 path->aperture_width = scale( track->GetWidth() );
1674 path->AppendPoint( mapPt( track->GetStart() ) );
1675 path->AppendPoint( mapPt( track->GetEnd() ) );
1676 }
1677 }
1678
1679 //-----<export the existing real BOARD instantiated vias>-----------------
1680 {
1681 // Export all vias, once per unique size and drill diameter combo.
1682 for( PCB_TRACK* track : aBoard->Tracks() )
1683 {
1684 if( track->Type() != PCB_VIA_T )
1685 continue;
1686
1687 PCB_VIA* via = static_cast<PCB_VIA*>( track );
1688 int netcode = via->GetNetCode();
1689
1690 if( netcode == 0 )
1691 continue;
1692
1693 PADSTACK* padstack = makeVia( via );
1694 PADSTACK* registered = m_pcb->m_library->LookupVia( padstack );
1695
1696 // if the one looked up is not our padstack, then delete our padstack
1697 // since it was a duplicate of one already registered.
1698 if( padstack != registered )
1699 delete padstack;
1700
1701 WIRE_VIA* dsnVia = new WIRE_VIA( m_pcb->m_wiring );
1702
1703 m_pcb->m_wiring->wire_vias.push_back( dsnVia );
1704
1705 dsnVia->m_padstack_id = registered->m_padstack_id;
1706 dsnVia->m_vertexes.push_back( mapPt( via->GetPosition() ) );
1707
1708 NETINFO_ITEM* net = aBoard->FindNet( netcode );
1709 wxASSERT( net );
1710
1711 dsnVia->m_net_id = TO_UTF8( net->GetNetname() );
1712
1713 if( via->IsLocked() )
1714 dsnVia->m_via_type = T_fix; // vias with fix property are not returned in .ses files
1715 else
1716 dsnVia->m_via_type = T_protect;
1717 }
1718 }
1719
1720 //-----<via_descriptor>-------------------------------------------------
1721 {
1722 // The pcb->library will output <padstack_descriptors> which is a combined list of part
1723 // padstacks and via padstacks. specctra dsn uses the <via_descriptors> to say which of
1724 // those padstacks are vias.
1725
1726 // Output the vias in the padstack list here, by name only. This must be done after
1727 // exporting existing vias as WIRE_VIAs.
1728 VIA* vias = m_pcb->m_structure->m_via;
1729
1730 for( unsigned viaNdx = 0; viaNdx < m_pcb->m_library->m_vias.size(); ++viaNdx )
1731 vias->AppendVia( m_pcb->m_library->m_vias[viaNdx].m_padstack_id.c_str() );
1732 }
1733
1734 //-----<output NETCLASSs>----------------------------------------------------
1735
1736 // Export netclass info
1737 exportNETCLASS( netSettings->GetDefaultNetclass().get(), aBoard );
1738
1739 for( const auto& [name, netclass] : netclassesInUse )
1740 exportNETCLASS( netclass, aBoard );
1741}
1742
1743
1744void SPECCTRA_DB::exportNETCLASS( const NETCLASS* aNetClass, const BOARD* aBoard )
1745{
1746 /* From page 11 of specctra spec:
1747 *
1748 * Routing and Placement Rule Hierarchies
1749 *
1750 * Routing and placement rules can be defined at multiple levels of design
1751 * specification. When a routing or placement rule is defined for an object at
1752 * multiple levels, a predefined routing or placement precedence order
1753 * automatically determines which rule to apply to the object. The routing rule
1754 * precedence order is
1755 *
1756 * pcb < layer < class < class layer < group_set < group_set layer < net <
1757 * net layer < group < group layer < fromto < fromto layer < class_class <
1758 * class_class layer < padstack < region < class region < net region <
1759 * class_class region
1760 *
1761 * A pcb rule (global rule for the PCB design) has the lowest precedence in the
1762 * hierarchy. A class-to-class region rule has the highest precedence. Rules
1763 * set at one level of the hierarchy override conflicting rules set at lower
1764 * levels. The placement rule precedence order is
1765 *
1766 * pcb < image_set < image < component < super cluster < room <
1767 * room_image_set < family_family < image_image
1768 *
1769 * A pcb rule (global rule for the PCB design) has the lowest precedence in the
1770 * hierarchy. An image-to-image rule has the highest precedence. Rules set at
1771 * one level of the hierarchy override conflicting rules set at lower levels.
1772 */
1773
1774 char text[256];
1775
1776 CLASS* clazz = new CLASS( m_pcb->m_network );
1777
1778 m_pcb->m_network->m_classes.push_back( clazz );
1779
1780 clazz->m_class_id = TO_UTF8( aNetClass->GetName() );
1781
1782 for( NETINFO_ITEM* net : aBoard->GetNetInfo() )
1783 {
1784 if( net->GetNetClass()->GetName() == clazz->m_class_id )
1785 clazz->m_net_ids.push_back( TO_UTF8( net->GetNetname() ) );
1786 }
1787
1788 clazz->m_rules = new RULE( clazz, T_rule );
1789
1790 // output the track width.
1791 if( aNetClass->HasTrackWidth() )
1792 {
1793 int trackWidth = aNetClass->GetTrackWidth();
1794 std::snprintf( text, sizeof( text ), "(width %.6g)", scale( trackWidth ) );
1795 clazz->m_rules->m_rules.push_back( text );
1796 }
1797
1798 // output the clearance.
1799 if( aNetClass->HasClearance() )
1800 {
1801 int clearance = aNetClass->GetClearance();
1802 std::snprintf( text, sizeof( text ), "(clearance %.6g)", scale( clearance ) );
1803 clazz->m_rules->m_rules.push_back( text );
1804 }
1805
1806 // Freerouter creates a class named 'default' anyway, and if we try to use that we end up
1807 // with two 'default' via rules so use something else as the name of our default class.
1808 if( aNetClass->GetName() == NETCLASS::Default )
1809 clazz->m_class_id = "kicad_default";
1810
1811 // The easiest way to get the via name is to create a temporary via (which generates the
1812 // name internal to the PADSTACK), and then grab the name and delete the via. There are not
1813 // that many netclasses so this should never become a performance issue.
1814
1815 PADSTACK* via = makeVia( aNetClass->GetViaDiameter(), aNetClass->GetViaDrill(),
1817
1818 snprintf( text, sizeof( text ), "(use_via \"%s\")", via->GetPadstackId().c_str() );
1819 clazz->m_circuit.push_back( text );
1820
1821 delete via;
1822}
1823
1824
1826{
1827 // DSN Images (=KiCad FOOTPRINTs and PADs) must be presented from the top view.
1828 // Note: to export footprints, the footprints must be flipped around the X axis, otherwise
1829 // the rotation angle is not good.
1830 for( FOOTPRINT* footprint : aBoard->Footprints() )
1831 {
1832 footprint->SetFlag( 0 );
1833
1834 if( footprint->GetLayer() == B_Cu )
1835 {
1836 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
1837 footprint->SetFlag( 1 );
1838 }
1839 }
1840
1842}
1843
1844
1846{
1848 return;
1849
1850 // DSN Images (=KiCad FOOTPRINTs and PADs) must be presented from the
1851 // top view. Restore those that were flipped.
1852 // Note: to export footprints, the footprints were flipped around the X axis,
1853 for( FOOTPRINT* footprint : aBoard->Footprints() )
1854 {
1855 if( footprint->GetFlag() )
1856 {
1857 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
1858 footprint->SetFlag( 0 );
1859 }
1860 }
1861
1862 m_footprintsAreFlipped = false;
1863}
1864
1865} // namespace DSN
const char * name
@ ERROR_OUTSIDE
@ ERROR_INSIDE
constexpr int ARC_HIGH_DEF
Definition base_units.h:144
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ LT_POWER
Definition board.h:246
@ LT_MIXED
Definition board.h:247
@ LT_JUMPER
Definition board.h:248
@ LT_SIGNAL
Definition board.h:245
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:37
bool IsContentModified() const
Definition base_screen.h:56
void SetContentModified(bool aModified=true)
Definition base_screen.h:55
std::shared_ptr< NET_SETTINGS > m_NetSettings
int GetMaxError() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
const ZONES & Zones() const
Definition board.h:469
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition board.cpp:1019
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition board.cpp:3268
int GetCopperLayerCount() const
Definition board.cpp:1155
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, bool aInferOutlineIfNecessary, 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:3651
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
The <class_descriptor> in the specctra spec.
Definition specctra.h:2725
std::vector< std::string > m_circuit
circuit descriptor list
Definition specctra.h:2804
std::string m_class_id
Definition specctra.h:2800
RULE * m_rules
Definition specctra.h:2806
std::vector< std::string > m_net_ids
Definition specctra.h:2801
Implement a <component_descriptor> in the specctra dsn spec.
Definition specctra.h:1770
void Append(ELEM *aElem)
Definition specctra.h:340
Used for <keepout_descriptor> and <plane_descriptor>.
Definition specctra.h:916
void AddWindow(WINDOW *aWindow)
Definition specctra.h:957
void SetShape(ELEM *aShape)
Definition specctra.h:940
PROPERTIES properties
Definition specctra.h:1295
DSN_T layer_type
one of: T_signal, T_power, T_mixed, T_jumper
Definition specctra.h:1286
std::string name
Definition specctra.h:1285
A <net_descriptor> in the DSN spec.
Definition specctra.h:2575
std::vector< PIN_REF > m_pins
Definition specctra.h:2678
std::string m_net_id
Definition specctra.h:2673
Hold either a via or a pad definition.
Definition specctra.h:2113
std::string m_padstack_id
Definition specctra.h:2212
void SetPadstackId(const char *aPadstackId)
Definition specctra.h:2146
Support both the <path_descriptor> and the <polygon_descriptor> per the specctra dsn spec.
Definition specctra.h:598
void SetLayerId(const std::string &aLayerId)
Definition specctra.h:615
void AppendPoint(const POINT &aPoint)
Definition specctra.h:608
std::string layer_id
Definition specctra.h:665
Implement a <placement_reference> in the specctra dsn spec.
Definition specctra.h:1692
void SetVertex(const POINT &aVertex)
Definition specctra.h:1720
void SetRotation(double aRotation)
Definition specctra.h:1727
DSN_T m_side
Definition specctra.h:1739
std::string m_part_number
Definition specctra.h:1762
std::string m_component_id
reference designator
Definition specctra.h:1737
std::vector< std::string > m_rules
rules are saved in std::string form.
Definition specctra.h:548
A "(shape ..)" element in the specctra dsn spec.
Definition specctra.h:1891
A DSN data tree, usually coming from a DSN file.
Definition specctra.h:3621
int m_top_via_layer
specctra cu layers, 0 based index:
Definition specctra.h:4003
IMAGE * makeIMAGE(BOARD *aBoard, FOOTPRINT *aFootprint)
Allocates an I#MAGE on the heap and creates all the PINs according to the PADs in the FOOTPRINT.
void buildLayerMaps(BOARD *aBoard)
Create a few data translation structures for layer name and number mapping between the DSN::PCB struc...
Definition specctra.cpp:73
std::map< int, PCB_LAYER_ID > m_pcbLayer2kicad
maps PCB layer number to BOARD layer numbers
Definition specctra.h:3984
void ExportPCB(const wxString &aFilename, bool aNameChange=false)
Write the internal PCB instance out as a SPECTRA DSN format file.
SHAPE_POLY_SET m_brd_outlines
Definition specctra.h:3970
void FlipFOOTPRINTs(BOARD *aBoard)
Flip the footprints which are on the back side of the board to the front.
bool m_footprintsAreFlipped
Definition specctra.h:3977
void deleteNETs()
Delete all the NETs that may be in here.
Definition specctra.h:3930
void fillBOUNDARY(BOARD *aBoard, BOUNDARY *aBoundary)
Make the board perimeter for the DSN file by filling the BOUNDARY element in the specctra element tre...
PADSTACK * makePADSTACK(BOARD *aBoard, PAD *aPad)
Create a PADSTACK which matches the given pad.
void SetPCB(PCB *aPcb)
Delete any existing PCB and replaces it with the given one.
Definition specctra.h:3666
std::vector< std::string > m_layerIds
indexed by PCB layer number
Definition specctra.h:3981
static PCB * MakePCB()
Make a PCB with all the default ELEMs and parts on the heap.
bool BuiltBoardOutlines(BOARD *aBoard)
Build the board outlines and store it in m_brd_outlines.
void exportNETCLASS(const NETCLASS *aNetClass, const BOARD *aBoard)
Export aNetClass to the DSN file.
PADSTACK * makeVia(int aCopperDiameter, int aDrillDiameter, int aTopLayer, int aBotLayer)
Make a round through hole PADSTACK using the given KiCad diameter in deci-mils.
boost::ptr_set< PADSTACK > m_padstackset
Definition specctra.h:3997
std::map< PCB_LAYER_ID, int > m_kicadLayer2pcb
maps BOARD layer number to PCB layer numbers
Definition specctra.h:3983
std::vector< NET * > m_nets
we don't want ownership here permanently, so we don't use boost::ptr_vector
Definition specctra.h:4000
void FromBOARD(BOARD *aBoard)
Add the entire BOARD to the PCB but does not write it out.
void RevertFOOTPRINTs(BOARD *aBoard)
Flip the footprints which were on the back side of the board back to the back.
A <via_descriptor> in the specctra dsn spec.
Definition specctra.h:1047
void AppendVia(const char *aViaName)
Definition specctra.h:1055
void SetShape(ELEM *aShape)
Definition specctra.h:870
A <wire_via_descriptor> in the specctra dsn spec.
Definition specctra.h:2968
std::string m_net_id
Definition specctra.h:3097
std::string m_padstack_id
Definition specctra.h:3095
DSN_T m_via_type
Definition specctra.h:3099
std::vector< POINT > m_vertexes
Definition specctra.h:3096
A <wire_shape_descriptor> in the specctra dsn spec.
Definition specctra.h:2853
void AddWindow(WINDOW *aWindow)
Definition specctra.h:2888
DSN_T m_wire_type
Definition specctra.h:2955
void SetShape(ELEM *aShape)
Definition specctra.h:2873
std::string m_net_id
Definition specctra.h:2953
A <wiring_descriptor> in the specctra dsn spec.
Definition specctra.h:3111
boost::ptr_vector< WIRE > wires
Definition specctra.h:3148
EDA_ANGLE Normalize()
Definition eda_angle.h:228
double AsDegrees() const
Definition eda_angle.h:115
int GetRadius() const
SHAPE_T GetShape() const
Definition eda_shape.h:178
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
ZONES & Zones()
Definition footprint.h:361
const TRANSFORM_TRS & GetTransform() const
Definition footprint.h:395
const LIB_ID & GetFPID() const
Definition footprint.h:417
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
VECTOR2I GetPosition() const override
Definition footprint.h:379
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
UTF8 Format() const
Definition lib_id.cpp:132
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition lset.cpp:259
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
A streaming C++ equivalent for MurmurHash3_x64_128.
Definition mmh3_hash.h:61
FORCE_INLINE void add(const std::string &input)
Definition mmh3_hash.h:138
FORCE_INLINE HASH_128 digest()
Definition mmh3_hash.h:157
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
int GetViaDiameter() const
Definition netclass.h:158
int GetViaDrill() const
Definition netclass.h:166
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition netclass.cpp:382
bool HasTrackWidth() const
Definition netclass.h:149
int GetTrackWidth() const
Definition netclass.h:150
int GetClearance() const
Definition netclass.h:142
bool HasClearance() const
Definition netclass.h:141
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetname() const
Definition netinfo.h:110
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:306
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:232
iterator begin() const
Definition netinfo.h:351
iterator end() const
Definition netinfo.h:356
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:579
void MergePrimitivesAsPolygon(PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aMergedPolygon, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Merge all basic shapes to a SHAPE_POLY_SET.
Definition pad.cpp:3480
int GetRoundRectCornerRadius(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1053
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition pad.cpp:1545
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition pad.h:950
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
Definition pad.h:307
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
Definition pad.cpp:848
VECTOR2I GetDrillSize() const
Definition pad.h:320
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
const PADSTACK & Padstack() const
Definition pad.h:331
int GetChamferPositions(PCB_LAYER_ID aLayer) const
Definition pad.h:878
double GetChamferRectRatio(PCB_LAYER_ID aLayer) const
Definition pad.h:860
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
bool ExportSpecctraFile(const wxString &aFullFilename)
Export the current BOARD to a specctra dsn file.
int GetWidth() const override
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition collectors.h:518
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
const PADSTACK & Padstack() const
Definition pcb_track.h:435
int GetWidth() const override
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Return the 2 layers used by the via (the via actually uses all layers between these 2 layers)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
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.
HASH_128 GetHash() const
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR IterateWithHoles(int aOutline)
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
int FullPointCount() const
Return the number of points in the shape poly set.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void Unfracture()
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const std::vector< POLYGON > & CPolygons() const
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
const char * c_str() const
Definition utf8.h:104
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
int ConvertArcToPolyline(SHAPE_LINE_CHAIN &aPolyline, VECTOR2I aCenter, int aRadius, const EDA_ANGLE &aStartAngleDeg, const EDA_ANGLE &aArcAngleDeg, double aAccuracy, ERROR_LOC aErrorLoc)
Generate a polyline to approximate a arc.
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.
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
static bool registered
@ PLACE
Definition cursors.h:95
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
#define LAYER(n, l)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:478
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:476
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
a few functions useful in geometry calculations.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ B_Cu
Definition layer_ids.h:61
@ B_CrtYd
Definition layer_ids.h:111
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:28
This source file implements export and import capabilities to the specctra dsn file format.
Definition specctra.cpp:60
std::map< wxString, int > PINMAP
data type used to ensure unique-ness of pin names, holding (wxString and int)
static double mapX(int x)
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename, REPORTER *aReporter=nullptr)
Helper method to export board to DSN file.
static SPECCTRA_SHAPE_ID appendPadstackShape(PADSTACK *aPadstack, PAD *aPad, PCB_LAYER_ID aPadLayer, const std::vector< std::string > &aLayerNames)
Append the copper aPad carries on aPadLayer to aPadstack, one shape per Specctra layer id in aLayerNa...
static double mapY(int y)
static double IU2um(int kicadDist)
Convert integer internal units to float um.
static POINT mapPt(const VECTOR2I &pt)
Convert a KiCad point into a DSN file point.
static bool isRoundKeepout(PAD *aPad)
Decide if the pad is a copper-less through hole which needs to be made into a round keepout.
static std::string sanitizeForDSNString(const wxString &aValue)
static double scale(int kicadDist)
Convert a distance from Pcbnew internal units to the reported Specctra DSN units in floating point fo...
static PATH * makePath(const POINT &aStart, const POINT &aEnd, const std::string &aLayerName)
Create a PATH element with a single straight line, a pair of vertices.
void ReportWarning(REPORTER *aReporter, const wxString &aMessage)
Report a warning through the given reporter when available, otherwise fall back to the legacy wxLogWa...
Definition specctra.h:89
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ CHAMFERED_RECT
Definition padstack.h:61
@ ROUNDRECT
Definition padstack.h:58
@ TRAPEZOID
Definition padstack.h:57
@ RECTANGLE
Definition padstack.h:55
@ NET
This item represents a net.
DSN::T DSN_T
Definition specctra.h:54
const int scale
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A <pin_reference> definition in the specctra dsn spec.
Definition specctra.h:2438
std::string pin_id
Definition specctra.h:2464
std::string component_id
Definition specctra.h:2463
A point in the SPECCTRA DSN coordinate system.
Definition specctra.h:123
void FixNegativeZero()
Change negative zero to positive zero in the IEEE floating point storage format.
Definition specctra.h:164
double y
Definition specctra.h:125
double x
Definition specctra.h:124
The identity of the copper on one padstack layer.
bool operator==(const SPECCTRA_SHAPE_ID &aOther) const =default
std::string m_family
Shape family, eg "Round".
std::string m_dims
Dimensions, unique within a family.
std::string m_offset
Hole-to-copper offset, empty when centred.
A storage class for 128-bit hash value.
Definition hash_128.h:33
std::string ToString() const
Definition hash_128.h:44
std::string path
KIBIS_COMPONENT * comp
KIBIS_PIN * pin
const SHAPE_LINE_CHAIN chain
int radius
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
int clearance
int delta
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:227
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
static PIECE polygon(std::vector< VIA_CROSS_SECTION_GEOMETRY::POINT > aPoints, bool aMixed=false)