KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_solder_mask.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) 2004-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>
27#include <footprint.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <pcb_text.h>
31#include <zone.h>
32#include <geometry/seg.h>
33#include <drc/drc_engine.h>
34#include <drc/drc_item.h>
35#include <drc/drc_rule.h>
37#include <drc/drc_rtree.h>
38
39/*
40 Solder mask tests. Checks for silkscreen which is clipped by mask openings and for bridges
41 between mask apertures with different nets.
42 Errors generated:
43 - DRCE_SILK_CLEARANCE
44 - DRCE_SOLDERMASK_BRIDGE
45*/
46
48{
49public:
51 m_board( nullptr ),
52 m_webWidth( 0 ),
53 m_maxError( 0 ),
55 {
56 m_bridgeRule.m_Name = _( "board setup solder mask min width" );
57 }
58
60 {
61 }
62
63 virtual bool Run() override;
64
65 virtual const wxString GetName() const override
66 {
67 return wxT( "solder_mask_issues" );
68 };
69
70 virtual const wxString GetDescription() const override
71 {
72 return wxT( "Tests for silkscreen being clipped by solder mask and copper being exposed "
73 "by mask apertures of other nets" );
74 }
75
76private:
77 void addItemToRTrees( BOARD_ITEM* aItem );
78 void buildRTrees();
79
81 void testMaskBridges();
82
83 void testItemAgainstItems( BOARD_ITEM* aItem, const BOX2I& aItemBBox,
84 PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer );
85 void testMaskItemAgainstZones( BOARD_ITEM* item, const BOX2I& itemBBox,
86 PCB_LAYER_ID refLayer, PCB_LAYER_ID targetLayer );
87
88 bool checkMaskAperture( BOARD_ITEM* aMaskItem, BOARD_ITEM* aTestItem, PCB_LAYER_ID aTestLayer,
89 int aTestNet, BOARD_ITEM** aCollidingItem );
90
91 bool checkItemMask( BOARD_ITEM* aMaskItem, int aTestNet );
92
93private:
95
100
101 std::unique_ptr<DRC_RTREE> m_fullSolderMaskRTree;
102 std::unique_ptr<DRC_RTREE> m_itemTree;
103
104 std::unordered_map<PTR_PTR_CACHE_KEY, LSET> m_checkedPairs;
105
106 // Shapes used to define solder mask apertures don't have nets, so we assign them the
107 // first object+net that bridges their aperture (after which any other nets will generate
108 // violations).
109 std::unordered_map<PTR_LAYER_CACHE_KEY, std::pair<BOARD_ITEM*, int>> m_maskApertureNetMap;
110};
111
112
114{
115 ZONE* solderMask = m_board->m_SolderMaskBridges;
116
117 if( aItem->Type() == PCB_ZONE_T )
118 {
119 ZONE* zone = static_cast<ZONE*>( aItem );
120
121 for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
122 {
123 if( zone->IsOnLayer( layer ) )
124 {
125 solderMask->GetFill( layer )->BooleanAdd( *zone->GetFilledPolysList( layer ),
127 }
128 }
129 }
130 else if( aItem->Type() == PCB_PAD_T )
131 {
132 for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
133 {
134 if( aItem->IsOnLayer( layer ) )
135 {
136 PAD* pad = static_cast<PAD*>( aItem );
137 int clearance = ( m_webWidth / 2 ) + pad->GetSolderMaskExpansion( layer );
138
139 aItem->TransformShapeToPolygon( *solderMask->GetFill( layer ), layer, clearance,
141
142 m_itemTree->Insert( aItem, layer, m_largestClearance );
143 }
144 }
145 }
146 else if( aItem->Type() == PCB_VIA_T )
147 {
148 for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
149 {
150 if( aItem->IsOnLayer( layer ) )
151 {
152 PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
153 int clearance = ( m_webWidth / 2 ) + via->GetSolderMaskExpansion();
154
155 via->TransformShapeToPolygon( *solderMask->GetFill( layer ), layer, clearance,
157
158 m_itemTree->Insert( aItem, layer, m_largestClearance );
159 }
160 }
161 }
162 else if( aItem->Type() == PCB_FIELD_T || aItem->Type() == PCB_TEXT_T )
163 {
164 for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
165 {
166 if( aItem->IsOnLayer( layer ) )
167 {
168 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( aItem );
169
170 text->TransformTextToPolySet( *solderMask->GetFill( layer ),
172
173 m_itemTree->Insert( aItem, layer, m_largestClearance );
174 }
175 }
176 }
177 else
178 {
179 for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
180 {
181 if( aItem->IsOnLayer( layer ) )
182 {
183 aItem->TransformShapeToPolygon( *solderMask->GetFill( layer ), layer,
185
186 m_itemTree->Insert( aItem, layer, m_largestClearance );
187 }
188 }
189 }
190}
191
192
194{
195 ZONE* solderMask = m_board->m_SolderMaskBridges;
196 LSET layers( { F_Mask, B_Mask, F_Cu, B_Cu } );
197
198 const size_t progressDelta = 500;
199 int count = 0;
200 int ii = 0;
201
202 solderMask->GetFill( F_Mask )->RemoveAllContours();
203 solderMask->GetFill( B_Mask )->RemoveAllContours();
204
205 m_fullSolderMaskRTree = std::make_unique<DRC_RTREE>();
206 m_itemTree = std::make_unique<DRC_RTREE>();
207
209 [&]( BOARD_ITEM* item ) -> bool
210 {
211 ++count;
212 return true;
213 } );
214
216 [&]( BOARD_ITEM* item ) -> bool
217 {
218 if( !reportProgress( ii++, count, progressDelta ) )
219 return false;
220
221 addItemToRTrees( item );
222 return true;
223 } );
224
227
228 solderMask->GetFill( F_Mask )->Deflate( m_webWidth / 2, CORNER_STRATEGY::CHAMFER_ALL_CORNERS,
229 m_maxError );
230 solderMask->GetFill( B_Mask )->Deflate( m_webWidth / 2, CORNER_STRATEGY::CHAMFER_ALL_CORNERS,
231 m_maxError );
232
233 solderMask->SetFillFlag( F_Mask, true );
234 solderMask->SetFillFlag( B_Mask, true );
235 solderMask->SetIsFilled( true );
236
237 solderMask->CacheTriangulation();
238
239 m_fullSolderMaskRTree->Insert( solderMask, F_Mask );
240 m_fullSolderMaskRTree->Insert( solderMask, B_Mask );
241
242 m_checkedPairs.clear();
243}
244
245
247{
248 LSET silkLayers( { F_SilkS, B_SilkS } );
249
250 const size_t progressDelta = 250;
251 int count = 0;
252 int ii = 0;
253
255 [&]( BOARD_ITEM* item ) -> bool
256 {
257 ++count;
258 return true;
259 } );
260
262 [&]( BOARD_ITEM* item ) -> bool
263 {
265 return false;
266
267 if( !reportProgress( ii++, count, progressDelta ) )
268 return false;
269
270 if( isInvisibleText( item ) )
271 return true;
272
273 for( PCB_LAYER_ID layer : silkLayers.Seq() )
274 {
275 if( !item->IsOnLayer( layer ) )
276 continue;
277
278 PCB_LAYER_ID maskLayer = layer == F_SilkS ? F_Mask : B_Mask;
279 BOX2I itemBBox = item->GetBoundingBox();
280 DRC_CONSTRAINT constraint = m_drcEngine->EvalRules( SILK_CLEARANCE_CONSTRAINT,
281 item, nullptr, maskLayer );
282 int clearance = constraint.GetValue().Min();
283 int actual;
284 VECTOR2I pos;
285
286 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance < 0 )
287 return true;
288
289 std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape( layer );
290
291 if( m_fullSolderMaskRTree->QueryColliding( itemBBox, itemShape.get(), maskLayer,
292 clearance, &actual, &pos ) )
293 {
294 auto drce = DRC_ITEM::Create( DRCE_SILK_CLEARANCE );
295
296 if( clearance > 0 )
297 {
298 wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
299 constraint.GetName(),
300 clearance,
301 actual );
302
303 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
304 }
305
306 drce->SetItems( item );
307 drce->SetViolatingRule( constraint.GetParentRule() );
308
309 reportViolation( drce, pos, layer );
310 }
311 }
312
313 return true;
314 } );
315}
316
317
319{
320 if( aItem->Type() == PCB_PAD_T )
321 {
322 PAD* pad = static_cast<PAD*>( aItem );
323
324 // TODO(JE) padstacks
325 if( pad->GetAttribute() == PAD_ATTRIB::NPTH
326 && ( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CIRCLE
327 || pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::OVAL )
328 && pad->GetSize( PADSTACK::ALL_LAYERS ).x <= pad->GetDrillSize().x
329 && pad->GetSize( PADSTACK::ALL_LAYERS ).y <= pad->GetDrillSize().y )
330 {
331 return true;
332 }
333 }
334
335 return false;
336}
337
338
339// Simple mask apertures aren't associated with copper items, so they only constitute a bridge
340// when they expose other copper items having at least two distinct nets. We use a map to record
341// the first net exposed by each mask aperture (on each copper layer).
342//
343// Note that this algorithm is also used for free pads.
344
346{
347 if( aItem->Type() == PCB_PAD_T && static_cast<PAD*>( aItem )->IsFreePad() )
348 return true;
349
350 static const LSET saved( { F_Mask, B_Mask } );
351
352 LSET maskLayers = aItem->GetLayerSet() & saved;
353 LSET copperLayers = ( aItem->GetLayerSet() & ~saved ) & LSET::AllCuMask();
354
355 return maskLayers.count() > 0 && copperLayers.count() == 0;
356}
357
358
360 PCB_LAYER_ID aTestLayer, int aTestNet,
361 BOARD_ITEM** aCollidingItem )
362{
363 if( aTestLayer == F_Mask && !aTestItem->IsOnLayer( PADSTACK::ALL_LAYERS ) )
364 return false;
365
366 if( aTestLayer == B_Mask && !aTestItem->IsOnLayer( B_Cu ) )
367 return false;
368
369 PCB_LAYER_ID maskLayer = IsFrontLayer( aTestLayer ) ? F_Mask : B_Mask;
370
371 FOOTPRINT* fp = aMaskItem->GetParentFootprint();
372
373 if( fp && ( fp->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 )
374 {
375 // Mask apertures in footprints which allow soldermask bridges are ignored entirely.
376 return false;
377 }
378
379 PTR_LAYER_CACHE_KEY key = { aMaskItem, maskLayer };
380
381 auto ii = m_maskApertureNetMap.find( key );
382
383 if( ii == m_maskApertureNetMap.end() )
384 {
385 m_maskApertureNetMap[ key ] = { aTestItem, aTestNet };
386
387 // First net; no bridge yet....
388 return false;
389 }
390
391 auto& [cacheKey, cacheEntry] = *ii;
392 auto& [alreadyEncounteredItem, encounteredItemNet] = cacheEntry;
393
394 if( encounteredItemNet == aTestNet && aTestNet >= 0 )
395 {
396 // Same net; still no bridge...
397 return false;
398 }
399
400 if( fp && aTestItem->GetParentFootprint() == fp )
401 {
402 std::map<wxString, int> padToNetTieGroupMap = fp->MapPadNumbersToNetTieGroups();
403 PAD* padA = nullptr;
404 PAD* padB = nullptr;
405
406 if( alreadyEncounteredItem->Type() == PCB_PAD_T )
407 padA = static_cast<PAD*>( alreadyEncounteredItem );
408
409 if( aTestItem->Type() == PCB_PAD_T )
410 padB = static_cast<PAD*>( aTestItem );
411
412 if( padA && padB && ( padA->SameLogicalPadAs( padB ) || padA->SharesNetTieGroup( padB ) ) )
413 {
414 return false;
415 }
416 else if( padA && aTestItem->Type() == PCB_SHAPE_T )
417 {
418 if( padToNetTieGroupMap.contains( padA->GetNumber() ) )
419 return false;
420 }
421 else if( padB && alreadyEncounteredItem->Type() == PCB_SHAPE_T )
422 {
423 if( padToNetTieGroupMap.contains( padB->GetNumber() ) )
424 return false;
425 }
426 }
427
428 *aCollidingItem = alreadyEncounteredItem;
429 return true;
430}
431
432
434{
435 FOOTPRINT* fp = aMaskItem->GetParentFootprint();
436
437 wxCHECK( fp, false );
438
439 if( ( fp->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 )
440 {
441 // If we're allowing bridges then we're allowing bridges. Nothing to check.
442 return false;
443 }
444
445 // Graphic items are used to implement net-ties between pads of a group within a net-tie
446 // footprint. They must be allowed to intrude into their pad's mask aperture.
447 if( aTestNet < 0 && aMaskItem->Type() == PCB_PAD_T && fp->IsNetTie() )
448 {
449 std::map<wxString, int> padNumberToGroupIdxMap = fp->MapPadNumbersToNetTieGroups();
450
451 if( padNumberToGroupIdxMap[ static_cast<PAD*>( aMaskItem )->GetNumber() ] >= 0 )
452 return false;
453 }
454
455 return true;
456}
457
458
460 PCB_LAYER_ID aRefLayer,
461 PCB_LAYER_ID aTargetLayer )
462{
463 int itemNet = -1;
464
465 if( aItem->IsConnected() )
466 itemNet = static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
467
469 PAD* pad = aItem->Type() == PCB_PAD_T ? static_cast<PAD*>( aItem )
470 : nullptr;
471 PCB_VIA* via = aItem->Type() == PCB_VIA_T ? static_cast<PCB_VIA*>( aItem )
472 : nullptr;
473 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aRefLayer );
474
475 m_itemTree->QueryColliding( aItem, aRefLayer, aTargetLayer,
476 // Filter:
477 [&]( BOARD_ITEM* other ) -> bool
478 {
479 FOOTPRINT* itemFP = aItem->GetParentFootprint();
480 PAD* otherPad = other->Type() == PCB_PAD_T ? static_cast<PAD*>( other )
481 : nullptr;
482 int otherNet = -1;
483
484 if( other->IsConnected() )
485 otherNet = static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetCode();
486
487 if( otherNet > 0 && otherNet == itemNet )
488 return false;
489
490 if( isNullAperture( other ) )
491 return false;
492
493 if( itemFP && itemFP == other->GetParentFootprint() )
494 {
495 // Board-wide exclusion
497 return false;
498
499 // Footprint-specific exclusion
500 if( ( itemFP->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 )
501 return false;
502 }
503
504 if( pad && otherPad && ( pad->SameLogicalPadAs( otherPad )
505 || pad->SharesNetTieGroup( otherPad ) ) )
506 {
507 return false;
508 }
509
510 BOARD_ITEM* a = aItem;
511 BOARD_ITEM* b = other;
512
513 // store canonical order so we don't collide in both directions (a:b and b:a)
514 if( static_cast<void*>( a ) > static_cast<void*>( b ) )
515 std::swap( a, b );
516
517 auto it = m_checkedPairs.find( { a, b } );
518
519 if( it != m_checkedPairs.end() && it->second.test( aTargetLayer ) )
520 {
521 return false;
522 }
523 else
524 {
525 m_checkedPairs[ { a, b } ].set( aTargetLayer );
526 return true;
527 }
528 },
529 // Visitor:
530 [&]( BOARD_ITEM* other ) -> bool
531 {
532 PAD* otherPad = other->Type() == PCB_PAD_T ? static_cast<PAD*>( other )
533 : nullptr;
534 PCB_VIA* otherVia = other->Type() == PCB_VIA_T ? static_cast<PCB_VIA*>( other )
535 : nullptr;
536 auto otherShape = other->GetEffectiveShape( aTargetLayer );
537 int otherNet = -1;
538
539 if( other->IsConnected() )
540 otherNet = static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetCode();
541
542 int actual;
543 VECTOR2I pos;
544 int clearance = 0;
545
546 if( aRefLayer == F_Mask || aRefLayer == B_Mask )
547 {
548 // Aperture-to-aperture must enforce web-min-width
549 clearance = m_webWidth;
550 }
551 else // ( aRefLayer == F_Cu || aRefLayer == B_Cu )
552 {
553 // Copper-to-aperture uses the solder-mask-to-copper-clearance
555 }
556
557 if( pad )
558 clearance += pad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
559 else if( via && !via->IsTented( aRefLayer ) )
560 clearance += via->GetSolderMaskExpansion();
561
562 if( otherPad )
563 clearance += otherPad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
564 else if( otherVia && !otherVia->IsTented( aRefLayer ) )
565 clearance += otherVia->GetSolderMaskExpansion();
566
567 if( itemShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
568 {
569 wxString msg;
570 BOARD_ITEM* colliding = nullptr;
571
572 if( aTargetLayer == F_Mask )
573 msg = _( "Front solder mask aperture bridges items with different nets" );
574 else
575 msg = _( "Rear solder mask aperture bridges items with different nets" );
576
577 // Simple mask apertures aren't associated with copper items, so they only
578 // constitute a bridge when they expose other copper items having at least
579 // two distinct nets.
580 if( isMaskAperture( aItem ) )
581 {
582 if( checkMaskAperture( aItem, other, aRefLayer, otherNet, &colliding ) )
583 {
585
586 drce->SetErrorMessage( msg );
587 drce->SetItems( aItem, colliding, other );
588 drce->SetViolatingRule( &m_bridgeRule );
589 reportViolation( drce, pos, aTargetLayer );
590 }
591 }
592 else if( isMaskAperture( other ) )
593 {
594 if( checkMaskAperture( other, aItem, aRefLayer, itemNet, &colliding ) )
595 {
597
598 drce->SetErrorMessage( msg );
599 drce->SetItems( other, colliding, aItem );
600 drce->SetViolatingRule( &m_bridgeRule );
601 reportViolation( drce, pos, aTargetLayer );
602 }
603 }
604 else if( checkItemMask( other, itemNet ) )
605 {
607
608 drce->SetErrorMessage( msg );
609 drce->SetItems( aItem, other );
610 drce->SetViolatingRule( &m_bridgeRule );
611 reportViolation( drce, pos, aTargetLayer );
612 }
613 }
614
615 return !m_drcEngine->IsCancelled();
616 },
618}
619
620
622 const BOX2I& aItemBBox,
623 PCB_LAYER_ID aMaskLayer,
624 PCB_LAYER_ID aTargetLayer )
625{
626 for( ZONE* zone : m_board->m_DRCCopperZones )
627 {
628 if( !zone->GetLayerSet().test( aTargetLayer ) )
629 continue;
630
631 int zoneNet = zone->GetNetCode();
632
633 if( aItem->IsConnected() )
634 {
635 BOARD_CONNECTED_ITEM* connectedItem = static_cast<BOARD_CONNECTED_ITEM*>( aItem );
636
637 if( zoneNet == connectedItem->GetNetCode() && zoneNet > 0 )
638 continue;
639 }
640
641 BOX2I inflatedBBox( aItemBBox );
643
644 if( aItem->Type() == PCB_PAD_T )
645 clearance += static_cast<PAD*>( aItem )->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
646 else if( aItem->Type() == PCB_VIA_T )
647 clearance += static_cast<PCB_VIA*>( aItem )->GetSolderMaskExpansion();
648
649 inflatedBBox.Inflate( clearance );
650
651 if( !inflatedBBox.Intersects( zone->GetBoundingBox() ) )
652 continue;
653
654 DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ zone ].get();
655 int actual;
656 VECTOR2I pos;
657
658 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aMaskLayer );
659
660 if( zoneTree && zoneTree->QueryColliding( aItemBBox, itemShape.get(), aTargetLayer,
661 clearance, &actual, &pos ) )
662 {
663 wxString msg;
664 BOARD_ITEM* colliding = nullptr;
665
666 if( aMaskLayer == F_Mask )
667 msg = _( "Front solder mask aperture bridges items with different nets" );
668 else
669 msg = _( "Rear solder mask aperture bridges items with different nets" );
670
671 // Simple mask apertures aren't associated with copper items, so they only constitute
672 // a bridge when they expose other copper items having at least two distinct nets.
673 if( isMaskAperture( aItem ) && zoneNet >= 0 )
674 {
675 if( checkMaskAperture( aItem, zone, aTargetLayer, zoneNet, &colliding ) )
676 {
678
679 drce->SetErrorMessage( msg );
680 drce->SetItems( aItem, colliding, zone );
681 drce->SetViolatingRule( &m_bridgeRule );
682 reportViolation( drce, pos, aTargetLayer );
683 }
684 }
685 else
686 {
688
689 drce->SetErrorMessage( msg );
690 drce->SetItems( aItem, zone );
691 drce->SetViolatingRule( &m_bridgeRule );
692 reportViolation( drce, pos, aTargetLayer );
693 }
694 }
695
696 if( m_drcEngine->IsCancelled() )
697 return;
698 }
699}
700
701
703{
704 LSET copperAndMaskLayers( { F_Mask, B_Mask, F_Cu, B_Cu } );
705
706 const size_t progressDelta = 250;
707 int count = 0;
708 int ii = 0;
709
710 forEachGeometryItem( s_allBasicItemsButZones, copperAndMaskLayers,
711 [&]( BOARD_ITEM* item ) -> bool
712 {
713 ++count;
714 return true;
715 } );
716
717 forEachGeometryItem( s_allBasicItemsButZones, copperAndMaskLayers,
718 [&]( BOARD_ITEM* item ) -> bool
719 {
721 return false;
722
723 if( !reportProgress( ii++, count, progressDelta ) )
724 return false;
725
726 BOX2I itemBBox = item->GetBoundingBox();
727
728 if( item->IsOnLayer( F_Mask ) && !isNullAperture( item ) )
729 {
730 // Test for aperture-to-aperture collisions
731 testItemAgainstItems( item, itemBBox, F_Mask, F_Mask );
732
733 // Test for aperture-to-zone collisions
734 testMaskItemAgainstZones( item, itemBBox, F_Mask, F_Cu );
735 }
736 else if( item->IsOnLayer( PADSTACK::ALL_LAYERS ) )
737 {
738 // Test for copper-item-to-aperture collisions
739 testItemAgainstItems( item, itemBBox, F_Cu, F_Mask );
740 }
741
742 if( item->IsOnLayer( B_Mask ) && !isNullAperture( item ) )
743 {
744 // Test for aperture-to-aperture collisions
745 testItemAgainstItems( item, itemBBox, B_Mask, B_Mask );
746
747 // Test for aperture-to-zone collisions
748 testMaskItemAgainstZones( item, itemBBox, B_Mask, B_Cu );
749 }
750 else if( item->IsOnLayer( B_Cu ) )
751 {
752 // Test for copper-item-to-aperture collisions
753 testItemAgainstItems( item, itemBBox, B_Cu, B_Mask );
754 }
755
756 return true;
757 } );
758}
759
760
762{
765 {
766 reportAux( wxT( "Solder mask violations ignored. Tests not run." ) );
767 return true; // continue with other tests
768 }
769
774
775 for( FOOTPRINT* footprint : m_board->Footprints() )
776 {
777 for( PAD* pad : footprint->Pads() )
778 m_largestClearance = std::max( m_largestClearance, pad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS ) );
779 }
780
781 // Order is important here: m_webWidth must be added in before m_largestCourtyardClearance is
782 // maxed with the various SILK_CLEARANCE_CONSTRAINTS.
784
785 DRC_CONSTRAINT worstClearanceConstraint;
786
787 if( m_drcEngine->QueryWorstConstraint( SILK_CLEARANCE_CONSTRAINT, worstClearanceConstraint ) )
788 m_largestClearance = std::max( m_largestClearance, worstClearanceConstraint.m_Value.Min() );
789
790 reportAux( wxT( "Worst clearance : %d nm" ), m_largestClearance );
791
792 if( !reportPhase( _( "Building solder mask..." ) ) )
793 return false; // DRC cancelled
794
795 m_checkedPairs.clear();
796 m_maskApertureNetMap.clear();
797
798 buildRTrees();
799
800 if( !reportPhase( _( "Checking solder mask to silk clearance..." ) ) )
801 return false; // DRC cancelled
802
804
805 if( !reportPhase( _( "Checking solder mask web integrity..." ) ) )
806 return false; // DRC cancelled
807
809
811
812 return !m_drcEngine->IsCancelled();
813}
814
815
816namespace detail
817{
819}
@ ERROR_OUTSIDE
Definition: approximation.h:33
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Container for design settings for a BOARD object.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:133
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:256
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:319
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:279
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:299
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:257
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
ZONE * m_SolderMaskBridges
Definition: board.h:1308
std::vector< ZONE * > m_DRCCopperZones
Definition: board.h:1305
const FOOTPRINTS & Footprints() const
Definition: board.h:331
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1298
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
MINOPTMAX< int > m_Value
Definition: drc_rule.h:190
BOARD * GetBoard() const
Definition: drc_engine.h:99
bool IsErrorLimitExceeded(int error_code)
bool IsCancelled() const
bool QueryWorstConstraint(DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:372
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:48
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:215
wxString m_Name
Definition: drc_rule.h:117
virtual const wxString GetName() const override
void testMaskItemAgainstZones(BOARD_ITEM *item, const BOX2I &itemBBox, PCB_LAYER_ID refLayer, PCB_LAYER_ID targetLayer)
bool checkMaskAperture(BOARD_ITEM *aMaskItem, BOARD_ITEM *aTestItem, PCB_LAYER_ID aTestLayer, int aTestNet, BOARD_ITEM **aCollidingItem)
std::unique_ptr< DRC_RTREE > m_fullSolderMaskRTree
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual const wxString GetDescription() const override
std::unordered_map< PTR_PTR_CACHE_KEY, LSET > m_checkedPairs
bool checkItemMask(BOARD_ITEM *aMaskItem, int aTestNet)
std::unordered_map< PTR_LAYER_CACHE_KEY, std::pair< BOARD_ITEM *, int > > m_maskApertureNetMap
void testItemAgainstItems(BOARD_ITEM *aItem, const BOX2I &aItemBBox, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer)
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
static std::vector< KICAD_T > s_allBasicItemsButZones
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
static std::vector< KICAD_T > s_allBasicItems
DRC_ENGINE * m_drcEngine
bool isInvisibleText(const BOARD_ITEM *aItem) const
void reportAux(const wxString &aMsg)
virtual void reportRuleStatistics()
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
std::map< wxString, int > MapPadNumbersToNetTieGroups() const
Definition: footprint.cpp:2972
int GetAttributes() const
Definition: footprint.h:290
bool IsNetTie() const
Definition: footprint.h:297
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
T Min() const
Definition: minoptmax.h:33
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
Definition: pad.h:54
const wxString & GetNumber() const
Definition: pad.h:134
bool SameLogicalPadAs(const PAD *aOther) const
Before we had custom pad shapes it was common to have multiple overlapping pads to represent a more c...
Definition: pad.h:157
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
Definition: pad.cpp:1082
bool IsFreePad() const
Definition: pad.cpp:262
bool SharesNetTieGroup(const PAD *aOther) const
Definition: pad.cpp:239
int GetSolderMaskExpansion() const
Definition: pcb_track.cpp:923
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union For aFastMode meaning, see function booleanOp.
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:617
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:1115
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:381
void SetFillFlag(PCB_LAYER_ID aLayer, bool aFlag)
Definition: zone.h:259
SHAPE_POLY_SET * GetFill(PCB_LAYER_ID aLayer)
Definition: zone.h:623
void SetIsFilled(bool isFilled)
Definition: zone.h:262
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:375
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:130
The common library.
@ DRCE_SOLDERMASK_BRIDGE
Definition: drc_item.h:93
@ DRCE_SILK_CLEARANCE
Definition: drc_item.h:96
@ SILK_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:56
bool isMaskAperture(BOARD_ITEM *aItem)
bool isNullAperture(BOARD_ITEM *aItem)
#define _(s)
@ FP_ALLOW_SOLDERMASK_BRIDGES
Definition: footprint.h:81
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition: layer_ids.h:621
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ F_SilkS
Definition: layer_ids.h:100
@ B_SilkS
Definition: layer_ids.h:101
@ F_Cu
Definition: layer_ids.h:64
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:107
@ 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_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87