KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_item.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) 2007 Dick Hollenbeck, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "core/kicad_algo.h"
22#include <algorithm>
23#include <drc/drc_item.h>
24#include <drc/drc_rule.h>
25#include <board.h>
26#include <pad.h>
27#include <pad_utils.h>
28#include <pcb_marker.h>
29#include <i18n_utility.h>
30
31
33{
34 switch( aCode )
35 {
47
50
72 return DRCE_PADSTACK;
73 }
74
75 wxFAIL_MSG( wxT( "Unknown pad check code" ) );
76 return DRCE_PADSTACK;
77}
78
79
80// These, being statically-defined, require specialized I18N handling.
81// We don't translate on initialization and instead do it in the getters.
82
83// NOTE: Avoid changing the settings key for a DRC item after it has been created
84
85
86DRC_ITEM DRC_ITEM::heading_electrical( 0, _HKI( "Electrical" ), "" );
87DRC_ITEM DRC_ITEM::heading_DFM( 0, _HKI( "Design for Manufacturing" ), "" );
88DRC_ITEM DRC_ITEM::heading_schematic_parity( 0, _HKI( "Schematic Parity" ), "" );
89DRC_ITEM DRC_ITEM::heading_signal_integrity( 0, _HKI( "Signal Integrity" ), "" );
90DRC_ITEM DRC_ITEM::heading_readability( 0, _HKI( "Readability" ), "" );
91DRC_ITEM DRC_ITEM::heading_misc( 0, _HKI( "Miscellaneous" ), "" );
94
96 _HKI( "Missing connection between items" ),
97 wxT( "unconnected_items" ) );
98
100 _HKI( "Items shorting two nets" ),
101 wxT( "shorting_items" ) );
102
104 _HKI( "Items not allowed" ),
105 wxT( "items_not_allowed" ) );
106
108 _HKI( "Text or graphic on Edge.Cuts layer" ),
109 wxT( "text_on_edge_cuts" ) );
110
112 _HKI( "Clearance violation" ),
113 wxT( "clearance" ) );
114
116 _HKI( "Creepage violation" ),
117 wxT( "creepage" ) );
118
120 _HKI( "Tracks crossing" ),
121 wxT( "tracks_crossing" ) );
122
124 _HKI( "Board edge clearance violation" ),
125 wxT( "copper_edge_clearance" ) );
126
128 _HKI( "Copper outside board outline" ),
129 wxT( "copper_outside_board" ) );
130
132 _HKI( "Isolated copper fill" ),
133 wxT( "isolated_copper" ) );
134
136 _HKI( "Thermal relief connection to zone incomplete" ),
137 wxT( "starved_thermal" ) );
138
140 _HKI( "Via is not connected or connected on only one layer" ),
141 wxT( "via_dangling" ) );
142
144 _HKI( "Track has unconnected end" ),
145 wxT( "track_dangling" ) );
146
148 _HKI( "Hole clearance violation" ),
149 wxT( "hole_clearance" ) );
150
152 _HKI( "Drilled hole too close to other hole" ),
153 wxT( "hole_to_hole" ) );
154
156 _HKI( "Drilled holes co-located" ),
157 wxT( "holes_co_located" ) );
158
160 _HKI( "Copper connection too narrow" ),
161 wxT( "connection_width" ) );
162
164 _HKI( "Track width" ),
165 wxT( "track_width" ) );
166
168 _HKI( "Track angle" ),
169 wxT( "track_angle" ) );
170
172 _HKI( "Track segment length" ),
173 wxT( "track_segment_length" ) );
174
176 _HKI( "Annular width" ),
177 wxT( "annular_width" ) );
178
180 _HKI( "Hole size out of range" ),
181 wxT( "drill_out_of_range" ) );
182
184 _HKI( "Via diameter" ),
185 wxT( "via_diameter" ) );
186
188 _HKI( "Padstack is questionable" ),
189 wxT( "padstack" ) );
190
192 _HKI( "Padstack is not valid" ),
193 wxT( "padstack_invalid" ) );
194
196 _HKI( "Micro via hole size out of range" ),
197 wxT( "microvia_drill_out_of_range" ) );
198
200 _HKI( "Microvia stack has malformed span" ),
201 wxT( "malformed_microvia_stack_span" ) );
202
204 _HKI( "Microvia under microvia not filled" ),
205 wxT( "microvia_stack_not_filled" ) );
206
208 _HKI( "Microvia stack too deep" ),
209 wxT( "microvia_stack_depth" ) );
210
212 _HKI( "Hole too deep for its diameter" ),
213 wxT( "hole_aspect_ratio" ) );
214
216 _HKI( "Microvia crosses core material" ),
217 wxT( "microvia_crosses_core" ) );
218
220 _HKI( "Microvia spans more than one dielectric" ),
221 wxT( "microvia_spans_dielectrics" ) );
222
224 _HKI( "Courtyards overlap" ),
225 wxT( "courtyards_overlap" ) );
226
228 _HKI( "Footprint has no courtyard defined" ),
229 wxT( "missing_courtyard" ) );
230
232 _HKI( "Footprint has malformed courtyard" ),
233 wxT( "malformed_courtyard" ) );
234
236 _HKI( "PTH inside courtyard" ),
237 wxT( "pth_inside_courtyard" ) );
238
240 _HKI( "NPTH inside courtyard" ),
241 wxT( "npth_inside_courtyard" ) );
242
244 _HKI( "Item on a disabled copper layer" ),
245 wxT( "item_on_disabled_layer" ) );
246
248 _HKI( "Board has malformed outline" ),
249 wxT( "invalid_outline" ) );
250
252 _HKI( "Duplicate footprints" ),
253 wxT( "duplicate_footprints" ) );
254
256 _HKI( "Missing footprint" ),
257 wxT( "missing_footprint" ) );
258
260 _HKI( "Extra footprint" ),
261 wxT( "extra_footprint" ) );
262
264 _HKI( "Pad net doesn't match schematic" ),
265 wxT( "net_conflict" ) );
266
268 _HKI( "Footprint attributes don't match symbol" ),
269 wxT( "footprint_symbol_mismatch" ) );
270
272 _HKI( "Footprint doesn't match symbol's footprint filters" ),
273 wxT( "footprint_filters_mismatch" ) );
274
276 _HKI( "Footprint field does not match symbol field" ),
277 wxT( "footprint_symbol_field_mismatch" ) );
278
280 _HKI( "Via-stitching zones overlap for same net" ),
281 wxT( "via_stitch_overlap" ) );
282
284 _HKI( "Footprint not found in libraries" ),
285 wxT( "lib_footprint_issues" ) );
286
288 _HKI( "Footprint doesn't match copy in library" ),
289 wxT( "lib_footprint_mismatch" ) );
290
292 _HKI( "Unresolved text variable" ),
293 wxT( "unresolved_variable" ) );
294
296 _HKI( "Assertion failure" ),
297 wxT( "assertion_failure" ) );
298
300 _HKI( "Warning" ),
301 wxT( "generic_warning" ) );
302
304 _HKI( "Error" ),
305 wxT( "generic_error" ) );
306
308 _HKI( "Copper sliver" ),
309 wxT( "copper_sliver" ) );
310
312 _HKI( "Solder mask aperture bridges items with different nets" ),
313 wxT( "solder_mask_bridge" ) );
314
316 _HKI( "Silkscreen clipped by solder mask" ),
317 wxT( "silk_over_copper" ) );
318
320 _HKI( "Silkscreen clipped by board edge" ),
321 wxT( "silk_edge_clearance" ) );
322
324 _HKI( "Silkscreen clearance" ),
325 wxT( "silk_overlap" ) );
326
328 _HKI( "Line width out of range" ),
329 wxT( "line_width" ) );
330
332 _HKI( "Text height out of range" ),
333 wxT( "text_height" ) );
334
336 _HKI( "Track length out of range" ),
337 wxT( "length_out_of_range" ) );
338
340 _HKI( "Net chain stub length out of range" ),
341 wxT( "net_chain_stub_length" ) );
342
344 _HKI( "Net chain routed without continuous copper on the required reference layer" ),
345 wxT( "net_chain_return_path" ) );
346
348 _HKI( "Net chain nets do not have consistent tuning profile assignment" ),
349 wxT( "net_chain_tuning_profiles" ) );
350
352 _HKI( "Skew between tracks out of range" ),
353 wxT( "skew_out_of_range" ) );
354
355// Note: this used to only check against a max value, hence the settings key too_many_vias
357 _HKI( "Too many or too few vias on a connection" ),
358 wxT( "too_many_vias" ) );
359
361 _HKI( "Differential pair gap out of range" ),
362 wxT( "diff_pair_gap_out_of_range" ) );
363
365 _HKI( "Differential uncoupled length too long" ),
366 wxT( "diff_pair_uncoupled_length_too_long" ) );
367
369 _HKI( "Footprint is not valid" ),
370 wxT( "footprint" ) );
371
373 _HKI( "Footprint component type doesn't match footprint pads" ),
374 wxT( "footprint_type_mismatch" ) );
375
377 _HKI( "Through hole pad has no hole" ),
378 wxT( "through_hole_pad_without_hole" ) );
379
381 _HKI( "Footprint with pads is scaled (physical part size unchanged)" ),
382 wxT( "footprint_scaled_with_pads" ) );
383
385 _HKI( "Mirrored text on front layer" ),
386 wxT( "mirrored_text_on_front_layer" ) );
387
389 _HKI( "Non-Mirrored text on back layer" ),
390 wxT( "nonmirrored_text_on_back_layer" ) );
391
393 _HKI( "Missing tuning profile" ),
394 wxT( "missing_tuning_profile" ) );
395
397 _HKI( "Tuning profile track geometries" ),
398 wxT( "tuning_profile_track_geometries" ) );
399
401 _HKI( "Track connected to post-machined or backdrilled layer" ),
402 wxT( "track_on_post_machined_layer" ) );
403
405 _HKI( "Track endpoint not centered on via" ),
406 wxT( "track_not_centered_on_via" ) );
407
408std::vector<std::reference_wrapper<RC_ITEM>> DRC_ITEM::allItemTypes( {
417
448
458
468
477
495
496 // DRC_ITEM types with no user-editable severities
497 // NOTE: this MUST be the last grouping in the list!
502} );
503
504
505std::shared_ptr<DRC_ITEM> DRC_ITEM::Create( int aErrorCode )
506{
507 switch( aErrorCode )
508 {
509 case DRCE_UNCONNECTED_ITEMS: return std::make_shared<DRC_ITEM>( unconnectedItems );
510 case DRCE_SHORTING_ITEMS: return std::make_shared<DRC_ITEM>( shortingItems );
511 case DRCE_ALLOWED_ITEMS: return std::make_shared<DRC_ITEM>( itemsNotAllowed );
512 case DRCE_TEXT_ON_EDGECUTS: return std::make_shared<DRC_ITEM>( textOnEdgeCuts );
513 case DRCE_CLEARANCE: return std::make_shared<DRC_ITEM>( clearance );
514 case DRCE_CREEPAGE: return std::make_shared<DRC_ITEM>( creepage );
515 case DRCE_TRACKS_CROSSING: return std::make_shared<DRC_ITEM>( tracksCrossing );
516 case DRCE_EDGE_CLEARANCE: return std::make_shared<DRC_ITEM>( edgeClearance );
517 case DRCE_COPPER_OUTSIDE_BOARD: return std::make_shared<DRC_ITEM>( copperOutsideBoard );
518 case DRCE_ISOLATED_COPPER: return std::make_shared<DRC_ITEM>( isolatedCopper );
519 case DRCE_STARVED_THERMAL: return std::make_shared<DRC_ITEM>( starvedThermal );
520 case DRCE_DANGLING_VIA: return std::make_shared<DRC_ITEM>( viaDangling );
521 case DRCE_DANGLING_TRACK: return std::make_shared<DRC_ITEM>( trackDangling );
522 case DRCE_DRILLED_HOLES_TOO_CLOSE: return std::make_shared<DRC_ITEM>( holeNearHole );
523 case DRCE_DRILLED_HOLES_COLOCATED: return std::make_shared<DRC_ITEM>( holesCoLocated );
524 case DRCE_HOLE_CLEARANCE: return std::make_shared<DRC_ITEM>( holeClearance );
525 case DRCE_CONNECTION_WIDTH: return std::make_shared<DRC_ITEM>( connectionWidth );
526 case DRCE_TRACK_WIDTH: return std::make_shared<DRC_ITEM>( trackWidth );
527 case DRCE_TRACK_ANGLE: return std::make_shared<DRC_ITEM>( trackAngle );
528 case DRCE_TRACK_SEGMENT_LENGTH: return std::make_shared<DRC_ITEM>( trackSegmentLength );
529 case DRCE_ANNULAR_WIDTH: return std::make_shared<DRC_ITEM>( annularWidth );
530 case DRCE_DRILL_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( drillTooSmall );
531 case DRCE_VIA_DIAMETER: return std::make_shared<DRC_ITEM>( viaDiameter );
532 case DRCE_PADSTACK: return std::make_shared<DRC_ITEM>( padstack );
533 case DRCE_PADSTACK_INVALID: return std::make_shared<DRC_ITEM>( padstackInvalid );
534 case DRCE_MICROVIA_DRILL_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( microviaDrillTooSmall );
535 case DRCE_MALFORMED_MICROVIA_STACK_SPAN: return std::make_shared<DRC_ITEM>( malformedMicroviaStackSpan );
536 case DRCE_MICROVIA_STACK_NOT_FILLED: return std::make_shared<DRC_ITEM>( microviaStackNotFilled );
537 case DRCE_MICROVIA_STACK_DEPTH: return std::make_shared<DRC_ITEM>( microviaStackDepth );
538 case DRCE_HOLE_ASPECT_RATIO: return std::make_shared<DRC_ITEM>( holeAspectRatio );
539 case DRCE_MICROVIA_CROSSES_CORE: return std::make_shared<DRC_ITEM>( microviaCrossesCore );
540 case DRCE_MICROVIA_SPANS_DIELECTRICS: return std::make_shared<DRC_ITEM>( microviaSpansDielectrics );
541 case DRCE_OVERLAPPING_FOOTPRINTS: return std::make_shared<DRC_ITEM>( courtyardsOverlap );
542 case DRCE_MISSING_COURTYARD: return std::make_shared<DRC_ITEM>( missingCourtyard );
543 case DRCE_MALFORMED_COURTYARD: return std::make_shared<DRC_ITEM>( malformedCourtyard );
544 case DRCE_PTH_IN_COURTYARD: return std::make_shared<DRC_ITEM>( pthInsideCourtyard );
545 case DRCE_NPTH_IN_COURTYARD: return std::make_shared<DRC_ITEM>( npthInsideCourtyard );
546 case DRCE_DISABLED_LAYER_ITEM: return std::make_shared<DRC_ITEM>( itemOnDisabledLayer );
547 case DRCE_INVALID_OUTLINE: return std::make_shared<DRC_ITEM>( invalidOutline );
548 case DRCE_MISSING_FOOTPRINT: return std::make_shared<DRC_ITEM>( missingFootprint );
549 case DRCE_DUPLICATE_FOOTPRINT: return std::make_shared<DRC_ITEM>( duplicateFootprints );
550 case DRCE_NET_CONFLICT: return std::make_shared<DRC_ITEM>( netConflict );
551 case DRCE_EXTRA_FOOTPRINT: return std::make_shared<DRC_ITEM>( extraFootprint );
552 case DRCE_SCHEMATIC_PARITY: return std::make_shared<DRC_ITEM>( schematicParity );
553 case DRCE_SCHEMATIC_FIELDS_PARITY: return std::make_shared<DRC_ITEM>( schematicFieldsParity );
554 case DRCE_FOOTPRINT_FILTERS: return std::make_shared<DRC_ITEM>( footprintFilters );
555 case DRCE_LIB_FOOTPRINT_ISSUES: return std::make_shared<DRC_ITEM>( libFootprintIssues );
556 case DRCE_LIB_FOOTPRINT_MISMATCH: return std::make_shared<DRC_ITEM>( libFootprintMismatch );
557 case DRCE_UNRESOLVED_VARIABLE: return std::make_shared<DRC_ITEM>( unresolvedVariable );
558 case DRCE_ASSERTION_FAILURE: return std::make_shared<DRC_ITEM>( assertionFailure );
559 case DRCE_GENERIC_WARNING: return std::make_shared<DRC_ITEM>( genericWarning );
560 case DRCE_GENERIC_ERROR: return std::make_shared<DRC_ITEM>( genericError );
561 case DRCE_COPPER_SLIVER: return std::make_shared<DRC_ITEM>( copperSliver );
562 case DRCE_SILK_CLEARANCE: return std::make_shared<DRC_ITEM>( silkClearance );
563 case DRCE_SILK_MASK_CLEARANCE: return std::make_shared<DRC_ITEM>( silkMaskClearance );
564 case DRCE_SILK_EDGE_CLEARANCE: return std::make_shared<DRC_ITEM>( silkEdgeClearance );
565 case DRCE_SOLDERMASK_BRIDGE: return std::make_shared<DRC_ITEM>( solderMaskBridge );
566 case DRCE_TEXT_HEIGHT: return std::make_shared<DRC_ITEM>( textHeightOutOfRange );
567 case DRCE_LINE_WIDTH: return std::make_shared<DRC_ITEM>( lineWidthOutOfRange );
568 case DRCE_LENGTH_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( lengthOutOfRange );
569 case DRCE_NET_CHAIN_STUB_TOO_LONG: return std::make_shared<DRC_ITEM>( netChainStubTooLong );
570 case DRCE_NET_CHAIN_RETURN_PATH_BREAK: return std::make_shared<DRC_ITEM>( netChainReturnPathBreak );
571 case DRCE_NET_CHAIN_TUNING_PROFILES: return std::make_shared<DRC_ITEM>( netChainTuningProfiles );
572 case DRCE_SKEW_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( skewOutOfRange );
573 case DRCE_VIA_COUNT_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( viaCountOutOfRange );
574 case DRCE_DP_GAP_OUT_OF_RANGE: return std::make_shared<DRC_ITEM>( diffPairGapOutOfRange );
575 case DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG: return std::make_shared<DRC_ITEM>( diffPairUncoupledLengthTooLong );
576 case DRCE_FOOTPRINT: return std::make_shared<DRC_ITEM>( footprint );
577 case DRCE_FOOTPRINT_TYPE_MISMATCH: return std::make_shared<DRC_ITEM>( footprintTypeMismatch );
578 case DRCE_PAD_TH_WITH_NO_HOLE: return std::make_shared<DRC_ITEM>( footprintTHPadhasNoHole );
579 case DRCE_FOOTPRINT_SCALED_WITH_PADS: return std::make_shared<DRC_ITEM>( footprintScaledWithPads );
580 case DRCE_MIRRORED_TEXT_ON_FRONT_LAYER: return std::make_shared<DRC_ITEM>( mirroredTextOnFrontLayer );
581 case DRCE_UNMIRRORED_TEXT_ON_BACK_LAYER: return std::make_shared<DRC_ITEM>( unMirroredTextOnBackLayer );
582 case DRCE_MISSING_TUNING_PROFILE: return std::make_shared<DRC_ITEM>( missingTuningProfile );
583 case DRCE_TRACK_ON_POST_MACHINED_LAYER: return std::make_shared<DRC_ITEM>( trackOnPostMachinedLayer );
584 case DRCE_TRACK_NOT_CENTERED_ON_VIA: return std::make_shared<DRC_ITEM>( trackNotCenteredOnVia );
585 case DRCE_VIA_STITCH_OVERLAP: return std::make_shared<DRC_ITEM>( viaStitchOverlap );
586
587 default:
588 return nullptr;
589 }
590}
591
592
593std::shared_ptr<DRC_ITEM> DRC_ITEM::Create( const wxString& aErrorKey )
594{
595 // Exclusions written before 11.0 use the old text thickness key
596 const wxString key = aErrorKey == wxS( "text_thickness" ) ? wxString( wxS( "line_width" ) ) : aErrorKey;
597
598 for( const std::reference_wrapper<RC_ITEM>& item : allItemTypes )
599 {
600 if( key == item.get().GetSettingsKey() )
601 return std::make_shared<DRC_ITEM>( static_cast<const DRC_ITEM&>( item.get() ) );
602 }
603
604 // This can happen if a project has old-format exclusions. Just drop these items.
605 return nullptr;
606}
607
608
610{
612 {
613 // we have lots of segments, but it's enough to show the first P and the first N
614 return niluuid;
615 }
616
617 return m_ids.size() > 2 ? m_ids[2] : niluuid;
618}
619
620
622{
624 {
625 // we have lots of segments, but it's enough to show the first P and the first N
626 return niluuid;
627 }
628
629 return m_ids.size() > 3 ? m_ids[3] : niluuid;
630}
631
632
633wxString DRC_ITEM::GetViolatingRuleDesc( bool aTranslate ) const
634{
635 if( m_violatingRule )
636 return wxString::Format( aTranslate ? _( "Rule: %s" ) : wxString( wxT( "Rule: %s" ) ), m_violatingRule->m_Name );
637 else
638 return aTranslate ? _( "Local override" ) : wxString( wxT( "Local override" ) );
639}
640
641
642void DRC_ITEM::GetViolationLayers( BOARD* aBoard, const std::shared_ptr<RC_ITEM>& aItem, PCB_MARKER* aMarker,
643 PCB_LAYER_ID& aPrincipalLayer, LSET& aViolationLayers )
644{
645 auto getActiveLayers = []( BOARD_ITEM* it ) -> LSET
646 {
647 if( it->Type() == PCB_PAD_T )
648 {
649 PAD* pad = static_cast<PAD*>( it );
650 LSET layers;
651
652 for( int layer : it->GetLayerSet() )
653 {
654 if( pad->FlashLayer( layer ) )
655 layers.set( layer );
656 }
657
658 return layers;
659 }
660 else
661 {
662 return it->GetLayerSet();
663 }
664 };
665
666 aPrincipalLayer = UNDEFINED_LAYER;
667 aViolationLayers = LSET();
668
669 BOARD_ITEM* a = aBoard->ResolveItem( aItem->GetMainItemID(), true );
670 BOARD_ITEM* b = aBoard->ResolveItem( aItem->GetAuxItemID(), true );
671 BOARD_ITEM* c = aBoard->ResolveItem( aItem->GetAuxItem2ID(), true );
672 BOARD_ITEM* d = aBoard->ResolveItem( aItem->GetAuxItem3ID(), true );
673
674 if( aItem->GetErrorCode() == DRCE_MALFORMED_COURTYARD )
675 {
676 if( a && ( a->GetFlags() & MALFORMED_B_COURTYARD ) > 0 && ( a->GetFlags() & MALFORMED_F_COURTYARD ) == 0 )
677 {
678 aPrincipalLayer = B_CrtYd;
679 }
680 else
681 {
682 aPrincipalLayer = F_CrtYd;
683 }
684 }
685 else if( aItem->GetErrorCode() == DRCE_INVALID_OUTLINE || aItem->GetErrorCode() == DRCE_EDGE_CLEARANCE )
686 {
687 aPrincipalLayer = Edge_Cuts;
688 }
689 else
690 {
691 // The marker's layer is set by the test provider
692 if( aMarker )
693 {
694 PCB_LAYER_ID markerLayer = aMarker->GetLayer();
695
696 if( markerLayer > UNDEFINED_LAYER )
697 aPrincipalLayer = markerLayer;
698 }
699
700 // Fall back to intersecting the layer sets of the contributing items
701 if( aPrincipalLayer <= UNDEFINED_LAYER )
702 {
703 if( a || b || c || d )
704 aViolationLayers = LSET::AllLayersMask();
705
706 for( BOARD_ITEM* it : { a, b, c, d } )
707 {
708 if( !it )
709 continue;
710
711 LSET layersList = getActiveLayers( it );
712 aViolationLayers &= layersList;
713
714 if( aPrincipalLayer <= UNDEFINED_LAYER && layersList.count() )
715 aPrincipalLayer = layersList.Seq().front();
716 }
717 }
718 }
719
720 if( aViolationLayers.count() )
721 aPrincipalLayer = aViolationLayers.Seq().front();
722 else if( aPrincipalLayer >= 0 )
723 aViolationLayers.set( aPrincipalLayer );
724}
725
726
728{
729 m_severities = aSeverities;
730
731 m_filteredMarkers.clear();
732
733 for( PCB_MARKER* marker : m_board->Markers() )
734 {
735 if( alg::contains( m_markerTypes, marker->GetMarkerType() )
736 && ( marker->GetSeverity() & m_severities ) > 0 )
737 {
738 m_filteredMarkers.push_back( marker );
739 }
740 }
741
742 // Sort markers so that errors appear before warnings
743 std::stable_sort( m_filteredMarkers.begin(), m_filteredMarkers.end(),
744 []( const PCB_MARKER* a, const PCB_MARKER* b )
745 {
746 return a->GetSeverity() > b->GetSeverity();
747 } );
748}
749
750
752{
753 return m_severities;
754}
755
756
757int DRC_ITEMS_PROVIDER::GetCount( int aSeverity ) const
758{
759 if( aSeverity < 0 )
760 return (int) m_filteredMarkers.size();
761
762 return static_cast<int>( std::ranges::count_if( m_board->Markers(),
763 [&]( const PCB_MARKER* marker )
764 {
765 return alg::contains( m_markerTypes, marker->GetMarkerType() )
766 && ( marker->GetSeverity() & aSeverity ) > 0;
767 } ) );
768}
769
770
771std::shared_ptr<RC_ITEM> DRC_ITEMS_PROVIDER::GetItem( int aIndex ) const
772{
773 PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
774
775 return marker ? marker->GetRCItem() : nullptr;
776}
777
778
779void DRC_ITEMS_PROVIDER::DeleteItem( int aIndex, bool aDeep )
780{
781 PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
782 m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
783
784 if( aDeep )
785 m_board->Delete( marker );
786}
787
788
790{
791 return m_board.ResolveItem( aKiid, true );
792}
BASE_SET & set(size_t pos)
Definition base_set.h:126
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
EDA_ITEM * doResolveItemById(const KIID &aKiid) const override
The actual resolution logic for an item by its KIID, must be implemented against the actual item stor...
Definition drc_item.cpp:789
const BOARD & m_board
Definition drc_item.h:361
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2176
void SetSeverities(int aSeverities) override
Definition drc_item.cpp:727
std::vector< MARKER_BASE::MARKER_T > m_markerTypes
Definition drc_item.h:340
void DeleteItem(int aIndex, bool aDeep) override
Remove (and optionally deletes) the indexed item from the list.
Definition drc_item.cpp:779
int GetSeverities() const override
Definition drc_item.cpp:751
int GetCount(int aSeverity=-1) const override
Definition drc_item.cpp:757
std::vector< PCB_MARKER * > m_filteredMarkers
Definition drc_item.h:343
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
Definition drc_item.cpp:771
static DRC_ITEM viaStitchOverlap
Definition drc_item.h:301
static DRC_ITEM lengthOutOfRange
Definition drc_item.h:282
KIID GetAuxItem3ID() const override
Definition drc_item.cpp:621
static DRC_ITEM viaDiameter
Definition drc_item.h:246
static DRC_ITEM silkEdgeClearance
Definition drc_item.h:277
static DRC_ITEM trackWidth
Definition drc_item.h:241
static DRC_ITEM heading_DFM
Definition drc_item.h:215
static DRC_ITEM microviaSpansDielectrics
Definition drc_item.h:255
static DRC_ITEM annularWidth
Definition drc_item.h:244
static DRC_ITEM pthInsideCourtyard
Definition drc_item.h:259
static DRC_ITEM microviaStackDepth
Definition drc_item.h:252
static DRC_ITEM trackSegmentLength
Definition drc_item.h:243
static DRC_ITEM schematicParity
Definition drc_item.h:267
static DRC_ITEM netConflict
Definition drc_item.h:266
static void GetViolationLayers(BOARD *aBoard, const std::shared_ptr< RC_ITEM > &aItem, PCB_MARKER *aMarker, PCB_LAYER_ID &aPrincipalLayer, LSET &aViolationLayers)
Work out which layer to focus on and which layers a violation involves.
Definition drc_item.cpp:642
static DRC_ITEM copperSliver
Definition drc_item.h:275
static DRC_ITEM trackNotCenteredOnVia
Definition drc_item.h:299
static DRC_ITEM holeNearHole
Definition drc_item.h:237
static DRC_ITEM heading_signal_integrity
Definition drc_item.h:217
static DRC_ITEM courtyardsOverlap
Definition drc_item.h:256
static DRC_ITEM trackOnPostMachinedLayer
Definition drc_item.h:298
static DRC_ITEM connectionWidth
Definition drc_item.h:240
static DRC_ITEM footprint
Definition drc_item.h:290
static DRC_ITEM unresolvedVariable
Definition drc_item.h:271
static DRC_ITEM assertionFailure
Definition drc_item.h:272
static DRC_ITEM npthInsideCourtyard
Definition drc_item.h:260
static DRC_ITEM footprintFilters
Definition drc_item.h:268
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:505
static DRC_ITEM textOnEdgeCuts
Definition drc_item.h:226
static DRC_ITEM creepage
Definition drc_item.h:228
static std::vector< std::reference_wrapper< RC_ITEM > > allItemTypes
A list of all DRC_ITEM types which are valid error codes.
Definition drc_item.h:212
static DRC_ITEM tuningProfileImplicitRules
Definition drc_item.h:297
static DRC_ITEM starvedThermal
Definition drc_item.h:234
static DRC_ITEM footprintScaledWithPads
Definition drc_item.h:293
static DRC_ITEM heading_deprecated
Definition drc_item.h:221
static DRC_ITEM shortingItems
Definition drc_item.h:224
static DRC_ITEM tracksCrossing
Definition drc_item.h:229
static DRC_ITEM missingCourtyard
Definition drc_item.h:257
static DRC_ITEM skewOutOfRange
Definition drc_item.h:286
static DRC_ITEM trackDangling
Definition drc_item.h:236
static DRC_ITEM netChainStubTooLong
Definition drc_item.h:283
static DRC_ITEM viaDangling
Definition drc_item.h:235
static DRC_ITEM genericError
Definition drc_item.h:274
static DRC_ITEM netChainReturnPathBreak
Definition drc_item.h:284
static DRC_ITEM drillTooSmall
Definition drc_item.h:245
static DRC_ITEM holesCoLocated
Definition drc_item.h:238
static DRC_ITEM missingFootprint
Definition drc_item.h:264
static DRC_ITEM textHeightOutOfRange
Definition drc_item.h:280
static DRC_ITEM diffPairGapOutOfRange
Definition drc_item.h:288
static DRC_ITEM heading_electrical
Definition drc_item.h:214
static DRC_ITEM padstack
Definition drc_item.h:247
static DRC_ITEM itemOnDisabledLayer
Definition drc_item.h:261
static DRC_ITEM mirroredTextOnFrontLayer
Definition drc_item.h:294
static DRC_ITEM heading_readability
Definition drc_item.h:218
static DRC_ITEM microviaStackNotFilled
Definition drc_item.h:251
static DRC_ITEM itemsNotAllowed
Definition drc_item.h:225
static DRC_ITEM holeAspectRatio
Definition drc_item.h:253
DRC_ITEM(int aErrorCode=0, const wxString &aTitle="", const wxString &aSettingsKey="")
Definition drc_item.h:203
static DRC_ITEM extraFootprint
Definition drc_item.h:265
static DRC_ITEM diffPairUncoupledLengthTooLong
Definition drc_item.h:289
static DRC_ITEM netChainTuningProfiles
Definition drc_item.h:285
KIID GetAuxItem2ID() const override
Definition drc_item.cpp:609
static DRC_ITEM unconnectedItems
Definition drc_item.h:223
static DRC_ITEM clearance
Definition drc_item.h:227
DRC_RULE * m_violatingRule
Definition drc_item.h:304
static DRC_ITEM missingTuningProfile
Definition drc_item.h:296
static DRC_ITEM libFootprintMismatch
Definition drc_item.h:270
static DRC_ITEM microviaCrossesCore
Definition drc_item.h:254
static DRC_ITEM malformedMicroviaStackSpan
Definition drc_item.h:250
static DRC_ITEM viaCountOutOfRange
Definition drc_item.h:287
static DRC_ITEM lineWidthOutOfRange
Definition drc_item.h:281
static DRC_ITEM copperOutsideBoard
Definition drc_item.h:231
static DRC_ITEM edgeClearance
Definition drc_item.h:230
static DRC_ITEM silkMaskClearance
Definition drc_item.h:276
static DRC_ITEM unMirroredTextOnBackLayer
Definition drc_item.h:295
static DRC_ITEM genericWarning
Definition drc_item.h:273
static DRC_ITEM schematicFieldsParity
Definition drc_item.h:300
static DRC_ITEM invalidOutline
Definition drc_item.h:262
static DRC_ITEM isolatedCopper
Definition drc_item.h:233
static DRC_ITEM malformedCourtyard
Definition drc_item.h:258
static DRC_ITEM heading_internal
Definition drc_item.h:220
static DRC_ITEM holeClearance
Definition drc_item.h:239
static DRC_ITEM libFootprintIssues
Definition drc_item.h:269
static DRC_ITEM padstackInvalid
Definition drc_item.h:248
static DRC_ITEM trackAngle
Definition drc_item.h:242
static DRC_ITEM heading_schematic_parity
Definition drc_item.h:216
static DRC_ITEM microviaDrillTooSmall
Definition drc_item.h:249
wxString GetViolatingRuleDesc(bool aTranslate) const override
Definition drc_item.cpp:633
static DRC_ITEM solderMaskBridge
Definition drc_item.h:278
static DRC_ITEM heading_misc
Definition drc_item.h:219
static DRC_ITEM footprintTypeMismatch
Definition drc_item.h:291
static DRC_ITEM footprintTHPadhasNoHole
Definition drc_item.h:292
static DRC_ITEM silkClearance
Definition drc_item.h:279
static DRC_ITEM duplicateFootprints
Definition drc_item.h:263
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
static const LSET & AllLayersMask()
Definition lset.cpp:637
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition pad.h:61
int m_errorCode
The error code's numeric value.
Definition rc_item.h:260
std::vector< KIID > m_ids
Definition rc_item.h:266
int ConvertPadCheckToDrcCode(PAD_UTILS::PAD_CHECK_CODE aCode)
Map a granular PAD_UTILS::PAD_CHECK_CODE to the DRC error code used to report it at the DRC level (in...
Definition drc_item.cpp:32
@ DRCE_DISABLED_LAYER_ITEM
Definition drc_item.h:86
@ DRCE_FOOTPRINT_SCALED_WITH_PADS
Definition drc_item.h:101
@ DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG
Definition drc_item.h:126
@ DRCE_SKEW_OUT_OF_RANGE
Definition drc_item.h:123
@ DRCE_CREEPAGE
Definition drc_item.h:53
@ DRCE_TUNING_PROFILE_IMPLICIT_RULES
Definition drc_item.h:132
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:63
@ DRCE_MICROVIA_STACK_DEPTH
Definition drc_item.h:76
@ DRCE_SILK_EDGE_CLEARANCE
Definition drc_item.h:114
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:94
@ DRCE_SILK_MASK_CLEARANCE
Definition drc_item.h:112
@ DRCE_VIA_DIAMETER
Definition drc_item.h:70
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:48
@ DRCE_DP_GAP_OUT_OF_RANGE
Definition drc_item.h:125
@ DRCE_TRACK_WIDTH
Definition drc_item.h:64
@ DRCE_PADSTACK
Definition drc_item.h:71
@ DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
Definition drc_item.h:128
@ DRCE_HOLE_ASPECT_RATIO
Definition drc_item.h:77
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:97
@ DRCE_VIA_STITCH_OVERLAP
Definition drc_item.h:140
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:78
@ DRCE_OVERLAPPING_FOOTPRINTS
Definition drc_item.h:80
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:87
@ DRCE_TRACK_ON_POST_MACHINED_LAYER
Definition drc_item.h:134
@ DRCE_TEXT_ON_EDGECUTS
Definition drc_item.h:51
@ DRCE_NET_CHAIN_STUB_TOO_LONG
Definition drc_item.h:120
@ DRCE_MALFORMED_MICROVIA_STACK_SPAN
Definition drc_item.h:74
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:69
@ DRCE_EDGE_CLEARANCE
Definition drc_item.h:55
@ DRCE_NET_CHAIN_RETURN_PATH_BREAK
Definition drc_item.h:121
@ DRCE_STARVED_THERMAL
Definition drc_item.h:58
@ DRCE_TRACK_SEGMENT_LENGTH
Definition drc_item.h:66
@ DRCE_SCHEMATIC_FIELDS_PARITY
Definition drc_item.h:138
@ DRCE_MISSING_COURTYARD
Definition drc_item.h:81
@ DRCE_MICROVIA_STACK_NOT_FILLED
Definition drc_item.h:75
@ DRCE_TRACK_ANGLE
Definition drc_item.h:65
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:136
@ DRCE_COPPER_OUTSIDE_BOARD
Definition drc_item.h:143
@ DRCE_CLEARANCE
Definition drc_item.h:52
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:57
@ DRCE_GENERIC_ERROR
Definition drc_item.h:106
@ DRCE_NET_CHAIN_TUNING_PROFILES
Definition drc_item.h:122
@ DRCE_MISSING_TUNING_PROFILE
Definition drc_item.h:131
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:61
@ DRCE_ALLOWED_ITEMS
Definition drc_item.h:50
@ DRCE_COPPER_SLIVER
Definition drc_item.h:108
@ DRCE_PTH_IN_COURTYARD
Definition drc_item.h:84
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition drc_item.h:73
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:49
@ DRCE_MALFORMED_COURTYARD
Definition drc_item.h:82
@ DRCE_DANGLING_VIA
Definition drc_item.h:59
@ DRCE_PADSTACK_INVALID
Definition drc_item.h:72
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:103
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:96
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:90
@ DRCE_DANGLING_TRACK
Definition drc_item.h:60
@ DRCE_TEXT_HEIGHT
Definition drc_item.h:116
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:104
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:109
@ DRCE_DRILLED_HOLES_COLOCATED
Definition drc_item.h:62
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:91
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:115
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:119
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:98
@ DRCE_NET_CONFLICT
Definition drc_item.h:92
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:89
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:99
@ DRCE_FOOTPRINT
Definition drc_item.h:100
@ DRCE_UNMIRRORED_TEXT_ON_BACK_LAYER
Definition drc_item.h:129
@ DRCE_LINE_WIDTH
Definition drc_item.h:117
@ DRCE_GENERIC_WARNING
Definition drc_item.h:105
@ DRCE_NPTH_IN_COURTYARD
Definition drc_item.h:85
@ DRCE_CONNECTION_WIDTH
Definition drc_item.h:68
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:93
@ DRCE_TRACKS_CROSSING
Definition drc_item.h:54
@ DRCE_VIA_COUNT_OUT_OF_RANGE
Definition drc_item.h:124
@ DRCE_MICROVIA_SPANS_DIELECTRICS
Definition drc_item.h:79
@ DRCE_ANNULAR_WIDTH
Definition drc_item.h:67
#define _(s)
#define MALFORMED_F_COURTYARD
#define MALFORMED_B_COURTYARD
Some functions to handle hotkeys in KiCad.
KIID niluuid(0)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ Edge_Cuts
Definition layer_ids.h:108
@ B_CrtYd
Definition layer_ids.h:111
@ UNDEFINED_LAYER
Definition layer_ids.h:57
PAD_CHECK_CODE
A specific pad check finding reason.
Definition pad_utils.h:82
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
#define _HKI(x)
Definition page_info.cpp:40
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79