KiCad PCB EDA Suite
Loading...
Searching...
No Matches
target3001_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
21
22#include <algorithm>
23#include <cmath>
24
25#include <base_units.h>
26#include <board.h>
29#include <eda_units.h>
30#include <footprint.h>
32#include <geometry/shape_rect.h>
33#include <ki_exception.h>
34#include <macros.h>
35#include <netinfo.h>
36#include <pad.h>
37#include <pcb_shape.h>
38#include <pcb_text.h>
39#include <pcb_track.h>
40#include <reporter.h>
41#include <zone.h>
42
43#include <wx/tokenzr.h>
44
49using TARGET3001::ARC;
62
63namespace
64{
65
66// Corner chamfer of an octagonal pad as a fraction of its smaller side
67constexpr double OCTAGON_CHAMFER_RATIO = 0.25;
68
69EDA_ANGLE angle( float aDegrees )
70{
71 return EDA_ANGLE( double( aDegrees ), DEGREES_T );
72}
73
74
75LINE_STYLE lineStyle( uint8_t aDash )
76{
77 switch( aDash )
78 {
79 case 1: return LINE_STYLE::DASH;
80 case 2: return LINE_STYLE::DASHDOT;
81 case 3: return LINE_STYLE::DASHDOTDOT;
82 case 4: return LINE_STYLE::DOT;
83 default: return LINE_STYLE::SOLID;
84 }
85}
86
87
89std::vector<VECTOR2I> parsePolyPad( const std::string& aValue )
90{
91 std::vector<VECTOR2I> pts;
92 wxStringTokenizer tokens( wxString( aValue ), wxS( ";" ), wxTOKEN_STRTOK );
93
94 while( tokens.HasMoreTokens() )
95 {
96 wxString pair = tokens.GetNextToken();
97 long x = 0;
98 long y = 0;
99
100 if( !pair.BeforeFirst( ',' ).ToLong( &x ) || !pair.AfterFirst( ',' ).ToLong( &y ) )
101 return {};
102
103 pts.emplace_back( int( x ), int( y ) );
104 }
105
106 return pts;
107}
108
109
111int mostCommon( const std::map<int, int>& aCounts )
112{
113 auto it = std::max_element( aCounts.begin(), aCounts.end(),
114 []( const auto& a, const auto& b )
115 {
116 return a.second < b.second;
117 } );
118
119 return it->first;
120}
121
122
124int padFillGap( const PAD& aPad, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aFill, int aReach )
125{
126 int gap = 0;
127 ::PAD_SHAPE shape = aPad.GetShape( aLayer );
128
129 // The vendor may knock out an octagon around a rectangular pad, so only side midpoints agree; round
130 // knockouts are polygons around the pad that touch it only at their tangent points
132 return aFill.Collide( aPad.GetEffectiveShape( aLayer ).get(), aReach, &gap ) ? gap : 0;
133
134 VECTOR2I half = aPad.GetSize( aLayer ) / 2;
135 int best = 0;
136
137 for( VECTOR2I side :
138 { VECTOR2I( half.x, 0 ), VECTOR2I( -half.x, 0 ), VECTOR2I( 0, half.y ), VECTOR2I( 0, -half.y ) } )
139 {
140 RotatePoint( side, aPad.GetOrientation() );
141
142 SHAPE_RECT probe( aPad.ShapePos( aLayer ) + side, 1, 1 );
143
144 if( !aFill.Collide( &probe, aReach, &gap ) || gap <= 0 )
145 continue;
146
147 best = best ? std::min( best, gap ) : gap;
148 }
149
150 return best;
151}
152
153} // namespace
154
155
157 REPORTER* aReporter ) :
158 m_board( aBoard ),
159 m_project( aProject ),
160 m_reporter( aReporter )
161{
162}
163
164
166{
168 buildNets();
178
179 // A pour runs up to a contour stroke without clearance; KiCad has one edge clearance per board
181 m_board->GetDesignSettings().m_CopperEdgeClearance = 0;
182
183 // BOARD::SetProject keeps importer settings only when they are flagged as loaded
184 m_board->m_LegacyDesignSettingsLoaded = true;
185
186 // TARGET 3001! places the board around its own origin with Y up; move it onto the sheet
187 BOX2I bbox = m_board->GetBoardEdgesBoundingBox();
188
189 if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
190 bbox = m_board->ComputeBoundingBox( false );
191
192 const int margin = pcbIUScale.mmToIU( 20 );
193 m_board->Move( VECTOR2I( margin - bbox.GetX(), margin - bbox.GetY() ) );
194}
195
196
198{
199 if( aLayer < 0 || aLayer >= BOARD_LAYER_COUNT )
200 return LAYER_FUNCTION::OTHER;
201
202 return LAYER_FUNCTION( m_project.layerFunctions[aLayer] );
203}
204
205
206bool TARGET3001_PCB_BUILDER::isCopper( int aLayer ) const
207{
208 LAYER_FUNCTION f = LayerFunction( aLayer );
209
210 return f == LAYER_FUNCTION::COPPER_BOTTOM || f == LAYER_FUNCTION::COPPER_INSIDE
211 || f == LAYER_FUNCTION::COPPER_TOP;
212}
213
214
215static wxString ruleMm( int aValue )
216{
217 return wxString::FromUTF8( EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aValue ) ) + wxS( "mm" );
218}
219
220
222static wxString ruleLiteral( const wxString& aValue )
223{
224 wxString text = aValue;
225 text.Replace( wxS( "\\" ), wxS( "\\\\" ) );
226 text.Replace( wxS( "'" ), wxS( "\\\\'" ) );
227 text.Replace( wxS( "\"" ), wxS( "\\\"" ) );
228 return wxS( "'" ) + text + wxS( "'" );
229}
230
231
233{
234 if( m_pourLayers.empty() && !m_hasPolygonPours )
235 return;
236
237 std::map<int, int> boardCounts;
238 std::map<int, std::vector<wxString>> netsByClearance;
239
240 for( const auto& [signal, counts] : m_signalClearances )
241 {
242 NETINFO_ITEM* item = net( signal );
243
244 if( !item || item->GetNetCode() <= 0 || counts.empty() )
245 continue;
246
247 netsByClearance[mostCommon( counts )].push_back( item->GetNetname() );
248
249 for( const auto& [clearance, count] : counts )
250 boardCounts[clearance] += count;
251 }
252
253 if( boardCounts.empty() )
254 return;
255
256 auto addRule = [&]( const wxString& aName, int aClearance, const wxString& aCondition )
257 {
258 m_designRules += wxString::Format( wxS( "\n(rule \"%s\"\n (constraint clearance (min %s))\n"
259 " (condition \"%s\"))\n" ),
260 aName, ruleMm( aClearance ), aCondition );
261 };
262
263 // An area keeps each element's own clearance, which KiCad tracks and vias cannot hold
264 int base = mostCommon( boardCounts );
265 m_designRules = wxS( "(version 1)\n" );
266 addRule( wxS( "TARGET 3001! copper areas" ), base, wxS( "A.Type == 'Zone'" ) );
267
268 for( const auto& [clearance, nets] : netsByClearance )
269 {
270 if( clearance == base )
271 continue;
272
273 wxString condition;
274
275 for( const wxString& name : nets )
276 {
277 if( !condition.IsEmpty() )
278 condition += wxS( " || " );
279
280 condition += wxS( "B.NetName == " ) + ruleLiteral( name );
281 }
282
283 addRule( wxS( "TARGET 3001! copper areas to " ) + ruleMm( clearance ) + wxS( " signals" ), clearance,
284 wxS( "A.Type == 'Zone' && (" ) + condition + wxS( ")" ) );
285 }
286}
287
288
290{
291 if( m_pourLayers.empty() )
292 return;
293
294 if( m_designRules.IsEmpty() )
295 m_designRules = wxS( "(version 1)\n" );
296
297 // Later rules win, so the NO_AURA layers come last
298 m_designRules += wxS( "\n(rule \"TARGET 3001! areas join own pads and vias\"\n"
299 " (condition \"A.hasCustomProperty('TARGET3001_AURA') "
300 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
301 " (constraint zone_connection solid))\n" );
302
303 // Require at least one spoke to match the import
304 m_designRules += wxS( "\n(rule \"TARGET 3001! area spokes\"\n"
305 " (condition \"B.hasCustomProperty('TARGET3001_AREA')\")\n"
306 " (constraint min_resolved_spokes 1))\n" );
307
308 for( int aura : m_auraValues )
309 {
310 m_designRules += wxString::Format( wxS( "\n(rule \"TARGET 3001! aura %s\"\n"
311 " (condition \"A.customProperty('TARGET3001_AURA') == '%d' "
312 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
313 " (constraint zone_connection none)\n"
314 " (constraint physical_clearance (min %s)))\n" ),
315 ruleMm( aura ), aura, ruleMm( aura ) );
316 }
317
318 for( PCB_LAYER_ID layer : m_noAuraLayers )
319 {
320 wxString name = LSET::Name( layer );
321
322 m_designRules += wxString::Format( wxS( "\n(rule \"TARGET 3001! no aura on %s\"\n"
323 " (layer \"%s\")\n"
324 " (condition \"A.customProperty('TARGET3001_NO_AURA') == '*,%s,*' "
325 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
326 " (constraint zone_connection solid)\n"
327 " (constraint physical_clearance (min 0mm)))\n" ),
328 name, name, name );
329 }
330}
331
332
334{
335 aItem.SetCustomProperty( wxS( "TARGET3001_AURA" ), wxString::Format( wxS( "%d" ), aAura ) );
336
337 if( aAura <= 0 )
338 return;
339
340 m_auraValues.insert( aAura );
341
342 // Names are comma delimited both sides so a rule can match one layer with a wildcard
343 wxString layers;
344
345 if( const std::string* list = aBase.FindProp( "NO_AURA" ) )
346 {
347 wxStringTokenizer tokens( wxString::FromUTF8( *list ), wxS( "," ) );
348
349 while( tokens.HasMoreTokens() )
350 {
351 long layer = 0;
352
353 if( !tokens.GetNextToken().Trim().Trim( false ).ToLong( &layer ) || !isCopper( int( layer ) ) )
354 continue;
355
356 if( std::optional<PCB_LAYER_ID> cu = mapLayer( int( layer ) ) )
357 {
358 layers += ( layers.IsEmpty() ? wxS( "," ) : wxS( "" ) ) + LSET::Name( *cu ) + wxS( "," );
359 m_noAuraLayers.insert( *cu );
360 }
361 }
362 }
363
364 if( !layers.IsEmpty() )
365 aItem.SetCustomProperty( wxS( "TARGET3001_NO_AURA" ), layers );
366}
367
368
370{
371 std::vector<int> top;
372 std::vector<int> inner;
373 std::vector<int> bottom;
374
375 for( int layer = 0; layer < BOARD_LAYER_COUNT; layer++ )
376 {
377 switch( LayerFunction( layer ) )
378 {
379 case LAYER_FUNCTION::COPPER_TOP: top.push_back( layer ); break;
380 case LAYER_FUNCTION::COPPER_INSIDE: inner.push_back( layer ); break;
381 case LAYER_FUNCTION::COPPER_BOTTOM: bottom.push_back( layer ); break;
382 default: break;
383 }
384 }
385
386 m_copperStack.clear();
387 m_copperStack.insert( m_copperStack.end(), top.begin(), top.end() );
388 // Inner copper layer numbers increase towards the top side
389 m_copperStack.insert( m_copperStack.end(), inner.rbegin(), inner.rend() );
390 m_copperStack.insert( m_copperStack.end(), bottom.begin(), bottom.end() );
391
392 if( m_copperStack.size() > MAX_CU_LAYERS )
393 {
394 THROW_IO_ERROR( wxString::Format( _( "TARGET 3001! board has %zu copper layers; at most %d are supported." ),
395 m_copperStack.size(), MAX_CU_LAYERS ) );
396 }
397
398 int copperCount = std::max<int>( 2, m_copperStack.size() );
399
400 if( copperCount % 2 )
401 copperCount++;
402
403 m_board->SetCopperLayerCount( copperCount );
404
405 for( size_t i = 0; i < m_copperStack.size(); i++ )
406 {
407 PCB_LAYER_ID id;
408
409 // A board with only bottom copper keeps it on the bottom
410 if( i + 1 == m_copperStack.size() && !bottom.empty() )
411 id = B_Cu;
412 else if( i == 0 )
413 id = F_Cu;
414 else
415 id = BoardLayerFromLegacyId( int( i ) );
416
417 m_layerMap[m_copperStack[i]] = id;
418 }
419
420 for( int layer = 0; layer < BOARD_LAYER_COUNT && !m_contourLayer; layer++ )
421 {
422 if( LayerFunction( layer ) == LAYER_FUNCTION::OUTLINE )
423 m_contourLayer = layer;
424 }
425
426 int nextUser = 0;
427
428 for( int layer = 0; layer < BOARD_LAYER_COUNT; layer++ )
429 {
430 if( m_layerMap.count( layer ) )
431 continue;
432
433 std::optional<PCB_LAYER_ID> id;
434
435 switch( LayerFunction( layer ) )
436 {
437 case LAYER_FUNCTION::POSITION_BOTTOM: id = B_SilkS; break;
438 case LAYER_FUNCTION::POSITION_TOP: id = F_SilkS; break;
439 case LAYER_FUNCTION::NAMES_BOTTOM: id = B_SilkS; break;
440 case LAYER_FUNCTION::NAMES_TOP: id = F_SilkS; break;
441 case LAYER_FUNCTION::VALUES_BOTTOM: id = B_Fab; break;
442 case LAYER_FUNCTION::VALUES_TOP: id = F_Fab; break;
443 case LAYER_FUNCTION::MASK_BOTTOM: id = B_Mask; break;
444 case LAYER_FUNCTION::MASK_TOP: id = F_Mask; break;
445 case LAYER_FUNCTION::PASTE_BOTTOM: id = B_Paste; break;
446 case LAYER_FUNCTION::PASTE_TOP: id = F_Paste; break;
447 case LAYER_FUNCTION::GLUE_BOTTOM: id = B_Adhes; break;
448 case LAYER_FUNCTION::GLUE_TOP: id = F_Adhes; break;
449 // Milling is a tool path around the outline, so it stays on its own user layer
450 case LAYER_FUNCTION::OUTLINE: id = Edge_Cuts; break;
451 case LAYER_FUNCTION::DIMENSIONING: id = Dwgs_User; break;
452 case LAYER_FUNCTION::DRILL_PLAN: id = Cmts_User; break;
453
454 // Pour areas and keepouts become zones; air wires are derived data
455 case LAYER_FUNCTION::AREA_BOTTOM:
456 case LAYER_FUNCTION::AREA_INSIDE:
457 case LAYER_FUNCTION::AREA_TOP:
458 case LAYER_FUNCTION::DELETION_BOTTOM:
459 case LAYER_FUNCTION::DELETION_INSIDE:
460 case LAYER_FUNCTION::DELETION_TOP:
461 case LAYER_FUNCTION::AIR_WIRES:
462 break;
463
464 default:
465 if( nextUser < 9 )
466 id = static_cast<PCB_LAYER_ID>( User_1 + 2 * nextUser++ );
467 else
468 id = Cmts_User;
469
470 break;
471 }
472
473 if( id )
474 m_layerMap[layer] = *id;
475 }
476
477 LSET enabled = m_board->GetEnabledLayers();
478
479 for( const auto& [target, id] : m_layerMap )
480 enabled.set( id );
481
482 m_board->SetEnabledLayers( enabled );
483 m_board->SetVisibleLayers( enabled );
484
485 for( const auto& [target, id] : m_layerMap )
486 {
487 if( id >= User_1 && id <= User_9 )
488 m_board->SetLayerName( id, wxString::Format( wxS( "Target layer %d" ), target ) );
489 }
490}
491
492
493std::optional<PCB_LAYER_ID> TARGET3001_PCB_BUILDER::mapLayer( int aLayer ) const
494{
495 auto it = m_layerMap.find( aLayer );
496
497 if( it == m_layerMap.end() )
498 return std::nullopt;
499
500 return it->second;
501}
502
503
504std::optional<PCB_LAYER_ID> TARGET3001_PCB_BUILDER::pourCopperLayer( int aLayer ) const
505{
506 int defaultCopper;
507
508 switch( LayerFunction( aLayer ) )
509 {
510 case LAYER_FUNCTION::AREA_BOTTOM:
511 case LAYER_FUNCTION::AREA_INSIDE:
512 case LAYER_FUNCTION::AREA_TOP:
513 defaultCopper = aLayer + 2;
514 break;
515
516 case LAYER_FUNCTION::DELETION_BOTTOM:
517 case LAYER_FUNCTION::DELETION_INSIDE:
518 case LAYER_FUNCTION::DELETION_TOP:
519 defaultCopper = aLayer + 1;
520 break;
521
522 default:
523 return std::nullopt;
524 }
525
526 int copper = m_project.layerAssociations[aLayer];
527
528 // An association that names no copper layer is unset and the default pairing applies
529 if( copper == NO_ASSOCIATION || !isCopper( copper ) )
530 copper = defaultCopper;
531
532 if( copper >= BOARD_LAYER_COUNT || !isCopper( copper ) )
533 return std::nullopt;
534
535 return mapLayer( copper );
536}
537
538
539std::optional<PCB_LAYER_ID> TARGET3001_PCB_BUILDER::polygonLayer( const TARGET3001::POLYGON_POUR& aPoly ) const
540{
541 std::optional<PCB_LAYER_ID> layer = mapLayer( aPoly.layer );
542
543 if( !layer || !IsCopperLayer( *layer ) || aPoly.outline.size() < 3 )
544 return std::nullopt;
545
546 return layer;
547}
548
549
551{
552 for( size_t i = 0; i < m_project.signals.size(); i++ )
553 {
554 const ELEMENT& e = m_project.signals[i];
555
556 if( e.type != ELEMENT_TYPE::SIGNAL || !e.signal )
557 continue;
558
559 wxString name = ToWx( e.signal->name );
560
561 if( name.IsEmpty() )
562 name = wxString::Format( wxS( "Net-%zu" ), i + 1 );
563
564 // Net names must be unique in KiCad
565 if( m_board->FindNet( name ) )
566 name = wxString::Format( wxS( "%s_%zu" ), name, i + 1 );
567
568 m_nets[e.base.signal] = m_board->FindOrAddNet( name, -1, ADD_MODE::APPEND );
569 }
570}
571
572
574{
575 auto it = m_nets.find( aSignal );
576 return it == m_nets.end() ? nullptr : it->second;
577}
578
579
581{
582 for( const ELEMENT& e : m_project.components )
583 {
584 if( e.type == ELEMENT_TYPE::COMPONENT && e.component )
585 addFootprint( e );
586 }
587}
588
589
591{
592 const TARGET3001::COMPONENT& comp = *aComponent.component;
593
594 // A component is on the board only when its package heads the list and sits on a position layer;
595 // anything else exists only in the schematic
596 if( comp.packageItems.empty() )
597 return;
598
599 const ELEMENT* placement = &comp.packageItems.front();
600
601 if( placement->type != ELEMENT_TYPE::PACKAGE || !placement->package )
602 return;
603
604 LAYER_FUNCTION placementLayer = LayerFunction( placement->base.layer );
605
606 if( placementLayer != LAYER_FUNCTION::POSITION_TOP && placementLayer != LAYER_FUNCTION::POSITION_BOTTOM )
607 return;
608
609 const PACKAGE& pkg = *placement->package;
610
611 FOOTPRINT* fp = new FOOTPRINT( m_board );
612 m_board->Add( fp, ADD_MODE::APPEND );
613
614 fp->SetFPIDAsString( wxS( "Target3001:" ) + ToWx( pkg.package ) );
615 fp->SetPosition( toKi( placement->base.x, placement->base.y ) );
616 fp->SetOrientation( angle( pkg.direction ) );
617
618 // Items are stored already flipped, so only the side changes here
619 if( pkg.bottomSide )
620 fp->SetLayer( B_Cu );
621
622 wxString reference = ToWx( comp.prefix ).Trim().Trim( false );
623 uint16_t number = comp.referenceExtension.value_or( comp.referenceNumber );
624
625 if( number )
626 reference << number;
627
628 fp->SetReference( reference );
629 fp->SetValue( ToWx( comp.value ) );
630 fp->Reference().SetVisible( false );
631 fp->Value().SetVisible( false );
632
633 for( const ELEMENT& item : comp.packageItems )
634 {
635 if( &item != placement )
636 addItem( item, fp, fp, false );
637 }
638}
639
640
642{
643 std::vector<const ELEMENT*> spokes;
644
645 for( const ELEMENT& e : m_project.signals )
646 {
647 if( e.type != ELEMENT_TYPE::SIGNAL || !e.signal )
648 continue;
649
650 std::set<int64_t> polygons;
651
652 for( const TARGET3001::POLYGON_POUR& poly : e.signal->polygons )
653 {
654 if( polygonLayer( poly ) )
655 polygons.insert( poly.id );
656 }
657
658 for( const ELEMENT& t : e.signal->tracks )
659 {
660 // Thermal spokes are generated by the vendor area fill; KiCad zones make their own
661 if( t.base.FlagProp( "THERMAL_SNIPPET" ) )
662 continue;
663
664 // A polygon's stored fill becomes the fill of its zone
665 if( std::optional<int64_t> id = t.base.PolygonId(); id && polygons.count( *id ) )
666 {
667 bool spoke = t.base.FlagProp( "THERMAL_LIGAMENT" );
668
669 if( !( t.base.flags & 1 ) )
670 elementOutline( t, spoke ? m_polygonSpokes[*id] : m_polygonFills[*id] );
671
672 continue;
673 }
674
675 // Old style areas store their thermal spokes as flat status 0 strokes
676 if( t.type == ELEMENT_TYPE::LINE && t.base.status == 0 && !t.line.roundEnds )
677 {
678 spokes.push_back( &t );
679 continue;
680 }
681
682 addItem( t, m_board, nullptr, true );
683 }
684 }
685
686 buildAreaSpokes( spokes );
687
688 for( auto& [key, polys] : m_copperFills )
689 {
690 polys.Simplify();
691
692 for( int i = 0; i < polys.OutlineCount(); i++ )
693 {
694 PCB_SHAPE* shape = new PCB_SHAPE( m_board, SHAPE_T::POLY );
695 shape->SetPolyShape( SHAPE_POLY_SET( polys.Polygon( i ) ) );
696 shape->SetFilled( true );
698 shape->SetLayer( PCB_LAYER_ID( key.second ) );
699 shape->SetNet( net( uint16_t( key.first ) ) );
700 m_board->Add( shape, ADD_MODE::APPEND );
701 }
702 }
703}
704
705
706void TARGET3001_PCB_BUILDER::buildAreaSpokes( const std::vector<const ELEMENT*>& aSpokes )
707{
708 std::set<std::pair<uint16_t, PCB_LAYER_ID>> areas;
709 std::map<int, std::vector<PAD*>> padsByNet;
710 std::map<int, std::vector<PCB_VIA*>> viasByNet;
711
712 for( const POUR_AREA& area : m_pourAreas )
713 areas.emplace( area.signal, area.layer );
714
715 for( FOOTPRINT* fp : m_board->Footprints() )
716 {
717 for( PAD* pad : fp->Pads() )
718 padsByNet[pad->GetNetCode()].push_back( pad );
719 }
720
721 for( PCB_TRACK* track : m_board->Tracks() )
722 {
723 if( track->Type() == PCB_VIA_T )
724 viasByNet[track->GetNetCode()].push_back( static_cast<PCB_VIA*>( track ) );
725 }
726
727 std::map<PAD*, const ELEMENT*> padSpokes;
728 std::set<PCB_VIA*> spokedVias;
729
730 for( const ELEMENT* spoke : aSpokes )
731 {
732 const ELEMENT_BASE& b = spoke->base;
733 std::optional<PCB_LAYER_ID> layer = mapLayer( b.layer );
734 NETINFO_ITEM* item = net( b.signal );
735 VECTOR2I start = toKi( b.x, b.y );
736 bool relief = false;
737
738 if( layer && IsCopperLayer( *layer ) && item && areas.count( { b.signal, *layer } ) )
739 {
740 for( PAD* pad : padsByNet[item->GetNetCode()] )
741 {
742 if( pad->IsOnLayer( *layer ) && pad->GetEffectiveShape( *layer )->Collide( start ) )
743 {
744 const ELEMENT*& widest = padSpokes[pad];
745
746 if( !widest || spoke->line.width > widest->line.width )
747 widest = spoke;
748
749 relief = true;
750 break;
751 }
752 }
753
754 for( PCB_VIA* via : viasByNet[item->GetNetCode()] )
755 {
756 if( !relief && via->IsOnLayer( *layer ) && via->GetEffectiveShape( *layer )->Collide( start ) )
757 {
758 spokedVias.insert( via );
759 relief = true;
760 }
761 }
762 }
763
764 if( !relief )
765 addItem( *spoke, m_board, nullptr, true );
766 }
767
768 for( const auto& [pad, spoke] : padSpokes )
769 {
770 VECTOR2I dir = toKi( spoke->line.x2, spoke->line.y2 ) - toKi( spoke->base.x, spoke->base.y );
771 RotatePoint( dir, -pad->GetOrientation() );
772
773 // Pad spokes repeat every 90 degrees starting at the spoke angle
774 double degrees = std::fmod( EDA_ANGLE( VECTOR2D( dir ) ).AsDegrees() + 360.0, 90.0 );
775
776 // Untagged, the pad joins its area and the local connection picks spokes over solid
777 pad->SetCustomProperty( wxS( "TARGET3001_AURA" ), wxS( "0" ) );
778 pad->SetLocalZoneConnection( ZONE_CONNECTION::THERMAL );
779 pad->SetLocalThermalSpokeWidthOverride( spoke->line.width );
780 pad->SetThermalSpokeAngle( EDA_ANGLE( degrees, DEGREES_T ) );
781
782 if( std::optional<int> aura = pad->GetLocalClearance(); aura && *aura > 0 )
783 pad->SetLocalThermalGapOverride( aura );
784 }
785
786 // Vias get no spokes in a solid fill, so a spoked via joins its area solidly
787 for( PCB_VIA* via : spokedVias )
788 via->SetCustomProperty( wxS( "TARGET3001_AURA" ), wxS( "0" ) );
789}
790
791
793{
794 for( const ELEMENT& e : m_project.boardItems )
795 addItem( e, m_board, nullptr, false );
796}
797
798
800{
801 std::map<std::pair<uint16_t, PCB_LAYER_ID>, SHAPE_POLY_SET> pours;
802
803 for( POUR_AREA& area : m_pourAreas )
804 pours[{ area.signal, area.layer }].Append( area.outline );
805
806 for( auto& [key, outline] : pours )
807 {
808 outline.Simplify();
809
810 for( int i = 0; i < outline.OutlineCount(); i++ )
811 {
812 ZONE* zone = new ZONE( m_board );
813 zone->SetLayer( key.second );
814 zone->SetNet( net( key.first ) );
815
816 // Unconnected islands of an area stay filled
818
819 // Each foreign element carves the fill by its own clearance, which only rules can hold; a zero
820 // local clearance defers to them
821 zone->SetLocalClearance( 0 );
822 zone->SetCustomProperty( wxS( "TARGET3001_AREA" ), wxS( "1" ) );
823 m_pourLayers.insert( key );
824
825 // Keep holes; a ring of edge strokes must not become a solid area
826 *zone->Outline() = SHAPE_POLY_SET( outline.Polygon( i ) );
827 m_board->Add( zone, ADD_MODE::APPEND );
828 }
829 }
830
831 for( auto& [layer, keepout] : m_pourKeepouts )
832 {
833 keepout.Simplify();
834
835 for( int i = 0; i < keepout.OutlineCount(); i++ )
836 {
837 ZONE* zone = new ZONE( m_board );
838 zone->SetIsRuleArea( true );
839 zone->SetDoNotAllowZoneFills( true );
840 zone->SetDoNotAllowTracks( false );
841 zone->SetDoNotAllowVias( false );
842 zone->SetDoNotAllowPads( false );
843 zone->SetDoNotAllowFootprints( false );
844 zone->SetLayer( PCB_LAYER_ID( layer ) );
845 *zone->Outline() = SHAPE_POLY_SET( keepout.Polygon( i ) );
846 m_board->Add( zone, ADD_MODE::APPEND );
847 }
848 }
849}
850
851
853{
854 for( const ELEMENT& e : m_project.signals )
855 {
856 if( e.type != ELEMENT_TYPE::SIGNAL || !e.signal )
857 continue;
858
859 for( const TARGET3001::POLYGON_POUR& poly : e.signal->polygons )
860 {
861 std::optional<PCB_LAYER_ID> layer = polygonLayer( poly );
862
863 if( !layer )
864 continue;
865
866 ZONE* zone = new ZONE( m_board );
867 zone->SetLayer( *layer );
868 zone->SetNet( net( e.base.signal ) );
869 zone->Outline()->NewOutline();
870
871 // The outline repeats its first vertex at the end; KiCad closes it implicitly
872 size_t count = poly.outline.size();
873
874 if( poly.outline.front() == poly.outline.back() )
875 count--;
876
877 for( size_t i = 0; i < count; i++ )
878 zone->Outline()->Append( toKi( poly.outline[i].first, poly.outline[i].second ) );
879
880 // An unset stroke width falls back to the vendor default
881 int width = poly.width > 0 ? poly.width : pcbIUScale.mmToIU( 0.15 );
882
883 zone->SetMinThickness( width );
884 zone->SetThermalReliefSpokeWidth( 2 * width );
887 zone->SetAssignedPriority( unsigned( std::max( 0, poly.rank ) ) );
888 zone->SetLocalClearance( 0 );
889
890 if( poly.edgeClearance > 0 )
891 {
892 zone->SetCustomProperty( wxS( "TARGET3001_EDGE_CLEARANCE" ),
893 wxString::Format( wxS( "%d" ), poly.edgeClearance ) );
895 }
896
897 if( poly.aura > 0 )
898 {
899 zone->SetCustomProperty( wxS( "TARGET3001_POLYGON_AURA" ), wxString::Format( wxS( "%d" ), poly.aura ) );
900 m_polygonAuras.insert( poly.aura );
901 }
902
903 // The stored fill shows the board as the vendor left it until the zones are refilled
904 SHAPE_POLY_SET& body = m_polygonFills[poly.id];
905 SHAPE_POLY_SET& spokes = m_polygonSpokes[poly.id];
906
907 if( !body.IsEmpty() )
908 {
909 body.Simplify();
910 spokes.Simplify();
911
912 SHAPE_POLY_SET fill = body;
913 fill.BooleanAdd( spokes );
914 fill.Fracture();
915 zone->SetFilledPolysList( *layer, fill );
916 zone->SetIsFilled( true );
917 zone->SetNeedRefill( false );
918 }
919
920 if( poly.thermals )
921 m_polygonZones.emplace_back( zone, poly.id );
922
923 m_hasPolygonPours = true;
924 m_board->Add( zone, ADD_MODE::APPEND );
925 }
926 }
927}
928
929
931{
932 // Vendor knockouts stand off a pad by a few um more than its gap, well below any gap a designer enters
933 const int step = pcbIUScale.mmToIU( 0.01 );
934 const int reach = pcbIUScale.mmToIU( 5 );
935
936 std::map<PAD*, std::map<ZONE*, int>> padGaps;
937 std::map<ZONE*, std::map<int, int>> zoneCounts;
938 std::map<int, int> boardCounts;
939
940 for( const auto& [zone, id] : m_polygonZones )
941 {
942 const SHAPE_POLY_SET& body = m_polygonFills[id];
943 const SHAPE_POLY_SET& spokes = m_polygonSpokes[id];
944 PCB_LAYER_ID layer = zone->GetLayer();
945
946 for( FOOTPRINT* fp : m_board->Footprints() )
947 {
948 for( PAD* pad : fp->Pads() )
949 {
950 if( pad->GetNetCode() != zone->GetNetCode() || !pad->FlashLayer( layer )
951 || !zone->Outline()->Contains( pad->GetPosition() ) )
952 {
953 continue;
954 }
955
956 // Only a pad the fill reaches through spokes shows its thermal gap
957 if( !spokes.Collide( pad->GetEffectiveShape( layer ).get() ) )
958 continue;
959
960 int gap = KiROUND( double( padFillGap( *pad, layer, body, reach ) ) / step ) * step;
961
962 if( gap <= 0 )
963 continue;
964
965 padGaps[pad][zone] = gap;
966 zoneCounts[zone][gap]++;
967 boardCounts[gap]++;
968 }
969 }
970 }
971
972 if( boardCounts.empty() )
973 return;
974
975 // A zone without spoked pads takes the board's gap, so a refill treats its pads alike
976 for( const auto& [zone, id] : m_polygonZones )
977 {
978 auto it = zoneCounts.find( zone );
979 zone->SetThermalReliefGap( mostCommon( it != zoneCounts.end() ? it->second : boardCounts ) );
980 }
981
982 std::map<wxString, int> references;
983
984 for( FOOTPRINT* fp : m_board->Footprints() )
985 references[fp->GetReference()]++;
986
987 std::map<int, std::vector<wxString>> footprintsByGap;
988
989 for( FOOTPRINT* fp : m_board->Footprints() )
990 {
991 std::map<PAD*, int> overrides;
992 std::set<int> gaps;
993
994 for( PAD* pad : fp->Pads() )
995 {
996 auto it = padGaps.find( pad );
997
998 if( it == padGaps.end() )
999 continue;
1000
1001 std::map<int, int> counts;
1002 bool differs = false;
1003
1004 for( const auto& [zone, gap] : it->second )
1005 {
1006 counts[gap]++;
1007 gaps.insert( gap );
1008 differs |= gap != zone->GetThermalReliefGap();
1009 }
1010
1011 if( differs )
1012 overrides[pad] = mostCommon( counts );
1013 }
1014
1015 if( overrides.empty() )
1016 continue;
1017
1018 // A footprint rule needs one gap for all its measured pads and a reference no other footprint shares
1019 const wxString& ref = fp->GetReference();
1020
1021 if( gaps.size() == 1 && !ref.IsEmpty() && references[ref] == 1 )
1022 {
1023 footprintsByGap[*gaps.begin()].push_back( ref );
1024 continue;
1025 }
1026
1027 for( const auto& [pad, gap] : overrides )
1028 pad->SetLocalThermalGapOverride( gap );
1029 }
1030
1031 if( footprintsByGap.empty() )
1032 return;
1033
1034 if( m_designRules.IsEmpty() )
1035 m_designRules = wxS( "(version 1)\n" );
1036
1037 // Pads inherit a thermal gap rule that matches their footprint
1038 for( const auto& [gap, refs] : footprintsByGap )
1039 {
1040 wxString condition;
1041
1042 for( const wxString& ref : refs )
1043 {
1044 if( !condition.IsEmpty() )
1045 condition += wxS( " || " );
1046
1047 condition += wxS( "A.Reference == " ) + ruleLiteral( ref );
1048 }
1049
1050 m_designRules += wxString::Format( wxS( "\n(rule \"TARGET 3001! thermal gap %s\"\n"
1051 " (condition \"A.Type == 'Footprint' && (%s)\")\n"
1052 " (constraint thermal_relief_gap (min %s)))\n" ),
1053 ruleMm( gap ), condition, ruleMm( gap ) );
1054 }
1055}
1056
1057
1059{
1060 if( m_polygonEdgeClearances.empty() && m_polygonAuras.empty() )
1061 return;
1062
1063 if( m_designRules.IsEmpty() )
1064 m_designRules = wxS( "(version 1)\n" );
1065
1067 {
1068 m_designRules += wxString::Format( wxS( "\n(rule \"TARGET 3001! polygon contour distance %s\"\n"
1069 " (condition \"A.customProperty('TARGET3001_EDGE_CLEARANCE') "
1070 "== '%d'\")\n"
1071 " (constraint edge_clearance (min %s)))\n" ),
1073 }
1074
1075 // The larger aura of two polygons wins, so larger values come later
1076 for( int aura : m_polygonAuras )
1077 {
1078 m_designRules += wxString::Format( wxS( "\n(rule \"TARGET 3001! polygon aura %s\"\n"
1079 " (condition \"A.customProperty('TARGET3001_POLYGON_AURA') "
1080 "== '%d' && B.Type == 'Zone'\")\n"
1081 " (constraint clearance (min %s)))\n" ),
1082 ruleMm( aura ), aura, ruleMm( aura ) );
1083 }
1084}
1085
1086
1088{
1089 const ELEMENT_BASE& b = aElem.base;
1090 VECTOR2I p0 = toKi( b.x, b.y );
1091
1092 switch( aElem.type )
1093 {
1094 case ELEMENT_TYPE::TRIANGLE:
1095 {
1096 const TRIANGLE& t = aElem.triangle;
1097 aOut.NewOutline();
1098 aOut.Append( p0 );
1099 aOut.Append( toKi( t.x2, t.y2 ) );
1100 aOut.Append( toKi( t.x3, t.y3 ) );
1101 return true;
1102 }
1103
1104 case ELEMENT_TYPE::RECTANGLE:
1105 {
1106 const RECTANGLE& r = aElem.rectangle;
1107 EDA_ANGLE rot = angle( r.direction );
1108 VECTOR2D corners[4] = { { 0.0, 0.0 }, { double( r.width ), 0.0 },
1109 { double( r.width ), double( r.height ) }, { 0.0, double( r.height ) } };
1110
1111 aOut.NewOutline();
1112
1113 for( const VECTOR2D& c : corners )
1114 {
1115 VECTOR2D rotated = c;
1116 RotatePoint( rotated, -rot );
1117 aOut.Append( toKi( b.x + KiROUND( rotated.x ), b.y + KiROUND( rotated.y ) ) );
1118 }
1119
1120 return true;
1121 }
1122
1123 case ELEMENT_TYPE::DISC:
1125 return true;
1126
1127 case ELEMENT_TYPE::LINE:
1128 TransformOvalToPolygon( aOut, p0, toKi( aElem.line.x2, aElem.line.y2 ), std::max( 1, aElem.line.width ),
1130 return true;
1131
1132 case ELEMENT_TYPE::FIDUCIAL:
1133 for( const std::unique_ptr<PCB_SHAPE>& shape : fiducialShapes( aElem, m_board ) )
1134 shape->TransformShapeToPolygon( aOut, F_Cu, 0, ARC_HIGH_DEF, ERROR_INSIDE );
1135
1136 return true;
1137
1138 case ELEMENT_TYPE::ARC:
1139 {
1140 const ARC& a = aElem.arc;
1142 int width = std::max( 1, a.width );
1143 double sweep = a.Sweep();
1144
1145 if( sweep >= 360.0 - 1e-6 )
1146 {
1148 return true;
1149 }
1150
1151 auto onArc = [&]( double aDeg )
1152 {
1153 return center + VECTOR2I( KiROUND( a.radius * cos( DEG2RAD( aDeg ) ) ),
1154 -KiROUND( a.radius * sin( DEG2RAD( aDeg ) ) ) );
1155 };
1156
1157 TransformArcToPolygon( aOut, onArc( a.startAngle ), onArc( a.startAngle + sweep / 2.0 ),
1158 onArc( a.startAngle + sweep ), width, ARC_HIGH_DEF, ERROR_INSIDE );
1159 return true;
1160 }
1161
1162 default:
1163 return false;
1164 }
1165}
1166
1167
1169{
1170 if( ( aElem.type == ELEMENT_TYPE::LINE && aElem.line.clearance == 0 )
1171 || ( aElem.type == ELEMENT_TYPE::ARC && aElem.arc.clearance == 0 )
1172 || ( aElem.type == ELEMENT_TYPE::SPLINE && aElem.spline.clearance == 0 ) )
1173 {
1175 }
1176}
1177
1178
1180 bool aIsTrack )
1181{
1182 const ELEMENT_BASE& b = aElem.base;
1183
1184 if( b.layer == m_contourLayer && b.flags == 0 && aElem.type != ELEMENT_TYPE::TEXT )
1185 noteContour( aElem );
1186
1187 // Hidden board elements are not drawn; hidden text is kept as invisible text
1188 if( ( b.flags & 1 ) && aElem.type != ELEMENT_TYPE::TEXT )
1189 return;
1190
1191 if( aElem.type == ELEMENT_TYPE::PAD )
1192 {
1193 if( aFootprint )
1194 addPad( aElem, aFootprint );
1195 else if( aIsTrack )
1196 addVia( aElem );
1197 else
1198 addPad( aElem, nullptr );
1199
1200 return;
1201 }
1202
1203 // Pour areas and keepouts are collected and turned into zones at the end
1204 if( std::optional<PCB_LAYER_ID> pourLayer = pourCopperLayer( b.layer ) )
1205 {
1206 SHAPE_POLY_SET outline;
1207
1208 if( aElem.type == ELEMENT_TYPE::TEXT )
1209 {
1210 if( ( b.flags & 1 ) || aElem.text.weight == 0 )
1211 return;
1212
1213 // Text on these layers cuts or fills by its glyph strokes
1214 PCB_TEXT glyphs( m_board );
1215 glyphs.SetText( m_project.FunctionText( aElem.text, false ).value_or( ToWx( aElem.text.text ) ) );
1216 configureText( &glyphs, aElem, *pourLayer );
1217 glyphs.TransformTextToPolySet( outline, 0, ARC_HIGH_DEF, ERROR_INSIDE );
1218 }
1219 else if( !elementOutline( aElem, outline ) )
1220 {
1221 return;
1222 }
1223
1225 bool isArea = f == LAYER_FUNCTION::AREA_BOTTOM || f == LAYER_FUNCTION::AREA_INSIDE
1226 || f == LAYER_FUNCTION::AREA_TOP;
1227
1228 // Flagged areas take no part in the fill
1229 if( isArea && b.signal && b.flags == 0 )
1230 m_pourAreas.push_back( { b.signal, *pourLayer, std::move( outline ) } );
1231 else if( !isArea )
1232 m_pourKeepouts[*pourLayer].Append( outline );
1233
1234 return;
1235 }
1236
1237 std::vector<PCB_LAYER_ID> layers;
1238
1239 // The all-copper layer draws the same element, unmirrored, on every copper layer
1240 if( b.layer == ALL_COPPER_LAYER )
1241 {
1242 for( PCB_LAYER_ID cu : m_board->GetEnabledLayers().CuStack() )
1243 layers.push_back( cu );
1244 }
1245 else if( std::optional<PCB_LAYER_ID> layer = mapLayer( b.layer ) )
1246 {
1247 layers.push_back( *layer );
1248 }
1249
1250 for( PCB_LAYER_ID layer : layers )
1251 {
1252 if( aElem.type == ELEMENT_TYPE::TEXT )
1253 addText( aElem, aParent, aFootprint, layer );
1254 else
1255 addShape( aElem, aParent, aFootprint, aIsTrack, layer );
1256 }
1257}
1258
1259
1261 bool aIsTrack, PCB_LAYER_ID aLayer )
1262{
1263 const ELEMENT_BASE& b = aElem.base;
1264 bool copper = IsCopperLayer( aLayer );
1265
1266 if( copper )
1267 {
1268 std::optional<int> clearance;
1269
1270 if( aElem.type == ELEMENT_TYPE::LINE )
1271 clearance = aElem.line.clearance;
1272 else if( aElem.type == ELEMENT_TYPE::ARC )
1273 clearance = aElem.arc.clearance;
1274 else if( aElem.type == ELEMENT_TYPE::SPLINE )
1275 clearance = aElem.spline.clearance;
1276
1277 // A zero clearance keeps the netclass clearance rather than letting another signal's area touch
1278 if( clearance && *clearance > 0 && b.signal )
1280 }
1281
1282 switch( aElem.type )
1283 {
1284 case ELEMENT_TYPE::LINE:
1285 {
1286 const LINE& l = aElem.line;
1287
1288 if( copper && aIsTrack && !aFootprint )
1289 {
1290 PCB_TRACK* track = new PCB_TRACK( m_board );
1291 track->SetStart( toKi( b.x, b.y ) );
1292 track->SetEnd( toKi( l.x2, l.y2 ) );
1293 track->SetWidth( l.width );
1294 track->SetLayer( aLayer );
1295 track->SetNet( net( b.signal ) );
1296 m_board->Add( track, ADD_MODE::APPEND );
1297 return;
1298 }
1299
1300 PCB_SHAPE* shape = new PCB_SHAPE( aParent, SHAPE_T::SEGMENT );
1301 shape->SetStart( toKi( b.x, b.y ) );
1302 shape->SetEnd( toKi( l.x2, l.y2 ) );
1303 shape->SetStroke( STROKE_PARAMS( l.width, lineStyle( l.dashStyle ) ) );
1304 shape->SetLayer( aLayer );
1305
1306 if( copper )
1307 shape->SetNet( net( b.signal ) );
1308
1309 aParent->Add( shape, ADD_MODE::APPEND );
1310 return;
1311 }
1312
1313 case ELEMENT_TYPE::ARC:
1314 {
1315 const ARC& a = aElem.arc;
1317 double sweep = a.Sweep();
1318
1319 bool full = sweep >= 360.0 - 1e-6;
1320
1321 if( full )
1322 {
1323 PCB_SHAPE* shape = new PCB_SHAPE( aParent, SHAPE_T::CIRCLE );
1324 shape->SetCenter( center );
1325 shape->SetRadius( a.radius );
1327 shape->SetLayer( aLayer );
1328
1329 if( copper )
1330 shape->SetNet( net( b.signal ) );
1331
1332 aParent->Add( shape, ADD_MODE::APPEND );
1333 return;
1334 }
1335
1336 double midDeg = double( a.startAngle ) + sweep / 2.0;
1337 VECTOR2I start = center + VECTOR2I( KiROUND( a.radius * cos( DEG2RAD( a.startAngle ) ) ),
1338 -KiROUND( a.radius * sin( DEG2RAD( a.startAngle ) ) ) );
1339 VECTOR2I mid = center + VECTOR2I( KiROUND( a.radius * cos( DEG2RAD( midDeg ) ) ),
1340 -KiROUND( a.radius * sin( DEG2RAD( midDeg ) ) ) );
1341 VECTOR2I end = center + VECTOR2I( KiROUND( a.radius * cos( DEG2RAD( a.startAngle + sweep ) ) ),
1342 -KiROUND( a.radius * sin( DEG2RAD( a.startAngle + sweep ) ) ) );
1343
1344 if( copper && aIsTrack && !aFootprint )
1345 {
1346 PCB_ARC* arc = new PCB_ARC( m_board );
1347 arc->SetStart( start );
1348 arc->SetMid( mid );
1349 arc->SetEnd( end );
1350 arc->SetWidth( a.width );
1351 arc->SetLayer( aLayer );
1352 arc->SetNet( net( b.signal ) );
1353 m_board->Add( arc, ADD_MODE::APPEND );
1354 return;
1355 }
1356
1357 PCB_SHAPE* shape = new PCB_SHAPE( aParent, SHAPE_T::ARC );
1358 shape->SetArcGeometry( start, mid, end );
1360 shape->SetLayer( aLayer );
1361
1362 if( copper )
1363 shape->SetNet( net( b.signal ) );
1364
1365 aParent->Add( shape, ADD_MODE::APPEND );
1366 return;
1367 }
1368
1369 case ELEMENT_TYPE::SPLINE:
1370 {
1371 const SPLINE& s = aElem.spline;
1372 VECTOR2I p0 = toKi( b.x, b.y );
1373 VECTOR2I c = toKi( s.controlX, s.controlY );
1374 VECTOR2I p2 = toKi( s.endX, s.endY );
1375
1376 // Elevate the quadratic curve to the cubic form KiCad stores
1377 PCB_SHAPE* shape = new PCB_SHAPE( aParent, SHAPE_T::BEZIER );
1378 shape->SetStart( p0 );
1379 shape->SetBezierC1( p0 + ( c - p0 ) * 2 / 3 );
1380 shape->SetBezierC2( p2 + ( c - p2 ) * 2 / 3 );
1381 shape->SetEnd( p2 );
1383 shape->SetLayer( aLayer );
1385
1386 if( copper )
1387 shape->SetNet( net( b.signal ) );
1388
1389 aParent->Add( shape, ADD_MODE::APPEND );
1390 return;
1391 }
1392
1393 case ELEMENT_TYPE::TRIANGLE:
1394 case ELEMENT_TYPE::RECTANGLE:
1395 case ELEMENT_TYPE::DISC:
1396 {
1397 SHAPE_POLY_SET outline;
1398 elementOutline( aElem, outline );
1399
1400 // Stored copper fills are triangulated; merge them back into polygons per net and layer
1401 if( copper && aIsTrack && !aFootprint && aElem.type == ELEMENT_TYPE::TRIANGLE )
1402 {
1403 m_copperFills[{ b.signal, aLayer }].Append( outline );
1404 return;
1405 }
1406
1407 PCB_SHAPE* shape;
1408
1409 if( aElem.type == ELEMENT_TYPE::DISC )
1410 {
1411 shape = new PCB_SHAPE( aParent, SHAPE_T::CIRCLE );
1412 shape->SetCenter( toKi( b.x, b.y ) );
1413 shape->SetRadius( aElem.disc.radius );
1414 }
1415 else
1416 {
1417 shape = new PCB_SHAPE( aParent, SHAPE_T::POLY );
1418 shape->SetPolyShape( outline );
1419 }
1420
1421 shape->SetFilled( true );
1423 shape->SetLayer( aLayer );
1424
1425 if( copper )
1426 shape->SetNet( net( b.signal ) );
1427
1428 aParent->Add( shape, ADD_MODE::APPEND );
1429 return;
1430 }
1431
1432 case ELEMENT_TYPE::FIDUCIAL:
1433 for( std::unique_ptr<PCB_SHAPE>& shape : fiducialShapes( aElem, aParent ) )
1434 {
1435 shape->SetLayer( aLayer );
1436
1437 if( copper )
1438 shape->SetNet( net( b.signal ) );
1439
1440 aParent->Add( shape.release(), ADD_MODE::APPEND );
1441 }
1442
1443 return;
1444
1445 default:
1446 return;
1447 }
1448}
1449
1450
1451std::vector<std::unique_ptr<PCB_SHAPE>> TARGET3001_PCB_BUILDER::fiducialShapes( const ELEMENT& aElem,
1452 BOARD_ITEM_CONTAINER* aParent ) const
1453{
1454 const FIDUCIAL& f = aElem.fiducial;
1455 const ELEMENT_BASE& b = aElem.base;
1456 std::vector<std::unique_ptr<PCB_SHAPE>> shapes;
1457
1458 auto circle = [&]( int aRadius, int aWidth, bool aFilled )
1459 {
1460 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aParent, SHAPE_T::CIRCLE );
1461 shape->SetCenter( toKi( b.x, b.y ) );
1462 shape->SetRadius( aRadius );
1463 shape->SetStroke( STROKE_PARAMS( aWidth, LINE_STYLE::SOLID ) );
1464 shape->SetFilled( aFilled );
1465 shapes.push_back( std::move( shape ) );
1466 };
1467
1469 {
1470 circle( f.radius, 0, true );
1471 return shapes;
1472 }
1473
1474 int ring = std::max( 0, f.radius - f.width / 2 );
1475 circle( ring, f.width, false );
1476
1478 return shapes;
1479
1480 circle( KiROUND( ring * 2.0 / 3.0 ), f.width, false );
1481 circle( KiROUND( ring / 3.0 ), f.width, false );
1482
1483 // Cross arms reach the outer ring's centreline along the mark's own axes
1484 for( double axis : { 0.0, 90.0 } )
1485 {
1486 double rad = DEG2RAD( f.direction + axis );
1487 int32_t dx = KiROUND( ring * cos( rad ) );
1488 int32_t dy = KiROUND( ring * sin( rad ) );
1489
1490 std::unique_ptr<PCB_SHAPE> arm = std::make_unique<PCB_SHAPE>( aParent, SHAPE_T::SEGMENT );
1491 arm->SetStart( toKi( b.x + dx, b.y + dy ) );
1492 arm->SetEnd( toKi( b.x - dx, b.y - dy ) );
1493 arm->SetStroke( STROKE_PARAMS( f.width, LINE_STYLE::SOLID ) );
1494 shapes.push_back( std::move( arm ) );
1495 }
1496
1497 return shapes;
1498}
1499
1500
1501void TARGET3001_PCB_BUILDER::addPad( const ELEMENT& aElem, FOOTPRINT* aFootprint )
1502{
1503 const TARGET3001::PAD& src = aElem.pad;
1504 const ELEMENT_BASE& b = aElem.base;
1505
1506 FOOTPRINT* fp = aFootprint;
1507
1508 // Free pads (mounting holes, test points) get a footprint of their own
1509 if( !fp )
1510 {
1511 fp = new FOOTPRINT( m_board );
1512 fp->SetPosition( toKi( b.x, b.y ) );
1513 fp->SetReference( wxString::Format( wxS( "H%d" ), ++m_freePadCount ) );
1514 fp->Reference().SetVisible( false );
1515 fp->Value().SetVisible( false );
1517 m_board->Add( fp, ADD_MODE::APPEND );
1518 }
1519
1520 ::PAD* pad = new ::PAD( fp );
1521 pad->SetPosition( toKi( b.x, b.y ) );
1522 pad->SetOrientation( angle( src.direction ) );
1523
1524 VECTOR2I size( std::max( 1, src.width ), std::max( 1, src.height ) );
1525 std::optional<LSET> padstack = padstackLayers( b.layer );
1526
1527 pad->SetSize( PADSTACK::ALL_LAYERS, size );
1528
1529 switch( TARGET3001::PAD_SHAPE( src.shape ) )
1530 {
1532 if( size.x == size.y )
1533 {
1535 }
1536 else
1537 {
1538 // Unequal round pads are true ellipses, which KiCad only has as a custom shape
1539 bool wide = size.x > size.y;
1540 SHAPE_ELLIPSE ellipse( VECTOR2I( 0, 0 ), std::max( size.x, size.y ) / 2,
1541 std::min( size.x, size.y ) / 2, wide ? ANGLE_0 : ANGLE_90 );
1542 SHAPE_POLY_SET outline( ellipse.ConvertToPolyline( m_board->GetDesignSettings().m_MaxError ) );
1543 int anchor = std::min( size.x, size.y );
1544
1546 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, ::PAD_SHAPE::CIRCLE );
1548 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, outline, 0, true );
1549 }
1550
1551 break;
1552
1554 {
1555 const std::string* prop = b.FindProp( "POLY_PAD" );
1556 std::vector<VECTOR2I> pts = prop ? parsePolyPad( *prop ) : std::vector<VECTOR2I>();
1557
1558 if( pts.size() >= 3 )
1559 {
1560 std::vector<VECTOR2I> local;
1561
1562 for( const VECTOR2I& pt : pts )
1563 local.emplace_back( pt.x, -pt.y );
1564
1565 // The custom shape carries all the copper; the anchor only needs to sit inside it
1566 int anchor = pcbIUScale.mmToIU( 0.001 );
1567
1569 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, ::PAD_SHAPE::CIRCLE );
1571 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, local, 0, true );
1572 break;
1573 }
1574
1575 // Fewer than three vertices falls back to an octagon
1577 }
1578
1581 pad->SetChamferRectRatio( PADSTACK::ALL_LAYERS, OCTAGON_CHAMFER_RATIO );
1582 pad->SetChamferPositions( PADSTACK::ALL_LAYERS, RECT_CHAMFER_ALL );
1583 break;
1584
1587 break;
1588
1590 default:
1591 {
1592 long rounded = 0;
1593
1594 // RECT_ROUNDED is the corner diameter in percent of the smaller side
1595 if( const std::string* prop = b.FindProp( "RECT_ROUNDED" ) )
1596 wxString( *prop ).ToLong( &rounded );
1597
1598 if( rounded > 0 )
1599 {
1601 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, std::min( 0.5, rounded / 200.0 ) );
1602 }
1603 else
1604 {
1606 }
1607
1608 break;
1609 }
1610 }
1611
1612 pad->SetNumber( TARGET3001::PadNumber( aElem ) );
1613
1614 bool hasHole = src.drill > 0;
1615
1616 if( hasHole )
1617 {
1618 pad->SetDrillSize( VECTOR2I( src.drill, src.drill ) );
1619
1620 if( const std::string* slot = b.FindProp( "SLOT_HOLE" ) )
1621 {
1622 long length = 0;
1623
1624 if( wxString( *slot ).ToLong( &length ) && length > src.drill )
1625 {
1626 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
1627 pad->SetDrillSize( VECTOR2I( int( length ), src.drill ) );
1628 }
1629 }
1630
1631 // A hole is unplated only when it is larger than its copper
1632 bool plated = std::max( src.width, src.height ) >= src.drill;
1633
1634 pad->SetAttribute( plated ? PAD_ATTRIB::PTH : PAD_ATTRIB::NPTH );
1635
1636 if( !plated )
1637 pad->SetLayerSet( ::PAD::UnplatedHoleMask() );
1638 else if( padstack )
1639 pad->SetLayerSet( *padstack );
1640 else
1641 pad->SetLayerSet( ::PAD::PTHMask() );
1642
1643 if( !plated )
1644 {
1645 VECTOR2I hole = pad->GetDrillSize();
1646
1647 pad->DeletePrimitivesList();
1648 pad->SetShape( PADSTACK::ALL_LAYERS, hole.x == hole.y ? ::PAD_SHAPE::CIRCLE : ::PAD_SHAPE::OVAL );
1649 pad->SetSize( PADSTACK::ALL_LAYERS, hole );
1650 }
1651 }
1652 else if( padstack )
1653 {
1654 pad->SetAttribute( PAD_ATTRIB::SMD );
1655 pad->SetLayerSet( *padstack );
1656 }
1657 else
1658 {
1659 std::optional<PCB_LAYER_ID> copper = mapLayer( b.layer );
1660 PCB_LAYER_ID side = copper && IsCopperLayer( *copper ) ? *copper : F_Cu;
1661 LSET layers( { side } );
1662
1663 if( side == F_Cu )
1664 layers |= LSET( { F_Mask, F_Paste } );
1665 else if( side == B_Cu )
1666 layers |= LSET( { B_Mask, B_Paste } );
1667
1668 pad->SetAttribute( PAD_ATTRIB::SMD );
1669 pad->SetLayerSet( layers );
1670 }
1671
1672 if( src.clearance > 0 )
1673 pad->SetLocalClearance( src.clearance );
1674
1675 pad->SetNet( net( b.signal ) );
1676
1677 if( b.signal )
1678 tagAura( *pad, b, src.clearance );
1679
1680 fp->Add( pad, ADD_MODE::APPEND );
1681
1682 if( padstack )
1684}
1685
1686
1687void TARGET3001_PCB_BUILDER::addPadstackCuts( const BOARD_ITEM& aItem, int aPadstack )
1688{
1689 const TARGET3001::PADSTACK_DEF& def = m_project.settings.padstacks[aPadstack];
1690
1691 // A padstack flagged on a deletion layer cuts the computed copper there, grown by its oversize
1692 for( int layer = 0; layer < TARGET3001::BOARD_LAYER_COUNT; layer++ )
1693 {
1694 LAYER_FUNCTION f = LayerFunction( layer );
1695
1696 if( !def.onLayer[layer]
1697 || ( f != LAYER_FUNCTION::DELETION_BOTTOM && f != LAYER_FUNCTION::DELETION_INSIDE
1698 && f != LAYER_FUNCTION::DELETION_TOP ) )
1699 {
1700 continue;
1701 }
1702
1703 if( std::optional<PCB_LAYER_ID> copper = pourCopperLayer( layer ) )
1704 {
1705 aItem.TransformShapeToPolygon( m_pourKeepouts[*copper], *copper, std::max( 0, def.oversize[layer] ),
1707 }
1708 }
1709}
1710
1711
1712std::optional<LSET> TARGET3001_PCB_BUILDER::padstackLayers( int aLayer ) const
1713{
1714 const std::vector<TARGET3001::PADSTACK_DEF>& padstacks = m_project.settings.padstacks;
1715 size_t index = size_t( aLayer - TARGET3001::FIRST_PADSTACK_LAYER );
1716
1717 if( aLayer < TARGET3001::FIRST_PADSTACK_LAYER || index >= padstacks.size() )
1718 return std::nullopt;
1719
1720 LSET layers;
1721
1722 for( int layer = 0; layer < TARGET3001::BOARD_LAYER_COUNT; layer++ )
1723 {
1724 if( !padstacks[index].onLayer[layer] )
1725 continue;
1726
1727 std::optional<PCB_LAYER_ID> mapped = mapLayer( layer );
1728
1729 if( mapped && ( IsCopperLayer( *mapped ) || IsSolderMaskLayer( *mapped ) || *mapped == F_Paste
1730 || *mapped == B_Paste ) )
1731 {
1732 layers.set( *mapped );
1733 }
1734 }
1735
1736 return layers;
1737}
1738
1739
1741{
1742 const TARGET3001::PAD& src = aElem.pad;
1743 const ELEMENT_BASE& b = aElem.base;
1744
1746 bool slotted = b.FindProp( "SLOT_HOLE" ) != nullptr;
1747 std::optional<LSET> padstack = padstackLayers( b.layer );
1748 LSET allCopper = LSET::AllCuMask( m_board->GetCopperLayerCount() );
1749
1750 // Copper without a hole is a pad-shaped piece of copper; a hole larger than its copper is unplated.
1751 // Slots, oval or rectangular copper and padstacks missing a copper layer have no via equivalent.
1752 if( src.drill <= 0 || std::max( src.width, src.height ) < src.drill || slotted
1754 || ( padstack && ( *padstack & allCopper ) != allCopper ) )
1755 {
1756 addPad( aElem, nullptr );
1757 return;
1758 }
1759
1760 PCB_VIA* via = new PCB_VIA( m_board );
1761 via->SetPosition( toKi( b.x, b.y ) );
1762 via->SetWidth( PADSTACK::ALL_LAYERS, std::max( src.width, src.height ) );
1763 via->SetDrill( src.drill );
1764 via->SetViaType( VIATYPE::THROUGH );
1765 via->SetLayerPair( F_Cu, B_Cu );
1766 via->SetNet( net( b.signal ) );
1767
1768 if( b.signal )
1769 tagAura( *via, b, src.clearance );
1770
1771 m_board->Add( via, ADD_MODE::APPEND );
1772
1773 if( b.signal && src.clearance > 0 )
1775
1776 if( padstack )
1778}
1779
1780
1782{
1783 const TEXT& t = aElem.text;
1784 const ELEMENT_BASE& b = aElem.base;
1785
1786 aText->SetLayer( aLayer );
1787 m_fonts.Apply( aText, aElem, 1 );
1788 aText->SetTextAngle( angle( t.direction ) );
1789 aText->SetMirrored( t.mirrored != 0 );
1792 aText->SetTextPos( toKi( b.x, b.y ) );
1793
1794 // Right-aligned text also stores its right end, which keeps the alignment when font metrics differ
1795 if( std::optional<std::pair<int32_t, int32_t>> end = b.TextRightEnd() )
1796 {
1797 // Mirroring flips both ends, so the stored end stays the right-justified one
1798 aText->SetTextPos( toKi( end->first, end->second ) );
1800 }
1801
1802 aText->SetTextPos( aText->GetTextPos() + TARGET3001::FONTS::BaselineShift( *aText ) );
1803 aText->SetVisible( !( b.flags & 1 ) && t.weight != 0 );
1804}
1805
1806
1808 FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer )
1809{
1810 const TEXT& t = aElem.text;
1811
1812 if( aFootprint && t.function == uint8_t( TEXT_FUNCTION::REFERENCE ) )
1813 {
1814 aFootprint->Reference().SetText( ToWx( t.text ) );
1815 configureText( &aFootprint->Reference(), aElem, aLayer );
1816 return;
1817 }
1818
1819 if( aFootprint && t.function == uint8_t( TEXT_FUNCTION::VALUE ) )
1820 {
1821 aFootprint->Value().SetText( ToWx( t.text ) );
1822 configureText( &aFootprint->Value(), aElem, aLayer );
1823 return;
1824 }
1825
1826 PCB_TEXT* text = new PCB_TEXT( aParent );
1827 text->SetText( m_project.FunctionText( t, false ).value_or( ToWx( t.text ) ) );
1828 configureText( text, aElem, aLayer );
1829 aParent->Add( text, ADD_MODE::APPEND );
1830}
int index
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
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BASE_SET & set(size_t pos)
Definition base_set.h:126
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
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.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
constexpr coord_type GetY() const
Definition box2.h:211
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr coord_type GetX() const
Definition box2.h:210
constexpr size_type GetHeight() const
Definition box2.h:218
void SetCustomProperty(const wxString &aKey, const wxString &aValue)
Definition eda_item.h:255
virtual void SetFilled(bool aFlag)
Definition eda_shape.h:145
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
void SetRadius(int aX)
Definition eda_shape.h:359
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:355
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
void SetPosition(const VECTOR2I &aPos) override
void SetOrientation(const EDA_ANGLE &aNewAngle)
void SetAttributes(int aAttributes)
Definition footprint.h:510
PCB_FIELD & Value()
read/write accessors:
Definition footprint.h:831
void SetReference(const wxString &aReference)
Definition footprint.h:799
void SetValue(const wxString &aValue)
Definition footprint.h:822
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.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetFPIDAsString(const wxString &aFPID)
Definition footprint.h:420
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 wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetname() const
Definition netinfo.h:110
int GetNetCode() const
Definition netinfo.h:104
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
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:641
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1672
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition pad.cpp:1124
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1825
void SetMid(const VECTOR2I &aMid)
Definition pcb_track.h:303
void SetCenter(const VECTOR2I &aCenter) override
void SetBezierC1(const VECTOR2I &aPt) override
void SetEnd(const VECTOR2I &aEnd) override
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetBezierC2(const VECTOR2I &aPt) override
void SetStroke(const STROKE_PARAMS &aStroke) override
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) override
Set the three controlling points for an arc.
VECTOR2I GetTextPos() const override
Definition pcb_text.cpp:463
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
Definition pcb_text.cpp:784
void SetTextAngle(const EDA_ANGLE &aAngle) override
Definition pcb_text.cpp:574
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
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
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)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
Simple container to manage line stroke parameters.
static VECTOR2I BaselineShift(const EDA_TEXT &aText)
Offset in text units that moves aText so the baseline-left point of its first glyph lies on its posit...
TARGET3001::LAYER_FUNCTION LayerFunction(int aLayer) const
Function of a TARGET 3001! board layer in this project.
const TARGET3001::PROJECT & m_project
std::map< uint16_t, NETINFO_ITEM * > m_nets
by signal ID
std::vector< POUR_AREA > m_pourAreas
void addShape(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, bool aIsTrack, PCB_LAYER_ID aLayer)
Add the graphic or track form of aElem on one KiCad layer.
void addVia(const TARGET3001::ELEMENT &aElem)
std::map< int, SHAPE_POLY_SET > m_pourKeepouts
KiCad layer -> pour keepout.
void addFootprint(const TARGET3001::ELEMENT &aComponent)
std::vector< int > m_copperStack
TARGET layers, top to bottom.
void addItem(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, bool aIsTrack)
Add one board element to aParent; footprint items are passed with their footprint.
void buildAreaSpokes(const std::vector< const TARGET3001::ELEMENT * > &aSpokes)
Turn the spokes an old style area stores into thermal reliefs on the pads they start in.
std::vector< std::unique_ptr< PCB_SHAPE > > fiducialShapes(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent) const
Strokes and discs that draw a fiducial mark, not yet assigned a layer.
std::vector< std::pair< ZONE *, int64_t > > m_polygonZones
thermal polygon zones and their POLYGONID
std::optional< PCB_LAYER_ID > pourCopperLayer(int aLayer) const
Copper layer that an area or deletion layer applies to.
void buildAreaClearanceRules()
Clearance rules between copper areas and each signal's tracks and vias.
bool isCopper(int aLayer) const
NETINFO_ITEM * net(uint16_t aSignal) const
void addPad(const TARGET3001::ELEMENT &aElem, FOOTPRINT *aFootprint)
bool elementOutline(const TARGET3001::ELEMENT &aElem, SHAPE_POLY_SET &aOut) const
Outline of a filled element (rectangle, triangle, disc, stroked line or arc) in KiCad coordinates.
void buildAuraRules()
Rules that keep areas the aura distance from pads and vias, except on their NO_AURA layers.
std::set< std::pair< uint16_t, PCB_LAYER_ID > > m_pourLayers
(signal, KiCad layer) holding an area
std::map< int64_t, SHAPE_POLY_SET > m_polygonSpokes
POLYGONID -> stored thermal spokes.
std::map< std::pair< int, int >, SHAPE_POLY_SET > m_copperFills
(net, KiCad layer) -> filled copper
std::map< uint16_t, std::map< int, int > > m_signalClearances
Track and via clearances counted per signal, then per clearance value.
TARGET3001_PCB_BUILDER(BOARD *aBoard, const TARGET3001::PROJECT &aProject, REPORTER *aReporter)
void addPadstackCuts(const BOARD_ITEM &aItem, int aPadstack)
Cut aItem, grown per layer, from the pours of the deletion layers padstack aPadstack lists.
std::optional< PCB_LAYER_ID > polygonLayer(const TARGET3001::POLYGON_POUR &aPoly) const
Copper layer of a signal polygon that can become a zone.
std::optional< LSET > padstackLayers(int aLayer) const
Copper, mask and paste layers of the padstack a pad layer >= 101 selects.
void buildThermalGaps()
Thermal gaps the stored fill leaves around spoked pads, as zone defaults and pad or footprint overrid...
void addText(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer)
void tagAura(BOARD_CONNECTED_ITEM &aItem, const TARGET3001::ELEMENT_BASE &aBase, int aAura)
Tag a pad or via with its aura so the aura rules can match it.
void buildPolygonRules()
Rules for the board contour and foreign polygon distances each signal polygon keeps.
std::set< int > m_auraValues
distinct aura distances above zero
std::map< int64_t, SHAPE_POLY_SET > m_polygonFills
POLYGONID -> stored fill without spokes.
std::set< int > m_polygonEdgeClearances
void noteContour(const TARGET3001::ELEMENT &aElem)
Record whether a board contour stroke carries a clearance.
void configureText(PCB_TEXT *aText, const TARGET3001::ELEMENT &aElem, PCB_LAYER_ID aLayer)
VECTOR2I toKi(int32_t aX, int32_t aY) const
std::set< PCB_LAYER_ID > m_noAuraLayers
copper layers some NO_AURA list names
std::optional< int > m_contourLayer
first TARGET layer holding the contour
std::optional< PCB_LAYER_ID > mapLayer(int aLayer) const
Copper or graphic layer for a board element, if KiCad has a place for it.
std::map< int, PCB_LAYER_ID > m_layerMap
bool m_contourCarvesNothing
a contour stroke has no clearance
A triangle object.
Definition triangle_3d.h:39
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 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 SetDoNotAllowFootprints(bool aEnable)
Definition zone.h:861
void SetDoNotAllowZoneFills(bool aEnable)
Definition zone.h:857
void SetAssignedPriority(unsigned aPriority)
Definition zone.h:117
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition zone.h:313
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:864
void TransformRingToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
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 TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
@ SEGMENT
Definition eda_shape.h:57
@ FP_EXCLUDE_FROM_POS_FILES
Definition footprint.h:88
@ FP_BOARD_ONLY
Definition footprint.h:90
@ FP_EXCLUDE_FROM_BOM
Definition footprint.h:89
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PCB_LAYER_ID BoardLayerFromLegacyId(int aLegacyId)
Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
Definition layer_id.cpp:230
bool IsSolderMaskLayer(int aLayer)
Definition layer_ids.h:815
#define MAX_CU_LAYERS
Definition layer_ids.h:172
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
@ B_Adhes
Definition layer_ids.h:99
@ Edge_Cuts
Definition layer_ids.h:108
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ F_Adhes
Definition layer_ids.h:98
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ User_9
Definition layer_ids.h:128
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ User_1
Definition layer_ids.h:120
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition macros.h:79
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
LAYER_FUNCTION
Board layer function codes stored per layer in the project header.
constexpr int FIRST_PADSTACK_LAYER
A pad on board layer FIRST_PADSTACK_LAYER + n takes its layers from project padstack n.
wxString PadNumber(const ELEMENT &aPad)
Number of a pad element in KiCad, its PADNAME when present, else its stored number.
constexpr int ALL_COPPER_LAYER
Board elements on this layer exist on every copper layer.
@ POLYGON
vertices in the POLY_PAD property
@ CROSSHAIR_RINGS
cross and rings at 1, 2/3 and 1/3 of the outer centreline radius
@ FILLED_CIRCLE
solid disc of the outer radius
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
ELEMENT_TYPE
Element class tags as stored in the file.
constexpr int BOARD_LAYER_COUNT
Board layers 0..99 carry a per-project function; 100 and above have fixed meanings.
constexpr uint8_t NO_ASSOCIATION
Layer association value for a layer that belongs to no copper layer.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition padstack.h:53
@ CHAMFERED_RECT
Definition padstack.h:61
@ ROUNDRECT
Definition padstack.h:58
@ RECTANGLE
Definition padstack.h:55
LINE_STYLE
Dashed line types.
Stroked arc or circle. The base position is the start point.
double Sweep() const
Counter-clockwise sweep in (0, 360]; equal angles give a full circle.
float startAngle
degrees, counter-clockwise from +X
Fields shared by every drawable element.
std::optional< int64_t > PolygonId() const
ID of the signal polygon whose stored fill this element is part of, if any.
bool FlagProp(const std::string &aKey) const
True when property aKey holds one of the format's boolean true words.
uint16_t signal
ID of the owning signal (a signal stores its own), 0 for none.
std::optional< std::pair< int32_t, int32_t > > TextRightEnd() const
Right end of right-aligned text from its ARXY property, in file coordinates.
const std::string * FindProp(const std::string &aKey) const
Return the value of the first property named aKey, if any.
One element of any class.
std::shared_ptr< COMPONENT > component
std::shared_ptr< SIGNAL > signal
std::shared_ptr< PACKAGE > package
uint8_t kind
FIDUCIAL_KIND.
uint8_t dashStyle
0 solid, 1 long dash, 2 dash-dot, 3 other, 4 short dash
Footprint placement. Pads and graphics of the footprint are stored in board coordinates.
Project padstack; the board layers a pad exists on and how far it grows on each.
std::array< bool, BOARD_LAYER_COUNT > onLayer
std::array< int32_t, BOARD_LAYER_COUNT > oversize
growth per side, nm
int32_t width
along the pad's own X axis before rotation
int32_t drill
0 for no hole
Copper polygon of a signal, stored in a "$%&POLY" signal property.
int32_t rank
a polygon is cut out of every one of lower rank on its layer
std::vector< std::pair< int32_t, int32_t > > outline
closed, first vertex repeated last
int32_t aura
distance kept from other signals' polygons, 0 for the default
int32_t edgeClearance
distance kept from the board contour, 0 for none
int32_t width
fill stroke width, 0 for the board default
bool thermals
own pads join by spokes rather than solidly
Filled rectangle anchored at a corner (the base position); sizes are signed.
Quadratic Bezier from the base position to the end point.
Filled triangle given by three absolute corners (the first is the base position).
constexpr int ALL_COPPER_LAYER
Board elements on this layer exist on every copper layer.
constexpr int BOARD_LAYER_COUNT
Board layers 0..99 carry a per-project function; 100 and above have fixed meanings.
static wxString ruleLiteral(const wxString &aValue)
An expression string literal, whose only escape is \', inside a quoted rules file string.
constexpr uint8_t NO_ASSOCIATION
Layer association value for a layer that belongs to no copper layer.
static wxString ruleMm(int aValue)
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
KIBIS top(path, &reporter)
KIBIS_COMPONENT * comp
VECTOR2I center
VECTOR2I end
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
int clearance
static double sweep(float aStart, float aEnd)
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
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
double DEG2RAD(double deg)
Definition trigo.h:178
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ FULL
pads are covered by copper
Definition zones.h:47