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 int 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 if( testItemAgainstItem( item, itemShape.get(), layer,
222 other ) > 0 )
223 {
224 BOARD_ITEM* a = item;
225 BOARD_ITEM* b = other;
226
227 // store canonical order
228 if( static_cast<void*>( a ) > static_cast<void*>( b ) )
229 std::swap( a, b );
230
231 // Once we record one DRC for error for physical clearance
232 // we don't need to record more
233 checkedPairs[ { a, b } ].set();
234 }
235
236 return !m_drcEngine->IsCancelled();
237 },
239
240 testItemAgainstZones( item, layer );
241 }
242
243 return true;
244 } );
245 }
246
247 progressDelta = 100;
248 count = 0;
249 ii = 0;
250
251 //
252 // Generate a count for progress reporting.
253 //
254
255 forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
257 [&]( BOARD_ITEM* item ) -> bool
258 {
259 ZONE* zone = dynamic_cast<ZONE*>( item );
260
261 if( zone && zone->GetIsRuleArea() )
262 return true; // Continue with other items
263
264 count += ( item->GetLayerSet() & LSET::AllCuMask() ).count();
265
266 return true;
267 } );
268
269 //
270 // Run clearance checks -within- polygonal items.
271 //
272
273 forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
275 [&]( BOARD_ITEM* item ) -> bool
276 {
277 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
278 ZONE* zone = dynamic_cast<ZONE*>( item );
279
280 if( zone && zone->GetIsRuleArea() )
281 return true; // Continue with other items
282
283 for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
284 {
285 if( IsCopperLayer( layer ) )
286 {
287 if( !reportProgress( ii++, count, progressDelta ) )
288 return false;
289
290 DRC_CONSTRAINT c = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT,
291 item, nullptr, layer );
292
293 if( shape )
294 {
295 switch( shape->GetShape() )
296 {
297 case SHAPE_T::POLY:
298 testShapeLineChain( shape->GetPolyShape().Outline( 0 ),
299 shape->GetWidth(), layer, item, c );
300 break;
301
302 case SHAPE_T::BEZIER:
303 {
304 SHAPE_LINE_CHAIN asPoly;
305
307
308 for( const VECTOR2I& pt : shape->GetBezierPoints() )
309 asPoly.Append( pt );
310
311 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
312 break;
313 }
314
315 case SHAPE_T::ARC:
316 {
317 SHAPE_LINE_CHAIN asPoly;
318
319 VECTOR2I center = shape->GetCenter();
320 EDA_ANGLE angle = -shape->GetArcAngle();
321 double r = shape->GetRadius();
322 int steps = GetArcToSegmentCount( r, errorMax, angle );
323
324 asPoly.Append( shape->GetStart() );
325
326 for( int step = 1; step <= steps; ++step )
327 {
328 EDA_ANGLE rotation = ( angle * step ) / steps;
329 VECTOR2I pt = shape->GetStart();
330
331 RotatePoint( pt, center, rotation );
332 asPoly.Append( pt );
333 }
334
335 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
336 break;
337 }
338
339 case SHAPE_T::RECT:
340 {
341 SHAPE_LINE_CHAIN asPoly;
342 std::vector<VECTOR2I> pts = shape->GetRectCorners();
343 asPoly.Append( pts[0] );
344 asPoly.Append( pts[1] );
345 asPoly.Append( pts[2] );
346 asPoly.Append( pts[3] );
347 asPoly.SetClosed( true );
348
349 testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
350 break;
351 }
352
353 default:
355 }
356 }
357
358 if( zone )
359 testZoneLayer( static_cast<ZONE*>( item ), layer, c );
360 }
361
362 if( m_drcEngine->IsCancelled() )
363 return false;
364 }
365
366 return !m_drcEngine->IsCancelled();
367 } );
368
369 reportRuleStatistics();
370
371 return !m_drcEngine->IsCancelled();
372}
373
374
376 int aLineWidth, PCB_LAYER_ID aLayer,
377 BOARD_ITEM* aParentItem,
378 DRC_CONSTRAINT& aConstraint )
379{
380 // We don't want to collide with neighboring segments forming a curve until the concavity
381 // approaches 180 degrees.
382 double angleTolerance = DEG2RAD( 180.0 - ADVANCED_CFG::GetCfg().m_SliverAngleTolerance );
383 int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
384 int count = aOutline.SegmentCount();
385 int clearance = aConstraint.GetValue().Min();
386
387 if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
388 return;
389
390 // Trigonometry is not cheap; cache seg angles
391 std::vector<double> angles;
392 angles.reserve( count );
393
394 auto angleDiff =
395 []( double a, double b ) -> double
396 {
397 if( a > b )
398 std::swap( a, b );
399
400 double diff = b - a;
401
402 if( diff > M_PI )
403 return 2 * M_PI - diff;
404 else
405 return diff;
406 };
407
408 for( int ii = 0; ii < count; ++ii )
409 {
410 const SEG& seg = aOutline.CSegment( ii );
411
412 // NB: don't store angles of really short segments (which could point anywhere)
413
414 if( seg.SquaredLength() > SEG::Square( epsilon * 2 ) )
415 {
416 angles.push_back( EDA_ANGLE( seg.B - seg.A ).AsRadians() );
417 }
418 else if( ii > 0 )
419 {
420 angles.push_back( angles.back() );
421 }
422 else
423 {
424 for( int jj = 1; jj < count; ++jj )
425 {
426 const SEG& following = aOutline.CSegment( jj );
427
428 if( following.SquaredLength() > SEG::Square( epsilon * 2 ) || jj == count - 1 )
429 {
430 angles.push_back( EDA_ANGLE( following.B - following.A ).AsRadians() );
431 break;
432 }
433 }
434 }
435 }
436
437 // Find collisions before reporting so that we can condense them into fewer reports.
438 std::vector< std::pair<VECTOR2I, int> > collisions;
439
440 for( int ii = 0; ii < count; ++ii )
441 {
442 const SEG seg = aOutline.CSegment( ii );
443 double segAngle = angles[ ii ];
444
445 // Exclude segments on either side of us until we reach the angle tolerance
446 int firstCandidate = ii + 1;
447 int lastCandidate = count - 1;
448
449 while( firstCandidate < count )
450 {
451 if( angleDiff( segAngle, angles[ firstCandidate ] ) < angleTolerance )
452 firstCandidate++;
453 else
454 break;
455 }
456
457 if( aOutline.IsClosed() )
458 {
459 if( ii > 0 )
460 lastCandidate = ii - 1;
461
462 while( lastCandidate != std::min( firstCandidate, count - 1 ) )
463 {
464 if( angleDiff( segAngle, angles[ lastCandidate ] ) < angleTolerance )
465 lastCandidate = ( lastCandidate == 0 ) ? count - 1 : lastCandidate - 1;
466 else
467 break;
468 }
469 }
470
471 // Now run the collision between seg and each candidate seg in the candidate range.
472 if( lastCandidate < ii )
473 lastCandidate = count - 1;
474
475 for( int jj = firstCandidate; jj <= lastCandidate; ++jj )
476 {
477 const SEG candidate = aOutline.CSegment( jj );
478 int actual;
479
480 if( seg.Collide( candidate, clearance + aLineWidth - epsilon, &actual ) )
481 {
482 VECTOR2I firstPoint = seg.NearestPoint( candidate );
483 VECTOR2I secondPoint = candidate.NearestPoint( seg );
484 VECTOR2I pos = ( firstPoint + secondPoint ) / 2;
485
486 if( !collisions.empty() &&
487 ( pos - collisions.back().first ).EuclideanNorm() < clearance * 2 )
488 {
489 if( actual < collisions.back().second )
490 {
491 collisions.back().first = pos;
492 collisions.back().second = actual;
493 }
494
495 continue;
496 }
497
498 collisions.push_back( { pos, actual } );
499 }
500 }
501 }
502
503 for( std::pair<VECTOR2I, int> collision : collisions )
504 {
505 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
506 VECTOR2I pt = collision.first;
507
508 if( aParentItem->GetParentFootprint() )
509 pt += aParentItem->GetParentFootprint()->GetPosition();
510
511 wxString msg = formatMsg( _( "Internal clearance violation (%s clearance %s; actual %s)" ),
512 aConstraint.GetName(),
513 clearance,
514 collision.second );
515
516 drce->SetErrorMessage( msg );
517 drce->SetItems( aParentItem );
518 drce->SetViolatingRule( aConstraint.GetParentRule() );
519
520 reportViolation( drce, pt, aLayer );
521 }
522}
523
524
526 DRC_CONSTRAINT& aConstraint )
527{
528 int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
529 int clearance = aConstraint.GetValue().Min();
530
531 if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
532 return;
533
534 SHAPE_POLY_SET fill = aZone->GetFilledPolysList( aLayer )->CloneDropTriangulation();
535
536 // Turn fractured fill into outlines and holes
538
539 for( int outlineIdx = 0; outlineIdx < fill.OutlineCount(); ++outlineIdx )
540 {
541 SHAPE_LINE_CHAIN* firstOutline = &fill.Outline( outlineIdx );
542
543 //
544 // Step one: outline to outline clearance violations
545 //
546
547 for( int ii = outlineIdx + 1; ii < fill.OutlineCount(); ++ii )
548 {
549 SHAPE_LINE_CHAIN* secondOutline = &fill.Outline( ii );
550
551 for( int jj = 0; jj < secondOutline->SegmentCount(); ++jj )
552 {
553 SEG secondSeg = secondOutline->Segment( jj );
554 int actual;
555 VECTOR2I pos;
556
557 if( firstOutline->Collide( secondSeg, clearance - epsilon, &actual, &pos ) )
558 {
559 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
560 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
561 aConstraint.GetName(),
562 clearance,
563 actual );
564
565 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
566 drce->SetItems( aZone );
567 drce->SetViolatingRule( aConstraint.GetParentRule() );
568
569 reportViolation( drce, pos, aLayer );
570 }
571 }
572
573 if( m_drcEngine->IsCancelled() )
574 return;
575 }
576
577 //
578 // Step two: interior hole clearance violations
579 //
580
581 for( int holeIdx = 0; holeIdx < fill.HoleCount( outlineIdx ); ++holeIdx )
582 {
583 testShapeLineChain( fill.Hole( outlineIdx, holeIdx ), 0, aLayer, aZone, aConstraint );
584
585 if( m_drcEngine->IsCancelled() )
586 return;
587 }
588 }
589}
590
591
593 SHAPE* aItemShape,
594 PCB_LAYER_ID aLayer,
595 BOARD_ITEM* other )
596{
597 bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
599 DRC_CONSTRAINT constraint;
600 int clearance = 0;
601 int actual;
602 int violations = 0;
603 VECTOR2I pos;
604
605 std::shared_ptr<SHAPE> otherShape = other->GetEffectiveShape( aLayer );
606
607 if( testClearance )
608 {
609 constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, other, aLayer );
610 clearance = constraint.GetValue().Min();
611 }
612
613 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
614 {
615 if( aItemShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
616 {
617 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
618 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
619 constraint.GetName(),
620 clearance,
621 actual );
622
623 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
624 drce->SetItems( aItem, other );
625 drce->SetViolatingRule( constraint.GetParentRule() );
626
627 reportViolation( drce, pos, aLayer );
628 ++violations;
629 }
630 }
631
632 if( testHoles )
633 {
634 std::shared_ptr<SHAPE_SEGMENT> itemHoleShape;
635 std::shared_ptr<SHAPE_SEGMENT> otherHoleShape;
636 clearance = 0;
637
638 if( aItem->Type() == PCB_VIA_T )
639 {
640 if( aItem->GetLayerSet().Contains( aLayer ) )
641 itemHoleShape = aItem->GetEffectiveHoleShape();
642 else
643 return violations;
644 }
645 else if( aItem->HasHole() )
646 {
647 itemHoleShape = aItem->GetEffectiveHoleShape();
648 }
649
650 if( other->Type() == PCB_VIA_T )
651 {
652 if( other->GetLayerSet().Contains( aLayer ) )
653 otherHoleShape = other->GetEffectiveHoleShape();
654 else
655 return violations;
656 }
657 else if( other->HasHole() )
658 {
659 otherHoleShape = other->GetEffectiveHoleShape();
660 }
661
662 if( itemHoleShape || otherHoleShape )
663 {
664 constraint = m_drcEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT, other, aItem,
665 aLayer );
666 clearance = constraint.GetValue().Min();
667 }
668
669 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
670 {
671 if( itemHoleShape && itemHoleShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
672 {
673 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
674 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
675 constraint.GetName(),
676 clearance ,
677 actual );
678
679 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
680 drce->SetItems( aItem, other );
681 drce->SetViolatingRule( constraint.GetParentRule() );
682
683 reportViolation( drce, pos, aLayer );
684 ++violations;
685 }
686
687 if( otherHoleShape && otherHoleShape->Collide( aItemShape, clearance, &actual, &pos ) )
688 {
689 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
690 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
691 constraint.GetName(),
692 clearance,
693 actual );
694
695 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
696 drce->SetItems( aItem, other );
697 drce->SetViolatingRule( constraint.GetParentRule() );
698
699 reportViolation( drce, pos, aLayer );
700 ++violations;
701 }
702 }
703 }
704
705 return violations;
706}
707
708
710 PCB_LAYER_ID aLayer )
711{
712 for( ZONE* zone : m_board->m_DRCZones )
713 {
714 if( !zone->GetLayerSet().test( aLayer ) )
715 continue;
716
717 BOX2I itemBBox = aItem->GetBoundingBox();
718 BOX2I worstCaseBBox = itemBBox;
719
720 worstCaseBBox.Inflate( m_board->m_DRCMaxClearance );
721
722 if( !worstCaseBBox.Intersects( zone->GetBoundingBox() ) )
723 continue;
724
725 bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
727
728 if( !testClearance && !testHoles )
729 return;
730
731 DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ zone ].get();
732 DRC_CONSTRAINT constraint;
733 bool colliding;
734 int clearance = -1;
735 int actual;
736 VECTOR2I pos;
737
738 if( testClearance )
739 {
740 constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, zone,
741 aLayer );
742 clearance = constraint.GetValue().Min();
743 }
744
745 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
746 {
747 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aLayer );
748
749 if( aItem->Type() == PCB_PAD_T )
750 {
751 PAD* pad = static_cast<PAD*>( aItem );
752
753 if( !pad->FlashLayer( aLayer ) )
754 {
755 if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
756 continue;
757
758 std::shared_ptr<SHAPE_SEGMENT> hole = pad->GetEffectiveHoleShape();
759 int size = hole->GetWidth();
760
761 itemShape = std::make_shared<SHAPE_SEGMENT>( hole->GetSeg(), size );
762 }
763 }
764
765 if( zoneTree )
766 {
767 colliding = zoneTree->QueryColliding( itemBBox, itemShape.get(), aLayer, clearance,
768 &actual, &pos );
769 }
770 else
771 {
772 colliding = zone->Outline()->Collide( itemShape.get(), clearance, &actual, &pos );
773 }
774
775 if( colliding )
776 {
777 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
778 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
779 constraint.GetName(),
780 clearance,
781 actual );
782
783 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
784 drce->SetItems( aItem, zone );
785 drce->SetViolatingRule( constraint.GetParentRule() );
786
787 reportViolation( drce, pos, aLayer );
788 }
789 }
790
791 if( testHoles )
792 {
793 std::shared_ptr<SHAPE_SEGMENT> holeShape;
794
795 if( aItem->Type() == PCB_VIA_T )
796 {
797 if( aItem->GetLayerSet().Contains( aLayer ) )
798 holeShape = aItem->GetEffectiveHoleShape();
799 }
800 else if( aItem->HasHole() )
801 {
802 holeShape = aItem->GetEffectiveHoleShape();
803 }
804
805 if( holeShape )
806 {
808 zone, aLayer );
809 clearance = constraint.GetValue().Min();
810
811 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE
812 && clearance > 0
813 && zoneTree->QueryColliding( itemBBox, holeShape.get(), aLayer, clearance,
814 &actual, &pos ) )
815 {
816 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
817 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
818 constraint.GetName(),
819 clearance,
820 actual );
821
822 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
823 drce->SetItems( aItem, zone );
824 drce->SetViolatingRule( constraint.GetParentRule() );
825
826 reportViolation( drce, pos, aLayer );
827 }
828 }
829 }
830
831 if( m_drcEngine->IsCancelled() )
832 return;
833 }
834}
835
836
837namespace detail
838{
840}
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:70
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:197
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Definition: board_item.cpp:239
virtual bool IsOnLayer(PCB_LAYER_ID aLayer, bool aIncludeCourtyards=false) const
Test to see if this object is on the given layer.
Definition: board_item.h:257
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:229
virtual bool HasHole() const
Definition: board_item.h:140
int m_DRCMaxPhysicalClearance
Definition: board.h:1172
int m_DRCMaxClearance
Definition: board.h:1171
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1164
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:704
std::vector< ZONE * > m_DRCZones
Definition: board.h:1169
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:149
SEVERITY GetSeverity() const
Definition: drc_rule.h:162
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:141
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:145
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:669
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
int 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:249
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:585
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:523
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:1035
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:532
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:602
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:60
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:269
static SEG::ecoord Square(int a)
Definition: seg.h:123
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
Definition: seg.cpp:231
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:124
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:179
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:703
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:608
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:329
SHAPE_POLY_SET * Outline()
Definition: zone.h:318
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:71
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:70
#define _(s)
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:827
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