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 if( FOOTPRINT* fp = aMaskItem->GetParentFootprint() )
436 {
437 if( ( fp->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 )
438 {
439 // If we're allowing bridges then we're allowing bridges. Nothing to check.
440 return false;
441 }
442
443 // Graphic items are used to implement net-ties between pads of a group within a net-tie
444 // footprint. They must be allowed to intrude into their pad's mask aperture.
445 if( aTestNet < 0 && aMaskItem->Type() == PCB_PAD_T && fp->IsNetTie() )
446 {
447 std::map<wxString, int> padNumberToGroupIdxMap = fp->MapPadNumbersToNetTieGroups();
448
449 if( padNumberToGroupIdxMap[ static_cast<PAD*>( aMaskItem )->GetNumber() ] >= 0 )
450 return false;
451 }
452 }
453
454 return true;
455}
456
457
459 PCB_LAYER_ID aRefLayer,
460 PCB_LAYER_ID aTargetLayer )
461{
462 int itemNet = -1;
463
464 if( aItem->IsConnected() )
465 itemNet = static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
466
468 PAD* pad = aItem->Type() == PCB_PAD_T ? static_cast<PAD*>( aItem )
469 : nullptr;
470 PCB_VIA* via = aItem->Type() == PCB_VIA_T ? static_cast<PCB_VIA*>( aItem )
471 : nullptr;
472 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aRefLayer );
473
474 m_itemTree->QueryColliding( aItem, aRefLayer, aTargetLayer,
475 // Filter:
476 [&]( BOARD_ITEM* other ) -> bool
477 {
478 FOOTPRINT* itemFP = aItem->GetParentFootprint();
479 PAD* otherPad = other->Type() == PCB_PAD_T ? static_cast<PAD*>( other )
480 : nullptr;
481 int otherNet = -1;
482
483 if( other->IsConnected() )
484 otherNet = static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetCode();
485
486 if( otherNet > 0 && otherNet == itemNet )
487 return false;
488
489 if( isNullAperture( other ) )
490 return false;
491
492 if( itemFP && itemFP == other->GetParentFootprint() )
493 {
494 // Board-wide exclusion
496 return false;
497
498 // Footprint-specific exclusion
499 if( ( itemFP->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 )
500 return false;
501 }
502
503 if( pad && otherPad && ( pad->SameLogicalPadAs( otherPad )
504 || pad->SharesNetTieGroup( otherPad ) ) )
505 {
506 return false;
507 }
508
509 BOARD_ITEM* a = aItem;
510 BOARD_ITEM* b = other;
511
512 // store canonical order so we don't collide in both directions (a:b and b:a)
513 if( static_cast<void*>( a ) > static_cast<void*>( b ) )
514 std::swap( a, b );
515
516 auto it = m_checkedPairs.find( { a, b } );
517
518 if( it != m_checkedPairs.end() && it->second.test( aTargetLayer ) )
519 {
520 return false;
521 }
522 else
523 {
524 m_checkedPairs[ { a, b } ].set( aTargetLayer );
525 return true;
526 }
527 },
528 // Visitor:
529 [&]( BOARD_ITEM* other ) -> bool
530 {
531 PAD* otherPad = other->Type() == PCB_PAD_T ? static_cast<PAD*>( other )
532 : nullptr;
533 PCB_VIA* otherVia = other->Type() == PCB_VIA_T ? static_cast<PCB_VIA*>( other )
534 : nullptr;
535 auto otherShape = other->GetEffectiveShape( aTargetLayer );
536 int otherNet = -1;
537
538 if( other->IsConnected() )
539 otherNet = static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetCode();
540
541 int actual;
542 VECTOR2I pos;
543 int clearance = 0;
544
545 if( aRefLayer == F_Mask || aRefLayer == B_Mask )
546 {
547 // Aperture-to-aperture must enforce web-min-width
548 clearance = m_webWidth;
549 }
550 else // ( aRefLayer == F_Cu || aRefLayer == B_Cu )
551 {
552 // Copper-to-aperture uses the solder-mask-to-copper-clearance
554 }
555
556 if( pad )
557 clearance += pad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
558 else if( via && !via->IsTented( aRefLayer ) )
559 clearance += via->GetSolderMaskExpansion();
560
561 if( otherPad )
562 clearance += otherPad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
563 else if( otherVia && !otherVia->IsTented( aRefLayer ) )
564 clearance += otherVia->GetSolderMaskExpansion();
565
566 if( itemShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
567 {
568 wxString msg;
569 BOARD_ITEM* colliding = nullptr;
570
571 if( aTargetLayer == F_Mask )
572 msg = _( "Front solder mask aperture bridges items with different nets" );
573 else
574 msg = _( "Rear solder mask aperture bridges items with different nets" );
575
576 // Simple mask apertures aren't associated with copper items, so they only
577 // constitute a bridge when they expose other copper items having at least
578 // two distinct nets.
579 if( isMaskAperture( aItem ) )
580 {
581 if( checkMaskAperture( aItem, other, aRefLayer, otherNet, &colliding ) )
582 {
584
585 drce->SetErrorMessage( msg );
586 drce->SetItems( aItem, colliding, other );
587 drce->SetViolatingRule( &m_bridgeRule );
588 reportViolation( drce, pos, aTargetLayer );
589 }
590 }
591 else if( isMaskAperture( other ) )
592 {
593 if( checkMaskAperture( other, aItem, aRefLayer, itemNet, &colliding ) )
594 {
596
597 drce->SetErrorMessage( msg );
598 drce->SetItems( other, colliding, aItem );
599 drce->SetViolatingRule( &m_bridgeRule );
600 reportViolation( drce, pos, aTargetLayer );
601 }
602 }
603 else if( checkItemMask( other, itemNet ) )
604 {
606
607 drce->SetErrorMessage( msg );
608 drce->SetItems( aItem, other );
609 drce->SetViolatingRule( &m_bridgeRule );
610 reportViolation( drce, pos, aTargetLayer );
611 }
612 }
613
614 return !m_drcEngine->IsCancelled();
615 },
617}
618
619
621 const BOX2I& aItemBBox,
622 PCB_LAYER_ID aMaskLayer,
623 PCB_LAYER_ID aTargetLayer )
624{
625 for( ZONE* zone : m_board->m_DRCCopperZones )
626 {
627 if( !zone->GetLayerSet().test( aTargetLayer ) )
628 continue;
629
630 int zoneNet = zone->GetNetCode();
631
632 if( aItem->IsConnected() )
633 {
634 BOARD_CONNECTED_ITEM* connectedItem = static_cast<BOARD_CONNECTED_ITEM*>( aItem );
635
636 if( zoneNet == connectedItem->GetNetCode() && zoneNet > 0 )
637 continue;
638 }
639
640 BOX2I inflatedBBox( aItemBBox );
642
643 if( aItem->Type() == PCB_PAD_T )
644 clearance += static_cast<PAD*>( aItem )->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS );
645 else if( aItem->Type() == PCB_VIA_T )
646 clearance += static_cast<PCB_VIA*>( aItem )->GetSolderMaskExpansion();
647
648 inflatedBBox.Inflate( clearance );
649
650 if( !inflatedBBox.Intersects( zone->GetBoundingBox() ) )
651 continue;
652
653 DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ zone ].get();
654 int actual;
655 VECTOR2I pos;
656
657 std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aMaskLayer );
658
659 if( zoneTree && zoneTree->QueryColliding( aItemBBox, itemShape.get(), aTargetLayer,
660 clearance, &actual, &pos ) )
661 {
662 wxString msg;
663 BOARD_ITEM* colliding = nullptr;
664
665 if( aMaskLayer == F_Mask )
666 msg = _( "Front solder mask aperture bridges items with different nets" );
667 else
668 msg = _( "Rear solder mask aperture bridges items with different nets" );
669
670 // Simple mask apertures aren't associated with copper items, so they only constitute
671 // a bridge when they expose other copper items having at least two distinct nets.
672 if( isMaskAperture( aItem ) && zoneNet >= 0 )
673 {
674 if( checkMaskAperture( aItem, zone, aTargetLayer, zoneNet, &colliding ) )
675 {
677
678 drce->SetErrorMessage( msg );
679 drce->SetItems( aItem, colliding, zone );
680 drce->SetViolatingRule( &m_bridgeRule );
681 reportViolation( drce, pos, aTargetLayer );
682 }
683 }
684 else
685 {
687
688 drce->SetErrorMessage( msg );
689 drce->SetItems( aItem, zone );
690 drce->SetViolatingRule( &m_bridgeRule );
691 reportViolation( drce, pos, aTargetLayer );
692 }
693 }
694
695 if( m_drcEngine->IsCancelled() )
696 return;
697 }
698}
699
700
702{
703 LSET copperAndMaskLayers( { F_Mask, B_Mask, F_Cu, B_Cu } );
704
705 const size_t progressDelta = 250;
706 int count = 0;
707 int ii = 0;
708
709 forEachGeometryItem( s_allBasicItemsButZones, copperAndMaskLayers,
710 [&]( BOARD_ITEM* item ) -> bool
711 {
712 ++count;
713 return true;
714 } );
715
716 forEachGeometryItem( s_allBasicItemsButZones, copperAndMaskLayers,
717 [&]( BOARD_ITEM* item ) -> bool
718 {
720 return false;
721
722 if( !reportProgress( ii++, count, progressDelta ) )
723 return false;
724
725 BOX2I itemBBox = item->GetBoundingBox();
726
727 if( item->IsOnLayer( F_Mask ) && !isNullAperture( item ) )
728 {
729 // Test for aperture-to-aperture collisions
730 testItemAgainstItems( item, itemBBox, F_Mask, F_Mask );
731
732 // Test for aperture-to-zone collisions
733 testMaskItemAgainstZones( item, itemBBox, F_Mask, F_Cu );
734 }
735 else if( item->IsOnLayer( PADSTACK::ALL_LAYERS ) )
736 {
737 // Test for copper-item-to-aperture collisions
738 testItemAgainstItems( item, itemBBox, F_Cu, F_Mask );
739 }
740
741 if( item->IsOnLayer( B_Mask ) && !isNullAperture( item ) )
742 {
743 // Test for aperture-to-aperture collisions
744 testItemAgainstItems( item, itemBBox, B_Mask, B_Mask );
745
746 // Test for aperture-to-zone collisions
747 testMaskItemAgainstZones( item, itemBBox, B_Mask, B_Cu );
748 }
749 else if( item->IsOnLayer( B_Cu ) )
750 {
751 // Test for copper-item-to-aperture collisions
752 testItemAgainstItems( item, itemBBox, B_Cu, B_Mask );
753 }
754
755 return true;
756 } );
757}
758
759
761{
764 {
765 reportAux( wxT( "Solder mask violations ignored. Tests not run." ) );
766 return true; // continue with other tests
767 }
768
773
774 for( FOOTPRINT* footprint : m_board->Footprints() )
775 {
776 for( PAD* pad : footprint->Pads() )
777 m_largestClearance = std::max( m_largestClearance, pad->GetSolderMaskExpansion( PADSTACK::ALL_LAYERS ) );
778 }
779
780 // Order is important here: m_webWidth must be added in before m_largestCourtyardClearance is
781 // maxed with the various SILK_CLEARANCE_CONSTRAINTS.
783
784 DRC_CONSTRAINT worstClearanceConstraint;
785
786 if( m_drcEngine->QueryWorstConstraint( SILK_CLEARANCE_CONSTRAINT, worstClearanceConstraint ) )
787 m_largestClearance = std::max( m_largestClearance, worstClearanceConstraint.m_Value.Min() );
788
789 reportAux( wxT( "Worst clearance : %d nm" ), m_largestClearance );
790
791 if( !reportPhase( _( "Building solder mask..." ) ) )
792 return false; // DRC cancelled
793
794 m_checkedPairs.clear();
795 m_maskApertureNetMap.clear();
796
797 buildRTrees();
798
799 if( !reportPhase( _( "Checking solder mask to silk clearance..." ) ) )
800 return false; // DRC cancelled
801
803
804 if( !reportPhase( _( "Checking solder mask web integrity..." ) ) )
805 return false; // DRC cancelled
806
808
810
811 return !m_drcEngine->IsCancelled();
812}
813
814
815namespace detail
816{
818}
@ 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:255
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:278
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:298
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:895
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:382
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:217
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:3084
int GetAttributes() const
Definition: footprint.h:290
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:686
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:928
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:620
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:1301
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:567
void SetFillFlag(PCB_LAYER_ID aLayer, bool aFlag)
Definition: zone.h:262
SHAPE_POLY_SET * GetFill(PCB_LAYER_ID aLayer)
Definition: zone.h:626
void SetIsFilled(bool isFilled)
Definition: zone.h:265
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:561
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
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:632
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