KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easypc_pcb_builder.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
29
30#include <board.h>
33#include <footprint.h>
34#include <ki_exception.h>
35#include <lib_id.h>
37#include <netclass.h>
38#include <netinfo.h>
39#include <pad.h>
40#include <pcb_group.h>
41#include <pcb_shape.h>
42#include <pcb_text.h>
43#include <pcb_track.h>
45#include <reporter.h>
46#include <string_utils.h>
47#include <title_block.h>
48#include <zone.h>
49
50#include <limits>
51#include <optional>
52#include <set>
53
54
55using namespace EASYPC;
56
57
58namespace EASYPC_PCB
59{
60
61namespace
62{
63
65 constexpr int PLANE_MAX_ERROR = 1000;
66
68 constexpr int PLANE_MIN_THICKNESS = 10000;
69
71 struct COPPER_KIND
72 {
73 int Kind;
74 const char* Name;
75 const char* Type;
76 };
77
78 constexpr COPPER_KIND COPPER_KINDS[] = { { SPACING_TRACK, "track", "'Track'" },
79 { SPACING_PAD, "pad", "'Pad'" },
80 { SPACING_VIA, "via", "'Via'" },
81 { SPACING_SHAPE, "shape", "'Graphic'" },
82 { SPACING_TEXT, "text", "'Text'" } };
83
84
85 wxString kindTest( const COPPER_KIND& aKind, const wxString& aItem )
86 {
87 wxString test = aItem + wxS( ".Type == " ) + aKind.Type;
88
89 if( aKind.Kind == SPACING_SHAPE )
90 return wxS( "(" ) + test + wxS( " || " ) + aItem + wxS( ".Type == 'Zone')" );
91
92 return test;
93 }
94
95
97 wxString mm( int64_t aDsu )
98 {
99 uint64_t magnitude = aDsu < 0 ? 0 - static_cast<uint64_t>( aDsu ) : static_cast<uint64_t>( aDsu );
100
101 return wxString::Format( wxS( "%s%llu.%04llumm" ), aDsu < 0 ? wxS( "-" ) : wxS( "" ),
102 static_cast<unsigned long long>( magnitude / 10000 ),
103 static_cast<unsigned long long>( magnitude % 10000 ) );
104 }
105
106
108 wxString quoteSexpr( const wxString& aText )
109 {
110 wxString text = aText;
111 text.Replace( wxS( "\\" ), wxS( "\\\\" ) );
112 text.Replace( wxS( "\"" ), wxS( "\\\"" ) );
113 return wxS( "\"" ) + text + wxS( "\"" );
114 }
115
116
118 int32_t spacingValue( const SOURCE_SPACINGS& aSpacings, int aTypeA, int aTypeB )
119 {
120 if( aSpacings.Bidirectional && aTypeB > aTypeA )
121 std::swap( aTypeA, aTypeB );
122
123 auto it = aSpacings.Values.find(
124 static_cast<int32_t>( ( static_cast<uint32_t>( aTypeA ) << 16 ) | ( aTypeB & 0xffff ) ) );
125 return it == aSpacings.Values.end() ? -1 : it->second;
126 }
127
128
129 class PCB_BUILDER
130 {
131 public:
132 PCB_BUILDER( const DESIGN_DOCUMENT& aDocument, BOARD& aBoard, REPORTER* aReporter );
133
134 void Build();
135
136 std::unique_ptr<LAYER_MAPPER> m_layers;
137 wxString m_customRules;
138
139 private:
140 void buildLayers();
141 void buildRules();
142 void buildNetClasses();
143 void buildFootprints();
144 void buildFreeItems();
145 void buildTracksAndVias();
146 void buildAreas();
147 void buildPlanes();
148 void buildGroups();
149
151 SHAPE_POLY_SET planeClearances( const SOURCE_LAYER& aLayer, PCB_LAYER_ID aKiCadLayer,
152 NETINFO_ITEM* aNet ) const;
153
155 bool becomesZone( const SOURCE_AREA& aArea ) const;
156
157 void placeValueTexts( FOOTPRINT& aFootprint, const SOURCE_COMPONENT_INSTANCE& aInstance,
158 const SOURCE_SYMBOL_INSTANCE& aSymbolInstance );
159
161 int32_t designValue( int aTypeA, int aTypeB ) const;
162
163 int32_t shapeSpacing( int aKind ) const
164 {
165 return m_spacings ? spacingValue( *m_spacings, SPACING_SHAPE, aKind ) : -1;
166 }
167
168 void addRule( const wxString& aName, const wxString& aConstraint, const wxString& aCondition );
169
170 NETINFO_ITEM* netOfNode( const OBJECT* aNode ) const;
171
172 const DESIGN_DOCUMENT& m_doc;
173 const SOURCE_DESIGN* m_design;
174 const SOURCE_SPACINGS* m_spacings;
175 BOARD& m_board;
176 REPORTER* m_reporter;
177 FRAME m_frame;
178 std::map<const OBJECT*, NETINFO_ITEM*> m_nets;
179 std::map<const OBJECT*, std::vector<BOARD_ITEM*>> m_created;
180 bool m_viaMask[2] = { false, false };
181 };
182
183} // namespace
184
185
186PCB_BUILDER::PCB_BUILDER( const DESIGN_DOCUMENT& aDocument, BOARD& aBoard, REPORTER* aReporter ) :
187 m_doc( aDocument ),
188 m_design( dynamic_cast<const SOURCE_DESIGN*>( aDocument.Design.get() ) ),
189 m_spacings( m_design ? dynamic_cast<const SOURCE_SPACINGS*>( m_design->Spacings ) : nullptr ),
190 m_board( aBoard ),
191 m_reporter( aReporter )
192{
193 if( !m_design )
194 THROW_IO_ERROR( _( "Easy-PC design has no design root." ) );
195
196 m_layers = std::make_unique<LAYER_MAPPER>( TypedItems<const SOURCE_LAYER>( m_design->Layers ) );
197
198 // Put the board's top left corner one inch in from the KiCad origin
199 bool any = false;
200
201 for( const SOURCE_BOARD* board : TypedItems<const SOURCE_BOARD>( m_design->Boards ) )
202 {
203 const SOURCE_SHAPE* shape = dynamic_cast<const SOURCE_SHAPE*>( board->Shape );
204
205 if( !shape )
206 continue;
207
208 for( const OBJECT* obj : shape->Segments )
209 {
210 if( const SOURCE_SEGMENT* seg = dynamic_cast<const SOURCE_SEGMENT*>( obj ) )
211 {
212 m_frame.Origin.X = any ? std::min( m_frame.Origin.X, seg->X ) : seg->X;
213 m_frame.Origin.Y = any ? std::max( m_frame.Origin.Y, seg->Y ) : seg->Y;
214 any = true;
215 }
216 }
217 }
218
219 m_frame.Offset = VECTOR2I( 25400000, 25400000 );
220}
221
222
223void PCB_BUILDER::Build()
224{
225 buildLayers();
226
227 for( const SOURCE_NET* net : TypedItems<const SOURCE_NET>( m_design->Nets ) )
228 {
229 // The schematic import names the net the same way, so an update from the schematic keeps it
230 m_nets[net] = m_board.FindOrAddNet( ToKiCadMarkup( net->Name ) );
231 }
232
233 buildRules();
234
235 for( const SOURCE_BOARD* board : TypedItems<const SOURCE_BOARD>( m_design->Boards ) )
236 AddShapeItem( m_board, *board, m_frame, *m_layers, Edge_Cuts );
237
238 buildFootprints();
239 buildFreeItems();
240 buildTracksAndVias();
241 buildAreas();
242 buildPlanes();
243 buildGroups();
244
245 TITLE_BLOCK titleBlock;
246 EASYPC::FillTitleBlock( m_doc, titleBlock );
247 m_board.SetTitleBlock( titleBlock );
248
249 // Items sit right of and below the page origin by the frame offset, so the page must reach back to it
250 BOX2L extents( VECTOR2L( 0, 0 ) );
251 extents.Merge( VECTOR2L( m_board.ComputeBoundingBox( false ).GetEnd() ) );
252 m_board.SetPageSettings( EASYPC::PageForExtents( extents ) );
253}
254
255
256int32_t PCB_BUILDER::designValue( int aTypeA, int aTypeB ) const
257{
258 if( !m_spacings || m_spacings->Bidirectional )
259 return m_spacings ? spacingValue( *m_spacings, aTypeA, aTypeB ) : -1;
260
261 // A one-way table depends on which item the caller names first; KiCad pairs are unordered
262 return std::max( spacingValue( *m_spacings, aTypeA, aTypeB ), spacingValue( *m_spacings, aTypeB, aTypeA ) );
263}
264
265
266void PCB_BUILDER::addRule( const wxString& aName, const wxString& aConstraint, const wxString& aCondition )
267{
268 if( m_customRules.IsEmpty() )
269 m_customRules = wxS( "(version 1)\n" );
270
271 m_customRules += wxS( "\n(rule " ) + quoteSexpr( aName ) + wxS( "\n " ) + aConstraint + wxS( "\n" );
272 m_customRules += wxS( " (condition " ) + quoteSexpr( aCondition ) + wxS( "))\n" );
273}
274
275
276void PCB_BUILDER::buildRules()
277{
279
280 // BOARD::SetProject keeps importer settings and net classes only when they are flagged as loaded
281 m_board.m_LegacyDesignSettingsLoaded = true;
282 m_board.m_LegacyNetclassesLoaded = true;
283
284 // Easy-PC has no board-wide clearance floor; every pair gets its own rule
285 bds.m_MinClearance = 0;
286 bds.m_HoleClearance = 0;
287 bds.m_HoleToHoleMin = 0;
288 bds.m_CopperEdgeClearance = 0;
289 bds.m_SolderMaskMinWidth = 0;
291
292 // Design parameters are only stored above engine 8000
293 auto param = [&]( int aId )
294 {
295 return m_design->Version > 8000 ? std::max( 0, m_design->DesignParameters.Param( aId ) ) : 0;
296 };
297
303
304 if( param( DP_MIN_ANNULAR_RING ) > 0 )
305 {
306 addRule( wxS( "Easy-PC minimum pad annular ring" ),
307 wxS( "(constraint annular_width (min " ) + mm( param( DP_MIN_ANNULAR_RING ) ) + wxS( "))" ),
308 wxS( "A.Type == 'Pad'" ) );
309 }
310
311 if( param( DP_MIN_TEXT_SIZE ) > 0 )
312 {
313 addRule( wxS( "Easy-PC minimum text size" ),
314 wxS( "(constraint text_height (min " ) + mm( param( DP_MIN_TEXT_SIZE ) ) + wxS( "))" ),
315 wxS( "A.Type == 'Text'" ) );
316 }
317
318 buildNetClasses();
319
320 if( !m_spacings )
321 return;
322
323 // A pair missing from the table is not checked (GetSpacing returns -1), which in KiCad needs an explicit 0
324 for( size_t i = 0; i < std::size( COPPER_KINDS ); ++i )
325 {
326 for( size_t j = i; j < std::size( COPPER_KINDS ); ++j )
327 {
328 const COPPER_KIND& a = COPPER_KINDS[i];
329 const COPPER_KIND& b = COPPER_KINDS[j];
330
331 addRule( wxString::Format( wxS( "Easy-PC %s to %s" ), a.Name, b.Name ),
332 wxS( "(constraint clearance (min " ) + mm( std::max( 0, designValue( a.Kind, b.Kind ) ) )
333 + wxS( "))" ),
334 kindTest( a, wxS( "A" ) ) + wxS( " && " ) + kindTest( b, wxS( "B" ) ) );
335 }
336 }
337
338 for( const COPPER_KIND& kind : COPPER_KINDS )
339 {
340 addRule( wxString::Format( wxS( "Easy-PC board to %s" ), kind.Name ),
341 wxS( "(constraint edge_clearance (min " )
342 + mm( std::max( 0, designValue( SPACING_BOARD, kind.Kind ) ) ) + wxS( "))" ),
343 kindTest( kind, wxS( "A" ) ) );
344 }
345}
346
347
348void PCB_BUILDER::buildNetClasses()
349{
350 std::shared_ptr<NET_SETTINGS>& netSettings = m_board.GetDesignSettings().m_NetSettings;
351
352 // A track to track spacing is the closest Easy-PC has to a netclass clearance; custom rules refine it
353 int32_t trackSpacing = designValue( SPACING_TRACK, SPACING_TRACK );
354
355 auto fill = [&]( NETCLASS& aClass, const SOURCE_NET_CLASS* aSource )
356 {
357 aClass.SetClearance( static_cast<int>( DsuToNm( std::max( 0, trackSpacing ) ) ) );
358
359 if( !aSource )
360 return;
361
362 int32_t nominal = 0;
363
364 for( const SOURCE_TRACK_STYLE* style : { aSource->TrackStyle1, aSource->TrackStyle2 } )
365 {
366 if( style )
367 nominal = std::max( nominal, style->Width );
368 }
369
370 if( nominal > 0 )
371 {
372 aClass.SetTrackWidth( static_cast<int>( DsuToNm( nominal ) ) );
373 aClass.SetDiffPairWidth( static_cast<int>( DsuToNm( nominal ) ) );
374 }
375
376 if( aSource->ViaStyle )
377 {
378 aClass.SetViaDiameter( static_cast<int>( DsuToNm( aSource->ViaStyle->Size ) ) );
379
380 if( aSource->ViaStyle->Drill > 0 )
381 aClass.SetViaDrill( static_cast<int>( DsuToNm( aSource->ViaStyle->Drill ) ) );
382 }
383
384 // The stored gap applies whether or not diff pairs are enabled
385 if( aSource->DiffPairGap > 0 )
386 aClass.SetDiffPairGap( static_cast<int>( DsuToNm( aSource->DiffPairGap ) ) );
387 };
388
389 std::map<const OBJECT*, wxString> classNames;
390 const SOURCE_NET_CLASS* defaultSource = nullptr;
391 wxString defaultName;
392
393 if( const SOURCE_DEFAULTS* defaults = dynamic_cast<const SOURCE_DEFAULTS*>( m_design->Defaults ) )
394 defaultName = defaults->NetClass;
395
397 {
398 if( !defaultName.IsEmpty() && source->Name.CmpNoCase( defaultName ) == 0 && !defaultSource )
399 defaultSource = source;
400
401 wxString name =
402 source->Name.CmpNoCase( NETCLASS::Default ) == 0 ? wxString( wxS( "EasyPC_Default" ) ) : source->Name;
403
404 std::shared_ptr<NETCLASS> netclass = std::make_shared<NETCLASS>( name );
405 fill( *netclass, source );
406 netSettings->SetNetclass( name, netclass );
407 classNames[source] = name;
408
409 // Only the minimum style is a DRC limit in Easy-PC's own checks, so it becomes a rule
410 int32_t minimum = std::numeric_limits<int32_t>::max();
411
412 for( const SOURCE_TRACK_STYLE* style : { source->TrackStyle1, source->TrackStyle2 } )
413 {
414 if( style )
415 minimum = std::min( minimum, style->Width );
416 }
417
418 std::optional<wxString> literal = LIBEVAL::EscapeStringLiteral( name );
419
420 if( minimum != std::numeric_limits<int32_t>::max() && minimum > 0 && literal )
421 {
422 addRule( wxS( "Easy-PC net class " ) + source->Name + wxS( " minimum width" ),
423 wxS( "(constraint track_width (min " ) + mm( minimum ) + wxS( "))" ),
424 wxS( "A.NetClass == '" ) + *literal + wxS( "'" ) );
425 }
426 }
427
428 fill( *netSettings->GetDefaultNetclass(), defaultSource );
429
430 for( const auto& [net, kicadNet] : m_nets )
431 {
432 if( auto it = classNames.find( static_cast<const SOURCE_NET*>( net )->NetClass ); it != classNames.end() )
433 {
434 netSettings->SetNetclassPatternAssignment( kicadNet->GetNetname(), it->second );
435 kicadNet->SetNetClass( netSettings->GetNetClassByName( it->second ) );
436 }
437 }
438}
439
440
441SHAPE_POLY_SET PCB_BUILDER::planeClearances( const SOURCE_LAYER& aLayer, PCB_LAYER_ID aKiCadLayer,
442 NETINFO_ITEM* aNet ) const
443{
444 // The negative plane plot (Ampera_V1, Chademo_VCU_V3_ISA, GwizBluePill, router2 ODB++): every feature it draws
445 // is a clearance, and the plane is the board less them
447 int iso = m_frame.Length( m_design->IsolationGap );
448 int spoke = m_frame.Length( m_design->ThermalRelief );
449 EDA_ANGLE spokeAngle = m_design->ThermalAngled ? ANGLE_45 : ANGLE_0;
450
451 // A ring from the land out by isolation_gap, cut by four spokes; round for a round land and rectangular, in the
452 // land's orientation, for a rectangular one (GwizBluePill T116)
453 auto thermal = [&]( const VECTOR2I& aCentre, const VECTOR2I& aLand, bool aRectangular, const EDA_ANGLE& aAngle )
454 {
455 SHAPE_POLY_SET ring;
456 SHAPE_POLY_SET land;
457 SHAPE_POLY_SET spokes;
458 int reach = std::max( aLand.x, aLand.y );
459
460 if( aRectangular )
461 {
462 TransformTrapezoidToPolygon( ring, aCentre, aLand + VECTOR2I( 2 * iso, 2 * iso ), aAngle, 0, 0, 0,
463 PLANE_MAX_ERROR, ERROR_OUTSIDE );
464 TransformTrapezoidToPolygon( land, aCentre, aLand, aAngle, 0, 0, 0, PLANE_MAX_ERROR, ERROR_INSIDE );
465 }
466 else
467 {
468 TransformCircleToPolygon( ring, aCentre, aLand.x / 2 + iso, PLANE_MAX_ERROR, ERROR_OUTSIDE );
469 TransformCircleToPolygon( land, aCentre, aLand.x / 2, PLANE_MAX_ERROR, ERROR_INSIDE );
470 }
471
472 ring.BooleanSubtract( land );
473
474 // The spokes run from the centre past the ring with square ends
475 for( int i = 0; i < 4; ++i )
476 {
477 VECTOR2I dir( reach + iso + spoke, 0 );
478 VECTOR2I side( 0, spoke / 2 );
480
481 RotatePoint( dir, spokeAngle + ANGLE_90 * i );
482 RotatePoint( side, spokeAngle + ANGLE_90 * i );
483 rect.Append( aCentre + side );
484 rect.Append( aCentre + dir + side );
485 rect.Append( aCentre + dir - side );
486 rect.Append( aCentre - side );
487 rect.SetClosed( true );
488 spokes.AddOutline( rect );
489 }
490
491 ring.BooleanSubtract( spokes );
492 clear.Append( ring );
493 };
494
495 for( FOOTPRINT* fp : m_board.Footprints() )
496 {
497 for( PAD* pad : fp->Pads() )
498 {
499 if( !pad->IsOnLayer( aKiCadLayer ) )
500 continue;
501
502 VECTOR2I size = pad->GetSize( aKiCadLayer );
503 ::PAD_SHAPE shape = pad->GetShape( aKiCadLayer );
504
505 if( pad->GetNet() == aNet && pad->GetAttribute() == PAD_ATTRIB::PTH )
506 {
507 thermal( pad->GetPosition(), size,
509 || shape == ::PAD_SHAPE::CHAMFERED_RECT,
510 pad->GetOrientation() );
511 continue;
512 }
513
514 // A surface pad on an outer plane's own net is part of its copper
515 if( pad->GetNet() == aNet && !pad->HasHole() )
516 continue;
517
518 if( shape == ::PAD_SHAPE::CUSTOM )
519 {
520 pad->TransformShapeToPolygon( clear, aKiCadLayer, iso, PLANE_MAX_ERROR, ERROR_OUTSIDE );
521 continue;
522 }
523
524 // The clearance grows each half size by the isolation, keeping a rectangle's corners square
525 PAD grown( *pad );
526 grown.SetSize( aKiCadLayer, size + VECTOR2I( 2 * iso, 2 * iso ) );
527 grown.TransformShapeToPolygon( clear, aKiCadLayer, 0, PLANE_MAX_ERROR, ERROR_OUTSIDE );
528 }
529 }
530
531 for( PCB_TRACK* track : m_board.Tracks() )
532 {
533 if( !track->IsOnLayer( aKiCadLayer ) )
534 continue;
535
536 PCB_VIA* via = dynamic_cast<PCB_VIA*>( track );
537
538 if( via && via->GetNet() == aNet )
539 {
540 int width = via->GetWidth( aKiCadLayer );
541 thermal( via->GetPosition(), VECTOR2I( width, width ), false, ANGLE_0 );
542 }
543 else if( via )
544 {
545 TransformCircleToPolygon( clear, via->GetPosition(), via->GetWidth( aKiCadLayer ) / 2 + iso,
546 PLANE_MAX_ERROR, ERROR_OUTSIDE );
547 }
548 else if( track->GetNet() != aNet )
549 {
550 track->TransformShapeToPolygon( clear, aKiCadLayer, iso, PLANE_MAX_ERROR, ERROR_OUTSIDE );
551 }
552 }
553
554 // A pour keepout is cleared as its region and its outline stroke
555 for( const SOURCE_AREA* area : TypedItems<const SOURCE_AREA>( m_design->Areas ) )
556 {
557 const SOURCE_DESIGN_SHAPE* shape = dynamic_cast<const SOURCE_DESIGN_SHAPE*>( area->Shape );
558
559 if( !shape || !( area->Flags & AREA_POUR_KEEPOUT ) || area->Layer != &aLayer )
560 continue;
561
562 clear.Append( ShapeItemArea( *area, m_frame, PLANE_MAX_ERROR ) );
563 SHAPE_POLY_SET region = ShapeToPolySet( *shape, m_frame );
564 region.ClearArcs();
565 clear.Append( region );
566 }
567
568 clear.Simplify();
569 return clear;
570}
571
572
573void PCB_BUILDER::buildPlanes()
574{
575 // A copper layer with a net is a power plane, which plots negative: the board, less a clearance
576 // of isolation_gap around foreign items and a thermal of isolation_gap with spokes of thermal_relief on its own
577 std::vector<ZONE*> planes;
578 std::optional<SHAPE_POLY_SET> outline;
579
580 for( const SOURCE_LAYER* layer : TypedItems<const SOURCE_LAYER>( m_design->Layers ) )
581 {
582 PCB_LAYER_ID kicadLayer = m_layers->Map( layer );
583 auto netIt = m_nets.find( layer->Net );
584
585 if( layer->Usage != LAYER_USAGE_ELECTRICAL || !layer->Net || kicadLayer == UNDEFINED_LAYER
586 || netIt == m_nets.end() )
587 {
588 continue;
589 }
590
591 // The plot clears the board edge by the board to shape spacing beyond the outline's half width
592 for( const SOURCE_BOARD* board : TypedItems<const SOURCE_BOARD>( outline ? nullptr : m_design->Boards ) )
593 {
594 const SOURCE_DESIGN_SHAPE* shape = dynamic_cast<const SOURCE_DESIGN_SHAPE*>( board->Shape );
595 const SOURCE_LINE_STYLE* style = dynamic_cast<const SOURCE_LINE_STYLE*>( board->Style );
596 SHAPE_POLY_SET region;
597
598 if( shape && shape->IsClosed() )
599 {
600 region = ShapeToPolySet( *shape, m_frame );
601 region.ClearArcs();
602 region.Deflate( m_frame.Length( std::max( shapeSpacing( SPACING_BOARD ), 0 ) )
603 + ( style ? m_frame.Length( style->Width ) / 2 : 0 ),
604 CORNER_STRATEGY::ROUND_ALL_CORNERS, PLANE_MAX_ERROR );
605 }
606
607 ( outline ? *outline : outline.emplace() ).BooleanAdd( region );
608 }
609
610 if( !outline || outline->IsEmpty() )
611 continue;
612
613 ZONE* zone = new ZONE( &m_board );
614 zone->SetLayer( kicadLayer );
615 zone->SetNet( netIt->second );
616 zone->SetZoneName( layer->Name );
617 *zone->Outline() = *outline;
618 zone->SetLocalClearance( m_frame.Length( m_design->IsolationGap ) );
620 zone->SetThermalReliefGap( m_frame.Length( m_design->IsolationGap ) );
621 zone->SetThermalReliefSpokeWidth( m_frame.Length( m_design->ThermalRelief ) );
622 zone->SetMinThickness( PLANE_MIN_THICKNESS );
624 m_board.Add( zone );
625 planes.push_back( zone );
626
627 // The fill is drawn as the plane plots; KiCad's filler has no via thermals and clears a
628 // dropped pad only around its hole, so its settings above serve a later refill
629 SHAPE_POLY_SET fill = *outline;
630 fill.BooleanSubtract( planeClearances( *layer, kicadLayer, netIt->second ) );
631 fill.Fracture();
632 zone->SetFilledPolysList( kicadLayer, fill );
633 zone->SetIsFilled( true );
634 zone->SetNeedRefill( false );
635 }
636
637 if( planes.empty() )
638 return;
639
640 wxString names;
641 LSET planeLayers;
642
643 for( ZONE* zone : planes )
644 {
645 names += ( names.IsEmpty() ? wxString() : wxString( wxS( ", " ) ) ) + zone->GetZoneName();
646 planeLayers.set( zone->GetLayer() );
647 }
648
649 if( m_reporter )
650 {
651 m_reporter->Report( wxString::Format( _( "Easy-PC power planes (%s) were imported with the copper the "
652 "program plots. KiCad cannot refill them the same way: a refill "
653 "makes via thermals solid and clears foreign through-hole lands "
654 "only around their holes." ),
655 names ),
657 }
658
659 // A plane plots a foreign pad or via as its clearance alone; with only planes inside, KiCad drops their
660 // unconnected inner copper the same way
661 bool onlyPlanesInside = ( m_board.GetEnabledLayers() & LSET::InternalCuMask() ) == planeLayers;
662
663 for( FOOTPRINT* fp : m_board.Footprints() )
664 {
665 for( PAD* pad : fp->Pads() )
666 {
667 if( onlyPlanesInside && pad->GetAttribute() == PAD_ATTRIB::PTH )
668 pad->Padstack().SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
669
670 // KiCad's filler records which lands a fill reaches; the stored fill reaches every land on its own net.
671 // The plot's thermal spokes run on the axes unless the design angles them
672 for( ZONE* zone : planes )
673 {
674 if( pad->GetNet() == zone->GetNet() )
675 pad->SetThermalSpokeAngle( m_design->ThermalAngled ? ANGLE_45 : ANGLE_0 );
676
677 if( pad->HasHole() && pad->IsOnLayer( zone->GetLayer() ) && pad->GetNet() == zone->GetNet() )
678 pad->SetZoneLayerOverride( zone->GetLayer(), ZLO_FORCE_FLASHED );
679 }
680 }
681 }
682
683 for( PCB_TRACK* track : m_board.Tracks() )
684 {
685 PCB_VIA* via = dynamic_cast<PCB_VIA*>( track );
686
687 if( !via )
688 continue;
689
690 if( onlyPlanesInside )
691 via->Padstack().SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
692
693 for( ZONE* zone : planes )
694 {
695 if( via->IsOnLayer( zone->GetLayer() ) && via->GetNet() == zone->GetNet() )
696 via->SetZoneLayerOverride( zone->GetLayer(), ZLO_FORCE_FLASHED );
697 }
698 }
699}
700
701
702void PCB_BUILDER::buildGroups()
703{
704 // A dimension is stored as a group of its lines, arrows and text, kept as drawn
705 for( const SOURCE_GROUP* group : TypedItems<const SOURCE_GROUP>( m_design->Groups ) )
706 {
707 PCB_GROUP* kgroup = new PCB_GROUP( &m_board );
708 kgroup->SetName( group->Name );
709
710 for( const OBJECT* member : group->Members )
711 {
712 auto it = m_created.find( member );
713
714 if( it == m_created.end() )
715 continue;
716
717 for( BOARD_ITEM* item : it->second )
718 {
719 if( !item->GetParentGroup() )
720 kgroup->AddItem( item );
721 }
722 }
723
724 if( kgroup->GetItems().empty() )
725 delete kgroup;
726 else
727 m_board.Add( kgroup );
728 }
729}
730
731
732void PCB_BUILDER::buildLayers()
733{
734 int copper = m_layers->CopperCount();
735 m_board.SetCopperLayerCount( copper );
736
737 LSET enabled = LSET::AllCuMask( copper ) | LSET( { Edge_Cuts } );
739
740 // Mask and paste openings are the pad grown by the layer type's oversize
741 for( const SOURCE_LAYER* layer : TypedItems<const SOURCE_LAYER>( m_design->Layers ) )
742 {
743 PCB_LAYER_ID id = m_layers->Map( layer );
744 const SOURCE_LAYER_TYPE* type = layer->Type;
745 bool mask = id == F_Mask || id == B_Mask;
746
747 if( id == UNDEFINED_LAYER )
748 continue;
749
750 enabled.set( id );
751
752 if( IsCopperLayer( id ) || IsUserLayer( id ) )
753 m_board.SetLayerName( id, layer->Name );
754
755 if( !type || ( !mask && id != F_Paste && id != B_Paste ) )
756 continue;
757
758 // Vias are plotted on a mask layer only when its type enables them
759 if( mask )
760 m_viaMask[id == F_Mask ? 0 : 1] = type->ViasEnabled;
761
762 if( type->OversizeType == LAYER_OVERSIZE_TYPE::FIXED && mask )
763 bds.m_SolderMaskExpansion = m_frame.Length( type->Oversize );
764 else if( type->OversizeType == LAYER_OVERSIZE_TYPE::FIXED )
765 bds.m_SolderPasteMargin = m_frame.Length( type->Oversize );
766 else if( type->OversizeType == LAYER_OVERSIZE_TYPE::PERCENT && !mask )
767 bds.m_SolderPasteMarginRatio = type->Oversize / 100.0;
768 }
769
770 m_board.SetEnabledLayers( enabled );
771 m_board.SetVisibleLayers( enabled );
772}
773
774
775NETINFO_ITEM* PCB_BUILDER::netOfNode( const OBJECT* aNode ) const
776{
777 const SOURCE_NODE* node = dynamic_cast<const SOURCE_NODE*>( aNode );
778 auto it = node ? m_nets.find( node->Parent ) : m_nets.end();
779
780 return it == m_nets.end() ? nullptr : it->second;
781}
782
783
784void PCB_BUILDER::buildFootprints()
785{
786 for( const SOURCE_COMPONENT_INSTANCE* ci :
788 {
789 const SOURCE_COMPONENT* component = dynamic_cast<const SOURCE_COMPONENT*>( ci->Component );
790 const SOURCE_PCB_COMPONENT* pcb = component ? component->Board : nullptr;
791
792 for( const SOURCE_SYMBOL_INSTANCE* si : TypedItems<const SOURCE_SYMBOL_INSTANCE>( ci->SymbolInstances ) )
793 {
794 const SOURCE_SYMBOL* symbol = dynamic_cast<const SOURCE_SYMBOL*>( si->Symbol );
795
796 if( si->Gate != -1 || !si->Placed || !symbol )
797 continue;
798
799 std::map<const SOURCE_FREE_PAD*, PAD*> padMap;
800 LIB_ID id( wxS( "easypc" ), EscapeString( symbol->Name, CTX_LIBID ) );
801 std::unique_ptr<FOOTPRINT> fp = ConvertFootprint( *symbol, *m_layers, id, pcb, &padMap );
802
803 fp->SetParent( &m_board );
804
805 // A pad instance's style exception replaces the definition's style for that one pad
806 FRAME symbolFrame{ POINT32{ symbol->OriginX, symbol->OriginY } };
807
809 {
810 const SOURCE_FREE_PAD* freePad = dynamic_cast<const SOURCE_FREE_PAD*>( pi->Pad );
811 const SOURCE_PAD_STYLE* exception = dynamic_cast<const SOURCE_PAD_STYLE*>( pi->StyleException );
812 auto it = padMap.find( freePad );
813
814 if( !exception || it == padMap.end() )
815 continue;
816
817 std::unique_ptr<PAD> pad = CreatePad( fp.get(), *freePad, *exception, symbolFrame, *m_layers );
818 pad->SetNumber( it->second->GetNumber() );
819 fp->Remove( it->second );
820 delete it->second;
821 it->second = pad.get();
822 fp->Add( pad.release() );
823 }
824
825 fp->SetReference( ci->Name );
826
827 if( component && component->Schematic )
828 fp->SetValue( component->Schematic->Name );
829
830 // Native placement is mirror in X, then rotate anticlockwise, then translate. A left-right flip
831 // records 180 degrees in the orientation, so the rotation is applied relative to it
832 if( si->Mirrored )
833 fp->Flip( VECTOR2I( 0, 0 ), FLIP_DIRECTION::LEFT_RIGHT );
834
835 fp->Rotate( VECTOR2I( 0, 0 ), FRAME::Angle( si->Angle ) );
836 fp->SetPosition( m_frame.ToKiCad( si->Position ) );
837
838 placeValueTexts( *fp, *ci, *si );
839
841 {
842 auto it = padMap.find( dynamic_cast<const SOURCE_FREE_PAD*>( pi->Pad ) );
843 NETINFO_ITEM* net = netOfNode( pi->Node );
844
845 if( it != padMap.end() && net )
846 it->second->SetNet( net );
847 }
848
849 m_board.Add( fp.release() );
850 }
851 }
852}
853
854
855void PCB_BUILDER::placeValueTexts( FOOTPRINT& aFootprint, const SOURCE_COMPONENT_INSTANCE& aInstance,
856 const SOURCE_SYMBOL_INSTANCE& aSymbolInstance )
857{
858 bool referencePlaced = false;
859 bool valuePlaced = false;
860
861 // The positions are in board coordinates, so they are applied after the footprint is placed. The first
862 // reference and value positions place the fields; a further reference position is a text of its own
864 {
865 if( ( vp->Types & VALUE_REFERENCE_NAME ) && !referencePlaced )
866 {
867 bool placed = ApplyTextPosition( aFootprint.Reference(), *vp, m_frame, *m_layers );
868 aFootprint.Reference().SetVisible( placed && vp->Displayed );
869 referencePlaced = true;
870 }
871 else if( ( vp->Types & VALUE_COMPONENT_NAME ) && !valuePlaced )
872 {
873 bool placed = ApplyTextPosition( aFootprint.Value(), *vp, m_frame, *m_layers );
874 aFootprint.Value().SetVisible( placed && vp->Displayed );
875 valuePlaced = true;
876 }
877 else if( ( vp->Types & VALUE_REFERENCE_NAME ) && vp->Displayed )
878 {
879 std::unique_ptr<PCB_TEXT> item = std::make_unique<PCB_TEXT>( &aFootprint );
880 item->SetText( aInstance.Name );
881
882 if( ApplyTextPosition( *item, *vp, m_frame, *m_layers ) )
883 aFootprint.Add( item.release() );
884 }
885 }
886
887 if( !referencePlaced )
888 aFootprint.Reference().SetVisible( false );
889
890 if( !valuePlaced )
891 aFootprint.Value().SetVisible( false );
892}
893
894
895void PCB_BUILDER::buildFreeItems()
896{
897 // The design list also holds every area's stored pour; buildAreas() makes those zone fills
898 std::set<const SOURCE_FREE_COPPER*> poured;
899
900 for( const SOURCE_AREA* area : TypedItems<const SOURCE_AREA>( m_design->Areas ) )
901 {
902 if( becomesZone( *area ) )
903 {
904 for( const SOURCE_FREE_COPPER* piece : TypedItems<const SOURCE_FREE_COPPER>( area->Copper ) )
905 poured.insert( piece );
906 }
907 }
908
909 for( const SOURCE_FREE_COPPER* copper : TypedItems<const SOURCE_FREE_COPPER>( m_design->Coppers ) )
910 {
911 if( poured.count( copper ) )
912 continue;
913
914 NETINFO_ITEM* net = nullptr;
915
916 for( const SOURCE_COPPER_TERMINAL* term : TypedItems<const SOURCE_COPPER_TERMINAL>( copper->Terminals ) )
917 {
918 if( ( net = netOfNode( term->Node ) ) != nullptr )
919 break;
920 }
921
922 for( PCB_SHAPE* shape : AddShapeItem( m_board, *copper, m_frame, *m_layers ) )
923 {
924 if( net && IsCopperLayer( shape->GetLayer() ) )
925 shape->SetNet( net );
926
927 m_created[copper].push_back( shape );
928 }
929 }
930
932 {
933 if( PCB_TEXT* ktext = AddText( m_board, *text, text->Text, m_frame, *m_layers ) )
934 m_created[text].push_back( ktext );
935 }
936
937 for( const SOURCE_FREE_PAD* freePad : TypedItems<const SOURCE_FREE_PAD>( m_design->Pads ) )
938 {
939 const SOURCE_PAD_STYLE* style = dynamic_cast<const SOURCE_PAD_STYLE*>( freePad->Style );
940
941 if( !style )
942 continue;
943
944 // KiCad pads live in footprints, so each free pad gets a footprint of its own at the pad position
945 FOOTPRINT* fp = new FOOTPRINT( &m_board );
946 fp->SetReference( wxEmptyString );
947 fp->Reference().SetVisible( false );
948 fp->Value().SetVisible( false );
949
950 std::unique_ptr<PAD> pad = CreatePad( fp, *freePad, *style, FRAME{ freePad->Position }, *m_layers );
951
952 if( NETINFO_ITEM* net = netOfNode( freePad->Node ) )
953 pad->SetNet( net );
954
955 fp->Add( pad.release() );
956 fp->SetPosition( m_frame.ToKiCad( freePad->Position ) );
957 m_board.Add( fp );
958 m_created[freePad].push_back( fp );
959 }
960}
961
962
963void PCB_BUILDER::buildTracksAndVias()
964{
965 std::set<const SOURCE_VIA*> vias;
966
967 for( const SOURCE_NET* net : TypedItems<const SOURCE_NET>( m_design->Nets ) )
968 {
969 NETINFO_ITEM* info = m_nets[net];
970
971 for( const SOURCE_NODE* node : TypedItems<const SOURCE_NODE>( net->Nodes ) )
972 {
973 const SOURCE_VIA* via = dynamic_cast<const SOURCE_VIA*>( node->Item );
974 const SOURCE_PAD_STYLE* style = via ? dynamic_cast<const SOURCE_PAD_STYLE*>( via->Style ) : nullptr;
975
976 if( !style || !vias.insert( via ).second )
977 continue;
978
979 PCB_VIA* kvia = new PCB_VIA( &m_board );
980 kvia->SetPosition( m_frame.ToKiCad( via->Position ) );
981 kvia->SetWidth( PADSTACK::ALL_LAYERS, m_frame.Length( style->Size ) );
982 kvia->SetDrill( m_frame.Length( style->Drill ) );
983 kvia->SetNet( info );
984
985 // The net class forces tenting (0 open, 1 tented) or, with 2, defers to the via
986 const SOURCE_NET_CLASS* netClass = dynamic_cast<const SOURCE_NET_CLASS*>( net->NetClass );
987 int rule = netClass ? netClass->TentedVias : 2;
988 bool tented = rule == 1 || ( rule == 2 && via->Tented );
989
990 kvia->SetFrontTentingMode( !tented && m_viaMask[0] ? TENTING_MODE::NOT_TENTED : TENTING_MODE::TENTED );
991 kvia->SetBackTentingMode( !tented && m_viaMask[1] ? TENTING_MODE::NOT_TENTED : TENTING_MODE::TENTED );
992 m_board.Add( kvia );
993 m_created[via].push_back( kvia );
994 }
995
996 for( const SOURCE_CONNECTION* conn : TypedItems<const SOURCE_CONNECTION>( net->Connections ) )
997 {
998 const SOURCE_TRACK* track = dynamic_cast<const SOURCE_TRACK*>( conn->Track );
999 PCB_LAYER_ID layer = track ? m_layers->Map( track->Layer ) : UNDEFINED_LAYER;
1000
1001 if( layer == UNDEFINED_LAYER )
1002 continue;
1003
1004 std::vector<const SOURCE_TRACK_SEGMENT*> verts;
1005
1006 for( const OBJECT* obj : track->Segments )
1007 {
1008 if( const SOURCE_TRACK_SEGMENT* seg = dynamic_cast<const SOURCE_TRACK_SEGMENT*>( obj ) )
1009 verts.push_back( seg );
1010 }
1011
1012 auto add = [&]( PCB_TRACK* aItem, int aWidth )
1013 {
1014 aItem->SetWidth( aWidth );
1015 aItem->SetLayer( layer );
1016 aItem->SetNet( info );
1017 m_board.Add( aItem );
1018 m_created[conn].push_back( aItem );
1019 };
1020
1021 for( size_t i = 0; i + 1 < verts.size(); ++i )
1022 {
1023 const SOURCE_TRACK_SEGMENT* s = verts[i];
1024 const SOURCE_TRACK_SEGMENT* e = verts[i + 1];
1025 const SOURCE_TRACK_STYLE* style = dynamic_cast<const SOURCE_TRACK_STYLE*>( s->Style );
1026
1027 // A span's width is its own style's, with no fallback to the track's default style
1028 int width = style ? m_frame.Length( style->Width ) : 0;
1029
1030 // A zero-length span plots as a dot of the track width, which a degenerate track also does
1031 int32_t angle = s->X != e->X || s->Y != e->Y ? s->ArcAngle : 0;
1032 ARC_FORM form =
1033 ArcForm( POINT32{ s->X, s->Y }, POINT32{ e->X, e->Y }, angle, s->Anticlockwise, m_frame );
1034
1035 if( form.IsArc() )
1036 {
1037 PCB_ARC* arc = new PCB_ARC( &m_board );
1038 arc->SetStart( form.Start );
1039 arc->SetMid( form.Mid );
1040 arc->SetEnd( form.End );
1041 add( arc, width );
1042 }
1043
1044 for( size_t k = 1; k < form.Points.size(); ++k )
1045 {
1046 PCB_TRACK* ktrack = new PCB_TRACK( &m_board );
1047 ktrack->SetStart( form.Points[k - 1] );
1048 ktrack->SetEnd( form.Points[k] );
1049 add( ktrack, width );
1050 }
1051 }
1052 }
1053 }
1054}
1055
1056
1057bool PCB_BUILDER::becomesZone( const SOURCE_AREA& aArea ) const
1058{
1059 return aArea.Type == AREA_COPPER && !( aArea.Flags & AREA_POUR_KEEPOUT )
1060 && dynamic_cast<const SOURCE_DESIGN_SHAPE*>( aArea.Shape )
1061 && m_layers->Map( aArea.Layer ) != UNDEFINED_LAYER;
1062}
1063
1064
1065void PCB_BUILDER::buildAreas()
1066{
1067 int routingAreas = 0;
1068 int ruleAreas = 0;
1069
1070 for( const SOURCE_AREA* area : TypedItems<const SOURCE_AREA>( m_design->Areas ) )
1071 {
1072 const SOURCE_DESIGN_SHAPE* shape = dynamic_cast<const SOURCE_DESIGN_SHAPE*>( area->Shape );
1073
1074 if( !shape )
1075 continue;
1076
1077 // A pour keepout keeps every zone fill out; KiCad has no way to limit that to one net
1078 if( area->Flags & AREA_POUR_KEEPOUT )
1079 {
1080 LSET copper = m_layers->PadLayers( area->Layer, false ) & LSET::AllCuMask();
1081
1082 if( copper.none() )
1083 continue;
1084
1085 SHAPE_POLY_SET outline = ShapeToPolySet( *shape, m_frame );
1086 outline.ClearArcs();
1087
1088 ZONE* zone = new ZONE( &m_board );
1089 ++ruleAreas;
1090 zone->SetIsRuleArea( true );
1091 zone->SetZoneName( area->Name.IsEmpty() ? wxString::Format( wxS( "Easy-PC area %d" ), ruleAreas )
1092 : area->Name );
1093 zone->SetLayerSet( copper );
1094 *zone->Outline() = outline;
1095 zone->SetDoNotAllowTracks( false );
1096 zone->SetDoNotAllowVias( false );
1097 zone->SetDoNotAllowZoneFills( true );
1098 zone->SetDoNotAllowPads( false );
1099 zone->SetDoNotAllowFootprints( false );
1100 m_board.Add( zone );
1101 continue;
1102 }
1103
1104 // The routing area check is off in every known design, so these restrict nothing
1105 if( area->Type == AREA_ROUTING )
1106 {
1107 PCB_GROUP* group = new PCB_GROUP( &m_board );
1108 group->SetName( area->Name.IsEmpty() ? wxString( wxS( "Easy-PC routing area" ) ) : area->Name );
1109
1110 for( PCB_SHAPE* outline : AddShapeItem( m_board, *area, m_frame, *m_layers, Cmts_User ) )
1111 group->AddItem( outline );
1112
1113 ++routingAreas;
1114
1115 if( group->GetItems().empty() )
1116 {
1117 delete group;
1118 continue;
1119 }
1120
1121 m_board.Add( group );
1122 m_created[area].push_back( group );
1123 continue;
1124 }
1125
1126 if( !becomesZone( *area ) )
1127 continue;
1128
1129 PCB_LAYER_ID layer = m_layers->Map( area->Layer );
1130 ZONE* zone = new ZONE( &m_board );
1131 zone->SetLayer( layer );
1132 *zone->Outline() = ShapeToPolySet( *shape, m_frame );
1133
1134 if( auto netIt = m_nets.find( area->Net ); netIt != m_nets.end() )
1135 zone->SetNet( netIt->second );
1136
1137 // Pours clear each item by the shape spacing plus the pour net's guard; the
1138 // smallest over the item kinds is the zone's own clearance, larger kinds are left to the custom rules
1139 const SOURCE_NET* net = dynamic_cast<const SOURCE_NET*>( area->Net );
1140 int32_t clearance = -1;
1141
1142 for( int kind : { SPACING_TRACK, SPACING_PAD, SPACING_VIA, SPACING_SHAPE } )
1143 {
1144 int32_t spacing = shapeSpacing( kind );
1145
1146 if( spacing >= 0 && ( clearance < 0 || spacing < clearance ) )
1147 clearance = spacing;
1148 }
1149
1150 if( clearance >= 0 )
1151 zone->SetLocalClearance( m_frame.Length( int64_t( clearance ) + ( net ? net->GuardSpacing : 0 ) ) );
1152
1153 // Keep the imported pour within a micron of its stored outline.
1154 SHAPE_POLY_SET fill;
1155 int maxError = std::min( m_board.GetDesignSettings().m_MaxError, 1000 );
1156
1157 // One union of all pieces; adding them one by one is quadratic on large pours
1158 for( const SOURCE_FREE_COPPER* poured : TypedItems<const SOURCE_FREE_COPPER>( area->Copper ) )
1159 {
1160 SHAPE_POLY_SET piece = ShapeItemArea( *poured, m_frame, maxError );
1161
1162 for( int i = 0; i < piece.OutlineCount(); ++i )
1163 fill.AddPolygon( piece.Polygon( i ) );
1164 }
1165
1166 if( !fill.IsEmpty() )
1167 {
1168 fill.Simplify();
1169 fill.Fracture();
1170 zone->SetFilledPolysList( layer, fill );
1171 zone->SetIsFilled( true );
1172 zone->SetNeedRefill( false );
1173 }
1174
1175 m_board.Add( zone );
1176 }
1177
1178 if( routingAreas && m_reporter )
1179 {
1180 m_reporter->Report( wxString::Format( _( "%d Easy-PC routing areas were imported as outlines on Cmts.User; "
1181 "the design does not run its routing area check, so they restrict "
1182 "nothing." ),
1183 routingAreas ),
1185 }
1186}
1187
1188
1189wxString BuildBoard( const DESIGN_DOCUMENT& aDocument, BOARD& aBoard, REPORTER* aReporter,
1190 const LAYER_MAPPING_HANDLER& aLayerMapping )
1191{
1192 PCB_BUILDER builder( aDocument, aBoard, aReporter );
1193
1194 if( aLayerMapping )
1195 builder.m_layers->ApplyUserMapping( aLayerMapping( builder.m_layers->Describe() ) );
1196
1197 builder.Build();
1198 return builder.m_customRules;
1199}
1200
1201} // namespace EASYPC_PCB
const char * name
@ ERROR_OUTSIDE
@ ERROR_INSIDE
@ ZLO_FORCE_FLASHED
Definition board_item.h:77
BOX2< VECTOR2L > BOX2L
Definition box2.h:919
BASE_SET & set(size_t pos)
Definition base_set.h:126
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition board.h:565
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition board.cpp:1235
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
NETINFO_ITEM * FindOrAddNet(const wxString &aNetName, int aNetCode=-1, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)
Return the net with the given name, adding it to the board if there is none.
Definition board.cpp:2852
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition board.cpp:978
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition board.h:1030
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
Definition board.h:569
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aPhysicalLayersOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition board.cpp:2572
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1222
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition board.h:1037
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
void SetName(const wxString &aName)
Definition eda_group.h:76
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
void SetPosition(const VECTOR2I &aPos) override
PCB_FIELD & Value()
read/write accessors:
Definition footprint.h:831
void SetReference(const wxString &aReference)
Definition footprint.h:799
PCB_FIELD & Reference()
Definition footprint.h:832
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
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
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:573
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
void SetViaDiameter(int aDia)
Definition netclass.h:160
void SetViaDrill(int aSize)
Definition netclass.h:168
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
void SetDiffPairWidth(int aSize)
Definition netclass.h:192
void SetDiffPairGap(int aSize)
Definition netclass.h:200
void SetClearance(int aClearance)
Definition netclass.h:144
void SetTrackWidth(int aWidth)
Definition netclass.h:152
Handle the data for a net.
Definition netinfo.h:50
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
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool aIgnoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition pad.cpp:3036
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.cpp:264
void SetMid(const VECTOR2I &aMid)
Definition pcb_track.h:303
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
void SetFrontTentingMode(TENTING_MODE aMode)
void SetDrill(int aDrill)
Definition pcb_track.h:831
void SetBackTentingMode(TENTING_MODE aMode)
void SetPosition(const VECTOR2I &aPoint) override
Definition pcb_track.h:616
void SetWidth(int aWidth) override
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
int AddPolygon(const POLYGON &apolygon)
Adds a polygon to the set.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
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.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:38
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetNeedRefill(bool aNeedRefill)
Definition zone.h:310
void SetDoNotAllowPads(bool aEnable)
Definition zone.h:860
void SetLocalClearance(std::optional< int > aClearance)
Definition zone.h:183
void SetMinThickness(int aMinThickness)
Definition zone.h:316
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition zone.h:251
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
SHAPE_POLY_SET * Outline()
Definition zone.h:421
void SetIsRuleArea(bool aEnable)
Definition zone.h:835
void SetDoNotAllowTracks(bool aEnable)
Definition zone.h:859
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
Definition zone.h:748
void SetIsFilled(bool isFilled)
Definition zone.h:307
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:702
void SetDoNotAllowVias(bool aEnable)
Definition zone.h:858
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
Definition zone.cpp:668
void SetThermalReliefGap(int aThermalReliefGap)
Definition zone.h:240
void SetDoNotAllowFootprints(bool aEnable)
Definition zone.h:861
void SetDoNotAllowZoneFills(bool aEnable)
Definition zone.h:857
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition zone.h:313
void SetZoneName(const wxString &aName)
Definition zone.h:161
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:864
A type-safe container of any type.
Definition ki_any.h:92
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformTrapezoidToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aDeltaX, int aDeltaY, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle or trapezoid to a polygon.
@ ROUND_ALL_CORNERS
All angles are rounded.
Placed instances and connectivity: component, symbol and pad instances, nets, nodes,...
Symbols, components and gates, embedded in designs or the single object of a library item stream.
The design document and the design parameter tables the importers use.
Title block and page size, shared by the board and schematic builders.
Loading designs, library items and projects.
Easy-PC / DesignSpark items to KiCad board items, shared by the board builder and the ....
Easy-PC's text measurement, so text lands where Easy-PC draws it.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:473
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
std::string source
bool IsUserLayer(PCB_LAYER_ID aLayerId)
Test whether a layer is a non copper and a non tech layer.
Definition layer_ids.h:826
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ B_Mask
Definition layer_ids.h:94
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:27
std::unique_ptr< FOOTPRINT > ConvertFootprint(const SOURCE_SYMBOL &aSymbol, const LAYER_MAPPER &aLayers, const LIB_ID &aId, const SOURCE_PCB_COMPONENT *aComponent, std::map< const SOURCE_FREE_PAD *, PAD * > *aPadMap)
A footprint in symbol coordinates.
SHAPE_POLY_SET ShapeToPolySet(const SOURCE_DESIGN_SHAPE &aShape, const FRAME &aFrame)
A closed shape and its cutouts as an outline with holes.
std::unique_ptr< PAD > CreatePad(FOOTPRINT *aParent, const SOURCE_FREE_PAD &aPad, const SOURCE_PAD_STYLE &aStyle, const FRAME &aFrame, const LAYER_MAPPER &aLayers)
A pad with its style's per-layer exceptions; a mask or paste exception becomes a separate opening on ...
PCB_TEXT * AddText(BOARD_ITEM_CONTAINER &aContainer, const SOURCE_TEXT_POSITION &aPosition, const wxString &aText, const FRAME &aFrame, const LAYER_MAPPER &aLayers)
ARC_FORM ArcForm(const POINT32 &aStart, const POINT32 &aEnd, int32_t aArcAngle, bool aAnticlockwise, const FRAME &aFrame)
std::vector< PCB_SHAPE * > AddShapeItem(BOARD_ITEM_CONTAINER &aContainer, const SOURCE_SHAPE_ITEM &aItem, const FRAME &aFrame, const LAYER_MAPPER &aLayers, PCB_LAYER_ID aLayer)
Add a shape item as one filled polygon, a circle, or one shape per span; aLayer overrides the item's ...
wxString BuildBoard(const DESIGN_DOCUMENT &aDocument, BOARD &aBoard, REPORTER *aReporter, const LAYER_MAPPING_HANDLER &aLayerMapping)
Fill aBoard from a loaded Easy-PC / DesignSpark PCB design.
SHAPE_POLY_SET ShapeItemArea(const SOURCE_SHAPE_ITEM &aItem, const FRAME &aFrame, int aMaxError)
The copper a shape item plots: its filled region and every span stroked at the line width with round ...
@ DP_MIN_SOLDER_MASK_TO_TRACK
PAGE_INFO PageForExtents(const BOX2L &aExtentsNm)
Easy-PC stores no page size, so the first of A4 to A0 then A to E, landscape before portrait,...
std::vector< T * > TypedItems(const OBJECT *aList)
The items of ListItems that are a T, in order.
@ FIXED
not ABSOLUTE, which wingdi.h defines
wxString ToKiCadMarkup(const wxString &aText)
A displayed string in KiCad's markup.
PAD_SHAPE
Pad style shape, also the drill and exception shape.
void ApplyTextPosition(EDA_TEXT &aText, const SOURCE_TEXT_POSITION &aPos, const SCH_FRAME &aFrame, bool aKeepUpright, const wxString &aMeasured)
Place any KiCad text as the source position says: anchor, angle, mirror, justification and style.
constexpr int64_t DsuToNm(int64_t aDsu)
void FillTitleBlock(const DESIGN_DOCUMENT &aDoc, TITLE_BLOCK &aTitleBlock)
Fill a title block from the design's SummaryInformation property set: title from Title,...
std::optional< wxString > EscapeStringLiteral(const wxString &aText)
Escape text for use between the quotes of an expression string.
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ CHAMFERED_RECT
Definition padstack.h:61
@ ROUNDRECT
Definition padstack.h:58
@ RECTANGLE
Definition padstack.h:55
Class to handle a set of BOARD_ITEMs.
std::function< std::map< wxString, PCB_LAYER_ID >(const std::vector< INPUT_LAYER_DESC > &)> LAYER_MAPPING_HANDLER
Pointer to a function that takes a map of source and KiCad layers and returns a re-mapped version.
@ RPT_SEVERITY_WARNING
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
std::unique_ptr< OBJECT > Design
design root, not in the load array
Root of every deserialized object.
A point read as two int32 values.
SOURCE_SCM_COMPONENT * Schematic
OBJECT * Parent
null is the document in a design, nothing in a library item
int32_t Param(int aIndex, int32_t aDefault=0) const
The value at aIndex, or aDefault where the stored array is shorter, as the accessors do.
The document: OLE items, then the design.
SOURCE_DESIGN_PARAMETERS DesignParameters
after 8000
Every drawn shape, pour and dimension part.
A pad of a symbol definition.
Also the start of a dimension.
Layer type names determine silk, mask and paste roles.
int32_t TentedVias
0 none, 1 all, 2 per via
OBJECT * NetClass
the design's first class when the file stores none
The package half of a component.
int32_t ArcAngle
swept angle, 0 for a straight span
bool IsClosed() const
The last vertex links back to the first (formats 1 and 2) or the closed byte is set (format 3)
std::vector< OBJECT * > Segments
the vertex list as read
values maps (a << 16) | b of SPACING_ITEM bits to a clearance
std::map< int32_t, int32_t > Values
A placed footprint (gate -1) or a placed schematic gate.
OBJECT * ValuePositions
below 10003 built from the stored symbol name
Footprints and schematic symbols alike.
OBJECT * Style
track style of the span leaving this vertex
OBJECT * Layer
null in a schematic
A span as KiCad can hold it: a true arc, or a polyline that is the two ends of a straight span or poi...
std::vector< VECTOR2I > Points
Native to KiCad coordinates: scale by 100 nm, flip Y and move the native origin to the KiCad offset.
static EDA_ANGLE Angle(int32_t aMilliDegrees)
VECTOR2I ToKiCad(int32_t aX, int32_t aY) const
int Length(int64_t aLength) const
netlist clear()
int clearance
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< int64_t > VECTOR2L
Definition vector2d.h:709
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46