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 <confirm.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 return c.GetValue().Min();
1010 };
1011
1012 // Add non-connected pad clearances
1013 //
1014 auto knockoutPadClearance =
1015 [&]( PAD* aPad )
1016 {
1017 int init_gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone, aPad, aLayer );
1018 int gap = init_gap;
1019 bool hasHole = aPad->GetDrillSize().x > 0;
1020 bool flashLayer = aPad->FlashLayer( aLayer );
1021 bool platedHole = hasHole && aPad->GetAttribute() == PAD_ATTRIB::PTH;
1022
1023 if( flashLayer || platedHole )
1024 {
1025 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1026 aZone, aPad, aLayer ) );
1027 }
1028
1029 if( flashLayer && gap > 0 )
1030 addKnockout( aPad, aLayer, gap + extra_margin, aHoles );
1031
1032 if( hasHole )
1033 {
1034 // NPTH do not need copper clearance gaps to their holes
1035 if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
1036 gap = init_gap;
1037
1038 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
1039 aZone, aPad, aLayer ) );
1040
1041 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
1042 aZone, aPad, aLayer ) );
1043
1044 if( gap > 0 )
1045 addHoleKnockout( aPad, gap + extra_margin, aHoles );
1046 }
1047 };
1048
1049 for( PAD* pad : aNoConnectionPads )
1050 {
1051 if( checkForCancel( m_progressReporter ) )
1052 return;
1053
1054 knockoutPadClearance( pad );
1055 }
1056
1057 // Add non-connected track clearances
1058 //
1059 auto knockoutTrackClearance =
1060 [&]( PCB_TRACK* aTrack )
1061 {
1062 if( aTrack->GetBoundingBox().Intersects( zone_boundingbox ) )
1063 {
1064 bool sameNet = aTrack->GetNetCode() == aZone->GetNetCode();
1065
1066 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1067 sameNet = false;
1068
1069 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
1070 aZone, aTrack, aLayer );
1071
1072 if( aTrack->Type() == PCB_VIA_T )
1073 {
1074 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
1075
1076 if( via->GetZoneLayerOverride( aLayer ) == ZLO_FORCE_NO_ZONE_CONNECTION )
1077 sameNet = false;
1078 }
1079
1080 if( !sameNet )
1081 {
1082 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1083 aZone, aTrack, aLayer ) );
1084 }
1085
1086 if( aTrack->Type() == PCB_VIA_T )
1087 {
1088 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
1089
1090 if( via->FlashLayer( aLayer ) && gap > 0 )
1091 {
1092 via->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
1094 }
1095
1096 gap = std::max( gap, evalRulesForItems( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
1097 aZone, via, aLayer ) );
1098
1099 if( !sameNet )
1100 {
1101 gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
1102 aZone, via, aLayer ) );
1103 }
1104
1105 if( gap > 0 )
1106 {
1107 int radius = via->GetDrillValue() / 2;
1108
1109 TransformCircleToPolygon( aHoles, via->GetPosition(),
1110 radius + gap + extra_margin,
1112 }
1113 }
1114 else
1115 {
1116 if( gap > 0 )
1117 {
1118 aTrack->TransformShapeToPolygon( aHoles, aLayer, gap + extra_margin,
1120 }
1121 }
1122 }
1123 };
1124
1125 for( PCB_TRACK* track : m_board->Tracks() )
1126 {
1127 if( !track->IsOnLayer( aLayer ) )
1128 continue;
1129
1130 if( checkForCancel( m_progressReporter ) )
1131 return;
1132
1133 knockoutTrackClearance( track );
1134 }
1135
1136 // Add graphic item clearances.
1137 //
1138 auto knockoutGraphicClearance =
1139 [&]( BOARD_ITEM* aItem )
1140 {
1141 int shapeNet = -1;
1142
1143 if( aItem->Type() == PCB_SHAPE_T )
1144 shapeNet = static_cast<PCB_SHAPE*>( aItem )->GetNetCode();
1145
1146 bool sameNet = shapeNet == aZone->GetNetCode();
1147
1148 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1149 sameNet = false;
1150
1151 // A item on the Edge_Cuts or Margin is always seen as on any layer:
1152 if( aItem->IsOnLayer( aLayer )
1153 || aItem->IsOnLayer( Edge_Cuts )
1154 || aItem->IsOnLayer( Margin ) )
1155 {
1156 if( aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
1157 {
1158 bool ignoreLineWidths = false;
1159 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT,
1160 aZone, aItem, aLayer );
1161
1162 if( aItem->IsOnLayer( aLayer ) && !sameNet )
1163 {
1164 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT,
1165 aZone, aItem, aLayer ) );
1166 }
1167 else if( aItem->IsOnLayer( Edge_Cuts ) )
1168 {
1169 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
1170 aZone, aItem, aLayer ) );
1171 ignoreLineWidths = true;
1172 }
1173 else if( aItem->IsOnLayer( Margin ) )
1174 {
1175 gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
1176 aZone, aItem, aLayer ) );
1177 }
1178
1179 if( gap > 0 )
1180 addKnockout( aItem, aLayer, gap + extra_margin, ignoreLineWidths, aHoles );
1181 }
1182 }
1183 };
1184
1185 for( FOOTPRINT* footprint : m_board->Footprints() )
1186 {
1187 knockoutGraphicClearance( &footprint->Reference() );
1188 knockoutGraphicClearance( &footprint->Value() );
1189
1190 std::set<PAD*> allowedNetTiePads;
1191
1192 // Don't knock out holes for graphic items which implement a net-tie to the zone's net
1193 // on the layer being filled.
1194 if( footprint->IsNetTie() )
1195 {
1196 for( PAD* pad : footprint->Pads() )
1197 {
1198 bool sameNet = pad->GetNetCode() == aZone->GetNetCode();
1199
1200 if( !aZone->IsTeardropArea() && aZone->GetNetCode() == 0 )
1201 sameNet = false;
1202
1203 if( sameNet )
1204 {
1205 if( pad->IsOnLayer( aLayer ) )
1206 allowedNetTiePads.insert( pad );
1207
1208 for( PAD* other : footprint->GetNetTiePads( pad ) )
1209 {
1210 if( other->IsOnLayer( aLayer ) )
1211 allowedNetTiePads.insert( other );
1212 }
1213 }
1214 }
1215 }
1216
1217 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1218 {
1219 if( checkForCancel( m_progressReporter ) )
1220 return;
1221
1222 BOX2I itemBBox = item->GetBoundingBox();
1223
1224 if( !zone_boundingbox.Intersects( itemBBox ) )
1225 continue;
1226
1227 bool skipItem = false;
1228
1229 if( item->IsOnLayer( aLayer ) )
1230 {
1231 std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape();
1232
1233 for( PAD* pad : allowedNetTiePads )
1234 {
1235 if( pad->GetBoundingBox().Intersects( itemBBox )
1236 && pad->GetEffectiveShape()->Collide( itemShape.get() ) )
1237 {
1238 skipItem = true;
1239 break;
1240 }
1241 }
1242 }
1243
1244 if( !skipItem )
1245 knockoutGraphicClearance( item );
1246 }
1247 }
1248
1249 for( BOARD_ITEM* item : m_board->Drawings() )
1250 {
1251 if( checkForCancel( m_progressReporter ) )
1252 return;
1253
1254 knockoutGraphicClearance( item );
1255 }
1256
1257 // Add non-connected zone clearances
1258 //
1259 auto knockoutZoneClearance =
1260 [&]( ZONE* aKnockout )
1261 {
1262 // If the zones share no common layers
1263 if( !aKnockout->GetLayerSet().test( aLayer ) )
1264 return;
1265
1266 if( aKnockout->GetBoundingBox().Intersects( zone_boundingbox ) )
1267 {
1268 if( aKnockout->GetIsRuleArea() )
1269 {
1270 // Keepouts use outline with no clearance
1271 aKnockout->TransformSmoothedOutlineToPolygon( aHoles, 0, m_maxError,
1272 ERROR_OUTSIDE, nullptr );
1273 }
1274 else
1275 {
1276 int gap = evalRulesForItems( PHYSICAL_CLEARANCE_CONSTRAINT, aZone,
1277 aKnockout, aLayer );
1278
1279 gap = std::max( gap, evalRulesForItems( CLEARANCE_CONSTRAINT, aZone,
1280 aKnockout, aLayer ) );
1281
1282 SHAPE_POLY_SET poly;
1283 aKnockout->TransformShapeToPolygon( poly, aLayer, gap + extra_margin,
1285 aHoles.Append( poly );
1286 }
1287 }
1288 };
1289
1290 for( ZONE* otherZone : m_board->Zones() )
1291 {
1292 if( checkForCancel( m_progressReporter ) )
1293 return;
1294
1295 // Negative clearance permits zones to short
1296 if( evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, otherZone, aLayer ) < 0 )
1297 continue;
1298
1299 if( otherZone->GetIsRuleArea() )
1300 {
1301 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1302 knockoutZoneClearance( otherZone );
1303 }
1304 else if( otherZone->HigherPriority( aZone ) )
1305 {
1306 if( !otherZone->SameNet( aZone ) )
1307 knockoutZoneClearance( otherZone );
1308 }
1309 }
1310
1311 for( FOOTPRINT* footprint : m_board->Footprints() )
1312 {
1313 for( ZONE* otherZone : footprint->Zones() )
1314 {
1315 if( checkForCancel( m_progressReporter ) )
1316 return;
1317
1318 if( otherZone->GetIsRuleArea() )
1319 {
1320 if( otherZone->GetDoNotAllowCopperPour() && !aZone->IsTeardropArea() )
1321 knockoutZoneClearance( otherZone );
1322 }
1323 else if( otherZone->HigherPriority( aZone ) )
1324 {
1325 if( !otherZone->SameNet( aZone ) )
1326 knockoutZoneClearance( otherZone );
1327 }
1328 }
1329 }
1330
1332}
1333
1334
1340 SHAPE_POLY_SET& aRawFill )
1341{
1342 BOX2I zoneBBox = aZone->GetBoundingBox();
1343
1344 auto knockoutZoneOutline =
1345 [&]( ZONE* aKnockout )
1346 {
1347 // If the zones share no common layers
1348 if( !aKnockout->GetLayerSet().test( aLayer ) )
1349 return;
1350
1351 if( aKnockout->GetBoundingBox().Intersects( zoneBBox ) )
1352 {
1353 // Processing of arc shapes in zones is not yet supported because Clipper
1354 // can't do boolean operations on them. The poly outline must be converted to
1355 // segments first.
1356 SHAPE_POLY_SET outline = aKnockout->Outline()->CloneDropTriangulation();
1357 outline.ClearArcs();
1358
1359 aRawFill.BooleanSubtract( outline, SHAPE_POLY_SET::PM_FAST );
1360 }
1361 };
1362
1363 for( ZONE* otherZone : m_board->Zones() )
1364 {
1365 // Don't use the `HigherPriority()` check here because we _only_ want to knock out zones
1366 // with explicitly higher priorities, not those with equal priorities
1367 if( otherZone->SameNet( aZone )
1368 && otherZone->GetAssignedPriority() > aZone->GetAssignedPriority() )
1369 {
1370 // Do not remove teardrop area: it is not useful and not good
1371 if( !otherZone->IsTeardropArea() )
1372 knockoutZoneOutline( otherZone );
1373 }
1374 }
1375
1376 for( FOOTPRINT* footprint : m_board->Footprints() )
1377 {
1378 for( ZONE* otherZone : footprint->Zones() )
1379 {
1380 if( otherZone->SameNet( aZone ) && otherZone->HigherPriority( aZone ) )
1381 {
1382 // Do not remove teardrop area: it is not useful and not good
1383 if( !otherZone->IsTeardropArea() )
1384 knockoutZoneOutline( otherZone );
1385 }
1386 }
1387 }
1388}
1389
1390
1391#define DUMP_POLYS_TO_COPPER_LAYER( a, b, c ) \
1392 { if( m_debugZoneFiller && aDebugLayer == b ) \
1393 { \
1394 m_board->SetLayerName( b, c ); \
1395 SHAPE_POLY_SET d = a; \
1396 d.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); \
1397 aFillPolys = d; \
1398 return false; \
1399 } \
1400 }
1401
1402
1414bool ZONE_FILLER::fillCopperZone( const ZONE* aZone, PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer,
1415 const SHAPE_POLY_SET& aSmoothedOutline,
1416 const SHAPE_POLY_SET& aMaxExtents, SHAPE_POLY_SET& aFillPolys )
1417{
1419
1420 // Features which are min_width should survive pruning; features that are *less* than
1421 // min_width should not. Therefore we subtract epsilon from the min_width when
1422 // deflating/inflating.
1423 int half_min_width = aZone->GetMinThickness() / 2;
1424 int epsilon = pcbIUScale.mmToIU( 0.001 );
1425
1426 // Solid polygons are deflated and inflated during calculations. Deflating doesn't cause
1427 // issues, but inflate is tricky as it can create excessively long and narrow spikes for
1428 // acute angles.
1429 // ALLOW_ACUTE_CORNERS cannot be used due to the spike problem.
1430 // CHAMFER_ACUTE_CORNERS is tempting, but can still produce spikes in some unusual
1431 // circumstances (https://gitlab.com/kicad/code/kicad/-/issues/5581).
1432 // It's unclear if ROUND_ACUTE_CORNERS would have the same issues, but is currently avoided
1433 // as a "less-safe" option.
1434 // ROUND_ALL_CORNERS produces the uniformly nicest shapes, but also a lot of segments.
1435 // CHAMFER_ALL_CORNERS improves the segment count.
1436 CORNER_STRATEGY fastCornerStrategy = CORNER_STRATEGY::CHAMFER_ALL_CORNERS;
1437 CORNER_STRATEGY cornerStrategy = CORNER_STRATEGY::ROUND_ALL_CORNERS;
1438
1439 std::vector<PAD*> thermalConnectionPads;
1440 std::vector<PAD*> noConnectionPads;
1441 std::deque<SHAPE_LINE_CHAIN> thermalSpokes;
1442 SHAPE_POLY_SET clearanceHoles;
1443
1444 aFillPolys = aSmoothedOutline;
1445 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In1_Cu, wxT( "smoothed-outline" ) );
1446
1448 return false;
1449
1450 /* -------------------------------------------------------------------------------------
1451 * Knockout thermal reliefs.
1452 */
1453
1454 knockoutThermalReliefs( aZone, aLayer, aFillPolys, thermalConnectionPads, noConnectionPads );
1455 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In2_Cu, wxT( "minus-thermal-reliefs" ) );
1456
1458 return false;
1459
1460 /* -------------------------------------------------------------------------------------
1461 * Knockout electrical clearances.
1462 */
1463
1464 buildCopperItemClearances( aZone, aLayer, noConnectionPads, clearanceHoles );
1465 DUMP_POLYS_TO_COPPER_LAYER( clearanceHoles, In3_Cu, wxT( "clearance-holes" ) );
1466
1468 return false;
1469
1470 /* -------------------------------------------------------------------------------------
1471 * Add thermal relief spokes.
1472 */
1473
1474 buildThermalSpokes( aZone, aLayer, thermalConnectionPads, thermalSpokes );
1475
1477 return false;
1478
1479 // Create a temporary zone that we can hit-test spoke-ends against. It's only temporary
1480 // because the "real" subtract-clearance-holes has to be done after the spokes are added.
1481 static const bool USE_BBOX_CACHES = true;
1482 SHAPE_POLY_SET testAreas = aFillPolys.CloneDropTriangulation();
1483 testAreas.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1484 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In4_Cu, wxT( "minus-clearance-holes" ) );
1485
1486 // Prune features that don't meet minimum-width criteria
1487 if( half_min_width - epsilon > epsilon )
1488 {
1489 testAreas.Deflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1490 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In5_Cu, wxT( "spoke-test-deflated" ) );
1491
1492 testAreas.Inflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1493 DUMP_POLYS_TO_COPPER_LAYER( testAreas, In6_Cu, wxT( "spoke-test-reinflated" ) );
1494 }
1495
1497 return false;
1498
1499 // Spoke-end-testing is hugely expensive so we generate cached bounding-boxes to speed
1500 // things up a bit.
1501 testAreas.BuildBBoxCaches();
1502 int interval = 0;
1503
1504 SHAPE_POLY_SET debugSpokes;
1505
1506 for( const SHAPE_LINE_CHAIN& spoke : thermalSpokes )
1507 {
1508 const VECTOR2I& testPt = spoke.CPoint( 3 );
1509
1510 // Hit-test against zone body
1511 if( testAreas.Contains( testPt, -1, 1, USE_BBOX_CACHES ) )
1512 {
1513 if( m_debugZoneFiller )
1514 debugSpokes.AddOutline( spoke );
1515
1516 aFillPolys.AddOutline( spoke );
1517 continue;
1518 }
1519
1520 if( interval++ > 400 )
1521 {
1523 return false;
1524
1525 interval = 0;
1526 }
1527
1528 // Hit-test against other spokes
1529 for( const SHAPE_LINE_CHAIN& other : thermalSpokes )
1530 {
1531 // Hit test in both directions to avoid interactions with round-off errors.
1532 // (See https://gitlab.com/kicad/code/kicad/-/issues/13316.)
1533 if( &other != &spoke
1534 && other.PointInside( testPt, 1, USE_BBOX_CACHES )
1535 && spoke.PointInside( other.CPoint( 3 ), 1, USE_BBOX_CACHES ) )
1536 {
1537 if( m_debugZoneFiller )
1538 debugSpokes.AddOutline( spoke );
1539
1540 aFillPolys.AddOutline( spoke );
1541 break;
1542 }
1543 }
1544 }
1545
1546 DUMP_POLYS_TO_COPPER_LAYER( debugSpokes, In7_Cu, wxT( "spokes" ) );
1547
1549 return false;
1550
1551 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1552 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In8_Cu, wxT( "after-spoke-trimming" ) );
1553
1554 /* -------------------------------------------------------------------------------------
1555 * Prune features that don't meet minimum-width criteria
1556 */
1557
1558 if( half_min_width - epsilon > epsilon )
1559 aFillPolys.Deflate( half_min_width - epsilon, fastCornerStrategy, m_maxError );
1560
1561 // Min-thickness is the web thickness. On the other hand, a blob min-thickness by
1562 // min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
1563 // arbitrarily choose "at least 2X min-thickness on one axis". (Since we're doing this
1564 // during the deflated state, that means we test for "at least min-thickness".)
1565 for( int ii = aFillPolys.OutlineCount() - 1; ii >= 0; ii-- )
1566 {
1567 std::vector<SHAPE_LINE_CHAIN>& island = aFillPolys.Polygon( ii );
1568 BOX2I islandExtents;
1569
1570 for( const VECTOR2I& pt : island.front().CPoints() )
1571 {
1572 islandExtents.Merge( pt );
1573
1574 if( islandExtents.GetSizeMax() > aZone->GetMinThickness() )
1575 break;
1576 }
1577
1578 if( islandExtents.GetSizeMax() < aZone->GetMinThickness() )
1579 aFillPolys.DeletePolygon( ii );
1580 }
1581
1582 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In9_Cu, wxT( "deflated" ) );
1583
1585 return false;
1586
1587 /* -------------------------------------------------------------------------------------
1588 * Process the hatch pattern (note that we do this while deflated)
1589 */
1590
1591 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1592 {
1593 if( !addHatchFillTypeOnZone( aZone, aLayer, aDebugLayer, aFillPolys ) )
1594 return false;
1595 }
1596
1598 return false;
1599
1600 /* -------------------------------------------------------------------------------------
1601 * Finish minimum-width pruning by re-inflating
1602 */
1603
1604 if( half_min_width - epsilon > epsilon )
1605 aFillPolys.Inflate( half_min_width - epsilon, cornerStrategy, m_maxError, true );
1606
1607 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In15_Cu, wxT( "after-reinflating" ) );
1608
1609 /* -------------------------------------------------------------------------------------
1610 * Ensure additive changes (thermal stubs and inflating acute corners) do not add copper
1611 * outside the zone boundary, inside the clearance holes, or between otherwise isolated
1612 * islands
1613 */
1614
1615 for( PAD* pad : thermalConnectionPads )
1616 addHoleKnockout( pad, 0, clearanceHoles );
1617
1618 aFillPolys.BooleanIntersection( aMaxExtents, SHAPE_POLY_SET::PM_FAST );
1619 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In16_Cu, wxT( "after-trim-to-outline" ) );
1620 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1621 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In17_Cu, wxT( "after-trim-to-clearance-holes" ) );
1622
1623 /* -------------------------------------------------------------------------------------
1624 * Lastly give any same-net but higher-priority zones control over their own area.
1625 */
1626
1627 subtractHigherPriorityZones( aZone, aLayer, aFillPolys );
1628 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In18_Cu, wxT( "minus-higher-priority-zones" ) );
1629
1630 aFillPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
1631 return true;
1632}
1633
1634
1636 const SHAPE_POLY_SET& aSmoothedOutline,
1637 SHAPE_POLY_SET& aFillPolys )
1638{
1640 BOX2I zone_boundingbox = aZone->GetBoundingBox();
1641 SHAPE_POLY_SET clearanceHoles;
1642 long ticker = 0;
1643
1644 auto checkForCancel =
1645 [&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
1646 {
1647 return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
1648 };
1649
1650 auto knockoutGraphicClearance =
1651 [&]( BOARD_ITEM* aItem )
1652 {
1653 if( aItem->IsKnockout() && aItem->IsOnLayer( aLayer )
1654 && aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
1655 {
1657 aZone, aItem, aLayer );
1658
1659 addKnockout( aItem, aLayer, cc.GetValue().Min(), false, clearanceHoles );
1660 }
1661 };
1662
1663 for( FOOTPRINT* footprint : m_board->Footprints() )
1664 {
1665 if( checkForCancel( m_progressReporter ) )
1666 return false;
1667
1668 knockoutGraphicClearance( &footprint->Reference() );
1669 knockoutGraphicClearance( &footprint->Value() );
1670
1671 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1672 knockoutGraphicClearance( item );
1673 }
1674
1675 for( BOARD_ITEM* item : m_board->Drawings() )
1676 {
1677 if( checkForCancel( m_progressReporter ) )
1678 return false;
1679
1680 knockoutGraphicClearance( item );
1681 }
1682
1683 aFillPolys = aSmoothedOutline;
1684 aFillPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
1685
1686 for( ZONE* keepout : m_board->Zones() )
1687 {
1688 if( !keepout->GetIsRuleArea() )
1689 continue;
1690
1691 if( keepout->GetDoNotAllowCopperPour() && keepout->IsOnLayer( aLayer ) )
1692 {
1693 if( keepout->GetBoundingBox().Intersects( zone_boundingbox ) )
1694 aFillPolys.BooleanSubtract( *keepout->Outline(), SHAPE_POLY_SET::PM_FAST );
1695 }
1696 }
1697
1698 // Features which are min_width should survive pruning; features that are *less* than
1699 // min_width should not. Therefore we subtract epsilon from the min_width when
1700 // deflating/inflating.
1701 int half_min_width = aZone->GetMinThickness() / 2;
1702 int epsilon = pcbIUScale.mmToIU( 0.001 );
1703
1704 aFillPolys.Deflate( half_min_width - epsilon, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, m_maxError );
1705
1706 // Remove the non filled areas due to the hatch pattern
1707 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1708 {
1709 if( !addHatchFillTypeOnZone( aZone, aLayer, aLayer, aFillPolys ) )
1710 return false;
1711 }
1712
1713 // Re-inflate after pruning of areas that don't meet minimum-width criteria
1714 if( half_min_width - epsilon > epsilon )
1715 aFillPolys.Inflate( half_min_width - epsilon, CORNER_STRATEGY::ROUND_ALL_CORNERS, m_maxError );
1716
1718 return true;
1719}
1720
1721
1722/*
1723 * Build the filled solid areas data from real outlines (stored in m_Poly)
1724 * The solid areas can be more than one on copper layers, and do not have holes
1725 * ( holes are linked by overlapping segments to the main outline)
1726 */
1728{
1729 SHAPE_POLY_SET* boardOutline = m_brdOutlinesValid ? &m_boardOutline : nullptr;
1730 SHAPE_POLY_SET maxExtents;
1731 SHAPE_POLY_SET smoothedPoly;
1732 PCB_LAYER_ID debugLayer = UNDEFINED_LAYER;
1733
1734 if( m_debugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
1735 {
1736 debugLayer = aLayer;
1737 aLayer = F_Cu;
1738 }
1739
1740 if( !aZone->BuildSmoothedPoly( maxExtents, aLayer, boardOutline, &smoothedPoly ) )
1741 return false;
1742
1744 return false;
1745
1746 if( aZone->IsOnCopperLayer() )
1747 {
1748 if( fillCopperZone( aZone, aLayer, debugLayer, smoothedPoly, maxExtents, aFillPolys ) )
1749 aZone->SetNeedRefill( false );
1750 }
1751 else
1752 {
1753 if( fillNonCopperZone( aZone, aLayer, smoothedPoly, aFillPolys ) )
1754 aZone->SetNeedRefill( false );
1755 }
1756
1757 return true;
1758}
1759
1760
1765 const std::vector<PAD*>& aSpokedPadsList,
1766 std::deque<SHAPE_LINE_CHAIN>& aSpokesList )
1767{
1769 BOX2I zoneBB = aZone->GetBoundingBox();
1770 DRC_CONSTRAINT constraint;
1771
1772 zoneBB.Inflate( std::max( bds.GetBiggestClearanceValue(), aZone->GetLocalClearance().value() ) );
1773
1774 // Is a point on the boundary of the polygon inside or outside? The boundary may be off by
1775 // MaxError, and we add 1.5 mil for some wiggle room.
1776 int epsilon = KiROUND( bds.m_MaxError + pcbIUScale.IU_PER_MM * 0.038 ); // 1.5 mil
1777
1778 for( PAD* pad : aSpokedPadsList )
1779 {
1780 // We currently only connect to pads, not pad holes
1781 if( !pad->IsOnLayer( aLayer ) )
1782 continue;
1783
1784 constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone, aLayer );
1785 int thermalReliefGap = constraint.GetValue().Min();
1786
1787 constraint = bds.m_DRCEngine->EvalRules( THERMAL_SPOKE_WIDTH_CONSTRAINT, pad, aZone, aLayer );
1788 int spoke_w = constraint.GetValue().Opt();
1789
1790 // Spoke width should ideally be smaller than the pad minor axis.
1791 // Otherwise the thermal shape is not really a thermal relief,
1792 // and the algo to count the actual number of spokes can fail
1793 int spoke_max_allowed_w = std::min( pad->GetSize().x, pad->GetSize().y );
1794
1795 spoke_w = std::max( spoke_w, constraint.Value().Min() );
1796 spoke_w = std::min( spoke_w, constraint.Value().Max() );
1797
1798 // ensure the spoke width is smaller than the pad minor size
1799 spoke_w = std::min( spoke_w, spoke_max_allowed_w );
1800
1801 // Cannot create stubs having a width < zone min thickness
1802 if( spoke_w < aZone->GetMinThickness() )
1803 continue;
1804
1805 int spoke_half_w = spoke_w / 2;
1806
1807 // Quick test here to possibly save us some work
1808 BOX2I itemBB = pad->GetBoundingBox();
1809 itemBB.Inflate( thermalReliefGap + epsilon );
1810
1811 if( !( itemBB.Intersects( zoneBB ) ) )
1812 continue;
1813
1814 bool customSpokes = false;
1815
1816 if( pad->GetShape() == PAD_SHAPE::CUSTOM )
1817 {
1818 for( const std::shared_ptr<PCB_SHAPE>& primitive : pad->GetPrimitives() )
1819 {
1820 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::SEGMENT )
1821 {
1822 customSpokes = true;
1823 break;
1824 }
1825 }
1826 }
1827
1828 // Thermal spokes consist of square-ended segments from the pad center to points just
1829 // outside the thermal relief. The outside end has an extra center point (which must be
1830 // at idx 3) which is used for testing whether or not the spoke connects to copper in the
1831 // parent zone.
1832
1833 auto buildSpokesFromOrigin =
1834 [&]( const BOX2I& box )
1835 {
1836 for( int i = 0; i < 4; i++ )
1837 {
1838 SHAPE_LINE_CHAIN spoke;
1839
1840 switch( i )
1841 {
1842 case 0: // lower stub
1843 spoke.Append( +spoke_half_w, -spoke_half_w );
1844 spoke.Append( -spoke_half_w, -spoke_half_w );
1845 spoke.Append( -spoke_half_w, box.GetBottom() );
1846 spoke.Append( 0, box.GetBottom() ); // test pt
1847 spoke.Append( +spoke_half_w, box.GetBottom() );
1848 break;
1849
1850 case 1: // upper stub
1851 spoke.Append( +spoke_half_w, +spoke_half_w );
1852 spoke.Append( -spoke_half_w, +spoke_half_w );
1853 spoke.Append( -spoke_half_w, box.GetTop() );
1854 spoke.Append( 0, box.GetTop() ); // test pt
1855 spoke.Append( +spoke_half_w, box.GetTop() );
1856 break;
1857
1858 case 2: // right stub
1859 spoke.Append( -spoke_half_w, +spoke_half_w );
1860 spoke.Append( -spoke_half_w, -spoke_half_w );
1861 spoke.Append( box.GetRight(), -spoke_half_w );
1862 spoke.Append( box.GetRight(), 0 ); // test pt
1863 spoke.Append( box.GetRight(), +spoke_half_w );
1864 break;
1865
1866 case 3: // left stub
1867 spoke.Append( +spoke_half_w, +spoke_half_w );
1868 spoke.Append( +spoke_half_w, -spoke_half_w );
1869 spoke.Append( box.GetLeft(), -spoke_half_w );
1870 spoke.Append( box.GetLeft(), 0 ); // test pt
1871 spoke.Append( box.GetLeft(), +spoke_half_w );
1872 break;
1873 }
1874
1875 spoke.SetClosed( true );
1876 aSpokesList.push_back( std::move( spoke ) );
1877 }
1878 };
1879
1880 if( customSpokes )
1881 {
1882 SHAPE_POLY_SET thermalPoly;
1883 SHAPE_LINE_CHAIN thermalOutline;
1884
1885 pad->TransformShapeToPolygon( thermalPoly, aLayer, thermalReliefGap + epsilon,
1887
1888 if( thermalPoly.OutlineCount() )
1889 thermalOutline = thermalPoly.Outline( 0 );
1890
1891 for( const std::shared_ptr<PCB_SHAPE>& primitive : pad->GetPrimitives() )
1892 {
1893 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::SEGMENT )
1894 {
1895 SEG seg( primitive->GetStart(), primitive->GetEnd() );
1896 SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
1897
1898 RotatePoint( seg.A, pad->GetOrientation() );
1899 RotatePoint( seg.B, pad->GetOrientation() );
1900 seg.A += pad->ShapePos();
1901 seg.B += pad->ShapePos();
1902
1903 // Make sure seg.A is the origin
1904 if( !pad->GetEffectivePolygon( ERROR_OUTSIDE )->Contains( seg.A ) )
1905 seg.Reverse();
1906
1907 // Trim seg.B to the thermal outline
1908 if( thermalOutline.Intersect( seg, intersections ) )
1909 {
1910 seg.B = intersections.front().p;
1911
1912 VECTOR2I offset = ( seg.B - seg.A ).Perpendicular().Resize( spoke_half_w );
1913 SHAPE_LINE_CHAIN spoke;
1914
1915 spoke.Append( seg.A + offset );
1916 spoke.Append( seg.A - offset );
1917 spoke.Append( seg.B - offset );
1918 spoke.Append( seg.B ); // test pt
1919 spoke.Append( seg.B + offset );
1920
1921 spoke.SetClosed( true );
1922 aSpokesList.push_back( std::move( spoke ) );
1923 }
1924 }
1925 }
1926 }
1927 // If the spokes are at a cardinal angle then we can generate them from a bounding box
1928 // without trig.
1929 else if( ( pad->GetOrientation() + pad->GetThermalSpokeAngle() ).IsCardinal() )
1930 {
1931 BOX2I spokesBox = pad->GetBoundingBox();
1932 spokesBox.Inflate( thermalReliefGap + epsilon );
1933
1934 // Spokes are from center of pad shape, not from hole.
1935 spokesBox.Offset( - pad->ShapePos() );
1936
1937 buildSpokesFromOrigin( spokesBox );
1938
1939 auto spokeIter = aSpokesList.rbegin();
1940
1941 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1942 spokeIter->Move( pad->ShapePos() );
1943 }
1944 // Even if the spokes are rotated, we can fudge it for round and square pads by rotating
1945 // the bounding box to match the spokes.
1946 else if( pad->GetSizeX() == pad->GetSizeY() && pad->GetShape() != PAD_SHAPE::CUSTOM )
1947 {
1948 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
1949 // from dirtying the real pad's cached shapes.
1950 PAD dummy_pad( *pad );
1951 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
1952
1953 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
1954 // offset and is at position 0,0
1955 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
1956 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
1957
1958 BOX2I spokesBox = dummy_pad.GetBoundingBox();
1959 spokesBox.Inflate( thermalReliefGap + epsilon );
1960
1961 buildSpokesFromOrigin( spokesBox );
1962
1963 auto spokeIter = aSpokesList.rbegin();
1964
1965 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
1966 {
1967 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
1968 spokeIter->Move( pad->ShapePos() );
1969 }
1970
1971 // Remove group membership from dummy item before deleting
1972 dummy_pad.SetParentGroup( nullptr );
1973 }
1974 // And lastly, even when we have to resort to trig, we can use it only in a post-process
1975 // after the rotated-bounding-box trick from above.
1976 else
1977 {
1978 // Since the bounding-box needs to be correclty rotated we use a dummy pad to keep
1979 // from dirtying the real pad's cached shapes.
1980 PAD dummy_pad( *pad );
1981 dummy_pad.SetOrientation( pad->GetThermalSpokeAngle() );
1982
1983 // Spokes are from center of pad shape, not from hole. So the dummy pad has no shape
1984 // offset and is at position 0,0
1985 dummy_pad.SetPosition( VECTOR2I( 0, 0 ) );
1986 dummy_pad.SetOffset( VECTOR2I( 0, 0 ) );
1987
1988 BOX2I spokesBox = dummy_pad.GetBoundingBox();
1989
1990 // In this case make the box -big-; we're going to clip to the "real" bbox later.
1991 spokesBox.Inflate( thermalReliefGap + spokesBox.GetWidth() + spokesBox.GetHeight() );
1992
1993 buildSpokesFromOrigin( spokesBox );
1994
1995 BOX2I realBBox = pad->GetBoundingBox();
1996 realBBox.Inflate( thermalReliefGap + epsilon );
1997
1998 auto spokeIter = aSpokesList.rbegin();
1999
2000 for( int ii = 0; ii < 4; ++ii, ++spokeIter )
2001 {
2002 spokeIter->Rotate( pad->GetOrientation() + pad->GetThermalSpokeAngle() );
2003 spokeIter->Move( pad->ShapePos() );
2004
2005 VECTOR2I origin_p = spokeIter->GetPoint( 0 );
2006 VECTOR2I origin_m = spokeIter->GetPoint( 1 );
2007 VECTOR2I origin = ( origin_p + origin_m ) / 2;
2008 VECTOR2I end_m = spokeIter->GetPoint( 2 );
2009 VECTOR2I end = spokeIter->GetPoint( 3 );
2010 VECTOR2I end_p = spokeIter->GetPoint( 4 );
2011
2012 ClipLine( &realBBox, origin_p.x, origin_p.y, end_p.x, end_p.y );
2013 ClipLine( &realBBox, origin_m.x, origin_m.y, end_m.x, end_m.y );
2014 ClipLine( &realBBox, origin.x, origin.y, end.x, end.y );
2015
2016 spokeIter->SetPoint( 2, end_m );
2017 spokeIter->SetPoint( 3, end );
2018 spokeIter->SetPoint( 4, end_p );
2019 }
2020
2021 // Remove group membership from dummy item before deleting
2022 dummy_pad.SetParentGroup( nullptr );
2023 }
2024 }
2025
2026 for( size_t ii = 0; ii < aSpokesList.size(); ++ii )
2027 aSpokesList[ii].GenerateBBoxCache();
2028}
2029
2030
2032 PCB_LAYER_ID aDebugLayer, SHAPE_POLY_SET& aFillPolys )
2033{
2034 // Build grid:
2035
2036 // obviously line thickness must be > zone min thickness.
2037 // It can happens if a board file was edited by hand by a python script
2038 // Use 1 micron margin to be *sure* there is no issue in Gerber files
2039 // (Gbr file unit = 1 or 10 nm) due to some truncation in coordinates or calculations
2040 // This margin also avoid problems due to rounding coordinates in next calculations
2041 // that can create incorrect polygons
2042 int thickness = std::max( aZone->GetHatchThickness(),
2043 aZone->GetMinThickness() + pcbIUScale.mmToIU( 0.001 ) );
2044
2045 int linethickness = thickness - aZone->GetMinThickness();
2046 int gridsize = thickness + aZone->GetHatchGap();
2047 int maxError = m_board->GetDesignSettings().m_MaxError;
2048
2049 SHAPE_POLY_SET filledPolys = aFillPolys.CloneDropTriangulation();
2050 // Use a area that contains the rotated bbox by orientation, and after rotate the result
2051 // by -orientation.
2052 if( !aZone->GetHatchOrientation().IsZero() )
2053 filledPolys.Rotate( - aZone->GetHatchOrientation() );
2054
2055 BOX2I bbox = filledPolys.BBox( 0 );
2056
2057 // Build hole shape
2058 // the hole size is aZone->GetHatchGap(), but because the outline thickness
2059 // is aZone->GetMinThickness(), the hole shape size must be larger
2060 SHAPE_LINE_CHAIN hole_base;
2061 int hole_size = aZone->GetHatchGap() + aZone->GetMinThickness();
2062 VECTOR2I corner( 0, 0 );;
2063 hole_base.Append( corner );
2064 corner.x += hole_size;
2065 hole_base.Append( corner );
2066 corner.y += hole_size;
2067 hole_base.Append( corner );
2068 corner.x = 0;
2069 hole_base.Append( corner );
2070 hole_base.SetClosed( true );
2071
2072 // Calculate minimal area of a grid hole.
2073 // All holes smaller than a threshold will be removed
2074 double minimal_hole_area = hole_base.Area() * aZone->GetHatchHoleMinArea();
2075
2076 // Now convert this hole to a smoothed shape:
2077 if( aZone->GetHatchSmoothingLevel() > 0 )
2078 {
2079 // the actual size of chamfer, or rounded corner radius is the half size
2080 // of the HatchFillTypeGap scaled by aZone->GetHatchSmoothingValue()
2081 // aZone->GetHatchSmoothingValue() = 1.0 is the max value for the chamfer or the
2082 // radius of corner (radius = half size of the hole)
2083 int smooth_value = KiROUND( aZone->GetHatchGap()
2084 * aZone->GetHatchSmoothingValue() / 2 );
2085
2086 // Minimal optimization:
2087 // make smoothing only for reasonable smooth values, to avoid a lot of useless segments
2088 // and if the smooth value is small, use chamfer even if fillet is requested
2089 #define SMOOTH_MIN_VAL_MM 0.02
2090 #define SMOOTH_SMALL_VAL_MM 0.04
2091
2092 if( smooth_value > pcbIUScale.mmToIU( SMOOTH_MIN_VAL_MM ) )
2093 {
2094 SHAPE_POLY_SET smooth_hole;
2095 smooth_hole.AddOutline( hole_base );
2096 int smooth_level = aZone->GetHatchSmoothingLevel();
2097
2098 if( smooth_value < pcbIUScale.mmToIU( SMOOTH_SMALL_VAL_MM ) && smooth_level > 1 )
2099 smooth_level = 1;
2100
2101 // Use a larger smooth_value to compensate the outline tickness
2102 // (chamfer is not visible is smooth value < outline thickess)
2103 smooth_value += aZone->GetMinThickness() / 2;
2104
2105 // smooth_value cannot be bigger than the half size oh the hole:
2106 smooth_value = std::min( smooth_value, aZone->GetHatchGap() / 2 );
2107
2108 // the error to approximate a circle by segments when smoothing corners by a arc
2109 maxError = std::max( maxError * 2, smooth_value / 20 );
2110
2111 switch( smooth_level )
2112 {
2113 case 1:
2114 // Chamfer() uses the distance from a corner to create a end point
2115 // for the chamfer.
2116 hole_base = smooth_hole.Chamfer( smooth_value ).Outline( 0 );
2117 break;
2118
2119 default:
2120 if( aZone->GetHatchSmoothingLevel() > 2 )
2121 maxError /= 2; // Force better smoothing
2122
2123 hole_base = smooth_hole.Fillet( smooth_value, maxError ).Outline( 0 );
2124 break;
2125
2126 case 0:
2127 break;
2128 };
2129 }
2130 }
2131
2132 // Build holes
2133 SHAPE_POLY_SET holes;
2134
2135 for( int xx = 0; ; xx++ )
2136 {
2137 int xpos = xx * gridsize;
2138
2139 if( xpos > bbox.GetWidth() )
2140 break;
2141
2142 for( int yy = 0; ; yy++ )
2143 {
2144 int ypos = yy * gridsize;
2145
2146 if( ypos > bbox.GetHeight() )
2147 break;
2148
2149 // Generate hole
2150 SHAPE_LINE_CHAIN hole( hole_base );
2151 hole.Move( VECTOR2I( xpos, ypos ) );
2152 holes.AddOutline( hole );
2153 }
2154 }
2155
2156 holes.Move( bbox.GetPosition() );
2157
2158 if( !aZone->GetHatchOrientation().IsZero() )
2159 holes.Rotate( aZone->GetHatchOrientation() );
2160
2161 DUMP_POLYS_TO_COPPER_LAYER( holes, In10_Cu, wxT( "hatch-holes" ) );
2162
2163 int outline_margin = aZone->GetMinThickness() * 1.1;
2164
2165 // Using GetHatchThickness() can look more consistent than GetMinThickness().
2166 if( aZone->GetHatchBorderAlgorithm() && aZone->GetHatchThickness() > outline_margin )
2167 outline_margin = aZone->GetHatchThickness();
2168
2169 // The fill has already been deflated to ensure GetMinThickness() so we just have to
2170 // account for anything beyond that.
2171 SHAPE_POLY_SET deflatedFilledPolys = aFillPolys.CloneDropTriangulation();
2172 deflatedFilledPolys.Deflate( outline_margin - aZone->GetMinThickness(),
2173 CORNER_STRATEGY::CHAMFER_ALL_CORNERS, maxError );
2174 holes.BooleanIntersection( deflatedFilledPolys, SHAPE_POLY_SET::PM_FAST );
2175 DUMP_POLYS_TO_COPPER_LAYER( holes, In11_Cu, wxT( "fill-clipped-hatch-holes" ) );
2176
2177 SHAPE_POLY_SET deflatedOutline = aZone->Outline()->CloneDropTriangulation();
2178 deflatedOutline.Deflate( outline_margin, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, maxError );
2179 holes.BooleanIntersection( deflatedOutline, SHAPE_POLY_SET::PM_FAST );
2180 DUMP_POLYS_TO_COPPER_LAYER( holes, In12_Cu, wxT( "outline-clipped-hatch-holes" ) );
2181
2182 if( aZone->GetNetCode() != 0 )
2183 {
2184 // Vias and pads connected to the zone must not be allowed to become isolated inside
2185 // one of the holes. Effectively this means their copper outline needs to be expanded
2186 // to be at least as wide as the gap so that it is guaranteed to touch at least one
2187 // edge.
2188 BOX2I zone_boundingbox = aZone->GetBoundingBox();
2189 SHAPE_POLY_SET aprons;
2190 int min_apron_radius = ( aZone->GetHatchGap() * 10 ) / 19;
2191
2192 for( PCB_TRACK* track : m_board->Tracks() )
2193 {
2194 if( track->Type() == PCB_VIA_T )
2195 {
2196 PCB_VIA* via = static_cast<PCB_VIA*>( track );
2197
2198 if( via->GetNetCode() == aZone->GetNetCode()
2199 && via->IsOnLayer( aLayer )
2200 && via->GetBoundingBox().Intersects( zone_boundingbox ) )
2201 {
2202 int r = std::max( min_apron_radius,
2203 via->GetDrillValue() / 2 + outline_margin );
2204
2205 TransformCircleToPolygon( aprons, via->GetPosition(), r, maxError,
2206 ERROR_OUTSIDE );
2207 }
2208 }
2209 }
2210
2211 for( FOOTPRINT* footprint : m_board->Footprints() )
2212 {
2213 for( PAD* pad : footprint->Pads() )
2214 {
2215 if( pad->GetNetCode() == aZone->GetNetCode()
2216 && pad->IsOnLayer( aLayer )
2217 && pad->GetBoundingBox().Intersects( zone_boundingbox ) )
2218 {
2219 // What we want is to bulk up the pad shape so that the narrowest bit of
2220 // copper between the hole and the apron edge is at least outline_margin
2221 // wide (and that the apron itself meets min_apron_radius. But that would
2222 // take a lot of code and math, and the following approximation is close
2223 // enough.
2224 int pad_width = std::min( pad->GetSize().x, pad->GetSize().y );
2225 int slot_width = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
2226 int min_annular_ring_width = ( pad_width - slot_width ) / 2;
2227 int clearance = std::max( min_apron_radius - pad_width / 2,
2228 outline_margin - min_annular_ring_width );
2229
2230 clearance = std::max( 0, clearance - linethickness / 2 );
2231 pad->TransformShapeToPolygon( aprons, aLayer, clearance, maxError,
2232 ERROR_OUTSIDE );
2233 }
2234 }
2235 }
2236
2238 }
2239 DUMP_POLYS_TO_COPPER_LAYER( holes, In13_Cu, wxT( "pad-via-clipped-hatch-holes" ) );
2240
2241 // Now filter truncated holes to avoid small holes in pattern
2242 // It happens for holes near the zone outline
2243 for( int ii = 0; ii < holes.OutlineCount(); )
2244 {
2245 double area = holes.Outline( ii ).Area();
2246
2247 if( area < minimal_hole_area ) // The current hole is too small: remove it
2248 holes.DeletePolygon( ii );
2249 else
2250 ++ii;
2251 }
2252
2253 // create grid. Use SHAPE_POLY_SET::PM_STRICTLY_SIMPLE to
2254 // generate strictly simple polygons needed by Gerber files and Fracture()
2255 aFillPolys.BooleanSubtract( aFillPolys, holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
2256 DUMP_POLYS_TO_COPPER_LAYER( aFillPolys, In14_Cu, wxT( "after-hatching" ) );
2257
2258 return true;
2259}
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:2380
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:680
const ZONES & Zones() const
Definition: board.h:327
int GetMaxClearanceValue() const
Returns the maximum clearance value for any object on the board.
Definition: board.h:1157
int GetCopperLayerCount() const
Definition: board.cpp:656
const FOOTPRINTS & Footprints() const
Definition: board.h:323
const TRACKS & Tracks() const
Definition: board.h:321
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
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 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: confirm.h:47
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:57
int ShowModal() override
Definition: confirm.cpp:100
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:59
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition: pad.cpp:796
void SetOffset(const VECTOR2I &aOffset)
Definition: pad.h:263
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:1798
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: pad.h:211
void SetPosition(const VECTOR2I &aPos) override
Definition: pad.h:195
PAD_SHAPE GetShape() const
Definition: pad.h:193
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation angle of the pad.
Definition: pad.cpp:852
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:1781
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:626
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:350
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: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
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
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.
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
@ CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL
Definition: pad.h:46
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:588
#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