KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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 <pcb_tablecell.h>
39#include <pcb_table.h>
40#include <pcb_dimension.h>
43#include <board_commit.h>
44#include <progress_reporter.h>
48#include <kidialog.h>
49#include <core/thread_pool.h>
50#include <math/util.h> // for KiROUND
51#include "zone_filler.h"
52
53
55 m_board( aBoard ),
56 m_brdOutlinesValid( false ),
57 m_commit( aCommit ),
58 m_progressReporter( nullptr ),
59 m_maxError( ARC_HIGH_DEF ),
60 m_worstClearance( 0 )
61{
62 // To enable add "DebugZoneFiller=1" to kicad_advanced settings file.
64}
65
66
68{
69}
70
71
73{
74 m_progressReporter = aReporter;
75 wxASSERT_MSG( m_commit, wxT( "ZONE_FILLER must have a valid commit to call "
76 "SetProgressReporter" ) );
77}
78
79
90bool ZONE_FILLER::Fill( const std::vector<ZONE*>& aZones, bool aCheck, wxWindow* aParent )
91{
92 std::lock_guard<KISPINLOCK> lock( m_board->GetConnectivity()->GetLock() );
93
94 std::vector<std::pair<ZONE*, PCB_LAYER_ID>> toFill;
95 std::map<std::pair<ZONE*, PCB_LAYER_ID>, MD5_HASH> oldFillHashes;
96 std::map<ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>> isolatedIslandsMap;
97
98 std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
99
100 // Rebuild (from scratch, ignoring dirty flags) just in case. This really needs to be reliable.
101 connectivity->ClearRatsnest();
102 connectivity->Build( m_board, m_progressReporter );
103
105
107 {
108 m_progressReporter->Report( aCheck ? _( "Checking zone fills..." )
109 : _( "Building zone fills..." ) );
110 m_progressReporter->SetMaxProgress( aZones.size() );
112 }
113
114 // The board outlines is used to clip solid areas inside the board (when outlines are valid)
117
118 // Update and cache zone bounding boxes and pad effective shapes so that we don't have to
119 // make them thread-safe.
120 //
121 for( ZONE* zone : m_board->Zones() )
122 zone->CacheBoundingBox();
123
124 for( FOOTPRINT* footprint : m_board->Footprints() )
125 {
126 for( PAD* pad : footprint->Pads() )
127 {
128 if( pad->IsDirty() )
129 {
130 pad->BuildEffectiveShapes( UNDEFINED_LAYER );
131 pad->BuildEffectivePolygon( ERROR_OUTSIDE );
132 }
133 }
134
135 for( ZONE* zone : footprint->Zones() )
136 zone->CacheBoundingBox();
137
138 // Rules may depend on insideCourtyard() or other expressions
139 footprint->BuildCourtyardCaches();
140 }
141
142 LSET boardCuMask = m_board->GetEnabledLayers() & LSET::AllCuMask();
143
144 auto findHighestPriorityZone = [&]( const BOX2I& aBBox, const PCB_LAYER_ID aItemLayer,
145 const int aNetcode,
146 const std::function<bool( const ZONE* )> aTestFn ) -> ZONE*
147 {
148 unsigned highestPriority = 0;
149 ZONE* highestPriorityZone = nullptr;
150
151 for( ZONE* zone : m_board->Zones() )
152 {
153 // Rule areas are not filled
154 if( zone->GetIsRuleArea() )
155 continue;
156
157 if( zone->GetAssignedPriority() < highestPriority )
158 continue;
159
160 if( !zone->IsOnLayer( aItemLayer ) )
161 continue;
162
163 // Degenerate zones will cause trouble; skip them
164 if( zone->GetNumCorners() <= 2 )
165 continue;
166
167 if( !zone->GetBoundingBox().Intersects( aBBox ) )
168 continue;
169
170 if( !aTestFn( zone ) )
171 continue;
172
173 // Prefer highest priority and matching netcode
174 if( zone->GetAssignedPriority() > highestPriority || zone->GetNetCode() == aNetcode )
175 {
176 highestPriority = zone->GetAssignedPriority();
177 highestPriorityZone = zone;
178 }
179 }
180
181 return highestPriorityZone;
182 };
183
184 auto isInPourKeepoutArea = [&]( const BOX2I& aBBox, const PCB_LAYER_ID aItemLayer,
185 const VECTOR2I aTestPoint ) -> bool
186 {
187 for( ZONE* zone : m_board->Zones() )
188 {
189 if( !zone->GetIsRuleArea() )
190 continue;
191
192 if( !zone->GetDoNotAllowCopperPour() )
193 continue;
194
195 if( !zone->IsOnLayer( aItemLayer ) )
196 continue;
197
198 // Degenerate zones will cause trouble; skip them
199 if( zone->GetNumCorners() <= 2 )
200 continue;
201
202 if( !zone->GetBoundingBox().Intersects( aBBox ) )
203 continue;
204
205 if( zone->Outline()->Contains( aTestPoint ) )
206 return true;
207 }
208
209 return false;
210 };
211
212 // Determine state of conditional via flashing
213 for( PCB_TRACK* track : m_board->Tracks() )
214 {
215 if( track->Type() == PCB_VIA_T )
216 {
217 PCB_VIA* via = static_cast<PCB_VIA*>( track );
218
219 via->ClearZoneLayerOverrides();
220
221 if( !via->GetRemoveUnconnected() )
222 continue;
223
224 BOX2I bbox = via->GetBoundingBox();
225 VECTOR2I center = via->GetPosition();
226 int testRadius = via->GetDrillValue() / 2 + 1;
227 unsigned netcode = via->GetNetCode();
228 LSET layers = via->GetLayerSet() & boardCuMask;
229
230 // Checking if the via hole touches the zone outline
231 auto viaTestFn = [&]( const ZONE* aZone ) -> bool
232 {
233 return aZone->Outline()->Contains( center, -1, testRadius );
234 };
235
236 for( PCB_LAYER_ID layer : layers.Seq() )
237 {
238 if( !via->ConditionallyFlashed( layer ) )
239 continue;
240
241 if( isInPourKeepoutArea( bbox, layer, center ) )
242 {
243 via->SetZoneLayerOverride( layer, ZLO_FORCE_NO_ZONE_CONNECTION );
244 }
245 else
246 {
247 ZONE* zone = findHighestPriorityZone( bbox, layer, netcode, viaTestFn );
248
249 if( zone && zone->GetNetCode() == via->GetNetCode() )
250 via->SetZoneLayerOverride( layer, ZLO_FORCE_FLASHED );
251 else
252 via->SetZoneLayerOverride( layer, ZLO_FORCE_NO_ZONE_CONNECTION );
253 }
254 }
255 }
256 }
257
258 // Determine state of conditional pad flashing
259 for( FOOTPRINT* footprint : m_board->Footprints() )
260 {
261 for( PAD* pad : footprint->Pads() )
262 {
263 pad->ClearZoneLayerOverrides();
264
265 if( !pad->GetRemoveUnconnected() )
266 continue;
267
268 BOX2I bbox = pad->GetBoundingBox();
269 VECTOR2I center = pad->GetPosition();
270 unsigned netcode = pad->GetNetCode();
271 LSET layers = pad->GetLayerSet() & boardCuMask;
272
273 auto padTestFn = [&]( const ZONE* aZone ) -> bool
274 {
275 return aZone->Outline()->Contains( center );
276 };
277
278 for( PCB_LAYER_ID layer : layers.Seq() )
279 {
280 if( !pad->ConditionallyFlashed( layer ) )
281 continue;
282
283 if( isInPourKeepoutArea( bbox, layer, center ) )
284 {
285 pad->SetZoneLayerOverride( layer, ZLO_FORCE_NO_ZONE_CONNECTION );
286 }
287 else
288 {
289 ZONE* zone = findHighestPriorityZone( bbox, layer, netcode, padTestFn );
290
291 if( zone && zone->GetNetCode() == pad->GetNetCode() )
292 pad->SetZoneLayerOverride( layer, ZLO_FORCE_FLASHED );
293 else
294 pad->SetZoneLayerOverride( layer, ZLO_FORCE_NO_ZONE_CONNECTION );
295 }
296 }
297 }
298 }
299
300 for( ZONE* zone : aZones )
301 {
302 // Rule areas are not filled
303 if( zone->GetIsRuleArea() )
304 continue;
305
306 // Degenerate zones will cause trouble; skip them
307 if( zone->GetNumCorners() <= 2 )
308 continue;
309
310 if( m_commit )
311 m_commit->Modify( zone );
312
313 // calculate the hash value for filled areas. it will be used later to know if the
314 // current filled areas are up to date
315 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
316 {
317 zone->BuildHashValue( layer );
318 oldFillHashes[ { zone, layer } ] = zone->GetHashValue( layer );
319
320 // Add the zone to the list of zones to test or refill
321 toFill.emplace_back( std::make_pair( zone, layer ) );
322
323 isolatedIslandsMap[ zone ][ layer ] = ISOLATED_ISLANDS();
324 }
325
326 // Remove existing fill first to prevent drawing invalid polygons on some platforms
327 zone->UnFill();
328 }
329
330 auto check_fill_dependency =
331 [&]( ZONE* aZone, PCB_LAYER_ID aLayer, ZONE* aOtherZone ) -> bool
332 {
333 // Check to see if we have to knock-out the filled areas of a higher-priority
334 // zone. If so we have to wait until said zone is filled before we can fill.
335
336 // If the other zone is already filled on the requested layer then we're
337 // good-to-go
338 if( aOtherZone->GetFillFlag( aLayer ) )
339 return false;
340
341 // Even if keepouts exclude copper pours, the exclusion is by outline rather than
342 // filled area, so we're good-to-go here too
343 if( aOtherZone->GetIsRuleArea() )
344 return false;
345
346 // If the other zone is never going to be filled then don't wait for it
347 if( aOtherZone->GetNumCorners() <= 2 )
348 return false;
349
350 // If the zones share no common layers
351 if( !aOtherZone->GetLayerSet().test( aLayer ) )
352 return false;
353
354 if( aZone->HigherPriority( aOtherZone ) )
355 return false;
356
357 // Same-net zones always use outlines to produce determinate results
358 if( aOtherZone->SameNet( aZone ) )
359 return false;
360
361 // A higher priority zone is found: if we intersect and it's not filled yet
362 // then we have to wait.
363 BOX2I inflatedBBox = aZone->GetBoundingBox();
364 inflatedBBox.Inflate( m_worstClearance );
365
366 if( !inflatedBBox.Intersects( aOtherZone->GetBoundingBox() ) )
367 return false;
368
369 return aZone->Outline()->Collide( aOtherZone->Outline(), m_worstClearance );
370 };
371
372 auto fill_lambda =
373 [&]( std::pair<ZONE*, PCB_LAYER_ID> aFillItem ) -> int
374 {
375 PCB_LAYER_ID layer = aFillItem.second;
376 ZONE* zone = aFillItem.first;
377 bool canFill = true;
378
379 // Check for any fill dependencies. If our zone needs to be clipped by
380 // another zone then we can't fill until that zone is filled.
381 for( ZONE* otherZone : aZones )
382 {
383 if( otherZone == zone )
384 continue;
385
386 if( check_fill_dependency( zone, layer, otherZone ) )
387 {
388 canFill = false;
389 break;
390 }
391 }
392
394 return 0;
395
396 if( !canFill )
397 return 0;
398
399 // Now we're ready to fill.
400 {
401 std::unique_lock<std::mutex> zoneLock( zone->GetLock(), std::try_to_lock );
402
403 if( !zoneLock.owns_lock() )
404 return 0;
405
406 SHAPE_POLY_SET fillPolys;
407
408 if( !fillSingleZone( zone, layer, fillPolys ) )
409 return 0;
410
411 zone->SetFilledPolysList( layer, fillPolys );
412 }
413
416
417 return 1;
418 };
419
420 auto tesselate_lambda =
421 [&]( std::pair<ZONE*, PCB_LAYER_ID> aFillItem ) -> int
422 {
424 return 0;
425
426 PCB_LAYER_ID layer = aFillItem.second;
427 ZONE* zone = aFillItem.first;
428
429 {
430 std::unique_lock<std::mutex> zoneLock( zone->GetLock(), std::try_to_lock );
431
432 if( !zoneLock.owns_lock() )
433 return 0;
434
435 zone->CacheTriangulation( layer );
436 zone->SetFillFlag( layer, true );
437 }
438
439 return 1;
440 };
441
442 // Calculate the copper fills (NB: this is multi-threaded)
443 //
444 std::vector<std::pair<std::future<int>, int>> returns;
445 returns.reserve( toFill.size() );
446 size_t finished = 0;
447 bool cancelled = false;
448
450
451 for( const std::pair<ZONE*, PCB_LAYER_ID>& fillItem : toFill )
452 returns.emplace_back( std::make_pair( tp.submit( fill_lambda, fillItem ), 0 ) );
453
454 while( !cancelled && finished != 2 * toFill.size() )
455 {
456 for( size_t ii = 0; ii < returns.size(); ++ii )
457 {
458 auto& ret = returns[ii];
459
460 if( ret.second > 1 )
461 continue;
462
463 std::future_status status = ret.first.wait_for( std::chrono::seconds( 0 ) );
464
465 if( status == std::future_status::ready )
466 {
467 if( ret.first.get() ) // lambda completed
468 {
469 ++finished;
470 ret.second++; // go to next step
471 }
472
473 if( !cancelled )
474 {
475 // Queue the next step (will re-queue the existing step if it didn't complete)
476 if( ret.second == 0 )
477 returns[ii].first = tp.submit( fill_lambda, toFill[ii] );
478 else if( ret.second == 1 )
479 returns[ii].first = tp.submit( tesselate_lambda, toFill[ii] );
480 }
481 }
482 }
483
484 std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
485
486
488 {
490
492 cancelled = true;
493 }
494 }
495
496 // Make sure that all futures have finished.
497 // This can happen when the user cancels the above operation
498 for( auto& ret : returns )
499 {
500 if( ret.first.valid() )
501 {
502 std::future_status status = ret.first.wait_for( std::chrono::seconds( 0 ) );
503
504 while( status != std::future_status::ready )
505 {
508
509 status = ret.first.wait_for( std::chrono::milliseconds( 100 ) );
510 }
511 }
512 }
513
514 // Now update the connectivity to check for isolated copper islands
515 // (NB: FindIsolatedCopperIslands() is multi-threaded)
516 //
518 {
520 return false;
521
523 m_progressReporter->Report( _( "Removing isolated copper islands..." ) );
525 }
526
527 connectivity->SetProgressReporter( m_progressReporter );
528 connectivity->FillIsolatedIslandsMap( isolatedIslandsMap );
529 connectivity->SetProgressReporter( nullptr );
530
532 return false;
533
534 for( ZONE* zone : aZones )
535 {
536 // Keepout zones are not filled
537 if( zone->GetIsRuleArea() )
538 continue;
539
540 zone->SetIsFilled( true );
541 }
542
543 // Now remove isolated copper islands according to the isolated islands strategy assigned
544 // by the user (always, never, below-certain-size).
545 //
546 for( const auto& [ zone, zoneIslands ] : isolatedIslandsMap )
547 {
548 // If *all* the polygons are islands, do not remove any of them
549 bool allIslands = true;
550
551 for( const auto& [ layer, layerIslands ] : zoneIslands )
552 {
553 if( layerIslands.m_IsolatedOutlines.size()
554 != static_cast<size_t>( zone->GetFilledPolysList( layer )->OutlineCount() ) )
555 {
556 allIslands = false;
557 break;
558 }
559 }
560
561 if( allIslands )
562 continue;
563
564 for( const auto& [ layer, layerIslands ] : zoneIslands )
565 {
566 if( m_debugZoneFiller && LSET::InternalCuMask().Contains( layer ) )
567 continue;
568
569 if( layerIslands.m_IsolatedOutlines.empty() )
570 continue;
571
572 std::vector<int> islands = layerIslands.m_IsolatedOutlines;
573
574 // The list of polygons to delete must be explored from last to first in list,
575 // to allow deleting a polygon from list without breaking the remaining of the list
576 std::sort( islands.begin(), islands.end(), std::greater<int>() );
577
578 std::shared_ptr<SHAPE_POLY_SET> poly = zone->GetFilledPolysList( layer );
579 long long int minArea = zone->GetMinIslandArea();
580 ISLAND_REMOVAL_MODE mode = zone->GetIslandRemovalMode();
581
582 for( int idx : islands )
583 {
584 SHAPE_LINE_CHAIN& outline = poly->Outline( idx );
585
586 if( mode == ISLAND_REMOVAL_MODE::ALWAYS )
587 poly->DeletePolygonAndTriangulationData( idx, false );
588 else if ( mode == ISLAND_REMOVAL_MODE::AREA && outline.Area( true ) < minArea )
589 poly->DeletePolygonAndTriangulationData( idx, false );
590 else
591 zone->SetIsIsland( layer, idx );
592 }
593
594 poly->UpdateTriangulationDataHash();
595 zone->CalculateFilledArea();
596
598 return false;
599 }
600 }
601
602 // Now remove islands which are either outside the board edge or fail to meet the minimum
603 // area requirements
604 using island_check_return = std::vector<std::pair<std::shared_ptr<SHAPE_POLY_SET>, int>>;
605
606 std::vector<std::pair<std::shared_ptr<SHAPE_POLY_SET>, double>> polys_to_check;
607
608 // rough estimate to save re-allocation time
609 polys_to_check.reserve( m_board->GetCopperLayerCount() * aZones.size() );
610
611 for( ZONE* zone : aZones )
612 {
613 // Don't check for connections on layers that only exist in the zone but
614 // were disabled in the board
615 BOARD* board = zone->GetBoard();
616 LSET zoneCopperLayers = zone->GetLayerSet() & LSET::AllCuMask() & board->GetEnabledLayers();
617
618 // Min-thickness is the web thickness. On the other hand, a blob min-thickness by
619 // min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
620 // arbitrarily choose "at least 3X the area".
621 double minArea = (double) zone->GetMinThickness() * zone->GetMinThickness() * 3;
622
623 for( PCB_LAYER_ID layer : zoneCopperLayers.Seq() )
624 {
626 continue;
627
628 polys_to_check.emplace_back( zone->GetFilledPolysList( layer ), minArea );
629 }
630 }
631
632 auto island_lambda =
633 [&]( int aStart, int aEnd ) -> island_check_return
634 {
635 island_check_return retval;
636
637 for( int ii = aStart; ii < aEnd && !cancelled; ++ii )
638 {
639 auto [poly, minArea] = polys_to_check[ii];
640
641 for( int jj = poly->OutlineCount() - 1; jj >= 0; jj-- )
642 {
643 SHAPE_POLY_SET island;
644 SHAPE_POLY_SET intersection;
645 const SHAPE_LINE_CHAIN& test_poly = poly->Polygon( jj ).front();
646 double island_area = test_poly.Area();
647
648 if( island_area < minArea )
649 continue;
650
651
652 island.AddOutline( test_poly );
653 intersection.BooleanIntersection( m_boardOutline, island,
655
656 // Nominally, all of these areas should be either inside or outside the
657 // board outline. So this test should be able to just compare areas (if
658 // they are equal, you are inside). But in practice, we sometimes have
659 // slight overlap at the edges, so testing against half-size area acts as
660 // a fail-safe.
661 if( intersection.Area() < island_area / 2.0 )
662 retval.emplace_back( poly, jj );
663 }
664 }
665
666 return retval;
667 };
668
669 auto island_returns = tp.parallelize_loop( 0, polys_to_check.size(), island_lambda );
670 cancelled = false;
671
672 // Allow island removal threads to finish
673 for( size_t ii = 0; ii < island_returns.size(); ++ii )
674 {
675 std::future<island_check_return>& ret = island_returns[ii];
676
677 if( ret.valid() )
678 {
679 std::future_status status = ret.wait_for( std::chrono::seconds( 0 ) );
680
681 while( status != std::future_status::ready )
682 {
684 {
686
688 cancelled = true;
689 }
690
691 status = ret.wait_for( std::chrono::milliseconds( 100 ) );
692 }
693 }
694 }
695
696 if( cancelled )
697 return false;
698
699 for( size_t ii = 0; ii < island_returns.size(); ++ii )
700 {
701 std::future<island_check_return>& ret = island_returns[ii];
702
703 if( ret.valid() )
704 {
705 for( auto& action_item : ret.get() )
706 action_item.first->DeletePolygonAndTriangulationData( action_item.second, true );
707 }
708 }
709
710 for( ZONE* zone : aZones )
711 zone->CalculateFilledArea();
712
713
714 if( aCheck )
715 {
716 bool outOfDate = false;
717
718 for( ZONE* zone : aZones )
719 {
720 // Keepout zones are not filled
721 if( zone->GetIsRuleArea() )
722 continue;
723
724 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
725 {
726 zone->BuildHashValue( layer );
727
728 if( oldFillHashes[ { zone, layer } ] != zone->GetHashValue( layer ) )
729 outOfDate = true;
730 }
731 }
732
733 if( outOfDate )
734 {
735 KIDIALOG dlg( aParent, _( "Zone fills are out-of-date. Refill?" ),
736 _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
737 dlg.SetOKCancelLabels( _( "Refill" ), _( "Continue without Refill" ) );
738 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
739
740 if( dlg.ShowModal() == wxID_CANCEL )
741 return false;
742 }
743 else
744 {
745 // No need to commit something that hasn't changed (and committing will set
746 // the modified flag).
747 return false;
748 }
749 }
750
752 {
754 return false;
755
758 }
759
760 return true;
761}
762
763
768void ZONE_FILLER::addKnockout( PAD* aPad, PCB_LAYER_ID aLayer, int aGap, SHAPE_POLY_SET& aHoles )
769{
770 if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
771 {
772 SHAPE_POLY_SET poly;
773 aPad->TransformShapeToPolygon( poly, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
774
775 // the pad shape in zone can be its convex hull or the shape itself
777 {
778 std::vector<VECTOR2I> convex_hull;
779 BuildConvexHull( convex_hull, poly );
780
781 aHoles.NewOutline();
782
783 for( const VECTOR2I& pt : convex_hull )
784 aHoles.Append( pt );
785 }
786 else
787 aHoles.Append( poly );
788 }
789 else
790 {
791 aPad->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
792 }
793}
794
795
799void ZONE_FILLER::addHoleKnockout( PAD* aPad, int aGap, SHAPE_POLY_SET& aHoles )
800{
801 aPad->TransformHoleToPolygon( aHoles, aGap, m_maxError, ERROR_OUTSIDE );
802}
803
804
809void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap,
810 bool aIgnoreLineWidth, SHAPE_POLY_SET& aHoles )
811{
812 switch( aItem->Type() )
813 {
814 case PCB_FIELD_T:
815 case PCB_TEXT_T:
816 {
817 PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
818
819 if( text->IsVisible() )
820 {
821 if( text->IsKnockout() )
822 {
823 // Knockout text should only leave holes where the text is, not where the copper fill
824 // around it would be.
825 PCB_TEXT textCopy = *text;
826 textCopy.SetIsKnockout( false );
827 textCopy.TransformShapeToPolygon( aHoles, aLayer, 0, m_maxError, ERROR_OUTSIDE );
828 }
829 else
830 {
831 text->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
832 }
833 }
834
835 break;
836 }
837
838 case PCB_TEXTBOX_T:
839 case PCB_TABLE_T:
840 case PCB_SHAPE_T:
841 case PCB_TARGET_T:
842 aItem->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE,
843 aIgnoreLineWidth );
844 break;
845
847 case PCB_DIM_LEADER_T:
848 case PCB_DIM_CENTER_T:
849 case PCB_DIM_RADIAL_T:
851 {
852 PCB_DIMENSION_BASE* dim = static_cast<PCB_DIMENSION_BASE*>( aItem );
853
854 dim->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE, false );
855 dim->PCB_TEXT::TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE );
856 break;
857 }
858
859 default:
860 break;
861 }
862}
863
864
870 SHAPE_POLY_SET& aFill,
871 std::vector<PAD*>& aThermalConnectionPads,
872 std::vector<PAD*>& aNoConnectionPads )
873{
875 ZONE_CONNECTION connection;
876 DRC_CONSTRAINT constraint;
877 int padClearance;
878 int holeClearance;
879 SHAPE_POLY_SET holes;
880
881 for( FOOTPRINT* footprint : m_board->Footprints() )
882 {
883 for( PAD* pad : footprint->Pads() )
884 {
885 BOX2I padBBox = pad->GetBoundingBox();
886 padBBox.Inflate( m_worstClearance );
887
888 if( !padBBox.Intersects( aZone->GetBoundingBox() ) )
889 continue;
890
891 bool noConnection = pad->GetNetCode() != aZone->GetNetCode();
892
893 if( !aZone->IsTeardropArea() )
894 {
895 if( aZone->GetNetCode() == 0
896 || pad->GetZoneLayerOverride( aLayer ) == ZLO_FORCE_NO_ZONE_CONNECTION )
897 {
898 noConnection = true;
899 }
900 }
901
902 if( noConnection )
903 {
904 // collect these for knockout in buildCopperItemClearances()
905 aNoConnectionPads.push_back( pad );
906 continue;
907 }
908
909 if( aZone->IsTeardropArea() )
910 {
911 connection = ZONE_CONNECTION::FULL;
912 }
913 else
914 {
915 constraint = bds.m_DRCEngine->EvalZoneConnection( pad, aZone, aLayer );
916 connection = constraint.m_ZoneConnection;
917 }
918
919 switch( connection )
920 {
921 case ZONE_CONNECTION::THERMAL:
922 constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone,
923 aLayer );
924 padClearance = constraint.GetValue().Min();
925
926 if( pad->CanFlashLayer( aLayer ) )
927 {
928 aThermalConnectionPads.push_back( pad );
929 addKnockout( pad, aLayer, padClearance, holes );
930 }
931 else if( pad->GetDrillSize().x > 0 )
932 {
933 pad->TransformHoleToPolygon( holes, padClearance, m_maxError, ERROR_OUTSIDE );
934 }
935
936 break;
937
938 case ZONE_CONNECTION::NONE:
939 constraint = bds.m_DRCEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, pad,
940 aZone, aLayer );
941
942 if( constraint.GetValue().Min() > aZone->GetLocalClearance().value() )
943 padClearance = constraint.GetValue().Min();
944 else
945 padClearance = aZone->GetLocalClearance().value();
946
947 if( pad->FlashLayer( aLayer ) )
948 {
949 addKnockout( pad, aLayer, padClearance, holes );
950 }
951 else if( pad->GetDrillSize().x > 0 )
952 {
953 constraint = bds.m_DRCEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
954 pad, aZone, aLayer );
955
956 if( constraint.GetValue().Min() > padClearance )
957 holeClearance = constraint.GetValue().Min();
958 else
959 holeClearance = padClearance;
960
961 pad->TransformHoleToPolygon( holes, holeClearance, m_maxError, ERROR_OUTSIDE );
962 }
963
964 break;
965
966 default:
967 // No knockout
968 continue;
969 }
970 }
971 }
972
974}
975
976
982 const std::vector<PAD*>& aNoConnectionPads,
983 SHAPE_POLY_SET& aHoles )
984{
986 long ticker = 0;
987
988 auto checkForCancel =
989 [&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
990 {
991 return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
992 };
993
994 // A small extra clearance to be sure actual track clearances are not smaller than
995 // requested clearance due to many approximations in calculations, like arc to segment
996 // approx, rounding issues, etc.
997 BOX2I zone_boundingbox = aZone->GetBoundingBox();
999
1000 // Items outside the zone bounding box are skipped, so it needs to be inflated by the
1001 // largest clearance value found in the netclasses and rules
1002 zone_boundingbox.Inflate( m_worstClearance + extra_margin );
1003
1004 auto evalRulesForItems =
1005 [&bds]( DRC_CONSTRAINT_T aConstraint, const BOARD_ITEM* a, const BOARD_ITEM* b,
1006 PCB_LAYER_ID aEvalLayer ) -> int
1007 {
1008 DRC_CONSTRAINT c = bds.m_DRCEngine->EvalRules( aConstraint, a, b, aEvalLayer );
1009
1010 if( c.IsNull() )
1011 return -1;
1012 else
1013 return c.GetValue().Min();
1014 };
1015
1016 // Add non-connected pad clearances
1017 //
1018 auto knockoutPadClearance =
1019 [&]( PAD* aPad )
1020 {
1021 int init_gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone, aPad, aLayer );
1022 int gap = init_gap;
1023 bool hasHole = aPad->GetDrillSize().x > 0;
1024 bool flashLayer = aPad->FlashLayer( aLayer );
1025 bool platedHole = hasHole && aPad->GetAttribute() == PAD_ATTRIB::PTH;
1026
1027 if( flashLayer || platedHole )
1028 {
1029 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1030 aZone, aPad, aLayer ) );
1031 }
1032
1033 if( flashLayer && gap >= 0 )
1034 addKnockout( aPad, aLayer, gap + extra_margin, aHoles );
1035
1036 if( hasHole )
1037 {
1038 // NPTH do not need copper clearance gaps to their holes
1039 if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
1040 gap = init_gap;
1041
1042 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
1043 aZone, aPad, aLayer ) );
1044
1045 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
1046 aZone, aPad, aLayer ) );
1047
1048 if( gap >= 0 )
1049 addHoleKnockout( aPad, gap + extra_margin, aHoles );
1050 }
1051 };
1052
1053 for( PAD* pad : aNoConnectionPads )
1054 {
1055 if( checkForCancel( m_progressReporter ) )
1056 return;
1057
1058 knockoutPadClearance( pad );
1059 }
1060
1061 // Add non-connected track clearances
1062 //
1063 auto knockoutTrackClearance =
1064 [&]( PCB_TRACK* aTrack )
1065 {
1066 if( aTrack->GetBoundingBox().Intersects( zone_boundingbox ) )
1067 {
1068 bool sameNet = aTrack->GetNetCode() == aZone->GetNetCode();
1069
1070 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1071 sameNet = false;
1072
1073 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
1074 aZone, aTrack, aLayer );
1075
1076 if( aTrack->Type() == PCB_VIA_T )
1077 {
1078 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
1079
1080 if( via->GetZoneLayerOverride( aLayer ) == ZLO_FORCE_NO_ZONE_CONNECTION )
1081 sameNet = false;
1082 }
1083
1084 if( !sameNet )
1085 {
1086 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1087 aZone, aTrack, aLayer ) );
1088 }
1089
1090 if( aTrack->Type() == PCB_VIA_T )
1091 {
1092 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
1093
1094 if( via->FlashLayer( aLayer ) && gap > 0 )
1095 {
1096 via->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
1098 }
1099
1100 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
1101 aZone, via, aLayer ) );
1102
1103 if( !sameNet )
1104 {
1105 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
1106 aZone, via, aLayer ) );
1107 }
1108
1109 if( gap >= 0 )
1110 {
1111 int radius = via->GetDrillValue() / 2;
1112
1113 TransformCircleToPolygon( aHoles, via->GetPosition(),
1114 radius + gap + extra_margin,
1116 }
1117 }
1118 else
1119 {
1120 if( gap >= 0 )
1121 {
1122 aTrack->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
1124 }
1125 }
1126 }
1127 };
1128
1129 for( PCB_TRACK* track : m_board->Tracks() )
1130 {
1131 if( !track->IsOnLayer( aLayer ) )
1132 continue;
1133
1134 if( checkForCancel( m_progressReporter ) )
1135 return;
1136
1137 knockoutTrackClearance( track );
1138 }
1139
1140 // Add graphic item clearances.
1141 //
1142 auto knockoutGraphicClearance =
1143 [&]( BOARD_ITEM* aItem )
1144 {
1145 int shapeNet = -1;
1146
1147 if( aItem->Type() == PCB_SHAPE_T )
1148 shapeNet = static_cast<PCB_SHAPE*>( aItem )->GetNetCode();
1149
1150 bool sameNet = shapeNet == aZone->GetNetCode();
1151
1152 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1153 sameNet = false;
1154
1155 // A item on the Edge_Cuts or Margin is always seen as on any layer:
1156 if( aItem->IsOnLayer( aLayer )
1157 || aItem->IsOnLayer( Edge_Cuts )
1158 || aItem->IsOnLayer( Margin ) )
1159 {
1160 if( aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
1161 {
1162 bool ignoreLineWidths = false;
1163 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
1164 aZone, aItem, aLayer );
1165
1166 if( aItem->IsOnLayer( aLayer ) && !sameNet )
1167 {
1168 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1169 aZone, aItem, aLayer ) );
1170 }
1171 else if( aItem->IsOnLayer( Edge_Cuts ) )
1172 {
1173 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
1174 aZone, aItem, aLayer ) );
1175 ignoreLineWidths = true;
1176 }
1177 else if( aItem->IsOnLayer( Margin ) )
1178 {
1179 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
1180 aZone, aItem, aLayer ) );
1181 }
1182
1183 if( gap >= 0 )
1184 {
1185 gap += extra_margin;
1186 addKnockout( aItem, aLayer, gap, ignoreLineWidths, aHoles );
1187 }
1188 }
1189 }
1190 };
1191
1192 auto knockoutCourtyardClearance =
1193 [&]( FOOTPRINT* aFootprint )
1194 {
1195 if( aFootprint->GetBoundingBox().Intersects( zone_boundingbox ) )
1196 {
1197 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone,
1198 aFootprint, aLayer );
1199
1200 if( gap == 0 )
1201 {
1202 aHoles.Append( aFootprint->GetCourtyard( aLayer ) );
1203 }
1204 else if( gap > 0 )
1205 {
1206 SHAPE_POLY_SET hole = aFootprint->GetCourtyard( aLayer );
1207 hole.Inflate( gap, CORNER_STRATEGY::ROUND_ALL_CORNERS, m_maxError );
1208 aHoles.Append( hole );
1209 }
1210 }
1211 };
1212
1213 for( FOOTPRINT* footprint : m_board->Footprints() )
1214 {
1215 knockoutCourtyardClearance( footprint );
1216 knockoutGraphicClearance( &footprint->Reference() );
1217 knockoutGraphicClearance( &footprint->Value() );
1218
1219 std::set<PAD*> allowedNetTiePads;
1220
1221 // Don't knock out holes for graphic items which implement a net-tie to the zone's net
1222 // on the layer being filled.
1223 if( footprint->IsNetTie() )
1224 {
1225 for( PAD* pad : footprint->Pads() )
1226 {
1227 bool sameNet = pad->GetNetCode() == aZone->GetNetCode();
1228
1229 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1230 sameNet = false;
1231
1232 if( sameNet )
1233 {
1234 if( pad->IsOnLayer( aLayer ) )
1235 allowedNetTiePads.insert( pad );
1236
1237 for( PAD* other : footprint->GetNetTiePads( pad ) )
1238 {
1239 if( other->IsOnLayer( aLayer ) )
1240 allowedNetTiePads.insert( other );
1241 }
1242 }
1243 }
1244 }
1245
1246 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1247 {
1248 if( checkForCancel( m_progressReporter ) )
1249 return;
1250
1251 BOX2I itemBBox = item->GetBoundingBox();
1252
1253 if( !zone_boundingbox.Intersects( itemBBox ) )
1254 continue;
1255
1256 bool skipItem = false;
1257
1258 if( item->IsOnLayer( aLayer ) )
1259 {
1260 std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape();
1261
1262 for( PAD* pad : allowedNetTiePads )
1263 {
1264 if( pad->GetBoundingBox().Intersects( itemBBox )
1265 && pad->GetEffectiveShape()->Collide( itemShape.get() ) )
1266 {
1267 skipItem = true;
1268 break;
1269 }
1270 }
1271 }
1272
1273 if( !skipItem )
1274 knockoutGraphicClearance( item );
1275 }
1276 }
1277
1278 for( BOARD_ITEM* item : m_board->Drawings() )
1279 {
1280 if( checkForCancel( m_progressReporter ) )
1281 return;
1282
1283 knockoutGraphicClearance( item );
1284 }
1285
1286 // Add non-connected zone clearances
1287 //
1288 auto knockoutZoneClearance =
1289 [&]( ZONE* aKnockout )
1290 {
1291 // If the zones share no common layers
1292 if( !aKnockout->GetLayerSet().test( aLayer ) )
1293 return;
1294
1295 if( aKnockout->GetBoundingBox().Intersects( zone_boundingbox ) )
1296 {
1297 if( aKnockout->GetIsRuleArea() )
1298 {
1299 // Keepouts use outline with no clearance
1300 aKnockout->TransformSmoothedOutlineToPolygon( aHoles, 0, m_maxError,
1301 ERROR_OUTSIDE, nullptr );
1302 }
1303 else
1304 {
1305 int gap = std::max( 0, evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
1306 aZone, aKnockout, aLayer ) );
1307
1308 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1309 aZone, aKnockout, aLayer ) );
1310
1311 SHAPE_POLY_SET poly;
1312 aKnockout->TransformShapeToPolygon( poly, aLayer, gap + extra_margin,
1314 aHoles.Append( poly );
1315 }
1316 }
1317 };
1318
1319 for( ZONE* otherZone : m_board->Zones() )
1320 {
1321 if( checkForCancel( m_progressReporter ) )
1322 return;
1323
1324 // Negative clearance permits zones to short
1325 if( evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, otherZone, aLayer ) < 0 )
1326 continue;
1327
1328 if( otherZone->GetIsRuleArea() )
1329 {
1330 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1331 knockoutZoneClearance( otherZone );
1332 }
1333 else if( otherZone->HigherPriority( aZone ) )
1334 {
1335 if( !otherZone->SameNet( aZone ) )
1336 knockoutZoneClearance( otherZone );
1337 }
1338 }
1339
1340 for( FOOTPRINT* footprint : m_board->Footprints() )
1341 {
1342 for( ZONE* otherZone : footprint->Zones() )
1343 {
1344 if( checkForCancel( m_progressReporter ) )
1345 return;
1346
1347 if( otherZone->GetIsRuleArea() )
1348 {
1349 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1350 knockoutZoneClearance( otherZone );
1351 }
1352 else if( otherZone->HigherPriority( aZone ) )
1353 {
1354 if( !otherZone->SameNet( aZone ) )
1355 knockoutZoneClearance( otherZone );
1356 }
1357 }
1358 }
1359
1361}
1362
1363
1369 SHAPE_POLY_SET& aRawFill )
1370{
1371 BOX2I zoneBBox = aZone->GetBoundingBox();
1372
1373 auto knockoutZoneOutline =
1374 [&]( ZONE* aKnockout )
1375 {
1376 // If the zones share no common layers
1377 if( !aKnockout->GetLayerSet().test( aLayer ) )
1378 return;
1379
1380 if( aKnockout->GetBoundingBox().Intersects( zoneBBox ) )
1381 {
1382 // Processing of arc shapes in zones is not yet supported because Clipper
1383 // can't do boolean operations on them. The poly outline must be converted to
1384 // segments first.
1385 SHAPE_POLY_SET outline = aKnockout->Outline()->CloneDropTriangulation();
1386 outline.ClearArcs();
1387
1388 aRawFill.BooleanSubtract( outline, SHAPE_POLY_SET::PM_FAST );
1389 }
1390 };
1391
1392 for( ZONE* otherZone : m_board->Zones() )
1393 {
1394 // Don't use the `HigherPriority()` check here because we _only_ want to knock out zones
1395 // with explicitly higher priorities, not those with equal priorities
1396 if( otherZone->SameNet( aZone )
1397 && otherZone->GetAssignedPriority() > aZone->GetAssignedPriority() )
1398 {
1399 // Do not remove teardrop area: it is not useful and not good
1400 if( !otherZone->IsTeardropArea() )
1401 knockoutZoneOutline( otherZone );
1402 }
1403 }
1404
1405 for( FOOTPRINT* footprint : m_board->Footprints() )
1406 {
1407 for( ZONE* otherZone : footprint->Zones() )
1408 {
1409 if( otherZone->SameNet( aZone ) && otherZone->HigherPriority( aZone ) )
1410 {
1411 // Do not remove teardrop area: it is not useful and not good
1412 if( !otherZone->IsTeardropArea() )
1413 knockoutZoneOutline( otherZone );
1414 }
1415 }
1416 }
1417}
1418
1419
1420#define DUMP_POLYS_TO_COPPER_LAYER( a, b, c ) \
1421 { if( m_debugZoneFiller && aDebugLayer == b ) \
1422 { \
1423 m_board->SetLayerName( b, c ); \
1424 SHAPE_POLY_SET d = a; \
1425 d.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); \
1426 aFillPolys = d; \
1427 return false; \
1428 } \
1429 }
1430
1431
1443bool ZONE_FILLER::fillCopperZone( const ZONE* aZone, PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer,
1444 const SHAPE_POLY_SET& aSmoothedOutline,
1445 const SHAPE_POLY_SET& aMaxExtents, SHAPE_POLY_SET& aFillPolys )
1446{
1448
1449 // Features which are min_width should survive pruning; features that are *less* than
1450 // min_width should not. Therefore we subtract epsilon from the min_width when
1451 // deflating/inflating.
1452 int half_min_width = aZone->GetMinThickness() / 2;
1453 int epsilon = pcbIUScale.mmToIU( 0.001 );
1454
1455 // Solid polygons are deflated and inflated during calculations. Deflating doesn't cause
1456 // issues, but inflate is tricky as it can create excessively long and narrow spikes for
1457 // acute angles.
1458 // ALLOW_ACUTE_CORNERS cannot be used due to the spike problem.
1459 // CHAMFER_ACUTE_CORNERS is tempting, but can still produce spikes in some unusual
1460 // circumstances (https://gitlab.com/kicad/code/kicad/-/issues/5581).
1461 // It's unclear if ROUND_ACUTE_CORNERS would have the same issues, but is currently avoided
1462 // as a "less-safe" option.
1463 // ROUND_ALL_CORNERS produces the uniformly nicest shapes, but also a lot of segments.
1464 // CHAMFER_ALL_CORNERS improves the segment count.
1465 CORNER_STRATEGY fastCornerStrategy = CORNER_STRATEGY::CHAMFER_ALL_CORNERS;
1466 CORNER_STRATEGY cornerStrategy = CORNER_STRATEGY::ROUND_ALL_CORNERS;
1467
1468 std::vector<PAD*> thermalConnectionPads;
1469 std::vector<PAD*> noConnectionPads;
1470 std::deque<SHAPE_LINE_CHAIN> thermalSpokes;
1471 SHAPE_POLY_SET clearanceHoles;
1472
1473 aFillPolys = aSmoothedOutline;
1474 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In1_Cu, wxT( "smoothed-outline" ) );
1475
1477 return false;
1478
1479 /* -------------------------------------------------------------------------------------
1480 * Knockout thermal reliefs.
1481 */
1482
1483 knockoutThermalReliefs( aZone, aLayer, aFillPolys, thermalConnectionPads, noConnectionPads );
1484 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In2_Cu, wxT( "minus-thermal-reliefs" ) );
1485
1487 return false;
1488
1489 /* -------------------------------------------------------------------------------------
1490 * Knockout electrical clearances.
1491 */
1492
1493 buildCopperItemClearances( aZone, aLayer, noConnectionPads, clearanceHoles );
1494 DUMP_POLYS_TO_COPPER_LAYER( clearanceHoles, In3_Cu, wxT( "clearance-holes" ) );
1495
1497 return false;
1498
1499 /* -------------------------------------------------------------------------------------
1500 * Add thermal relief spokes.
1501 */
1502
1503 buildThermalSpokes( aZone, aLayer, thermalConnectionPads, thermalSpokes );
1504
1506 return false;
1507
1508 // Create a temporary zone that we can hit-test spoke-ends against. It's only temporary
1509 // because the "real" subtract-clearance-holes has to be done after the spokes are added.
1510 static const bool USE_BBOX_CACHES = true;
1511 SHAPE_POLY_SET testAreas = aFillPolys.CloneDropTriangulation();
1512 testAreas.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1513 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In4_Cu, wxT( "minus-clearance-holes" ) );
1514
1515 // Prune features that don't meet minimum-width criteria
1516 if( half_min_width - epsilon > epsilon )
1517 {
1518 testAreas.Deflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1519 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In5_Cu, wxT( "spoke-test-deflated" ) );
1520
1521 testAreas.Inflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1522 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In6_Cu, wxT( "spoke-test-reinflated" ) );
1523 }
1524
1526 return false;
1527
1528 // Spoke-end-testing is hugely expensive so we generate cached bounding-boxes to speed
1529 // things up a bit.
1530 testAreas.BuildBBoxCaches();
1531 int interval = 0;
1532
1533 SHAPE_POLY_SET debugSpokes;
1534
1535 for( const SHAPE_LINE_CHAIN& spoke : thermalSpokes )
1536 {
1537 const VECTOR2I& testPt = spoke.CPoint( 3 );
1538
1539 // Hit-test against zone body
1540 if( testAreas.Contains( testPt, -1, 1, USE_BBOX_CACHES ) )
1541 {
1542 if( m_debugZoneFiller )
1543 debugSpokes.AddOutline( spoke );
1544
1545 aFillPolys.AddOutline( spoke );
1546 continue;
1547 }
1548
1549 if( interval++ > 400 )
1550 {
1552 return false;
1553
1554 interval = 0;
1555 }
1556
1557 // Hit-test against other spokes
1558 for( const SHAPE_LINE_CHAIN& other : thermalSpokes )
1559 {
1560 // Hit test in both directions to avoid interactions with round-off errors.
1561 // (See https://gitlab.com/kicad/code/kicad/-/issues/13316.)
1562 if( &other != &spoke
1563 && other.PointInside( testPt, 1, USE_BBOX_CACHES )
1564 && spoke.PointInside( other.CPoint( 3 ), 1, USE_BBOX_CACHES ) )
1565 {
1566 if( m_debugZoneFiller )
1567 debugSpokes.AddOutline( spoke );
1568
1569 aFillPolys.AddOutline( spoke );
1570 break;
1571 }
1572 }
1573 }
1574
1575 DUMP_POLYS_TO_COPPER_LAYER( debugSpokes, In7_Cu, wxT( "spokes" ) );
1576
1578 return false;
1579
1580 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1581 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In8_Cu, wxT( "after-spoke-trimming" ) );
1582
1583 /* -------------------------------------------------------------------------------------
1584 * Prune features that don't meet minimum-width criteria
1585 */
1586
1587 if( half_min_width - epsilon > epsilon )
1588 aFillPolys.Deflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1589
1590 // Min-thickness is the web thickness. On the other hand, a blob min-thickness by
1591 // min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
1592 // arbitrarily choose "at least 2X min-thickness on one axis". (Since we're doing this
1593 // during the deflated state, that means we test for "at least min-thickness".)
1594 for( int ii = aFillPolys.OutlineCount() - 1; ii >= 0; ii-- )
1595 {
1596 std::vector<SHAPE_LINE_CHAIN>& island = aFillPolys.Polygon( ii );
1597 BOX2I islandExtents;
1598
1599 for( const VECTOR2I& pt : island.front().CPoints() )
1600 {
1601 islandExtents.Merge( pt );
1602
1603 if( islandExtents.GetSizeMax() > aZone->GetMinThickness() )
1604 break;
1605 }
1606
1607 if( islandExtents.GetSizeMax() < aZone->GetMinThickness() )
1608 aFillPolys.DeletePolygon( ii );
1609 }
1610
1611 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In9_Cu, wxT( "deflated" ) );
1612
1614 return false;
1615
1616 /* -------------------------------------------------------------------------------------
1617 * Process the hatch pattern (note that we do this while deflated)
1618 */
1619
1620 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1621 {
1622 if( !addHatchFillTypeOnZone( aZone, aLayer, aDebugLayer, aFillPolys ) )
1623 return false;
1624 }
1625
1627 return false;
1628
1629 /* -------------------------------------------------------------------------------------
1630 * Finish minimum-width pruning by re-inflating
1631 */
1632
1633 if( half_min_width - epsilon > epsilon )
1634 aFillPolys.Inflate( half_min_width - epsilon, cornerStrategy, m_maxError, true );
1635
1636 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In15_Cu, wxT( "after-reinflating" ) );
1637
1638 /* -------------------------------------------------------------------------------------
1639 * Ensure additive changes (thermal stubs and inflating acute corners) do not add copper
1640 * outside the zone boundary, inside the clearance holes, or between otherwise isolated
1641 * islands
1642 */
1643
1644 for( PAD* pad : thermalConnectionPads )
1645 addHoleKnockout( pad, 0, clearanceHoles );
1646
1647 aFillPolys.BooleanIntersection( aMaxExtents, SHAPE_POLY_SET::PM_FAST );
1648 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In16_Cu, wxT( "after-trim-to-outline" ) );
1649 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1650 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In17_Cu, wxT( "after-trim-to-clearance-holes" ) );
1651
1652 /* -------------------------------------------------------------------------------------
1653 * Lastly give any same-net but higher-priority zones control over their own area.
1654 */
1655
1656 subtractHigherPriorityZones( aZone, aLayer, aFillPolys );
1657 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In18_Cu, wxT( "minus-higher-priority-zones" ) );
1658
1659 aFillPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
1660 return true;
1661}
1662
1663
1665 const SHAPE_POLY_SET& aSmoothedOutline,
1666 SHAPE_POLY_SET& aFillPolys )
1667{
1669 BOX2I zone_boundingbox = aZone->GetBoundingBox();
1670 SHAPE_POLY_SET clearanceHoles;
1671 long ticker = 0;
1672
1673 auto checkForCancel =
1674 [&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
1675 {
1676 return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
1677 };
1678
1679 auto knockoutGraphicClearance =
1680 [&]( BOARD_ITEM* aItem )
1681 {
1682 if( aItem->IsKnockout() && aItem->IsOnLayer( aLayer )
1683 && aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
1684 {
1686 aZone, aItem, aLayer );
1687
1688 addKnockout( aItem, aLayer, cc.GetValue().Min(), false, clearanceHoles );
1689 }
1690 };
1691
1692 for( FOOTPRINT* footprint : m_board->Footprints() )
1693 {
1694 if( checkForCancel( m_progressReporter ) )
1695 return false;
1696
1697 knockoutGraphicClearance( &footprint->Reference() );
1698 knockoutGraphicClearance( &footprint->Value() );
1699
1700 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1701 knockoutGraphicClearance( item );
1702 }
1703
1704 for( BOARD_ITEM* item : m_board->Drawings() )
1705 {
1706 if( checkForCancel( m_progressReporter ) )
1707 return false;
1708
1709 knockoutGraphicClearance( item );
1710 }
1711
1712 aFillPolys = aSmoothedOutline;
1713 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1714
1715 for( ZONE* keepout : m_board->Zones() )
1716 {
1717 if( !keepout->GetIsRuleArea() )
1718 continue;
1719
1720 if( keepout->GetDoNotAllowCopperPour() && keepout->IsOnLayer( aLayer ) )
1721 {
1722 if( keepout->GetBoundingBox().Intersects( zone_boundingbox ) )
1723 aFillPolys.BooleanSubtract( *keepout->Outline(), SHAPE_POLY_SET::PM_FAST );
1724 }
1725 }
1726
1727 // Features which are min_width should survive pruning; features that are *less* than
1728 // min_width should not. Therefore we subtract epsilon from the min_width when
1729 // deflating/inflating.
1730 int half_min_width = aZone->GetMinThickness() / 2;
1731 int epsilon = pcbIUScale.mmToIU( 0.001 );
1732
1733 aFillPolys.Deflate( half_min_width - epsilon, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, m_maxError );
1734
1735 // Remove the non filled areas due to the hatch pattern
1736 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1737 {
1738 if( !addHatchFillTypeOnZone( aZone, aLayer, aLayer, aFillPolys ) )
1739 return false;
1740 }
1741
1742 // Re-inflate after pruning of areas that don't meet minimum-width criteria
1743 if( half_min_width - epsilon > epsilon )
1744 aFillPolys.Inflate( half_min_width - epsilon, CORNER_STRATEGY::ROUND_ALL_CORNERS, m_maxError );
1745
1747 return true;
1748}
1749
1750
1751/*
1752 * Build the filled solid areas data from real outlines (stored in m_Poly)
1753 * The solid areas can be more than one on copper layers, and do not have holes
1754 * ( holes are linked by overlapping segments to the main outline)
1755 */
1757{
1758 SHAPE_POLY_SET* boardOutline = m_brdOutlinesValid ? &m_boardOutline : nullptr;
1759 SHAPE_POLY_SET maxExtents;
1760 SHAPE_POLY_SET smoothedPoly;
1761 PCB_LAYER_ID debugLayer = UNDEFINED_LAYER;
1762
1763 if( m_debugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
1764 {
1765 debugLayer = aLayer;
1766 aLayer = F_Cu;
1767 }
1768
1769 if( !aZone->BuildSmoothedPoly( maxExtents, aLayer, boardOutline, &smoothedPoly ) )
1770 return false;
1771
1773 return false;
1774
1775 if( aZone->IsOnCopperLayer() )
1776 {
1777 if( fillCopperZone( aZone, aLayer, debugLayer, smoothedPoly, maxExtents, aFillPolys ) )
1778 aZone->SetNeedRefill( false );
1779 }
1780 else
1781 {
1782 if( fillNonCopperZone( aZone, aLayer, smoothedPoly, aFillPolys ) )
1783 aZone->SetNeedRefill( false );
1784 }
1785
1786 return true;
1787}
1788
1789
1794 const std::vector<PAD*>& aSpokedPadsList,
1795 std::deque<SHAPE_LINE_CHAIN>& aSpokesList )
1796{
1798 BOX2I zoneBB = aZone->GetBoundingBox();
1799 DRC_CONSTRAINT constraint;
1800
1801 zoneBB.Inflate( std::max( bds.GetBiggestClearanceValue(), aZone->GetLocalClearance().value() ) );
1802
1803 // Is a point on the boundary of the polygon inside or outside? The boundary may be off by
1804 // MaxError, and we add 1.5 mil for some wiggle room.
1805 int epsilon = KiROUND( bds.m_MaxError + pcbIUScale.IU_PER_MM * 0.038 ); // 1.5 mil
1806
1807 for( PAD* pad : aSpokedPadsList )
1808 {
1809 // We currently only connect to pads, not pad holes
1810 if( !pad->IsOnLayer( aLayer ) )
1811 continue;
1812
1813 constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone, aLayer );
1814 int thermalReliefGap = constraint.GetValue().Min();
1815
1816 constraint = bds.m_DRCEngine->EvalRules( THERMAL_SPOKE_WIDTH_CONSTRAINT, pad, aZone, aLayer );
1817 int spoke_w = constraint.GetValue().Opt();
1818
1819 // Spoke width should ideally be smaller than the pad minor axis.
1820 // Otherwise the thermal shape is not really a thermal relief,
1821 // and the algo to count the actual number of spokes can fail
1822 int spoke_max_allowed_w = std::min( pad->GetSize().x, pad->GetSize().y );
1823
1824 spoke_w = std::max( spoke_w, constraint.Value().Min() );
1825 spoke_w = std::min( spoke_w, constraint.Value().Max() );
1826
1827 // ensure the spoke width is smaller than the pad minor size
1828 spoke_w = std::min( spoke_w, spoke_max_allowed_w );
1829
1830 // Cannot create stubs having a width < zone min thickness
1831 if( spoke_w < aZone->GetMinThickness() )
1832 continue;
1833
1834 int spoke_half_w = spoke_w / 2;
1835
1836 // Quick test here to possibly save us some work
1837 BOX2I itemBB = pad->GetBoundingBox();
1838 itemBB.Inflate( thermalReliefGap + epsilon );
1839
1840 if( !( itemBB.Intersects( zoneBB ) ) )
1841 continue;
1842
1843 bool customSpokes = false;
1844
1845 if( pad->GetShape() == PAD_SHAPE::CUSTOM )
1846 {
1847 for( const std::shared_ptr<PCB_SHAPE>& primitive : pad->GetPrimitives() )
1848 {
1849 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::SEGMENT )
1850 {
1851 customSpokes = true;
1852 break;
1853 }
1854 }
1855 }
1856
1857 // Thermal spokes consist of square-ended segments from the pad center to points just
1858 // outside the thermal relief. The outside end has an extra center point (which must be
1859 // at idx 3) which is used for testing whether or not the spoke connects to copper in the
1860 // parent zone.
1861
1862 auto buildSpokesFromOrigin =
1863 [&]( const BOX2I& box )
1864 {
1865 for( int i = 0; i < 4; i++ )
1866 {
1867 SHAPE_LINE_CHAIN spoke;
1868
1869 switch( i )
1870 {
1871 case 0: // lower stub
1872 spoke.Append( +spoke_half_w, -spoke_half_w );
1873 spoke.Append( -spoke_half_w, -spoke_half_w );
1874 spoke.Append( -spoke_half_w, box.GetBottom() );
1875 spoke.Append( 0, box.GetBottom() ); // test pt
1876 spoke.Append( +spoke_half_w, box.GetBottom() );
1877 break;
1878
1879 case 1: // upper stub
1880 spoke.Append( +spoke_half_w, +spoke_half_w );
1881 spoke.Append( -spoke_half_w, +spoke_half_w );
1882 spoke.Append( -spoke_half_w, box.GetTop() );
1883 spoke.Append( 0, box.GetTop() ); // test pt
1884 spoke.Append( +spoke_half_w, box.GetTop() );
1885 break;
1886
1887 case 2: // right stub
1888 spoke.Append( -spoke_half_w, +spoke_half_w );
1889 spoke.Append( -spoke_half_w, -spoke_half_w );
1890 spoke.Append( box.GetRight(), -spoke_half_w );
1891 spoke.Append( box.GetRight(), 0 ); // test pt
1892 spoke.Append( box.GetRight(), +spoke_half_w );
1893 break;
1894
1895 case 3: // left stub
1896 spoke.Append( +spoke_half_w, +spoke_half_w );
1897 spoke.Append( +spoke_half_w, -spoke_half_w );
1898 spoke.Append( box.GetLeft(), -spoke_half_w );
1899 spoke.Append( box.GetLeft(), 0 ); // test pt
1900 spoke.Append( box.GetLeft(), +spoke_half_w );
1901 break;
1902 }
1903
1904 spoke.SetClosed( true );
1905 aSpokesList.push_back( std::move( spoke ) );
1906 }
1907 };
1908
1909 if( customSpokes )
1910 {
1911 SHAPE_POLY_SET thermalPoly;
1912 SHAPE_LINE_CHAIN thermalOutline;
1913
1914 pad->TransformShapeToPolygon( thermalPoly, aLayer, thermalReliefGap + epsilon,
1916
1917 if( thermalPoly.OutlineCount() )
1918 thermalOutline = thermalPoly.Outline( 0 );
1919
1920 for( const std::shared_ptr<PCB_SHAPE>& primitive : pad->GetPrimitives() )
1921 {
1922 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::SEGMENT )
1923 {
1924 SEG seg( primitive->GetStart(), primitive->GetEnd() );
1925 SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
1926
1927 RotatePoint( seg.A, pad->GetOrientation() );
1928 RotatePoint( seg.B, pad->GetOrientation() );
1929 seg.A += pad->ShapePos();
1930 seg.B += pad->ShapePos();
1931
1932 // Make sure seg.A is the origin
1933 if( !pad->GetEffectivePolygon( ERROR_OUTSIDE )->Contains( seg.A ) )
1934 seg.Reverse();
1935
1936 // Trim seg.B to the thermal outline
1937 if( thermalOutline.Intersect( seg, intersections ) )
1938 {
1939 seg.B = intersections.front().p;
1940
1941 VECTOR2I offset = ( seg.B - seg.A ).Perpendicular().Resize( spoke_half_w );
1942 SHAPE_LINE_CHAIN spoke;
1943
1944 spoke.Append( seg.A + offset );
1945 spoke.Append( seg.A - offset );
1946 spoke.Append( seg.B - offset );
1947 spoke.Append( seg.B ); // test pt
1948 spoke.Append( seg.B + offset );
1949
1950 spoke.SetClosed( true );
1951 aSpokesList.push_back( std::move( spoke ) );
1952 }
1953 }
1954 }
1955 }
1956 // If the spokes are at a cardinal angle then we can generate them from a bounding box
1957 // without trig.
1958 else if( ( pad->GetOrientation() + pad->GetThermalSpokeAngle() ).IsCardinal() )
1959 {
1960 BOX2I spokesBox = pad->GetBoundingBox();
1961 spokesBox.Inflate( thermalReliefGap + epsilon );
1962
1963 // Spokes are from center of pad shape, not from hole.
1964 spokesBox.Offset( - pad->ShapePos() );
1965
1966 buildSpokesFromOrigin( spokesBox );
1967
1968 auto spokeIter = aSpokesList.rbegin();
1969
1970 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1971 spokeIter->Move( pad->ShapePos() );
1972 }
1973 // Even if the spokes are rotated, we can fudge it for round and square pads by rotating
1974 // the bounding box to match the spokes.
1975 else if( pad->GetSizeX() == pad->GetSizeY() && pad->GetShape() != PAD_SHAPE::CUSTOM )
1976 {
1977 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
1978 // from dirtying the real pad's cached shapes.
1979 PAD dummy_pad( *pad );
1980 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
1981
1982 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
1983 // offset and is at position 0,0
1984 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
1985 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
1986
1987 BOX2I spokesBox = dummy_pad.GetBoundingBox();
1988 spokesBox.Inflate( thermalReliefGap + epsilon );
1989
1990 buildSpokesFromOrigin( spokesBox );
1991
1992 auto spokeIter = aSpokesList.rbegin();
1993
1994 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1995 {
1996 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
1997 spokeIter->Move( pad->ShapePos() );
1998 }
1999
2000 // Remove group membership from dummy item before deleting
2001 dummy_pad.SetParentGroup( nullptr );
2002 }
2003 // And lastly, even when we have to resort to trig, we can use it only in a post-process
2004 // after the rotated-bounding-box trick from above.
2005 else
2006 {
2007 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
2008 // from dirtying the real pad's cached shapes.
2009 PAD dummy_pad( *pad );
2010 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
2011
2012 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
2013 // offset and is at position 0,0
2014 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
2015 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
2016
2017 BOX2I spokesBox = dummy_pad.GetBoundingBox();
2018
2019 // In this case make the box -big-; we're going to clip to the "real" bbox later.
2020 spokesBox.Inflate( thermalReliefGap + spokesBox.GetWidth() + spokesBox.GetHeight() );
2021
2022 buildSpokesFromOrigin( spokesBox );
2023
2024 BOX2I realBBox = pad->GetBoundingBox();
2025 realBBox.Inflate( thermalReliefGap + epsilon );
2026
2027 auto spokeIter = aSpokesList.rbegin();
2028
2029 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
2030 {
2031 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
2032 spokeIter->Move( pad->ShapePos() );
2033
2034 VECTOR2I origin_p = spokeIter->GetPoint( 0 );
2035 VECTOR2I origin_m = spokeIter->GetPoint( 1 );
2036 VECTOR2I origin = ( origin_p + origin_m ) / 2;
2037 VECTOR2I end_m = spokeIter->GetPoint( 2 );
2038 VECTOR2I end = spokeIter->GetPoint( 3 );
2039 VECTOR2I end_p = spokeIter->GetPoint( 4 );
2040
2041 ClipLine( &realBBox, origin_p.x, origin_p.y, end_p.x, end_p.y );
2042 ClipLine( &realBBox, origin_m.x, origin_m.y, end_m.x, end_m.y );
2043 ClipLine( &realBBox, origin.x, origin.y, end.x, end.y );
2044
2045 spokeIter->SetPoint( 2, end_m );
2046 spokeIter->SetPoint( 3, end );
2047 spokeIter->SetPoint( 4, end_p );
2048 }
2049
2050 // Remove group membership from dummy item before deleting
2051 dummy_pad.SetParentGroup( nullptr );
2052 }
2053 }
2054
2055 for( size_t ii = 0; ii < aSpokesList.size(); ++ii )
2056 aSpokesList[ii].GenerateBBoxCache();
2057}
2058
2059
2061 PCB_LAYER_ID aDebugLayer, SHAPE_POLY_SET& aFillPolys )
2062{
2063 // Build grid:
2064
2065 // obviously line thickness must be > zone min thickness.
2066 // It can happens if a board file was edited by hand by a python script
2067 // Use 1 micron margin to be *sure* there is no issue in Gerber files
2068 // (Gbr file unit = 1 or 10 nm) due to some truncation in coordinates or calculations
2069 // This margin also avoid problems due to rounding coordinates in next calculations
2070 // that can create incorrect polygons
2071 int thickness = std::max( aZone->GetHatchThickness(),
2072 aZone->GetMinThickness() + pcbIUScale.mmToIU( 0.001 ) );
2073
2074 int linethickness = thickness - aZone->GetMinThickness();
2075 int gridsize = thickness + aZone->GetHatchGap();
2076 int maxError = m_board->GetDesignSettings().m_MaxError;
2077
2078 SHAPE_POLY_SET filledPolys = aFillPolys.CloneDropTriangulation();
2079 // Use a area that contains the rotated bbox by orientation, and after rotate the result
2080 // by -orientation.
2081 if( !aZone->GetHatchOrientation().IsZero() )
2082 filledPolys.Rotate( - aZone->GetHatchOrientation() );
2083
2084 BOX2I bbox = filledPolys.BBox( 0 );
2085
2086 // Build hole shape
2087 // the hole size is aZone->GetHatchGap(), but because the outline thickness
2088 // is aZone->GetMinThickness(), the hole shape size must be larger
2089 SHAPE_LINE_CHAIN hole_base;
2090 int hole_size = aZone->GetHatchGap() + aZone->GetMinThickness();
2091 VECTOR2I corner( 0, 0 );;
2092 hole_base.Append( corner );
2093 corner.x += hole_size;
2094 hole_base.Append( corner );
2095 corner.y += hole_size;
2096 hole_base.Append( corner );
2097 corner.x = 0;
2098 hole_base.Append( corner );
2099 hole_base.SetClosed( true );
2100
2101 // Calculate minimal area of a grid hole.
2102 // All holes smaller than a threshold will be removed
2103 double minimal_hole_area = hole_base.Area() * aZone->GetHatchHoleMinArea();
2104
2105 // Now convert this hole to a smoothed shape:
2106 if( aZone->GetHatchSmoothingLevel() > 0 )
2107 {
2108 // the actual size of chamfer, or rounded corner radius is the half size
2109 // of the HatchFillTypeGap scaled by aZone->GetHatchSmoothingValue()
2110 // aZone->GetHatchSmoothingValue() = 1.0 is the max value for the chamfer or the
2111 // radius of corner (radius = half size of the hole)
2112 int smooth_value = KiROUND( aZone->GetHatchGap()
2113 * aZone->GetHatchSmoothingValue() / 2 );
2114
2115 // Minimal optimization:
2116 // make smoothing only for reasonable smooth values, to avoid a lot of useless segments
2117 // and if the smooth value is small, use chamfer even if fillet is requested
2118 #define SMOOTH_MIN_VAL_MM 0.02
2119 #define SMOOTH_SMALL_VAL_MM 0.04
2120
2121 if( smooth_value > pcbIUScale.mmToIU( SMOOTH_MIN_VAL_MM ) )
2122 {
2123 SHAPE_POLY_SET smooth_hole;
2124 smooth_hole.AddOutline( hole_base );
2125 int smooth_level = aZone->GetHatchSmoothingLevel();
2126
2127 if( smooth_value < pcbIUScale.mmToIU( SMOOTH_SMALL_VAL_MM ) && smooth_level > 1 )
2128 smooth_level = 1;
2129
2130 // Use a larger smooth_value to compensate the outline tickness
2131 // (chamfer is not visible is smooth value < outline thickess)
2132 smooth_value += aZone->GetMinThickness() / 2;
2133
2134 // smooth_value cannot be bigger than the half size oh the hole:
2135 smooth_value = std::min( smooth_value, aZone->GetHatchGap() / 2 );
2136
2137 // the error to approximate a circle by segments when smoothing corners by a arc
2138 maxError = std::max( maxError * 2, smooth_value / 20 );
2139
2140 switch( smooth_level )
2141 {
2142 case 1:
2143 // Chamfer() uses the distance from a corner to create a end point
2144 // for the chamfer.
2145 hole_base = smooth_hole.Chamfer( smooth_value ).Outline( 0 );
2146 break;
2147
2148 default:
2149 if( aZone->GetHatchSmoothingLevel() > 2 )
2150 maxError /= 2; // Force better smoothing
2151
2152 hole_base = smooth_hole.Fillet( smooth_value, maxError ).Outline( 0 );
2153 break;
2154
2155 case 0:
2156 break;
2157 };
2158 }
2159 }
2160
2161 // Build holes
2162 SHAPE_POLY_SET holes;
2163
2164 for( int xx = 0; ; xx++ )
2165 {
2166 int xpos = xx * gridsize;
2167
2168 if( xpos > bbox.GetWidth() )
2169 break;
2170
2171 for( int yy = 0; ; yy++ )
2172 {
2173 int ypos = yy * gridsize;
2174
2175 if( ypos > bbox.GetHeight() )
2176 break;
2177
2178 // Generate hole
2179 SHAPE_LINE_CHAIN hole( hole_base );
2180 hole.Move( VECTOR2I( xpos, ypos ) );
2181 holes.AddOutline( hole );
2182 }
2183 }
2184
2185 holes.Move( bbox.GetPosition() );
2186
2187 if( !aZone->GetHatchOrientation().IsZero() )
2188 holes.Rotate( aZone->GetHatchOrientation() );
2189
2190 DUMP_POLYS_TO_COPPER_LAYER( holes, In10_Cu, wxT( "hatch-holes" ) );
2191
2192 int outline_margin = aZone->GetMinThickness() * 1.1;
2193
2194 // Using GetHatchThickness() can look more consistent than GetMinThickness().
2195 if( aZone->GetHatchBorderAlgorithm() && aZone->GetHatchThickness() > outline_margin )
2196 outline_margin = aZone->GetHatchThickness();
2197
2198 // The fill has already been deflated to ensure GetMinThickness() so we just have to
2199 // account for anything beyond that.
2200 SHAPE_POLY_SET deflatedFilledPolys = aFillPolys.CloneDropTriangulation();
2201 deflatedFilledPolys.Deflate( outline_margin - aZone->GetMinThickness(),
2202 CORNER_STRATEGY::CHAMFER_ALL_CORNERS, maxError );
2203 holes.BooleanIntersection( deflatedFilledPolys, SHAPE_POLY_SET::PM_FAST );
2204 DUMP_POLYS_TO_COPPER_LAYER( holes, In11_Cu, wxT( "fill-clipped-hatch-holes" ) );
2205
2206 SHAPE_POLY_SET deflatedOutline = aZone->Outline()->CloneDropTriangulation();
2207 deflatedOutline.Deflate( outline_margin, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, maxError );
2208 holes.BooleanIntersection( deflatedOutline, SHAPE_POLY_SET::PM_FAST );
2209 DUMP_POLYS_TO_COPPER_LAYER( holes, In12_Cu, wxT( "outline-clipped-hatch-holes" ) );
2210
2211 if( aZone->GetNetCode() != 0 )
2212 {
2213 // Vias and pads connected to the zone must not be allowed to become isolated inside
2214 // one of the holes. Effectively this means their copper outline needs to be expanded
2215 // to be at least as wide as the gap so that it is guaranteed to touch at least one
2216 // edge.
2217 BOX2I zone_boundingbox = aZone->GetBoundingBox();
2218 SHAPE_POLY_SET aprons;
2219 int min_apron_radius = ( aZone->GetHatchGap() * 10 ) / 19;
2220
2221 for( PCB_TRACK* track : m_board->Tracks() )
2222 {
2223 if( track->Type() == PCB_VIA_T )
2224 {
2225 PCB_VIA* via = static_cast<PCB_VIA*>( track );
2226
2227 if( via->GetNetCode() == aZone->GetNetCode()
2228 && via->IsOnLayer( aLayer )
2229 && via->GetBoundingBox().Intersects( zone_boundingbox ) )
2230 {
2231 int r = std::max( min_apron_radius,
2232 via->GetDrillValue() / 2 + outline_margin );
2233
2234 TransformCircleToPolygon( aprons, via->GetPosition(), r, maxError,
2235 ERROR_OUTSIDE );
2236 }
2237 }
2238 }
2239
2240 for( FOOTPRINT* footprint : m_board->Footprints() )
2241 {
2242 for( PAD* pad : footprint->Pads() )
2243 {
2244 if( pad->GetNetCode() == aZone->GetNetCode()
2245 && pad->IsOnLayer( aLayer )
2246 && pad->GetBoundingBox().Intersects( zone_boundingbox ) )
2247 {
2248 // What we want is to bulk up the pad shape so that the narrowest bit of
2249 // copper between the hole and the apron edge is at least outline_margin
2250 // wide (and that the apron itself meets min_apron_radius. But that would
2251 // take a lot of code and math, and the following approximation is close
2252 // enough.
2253 int pad_width = std::min( pad->GetSize().x, pad->GetSize().y );
2254 int slot_width = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
2255 int min_annular_ring_width = ( pad_width - slot_width ) / 2;
2256 int clearance = std::max( min_apron_radius - pad_width / 2,
2257 outline_margin - min_annular_ring_width );
2258
2259 clearance = std::max( 0, clearance - linethickness / 2 );
2260 pad->TransformShapeToPolygon( aprons, aLayer, clearance, maxError,
2261 ERROR_OUTSIDE );
2262 }
2263 }
2264 }
2265
2267 }
2268 DUMP_POLYS_TO_COPPER_LAYER( holes, In13_Cu, wxT( "pad-via-clipped-hatch-holes" ) );
2269
2270 // Now filter truncated holes to avoid small holes in pattern
2271 // It happens for holes near the zone outline
2272 for( int ii = 0; ii < holes.OutlineCount(); )
2273 {
2274 double area = holes.Outline( ii ).Area();
2275
2276 if( area < minimal_hole_area ) // The current hole is too small: remove it
2277 holes.DeletePolygon( ii );
2278 else
2279 ++ii;
2280 }
2281
2282 // create grid. Use SHAPE_POLY_SET::PM_STRICTLY_SIMPLE to
2283 // generate strictly simple polygons needed by Gerber files and Fracture()
2284 aFillPolys.BooleanSubtract( aFillPolys, holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
2285 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In14_Cu, wxT( "after-hatching" ) );
2286
2287 return true;
2288}
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:67
@ ZLO_FORCE_FLASHED
Definition: board_item.h:66
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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:77
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:90
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:205
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:297
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2373
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:677
const ZONES & Zones() const
Definition: board.h:327
int GetMaxClearanceValue() const
Returns the maximum clearance value for any object on the board.
Definition: board.cpp:800
int GetCopperLayerCount() const
Definition: board.cpp:653
const FOOTPRINTS & Footprints() const
Definition: board.h:323
const TRACKS & Tracks() const
Definition: board.h:321
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:460
const DRAWINGS & Drawings() const
Definition: board.h:325
const Vec & GetPosition() const
Definition: box2.h:201
int GetSizeMax() const
Definition: box2.h:225
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:249
size_type GetHeight() const
Definition: box2.h:205
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
size_type GetWidth() const
Definition: box2.h:204
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:128
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:623
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:74
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
MINOPTMAX< int > & Value()
Definition: drc_rule.h:142
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:141
ZONE_CONNECTION m_ZoneConnection
Definition: drc_rule.h:174
bool IsNull() const
Definition: drc_rule.h:136
bool IsZero() const
Definition: eda_angle.h:175
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:43
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: kidialog.cpp:51
bool SetOKCancelLabels(const ButtonLabel &ok, const ButtonLabel &cancel) override
Shows the 'do not show again' checkbox.
Definition: kidialog.h:53
int ShowModal() override
Definition: kidialog.cpp:95
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
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:418
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:647
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:823
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:863
T Min() const
Definition: minoptmax.h:33
T Max() const
Definition: minoptmax.h:34
T Opt() const
Definition: minoptmax.h:35
Definition: pad.h:53
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition: pad.cpp:762
void SetOffset(const VECTOR2I &aOffset)
Definition: pad.h:267
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition: pad.cpp:1800
void SetPosition(const VECTOR2I &aPos) override
Definition: pad.h:189
PAD_SHAPE GetShape() const
Definition: pad.h:187
PADSTACK::CUSTOM_SHAPE_ZONE_MODE GetCustomShapeInZoneOpt() const
Definition: pad.h:208
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation angle of the pad.
Definition: pad.cpp:827
bool TransformHoleToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Build the corner list of the polygonal drill shape in the board coordinate system.
Definition: pad.cpp:1783
Abstract dimension API.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
Definition: pcb_text.cpp:627
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).
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
void Reverse()
Definition: seg.h:351
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.
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Find all intersection points between our line chain and the segment aSeg.
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.
std::vector< INTERSECTION > INTERSECTIONS
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.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
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 difference For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
void DeletePolygon(int aIdx)
Delete aIdx-th polygon from the set.
double Area()
Return the area of this poly set.
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)
Return the aIndex-th subpolygon in the set.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
void BuildBBoxCaches() const
Construct BBoxCaches for Contains(), below.
int OutlineCount() const
Return the number of outlines in the set.
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
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:354
COMMIT * m_commit
Definition: zone_filler.h:134
int m_worstClearance
Definition: zone_filler.h:138
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 ...
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
ZONE_FILLER(BOARD *aBoard, COMMIT *aCommit)
Definition: zone_filler.cpp:54
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:72
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...
bool Fill(const std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
Definition: zone_filler.cpp:90
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
void SetNeedRefill(bool aNeedRefill)
Definition: zone.h:264
int GetHatchBorderAlgorithm() const
Definition: zone.h:302
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:490
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:1071
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:343
SHAPE_POLY_SET * Outline()
Definition: zone.h:336
void SetFillFlag(PCB_LAYER_ID aLayer, bool aFlag)
Definition: zone.h:258
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
Definition: zone.h:636
int GetMinThickness() const
Definition: zone.h:269
bool HigherPriority(const ZONE *aOther) const
Definition: zone.cpp:184
int GetHatchThickness() const
Definition: zone.h:284
double GetHatchHoleMinArea() const
Definition: zone.h:299
bool IsTeardropArea() const
Definition: zone.h:694
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:290
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
Definition: zone.cpp:1135
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:192
int GetHatchGap() const
Definition: zone.h:287
double GetHatchSmoothingValue() const
Definition: zone.h:296
int GetHatchSmoothingLevel() const
Definition: zone.h:293
bool IsOnCopperLayer() const override
Definition: zone.cpp:255
std::mutex & GetLock()
Definition: zone.h:248
unsigned GetAssignedPriority() const
Definition: zone.h:119
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
CORNER_STRATEGY
define how inflate transform build inflated polygon
DRC_CONSTRAINT_T
Definition: drc_rule.h:45
@ EDGE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:50
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:71
@ CLEARANCE_CONSTRAINT
Definition: drc_rule.h:47
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
Definition: drc_rule.h:60
@ THERMAL_RELIEF_GAP_CONSTRAINT
Definition: drc_rule.h:59
@ HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:48
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:70
#define _(s)
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.
double m_ExtraClearance
When filling zones, we add an extra amount of clearance to each zone to ensure that rounding errors d...
bool m_DebugZoneFiller
A mode that dumps the various stages of a F_Cu fill into In1_Cu through In9_Cu.
This file is part of the common library.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ 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:61
@ 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
const double epsilon
const double IU_PER_MM
Definition: base_units.h:76
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
A struct recording the isolated and single-pad islands within a zone.
Definition: zone.h:59
static thread_pool * tp
Definition: thread_pool.cpp:30
BS::thread_pool thread_pool
Definition: thread_pool.h:30
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
Definition: thread_pool.cpp:32
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition: typeinfo.h:90
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:106
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:101
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:104
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:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602
#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:58
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:47