KiCad PCB EDA Suite
drc_test_provider_physical_clearance.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) 2021-2022 KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <common.h>
25#include <macros.h>
27#include <footprint.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <pcb_shape.h>
31#include <zone.h>
32#include <advanced_config.h>
33#include <geometry/seg.h>
35#include <drc/drc_engine.h>
36#include <drc/drc_rtree.h>
37#include <drc/drc_item.h>
38#include <drc/drc_rule.h>
40
41/*
42 Physical clearance tests.
43
44 Errors generated:
45 - DRCE_PHYSICAL_CLEARANCE
46 - DRCE_PHYSICAL_HOLE_CLEARANCE
47*/
48
50{
51public:
54 {
55 }
56
58 {
59 }
60
61 virtual bool Run() override;
62
63 virtual const wxString GetName() const override
64 {
65 return wxT( "physical_clearance" );
66 };
67
68 virtual const wxString GetDescription() const override
69 {
70 return wxT( "Tests item clearances irrespective of nets" );
71 }
72
73private:
74 bool testItemAgainstItem( BOARD_ITEM* aItem, SHAPE* aItemShape, PCB_LAYER_ID aLayer,
75 BOARD_ITEM* other );
76
77 void testItemAgainstZones( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
78
79 void testShapeLineChain( const SHAPE_LINE_CHAIN& aOutline, int aLineWidth, PCB_LAYER_ID aLayer,
80 BOARD_ITEM* aParentItem, DRC_CONSTRAINT& aConstraint );
81
82 void testZoneLayer( ZONE* aZone, PCB_LAYER_ID aLayer, DRC_CONSTRAINT& aConstraint );
83
84private:
86};
87
88
90{
93
94 int errorMax = m_board->GetDesignSettings().m_MaxError;
95
97 {
98 reportAux( wxT( "No physical clearance constraints found. Tests not run." ) );
99 return true; // continue with other tests
100 }
101
102 reportAux( wxT( "Largest physical clearance : %d nm" ), m_board->m_DRCMaxPhysicalClearance );
103
104 size_t progressDelta = 250;
105 size_t count = 0;
106 size_t ii = 0;
107
108 if( !reportPhase( _( "Gathering physical items..." ) ) )
109 return false; // DRC cancelled
110
111 static const std::vector<KICAD_T> itemTypes = {
114 PCB_PAD_T,
118 };
119
120 static const LSET courtyards( 2, F_CrtYd, B_CrtYd );
121
122 //
123 // Generate a count for use in progress reporting.
124 //
125
127 [&]( BOARD_ITEM* item ) -> bool
128 {
129 ++count;
130 return true;
131 } );
132
133 //
134 // Generate a BOARD_ITEM RTree.
135 //
136
138 [&]( BOARD_ITEM* item ) -> bool
139 {
140 if( !reportProgress( ii++, count, progressDelta ) )
141 return false;
142
143 LSET layers = item->GetLayerSet();
144
145 // Special-case holes and edge-cuts which pierce all physical layers
146 if( item->HasHole() )
147 {
148 layers |= LSET::PhysicalLayersMask() | courtyards;
149 }
150 else if( item->Type() == PCB_FOOTPRINT_T )
151 {
152 layers = courtyards;
153 }
154 else if( item->IsOnLayer( Edge_Cuts ) )
155 {
156 layers |= LSET::PhysicalLayersMask() | courtyards;
157 }
158
159 for( PCB_LAYER_ID layer : layers.Seq() )
161
162 return true;
163 } );
164
165 std::unordered_map<PTR_PTR_CACHE_KEY, LSET> checkedPairs;
166 progressDelta = 100;
167 ii = 0;
168
169 //
170 // Run clearance checks -between- items.
171 //
172
175 {
176 if( !reportPhase( _( "Checking physical clearances..." ) ) )
177 return false; // DRC cancelled
178
180 [&]( BOARD_ITEM* item ) -> bool
181 {
182 if( !reportProgress( ii++, count, progressDelta ) )
183 return false;
184
185 LSET layers = item->GetLayerSet();
186
187 if( item->Type() == PCB_FOOTPRINT_T )
188 layers = courtyards;
189
190 for( PCB_LAYER_ID layer : layers.Seq() )
191 {
192 std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape( layer );
193
194 m_itemTree.QueryColliding( item, layer, layer,
195 // Filter:
196 [&]( BOARD_ITEM* other ) -> bool
197 {
198 BOARD_ITEM* a = item;
199 BOARD_ITEM* b = other;
200
201 // store canonical order so we don't collide in both
202 // directions (a:b and b:a)
203 if( static_cast<void*>( a ) > static_cast<void*>( b ) )
204 std::swap( a, b );
205
206 auto it = checkedPairs.find( { a, b } );
207
208 if( it != checkedPairs.end() && it->second.test( layer ) )
209 {
210 return false;
211 }
212 else
213 {
214 checkedPairs[ { a, b } ].set( layer );
215 return true;
216 }
217 },
218 // Visitor:
219 [&]( BOARD_ITEM* other ) -> bool
220 {
221 return testItemAgainstItem( item, itemShape.get(), layer,
222 other );
223 },
225
226 testItemAgainstZones( item, layer );
227 }
228
229 return true;
230 } );
231 }
232
233 progressDelta = 100;
234 count = 0;
235 ii = 0;
236
237 //
238 // Generate a count for progress reporting.
239 //
240
241 forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
243 [&]( BOARD_ITEM* item ) -> bool
244 {
245 ZONE* zone = dynamic_cast<ZONE*>( item );
246
247 if( zone && zone->GetIsRuleArea() )
248 return true; // Continue with other items
249
250 count += ( item->GetLayerSet() & LSET::AllCuMask() ).count();
251
252 return true;
253 } );
254
255 //
256 // Run clearance checks -within- polygonal items.
257 //
258
259 forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
261 [&]( BOARD_ITEM* item ) -> bool
262 {
263 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
264 ZONE* zone = dynamic_cast<ZONE*>( item );
265
266 if( zone && zone->GetIsRuleArea() )
267 return true; // Continue with other items
268
269 for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
270 {
271 if( IsCopperLayer( layer ) )
272 {
273 if( !reportProgress( ii++, count, progressDelta ) )
274 return false;
275
276 DRC_CONSTRAINT c = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT,
277 item, nullptr, layer );
278
279 if( shape )
280 {
281 switch( shape->GetShape() )
282 {
283 case SHAPE_T::POLY:
284 testShapeLineChain( shape->GetPolyShape().Outline( 0 ),
285 shape->GetWidth(), layer, item, c );
286 break;
287
288 case SHAPE_T::BEZIER:
289 {
290 SHAPE_LINE_CHAIN asPoly;
291
293
294 for( const VECTOR2I& pt : shape->GetBezierPoints() )
295 asPoly.Append( pt );
296
297 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
298 break;
299 }
300
301 case SHAPE_T::ARC:
302 {
303 SHAPE_LINE_CHAIN asPoly;
304
305 VECTOR2I center = shape->GetCenter();
306 EDA_ANGLE angle = -shape->GetArcAngle();
307 double r = shape->GetRadius();
308 int steps = GetArcToSegmentCount( r, errorMax, angle );
309
310 asPoly.Append( shape->GetStart() );
311
312 for( int step = 1; step <= steps; ++step )
313 {
314 EDA_ANGLE rotation = ( angle * step ) / steps;
315 VECTOR2I pt = shape->GetStart();
316
317 RotatePoint( pt, center, rotation );
318 asPoly.Append( pt );
319 }
320
321 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
322 break;
323 }
324
325 case SHAPE_T::RECT:
326 {
327 SHAPE_LINE_CHAIN asPoly;
328 std::vector<VECTOR2I> pts = shape->GetRectCorners();
329 asPoly.Append( pts[0] );
330 asPoly.Append( pts[1] );
331 asPoly.Append( pts[2] );
332 asPoly.Append( pts[3] );
333 asPoly.SetClosed( true );
334
335 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
336 break;
337 }
338
339 default:
341 }
342 }
343
344 if( zone )
345 testZoneLayer( static_cast<ZONE*>( item ), layer, c );
346 }
347
348 if( m_drcEngine->IsCancelled() )
349 return false;
350 }
351
352 return !m_drcEngine->IsCancelled();
353 } );
354
355 reportRuleStatistics();
356
357 return !m_drcEngine->IsCancelled();
358}
359
360
362 int aLineWidth, PCB_LAYER_ID aLayer,
363 BOARD_ITEM* aParentItem,
364 DRC_CONSTRAINT& aConstraint )
365{
366 // We don't want to collide with neighboring segments forming a curve until the concavity
367 // approaches 180 degrees.
368 double angleTolerance = DEG2RAD( 180.0 - ADVANCED_CFG::GetCfg().m_SliverAngleTolerance );
369 int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
370 int count = aOutline.SegmentCount();
371 int clearance = aConstraint.GetValue().Min();
372
373 if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
374 return;
375
376 // Trigonometry is not cheap; cache seg angles
377 std::vector<double> angles;
378 angles.reserve( count );
379
380 auto angleDiff =
381 []( double a, double b ) -> double
382 {
383 if( a > b )
384 std::swap( a, b );
385
386 double diff = b - a;
387
388 if( diff > M_PI )
389 return 2 * M_PI - diff;
390 else
391 return diff;
392 };
393
394 for( int ii = 0; ii < count; ++ii )
395 {
396 const SEG& seg = aOutline.CSegment( ii );
397
398 // NB: don't store angles of really short segments (which could point anywhere)
399
400 if( seg.SquaredLength() > SEG::Square( epsilon * 2 ) )
401 {
402 angles.push_back( EDA_ANGLE( seg.B - seg.A ).AsRadians() );
403 }
404 else if( ii > 0 )
405 {
406 angles.push_back( angles.back() );
407 }
408 else
409 {
410 for( int jj = 1; jj < count; ++jj )
411 {
412 const SEG& following = aOutline.CSegment( jj );
413
414 if( following.SquaredLength() > SEG::Square( epsilon * 2 ) || jj == count - 1 )
415 {
416 angles.push_back( EDA_ANGLE( following.B - following.A ).AsRadians() );
417 break;
418 }
419 }
420 }
421 }
422
423 // Find collisions before reporting so that we can condense them into fewer reports.
424 std::vector< std::pair<VECTOR2I, int> > collisions;
425
426 for( int ii = 0; ii < count; ++ii )
427 {
428 const SEG seg = aOutline.CSegment( ii );
429 double segAngle = angles[ ii ];
430
431 // Exclude segments on either side of us until we reach the angle tolerance
432 int firstCandidate = ii + 1;
433 int lastCandidate = count - 1;
434
435 while( firstCandidate < count )
436 {
437 if( angleDiff( segAngle, angles[ firstCandidate ] ) < angleTolerance )
438 firstCandidate++;
439 else
440 break;
441 }
442
443 if( aOutline.IsClosed() )
444 {
445 if( ii > 0 )
446 lastCandidate = ii - 1;
447
448 while( lastCandidate != std::min( firstCandidate, count - 1 ) )
449 {
450 if( angleDiff( segAngle, angles[ lastCandidate ] ) < angleTolerance )
451 lastCandidate = ( lastCandidate == 0 ) ? count - 1 : lastCandidate - 1;
452 else
453 break;
454 }
455 }
456
457 // Now run the collision between seg and each candidate seg in the candidate range.
458 if( lastCandidate < ii )
459 lastCandidate = count - 1;
460
461 for( int jj = firstCandidate; jj <= lastCandidate; ++jj )
462 {
463 const SEG candidate = aOutline.CSegment( jj );
464 int actual;
465
466 if( seg.Collide( candidate, clearance + aLineWidth - epsilon, &actual ) )
467 {
468 VECTOR2I firstPoint = seg.NearestPoint( candidate );
469 VECTOR2I secondPoint = candidate.NearestPoint( seg );
470 VECTOR2I pos = ( firstPoint + secondPoint ) / 2;
471
472 if( !collisions.empty() &&
473 ( pos - collisions.back().first ).EuclideanNorm() < clearance * 2 )
474 {
475 if( actual < collisions.back().second )
476 {
477 collisions.back().first = pos;
478 collisions.back().second = actual;
479 }
480
481 continue;
482 }
483
484 collisions.push_back( { pos, actual } );
485 }
486 }
487 }
488
489 for( std::pair<VECTOR2I, int> collision : collisions )
490 {
491 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
492 VECTOR2I pt = collision.first;
493
494 if( aParentItem->GetParentFootprint() )
495 pt += aParentItem->GetParentFootprint()->GetPosition();
496
497 wxString msg = formatMsg( _( "Internal clearance violation (%s clearance %s; actual %s)" ),
498 aConstraint.GetName(),
499 clearance,
500 collision.second );
501
502 drce->SetErrorMessage( msg );
503 drce->SetItems( aParentItem );
504 drce->SetViolatingRule( aConstraint.GetParentRule() );
505
506 reportViolation( drce, pt, aLayer );
507 }
508}
509
510
512 DRC_CONSTRAINT& aConstraint )
513{
514 int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
515 int clearance = aConstraint.GetValue().Min();
516
517 if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
518 return;
519
520 SHAPE_POLY_SET fill = aZone->GetFilledPolysList( aLayer )->CloneDropTriangulation();
521
522 // Turn fractured fill into outlines and holes
524
525 for( int outlineIdx = 0; outlineIdx < fill.OutlineCount(); ++outlineIdx )
526 {
527 SHAPE_LINE_CHAIN* firstOutline = &fill.Outline( outlineIdx );
528
529 //
530 // Step one: outline to outline clearance violations
531 //
532
533 for( int ii = outlineIdx + 1; ii < fill.OutlineCount(); ++ii )
534 {
535 SHAPE_LINE_CHAIN* secondOutline = &fill.Outline( ii );
536
537 for( int jj = 0; jj < secondOutline->SegmentCount(); ++jj )
538 {
539 SEG secondSeg = secondOutline->Segment( jj );
540 int actual;
541 VECTOR2I pos;
542
543 if( firstOutline->Collide( secondSeg, clearance - epsilon, &actual, &pos ) )
544 {
545 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
546 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
547 aConstraint.GetName(),
548 clearance,
549 actual );
550
551 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
552 drce->SetItems( aZone );
553 drce->SetViolatingRule( aConstraint.GetParentRule() );
554
555 reportViolation( drce, pos, aLayer );
556 }
557 }
558
559 if( m_drcEngine->IsCancelled() )
560 return;
561 }
562
563 //
564 // Step two: interior hole clearance violations
565 //
566
567 for( int holeIdx = 0; holeIdx < fill.HoleCount( outlineIdx ); ++holeIdx )
568 {
569 testShapeLineChain( fill.Hole( outlineIdx, holeIdx ), 0, aLayer, aZone, aConstraint );
570
571 if( m_drcEngine->IsCancelled() )
572 return;
573 }
574 }
575}
576
577
579 SHAPE* aItemShape,
580 PCB_LAYER_ID aLayer,
581 BOARD_ITEM* other )
582{
583 bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
585 DRC_CONSTRAINT constraint;
586 int clearance = 0;
587 int actual;
588 VECTOR2I pos;
589
590 std::shared_ptr<SHAPE> otherShape = other->GetEffectiveShape( aLayer );
591
592 if( testClearance )
593 {
594 constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, other, aLayer );
595 clearance = constraint.GetValue().Min();
596 }
597
598 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
599 {
600 if( aItemShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
601 {
602 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
603 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
604 constraint.GetName(),
605 clearance,
606 actual );
607
608 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
609 drce->SetItems( aItem, other );
610 drce->SetViolatingRule( constraint.GetParentRule() );
611
612 reportViolation( drce, pos, aLayer );
613 }
614 }
615
616 if( testHoles )
617 {
618 std::shared_ptr<SHAPE_SEGMENT> itemHoleShape;
619 std::shared_ptr<SHAPE_SEGMENT> otherHoleShape;
620 clearance = 0;
621
622 if( aItem->Type() == PCB_VIA_T )
623 {
624 if( aItem->GetLayerSet().Contains( aLayer ) )
625 itemHoleShape = aItem->GetEffectiveHoleShape();
626 }
627 else if( aItem->HasHole() )
628 {
629 itemHoleShape = aItem->GetEffectiveHoleShape();
630 }
631
632 if( other->Type() == PCB_VIA_T )
633 {
634 if( other->GetLayerSet().Contains( aLayer ) )
635 otherHoleShape = other->GetEffectiveHoleShape();
636 }
637 else if( other->HasHole() )
638 {
639 otherHoleShape = other->GetEffectiveHoleShape();
640 }
641
642 if( itemHoleShape || otherHoleShape )
643 {
644 constraint = m_drcEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT, other, aItem,
645 aLayer );
646 clearance = constraint.GetValue().Min();
647 }
648
649 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
650 {
651 if( itemHoleShape && itemHoleShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
652 {
653 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
654 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
655 constraint.GetName(),
656 clearance ,
657 actual );
658
659 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
660 drce->SetItems( aItem, other );
661 drce->SetViolatingRule( constraint.GetParentRule() );
662
663 reportViolation( drce, pos, aLayer );
664 }
665
666 if( otherHoleShape && otherHoleShape->Collide( aItemShape, clearance, &actual, &pos ) )
667 {
668 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
669 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
670 constraint.GetName(),
671 clearance,
672 actual );
673
674 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
675 drce->SetItems( aItem, other );
676 drce->SetViolatingRule( constraint.GetParentRule() );
677
678 reportViolation( drce, pos, aLayer );
679 }
680 }
681 }
682
683 return !m_drcEngine->IsCancelled();
684}
685
686
688 PCB_LAYER_ID aLayer )
689{
690 for( ZONE* zone : m_board->m_DRCZones )
691 {
692 if( !zone->GetLayerSet().test( aLayer ) )
693 continue;
694
695 BOX2I itemBBox = aItem->GetBoundingBox();
696 BOX2I worstCaseBBox = itemBBox;
697
698 worstCaseBBox.Inflate( m_board->m_DRCMaxClearance );
699
700 if( !worstCaseBBox.Intersects( zone->GetBoundingBox() ) )
701 continue;
702
703 bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
705
706 if( !testClearance && !testHoles )
707 return;
708
709 DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ zone ].get();
710 DRC_CONSTRAINT constraint;
711 bool colliding;
712 int clearance = -1;
713 int actual;
714 VECTOR2I pos;
715
716 if( testClearance )
717 {
718 constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, zone,
719 aLayer );
720 clearance = constraint.GetValue().Min();
721 }
722
723 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
724 {
725 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aLayer );
726
727 if( aItem->Type() == PCB_PAD_T )
728 {
729 PAD* pad = static_cast<PAD*>( aItem );
730
731 if( !pad->FlashLayer( aLayer ) )
732 {
733 if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
734 continue;
735
736 std::shared_ptr<SHAPE_SEGMENT> hole = pad->GetEffectiveHoleShape();
737 int size = hole->GetWidth();
738
739 itemShape = std::make_shared<SHAPE_SEGMENT>( hole->GetSeg(), size );
740 }
741 }
742
743 if( zoneTree )
744 {
745 colliding = zoneTree->QueryColliding( itemBBox, itemShape.get(), aLayer, clearance,
746 &actual, &pos );
747 }
748 else
749 {
750 colliding = zone->Outline()->Collide( itemShape.get(), clearance, &actual, &pos );
751 }
752
753 if( colliding )
754 {
755 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
756 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
757 constraint.GetName(),
758 clearance,
759 actual );
760
761 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
762 drce->SetItems( aItem, zone );
763 drce->SetViolatingRule( constraint.GetParentRule() );
764
765 reportViolation( drce, pos, aLayer );
766 }
767 }
768
769 if( testHoles )
770 {
771 std::shared_ptr<SHAPE_SEGMENT> holeShape;
772
773 if( aItem->Type() == PCB_VIA_T )
774 {
775 if( aItem->GetLayerSet().Contains( aLayer ) )
776 holeShape = aItem->GetEffectiveHoleShape();
777 }
778 else if( aItem->HasHole() )
779 {
780 holeShape = aItem->GetEffectiveHoleShape();
781 }
782
783 if( holeShape )
784 {
786 zone, aLayer );
787 clearance = constraint.GetValue().Min();
788
789 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE
790 && clearance > 0
791 && zoneTree->QueryColliding( itemBBox, holeShape.get(), aLayer, clearance,
792 &actual, &pos ) )
793 {
794 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
795 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
796 constraint.GetName(),
797 clearance,
798 actual );
799
800 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
801 drce->SetItems( aItem, zone );
802 drce->SetViolatingRule( constraint.GetParentRule() );
803
804 reportViolation( drce, pos, aLayer );
805 }
806 }
807 }
808
809 if( m_drcEngine->IsCancelled() )
810 return;
811 }
812}
813
814
815namespace detail
816{
818}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:245
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:219
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:185
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Definition: board_item.cpp:239
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:229
virtual bool HasHole() const
Definition: board_item.h:128
int m_DRCMaxPhysicalClearance
Definition: board.h:1153
int m_DRCMaxClearance
Definition: board.h:1152
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1145
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
std::vector< ZONE * > m_DRCZones
Definition: board.h:1150
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:269
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
wxString GetName() const
Definition: drc_rule.h:147
SEVERITY GetSeverity() const
Definition: drc_rule.h:160
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:139
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:143
BOARD * GetBoard() const
Definition: drc_engine.h:89
bool IsErrorLimitExceeded(int error_code)
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:671
bool IsCancelled() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:325
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:48
void Insert(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, int aWorstClearance=0)
Insert an item into the tree on a particular layer with an optional worst clearance.
Definition: drc_rtree.h:104
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
Definition: drc_rtree.h:211
void clear()
Remove all items from the RTree.
Definition: drc_rtree.h:166
bool testItemAgainstItem(BOARD_ITEM *aItem, SHAPE *aItemShape, PCB_LAYER_ID aLayer, BOARD_ITEM *other)
void testZoneLayer(ZONE *aZone, PCB_LAYER_ID aLayer, DRC_CONSTRAINT &aConstraint)
void testItemAgainstZones(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
virtual const wxString GetName() const override
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
void testShapeLineChain(const SHAPE_LINE_CHAIN &aOutline, int aLineWidth, PCB_LAYER_ID aLayer, BOARD_ITEM *aParentItem, DRC_CONSTRAINT &aConstraint)
virtual const wxString GetDescription() const override
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
virtual void reportAux(wxString fmt,...)
DRC_ENGINE * m_drcEngine
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, int aConstraint, int aActual)
double AsRadians() const
Definition: eda_angle.h:153
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:251
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:573
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:405
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
int GetRadius() const
Definition: eda_shape.cpp:511
SHAPE_T GetShape() const
Definition: eda_shape.h:113
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1023
int GetWidth() const
Definition: eda_shape.h:109
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition: eda_shape.h:230
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:75
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
static LSET AllLayersMask()
Definition: lset.cpp:808
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:600
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
T Min() const
Definition: minoptmax.h:33
Definition: pad.h:59
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:67
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.cpp:261
static SEG::ecoord Square(int a)
Definition: seg.h:123
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
Definition: seg.cpp:223
ecoord SquaredLength() const
Definition: seg.h:331
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
SEG Segment(int aIndex)
Return a copy of the aIndex-th segment in the line chain.
Represent a set of closed polygons.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
void Simplify(POLYGON_MODE aFastMode)
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the aIndex-th subpolygon in the set.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
An abstract shape on 2D plane.
Definition: shape.h:123
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:178
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:602
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:320
SHAPE_POLY_SET * Outline()
Definition: zone.h:312
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
The common library.
@ DRCE_HOLE_CLEARANCE
Definition: drc_item.h:53
@ DRCE_CLEARANCE
Definition: drc_item.h:43
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:70
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:69
#define _(s)
E_SERIE r
Definition: eserie.cpp:41
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:825
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ F_CrtYd
Definition: layer_ids.h:117
@ Edge_Cuts
Definition: layer_ids.h:113
@ B_CrtYd
Definition: layer_ids.h:116
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
double DEG2RAD(double deg)
Definition: trigo.h:195
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101