KiCad PCB EDA Suite
Loading...
Searching...
No Matches
create_layer_items.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <vector>
23#include <thread>
24#include <algorithm>
25#include <atomic>
26
27#include <wx/log.h>
28
29#include "board_adapter.h"
33#include <board.h>
34#include <footprint.h>
35#include <layer_range.h>
36#include <lset.h>
38#include <trigo.h>
39#include <pad.h>
40#include <pcb_barcode.h>
41#include <pcb_shape.h>
42#include <pcb_track.h>
43#include <zone.h>
44#include <pcb_painter.h> // for PCB_RENDER_SETTINGS
45
46#ifdef PRINT_STATISTICS_3D_VIEWER
47#include <core/profile.h>
48#endif
49
50/*
51 * This is used to draw pad outlines on silk layers.
52 */
53void buildPadOutlineAsPolygon( const PAD* aPad, PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aBuffer,
54 int aWidth, int aMaxError, ERROR_LOC aErrorLoc )
55{
56 if( aPad->GetShape( aLayer ) == PAD_SHAPE::CIRCLE ) // Draw a ring
57 {
58 TransformRingToPolygon( aBuffer, aPad->ShapePos( aLayer ), aPad->GetSize( aLayer ).x / 2,
59 aWidth, aMaxError, aErrorLoc );
60 }
61 else
62 {
63 // For other shapes, add outlines as thick segments in polygon buffer
64 const SHAPE_LINE_CHAIN& path = aPad->GetEffectivePolygon( aLayer, ERROR_INSIDE )->COutline( 0 );
65
66 for( int ii = 0; ii < path.PointCount(); ++ii )
67 {
68 const VECTOR2I& a = path.CPoint( ii );
69 const VECTOR2I& b = path.CPoint( ii + 1 );
70
71 TransformOvalToPolygon( aBuffer, a, b, aWidth, aMaxError, aErrorLoc );
72 }
73 }
74}
75
76// Draw a PCB_SHAPE outline according to the line style
77void drawPcbShapeWithStyle( const PCB_SHAPE* aDrwShape, SHAPE_POLY_SET* aLayerPoly, int aInflate = 0 )
78{
79 LINE_STYLE lineStyle = aDrwShape->GetStroke().GetLineStyle();
80 int maxError = aDrwShape->GetMaxError();
81
82 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
83 {
85 aInflate, maxError, ERROR_OUTSIDE, false ) ;
86 return;
87 }
88
89 std::vector<SHAPE*> shapes = aDrwShape->MakeEffectiveShapesForStroking( aDrwShape->GetWidth() );
90
91 const PCB_PLOT_PARAMS& plotParams = aDrwShape->GetBoard()->GetPlotOptions();
92 KIGFX::PCB_RENDER_SETTINGS renderSettings;
93
94 renderSettings.SetDashLengthRatio( plotParams.GetDashedLineDashRatio() );
95 renderSettings.SetGapLengthRatio( plotParams.GetDashedLineGapRatio() );
96
97 int minSegCount = 8;
98
99 for( SHAPE* shape : shapes )
100 {
101 int lineWidth = aDrwShape->GetWidth() + (2*aInflate);
102 STROKE_PARAMS::Stroke( shape, lineStyle, lineWidth, &renderSettings,
103 [&]( const VECTOR2I& a, const VECTOR2I& b )
104 {
105 TransformOvalToPolygon( *aLayerPoly, a, b, aDrwShape->GetWidth(), maxError,
106 ERROR_OUTSIDE, minSegCount );
107 } );
108 }
109
110 for( SHAPE* shape : shapes )
111 delete shape;
112};
113
114
115void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
116 SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc )
117{
118 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
119 {
120 if( !item->IsOnLayer( aLayer ) )
121 continue;
122
123 switch( item->Type() )
124 {
125 case PCB_SHAPE_T:
126 {
127 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
128 int margin = 0;
129
130 if( IsSolderMaskLayer( aLayer ) && shape->HasSolderMask() )
131 margin = shape->GetSolderMaskExpansion();
132
133 item->TransformShapeToPolySet( aBuffer, aLayer, margin, aMaxError, aErrorLoc );
134 break;
135 }
136
137 case PCB_BARCODE_T:
138 item->TransformShapeToPolySet( aBuffer, aLayer, 0, aMaxError, aErrorLoc );
139 break;
140
142 case PCB_DIM_CENTER_T:
143 case PCB_DIM_RADIAL_T:
145 case PCB_DIM_LEADER_T:
146 item->TransformShapeToPolySet( aBuffer, aLayer, 0, aMaxError, aErrorLoc );
147 break;
148
149 default:
150 break;
151 }
152 }
153}
154
155
156void transformFPTextToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
157 const std::bitset<LAYER_3D_END>& aFlags, SHAPE_POLY_SET& aBuffer,
158 int aMaxError, ERROR_LOC aErrorLoc )
159{
160 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
161 {
162 if( item->Type() == PCB_TEXT_T )
163 {
164 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
165
166 if( !aFlags.test( LAYER_FP_TEXT ) )
167 continue;
168
169 if( text->GetText() == wxT( "${REFERENCE}" ) && !aFlags.test( LAYER_FP_REFERENCES ) )
170 continue;
171
172 if( text->GetText() == wxT( "${VALUE}" ) && !aFlags.test( LAYER_FP_VALUES ) )
173 continue;
174
175 if( text->IsOnLayer( aLayer ) )
176 text->TransformTextToPolySet( aBuffer, 0, aMaxError, aErrorLoc );
177 }
178
179 if( item->Type() == PCB_TEXTBOX_T )
180 {
181 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
182
183 if( textbox->IsOnLayer( aLayer ) )
184 {
185 // border
186 if( textbox->IsBorderEnabled() )
187 {
188 // we use the box polygonal shape to honor the box rotation and line style
189 PCB_SHAPE tb_box = textbox->GetPolygonalBoxShape();
190 drawPcbShapeWithStyle( &tb_box, &aBuffer );
191 }
192
193 // Text itself
194 textbox->TransformTextToPolySet( aBuffer, 0, aMaxError, aErrorLoc );
195 }
196 }
197 }
198
199 for( const PCB_FIELD* field : aFootprint->GetFields() )
200 {
201 if( !aFlags.test( LAYER_FP_TEXT ) )
202 continue;
203
204 wxCHECK2( field, continue );
205
206 if( field->IsReference() && !aFlags.test( LAYER_FP_REFERENCES ) )
207 continue;
208
209 if( field->IsValue() && !aFlags.test( LAYER_FP_VALUES ) )
210 continue;
211
212 if( field->IsOnLayer( aLayer ) && field->IsVisible() )
213 field->TransformTextToPolySet( aBuffer, 0, aMaxError, aErrorLoc );
214 }
215}
216
217
219{
220#define DELETE_AND_FREE( ptr ) \
221 { \
222 delete ptr; \
223 ptr = nullptr; \
224 } \
225
226#define DELETE_AND_FREE_MAP( map ) \
227 { \
228 for( auto& [ layer, poly ] : map ) \
229 delete poly; \
230 \
231 map.clear(); \
232 }
233
235
238
241
242 m_NPTH_ODPolys.RemoveAllContours();
243 m_TH_ODPolys.RemoveAllContours();
244 m_viaTH_ODPolys.RemoveAllContours();
245 m_viaAnnuliPolys.RemoveAllContours();
246
247 m_frontCounterborePolys.RemoveAllContours();
248 m_backCounterborePolys.RemoveAllContours();
249 m_frontCountersinkPolys.RemoveAllContours();
250 m_backCountersinkPolys.RemoveAllContours();
251
254
259
260 m_TH_ODs.Clear();
261 m_TH_IDs.Clear();
262 m_viaAnnuli.Clear();
263 m_viaTH_ODs.Clear();
264
271}
272
273
274void BOARD_ADAPTER::createLayers( std::shared_ptr<REPORTER> aStatusReporter, std::stop_token aStop )
275{
277
278 if( aStop.stop_requested() )
279 return;
280
281 // Build Copper layers
282 // Based on:
283 // https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L692
284
285#ifdef PRINT_STATISTICS_3D_VIEWER
286 int64_t stats_startCopperLayersTime = GetRunningMicroSecs();
287
288 int64_t start_Time = stats_startCopperLayersTime;
289#endif
290
292
293 std::bitset<LAYER_3D_END> visibilityFlags = GetVisibleLayers();
294
295 m_trackCount = 0;
297 m_viaCount = 0;
299 m_holeCount = 0;
301
302 if( !m_board )
303 return;
304
305 // Prepare track list, convert in a vector. Calc statistic for the holes
306 std::vector<const PCB_TRACK*> trackList;
307 trackList.clear();
308 trackList.reserve( m_board->Tracks().size() );
309
310 for( PCB_TRACK* track : m_board->Tracks() )
311 {
312 // Skip tracks (not vias theyt are on more than one layer ) on disabled layers
313 if( track->Type() != PCB_VIA_T && !Is3dLayerEnabled( track->GetLayer(), visibilityFlags ) )
314 {
315 continue;
316 }
317
318 // Note: a PCB_TRACK holds normal segment tracks and also vias circles (that have also
319 // drill values)
320 trackList.push_back( track );
321
322 if( track->Type() == PCB_VIA_T )
323 {
324 const PCB_VIA *via = static_cast< const PCB_VIA*>( track );
325 m_viaCount++;
326 m_averageViaHoleDiameter += static_cast<float>( via->GetDrillValue() * m_biuTo3Dunits );
327 }
328 else
329 {
330 m_trackCount++;
331 m_averageTrackWidth += static_cast<float>( track->GetWidth() * m_biuTo3Dunits );
332 }
333 }
334
335 if( m_trackCount )
337
338 if( m_viaCount )
340
341 // Prepare copper layers index and containers
342 std::vector<PCB_LAYER_ID> layer_ids;
343 layer_ids.clear();
344 layer_ids.reserve( m_copperLayersCount );
345
347 {
348 if( !Is3dLayerEnabled( layer, visibilityFlags ) ) // Skip non enabled layers
349 continue;
350
351 layer_ids.push_back( layer );
352
353 BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
354 m_layerMap[layer] = layerContainer;
355
357 {
358 SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET;
359 m_layers_poly[layer] = layerPoly;
360 }
361 }
362
363 if( cfg.DifferentiatePlatedCopper() )
364 {
367
370 }
371
372 if( cfg.show_off_board_silk )
373 {
376 }
377
378 if( aStop.stop_requested() )
379 return;
380
381 if( aStatusReporter )
382 aStatusReporter->Report( _( "Create tracks and vias" ) );
383
384 // Create tracks as objects and add it to container
385 for( PCB_LAYER_ID layer : layer_ids )
386 {
387 wxASSERT( m_layerMap.contains( layer ) );
388
389 BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
390
391 for( const PCB_TRACK* track : trackList )
392 {
393 // NOTE: Vias can be on multiple layers
394 if( !track->IsOnLayer( layer ) )
395 continue;
396
397 // Skip vias annulus when not flashed on this layer
398 if( track->Type() == PCB_VIA_T && !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
399 continue;
400
401 // Add object item to layer container
402 createTrackWithMargin( track, layerContainer, layer );
403 }
404 }
405
406 if( aStop.stop_requested() )
407 return;
408
409 // Create VIAS and THTs objects and add it to holes containers
410 for( PCB_LAYER_ID layer : layer_ids )
411 {
412 // Check if the layer is already created
413 if( !m_layerHoleMap.contains( layer ) )
414 {
415 m_layerHoleMap[layer] = new BVH_CONTAINER_2D;
416 }
417
418 // ADD TRACKS
419 unsigned int nTracks = trackList.size();
420
421 for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
422 {
423 const PCB_TRACK *track = trackList[trackIdx];
424
425 if( !track->IsOnLayer( layer ) )
426 continue;
427
428 // ADD VIAS and THT
429 if( track->Type() == PCB_VIA_T )
430 {
431 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
432 const VIATYPE viatype = via->GetViaType();
433 const double holediameter = via->GetDrillValue() * BiuTo3dUnits();
434 const double viasize = via->GetWidth( layer ) * BiuTo3dUnits();
435 const double plating = GetHolePlatingThickness() * BiuTo3dUnits();
436
437 // holes and layer copper extend half info cylinder wall to hide transition
438 const float thickness = static_cast<float>( plating / 2.0f );
439 const float hole_inner_radius = static_cast<float>( holediameter / 2.0f );
440 const float ring_radius = static_cast<float>( viasize / 2.0f );
441
442 const bool capped = via->ResolveCappingMode() == CAPPING_MODE::CAPPED;
443
444 const SFVEC2F via_center( via->GetStart().x * m_biuTo3Dunits,
445 -via->GetStart().y * m_biuTo3Dunits );
446
447 if( viatype != VIATYPE::THROUGH )
448 {
449 // Add hole objects
450 BVH_CONTAINER_2D *layerHoleContainer = nullptr;
451 layerHoleContainer = m_layerHoleMap[layer];
452
453 // Add a hole for this layer
454 layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness,
455 *track ) );
456 }
457 else if( layer == layer_ids[0] ) // it only adds once the THT holes
458 {
459 // Add through hole object
460 if( !capped || !( IsFrontLayer( layer ) || IsBackLayer( layer ) ) )
461 {
462 m_TH_ODs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness, *track ) );
463 m_viaTH_ODs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness, *track ) );
464 }
465
466 if( cfg.clip_silk_on_via_annuli && ring_radius > 0.0 )
467 m_viaAnnuli.Add( new FILLED_CIRCLE_2D( via_center, ring_radius, *track ) );
468
469 if( hole_inner_radius > 0.0 )
470 m_TH_IDs.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius, *track ) );
471 }
472
473 // Add backdrill cutouts for vias - affects specific layers only
474 for( const PADSTACK::DRILL_PROPS& backdrill : { via->Padstack().SecondaryDrill(),
475 via->Padstack().TertiaryDrill() } )
476 {
477 float backdrillRadius = (float) backdrill.size.x * 0.5f * m_biuTo3Dunits;
478
479 // Only add if backdrill is larger than original hole
480 if( backdrillRadius > hole_inner_radius + thickness )
481 {
482 if( alg::contains( layer_ids, backdrill.start ) && alg::contains( layer_ids, backdrill.end ) )
483 {
484 if( LAYER_RANGE( backdrill.start, backdrill.end, m_copperLayersCount ).Contains( layer ) )
485 {
486 // Add to layer hole map for this layer
487 BVH_CONTAINER_2D* layerHoleContainer = m_layerHoleMap[layer];
488
489 layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center, backdrillRadius, *track ) );
490
491 // CounterboreCutouts are also required for silkscreen clipping
492 if( IsFrontLayer( layer ) )
493 {
494 m_frontCounterboreCutouts.Add( new FILLED_CIRCLE_2D( via_center, backdrillRadius,
495 *track ) );
496 }
497 else
498 {
499 m_backCounterboreCutouts.Add( new FILLED_CIRCLE_2D( via_center, backdrillRadius,
500 *track ) );
501 }
502 }
503 }
504
505 if( backdrill.start == F_Cu )
506 m_frontBackdrillCutouts.Add( new FILLED_CIRCLE_2D( via_center, backdrillRadius, *track ) );
507 else
508 m_backBackdrillCutouts.Add( new FILLED_CIRCLE_2D( via_center, backdrillRadius, *track ) );
509 }
510 }
511
512 // Add counterbore/countersink cutouts for vias
513 const auto frontMode = via->GetFrontPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::UNKNOWN );
514
515 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
516 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
517 {
518 const double frontR = (float) via->GetFrontPostMachiningSize() * 0.5f * m_biuTo3Dunits;
519
520 if( frontR > hole_inner_radius )
521 {
522 if( layer == layer_ids[0] ) // only add once for front layer
523 {
524 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
525 m_frontCounterboreCutouts.Add( new FILLED_CIRCLE_2D( via_center, frontR, *track ) );
526 else
527 m_frontCountersinkCutouts.Add( new FILLED_CIRCLE_2D( via_center, frontR, *track ) );
528 }
529
530 BVH_CONTAINER_2D *layerHoleContainer = m_layerHoleMap[layer];
531 layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center, frontR + thickness, *track ) );
532 }
533 }
534
535 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
536 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
537 {
538 const double backR = (float) via->GetBackPostMachiningSize() * 0.5f * m_biuTo3Dunits;
539
540 if( backR > hole_inner_radius )
541 {
542 if( layer == layer_ids.back() ) // only add once for back layer
543 {
544 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
545 m_backCounterboreCutouts.Add( new FILLED_CIRCLE_2D( via_center, backR, *track ) );
546 else
547 m_backCountersinkCutouts.Add( new FILLED_CIRCLE_2D( via_center, backR, *track ) );
548 }
549
550 BVH_CONTAINER_2D *layerHoleContainer = m_layerHoleMap[layer];
551 layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center, backR + thickness, *track ) );
552 }
553 }
554 }
555
556 if( cfg.DifferentiatePlatedCopper() && layer == F_Cu )
557 {
559 ERROR_INSIDE );
560 }
561 else if( cfg.DifferentiatePlatedCopper() && layer == B_Cu )
562 {
564 ERROR_INSIDE );
565 }
566 }
567
568 if( aStop.stop_requested() )
569 return;
570 }
571
572 // Create VIAS and THTs objects and add it to holes containers
573 for( PCB_LAYER_ID layer : layer_ids )
574 {
575 if( !m_layerHoleOdPolys.contains( layer ) )
577
578 if( !m_layerHoleIdPolys.contains( layer ) )
580
581 // ADD TRACKS
582 const unsigned int nTracks = trackList.size();
583
584 for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
585 {
586 const PCB_TRACK *track = trackList[trackIdx];
587
588 if( !track->IsOnLayer( layer ) )
589 continue;
590
591 // ADD VIAS and THT
592 if( track->Type() == PCB_VIA_T )
593 {
594 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
595 const VIATYPE viatype = via->GetViaType();
596
597 // Add outer holes of VIAs
598 SHAPE_POLY_SET *layerOuterHolesPoly = nullptr;
599 SHAPE_POLY_SET *layerInnerHolesPoly = nullptr;
600
601 // found
602 wxASSERT( m_layerHoleOdPolys.contains( layer ) );
603 wxASSERT( m_layerHoleIdPolys.contains( layer ) );
604
605 layerOuterHolesPoly = m_layerHoleOdPolys[layer];
606 layerInnerHolesPoly = m_layerHoleIdPolys[layer];
607
608 const int holediameter = via->GetDrillValue();
609 const int hole_outer_radius = (holediameter / 2) + GetHolePlatingThickness();
610
611 if( viatype != VIATYPE::THROUGH )
612 {
613 // Add PCB_VIA hole contours
614 TransformCircleToPolygon( *layerOuterHolesPoly, via->GetStart(), hole_outer_radius,
615 via->GetMaxError(), ERROR_INSIDE );
616
617 TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(), holediameter / 2,
618 via->GetMaxError(), ERROR_INSIDE );
619 }
620 else if( layer == layer_ids[0] ) // it only adds once the THT holes
621 {
622 const int hole_outer_ring_radius = KiROUND( via->GetWidth( layer ) / 2.0 );
623
624 // Add through hole contours
625 TransformCircleToPolygon( m_TH_ODPolys, via->GetStart(), hole_outer_radius,
626 via->GetMaxError(), ERROR_INSIDE );
627
628 // Add same thing for vias only
629 TransformCircleToPolygon( m_viaTH_ODPolys, via->GetStart(), hole_outer_radius,
630 via->GetMaxError(), ERROR_INSIDE );
631
633 {
634 TransformCircleToPolygon( m_viaAnnuliPolys, via->GetStart(), hole_outer_ring_radius,
635 via->GetMaxError(), ERROR_INSIDE );
636 }
637 }
638
639 // Add backdrill polygons for vias - affects specific layers only
640 for( const PADSTACK::DRILL_PROPS& backdrill : { via->Padstack().SecondaryDrill(),
641 via->Padstack().TertiaryDrill() } )
642 {
643 if( backdrill.size.x > 0
644 && alg::contains( layer_ids, backdrill.start )
645 && alg::contains( layer_ids, backdrill.end ) )
646 {
647 const int backdrillRadiusBIU = backdrill.size.x / 2;
648 const int backdrillOuterRadiusBIU = backdrillRadiusBIU + GetHolePlatingThickness();
649 const int holeOuterRadiusBIU = hole_outer_radius;
650
651 // Only add if backdrill is larger than original hole outer diameter
652 if( backdrillOuterRadiusBIU > holeOuterRadiusBIU )
653 {
654 // Iterate through layers affected by backdrill
655 if( LAYER_RANGE( backdrill.start, backdrill.end, m_copperLayersCount ).Contains( layer ) )
656 {
657 TransformCircleToPolygon( *m_layerHoleOdPolys[layer], via->GetStart(),
658 backdrillOuterRadiusBIU, via->GetMaxError(), ERROR_INSIDE );
659
660 TransformCircleToPolygon( *m_layerHoleIdPolys[layer], via->GetStart(),
661 backdrillRadiusBIU, via->GetMaxError(), ERROR_INSIDE );
662
664 backdrillOuterRadiusBIU, via->GetMaxError(), ERROR_INSIDE );
665 }
666 }
667 }
668 }
669
670 // Add counterbore/countersink polygons for vias
671 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
672 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
673 {
674 const int frontRadiusBIU = via->GetFrontPostMachiningSize() / 2;
675
676 if( frontRadiusBIU > holediameter / 2 )
677 {
678 int frontRadiusOuterBIU = frontRadiusBIU + GetHolePlatingThickness();
679
680 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
681 {
682 TransformCircleToPolygon( m_frontCounterborePolys, via->GetStart(), frontRadiusBIU,
683 via->GetMaxError(), ERROR_INSIDE );
684 }
685 else
686 {
687 TransformCircleToPolygon( m_frontCountersinkPolys, via->GetStart(), frontRadiusBIU,
688 via->GetMaxError(), ERROR_INSIDE );
689 }
690
691 TransformCircleToPolygon( *layerOuterHolesPoly, via->GetStart(), frontRadiusOuterBIU,
692 via->GetMaxError(), ERROR_INSIDE );
693 TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(), frontRadiusBIU,
694 via->GetMaxError(), ERROR_INSIDE );
695 }
696 }
697
698 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
699 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
700 {
701 const int backRadiusBIU = via->GetBackPostMachiningSize() / 2;
702
703 if( backRadiusBIU > holediameter / 2 )
704 {
705 int backRadiusOuterBIU = backRadiusBIU + GetHolePlatingThickness();
706
707 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
708 {
709 TransformCircleToPolygon( m_backCounterborePolys, via->GetStart(), backRadiusBIU,
710 via->GetMaxError(), ERROR_INSIDE );
711 }
712 else
713 {
714 TransformCircleToPolygon( m_backCountersinkPolys, via->GetStart(), backRadiusBIU,
715 via->GetMaxError(), ERROR_INSIDE );
716 }
717
718 TransformCircleToPolygon( *layerOuterHolesPoly, via->GetStart(), backRadiusOuterBIU,
719 via->GetMaxError(), ERROR_INSIDE );
720 TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(), backRadiusBIU,
721 via->GetMaxError(), ERROR_INSIDE );
722 }
723 }
724 }
725
726 if( aStop.stop_requested() )
727 return;
728 }
729 }
730
731 // Creates vertical outline contours of the tracks and add it to the poly of the layer
733 {
734 for( PCB_LAYER_ID layer : layer_ids )
735 {
736 wxASSERT( m_layers_poly.contains( layer ) );
737
738 SHAPE_POLY_SET *layerPoly = m_layers_poly[layer];
739
740 // ADD TRACKS
741 unsigned int nTracks = trackList.size();
742
743 for( unsigned int trackIdx = 0; trackIdx < nTracks; ++trackIdx )
744 {
745 const PCB_TRACK *track = trackList[trackIdx];
746
747 if( !track->IsOnLayer( layer ) )
748 continue;
749
750 // Skip vias annulus when not flashed on this layer
751 if( track->Type() == PCB_VIA_T && !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
752 continue;
753
754 // Add the track/via contour
755 track->TransformShapeToPolygon( *layerPoly, layer, 0, track->GetMaxError(), ERROR_INSIDE );
756 }
757 }
758 }
759
760 if( aStop.stop_requested() )
761 return;
762
763 // Add holes of footprints
764 for( FOOTPRINT* footprint : m_board->Footprints() )
765 {
766 for( PAD* pad : footprint->Pads() )
767 {
768 // Note: holes of NPTH are already built by GetBoardPolygonOutlines
769 if( !pad->HasHole() )
770 continue;
771
772 m_holeCount++;
773 double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0;
774 m_averageHoleDiameter += static_cast<float>( holeDiameter * m_biuTo3Dunits );
775
776 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
777 {
778 // Ensure the silk drawings are clipped to the NPTH hole, like other pad/via holes
779 // even if the clip to board body is not activated (remember NPTH holes are part of
780 // the board body)
782 continue;
783 }
784
785 // The hole in the body is inflated by copper thickness
786 int inflate = KiROUND( GetHolePlatingThickness() / 2.0 );
787
788 createPadHoleShape( pad, &m_TH_ODs, inflate );
789
791 createPadHoleShape( pad, &m_viaAnnuli, inflate );
792
794
795 const float holeDiameterIU = (float) ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0f;
796 const float holeInnerRadius = holeDiameterIU * 0.5f * (float) m_biuTo3Dunits;
797 const SFVEC2F padCenter( pad->GetPosition().x * static_cast<float>( m_biuTo3Dunits ),
798 -pad->GetPosition().y * static_cast<float>( m_biuTo3Dunits ) );
799
800 // Add backdrill cutouts for pads - affects specific layers only
801 for( const PADSTACK::DRILL_PROPS& backdrill : { pad->Padstack().SecondaryDrill(),
802 pad->Padstack().TertiaryDrill() } )
803 {
804 if( ( backdrill.size.x > 0 || backdrill.size.y > 0 )
805 && alg::contains( layer_ids, backdrill.start )
806 && alg::contains( layer_ids, backdrill.end ) )
807 {
808 const float backdrillR = (float) ( backdrill.size.x + backdrill.size.y ) * 0.25f
809 * (float) m_biuTo3Dunits;
810
811 // The hole outer diameter with plating
812 const float holeOuterR = holeInnerRadius + (float) GetHolePlatingThickness() * m_biuTo3Dunits;
813
814 // Only add if backdrill is larger than original hole outer diameter
815 if( backdrillR > holeOuterR )
816 {
817 // Iterate through layers affected by backdrill
818 for( PCB_LAYER_ID layer : LAYER_RANGE( backdrill.start, backdrill.end, m_copperLayersCount ) )
819 {
820 // Add to layer hole map for this layer
821 BVH_CONTAINER_2D* layerHoleContainer = nullptr;
822
823 if( !m_layerHoleMap.contains( layer ) )
824 {
825 layerHoleContainer = new BVH_CONTAINER_2D;
826 m_layerHoleMap[layer] = layerHoleContainer;
827 }
828 else
829 {
830 layerHoleContainer = m_layerHoleMap[layer];
831 }
832
833 layerHoleContainer->Add( new FILLED_CIRCLE_2D( padCenter, backdrillR, *pad ) );
834 }
835 }
836 }
837 }
838
839 // Add counterbore/countersink cutouts for pads
840 if( pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
841 || pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
842 {
843 float frontRadius = (float) pad->GetFrontPostMachiningSize() * 0.5f * (float) m_biuTo3Dunits;
844
845 if( frontRadius > holeInnerRadius )
846 {
847 if( pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
848 m_frontCounterboreCutouts.Add( new FILLED_CIRCLE_2D( padCenter, frontRadius, *pad ) );
849 else
850 m_frontCountersinkCutouts.Add( new FILLED_CIRCLE_2D( padCenter, frontRadius, *pad ) );
851 }
852 }
853
854 if( pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
855 || pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
856 {
857 float backRadius = (float) pad->GetBackPostMachiningSize() * 0.5f * (float) m_biuTo3Dunits;
858
859 if( backRadius > holeInnerRadius )
860 {
861 if( pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
862 m_backCounterboreCutouts.Add( new FILLED_CIRCLE_2D( padCenter, backRadius, *pad ) );
863 else
864 m_backCountersinkCutouts.Add( new FILLED_CIRCLE_2D( padCenter, backRadius, *pad ) );
865 }
866 }
867 }
868
869 if( aStop.stop_requested() )
870 return;
871 }
872
873 if( m_holeCount )
875
876 // Add contours of the pad holes (pads can be Circle or Segment holes)
877 for( FOOTPRINT* footprint : m_board->Footprints() )
878 {
879 for( PAD* pad : footprint->Pads() )
880 {
881 if( !pad->HasHole() )
882 continue;
883
884 // The hole in the body is inflated by copper thickness.
885 const int inflate = GetHolePlatingThickness();
886
887 if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
888 {
890 pad->TransformHoleToPolygon( m_viaAnnuliPolys, inflate, pad->GetMaxError(), ERROR_INSIDE );
891
892 pad->TransformHoleToPolygon( m_TH_ODPolys, inflate, pad->GetMaxError(), ERROR_INSIDE );
893 }
894 else
895 {
896 // If not plated, no copper.
898 pad->TransformHoleToPolygon( m_viaAnnuliPolys, 0, pad->GetMaxError(), ERROR_INSIDE );
899
900 pad->TransformHoleToPolygon( m_NPTH_ODPolys, 0, pad->GetMaxError(), ERROR_INSIDE );
901 }
902
903
904 // Add counterbore/countersink polygons for pads
905 const double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0;
906 const int holeRadius = KiROUND( holeDiameter / 2.0 );
907
908 const std::optional<PAD_DRILL_POST_MACHINING_MODE> frontMode = pad->GetFrontPostMachining();
909
910 if( frontMode.has_value()
912 && frontMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
913 {
914 const int frontRadiusBIU = pad->GetFrontPostMachiningSize() / 2;
915
916 if( frontRadiusBIU > holeRadius )
917 {
918 if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
919 {
920 TransformCircleToPolygon( m_frontCounterborePolys, pad->GetPosition(), frontRadiusBIU,
921 pad->GetMaxError(), ERROR_INSIDE );
922 }
923 else if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
924 {
925 TransformCircleToPolygon( m_frontCountersinkPolys, pad->GetPosition(), frontRadiusBIU,
926 pad->GetMaxError(), ERROR_INSIDE );
927 }
928 }
929 }
930
931 const std::optional<PAD_DRILL_POST_MACHINING_MODE> backMode = pad->GetBackPostMachining();
932
933 if( backMode.has_value()
935 && backMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
936 {
937 const int backRadiusBIU = pad->GetBackPostMachiningSize() / 2;
938
939 if( backRadiusBIU > holeRadius )
940 {
941 if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE )
942 {
943 TransformCircleToPolygon( m_backCounterborePolys, pad->GetPosition(), backRadiusBIU,
944 pad->GetMaxError(), ERROR_INSIDE );
945 }
946 else if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
947 {
948 TransformCircleToPolygon( m_backCountersinkPolys, pad->GetPosition(), backRadiusBIU,
949 pad->GetMaxError(), ERROR_INSIDE );
950 }
951 }
952 }
953
954 // Add backdrill polygons for pads - affects specific layers only
955 for( const PADSTACK::DRILL_PROPS& backdrill : { pad->Padstack().SecondaryDrill(),
956 pad->Padstack().TertiaryDrill() } )
957 {
958 if( ( backdrill.size.x > 0 || backdrill.size.y > 0 )
959 && alg::contains( layer_ids, backdrill.start )
960 && alg::contains( layer_ids, backdrill.end ) )
961 {
962 const int drilllRadiusBIU = ( backdrill.size.x + backdrill.size.y ) / 4;
963 const int holeOuterRadiusBIU = holeRadius + inflate;
964
965 // Only add if backdrill is larger than original hole outer diameter
966 if( drilllRadiusBIU > holeOuterRadiusBIU )
967 {
968 if( backdrill.start == F_Cu )
969 {
970 TransformCircleToPolygon( m_FrontBackdrillPolys, pad->GetPosition(), drilllRadiusBIU,
971 pad->GetMaxError(), ERROR_INSIDE );
972 }
973 else
974 {
975 TransformCircleToPolygon( m_BackBackdrillPolys, pad->GetPosition(), drilllRadiusBIU,
976 pad->GetMaxError(), ERROR_INSIDE );
977 }
978
979 // Iterate through layers affected by backdrill
980 for( PCB_LAYER_ID layer : LAYER_RANGE( backdrill.start, backdrill.end, m_copperLayersCount ) )
981 {
982 // Add polygon to per-layer hole polys
983 SHAPE_POLY_SET* layerHolePoly = nullptr;
984
985 if( !m_layerHoleOdPolys.contains( layer ) )
986 {
987 layerHolePoly = new SHAPE_POLY_SET;
988 m_layerHoleOdPolys[layer] = layerHolePoly;
989 }
990 else
991 {
992 layerHolePoly = m_layerHoleOdPolys[layer];
993 }
994
995 TransformCircleToPolygon( *layerHolePoly, pad->GetPosition(), drilllRadiusBIU,
996 pad->GetMaxError(), ERROR_INSIDE );
997 }
998 }
999 }
1000 }
1001 }
1002
1003 if( aStop.stop_requested() )
1004 return;
1005 }
1006
1007 // Add footprints copper items (pads, shapes and text) to containers
1008 for( PCB_LAYER_ID layer : layer_ids )
1009 {
1010 wxASSERT( m_layerMap.contains( layer ) );
1011
1012 BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
1013
1014 for( FOOTPRINT* fp : m_board->Footprints() )
1015 {
1016 addPads( fp, layerContainer, layer );
1017 addFootprintShapes( fp, layerContainer, layer, visibilityFlags );
1018
1019 // Add copper item to the plated copper polygon list if required
1020 if( cfg.DifferentiatePlatedCopper() && IsExternalCopperLayer( layer ) )
1021 {
1023
1024 fp->TransformPadsToPolySet( *layerPoly, layer, 0, fp->GetMaxError(), ERROR_INSIDE );
1025 transformFPTextToPolySet( fp, layer, visibilityFlags, *layerPoly, fp->GetMaxError(), ERROR_INSIDE );
1026 transformFPShapesToPolySet( fp, layer, *layerPoly, fp->GetMaxError(), ERROR_INSIDE );
1027 }
1028
1029 // Add copper item to poly contours (vertical outlines) if required
1031 {
1032 wxASSERT( m_layers_poly.contains( layer ) );
1033
1034 SHAPE_POLY_SET* layerPoly = m_layers_poly[layer];
1035
1036 fp->TransformPadsToPolySet( *layerPoly, layer, 0, fp->GetMaxError(), ERROR_INSIDE );
1037 transformFPTextToPolySet( fp, layer, visibilityFlags, *layerPoly, fp->GetMaxError(), ERROR_INSIDE );
1038 transformFPShapesToPolySet( fp, layer, *layerPoly, fp->GetMaxError(), ERROR_INSIDE );
1039 }
1040
1041 if( aStop.stop_requested() )
1042 return;
1043 }
1044 }
1045
1046 // Add graphic item on copper layers to object containers
1047 for( PCB_LAYER_ID layer : layer_ids )
1048 {
1049 wxASSERT( m_layerMap.contains( layer ) );
1050
1051 BVH_CONTAINER_2D *layerContainer = m_layerMap[layer];
1052
1053 // Add graphic items on copper layers (texts and other graphics)
1054 for( BOARD_ITEM* item : m_board->Drawings() )
1055 {
1056 if( !item->IsOnLayer( layer ) )
1057 continue;
1058
1059 switch( item->Type() )
1060 {
1061 case PCB_SHAPE_T:
1062 addShape( static_cast<PCB_SHAPE*>( item ), layerContainer, item, layer );
1063 break;
1064
1065 case PCB_TEXT_T:
1066 addText( static_cast<PCB_TEXT*>( item ), layerContainer, item );
1067 break;
1068
1069 case PCB_TEXTBOX_T:
1070 addShape( static_cast<PCB_TEXTBOX*>( item ), layerContainer, item );
1071 break;
1072
1073 case PCB_TABLE_T:
1074 addTable( static_cast<PCB_TABLE*>( item ), layerContainer, item );
1075 break;
1076
1077 case PCB_BARCODE_T:
1078 addBarCode( static_cast<PCB_BARCODE*>( item ), layerContainer, item );
1079 break;
1080
1081 case PCB_DIM_ALIGNED_T:
1082 case PCB_DIM_CENTER_T:
1083 case PCB_DIM_RADIAL_T:
1085 case PCB_DIM_LEADER_T:
1086 addShape( static_cast<PCB_DIMENSION_BASE*>( item ), layerContainer, item );
1087 break;
1088
1089 case PCB_REFERENCE_IMAGE_T: // ignore
1090 break;
1091
1092 default:
1093 wxLogTrace( m_logTrace, wxT( "createLayers: item type: %d not implemented" ), item->Type() );
1094 break;
1095 }
1096
1097 // Add copper item to the plated copper polygon list if required
1098 if( cfg.DifferentiatePlatedCopper() && IsExternalCopperLayer( layer ) )
1099 {
1101
1102 // Note: for TEXT and TEXTBOX, TransformShapeToPolygon returns the bounding
1103 // box shape, not the exact text shape. So it is not used for these items
1104 if( item->Type() == PCB_TEXTBOX_T )
1105 {
1106 PCB_TEXTBOX* text_box = static_cast<PCB_TEXTBOX*>( item );
1107 text_box->TransformTextToPolySet( *copperPolys, 0, text_box->GetMaxError(), ERROR_INSIDE );
1108
1109 // Add box outlines
1110 text_box->PCB_SHAPE::TransformShapeToPolygon( *copperPolys, layer, 0, text_box->GetMaxError(),
1111 ERROR_INSIDE );
1112 }
1113 else if( item->Type() == PCB_TEXT_T )
1114 {
1115 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
1116 text->TransformTextToPolySet( *copperPolys, 0, text->GetMaxError(), ERROR_INSIDE );
1117 }
1118 else if( item->Type() != PCB_REFERENCE_IMAGE_T )
1119 {
1120 item->TransformShapeToPolySet( *copperPolys, layer, 0, item->GetMaxError(), ERROR_INSIDE );
1121 }
1122 }
1123
1124 // Add copper item to poly contours (vertical outlines) if required
1126 {
1127 wxASSERT( m_layers_poly.contains( layer ) );
1128
1129 SHAPE_POLY_SET *layerPoly = m_layers_poly[layer];
1130
1131 switch( item->Type() )
1132 {
1133 case PCB_SHAPE_T:
1134 item->TransformShapeToPolySet( *layerPoly, layer, 0, item->GetMaxError(), ERROR_INSIDE );
1135 break;
1136
1137 case PCB_TEXT_T:
1138 {
1139 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
1140
1141 text->TransformTextToPolySet( *layerPoly, 0, text->GetMaxError(), ERROR_INSIDE );
1142 break;
1143 }
1144
1145 case PCB_TEXTBOX_T:
1146 {
1147 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
1148
1149 if( textbox->IsBorderEnabled() )
1150 {
1151 textbox->PCB_SHAPE::TransformShapeToPolygon( *layerPoly, layer, 0, textbox->GetMaxError(),
1152 ERROR_INSIDE );
1153 }
1154
1155 textbox->TransformTextToPolySet( *layerPoly, 0, textbox->GetMaxError(), ERROR_INSIDE );
1156 break;
1157 }
1158
1159 case PCB_TABLE_T:
1160 {
1161 PCB_TABLE* table = static_cast<PCB_TABLE*>( item );
1162
1163 for( PCB_TABLECELL* cell : table->GetCells() )
1164 cell->TransformTextToPolySet( *layerPoly, 0, cell->GetMaxError(), ERROR_INSIDE );
1165
1166 table->DrawBorders(
1167 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB,
1168 const STROKE_PARAMS& stroke )
1169 {
1170 SHAPE_SEGMENT seg( ptA, ptB, stroke.GetWidth() );
1171 seg.TransformToPolygon( *layerPoly, table->GetMaxError(), ERROR_INSIDE );
1172 } );
1173 break;
1174 }
1175
1176 case PCB_BARCODE_T:
1177 {
1178 PCB_BARCODE* bar_code = static_cast<PCB_BARCODE*>( item );
1179
1180 bar_code->TransformShapeToPolySet( *layerPoly, layer, 0, 0, ERROR_INSIDE );
1181 break;
1182 }
1183
1184 case PCB_DIM_ALIGNED_T:
1185 case PCB_DIM_CENTER_T:
1186 case PCB_DIM_RADIAL_T:
1188 case PCB_DIM_LEADER_T:
1189 {
1190 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( item );
1191
1192 dimension->TransformTextToPolySet( *layerPoly, 0, dimension->GetMaxError(), ERROR_INSIDE );
1193
1194 for( const std::shared_ptr<SHAPE>& shape : dimension->GetShapes() )
1195 shape->TransformToPolygon( *layerPoly, dimension->GetMaxError(), ERROR_INSIDE );
1196
1197 break;
1198 }
1199
1200 case PCB_REFERENCE_IMAGE_T: // ignore
1201 break;
1202
1203 default:
1204 wxLogTrace( m_logTrace, wxT( "createLayers: item type: %d not implemented" ), item->Type() );
1205 break;
1206 }
1207 }
1208 }
1209
1210 if( aStop.stop_requested() )
1211 return;
1212 }
1213
1214 if( aStop.stop_requested() )
1215 return;
1216
1217 if( cfg.show_zones )
1218 {
1219 if( aStatusReporter )
1220 aStatusReporter->Report( _( "Create zones" ) );
1221
1222 std::vector<std::pair<ZONE*, PCB_LAYER_ID>> zones;
1223 std::unordered_map<PCB_LAYER_ID, std::unique_ptr<std::mutex>> layer_lock;
1224
1225 for( ZONE* zone : m_board->Zones() )
1226 {
1227 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1228 {
1229 zones.emplace_back( std::make_pair( zone, layer ) );
1230 layer_lock.emplace( layer, std::make_unique<std::mutex>() );
1231
1232 if( cfg.DifferentiatePlatedCopper() && IsExternalCopperLayer( layer ) )
1233 {
1235
1236 zone->TransformShapeToPolygon( *copperPolys, layer, 0, zone->GetMaxError(), ERROR_INSIDE );
1237 }
1238 }
1239
1240 if( aStop.stop_requested() )
1241 return;
1242 }
1243
1244 // Add zones objects
1245 std::atomic<size_t> nextZone( 0 );
1246 std::atomic<size_t> threadsFinished( 0 );
1247
1248 size_t parallelThreadCount = std::min<size_t>( zones.size(),
1249 std::max<size_t>( std::thread::hardware_concurrency(), 2 ) );
1250
1251 for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1252 {
1253 std::thread t = std::thread(
1254 [&]()
1255 {
1256 for( size_t areaId = nextZone.fetch_add( 1 );
1257 areaId < zones.size();
1258 areaId = nextZone.fetch_add( 1 ) )
1259 {
1260 ZONE* zone = zones[areaId].first;
1261
1262 if( zone == nullptr )
1263 break;
1264
1265 PCB_LAYER_ID layer = zones[areaId].second;
1266
1267 if( m_layerMap.contains( layer ) )
1268 addSolidAreasShapes( zone, m_layerMap[layer], layer );
1269
1271 && m_layers_poly.contains( layer ) )
1272 {
1273 auto mut_it = layer_lock.find( layer );
1274
1275 if( mut_it != layer_lock.end() )
1276 {
1277 std::lock_guard< std::mutex > lock( *( mut_it->second ) );
1278 zone->TransformSolidAreasShapesToPolygon( layer, *m_layers_poly[layer] );
1279 }
1280 }
1281 }
1282
1283 threadsFinished++;
1284 } );
1285
1286 t.detach();
1287 }
1288
1289 while( threadsFinished < parallelThreadCount )
1290 std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
1291 }
1292 // End Build Copper layers
1293
1294 if( aStop.stop_requested() )
1295 return;
1296
1297 // This will make a union of all added contours
1298 m_TH_ODPolys.Simplify();
1299 m_NPTH_ODPolys.Simplify();
1300 m_viaTH_ODPolys.Simplify();
1301 m_viaAnnuliPolys.Simplify();
1302
1303 m_frontCounterborePolys.Simplify();
1304 m_backCounterborePolys.Simplify();
1305 m_frontCountersinkPolys.Simplify();
1306 m_backCountersinkPolys.Simplify();
1307
1308 // Build Tech layers
1309 // Based on:
1310 // https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L1059
1311 if( aStatusReporter )
1312 aStatusReporter->Report( _( "Build Tech layers" ) );
1313
1314 // draw graphic items, on technical layers
1315
1316 LSEQ techLayerList = LSET::AllNonCuMask().Seq( {
1317 B_Adhes,
1318 F_Adhes,
1319 B_Paste,
1320 F_Paste,
1321 B_SilkS,
1322 F_SilkS,
1323 B_Mask,
1324 F_Mask,
1325
1326 // Aux Layers
1327 Dwgs_User,
1328 Cmts_User,
1329 Eco1_User,
1330 Eco2_User,
1331 F_Fab,
1332 B_Fab,
1333 F_CrtYd,
1334 B_CrtYd,
1335 User_1,
1336 User_2,
1337 User_3,
1338 User_4,
1339 User_5,
1340 User_6,
1341 User_7,
1342 User_8,
1343 User_9,
1344 User_10,
1345 User_11,
1346 User_12,
1347 User_13,
1348 User_14,
1349 User_15,
1350 User_16,
1351 User_17,
1352 User_18,
1353 User_19,
1354 User_20,
1355 User_21,
1356 User_22,
1357 User_23,
1358 User_24,
1359 User_25,
1360 User_26,
1361 User_27,
1362 User_28,
1363 User_29,
1364 User_30,
1365 User_31,
1366 User_32,
1367 User_33,
1368 User_34,
1369 User_35,
1370 User_36,
1371 User_37,
1372 User_38,
1373 User_39,
1374 User_40,
1375 User_41,
1376 User_42,
1377 User_43,
1378 User_44,
1379 User_45,
1380 } );
1381
1382 std::bitset<LAYER_3D_END> enabledFlags = visibilityFlags;
1383
1385 {
1386 enabledFlags.set( LAYER_3D_SOLDERMASK_TOP );
1387 enabledFlags.set( LAYER_3D_SOLDERMASK_BOTTOM );
1388 }
1389
1390 if( aStop.stop_requested() )
1391 return;
1392
1393 for( PCB_LAYER_ID layer : techLayerList )
1394 {
1395 if( aStatusReporter )
1396 aStatusReporter->Report( wxString::Format( _( "Build Tech layer %d" ), (int) layer ) );
1397
1398 if( !Is3dLayerEnabled( layer, enabledFlags ) )
1399 continue;
1400
1401 BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
1402 m_layerMap[layer] = layerContainer;
1403
1404 SHAPE_POLY_SET *layerPoly = new SHAPE_POLY_SET;
1405 m_layers_poly[layer] = layerPoly;
1406
1407 if( Is3dLayerEnabled( layer, visibilityFlags ) )
1408 {
1409 // Add drawing objects
1410 for( BOARD_ITEM* item : m_board->Drawings() )
1411 {
1412 if( !item->IsOnLayer( layer ) )
1413 continue;
1414
1415 switch( item->Type() )
1416 {
1417 case PCB_SHAPE_T:
1418 addShape( static_cast<PCB_SHAPE*>( item ), layerContainer, item, layer );
1419 break;
1420
1421 case PCB_TEXT_T:
1422 addText( static_cast<PCB_TEXT*>( item ), layerContainer, item );
1423 break;
1424
1425 case PCB_TEXTBOX_T:
1426 addShape( static_cast<PCB_TEXTBOX*>( item ), layerContainer, item );
1427 break;
1428
1429 case PCB_TABLE_T:
1430 addTable( static_cast<PCB_TABLE*>( item ), layerContainer, item );
1431 break;
1432
1433 case PCB_BARCODE_T:
1434 addBarCode( static_cast<PCB_BARCODE*>( item ), layerContainer, item );
1435 break;
1436
1437 case PCB_DIM_ALIGNED_T:
1438 case PCB_DIM_CENTER_T:
1439 case PCB_DIM_RADIAL_T:
1441 case PCB_DIM_LEADER_T:
1442 addShape( static_cast<PCB_DIMENSION_BASE*>( item ), layerContainer, item );
1443 break;
1444
1445 default:
1446 break;
1447 }
1448 }
1449
1450 // Add track, via and arc tech layers
1451 if( IsSolderMaskLayer( layer ) )
1452 {
1453 for( PCB_TRACK* track : m_board->Tracks() )
1454 {
1455 if( !track->IsOnLayer( layer ) )
1456 continue;
1457
1458 // Only vias on a external copper layer can have a solder mask
1459 PCB_LAYER_ID copper_layer = ( layer == F_Mask ) ? F_Cu : B_Cu;
1460
1461 if( track->Type() == PCB_VIA_T )
1462 {
1463 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1464
1465 if( !via->FlashLayer( copper_layer ) )
1466 continue;
1467 }
1468
1469 int maskExpansion = track->GetSolderMaskExpansion();
1470 createTrackWithMargin( track, layerContainer, layer, maskExpansion );
1471 }
1472 }
1473
1474 // Add footprints tech layers - objects. Paste, mask, silk and fab belong to the
1475 // board fabrication outputs and render for every footprint, matching the gerber
1476 // plotters. DNP affects only the 3D model, handled by IsFootprintShown().
1477 for( FOOTPRINT* footprint : m_board->Footprints() )
1478 {
1479 if( layer == F_SilkS || layer == B_SilkS )
1480 {
1481 int linewidth = m_board->GetDesignSettings().m_LineThickness[ LAYER_CLASS_SILK ];
1482
1483 for( PAD* pad : footprint->Pads() )
1484 {
1485 if( !pad->IsOnLayer( layer ) )
1486 continue;
1487
1488 buildPadOutlineAsSegments( pad, layer, layerContainer, linewidth );
1489 }
1490 }
1491 else
1492 {
1493 addPads( footprint, layerContainer, layer );
1494 }
1495
1496 addFootprintShapes( footprint, layerContainer, layer, visibilityFlags );
1497 }
1498
1499 // Draw non copper zones
1500 if( cfg.show_zones )
1501 {
1502 for( ZONE* zone : m_board->Zones() )
1503 {
1504 if( zone->IsOnLayer( layer ) )
1505 addSolidAreasShapes( zone, layerContainer, layer );
1506 }
1507 }
1508 }
1509
1510 if( aStop.stop_requested() )
1511 return;
1512
1513 // Add item contours. We need these if we're building vertical walls or if this is a
1514 // mask layer and we're differentiating copper from plated copper.
1516 || ( cfg.DifferentiatePlatedCopper() && IsSolderMaskLayer( layer ) ) )
1517 {
1518 // DRAWINGS
1519 for( BOARD_ITEM* item : m_board->Drawings() )
1520 {
1521 if( !item->IsOnLayer( layer ) )
1522 continue;
1523
1524 switch( item->Type() )
1525 {
1526 case PCB_SHAPE_T:
1527 {
1528 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1529 int margin = 0;
1530
1531 if( IsSolderMaskLayer( layer ) && shape->HasSolderMask() )
1532 margin = shape->GetSolderMaskExpansion();
1533
1534 drawPcbShapeWithStyle( shape, layerPoly, margin );
1535 break;
1536 }
1537
1538 case PCB_TEXT_T:
1539 {
1540 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
1541
1542 text->TransformTextToPolySet( *layerPoly, 0, text->GetMaxError(), ERROR_INSIDE );
1543 break;
1544 }
1545
1546 case PCB_TEXTBOX_T:
1547 {
1548 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
1549
1550 if( textbox->IsBorderEnabled() )
1551 {
1552 // we use the box polygonal shape to honor the box rotation and line style
1553 PCB_SHAPE tb_box = textbox->GetPolygonalBoxShape();
1554 drawPcbShapeWithStyle( &tb_box, layerPoly );
1555 }
1556
1557 textbox->TransformTextToPolySet( *layerPoly, 0, textbox->GetMaxError(), ERROR_INSIDE );
1558 break;
1559 }
1560
1561 case PCB_TABLE_T:
1562 {
1563 PCB_TABLE* table = static_cast<PCB_TABLE*>( item );
1564
1565 for( PCB_TABLECELL* cell : table->GetCells() )
1566 cell->TransformTextToPolySet( *layerPoly, 0, cell->GetMaxError(), ERROR_INSIDE );
1567
1568 table->DrawBorders(
1569 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB,
1570 const STROKE_PARAMS& stroke )
1571 {
1572 SHAPE_SEGMENT seg( ptA, ptB, stroke.GetWidth() );
1573 seg.TransformToPolygon( *layerPoly, table->GetMaxError(), ERROR_INSIDE );
1574 } );
1575
1576 break;
1577 }
1578
1579 case PCB_BARCODE_T:
1580 {
1581 PCB_BARCODE* bar_code = static_cast<PCB_BARCODE*>( item );
1582
1583 bar_code->TransformShapeToPolySet( *layerPoly, layer, 0, 0, ERROR_INSIDE );
1584 break;
1585 }
1586
1587 default:
1588 break;
1589 }
1590 }
1591
1592 if( aStop.stop_requested() )
1593 return;
1594
1595 // NON-TENTED VIAS
1596 if( ( layer == F_Mask || layer == B_Mask ) )
1597 {
1598 int maskExpansion = GetBoard()->GetDesignSettings().m_SolderMaskExpansion;
1599
1600 for( PCB_TRACK* track : m_board->Tracks() )
1601 {
1602 if( track->Type() == PCB_VIA_T )
1603 {
1604 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1605
1606 if( via->FlashLayer( layer ) && !via->IsTented( layer ) )
1607 {
1608 track->TransformShapeToPolygon( *layerPoly, layer, maskExpansion, track->GetMaxError(),
1609 ERROR_INSIDE );
1610 }
1611 }
1612 else
1613 {
1614 if( track->HasSolderMask() )
1615 {
1616 track->TransformShapeToPolySet( *layerPoly, layer, maskExpansion, track->GetMaxError(),
1617 ERROR_INSIDE );
1618 }
1619 }
1620 }
1621 }
1622
1623 if( aStop.stop_requested() )
1624 return;
1625
1626 // FOOTPRINT CHILDREN
1627 for( FOOTPRINT* footprint : m_board->Footprints() )
1628 {
1629 if( layer == F_SilkS || layer == B_SilkS )
1630 {
1631 int linewidth = m_board->GetDesignSettings().m_LineThickness[ LAYER_CLASS_SILK ];
1632
1633 for( PAD* pad : footprint->Pads() )
1634 {
1635 if( pad->IsOnLayer( layer ) )
1636 {
1637 buildPadOutlineAsPolygon( pad, layer, *layerPoly, linewidth, pad->GetMaxError(),
1638 ERROR_INSIDE );
1639 }
1640 }
1641 }
1642 else
1643 {
1644 footprint->TransformPadsToPolySet( *layerPoly, layer, 0, footprint->GetMaxError(), ERROR_INSIDE );
1645 }
1646
1647 transformFPTextToPolySet( footprint, layer, visibilityFlags, *layerPoly, footprint->GetMaxError(),
1648 ERROR_INSIDE );
1649 transformFPShapesToPolySet( footprint, layer, *layerPoly, footprint->GetMaxError(), ERROR_INSIDE );
1650 }
1651
1652 if( aStop.stop_requested() )
1653 return;
1654
1655 if( cfg.show_zones || layer == F_Mask || layer == B_Mask )
1656 {
1657 for( ZONE* zone : m_board->Zones() )
1658 {
1659 if( zone->IsOnLayer( layer ) )
1660 zone->TransformSolidAreasShapesToPolygon( layer, *layerPoly );
1661 }
1662 }
1663
1664 if( aStop.stop_requested() )
1665 return;
1666
1667 // This will make a union of all added contours
1668 layerPoly->Simplify();
1669
1670 if( aStop.stop_requested() )
1671 return;
1672 }
1673 }
1674 // End Build Tech layers
1675
1676 if( aStop.stop_requested() )
1677 return;
1678
1679 // If we're rendering off-board silk, also render pads of footprints which are entirely
1680 // outside the board outline. This makes off-board footprints more visually recognizable.
1681 if( cfg.show_off_board_silk )
1682 {
1683 BOX2I boardBBox = m_board_poly.BBox();
1684
1685 for( FOOTPRINT* footprint : m_board->Footprints() )
1686 {
1687 if( !footprint->GetBoundingBox().Intersects( boardBBox ) )
1688 {
1689 if( footprint->IsFlipped() )
1690 addPads( footprint, m_offboardPadsBack, B_Cu );
1691 else
1692 addPads( footprint, m_offboardPadsFront, F_Cu );
1693 }
1694 }
1695
1696 m_offboardPadsFront->BuildBVH();
1697 m_offboardPadsBack->BuildBVH();
1698 }
1699
1700 if( aStop.stop_requested() )
1701 return;
1702
1703 // Simplify layer polygons
1704 if( aStatusReporter )
1705 aStatusReporter->Report( _( "Simplifying copper layer polygons" ) );
1706
1707 if( cfg.DifferentiatePlatedCopper() )
1708 {
1709 if( aStatusReporter )
1710 aStatusReporter->Report( _( "Calculating plated copper" ) );
1711
1712 // TRIM PLATED COPPER TO SOLDERMASK
1713 if( m_layers_poly.contains( F_Mask ) )
1714 m_frontPlatedCopperPolys->BooleanIntersection( *m_layers_poly.at( F_Mask ) );
1715
1716 if( m_layers_poly.contains( B_Mask ))
1717 m_backPlatedCopperPolys->BooleanIntersection( *m_layers_poly.at( B_Mask ) );
1718
1719 // Subtract plated copper from unplated copper
1720 if( m_layers_poly.contains( F_Cu ) )
1721 m_layers_poly[F_Cu]->BooleanSubtract( *m_frontPlatedCopperPolys );
1722
1723 if( m_layers_poly.contains( B_Cu ) )
1724 m_layers_poly[B_Cu]->BooleanSubtract( *m_backPlatedCopperPolys );
1725
1726 // ADD PLATED COPPER
1729
1732
1733 m_platedPadsFront->BuildBVH();
1734 m_platedPadsBack->BuildBVH();
1735
1736 if( aStop.stop_requested() )
1737 return;
1738 }
1739
1741 {
1742 std::vector<PCB_LAYER_ID> &selected_layer_id = layer_ids;
1743 std::vector<PCB_LAYER_ID> layer_id_without_F_and_B;
1744
1745 if( cfg.DifferentiatePlatedCopper() )
1746 {
1747 layer_id_without_F_and_B.clear();
1748 layer_id_without_F_and_B.reserve( layer_ids.size() );
1749
1750 for( PCB_LAYER_ID layer: layer_ids )
1751 {
1752 if( layer != F_Cu && layer != B_Cu )
1753 layer_id_without_F_and_B.push_back( layer );
1754 }
1755
1756 selected_layer_id = layer_id_without_F_and_B;
1757 }
1758
1759 if( selected_layer_id.size() > 0 )
1760 {
1761 if( aStatusReporter )
1762 {
1763 aStatusReporter->Report( wxString::Format( _( "Simplifying %d copper layers" ),
1764 (int) selected_layer_id.size() ) );
1765 }
1766
1767 std::atomic<size_t> nextItem( 0 );
1768 std::atomic<size_t> threadsFinished( 0 );
1769
1770 size_t parallelThreadCount = std::min<size_t>( std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
1771 selected_layer_id.size() );
1772
1773 for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1774 {
1775 std::thread t = std::thread(
1776 [&nextItem, &threadsFinished, &selected_layer_id, this]()
1777 {
1778 for( size_t i = nextItem.fetch_add( 1 );
1779 i < selected_layer_id.size();
1780 i = nextItem.fetch_add( 1 ) )
1781 {
1782 if( m_layers_poly.contains( selected_layer_id[i] ) )
1783 {
1784 // This will make a union of all added contours
1785 m_layers_poly[ selected_layer_id[i] ]->ClearArcs();
1786 m_layers_poly[ selected_layer_id[i] ]->Simplify();
1787 }
1788 }
1789
1790 threadsFinished++;
1791 } );
1792
1793 t.detach();
1794 }
1795
1796 while( threadsFinished < parallelThreadCount )
1797 std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
1798 }
1799
1800 if( aStop.stop_requested() )
1801 return;
1802 }
1803
1804 // Simplify holes polygon contours
1805 if( aStatusReporter )
1806 aStatusReporter->Report( _( "Simplify holes contours" ) );
1807
1808 for( PCB_LAYER_ID layer : layer_ids )
1809 {
1810 if( m_layerHoleOdPolys.contains( layer ) )
1811 {
1812 // found
1813 SHAPE_POLY_SET *polyLayer = m_layerHoleOdPolys[layer];
1814 polyLayer->Simplify();
1815
1816 wxASSERT( m_layerHoleIdPolys.contains( layer ) );
1817
1818 polyLayer = m_layerHoleIdPolys[layer];
1819 polyLayer->Simplify();
1820 }
1821
1822 if( aStop.stop_requested() )
1823 return;
1824 }
1825
1826 // Build BVH (Bounding volume hierarchy) for holes and vias
1827
1828 if( aStatusReporter )
1829 aStatusReporter->Report( _( "Build BVH for holes and vias" ) );
1830
1831 m_TH_IDs.BuildBVH();
1832 m_TH_ODs.BuildBVH();
1833 m_viaAnnuli.BuildBVH();
1834
1835 if( aStop.stop_requested() )
1836 return;
1837
1838 m_frontCounterboreCutouts.BuildBVH();
1839 m_backCounterboreCutouts.BuildBVH();
1840 m_frontCountersinkCutouts.BuildBVH();
1841 m_backCountersinkCutouts.BuildBVH();
1842 m_frontBackdrillCutouts.BuildBVH();
1843 m_backBackdrillCutouts.BuildBVH();
1844
1845 if( aStop.stop_requested() )
1846 return;
1847
1848 if( !m_layerHoleMap.empty() )
1849 {
1850 for( std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& hole : m_layerHoleMap )
1851 hole.second->BuildBVH();
1852 }
1853
1854 if( aStop.stop_requested() )
1855 return;
1856
1857 // We only need the Solder mask to initialize the BVH
1858 // because..?
1859 if( m_layerMap[B_Mask] )
1860 m_layerMap[B_Mask]->BuildBVH();
1861
1862 if( m_layerMap[F_Mask] )
1863 m_layerMap[F_Mask]->BuildBVH();
1864}
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_OUTSIDE
@ ERROR_INSIDE
@ LAYER_CLASS_SILK
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
MAP_CONTAINER_2D_BASE m_layerHoleMap
Holes for each layer.
double BiuTo3dUnits() const noexcept
Board integer units To 3D units.
BVH_CONTAINER_2D * m_offboardPadsBack
BVH_CONTAINER_2D m_frontCounterboreCutouts
Counterbore cutouts on front (top)
SHAPE_POLY_SET m_BackBackdrillPolys
Board back backdrill polygons B.Cu->in.
SHAPE_POLY_SET m_backCounterborePolys
Counterbore outer diameters on back.
SHAPE_POLY_SET m_TH_ODPolys
PTH outer diameters.
void createLayers(std::shared_ptr< REPORTER > aStatusReporter, std::stop_token aStop)
void addPads(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
unsigned int m_viaCount
BVH_CONTAINER_2D m_frontCountersinkCutouts
Countersink cutouts on front (top)
MAP_POLY m_layerHoleOdPolys
Hole outer diameters (per layer)
void addSolidAreasShapes(const ZONE *aZone, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
SHAPE_POLY_SET * m_frontPlatedCopperPolys
MAP_CONTAINER_2D_BASE m_layerMap
2D elements for each layer.
BVH_CONTAINER_2D m_TH_ODs
List of PTH outer diameters.
unsigned int m_trackCount
float m_averageTrackWidth
SHAPE_POLY_SET m_board_poly
Board outline polygon.
std::bitset< LAYER_3D_END > GetVisibleLayers() const
void addFootprintShapes(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId, const std::bitset< LAYER_3D_END > &aVisibilityFlags)
MAP_POLY m_layerHoleIdPolys
Hole inner diameters (per layer)
int GetHolePlatingThickness() const noexcept
Get the hole plating thickness (NB: in BOARD UNITS!).
SHAPE_POLY_SET m_viaAnnuliPolys
Via annular ring outer diameters.
BVH_CONTAINER_2D * m_offboardPadsFront
float m_averageViaHoleDiameter
BVH_CONTAINER_2D m_viaTH_ODs
List of via hole outer diameters.
SHAPE_POLY_SET m_frontCounterborePolys
Counterbore outer diameters on front.
BVH_CONTAINER_2D m_frontBackdrillCutouts
Backdrill cutouts to the front of the board (may come from either secondary or tertiary drills)
float m_averageHoleDiameter
SHAPE_POLY_SET m_viaTH_ODPolys
Via hole outer diameters.
void addBarCode(const PCB_BARCODE *aBarCode, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
const BOARD * GetBoard() const noexcept
BVH_CONTAINER_2D * m_platedPadsBack
void buildPadOutlineAsSegments(const PAD *aPad, PCB_LAYER_ID aLayer, CONTAINER_2D_BASE *aDstContainer, int aWidth)
MAP_POLY m_layers_poly
Amalgamated polygon contours for various types of items.
SHAPE_POLY_SET * m_backPlatedCopperPolys
EDA_3D_VIEWER_SETTINGS * m_Cfg
void addTable(const PCB_TABLE *aTable, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner)
void createPadHoleShape(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, int aInflateValue)
SHAPE_POLY_SET m_frontCountersinkPolys
Countersink outer diameters on front.
BVH_CONTAINER_2D m_backBackdrillCutouts
Backdrill cutouts to the back of the board (may come from either secondary or tertiary drills)
unsigned int m_holeCount
BVH_CONTAINER_2D m_viaAnnuli
List of via annular rings.
BVH_CONTAINER_2D m_backCountersinkCutouts
Countersink cutouts on back (bottom)
BVH_CONTAINER_2D m_backCounterboreCutouts
Counterbore cutouts on back (bottom)
BVH_CONTAINER_2D m_TH_IDs
List of PTH inner diameters.
BVH_CONTAINER_2D * m_platedPadsFront
void addShape(const PCB_SHAPE *aShape, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner, PCB_LAYER_ID aLayer)
SHAPE_POLY_SET m_NPTH_ODPolys
NPTH outer diameters.
SHAPE_POLY_SET m_backCountersinkPolys
Countersink outer diameters on back.
SHAPE_POLY_SET m_FrontBackdrillPolys
Board front backdril polygons F.Cu->in.
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer, const std::bitset< LAYER_3D_END > &aVisibilityFlags) const
Check if a layer is enabled.
double m_biuTo3Dunits
Scale factor to convert board internal units.
void createTrackWithMargin(const PCB_TRACK *aTrack, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayer, int aMargin=0, const BOARD_ITEM *aOwner=nullptr)
void addText(const EDA_TEXT *aText, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Convert the item shape to a polyset.
Definition board_item.h:582
int GetMaxError() const
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition board.h:1032
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
void Add(OBJECT_2D *aObject)
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:666
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
std::vector< SHAPE * > MakeEffectiveShapesForStroking(int aLineWidth=-1) const
Make a set of SHAPE objects to hand to STROKE_PARAMS::Stroke().
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
DRAWINGS & GraphicalItems()
Definition footprint.h:358
PCB specific render settings.
Definition pcb_painter.h:94
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
static bool Contains(int aStart_layer, int aEnd_layer, int aTest_layer)
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
Definition pad.h:61
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Definition pad.cpp:1111
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1825
Abstract dimension API.
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
Parameters and options when plotting/printing a board.
double GetDashedLineGapRatio() const
double GetDashedLineDashRatio() const
int GetWidth() const override
bool HasSolderMask() const
Definition pcb_shape.h:349
int GetSolderMaskExpansion() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
STROKE_PARAMS GetStroke() const override
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
bool IsBorderEnabled() const
Tests whether the border is disabled, as configured by the stroke.
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).
PCB_SHAPE GetPolygonalBoxShape() const
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 TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the track shape to a closed polygon.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
bool FlashLayer(int aLayer) const
Check to see whether the via should have a pad on the specific layer.
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 Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
Fills a SHAPE_POLY_SET with a polygon representation of this shape.
An abstract shape on 2D plane.
Definition shape.h:124
Simple container to manage line stroke parameters.
int GetWidth() const
LINE_STYLE GetLineStyle() const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void TransformSolidAreasShapesToPolygon(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer) const
Convert solid areas full shapes to polygon set (the full shape is the polygon area with a thick outli...
Definition zone.cpp:2133
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 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 DELETE_AND_FREE_MAP(map)
void transformFPShapesToPolySet(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer, int aMaxError, ERROR_LOC aErrorLoc)
void drawPcbShapeWithStyle(const PCB_SHAPE *aDrwShape, SHAPE_POLY_SET *aLayerPoly, int aInflate=0)
void transformFPTextToPolySet(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, const std::bitset< LAYER_3D_END > &aFlags, SHAPE_POLY_SET &aBuffer, int aMaxError, ERROR_LOC aErrorLoc)
void buildPadOutlineAsPolygon(const PAD *aPad, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer, int aWidth, int aMaxError, ERROR_LOC aErrorLoc)
#define DELETE_AND_FREE(ptr)
#define _(s)
static const wxChar * m_logTrace
Trace mask used to enable or disable debug output for this class.
bool IsSolderMaskLayer(int aLayer)
Definition layer_ids.h:815
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:591
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:590
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
Definition layer_ids.h:755
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ User_16
Definition layer_ids.h:135
@ User_29
Definition layer_ids.h:148
@ User_40
Definition layer_ids.h:159
@ User_15
Definition layer_ids.h:134
@ User_8
Definition layer_ids.h:127
@ F_CrtYd
Definition layer_ids.h:112
@ User_11
Definition layer_ids.h:130
@ User_25
Definition layer_ids.h:144
@ User_34
Definition layer_ids.h:153
@ User_45
Definition layer_ids.h:164
@ B_Adhes
Definition layer_ids.h:99
@ User_36
Definition layer_ids.h:155
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ User_6
Definition layer_ids.h:125
@ User_7
Definition layer_ids.h:126
@ User_19
Definition layer_ids.h:138
@ User_23
Definition layer_ids.h:142
@ F_Adhes
Definition layer_ids.h:98
@ User_41
Definition layer_ids.h:160
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ User_14
Definition layer_ids.h:133
@ User_39
Definition layer_ids.h:158
@ User_5
Definition layer_ids.h:124
@ User_20
Definition layer_ids.h:139
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ User_42
Definition layer_ids.h:161
@ User_43
Definition layer_ids.h:162
@ B_Paste
Definition layer_ids.h:101
@ User_10
Definition layer_ids.h:129
@ User_9
Definition layer_ids.h:128
@ User_27
Definition layer_ids.h:146
@ User_28
Definition layer_ids.h:147
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ Eco2_User
Definition layer_ids.h:106
@ User_35
Definition layer_ids.h:154
@ User_31
Definition layer_ids.h:150
@ User_3
Definition layer_ids.h:122
@ User_1
Definition layer_ids.h:120
@ User_12
Definition layer_ids.h:131
@ B_SilkS
Definition layer_ids.h:97
@ User_30
Definition layer_ids.h:149
@ User_37
Definition layer_ids.h:156
@ User_22
Definition layer_ids.h:141
@ User_38
Definition layer_ids.h:157
@ User_4
Definition layer_ids.h:123
@ User_21
Definition layer_ids.h:140
@ User_24
Definition layer_ids.h:143
@ User_13
Definition layer_ids.h:132
@ User_2
Definition layer_ids.h:121
@ User_17
Definition layer_ids.h:136
@ User_33
Definition layer_ids.h:152
@ User_26
Definition layer_ids.h:145
@ User_32
Definition layer_ids.h:151
@ User_18
Definition layer_ids.h:137
@ User_44
Definition layer_ids.h:163
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
BARCODE class definition.
VIATYPE
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
LINE_STYLE
Dashed line types.
bool DifferentiatePlatedCopper()
return true if platted copper aeras and non platted copper areas must be drawn using a different colo...
The properties of a padstack drill.
Definition padstack.h:277
const std::string table
std::string path
void ConvertPolygonToTriangles(const SHAPE_POLY_SET &aPolyList, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, const BOARD_ITEM &aBoardItem)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
glm::vec2 SFVEC2F
Definition xv3d_types.h:38