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