KiCad PCB EDA Suite
zone_filler.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) 2014-2017 CERN
5 * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz W┼éostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * 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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <future>
27#include <core/kicad_algo.h>
28#include <advanced_config.h>
29#include <board.h>
31#include <zone.h>
32#include <footprint.h>
33#include <pad.h>
34#include <pcb_target.h>
35#include <pcb_track.h>
36#include <pcb_text.h>
37#include <pcb_textbox.h>
38#include <fp_text.h>
39#include <fp_textbox.h>
42#include <board_commit.h>
43#include <progress_reporter.h>
47#include <confirm.h>
48#include <thread_pool.h>
49#include <math/util.h> // for KiROUND
50#include "zone_filler.h"
51
52
54 m_board( aBoard ),
55 m_brdOutlinesValid( false ),
56 m_commit( aCommit ),
57 m_progressReporter( nullptr ),
58 m_maxError( ARC_HIGH_DEF ),
59 m_worstClearance( 0 )
60{
61 // To enable add "DebugZoneFiller=1" to kicad_advanced settings file.
63}
64
65
67{
68}
69
70
72{
73 m_progressReporter = aReporter;
74 wxASSERT_MSG( m_commit, wxT( "ZONE_FILLER must have a valid commit to call "
75 "SetProgressReporter" ) );
76}
77
78
89bool ZONE_FILLER::Fill( std::vector<ZONE*>& aZones, bool aCheck, wxWindow* aParent )
90{
91 std::lock_guard<KISPINLOCK> lock( m_board->GetConnectivity()->GetLock() );
92
93 std::vector<std::pair<ZONE*, PCB_LAYER_ID>> toFill;
94 std::map<std::pair<ZONE*, PCB_LAYER_ID>, MD5_HASH> oldFillHashes;
95 std::vector<CN_ZONE_ISOLATED_ISLAND_LIST> islandsList;
96
97 std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
98
99 // Rebuild (from scratch, ignoring dirty flags) just in case. This really needs to be reliable.
100 connectivity->ClearRatsnest();
101 connectivity->Build( m_board, m_progressReporter );
102
104
106
108 {
109 m_progressReporter->Report( aCheck ? _( "Checking zone fills..." )
110 : _( "Building zone fills..." ) );
111 m_progressReporter->SetMaxProgress( aZones.size() );
113 }
114
115 // The board outlines is used to clip solid areas inside the board (when outlines are valid)
118
119 // Update and cache zone bounding boxes and pad effective shapes so that we don't have to
120 // make them thread-safe.
121 //
122 for( ZONE* zone : m_board->Zones() )
123 {
124 zone->CacheBoundingBox();
125 m_worstClearance = std::max( m_worstClearance, zone->GetLocalClearance() );
126 }
127
128 for( FOOTPRINT* footprint : m_board->Footprints() )
129 {
130 for( PAD* pad : footprint->Pads() )
131 {
132 if( pad->IsDirty() )
133 {
134 pad->BuildEffectiveShapes( UNDEFINED_LAYER );
135 pad->BuildEffectivePolygon();
136 }
137
138 pad->ClearZoneConnectionCache();
139
140 m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
141 }
142
143 for( ZONE* zone : footprint->Zones() )
144 {
145 zone->CacheBoundingBox();
146 m_worstClearance = std::max( m_worstClearance, zone->GetLocalClearance() );
147 }
148
149 // Rules may depend on insideCourtyard() or other expressions
150 footprint->BuildCourtyardCaches();
151 }
152
153 for( PCB_TRACK* track : m_board->Tracks() )
154 {
155 if( track->Type() == PCB_VIA_T )
156 static_cast<PCB_VIA*>( track )->ClearZoneConnectionCache();
157 }
158
159 // Sort by priority to reduce deferrals waiting on higher priority zones.
160 //
161 std::sort( aZones.begin(), aZones.end(),
162 []( const ZONE* lhs, const ZONE* rhs )
163 {
164 return lhs->HigherPriority( rhs );
165 } );
166
167 for( ZONE* zone : aZones )
168 {
169 // Rule areas are not filled
170 if( zone->GetIsRuleArea() )
171 continue;
172
173 // Degenerate zones will cause trouble; skip them
174 if( zone->GetNumCorners() <= 2 )
175 continue;
176
177 if( m_commit )
178 m_commit->Modify( zone );
179
180 // calculate the hash value for filled areas. it will be used later to know if the
181 // current filled areas are up to date
182 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
183 {
184 zone->BuildHashValue( layer );
185 oldFillHashes[ { zone, layer } ] = zone->GetHashValue( layer );
186
187 // Add the zone to the list of zones to test or refill
188 toFill.emplace_back( std::make_pair( zone, layer ) );
189 }
190
191 islandsList.emplace_back( CN_ZONE_ISOLATED_ISLAND_LIST( zone ) );
192
193 // Remove existing fill first to prevent drawing invalid polygons on some platforms
194 zone->UnFill();
195 }
196
197 auto check_fill_dependency =
198 [&]( ZONE* aZone, PCB_LAYER_ID aLayer, ZONE* aOtherZone ) -> bool
199 {
200 // Check to see if we have to knock-out the filled areas of a higher-priority
201 // zone. If so we have to wait until said zone is filled before we can fill.
202
203 // If the other zone is already filled then we're good-to-go
204 if( aOtherZone->GetFillFlag( aLayer ) )
205 return false;
206
207 // Even if keepouts exclude copper pours the exclusion is by outline, not by
208 // filled area, so we're good-to-go here too.
209 if( aOtherZone->GetIsRuleArea() )
210 return false;
211
212 // If the zones share no common layers
213 if( !aOtherZone->GetLayerSet().test( aLayer ) )
214 return false;
215
216 if( aZone->HigherPriority( aOtherZone ) )
217 return false;
218
219 // Same-net zones always use outline to produce predictable results
220 if( aOtherZone->SameNet( aZone ) )
221 return false;
222
223 // A higher priority zone is found: if we intersect and it's not filled yet
224 // then we have to wait.
225 BOX2I inflatedBBox = aZone->GetBoundingBox();
226 inflatedBBox.Inflate( m_worstClearance );
227
228 if( !inflatedBBox.Intersects( aOtherZone->GetBoundingBox() ) )
229 return false;
230
231 return aZone->Outline()->Collide( aOtherZone->Outline(), m_worstClearance );
232 };
233
234 auto fill_lambda =
235 [&]( std::pair<ZONE*, PCB_LAYER_ID> aFillItem ) -> int
236 {
237 PCB_LAYER_ID layer = aFillItem.second;
238 ZONE* zone = aFillItem.first;
239 bool canFill = true;
240
241 // Check for any fill dependencies. If our zone needs to be clipped by
242 // another zone then we can't fill until that zone is filled.
243 for( ZONE* otherZone : aZones )
244 {
245 if( otherZone == zone )
246 continue;
247
248 if( check_fill_dependency( zone, layer, otherZone ) )
249 {
250 canFill = false;
251 break;
252 }
253 }
254
256 return 0;
257
258 if( !canFill )
259 return 0;
260
261
262 // Now we're ready to fill.
263 std::unique_lock<std::mutex> zoneLock( zone->GetLock(), std::try_to_lock );
264
265 if( !zoneLock.owns_lock() )
266 return 0;
267
268
269 SHAPE_POLY_SET fillPolys;
270
271 if( !fillSingleZone( zone, layer, fillPolys ) )
272 return 0;
273
274 zone->SetFilledPolysList( layer, fillPolys );
275
278
279 return 1;
280 };
281
282 auto cache_optionally_flashed_connections =
283 [&]( ZONE* zone, PCB_LAYER_ID layer )
284 {
285 BOX2I zone_boundingbox = zone->GetBoundingBox();
286
287 // Check all conditionally-flashed vias and pads which aren't owned yet to see if
288 // we own them. If so, set their connection caches. See FlashLayer() for
289 // additional background.
290
291 for( PCB_TRACK* track : m_board->Tracks() )
292 {
293 if( track->Type() == PCB_VIA_T )
294 {
295 PCB_VIA* via = static_cast<PCB_VIA*>( track );
296
297 if( !via->IsOnLayer( layer ) || !via->ConditionallyFlashed( layer ) )
298 continue;
299
300 if( via->ZoneConnectionCache( layer ) == ZLC_UNRESOLVED
301 && via->GetBoundingBox().Intersects( zone_boundingbox ) )
302 {
303 auto viaShape = via->GetEffectiveShape( layer, FLASHING::ALWAYS_FLASHED );
304 auto flashedShape = via->GetEffectiveShape( layer, FLASHING::DEFAULT );
305
306 // If the via collides with the zone's outline then we "own" the via.
307 // If it collides with the fill then it's connected; otherwise not.
308
309 if( zone->Outline()->Collide( viaShape.get() ) )
310 {
311 if( zone->GetFill( layer )->Collide( flashedShape.get() ) )
312 via->ZoneConnectionCache( layer ) = ZLC_CONNECTED;
313 else
314 via->ZoneConnectionCache( layer ) = ZLC_UNCONNECTED;
315 }
316 }
317 }
318 }
319
320 for( FOOTPRINT* footprint : m_board->Footprints() )
321 {
322 for( PAD* pad : footprint->Pads() )
323 {
324 if( !pad->IsOnLayer( layer ) || !pad->GetRemoveUnconnected() )
325 continue;
326
327 if( pad->ZoneConnectionCache( layer ) == ZLC_UNRESOLVED
328 && pad->GetBoundingBox().Intersects( zone_boundingbox ) )
329 {
330 auto padShape = pad->GetEffectiveShape( layer, FLASHING::ALWAYS_FLASHED );
331 auto flashedShape = pad->GetEffectiveShape( layer, FLASHING::DEFAULT );
332
333 // If the pad collides with the zone's outline then we "own" the pad.
334 // If it collides with the fill then it's connected; otherwise not.
335
336 if( zone->Outline()->Collide( padShape.get() ) )
337 {
338 if( zone->GetFill( layer )->Collide( flashedShape.get() ) )
339 pad->ZoneConnectionCache( layer ) = ZLC_CONNECTED;
340 else
341 pad->ZoneConnectionCache( layer ) = ZLC_UNCONNECTED;
342 }
343 }
344 }
345 }
346 };
347
348 auto tesselate_lambda =
349 [&]( std::pair<ZONE*, PCB_LAYER_ID> aFillItem ) -> int
350 {
351
353 return 0;
354
355 PCB_LAYER_ID layer = aFillItem.second;
356 ZONE* zone = aFillItem.first;
357
358 zone->CacheTriangulation( layer );
359
360 if( zone->IsOnCopperLayer() )
361 cache_optionally_flashed_connections( zone, layer );
362
363 zone->SetFillFlag( layer, true );
364 return 1;
365 };
366
367 // Calculate the copper fills (NB: this is multi-threaded)
368 //
369 std::vector<std::pair<std::future<int>, int>> returns;
370 returns.reserve( toFill.size() );
371 size_t finished = 0;
372 bool cancelled = false;
373
375
376 for( const std::pair<ZONE*, PCB_LAYER_ID>& fillItem : toFill )
377 returns.emplace_back( std::make_pair( tp.submit( fill_lambda, fillItem ), 0 ) );
378
379 while( !cancelled && finished != 2 * toFill.size() )
380 {
381 for( size_t ii = 0; ii < returns.size(); ++ii )
382 {
383 auto& ret = returns[ii];
384
385 if( ret.second > 1 )
386 continue;
387
388 std::future_status status = ret.first.wait_for( std::chrono::seconds( 0 ) );
389
390 if( status == std::future_status::ready )
391 {
392 if( ret.first.get() )
393 {
394 ++finished;
395
396 if( !cancelled && ret.second == 0 )
397 returns[ii].first = tp.submit( tesselate_lambda, toFill[ii] );
398
399 ret.second++;
400 }
401 else if( !cancelled )
402 {
403 returns[ii].first = tp.submit( fill_lambda, toFill[ii] );
404 }
405 }
406 }
407
408 std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
409
410
412 {
414
416 cancelled = true;
417 }
418 }
419
420 // Now update the connectivity to check for isolated copper islands
421 // (NB: FindIsolatedCopperIslands() is multi-threaded)
422 //
424 {
426 return false;
427
429 m_progressReporter->Report( _( "Removing isolated copper islands..." ) );
431 }
432
433 connectivity->SetProgressReporter( m_progressReporter );
434 connectivity->FindIsolatedCopperIslands( islandsList );
435 connectivity->SetProgressReporter( nullptr );
436
438 return false;
439
440 for( ZONE* zone : aZones )
441 {
442 // Keepout zones are not filled
443 if( zone->GetIsRuleArea() )
444 continue;
445
446 zone->SetIsFilled( true );
447 }
448
449 // Now remove isolated copper islands according to the isolated islands strategy assigned
450 // by the user (always, never, below-certain-size).
451 //
452 for( CN_ZONE_ISOLATED_ISLAND_LIST& zone : islandsList )
453 {
454 for( PCB_LAYER_ID layer : zone.m_zone->GetLayerSet().Seq() )
455 {
456 if( m_debugZoneFiller && LSET::InternalCuMask().Contains( layer ) )
457 continue;
458
459 if( !zone.m_islands.count( layer ) )
460 continue;
461
462 std::vector<int>& islands = zone.m_islands.at( layer );
463
464 // The list of polygons to delete must be explored from last to first in list,
465 // to allow deleting a polygon from list without breaking the remaining of the list
466 std::sort( islands.begin(), islands.end(), std::greater<int>() );
467
468 std::shared_ptr<SHAPE_POLY_SET> poly = zone.m_zone->GetFilledPolysList( layer );
469 long long int minArea = zone.m_zone->GetMinIslandArea();
470 ISLAND_REMOVAL_MODE mode = zone.m_zone->GetIslandRemovalMode();
471
472 for( int idx : islands )
473 {
474 SHAPE_LINE_CHAIN& outline = poly->Outline( idx );
475
476 if( mode == ISLAND_REMOVAL_MODE::ALWAYS )
477 poly->DeletePolygonAndTriangulationData( idx, false );
478 else if ( mode == ISLAND_REMOVAL_MODE::AREA && outline.Area() < minArea )
479 poly->DeletePolygonAndTriangulationData( idx, false );
480 else
481 zone.m_zone->SetIsIsland( layer, idx );
482 }
483
484 poly->UpdateTriangulationDataHash();
485 zone.m_zone->CalculateFilledArea();
486
488 return false;
489 }
490 }
491
492 // Now remove islands which are either outside the board edge or fail to meet the minimum
493 // area requirements
494 //
495 for( ZONE* zone : aZones )
496 {
497 LSET zoneCopperLayers = zone->GetLayerSet() & LSET::AllCuMask( MAX_CU_LAYERS );
498
499 // Min-thickness is the web thickness. On the other hand, a blob min-thickness by
500 // min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
501 // arbitrarily choose "at least 2X the area".
502 double minArea = (double) zone->GetMinThickness() * zone->GetMinThickness() * 2;
503
504 for( PCB_LAYER_ID layer : zoneCopperLayers.Seq() )
505 {
507 continue;
508
509 std::shared_ptr<SHAPE_POLY_SET> poly = zone->GetFilledPolysList( layer );
510
511 for( int ii = poly->OutlineCount() - 1; ii >= 0; ii-- )
512 {
513 std::vector<SHAPE_LINE_CHAIN>& island = poly->Polygon( ii );
514
515 if( island.empty()
516 || !m_boardOutline.Contains( island.front().CPoint( 0 ) )
517 || island.front().Area() < minArea )
518 {
519 poly->DeletePolygonAndTriangulationData( ii, false );
520 }
521 }
522
523 poly->UpdateTriangulationDataHash();
524 zone->CalculateFilledArea();
525
527 return false;
528 }
529 }
530
531 if( aCheck )
532 {
533 bool outOfDate = false;
534
535 for( ZONE* zone : aZones )
536 {
537 // Keepout zones are not filled
538 if( zone->GetIsRuleArea() )
539 continue;
540
541 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
542 {
543 zone->BuildHashValue( layer );
544
545 if( oldFillHashes[ { zone, layer } ] != zone->GetHashValue( layer ) )
546 outOfDate = true;
547 }
548 }
549
550 if( outOfDate )
551 {
552 KIDIALOG dlg( aParent, _( "Zone fills are out-of-date. Refill?" ),
553 _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
554 dlg.SetOKCancelLabels( _( "Refill" ), _( "Continue without Refill" ) );
555 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
556
557 if( dlg.ShowModal() == wxID_CANCEL )
558 return false;
559 }
560 else
561 {
562 // No need to commit something that hasn't changed (and committing will set
563 // the modified flag).
564 return false;
565 }
566 }
567
569 {
571 return false;
572
575 }
576
577 return true;
578}
579
580
585void ZONE_FILLER::addKnockout( PAD* aPad, PCB_LAYER_ID aLayer, int aGap, SHAPE_POLY_SET& aHoles )
586{
587 if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
588 {
589 SHAPE_POLY_SET poly;
590 aPad->TransformShapeToPolygon( poly, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
591
592 // the pad shape in zone can be its convex hull or the shape itself
594 {
595 std::vector<VECTOR2I> convex_hull;
596 BuildConvexHull( convex_hull, poly );
597
598 aHoles.NewOutline();
599
600 for( const VECTOR2I& pt : convex_hull )
601 aHoles.Append( pt );
602 }
603 else
604 aHoles.Append( poly );
605 }
606 else
607 {
608 aPad->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
609 }
610}
611
612
616void ZONE_FILLER::addHoleKnockout( PAD* aPad, int aGap, SHAPE_POLY_SET& aHoles )
617{
618 aPad->TransformHoleToPolygon( aHoles, aGap, m_maxError, ERROR_OUTSIDE );
619}
620
621
626void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap,
627 bool aIgnoreLineWidth, SHAPE_POLY_SET& aHoles )
628{
629 EDA_TEXT* text = nullptr;
630
631 switch( aItem->Type() )
632 {
633 case PCB_TEXT_T: text = static_cast<PCB_TEXT*>( aItem ); break;
634 case PCB_TEXTBOX_T: text = static_cast<PCB_TEXTBOX*>( aItem ); break;
635 case PCB_FP_TEXT_T: text = static_cast<FP_TEXT*>( aItem ); break;
636 case PCB_FP_TEXTBOX_T: text = static_cast<FP_TEXTBOX*>( aItem ); break;
637 default: break;
638 }
639
640 if( text )
641 aGap += GetKnockoutTextMargin( text->GetTextSize(), text->GetTextThickness() );
642
643 switch( aItem->Type() )
644 {
645 case PCB_SHAPE_T:
646 case PCB_TEXT_T:
647 case PCB_TEXTBOX_T:
648 case PCB_FP_TEXTBOX_T:
649 case PCB_FP_SHAPE_T:
650 case PCB_TARGET_T:
651 aItem->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE,
652 aIgnoreLineWidth );
653 break;
654
655 case PCB_FP_TEXT_T:
656 if( text->IsVisible() )
657 {
658 aItem->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE,
659 aIgnoreLineWidth );
660 }
661
662 break;
663
664 default:
665 break;
666 }
667}
668
669
675 SHAPE_POLY_SET& aFill,
676 std::vector<PAD*>& aThermalConnectionPads,
677 std::vector<PAD*>& aNoConnectionPads )
678{
680 ZONE_CONNECTION connection;
681 DRC_CONSTRAINT constraint;
682 int padClearance;
683 int holeClearance;
684 SHAPE_POLY_SET holes;
685
686 for( FOOTPRINT* footprint : m_board->Footprints() )
687 {
688 for( PAD* pad : footprint->Pads() )
689 {
690 BOX2I padBBox = pad->GetBoundingBox();
691 padBBox.Inflate( m_worstClearance );
692
693 if( !padBBox.Intersects( aZone->GetBoundingBox() ) )
694 continue;
695
696 if( pad->GetNetCode() != aZone->GetNetCode() || pad->GetNetCode() <= 0 )
697 {
698 // collect these for knockout in buildCopperItemClearances()
699 aNoConnectionPads.push_back( pad );
700 continue;
701 }
702
703 if( aZone->IsTeardropArea() )
704 {
705 connection = ZONE_CONNECTION::FULL;
706 }
707 else
708 {
709 constraint = bds.m_DRCEngine->EvalZoneConnection( pad, aZone, aLayer );
710 connection = constraint.m_ZoneConnection;
711 }
712
713 switch( connection )
714 {
716 constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone,
717 aLayer );
718 padClearance = constraint.GetValue().Min();
719 holeClearance = padClearance;
720
721 if( pad->FlashLayer( aLayer ) )
722 aThermalConnectionPads.push_back( pad );
723
724 break;
725
727 constraint = bds.m_DRCEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, pad,
728 aZone, aLayer );
729
730 if( constraint.GetValue().Min() > aZone->GetLocalClearance() )
731 padClearance = constraint.GetValue().Min();
732 else
733 padClearance = aZone->GetLocalClearance();
734
735 constraint = bds.m_DRCEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT, pad,
736 aZone, aLayer );
737
738 if( constraint.GetValue().Min() > padClearance )
739 holeClearance = constraint.GetValue().Min();
740 else
741 holeClearance = padClearance;
742
743 break;
744
745 default:
746 // No knockout
747 continue;
748 }
749
750 if( pad->FlashLayer( aLayer ) )
751 addKnockout( pad, aLayer, padClearance, holes );
752 else if( pad->GetDrillSize().x > 0 )
753 pad->TransformHoleToPolygon( holes, holeClearance, m_maxError, ERROR_OUTSIDE );
754 }
755 }
756
758}
759
760
766 const std::vector<PAD*> aNoConnectionPads,
767 SHAPE_POLY_SET& aHoles )
768{
770 long ticker = 0;
771
772 auto checkForCancel =
773 [&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
774 {
775 return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
776 };
777
778 // A small extra clearance to be sure actual track clearances are not smaller than
779 // requested clearance due to many approximations in calculations, like arc to segment
780 // approx, rounding issues, etc.
781 BOX2I zone_boundingbox = aZone->GetBoundingBox();
783
784 // Items outside the zone bounding box are skipped, so it needs to be inflated by the
785 // largest clearance value found in the netclasses and rules
786 zone_boundingbox.Inflate( m_worstClearance + extra_margin );
787
788 auto evalRulesForItems =
789 [&bds]( DRC_CONSTRAINT_T aConstraint, const BOARD_ITEM* a, const BOARD_ITEM* b,
790 PCB_LAYER_ID aEvalLayer ) -> int
791 {
792 DRC_CONSTRAINT c = bds.m_DRCEngine->EvalRules( aConstraint, a, b, aEvalLayer );
793 return c.GetValue().Min();
794 };
795
796 // Add non-connected pad clearances
797 //
798 auto knockoutPadClearance =
799 [&]( PAD* aPad )
800 {
801 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone, aPad, aLayer );
802 bool hasHole = aPad->GetDrillSize().x > 0;
803 bool flashLayer = aPad->FlashLayer( aLayer );
804 bool platedHole = hasHole && aPad->GetAttribute() == PAD_ATTRIB::PTH;
805
806 if( flashLayer || platedHole )
807 {
808 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
809 aZone, aPad, aLayer ) );
810 }
811
812 if( flashLayer && gap > 0 )
813 addKnockout( aPad, aLayer, gap + extra_margin, aHoles );
814
815 if( hasHole )
816 {
817 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
818 aZone, aPad, aLayer ) );
819
820 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
821 aZone, aPad, aLayer ) );
822
823 if( gap > 0 )
824 addHoleKnockout( aPad, gap + extra_margin, aHoles );
825 }
826 };
827
828 for( PAD* pad : aNoConnectionPads )
829 {
830 if( checkForCancel( m_progressReporter ) )
831 return;
832
833 knockoutPadClearance( pad );
834 }
835
836 // Add non-connected track clearances
837 //
838 auto knockoutTrackClearance =
839 [&]( PCB_TRACK* aTrack )
840 {
841 if( aTrack->GetBoundingBox().Intersects( zone_boundingbox ) )
842 {
843 bool sameNet = aTrack->GetNetCode() == aZone->GetNetCode()
844 && aZone->GetNetCode() != 0;
845
846 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
847 aZone, aTrack, aLayer );
848
849 if( aTrack->Type() == PCB_VIA_T )
850 {
851 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
852
853 if( via->ZoneConnectionCache( aLayer ) == ZLC_UNCONNECTED )
854 sameNet = false;
855 }
856
857 if( !sameNet )
858 {
859 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
860 aZone, aTrack, aLayer ) );
861 }
862
863 if( aTrack->Type() == PCB_VIA_T )
864 {
865 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
866
867 if( via->FlashLayer( aLayer ) && gap > 0 )
868 {
869 via->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
871 }
872
873 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
874 aZone, via, aLayer ) );
875
876 if( !sameNet )
877 {
878 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
879 aZone, via, aLayer ) );
880 }
881
882 if( gap > 0 )
883 {
884 int radius = via->GetDrillValue() / 2;
885
886 TransformCircleToPolygon( aHoles, via->GetPosition(),
887 radius + gap + extra_margin,
889 }
890 }
891 else
892 {
893 if( gap > 0 )
894 {
895 aTrack->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
897 }
898 }
899 }
900 };
901
902 for( PCB_TRACK* track : m_board->Tracks() )
903 {
904 if( !track->IsOnLayer( aLayer ) )
905 continue;
906
907 if( checkForCancel( m_progressReporter ) )
908 return;
909
910 knockoutTrackClearance( track );
911 }
912
913 // Add graphic item clearances. They are by definition unconnected, and have no clearance
914 // definitions of their own.
915 //
916 auto knockoutGraphicClearance =
917 [&]( BOARD_ITEM* aItem )
918 {
919 // A item on the Edge_Cuts or Margin is always seen as on any layer:
920 if( aItem->IsOnLayer( aLayer )
921 || aItem->IsOnLayer( Edge_Cuts )
922 || aItem->IsOnLayer( Margin ) )
923 {
924 if( aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
925 {
926 bool ignoreLineWidths = false;
927 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
928 aZone, aItem, aLayer );
929
930 if( aItem->IsOnLayer( aLayer ) )
931 {
932 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
933 aZone, aItem, aLayer ) );
934 }
935 else if( aItem->IsOnLayer( Edge_Cuts ) )
936 {
937 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
938 aZone, aItem, Edge_Cuts ) );
939 ignoreLineWidths = true;
940 }
941 else if( aItem->IsOnLayer( Margin ) )
942 {
943 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
944 aZone, aItem, Margin ) );
945 }
946
947 addKnockout( aItem, aLayer, gap + extra_margin, ignoreLineWidths, aHoles );
948 }
949 }
950 };
951
952 for( FOOTPRINT* footprint : m_board->Footprints() )
953 {
954 knockoutGraphicClearance( &footprint->Reference() );
955 knockoutGraphicClearance( &footprint->Value() );
956
957 std::set<PAD*> allowedNetTiePads;
958
959 // Don't knock out holes for graphic items which implement a net-tie to the zone's net
960 // on the layer being filled.
961 if( footprint->IsNetTie() )
962 {
963 for( PAD* pad : footprint->Pads() )
964 {
965 if( pad->GetNetCode() == aZone->GetNetCode() )
966 {
967 if( pad->IsOnLayer( aLayer ) )
968 allowedNetTiePads.insert( pad );
969
970 for( PAD* other : footprint->GetNetTiePads( pad ) )
971 {
972 if( other->IsOnLayer( aLayer ) )
973 allowedNetTiePads.insert( other );
974 }
975 }
976 }
977 }
978
979 for( BOARD_ITEM* item : footprint->GraphicalItems() )
980 {
981 if( checkForCancel( m_progressReporter ) )
982 return;
983
984 BOX2I itemBBox = item->GetBoundingBox();
985
986 if( !zone_boundingbox.Intersects( itemBBox ) )
987 continue;
988
989 bool skipItem = false;
990
991 if( item->IsOnLayer( aLayer ) )
992 {
993 std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape();
994
995 for( PAD* pad : allowedNetTiePads )
996 {
997 if( pad->GetBoundingBox().Intersects( itemBBox )
998 && pad->GetEffectiveShape()->Collide( itemShape.get() ) )
999 {
1000 skipItem = true;
1001 break;
1002 }
1003 }
1004 }
1005
1006 if( !skipItem )
1007 knockoutGraphicClearance( item );
1008 }
1009 }
1010
1011 for( BOARD_ITEM* item : m_board->Drawings() )
1012 {
1013 if( checkForCancel( m_progressReporter ) )
1014 return;
1015
1016 knockoutGraphicClearance( item );
1017 }
1018
1019 // Add non-connected zone clearances
1020 //
1021 auto knockoutZoneClearance =
1022 [&]( ZONE* aKnockout )
1023 {
1024 // If the zones share no common layers
1025 if( !aKnockout->GetLayerSet().test( aLayer ) )
1026 return;
1027
1028 if( aKnockout->GetBoundingBox().Intersects( zone_boundingbox ) )
1029 {
1030 if( aKnockout->GetIsRuleArea() )
1031 {
1032 // Keepouts use outline with no clearance
1033 aKnockout->TransformSmoothedOutlineToPolygon( aHoles, 0, m_maxError,
1034 ERROR_OUTSIDE, nullptr );
1035 }
1036 else
1037 {
1038 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone,
1039 aKnockout, aLayer );
1040
1041 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT, aZone,
1042 aKnockout, aLayer ) );
1043
1044 SHAPE_POLY_SET poly;
1045 aKnockout->TransformShapeToPolygon( poly, aLayer, gap + extra_margin,
1047 aHoles.Append( poly );
1048 }
1049 }
1050 };
1051
1052 for( ZONE* otherZone : m_board->Zones() )
1053 {
1054 if( checkForCancel( m_progressReporter ) )
1055 return;
1056
1057 if( otherZone->GetIsRuleArea() )
1058 {
1059 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1060 knockoutZoneClearance( otherZone );
1061 }
1062 else if( otherZone->HigherPriority( aZone ) )
1063 {
1064 if( !otherZone->SameNet( aZone ) )
1065 knockoutZoneClearance( otherZone );
1066 }
1067 }
1068
1069 for( FOOTPRINT* footprint : m_board->Footprints() )
1070 {
1071 for( ZONE* otherZone : footprint->Zones() )
1072 {
1073 if( checkForCancel( m_progressReporter ) )
1074 return;
1075
1076 if( otherZone->GetIsRuleArea() )
1077 {
1078 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1079 knockoutZoneClearance( otherZone );
1080 }
1081 else if( otherZone->HigherPriority( aZone ) )
1082 {
1083 if( !otherZone->SameNet( aZone ) )
1084 knockoutZoneClearance( otherZone );
1085 }
1086 }
1087 }
1088
1090}
1091
1092
1098 SHAPE_POLY_SET& aRawFill )
1099{
1100 BOX2I zoneBBox = aZone->GetBoundingBox();
1101
1102 auto knockoutZoneOutline =
1103 [&]( ZONE* aKnockout )
1104 {
1105 // If the zones share no common layers
1106 if( !aKnockout->GetLayerSet().test( aLayer ) )
1107 return;
1108
1109 if( aKnockout->GetBoundingBox().Intersects( zoneBBox ) )
1110 {
1111 // Processing of arc shapes in zones is not yet supported because Clipper
1112 // can't do boolean operations on them. The poly outline must be converted to
1113 // segments first.
1114 SHAPE_POLY_SET outline = aKnockout->Outline()->CloneDropTriangulation();
1115 outline.ClearArcs();
1116
1117 aRawFill.BooleanSubtract( outline, SHAPE_POLY_SET::PM_FAST );
1118 }
1119 };
1120
1121 for( ZONE* otherZone : m_board->Zones() )
1122 {
1123 if( otherZone->SameNet( aZone ) && otherZone->HigherPriority( aZone ) )
1124 {
1125 // Do not remove teardrop area: it is not useful and not good
1126 if( !otherZone->IsTeardropArea() )
1127 knockoutZoneOutline( otherZone );
1128 }
1129 }
1130
1131 for( FOOTPRINT* footprint : m_board->Footprints() )
1132 {
1133 for( ZONE* otherZone : footprint->Zones() )
1134 {
1135 if( otherZone->SameNet( aZone ) && otherZone->HigherPriority( aZone ) )
1136 {
1137 // Do not remove teardrop area: it is not useful and not good
1138 if( !otherZone->IsTeardropArea() )
1139 knockoutZoneOutline( otherZone );
1140 }
1141 }
1142 }
1143}
1144
1145
1146#define DUMP_POLYS_TO_COPPER_LAYER( a, b, c ) \
1147 { if( m_debugZoneFiller && aDebugLayer == b ) \
1148 { \
1149 m_board->SetLayerName( b, c ); \
1150 SHAPE_POLY_SET d = a; \
1151 d.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); \
1152 aFillPolys = d; \
1153 return false; \
1154 } \
1155 }
1156
1157
1169bool ZONE_FILLER::fillCopperZone( const ZONE* aZone, PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer,
1170 const SHAPE_POLY_SET& aSmoothedOutline,
1171 const SHAPE_POLY_SET& aMaxExtents, SHAPE_POLY_SET& aFillPolys )
1172{
1174
1175 // Features which are min_width should survive pruning; features that are *less* than
1176 // min_width should not. Therefore we subtract epsilon from the min_width when
1177 // deflating/inflating.
1178 int half_min_width = aZone->GetMinThickness() / 2;
1179 int epsilon = pcbIUScale.mmToIU( 0.001 );
1180 int numSegs = GetArcToSegmentCount( half_min_width, m_maxError, FULL_CIRCLE );
1181
1182 // Solid polygons are deflated and inflated during calculations. Deflating doesn't cause
1183 // issues, but inflate is tricky as it can create excessively long and narrow spikes for
1184 // acute angles.
1185 // ALLOW_ACUTE_CORNERS cannot be used due to the spike problem.
1186 // CHAMFER_ACUTE_CORNERS is tempting, but can still produce spikes in some unusual
1187 // circumstances (https://gitlab.com/kicad/code/kicad/-/issues/5581).
1188 // It's unclear if ROUND_ACUTE_CORNERS would have the same issues, but is currently avoided
1189 // as a "less-safe" option.
1190 // ROUND_ALL_CORNERS produces the uniformly nicest shapes, but also a lot of segments.
1191 // CHAMFER_ALL_CORNERS improves the segment count.
1194
1195 std::vector<PAD*> thermalConnectionPads;
1196 std::vector<PAD*> noConnectionPads;
1197 std::deque<SHAPE_LINE_CHAIN> thermalSpokes;
1198 SHAPE_POLY_SET clearanceHoles;
1199
1200 aFillPolys = aSmoothedOutline;
1201 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In1_Cu, wxT( "smoothed-outline" ) );
1202
1204 return false;
1205
1206 /* -------------------------------------------------------------------------------------
1207 * Knockout thermal reliefs.
1208 */
1209
1210 knockoutThermalReliefs( aZone, aLayer, aFillPolys, thermalConnectionPads, noConnectionPads );
1211 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In2_Cu, wxT( "minus-thermal-reliefs" ) );
1212
1214 return false;
1215
1216 /* -------------------------------------------------------------------------------------
1217 * Knockout electrical clearances.
1218 */
1219
1220 buildCopperItemClearances( aZone, aLayer, noConnectionPads, clearanceHoles );
1221 DUMP_POLYS_TO_COPPER_LAYER( clearanceHoles, In3_Cu, wxT( "clearance-holes" ) );
1222
1224 return false;
1225
1226 /* -------------------------------------------------------------------------------------
1227 * Add thermal relief spokes.
1228 */
1229
1230 buildThermalSpokes( aZone, aLayer, thermalConnectionPads, thermalSpokes );
1231
1233 return false;
1234
1235 // Create a temporary zone that we can hit-test spoke-ends against. It's only temporary
1236 // because the "real" subtract-clearance-holes has to be done after the spokes are added.
1237 static const bool USE_BBOX_CACHES = true;
1238 SHAPE_POLY_SET testAreas = aFillPolys.CloneDropTriangulation();
1239 testAreas.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1240 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In4_Cu, wxT( "minus-clearance-holes" ) );
1241
1242 // Prune features that don't meet minimum-width criteria
1243 if( half_min_width - epsilon > epsilon )
1244 {
1245 testAreas.Deflate( half_min_width - epsilon, numSegs, fastCornerStrategy );
1246 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In5_Cu, wxT( "spoke-test-deflated" ) );
1247
1248 testAreas.Inflate( half_min_width - epsilon, numSegs, fastCornerStrategy );
1249 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In6_Cu, wxT( "spoke-test-reinflated" ) );
1250 }
1251
1253 return false;
1254
1255 // Spoke-end-testing is hugely expensive so we generate cached bounding-boxes to speed
1256 // things up a bit.
1257 testAreas.BuildBBoxCaches();
1258 int interval = 0;
1259
1260 SHAPE_POLY_SET debugSpokes;
1261
1262 for( const SHAPE_LINE_CHAIN& spoke : thermalSpokes )
1263 {
1264 const VECTOR2I& testPt = spoke.CPoint( 3 );
1265
1266 // Hit-test against zone body
1267 if( testAreas.Contains( testPt, -1, 1, USE_BBOX_CACHES ) )
1268 {
1269 if( m_debugZoneFiller )
1270 debugSpokes.AddOutline( spoke );
1271
1272 aFillPolys.AddOutline( spoke );
1273 continue;
1274 }
1275
1276 if( interval++ > 400 )
1277 {
1279 return false;
1280
1281 interval = 0;
1282 }
1283
1284 // Hit-test against other spokes
1285 for( const SHAPE_LINE_CHAIN& other : thermalSpokes )
1286 {
1287 if( &other != &spoke && other.PointInside( testPt, 1, USE_BBOX_CACHES ) )
1288 {
1289 if( m_debugZoneFiller )
1290 debugSpokes.AddOutline( spoke );
1291
1292 aFillPolys.AddOutline( spoke );
1293 break;
1294 }
1295 }
1296 }
1297
1298 DUMP_POLYS_TO_COPPER_LAYER( debugSpokes, In7_Cu, wxT( "spokes" ) );
1299
1301 return false;
1302
1303 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1304 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In8_Cu, wxT( "after-spoke-trimming" ) );
1305
1306 /* -------------------------------------------------------------------------------------
1307 * Prune features that don't meet minimum-width criteria
1308 */
1309
1310 if( half_min_width - epsilon > epsilon )
1311 aFillPolys.Deflate( half_min_width - epsilon, numSegs, cornerStrategy );
1312
1313 // Min-thickness is the web thickness. On the other hand, a blob min-thickness by
1314 // min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
1315 // arbitrarily choose "at least 1/2 min-thickness on one axis".
1316 for( int ii = aFillPolys.OutlineCount() - 1; ii >= 0; ii-- )
1317 {
1318 std::vector<SHAPE_LINE_CHAIN>& island = aFillPolys.Polygon( ii );
1319 BOX2I islandExtents = island.front().BBox();
1320
1321 if( islandExtents.GetSizeMax() < half_min_width )
1322 aFillPolys.DeletePolygon( ii );
1323 }
1324
1325 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In9_Cu, wxT( "deflated" ) );
1326
1328 return false;
1329
1330 /* -------------------------------------------------------------------------------------
1331 * Process the hatch pattern (note that we do this while deflated)
1332 */
1333
1335 {
1336 if( !addHatchFillTypeOnZone( aZone, aLayer, aDebugLayer, aFillPolys ) )
1337 return false;
1338 }
1339
1341 return false;
1342
1343 /* -------------------------------------------------------------------------------------
1344 * Finish minimum-width pruning by re-inflating
1345 */
1346
1347 if( half_min_width - epsilon > epsilon )
1348 aFillPolys.Inflate( half_min_width - epsilon, numSegs, cornerStrategy );
1349
1350 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In15_Cu, wxT( "after-reinflating" ) );
1351
1352 /* -------------------------------------------------------------------------------------
1353 * Ensure additive changes (thermal stubs and particularly inflating acute corners) do not
1354 * add copper outside the zone boundary or inside the clearance holes
1355 */
1356
1357 aFillPolys.BooleanIntersection( aMaxExtents, SHAPE_POLY_SET::PM_FAST );
1358 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In16_Cu, wxT( "after-trim-to-outline" ) );
1359 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1360 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In17_Cu, wxT( "after-trim-to-clearance-holes" ) );
1361
1362 /* -------------------------------------------------------------------------------------
1363 * Lastly give any same-net but higher-priority zones control over their own area.
1364 */
1365
1366 subtractHigherPriorityZones( aZone, aLayer, aFillPolys );
1367 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In18_Cu, wxT( "minus-higher-priority-zones" ) );
1368
1369 aFillPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
1370 return true;
1371}
1372
1373
1375 const SHAPE_POLY_SET& aSmoothedOutline,
1376 SHAPE_POLY_SET& aFillPolys )
1377{
1379 BOX2I zone_boundingbox = aZone->GetBoundingBox();
1380 SHAPE_POLY_SET clearanceHoles;
1381 long ticker = 0;
1382
1383 auto checkForCancel =
1384 [&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
1385 {
1386 return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
1387 };
1388
1389 auto knockoutGraphicClearance =
1390 [&]( BOARD_ITEM* aItem )
1391 {
1392 if( aItem->IsKnockout() && aItem->IsOnLayer( aLayer )
1393 && aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
1394 {
1396 aZone, aItem, aLayer );
1397
1398 addKnockout( aItem, aLayer, cc.GetValue().Min(), false, clearanceHoles );
1399 }
1400 };
1401
1402 for( FOOTPRINT* footprint : m_board->Footprints() )
1403 {
1404 if( checkForCancel( m_progressReporter ) )
1405 return false;
1406
1407 knockoutGraphicClearance( &footprint->Reference() );
1408 knockoutGraphicClearance( &footprint->Value() );
1409
1410 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1411 knockoutGraphicClearance( item );
1412 }
1413
1414 for( BOARD_ITEM* item : m_board->Drawings() )
1415 {
1416 if( checkForCancel( m_progressReporter ) )
1417 return false;
1418
1419 knockoutGraphicClearance( item );
1420 }
1421
1422 aFillPolys = aSmoothedOutline;
1423 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1424
1425 // Features which are min_width should survive pruning; features that are *less* than
1426 // min_width should not. Therefore we subtract epsilon from the min_width when
1427 // deflating/inflating.
1428 int half_min_width = aZone->GetMinThickness() / 2;
1429 int epsilon = pcbIUScale.mmToIU( 0.001 );
1430 int numSegs = GetArcToSegmentCount( half_min_width, m_maxError, FULL_CIRCLE );
1431
1432 aFillPolys.Deflate( half_min_width - epsilon, numSegs );
1433
1434 // Remove the non filled areas due to the hatch pattern
1436 {
1437 if( !addHatchFillTypeOnZone( aZone, aLayer, aLayer, aFillPolys ) )
1438 return false;
1439 }
1440
1441 // Re-inflate after pruning of areas that don't meet minimum-width criteria
1442 if( half_min_width - epsilon > epsilon )
1443 aFillPolys.Inflate( half_min_width - epsilon, numSegs );
1444
1446 return true;
1447}
1448
1449
1450/*
1451 * Build the filled solid areas data from real outlines (stored in m_Poly)
1452 * The solid areas can be more than one on copper layers, and do not have holes
1453 * ( holes are linked by overlapping segments to the main outline)
1454 */
1456{
1457 SHAPE_POLY_SET* boardOutline = m_brdOutlinesValid ? &m_boardOutline : nullptr;
1458 SHAPE_POLY_SET maxExtents;
1459 SHAPE_POLY_SET smoothedPoly;
1460 PCB_LAYER_ID debugLayer = UNDEFINED_LAYER;
1461
1462 if( m_debugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
1463 {
1464 debugLayer = aLayer;
1465 aLayer = F_Cu;
1466 }
1467
1468 if ( !aZone->BuildSmoothedPoly( maxExtents, aLayer, boardOutline, &smoothedPoly ) )
1469 return false;
1470
1472 return false;
1473
1474 if( aZone->IsOnCopperLayer() )
1475 {
1476 if( fillCopperZone( aZone, aLayer, debugLayer, smoothedPoly, maxExtents, aFillPolys ) )
1477 aZone->SetNeedRefill( false );
1478 }
1479 else
1480 {
1481 if( fillNonCopperZone( aZone, aLayer, smoothedPoly, aFillPolys ) )
1482 aZone->SetNeedRefill( false );
1483 }
1484
1485 return true;
1486}
1487
1488
1493 const std::vector<PAD*>& aSpokedPadsList,
1494 std::deque<SHAPE_LINE_CHAIN>& aSpokesList )
1495{
1497 BOX2I zoneBB = aZone->GetBoundingBox();
1498 DRC_CONSTRAINT constraint;
1499
1500 zoneBB.Inflate( std::max( bds.GetBiggestClearanceValue(), aZone->GetLocalClearance() ) );
1501
1502 // Is a point on the boundary of the polygon inside or outside? This small epsilon lets
1503 // us avoid the question.
1504 int epsilon = KiROUND( pcbIUScale.IU_PER_MM * 0.04 ); // about 1.5 mil
1505
1506 for( PAD* pad : aSpokedPadsList )
1507 {
1508 // We currently only connect to pads, not pad holes
1509 if( !pad->IsOnLayer( aLayer ) )
1510 continue;
1511
1512 constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone, aLayer );
1513 int thermalReliefGap = constraint.GetValue().Min();
1514
1515 constraint = bds.m_DRCEngine->EvalRules( THERMAL_SPOKE_WIDTH_CONSTRAINT, pad, aZone, aLayer );
1516 int spoke_w = constraint.GetValue().Opt();
1517
1518 // Spoke width should ideally be smaller than the pad minor axis.
1519 // Otherwise the thermal shape is not really a thermal relief,
1520 // and the algo to count the actual number of spokes can fail
1521 int spoke_max_allowed_w = std::min( pad->GetSize().x, pad->GetSize().y );
1522
1523 spoke_w = std::max( spoke_w, constraint.Value().Min() );
1524 spoke_w = std::min( spoke_w, constraint.Value().Max() );
1525
1526 // ensure the spoke width is smaller than the pad minor size
1527 spoke_w = std::min( spoke_w, spoke_max_allowed_w );
1528
1529 // Cannot create stubs having a width < zone min thickness
1530 if( spoke_w < aZone->GetMinThickness() )
1531 continue;
1532
1533 int spoke_half_w = spoke_w / 2;
1534
1535 // Quick test here to possibly save us some work
1536 BOX2I itemBB = pad->GetBoundingBox();
1537 itemBB.Inflate( thermalReliefGap + epsilon );
1538
1539 if( !( itemBB.Intersects( zoneBB ) ) )
1540 continue;
1541
1542 // Thermal spokes consist of square-ended segments from the pad center to points just
1543 // outside the thermal relief. The outside end has an extra center point (which must be
1544 // at idx 3) which is used for testing whether or not the spoke connects to copper in the
1545 // parent zone.
1546
1547 auto buildSpokesFromOrigin =
1548 [&]( const BOX2I& box )
1549 {
1550 for( int i = 0; i < 4; i++ )
1551 {
1552 SHAPE_LINE_CHAIN spoke;
1553
1554 switch( i )
1555 {
1556 case 0: // lower stub
1557 spoke.Append( +spoke_half_w, -spoke_half_w );
1558 spoke.Append( -spoke_half_w, -spoke_half_w );
1559 spoke.Append( -spoke_half_w, box.GetBottom() );
1560 spoke.Append( 0, box.GetBottom() ); // test pt
1561 spoke.Append( +spoke_half_w, box.GetBottom() );
1562 break;
1563
1564 case 1: // upper stub
1565 spoke.Append( +spoke_half_w, +spoke_half_w );
1566 spoke.Append( -spoke_half_w, +spoke_half_w );
1567 spoke.Append( -spoke_half_w, box.GetTop() );
1568 spoke.Append( 0, box.GetTop() ); // test pt
1569 spoke.Append( +spoke_half_w, box.GetTop() );
1570 break;
1571
1572 case 2: // right stub
1573 spoke.Append( -spoke_half_w, +spoke_half_w );
1574 spoke.Append( -spoke_half_w, -spoke_half_w );
1575 spoke.Append( box.GetRight(), -spoke_half_w );
1576 spoke.Append( box.GetRight(), 0 ); // test pt
1577 spoke.Append( box.GetRight(), +spoke_half_w );
1578 break;
1579
1580 case 3: // left stub
1581 spoke.Append( +spoke_half_w, +spoke_half_w );
1582 spoke.Append( +spoke_half_w, -spoke_half_w );
1583 spoke.Append( box.GetLeft(), -spoke_half_w );
1584 spoke.Append( box.GetLeft(), 0 ); // test pt
1585 spoke.Append( box.GetLeft(), +spoke_half_w );
1586 break;
1587 }
1588
1589 spoke.SetClosed( true );
1590 aSpokesList.push_back( std::move( spoke ) );
1591 }
1592 };
1593
1594 // If the spokes are at a cardinal angle then we can generate them from a bounding box
1595 // without trig.
1596 if( pad->GetThermalSpokeAngle().IsCardinal() )
1597 {
1598 BOX2I spokesBox = pad->GetBoundingBox();
1599 spokesBox.Inflate( thermalReliefGap + epsilon );
1600
1601 // Spokes are from center of pad shape, not from hole.
1602 spokesBox.Offset( - pad->ShapePos() );
1603
1604 buildSpokesFromOrigin( spokesBox );
1605
1606 auto spokeIter = aSpokesList.rbegin();
1607
1608 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1609 spokeIter->Move( pad->ShapePos() );
1610 }
1611 // Even if the spokes are rotated, we can fudge it for round and square pads by rotating
1612 // the bounding box to match the spokes.
1613 else if( pad->GetSizeX() == pad->GetSizeY() && pad->GetShape() != PAD_SHAPE::CUSTOM )
1614 {
1615 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
1616 // from dirtying the real pad's cached shapes.
1617 PAD dummy_pad( *pad );
1618 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
1619
1620 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
1621 // offset and is at position 0,0
1622 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
1623 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
1624
1625 BOX2I spokesBox = dummy_pad.GetBoundingBox();
1626 spokesBox.Inflate( thermalReliefGap + epsilon );
1627
1628 buildSpokesFromOrigin( spokesBox );
1629
1630 auto spokeIter = aSpokesList.rbegin();
1631
1632 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1633 {
1634 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
1635 spokeIter->Move( pad->ShapePos() );
1636 }
1637 }
1638 // And lastly, even when we have to resort to trig, we can use it only in a post-process
1639 // after the rotated-bounding-box trick from above.
1640 else
1641 {
1642 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
1643 // from dirtying the real pad's cached shapes.
1644 PAD dummy_pad( *pad );
1645 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
1646
1647 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
1648 // offset and is at position 0,0
1649 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
1650 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
1651
1652 BOX2I spokesBox = dummy_pad.GetBoundingBox();
1653
1654 // In this case make the box -big-; we're going to clip to the "real" bbox later.
1655 spokesBox.Inflate( thermalReliefGap + spokesBox.GetWidth() + spokesBox.GetHeight() );
1656
1657 buildSpokesFromOrigin( spokesBox );
1658
1659 BOX2I realBBox = pad->GetBoundingBox();
1660 realBBox.Inflate( thermalReliefGap + epsilon );
1661
1662 auto spokeIter = aSpokesList.rbegin();
1663
1664 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1665 {
1666 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
1667 spokeIter->Move( pad->ShapePos() );
1668
1669 VECTOR2I origin_p = spokeIter->GetPoint( 0 );
1670 VECTOR2I origin_m = spokeIter->GetPoint( 1 );
1671 VECTOR2I origin = ( origin_p + origin_m ) / 2;
1672 VECTOR2I end_m = spokeIter->GetPoint( 2 );
1673 VECTOR2I end = spokeIter->GetPoint( 3 );
1674 VECTOR2I end_p = spokeIter->GetPoint( 4 );
1675
1676 ClipLine( &realBBox, origin_p.x, origin_p.y, end_p.x, end_p.y );
1677 ClipLine( &realBBox, origin_m.x, origin_m.y, end_m.x, end_m.y );
1678 ClipLine( &realBBox, origin.x, origin.y, end.x, end.y );
1679
1680 spokeIter->SetPoint( 2, end_m );
1681 spokeIter->SetPoint( 3, end );
1682 spokeIter->SetPoint( 4, end_p );
1683 }
1684 }
1685 }
1686
1687 for( size_t ii = 0; ii < aSpokesList.size(); ++ii )
1688 aSpokesList[ii].GenerateBBoxCache();
1689}
1690
1691
1693 PCB_LAYER_ID aDebugLayer, SHAPE_POLY_SET& aFillPolys )
1694{
1695 // Build grid:
1696
1697 // obviously line thickness must be > zone min thickness.
1698 // It can happens if a board file was edited by hand by a python script
1699 // Use 1 micron margin to be *sure* there is no issue in Gerber files
1700 // (Gbr file unit = 1 or 10 nm) due to some truncation in coordinates or calculations
1701 // This margin also avoid problems due to rounding coordinates in next calculations
1702 // that can create incorrect polygons
1703 int thickness = std::max( aZone->GetHatchThickness(),
1704 aZone->GetMinThickness() + pcbIUScale.mmToIU( 0.001 ) );
1705
1706 int linethickness = thickness - aZone->GetMinThickness();
1707 int gridsize = thickness + aZone->GetHatchGap();
1708
1709 SHAPE_POLY_SET filledPolys = aFillPolys.CloneDropTriangulation();
1710 // Use a area that contains the rotated bbox by orientation, and after rotate the result
1711 // by -orientation.
1712 if( !aZone->GetHatchOrientation().IsZero() )
1713 filledPolys.Rotate( - aZone->GetHatchOrientation() );
1714
1715 BOX2I bbox = filledPolys.BBox( 0 );
1716
1717 // Build hole shape
1718 // the hole size is aZone->GetHatchGap(), but because the outline thickness
1719 // is aZone->GetMinThickness(), the hole shape size must be larger
1720 SHAPE_LINE_CHAIN hole_base;
1721 int hole_size = aZone->GetHatchGap() + aZone->GetMinThickness();
1722 VECTOR2I corner( 0, 0 );;
1723 hole_base.Append( corner );
1724 corner.x += hole_size;
1725 hole_base.Append( corner );
1726 corner.y += hole_size;
1727 hole_base.Append( corner );
1728 corner.x = 0;
1729 hole_base.Append( corner );
1730 hole_base.SetClosed( true );
1731
1732 // Calculate minimal area of a grid hole.
1733 // All holes smaller than a threshold will be removed
1734 double minimal_hole_area = hole_base.Area() * aZone->GetHatchHoleMinArea();
1735
1736 // Now convert this hole to a smoothed shape:
1737 if( aZone->GetHatchSmoothingLevel() > 0 )
1738 {
1739 // the actual size of chamfer, or rounded corner radius is the half size
1740 // of the HatchFillTypeGap scaled by aZone->GetHatchSmoothingValue()
1741 // aZone->GetHatchSmoothingValue() = 1.0 is the max value for the chamfer or the
1742 // radius of corner (radius = half size of the hole)
1743 int smooth_value = KiROUND( aZone->GetHatchGap()
1744 * aZone->GetHatchSmoothingValue() / 2 );
1745
1746 // Minimal optimization:
1747 // make smoothing only for reasonable smooth values, to avoid a lot of useless segments
1748 // and if the smooth value is small, use chamfer even if fillet is requested
1749 #define SMOOTH_MIN_VAL_MM 0.02
1750 #define SMOOTH_SMALL_VAL_MM 0.04
1751
1752 if( smooth_value > pcbIUScale.mmToIU( SMOOTH_MIN_VAL_MM ) )
1753 {
1754 SHAPE_POLY_SET smooth_hole;
1755 smooth_hole.AddOutline( hole_base );
1756 int smooth_level = aZone->GetHatchSmoothingLevel();
1757
1758 if( smooth_value < pcbIUScale.mmToIU( SMOOTH_SMALL_VAL_MM ) && smooth_level > 1 )
1759 smooth_level = 1;
1760
1761 // Use a larger smooth_value to compensate the outline tickness
1762 // (chamfer is not visible is smooth value < outline thickess)
1763 smooth_value += aZone->GetMinThickness() / 2;
1764
1765 // smooth_value cannot be bigger than the half size oh the hole:
1766 smooth_value = std::min( smooth_value, aZone->GetHatchGap() / 2 );
1767
1768 // the error to approximate a circle by segments when smoothing corners by a arc
1769 int error_max = std::max( pcbIUScale.mmToIU( 0.01 ), smooth_value / 20 );
1770
1771 switch( smooth_level )
1772 {
1773 case 1:
1774 // Chamfer() uses the distance from a corner to create a end point
1775 // for the chamfer.
1776 hole_base = smooth_hole.Chamfer( smooth_value ).Outline( 0 );
1777 break;
1778
1779 default:
1780 if( aZone->GetHatchSmoothingLevel() > 2 )
1781 error_max /= 2; // Force better smoothing
1782
1783 hole_base = smooth_hole.Fillet( smooth_value, error_max ).Outline( 0 );
1784 break;
1785
1786 case 0:
1787 break;
1788 };
1789 }
1790 }
1791
1792 // Build holes
1793 SHAPE_POLY_SET holes;
1794
1795 for( int xx = 0; ; xx++ )
1796 {
1797 int xpos = xx * gridsize;
1798
1799 if( xpos > bbox.GetWidth() )
1800 break;
1801
1802 for( int yy = 0; ; yy++ )
1803 {
1804 int ypos = yy * gridsize;
1805
1806 if( ypos > bbox.GetHeight() )
1807 break;
1808
1809 // Generate hole
1810 SHAPE_LINE_CHAIN hole( hole_base );
1811 hole.Move( VECTOR2I( xpos, ypos ) );
1812 holes.AddOutline( hole );
1813 }
1814 }
1815
1816 holes.Move( bbox.GetPosition() );
1817
1818 if( !aZone->GetHatchOrientation().IsZero() )
1819 holes.Rotate( aZone->GetHatchOrientation() );
1820
1821 DUMP_POLYS_TO_COPPER_LAYER( holes, In10_Cu, wxT( "hatch-holes" ) );
1822
1823 int outline_margin = aZone->GetMinThickness() * 1.1;
1824
1825 // Using GetHatchThickness() can look more consistent than GetMinThickness().
1826 if( aZone->GetHatchBorderAlgorithm() && aZone->GetHatchThickness() > outline_margin )
1827 outline_margin = aZone->GetHatchThickness();
1828
1829 // The fill has already been deflated to ensure GetMinThickness() so we just have to
1830 // account for anything beyond that.
1831 SHAPE_POLY_SET deflatedFilledPolys = aFillPolys.CloneDropTriangulation();
1832 deflatedFilledPolys.Deflate( outline_margin - aZone->GetMinThickness(), 16 );
1833 holes.BooleanIntersection( deflatedFilledPolys, SHAPE_POLY_SET::PM_FAST );
1834 DUMP_POLYS_TO_COPPER_LAYER( holes, In11_Cu, wxT( "fill-clipped-hatch-holes" ) );
1835
1836 SHAPE_POLY_SET deflatedOutline = aZone->Outline()->CloneDropTriangulation();
1837 deflatedOutline.Deflate( outline_margin, 16 );
1838 holes.BooleanIntersection( deflatedOutline, SHAPE_POLY_SET::PM_FAST );
1839 DUMP_POLYS_TO_COPPER_LAYER( holes, In12_Cu, wxT( "outline-clipped-hatch-holes" ) );
1840
1841 if( aZone->GetNetCode() != 0 )
1842 {
1843 // Vias and pads connected to the zone must not be allowed to become isolated inside
1844 // one of the holes. Effectively this means their copper outline needs to be expanded
1845 // to be at least as wide as the gap so that it is guaranteed to touch at least one
1846 // edge.
1847 BOX2I zone_boundingbox = aZone->GetBoundingBox();
1848 SHAPE_POLY_SET aprons;
1849 int min_apron_radius = ( aZone->GetHatchGap() * 10 ) / 19;
1850
1851 for( PCB_TRACK* track : m_board->Tracks() )
1852 {
1853 if( track->Type() == PCB_VIA_T )
1854 {
1855 PCB_VIA* via = static_cast<PCB_VIA*>( track );
1856
1857 if( via->GetNetCode() == aZone->GetNetCode()
1858 && via->IsOnLayer( aLayer )
1859 && via->GetBoundingBox().Intersects( zone_boundingbox ) )
1860 {
1861 int r = std::max( min_apron_radius,
1862 via->GetDrillValue() / 2 + outline_margin );
1863
1864 TransformCircleToPolygon( aprons, via->GetPosition(), r, ARC_HIGH_DEF,
1865 ERROR_OUTSIDE );
1866 }
1867 }
1868 }
1869
1870 for( FOOTPRINT* footprint : m_board->Footprints() )
1871 {
1872 for( PAD* pad : footprint->Pads() )
1873 {
1874 if( pad->GetNetCode() == aZone->GetNetCode()
1875 && pad->IsOnLayer( aLayer )
1876 && pad->GetBoundingBox().Intersects( zone_boundingbox ) )
1877 {
1878 // What we want is to bulk up the pad shape so that the narrowest bit of
1879 // copper between the hole and the apron edge is at least outline_margin
1880 // wide (and that the apron itself meets min_apron_radius. But that would
1881 // take a lot of code and math, and the following approximation is close
1882 // enough.
1883 int pad_width = std::min( pad->GetSize().x, pad->GetSize().y );
1884 int slot_width = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
1885 int min_annular_ring_width = ( pad_width - slot_width ) / 2;
1886 int clearance = std::max( min_apron_radius - pad_width / 2,
1887 outline_margin - min_annular_ring_width );
1888
1889 clearance = std::max( 0, clearance - linethickness / 2 );
1890 pad->TransformShapeToPolygon( aprons, aLayer, clearance, ARC_HIGH_DEF,
1891 ERROR_OUTSIDE );
1892 }
1893 }
1894 }
1895
1897 }
1898 DUMP_POLYS_TO_COPPER_LAYER( holes, In13_Cu, wxT( "pad-via-clipped-hatch-holes" ) );
1899
1900 // Now filter truncated holes to avoid small holes in pattern
1901 // It happens for holes near the zone outline
1902 for( int ii = 0; ii < holes.OutlineCount(); )
1903 {
1904 double area = holes.Outline( ii ).Area();
1905
1906 if( area < minimal_hole_area ) // The current hole is too small: remove it
1907 holes.DeletePolygon( ii );
1908 else
1909 ++ii;
1910 }
1911
1912 // create grid. Use SHAPE_POLY_SET::PM_STRICTLY_SIMPLE to
1913 // generate strictly simple polygons needed by Gerber files and Fracture()
1914 aFillPolys.BooleanSubtract( aFillPolys, holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
1915 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In14_Cu, wxT( "after-hatching" ) );
1916
1917 return true;
1918}
constexpr int ARC_HIGH_DEF
Definition: base_units.h:121
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
@ ZLC_UNRESOLVED
Definition: board_item.h:46
@ ZLC_CONNECTED
Definition: board_item.h:47
@ ZLC_UNCONNECTED
Definition: board_item.h:48
double m_ExtraClearance
Extra fill clearance for zone fills.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
bool m_DebugZoneFiller
A mode that dumps the various stages of a F_Cu fill into In1_Cu through In9_Cu.
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
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.
Definition: board_item.cpp:196
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
ZONES & Zones()
Definition: board.h:313
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:1911
FOOTPRINTS & Footprints()
Definition: board.h:307
TRACKS & Tracks()
Definition: board.h:304
DRAWINGS & Drawings()
Definition: board.h:310
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:424
const Vec & GetPosition() const
Definition: box2.h:184
int GetSizeMax() const
Definition: box2.h:200
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:224
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:269
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:111
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:72
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
MINOPTMAX< int > & Value()
Definition: drc_rule.h:140
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:139
ZONE_CONNECTION m_ZoneConnection
Definition: drc_rule.h:172
bool IsZero() const
Definition: eda_angle.h:169
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:46
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: confirm.cpp:56
bool SetOKCancelLabels(const ButtonLabel &ok, const ButtonLabel &cancel) override
Shows the 'do not show again' checkbox.
Definition: confirm.h:56
int ShowModal() override
Definition: confirm.cpp:100
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:600
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:733
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
T Min() const
Definition: minoptmax.h:33
T Max() const
Definition: minoptmax.h:34
T Opt() const
Definition: minoptmax.h:35
Definition: pad.h:59
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition: pad.cpp:622
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition: pad.cpp:1573
bool TransformHoleToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc) const
Build the corner list of the polygonal drill shape in the board coordinate system.
Definition: pad.cpp:1556
void SetOffset(const VECTOR2I &aOffset)
Definition: pad.h:268
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: pad.h:207
void SetPosition(const VECTOR2I &aPos) override
Definition: pad.h:191
PAD_SHAPE GetShape() const
Definition: pad.h:189
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation angle of the pad.
Definition: pad.cpp:681
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
double Area(bool aAbsolute=true) const
Return the area of this chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
SHAPE_POLY_SET Chamfer(int aDistance)
Return a chamfered version of the polygon set.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
void ClearArcs()
Appends a vertex at the end of the given outline/hole (default: the last outline)
CORNER_STRATEGY
< define how inflate transform build inflated polygon
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
@ ROUND_ALL_CORNERS
All angles are rounded.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
void DeletePolygon(int aIdx)
Delete aIdx-th polygon and its triangulation data from the set.
void Deflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
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,...
POLYGON & Polygon(int aIndex)
void Inflate(int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union between a and b, store the result in it self For aFastMode meaning,...
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
void Simplify(POLYGON_MODE aFastMode)
SHAPE_LINE_CHAIN & Outline(int aIndex)
int NewOutline()
Creates a new hole in a given outline.
void BuildBBoxCaches() const
Construct BBoxCaches for Contains(), below.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
SHAPE_POLY_SET Fillet(int aRadius, int aErrorMax)
Return a filleted version of the polygon set.
void Move(const VECTOR2I &aVector) override
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
SHAPE_POLY_SET CloneDropTriangulation() const
Creates a new empty polygon in the set and returns its index.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
COMMIT * m_commit
Definition: zone_filler.h:134
int m_worstClearance
Definition: zone_filler.h:138
void addKnockout(PAD *aPad, PCB_LAYER_ID aLayer, int aGap, SHAPE_POLY_SET &aHoles)
Add a knockout for a pad.
bool m_debugZoneFiller
Definition: zone_filler.h:140
void buildCopperItemClearances(const ZONE *aZone, PCB_LAYER_ID aLayer, const std::vector< PAD * > aNoConnectionPads, SHAPE_POLY_SET &aHoles)
Removes clearance from the shape for copper items which share the zone's layer but are not connected ...
ZONE_FILLER(BOARD *aBoard, COMMIT *aCommit)
Definition: zone_filler.cpp:53
void buildThermalSpokes(const ZONE *box, PCB_LAYER_ID aLayer, const std::vector< PAD * > &aSpokedPadsList, std::deque< SHAPE_LINE_CHAIN > &aSpokes)
Function buildThermalSpokes Constructs a list of all thermal spokes for the given zone.
void subtractHigherPriorityZones(const ZONE *aZone, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aRawFill)
Removes the outlines of higher-proirity zones with the same net.
SHAPE_POLY_SET m_boardOutline
Definition: zone_filler.h:132
bool m_brdOutlinesValid
Definition: zone_filler.h:133
bool addHatchFillTypeOnZone(const ZONE *aZone, PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer, SHAPE_POLY_SET &aFillPolys)
for zones having the ZONE_FILL_MODE::ZONE_FILL_MODE::HATCH_PATTERN, create a grid pattern in filled a...
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Definition: zone_filler.cpp:71
bool Fill(std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
Definition: zone_filler.cpp:89
BOARD * m_board
Definition: zone_filler.h:131
void knockoutThermalReliefs(const ZONE *aZone, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aFill, std::vector< PAD * > &aThermalConnectionPads, std::vector< PAD * > &aNoConnectionPads)
Removes thermal reliefs from the shape for any pads connected to the zone.
PROGRESS_REPORTER * m_progressReporter
Definition: zone_filler.h:135
bool fillCopperZone(const ZONE *aZone, PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer, const SHAPE_POLY_SET &aSmoothedOutline, const SHAPE_POLY_SET &aMaxExtents, SHAPE_POLY_SET &aFillPolys)
Function fillCopperZone Add non copper areas polygons (pads and tracks with clearance) to a filled co...
void addHoleKnockout(PAD *aPad, int aGap, SHAPE_POLY_SET &aHoles)
Add a knockout for a pad's hole.
bool fillNonCopperZone(const ZONE *aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aSmoothedOutline, SHAPE_POLY_SET &aFillPolys)
bool fillSingleZone(ZONE *aZone, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aFillPolys)
Build the filled solid areas polygons from zone outlines (stored in m_Poly) The solid areas can be mo...
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
void SetNeedRefill(bool aNeedRefill)
Definition: zone.h:246
int GetHatchBorderAlgorithm() const
Definition: zone.h:278
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:602
void CacheTriangulation(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Create a list of triangles that "fill" the solid areas used for instance to draw these solid areas on...
Definition: zone.cpp:1002
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:711
MD5_HASH GetHashValue(PCB_LAYER_ID aLayer)
Definition: zone.cpp:384
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:320
SHAPE_POLY_SET * Outline()
Definition: zone.h:312
void SetFillFlag(PCB_LAYER_ID aLayer, bool aFlag)
Definition: zone.h:240
long long int GetMinIslandArea() const
Definition: zone.h:714
SHAPE_POLY_SET * GetFill(PCB_LAYER_ID aLayer)
Definition: zone.h:608
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: zone.cpp:467
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
Definition: zone.h:623
int GetMinThickness() const
Definition: zone.h:251
bool HigherPriority(const ZONE *aOther) const
Definition: zone.cpp:183
void SetIsFilled(bool isFilled)
Definition: zone.h:243
int GetHatchThickness() const
Definition: zone.h:260
double GetHatchHoleMinArea() const
Definition: zone.h:275
bool IsTeardropArea() const
Definition: zone.h:681
void BuildHashValue(PCB_LAYER_ID aLayer)
Build the hash value of m_FilledPolysList, and store it internally in m_filledPolysHash.
Definition: zone.cpp:393
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:266
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
Definition: zone.cpp:1066
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:174
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
int GetHatchGap() const
Definition: zone.h:263
double GetHatchSmoothingValue() const
Definition: zone.h:272
int GetHatchSmoothingLevel() const
Definition: zone.h:269
void SetIsIsland(PCB_LAYER_ID aLayer, int aPolyIdx)
Definition: zone.h:637
bool IsOnCopperLayer() const override
Definition: zone.cpp:251
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
Definition: zone.cpp:1193
std::mutex & GetLock()
Definition: zone.h:230
This file is part of the common library.
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 BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
Definition: convex_hull.cpp:87
DRC_CONSTRAINT_T
Definition: drc_rule.h:44
@ EDGE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:49
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:70
@ CLEARANCE_CONSTRAINT
Definition: drc_rule.h:46
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
Definition: drc_rule.h:59
@ THERMAL_RELIEF_GAP_CONSTRAINT
Definition: drc_rule.h:58
@ HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:47
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:69
#define _(s)
static constexpr EDA_ANGLE & FULL_CIRCLE
Definition: eda_angle.h:410
E_SERIE r
Definition: eserie.cpp:41
a few functions useful in geometry calculations.
@ ERROR_OUTSIDE
bool ClipLine(const BOX2I *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
int GetKnockoutTextMargin(const VECTOR2I &aSize, int aThickness)
Returns the margin for knockout text.
Definition: gr_text.h:97
@ ALWAYS_FLASHED
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ In11_Cu
Definition: layer_ids.h:75
@ In17_Cu
Definition: layer_ids.h:81
@ Edge_Cuts
Definition: layer_ids.h:113
@ In9_Cu
Definition: layer_ids.h:73
@ In7_Cu
Definition: layer_ids.h:71
@ In15_Cu
Definition: layer_ids.h:79
@ In2_Cu
Definition: layer_ids.h:66
@ In10_Cu
Definition: layer_ids.h:74
@ Margin
Definition: layer_ids.h:114
@ In4_Cu
Definition: layer_ids.h:68
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
@ In16_Cu
Definition: layer_ids.h:80
@ In1_Cu
Definition: layer_ids.h:65
@ In13_Cu
Definition: layer_ids.h:77
@ In8_Cu
Definition: layer_ids.h:72
@ In14_Cu
Definition: layer_ids.h:78
@ In12_Cu
Definition: layer_ids.h:76
@ In6_Cu
Definition: layer_ids.h:70
@ In5_Cu
Definition: layer_ids.h:69
@ In3_Cu
Definition: layer_ids.h:67
@ F_Cu
Definition: layer_ids.h:64
@ In18_Cu
Definition: layer_ids.h:82
@ CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL
Definition: pad.h:45
@ PTH
Plated through hole pad.
A structure used for calculating isolated islands on a given zone across all its layers.
const double IU_PER_MM
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
Definition: thread_pool.cpp:32
static thread_pool * tp
Definition: thread_pool.cpp:30
BS::thread_pool thread_pool
Definition: thread_pool.h:30
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:111
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618
#define SMOOTH_MIN_VAL_MM
#define DUMP_POLYS_TO_COPPER_LAYER(a, b, c)
#define SMOOTH_SMALL_VAL_MM
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
Definition: zone_settings.h:57
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:50
@ THERMAL
Use thermal relief for pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper