KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_engine.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-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2014 Dick Hollenbeck, [email protected]
6 * Copyright (C) 2017-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <atomic>
27#include <reporter.h>
28#include <progress_reporter.h>
29#include <string_utils.h>
31#include <drc/drc_engine.h>
32#include <drc/drc_rtree.h>
33#include <drc/drc_rule_parser.h>
34#include <drc/drc_rule.h>
37#include <drc/drc_item.h>
39#include <footprint.h>
40#include <pad.h>
41#include <pcb_track.h>
42#include <core/thread_pool.h>
43#include <zone.h>
44
45
46// wxListBox's performance degrades horrifically with very large datasets. It's not clear
47// they're useful to the user anyway.
48#define ERROR_LIMIT 199
49#define EXTENDED_ERROR_LIMIT 499
50
51
52void drcPrintDebugMessage( int level, const wxString& msg, const char *function, int line )
53{
54 wxString valueStr;
55
56 if( wxGetEnv( wxT( "DRC_DEBUG" ), &valueStr ) )
57 {
58 int setLevel = wxAtoi( valueStr );
59
60 if( level <= setLevel )
61 printf( "%-30s:%d | %s\n", function, line, (const char *) msg.c_str() );
62 }
63}
64
65
68 m_designSettings ( aSettings ),
69 m_board( aBoard ),
70 m_drawingSheet( nullptr ),
71 m_schematicNetlist( nullptr ),
72 m_rulesValid( false ),
73 m_reportAllTrackErrors( false ),
74 m_testFootprints( false ),
75 m_reporter( nullptr ),
76 m_progressReporter( nullptr )
77{
78 m_errorLimits.resize( DRCE_LAST + 1 );
79
80 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
82}
83
84
86{
87 m_rules.clear();
88
89 for( std::pair<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> pair : m_constraintMap )
90 {
91 for( DRC_ENGINE_CONSTRAINT* constraint : *pair.second )
92 delete constraint;
93
94 delete pair.second;
95 }
96}
97
98
99static bool isKeepoutZone( const BOARD_ITEM* aItem, bool aCheckFlags )
100{
101 if( !aItem || aItem->Type() != PCB_ZONE_T )
102 return false;
103
104 const ZONE* zone = static_cast<const ZONE*>( aItem );
105
106 if( !zone->GetIsRuleArea() )
107 return false;
108
109 if( aCheckFlags )
110 {
111 if( !zone->GetDoNotAllowTracks()
112 && !zone->GetDoNotAllowVias()
113 && !zone->GetDoNotAllowPads()
114 && !zone->GetDoNotAllowCopperPour()
115 && !zone->GetDoNotAllowFootprints() )
116 {
117 return false;
118 }
119 }
120
121 return true;
122}
123
124
125std::shared_ptr<DRC_RULE> DRC_ENGINE::createImplicitRule( const wxString& name )
126{
127 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
128
129 rule->m_Name = name;
130 rule->m_Implicit = true;
131
132 addRule( rule );
133
134 return rule;
135}
136
137
139{
140 ReportAux( wxString::Format( wxT( "Building implicit rules (per-item/class overrides, etc...)" ) ) );
141
143
144 // 1) global defaults
145
146 std::shared_ptr<DRC_RULE> rule = createImplicitRule( _( "board setup constraints" ) );
147
148 DRC_CONSTRAINT widthConstraint( TRACK_WIDTH_CONSTRAINT );
149 widthConstraint.Value().SetMin( bds.m_TrackMinWidth );
150 rule->AddConstraint( widthConstraint );
151
152 DRC_CONSTRAINT connectionConstraint( CONNECTION_WIDTH_CONSTRAINT );
153 connectionConstraint.Value().SetMin( bds.m_MinConn );
154 rule->AddConstraint( connectionConstraint );
155
156 DRC_CONSTRAINT drillConstraint( HOLE_SIZE_CONSTRAINT );
157 drillConstraint.Value().SetMin( bds.m_MinThroughDrill );
158 rule->AddConstraint( drillConstraint );
159
160 DRC_CONSTRAINT annulusConstraint( ANNULAR_WIDTH_CONSTRAINT );
161 annulusConstraint.Value().SetMin( bds.m_ViasMinAnnularWidth );
162 rule->AddConstraint( annulusConstraint );
163
164 DRC_CONSTRAINT diameterConstraint( VIA_DIAMETER_CONSTRAINT );
165 diameterConstraint.Value().SetMin( bds.m_ViasMinSize );
166 rule->AddConstraint( diameterConstraint );
167
168 DRC_CONSTRAINT holeToHoleConstraint( HOLE_TO_HOLE_CONSTRAINT );
169 holeToHoleConstraint.Value().SetMin( bds.m_HoleToHoleMin );
170 rule->AddConstraint( holeToHoleConstraint );
171
172 rule = createImplicitRule( _( "board setup constraints zone fill strategy" ) );
173 DRC_CONSTRAINT thermalSpokeCountConstraint( MIN_RESOLVED_SPOKES_CONSTRAINT );
174 thermalSpokeCountConstraint.Value().SetMin( bds.m_MinResolvedSpokes );
175 rule->AddConstraint( thermalSpokeCountConstraint );
176
177 rule = createImplicitRule( _( "board setup constraints silk" ) );
178 rule->m_LayerCondition = LSET( 2, F_SilkS, B_SilkS );
179 DRC_CONSTRAINT silkClearanceConstraint( SILK_CLEARANCE_CONSTRAINT );
180 silkClearanceConstraint.Value().SetMin( bds.m_SilkClearance );
181 rule->AddConstraint( silkClearanceConstraint );
182
183 rule = createImplicitRule( _( "board setup constraints silk text height" ) );
184 rule->m_LayerCondition = LSET( 2, F_SilkS, B_SilkS );
185 DRC_CONSTRAINT silkTextHeightConstraint( TEXT_HEIGHT_CONSTRAINT );
186 silkTextHeightConstraint.Value().SetMin( bds.m_MinSilkTextHeight );
187 rule->AddConstraint( silkTextHeightConstraint );
188
189 rule = createImplicitRule( _( "board setup constraints silk text thickness" ) );
190 rule->m_LayerCondition = LSET( 2, F_SilkS, B_SilkS );
191 DRC_CONSTRAINT silkTextThicknessConstraint( TEXT_THICKNESS_CONSTRAINT );
192 silkTextThicknessConstraint.Value().SetMin( bds.m_MinSilkTextThickness );
193 rule->AddConstraint( silkTextThicknessConstraint );
194
195 rule = createImplicitRule( _( "board setup constraints hole" ) );
196 DRC_CONSTRAINT holeClearanceConstraint( HOLE_CLEARANCE_CONSTRAINT );
197 holeClearanceConstraint.Value().SetMin( bds.m_HoleClearance );
198 rule->AddConstraint( holeClearanceConstraint );
199
200 rule = createImplicitRule( _( "board setup constraints edge" ) );
201 DRC_CONSTRAINT edgeClearanceConstraint( EDGE_CLEARANCE_CONSTRAINT );
202 edgeClearanceConstraint.Value().SetMin( bds.m_CopperEdgeClearance );
203 rule->AddConstraint( edgeClearanceConstraint );
204
205 rule = createImplicitRule( _( "board setup constraints courtyard" ) );
206 DRC_CONSTRAINT courtyardClearanceConstraint( COURTYARD_CLEARANCE_CONSTRAINT );
207 holeToHoleConstraint.Value().SetMin( 0 );
208 rule->AddConstraint( courtyardClearanceConstraint );
209
210 // 2) micro-via specific defaults (new DRC doesn't treat microvias in any special way)
211
212 std::shared_ptr<DRC_RULE> uViaRule = createImplicitRule( _( "board setup micro-via constraints" ) );
213
214 uViaRule->m_Condition = new DRC_RULE_CONDITION( wxT( "A.Via_Type == 'Micro'" ) );
215
216 DRC_CONSTRAINT uViaDrillConstraint( HOLE_SIZE_CONSTRAINT );
217 uViaDrillConstraint.Value().SetMin( bds.m_MicroViasMinDrill );
218 uViaRule->AddConstraint( uViaDrillConstraint );
219
220 DRC_CONSTRAINT uViaDiameterConstraint( VIA_DIAMETER_CONSTRAINT );
221 uViaDiameterConstraint.Value().SetMin( bds.m_MicroViasMinSize );
222 uViaRule->AddConstraint( uViaDiameterConstraint );
223
224 // 3) per-netclass rules
225
226 std::vector<std::shared_ptr<DRC_RULE>> netclassClearanceRules;
227 std::vector<std::shared_ptr<DRC_RULE>> netclassItemSpecificRules;
228
229 auto makeNetclassRules =
230 [&]( const std::shared_ptr<NETCLASS>& nc, bool isDefault )
231 {
232 wxString ncName = nc->GetName();
233 wxString friendlyName;
234 wxString* shownName = &ncName;
235 wxString expr;
236
237 if( ncName.Replace( "'", "\\'" ) )
238 {
239 friendlyName = nc->GetName();
240 shownName = &friendlyName;
241 }
242
243 if( nc->GetClearance() || nc->GetTrackWidth() )
244 {
245 std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
246 netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), *shownName );
247 netclassRule->m_Implicit = true;
248
249 expr = wxString::Format( wxT( "A.NetClass == '%s'" ), ncName );
250 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
251 netclassClearanceRules.push_back( netclassRule );
252
253 if( nc->GetClearance() )
254 {
256 constraint.Value().SetMin( nc->GetClearance() );
257 netclassRule->AddConstraint( constraint );
258 }
259
260 if( nc->GetTrackWidth() )
261 {
263 constraint.Value().SetMin( bds.m_TrackMinWidth );
264 constraint.Value().SetOpt( nc->GetTrackWidth() );
265 netclassRule->AddConstraint( constraint );
266 }
267 }
268
269 if( nc->GetDiffPairWidth() )
270 {
271 std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
272 netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
273 *shownName );
274 netclassRule->m_Implicit = true;
275
276 expr = wxString::Format( wxT( "A.NetClass == '%s' && A.inDiffPair('*')" ),
277 ncName );
278 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
279 netclassItemSpecificRules.push_back( netclassRule );
280
282 constraint.Value().SetMin( bds.m_TrackMinWidth );
283 constraint.Value().SetOpt( nc->GetDiffPairWidth() );
284 netclassRule->AddConstraint( constraint );
285 }
286
287 if( nc->GetDiffPairGap() )
288 {
289 std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
290 netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
291 *shownName );
292 netclassRule->m_Implicit = true;
293
294 expr = wxString::Format( wxT( "A.NetClass == '%s'" ), ncName );
295 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
296 netclassItemSpecificRules.push_back( netclassRule );
297
299 constraint.Value().SetMin( bds.m_MinClearance );
300 constraint.Value().SetOpt( nc->GetDiffPairGap() );
301 netclassRule->AddConstraint( constraint );
302
303 // A narrower diffpair gap overrides the netclass min clearance
304 if( nc->GetDiffPairGap() < nc->GetClearance() )
305 {
306 netclassRule = std::make_shared<DRC_RULE>();
307 netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
308 *shownName );
309 netclassRule->m_Implicit = true;
310
311 expr = wxString::Format( wxT( "A.NetClass == '%s' && AB.isCoupledDiffPair()" ),
312 ncName );
313 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
314 netclassItemSpecificRules.push_back( netclassRule );
315
316 DRC_CONSTRAINT min_clearanceConstraint( CLEARANCE_CONSTRAINT );
317 min_clearanceConstraint.Value().SetMin( nc->GetDiffPairGap() );
318 netclassRule->AddConstraint( min_clearanceConstraint );
319 }
320 }
321
322 if( nc->GetViaDiameter() || nc->GetViaDrill() )
323 {
324 std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
325 netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), *shownName );
326 netclassRule->m_Implicit = true;
327
328 expr = wxString::Format( wxT( "A.NetClass == '%s' && A.Via_Type != 'Micro'" ),
329 ncName );
330 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
331 netclassItemSpecificRules.push_back( netclassRule );
332
333 if( nc->GetViaDiameter() )
334 {
336 constraint.Value().SetMin( bds.m_ViasMinSize );
337 constraint.Value().SetOpt( nc->GetViaDiameter() );
338 netclassRule->AddConstraint( constraint );
339 }
340
341 if( nc->GetViaDrill() )
342 {
344 constraint.Value().SetMin( bds.m_MinThroughDrill );
345 constraint.Value().SetOpt( nc->GetViaDrill() );
346 netclassRule->AddConstraint( constraint );
347 }
348 }
349
350 if( nc->GetuViaDiameter() || nc->GetuViaDrill() )
351 {
352 std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
353 netclassRule->m_Name = wxString::Format( _( "netclass '%s' (uvia)" ),
354 *shownName );
355 netclassRule->m_Implicit = true;
356
357 expr = wxString::Format( wxT( "A.NetClass == '%s' && A.Via_Type == 'Micro'" ),
358 ncName );
359 netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
360 netclassItemSpecificRules.push_back( netclassRule );
361
362 if( nc->GetuViaDiameter() )
363 {
365 constraint.Value().SetMin( bds.m_MicroViasMinSize );
366 constraint.Value().SetMin( nc->GetuViaDiameter() );
367 netclassRule->AddConstraint( constraint );
368 }
369
370 if( nc->GetuViaDrill() )
371 {
373 constraint.Value().SetMin( bds.m_MicroViasMinDrill );
374 constraint.Value().SetOpt( nc->GetuViaDrill() );
375 netclassRule->AddConstraint( constraint );
376 }
377 }
378 };
379
381 makeNetclassRules( bds.m_NetSettings->m_DefaultNetClass, true );
382
383 for( const auto& [ name, netclass ] : bds.m_NetSettings->m_NetClasses )
384 makeNetclassRules( netclass, false );
385
386 // The netclass clearance rules have to be sorted by min clearance so the right one fires
387 // if 'A' and 'B' belong to two different netclasses.
388 //
389 // The item-specific netclass rules are all unary, so there's no 'A' vs 'B' issue.
390
391 std::sort( netclassClearanceRules.begin(), netclassClearanceRules.end(),
392 []( const std::shared_ptr<DRC_RULE>& lhs, const std::shared_ptr<DRC_RULE>& rhs )
393 {
394 return lhs->m_Constraints[0].m_Value.Min()
395 < rhs->m_Constraints[0].m_Value.Min();
396 } );
397
398 for( std::shared_ptr<DRC_RULE>& ncRule : netclassClearanceRules )
399 addRule( ncRule );
400
401 for( std::shared_ptr<DRC_RULE>& ncRule : netclassItemSpecificRules )
402 addRule( ncRule );
403
404 // 3) keepout area rules
405
406 std::vector<ZONE*> keepoutZones;
407
408 for( ZONE* zone : m_board->Zones() )
409 {
410 if( isKeepoutZone( zone, true ) )
411 keepoutZones.push_back( zone );
412 }
413
414 for( FOOTPRINT* footprint : m_board->Footprints() )
415 {
416 for( ZONE* zone : footprint->Zones() )
417 {
418 if( isKeepoutZone( zone, true ) )
419 keepoutZones.push_back( zone );
420 }
421 }
422
423 for( ZONE* zone : keepoutZones )
424 {
425 wxString name = zone->GetZoneName();
426
427 if( name.IsEmpty() )
428 rule = createImplicitRule( _( "keepout area" ) );
429 else
430 rule = createImplicitRule( wxString::Format( _( "keepout area '%s'" ), name ) );
431
432 rule->m_ImplicitItemId = zone->m_Uuid;
433
434 rule->m_Condition = new DRC_RULE_CONDITION( wxString::Format( wxT( "A.intersectsArea('%s')" ),
435 zone->m_Uuid.AsString() ) );
436
437 rule->m_LayerCondition = zone->GetLayerSet();
438
439 int disallowFlags = 0;
440
441 if( zone->GetDoNotAllowTracks() )
442 disallowFlags |= DRC_DISALLOW_TRACKS;
443
444 if( zone->GetDoNotAllowVias() )
445 disallowFlags |= DRC_DISALLOW_VIAS;
446
447 if( zone->GetDoNotAllowPads() )
448 disallowFlags |= DRC_DISALLOW_PADS;
449
450 if( zone->GetDoNotAllowCopperPour() )
451 disallowFlags |= DRC_DISALLOW_ZONES;
452
453 if( zone->GetDoNotAllowFootprints() )
454 disallowFlags |= DRC_DISALLOW_FOOTPRINTS;
455
456 DRC_CONSTRAINT disallowConstraint( DISALLOW_CONSTRAINT );
457 disallowConstraint.m_DisallowFlags = disallowFlags;
458 rule->AddConstraint( disallowConstraint );
459 }
460
461 ReportAux( wxString::Format( wxT( "Building %d implicit netclass rules" ),
462 (int) netclassClearanceRules.size() ) );
463}
464
465
466void DRC_ENGINE::loadRules( const wxFileName& aPath )
467{
468 if( aPath.FileExists() )
469 {
470 std::vector<std::shared_ptr<DRC_RULE>> rules;
471
472 FILE* fp = wxFopen( aPath.GetFullPath(), wxT( "rt" ) );
473
474 if( fp )
475 {
476 DRC_RULES_PARSER parser( fp, aPath.GetFullPath() );
477 parser.Parse( rules, m_reporter );
478 }
479
480 // Copy the rules into the member variable afterwards so that if Parse() throws then
481 // the possibly malformed rules won't contaminate the current ruleset.
482
483 for( std::shared_ptr<DRC_RULE>& rule : rules )
484 m_rules.push_back( rule );
485 }
486}
487
488
490{
491 ReportAux( wxString::Format( wxT( "Compiling Rules (%d rules): " ), (int) m_rules.size() ) );
492
493 for( std::shared_ptr<DRC_RULE>& rule : m_rules )
494 {
495 DRC_RULE_CONDITION* condition = nullptr;
496
497 if( rule->m_Condition && !rule->m_Condition->GetExpression().IsEmpty() )
498 {
499 condition = rule->m_Condition;
500 condition->Compile( nullptr );
501 }
502
503 for( const DRC_CONSTRAINT& constraint : rule->m_Constraints )
504 {
505 if( !m_constraintMap.count( constraint.m_Type ) )
506 m_constraintMap[ constraint.m_Type ] = new std::vector<DRC_ENGINE_CONSTRAINT*>();
507
508 DRC_ENGINE_CONSTRAINT* engineConstraint = new DRC_ENGINE_CONSTRAINT;
509
510 engineConstraint->layerTest = rule->m_LayerCondition;
511 engineConstraint->condition = condition;
512 engineConstraint->constraint = constraint;
513 engineConstraint->parentRule = rule;
514 m_constraintMap[ constraint.m_Type ]->push_back( engineConstraint );
515 }
516 }
517}
518
519
520void DRC_ENGINE::InitEngine( const wxFileName& aRulePath )
521{
523
524 for( DRC_TEST_PROVIDER* provider : m_testProviders )
525 {
526 ReportAux( wxString::Format( wxT( "Create DRC provider: '%s'" ), provider->GetName() ) );
527 provider->SetDRCEngine( this );
528 }
529
530 m_rules.clear();
531 m_rulesValid = false;
532
533 for( std::pair<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> pair : m_constraintMap )
534 {
535 for( DRC_ENGINE_CONSTRAINT* constraint : *pair.second )
536 delete constraint;
537
538 delete pair.second;
539 }
540
541 m_constraintMap.clear();
542
543 m_board->IncrementTimeStamp(); // Clear board-level caches
544
545 try // attempt to load full set of rules (implicit + user rules)
546 {
548 loadRules( aRulePath );
549 compileRules();
550 }
551 catch( PARSE_ERROR& original_parse_error )
552 {
553 try // try again with just our implicit rules
554 {
556 compileRules();
557 }
558 catch( PARSE_ERROR& )
559 {
560 wxFAIL_MSG( wxT( "Compiling implicit rules failed." ) );
561 }
562
563 throw original_parse_error;
564 }
565
566 for( int ii = DRCE_FIRST; ii < DRCE_LAST; ++ii )
568
569 m_rulesValid = true;
570}
571
572
573void DRC_ENGINE::RunTests( EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints )
574{
575 SetUserUnits( aUnits );
576
577 m_reportAllTrackErrors = aReportAllTrackErrors;
578 m_testFootprints = aTestFootprints;
579
580 for( int ii = DRCE_FIRST; ii < DRCE_LAST; ++ii )
581 {
582 if( m_designSettings->Ignore( ii ) )
583 m_errorLimits[ ii ] = 0;
584 else if( ii == DRCE_CLEARANCE || ii == DRCE_UNCONNECTED_ITEMS )
586 else
588 }
589
591
592 m_board->IncrementTimeStamp(); // Invalidate all caches...
593
594 DRC_CACHE_GENERATOR cacheGenerator;
595 cacheGenerator.SetDRCEngine( this );
596
597 if( !cacheGenerator.Run() ) // ... and regenerate them.
598 return;
599
600 int timestamp = m_board->GetTimeStamp();
601
602 for( DRC_TEST_PROVIDER* provider : m_testProviders )
603 {
604 ReportAux( wxString::Format( wxT( "Run DRC provider: '%s'" ), provider->GetName() ) );
605
606 if( !provider->RunTests( aUnits ) )
607 break;
608 }
609
610 // DRC tests are multi-threaded; anything that causes us to attempt to re-generate the
611 // caches while DRC is running is problematic.
612 wxASSERT( timestamp == m_board->GetTimeStamp() );
613}
614
615
616#define REPORT( s ) { if( aReporter ) { aReporter->Report( s ); } }
617
619 PCB_LAYER_ID aLayer, REPORTER* aReporter )
620{
621 DRC_CONSTRAINT constraint = EvalRules( ZONE_CONNECTION_CONSTRAINT, a, b, aLayer, aReporter );
622
623 REPORT( "" )
624 REPORT( wxString::Format( _( "Resolved zone connection type: %s." ),
626
627 if( constraint.m_ZoneConnection == ZONE_CONNECTION::THT_THERMAL )
628 {
629 const PAD* pad = nullptr;
630
631 if( a->Type() == PCB_PAD_T )
632 pad = static_cast<const PAD*>( a );
633 else if( b->Type() == PCB_PAD_T )
634 pad = static_cast<const PAD*>( b );
635
636 if( pad && pad->GetAttribute() == PAD_ATTRIB::PTH )
637 {
638 constraint.m_ZoneConnection = ZONE_CONNECTION::THERMAL;
639 }
640 else
641 {
642 REPORT( wxString::Format( _( "Pad is not a through hole pad; connection will be: %s." ),
643 EscapeHTML( PrintZoneConnection( ZONE_CONNECTION::FULL ) ) ) )
644 constraint.m_ZoneConnection = ZONE_CONNECTION::FULL;
645 }
646 }
647
648 return constraint;
649}
650
651
652bool hasDrilledHole( const BOARD_ITEM* aItem )
653{
654 if( !aItem->HasHole() )
655 return false;
656
657 switch( aItem->Type() )
658 {
659 case PCB_VIA_T:
660 return true;
661
662 case PCB_PAD_T:
663 {
664 const PAD* pad = static_cast<const PAD*>( aItem );
665
666 return pad->GetDrillSizeX() == pad->GetDrillSizeY();
667 }
668
669 default:
670 return false;
671 }
672}
673
674
676 const BOARD_ITEM* b, PCB_LAYER_ID aLayer,
677 REPORTER* aReporter )
678{
679 /*
680 * NOTE: all string manipulation MUST BE KEPT INSIDE the REPORT macro. It absolutely
681 * kills performance when running bulk DRC tests (where aReporter is nullptr).
682 */
683
684 const BOARD_CONNECTED_ITEM* ac = a && a->IsConnected() ?
685 static_cast<const BOARD_CONNECTED_ITEM*>( a ) : nullptr;
686 const BOARD_CONNECTED_ITEM* bc = b && b->IsConnected() ?
687 static_cast<const BOARD_CONNECTED_ITEM*>( b ) : nullptr;
688
689 bool a_is_non_copper = a && ( !a->IsOnCopperLayer() || isKeepoutZone( a, false ) );
690 bool b_is_non_copper = b && ( !b->IsOnCopperLayer() || isKeepoutZone( b, false ) );
691
692 const PAD* pad = nullptr;
693 const ZONE* zone = nullptr;
694 const FOOTPRINT* parentFootprint = nullptr;
695
696 if( aConstraintType == ZONE_CONNECTION_CONSTRAINT
697 || aConstraintType == THERMAL_RELIEF_GAP_CONSTRAINT
698 || aConstraintType == THERMAL_SPOKE_WIDTH_CONSTRAINT )
699 {
700 if( a && a->Type() == PCB_PAD_T )
701 pad = static_cast<const PAD*>( a );
702 else if( a && a->Type() == PCB_ZONE_T )
703 zone = static_cast<const ZONE*>( a );
704
705 if( b && b->Type() == PCB_PAD_T )
706 pad = static_cast<const PAD*>( b );
707 else if( b && b->Type() == PCB_ZONE_T )
708 zone = static_cast<const ZONE*>( b );
709
710 if( pad )
711 parentFootprint = pad->GetParentFootprint();
712 }
713
714 DRC_CONSTRAINT constraint;
715 constraint.m_Type = aConstraintType;
716
717 auto applyConstraint =
718 [&]( const DRC_ENGINE_CONSTRAINT* c )
719 {
720 if( c->constraint.m_Value.HasMin() )
721 constraint.m_Value.SetMin( c->constraint.m_Value.Min() );
722
723 if( c->constraint.m_Value.HasOpt() )
724 constraint.m_Value.SetOpt( c->constraint.m_Value.Opt() );
725
726 if( c->constraint.m_Value.HasMax() )
727 constraint .m_Value.SetMax( c->constraint.m_Value.Max() );
728
729 // While the expectation would be to OR the disallow flags, we've already
730 // masked them down to aItem's type -- so we're really only looking for a
731 // boolean here.
732 constraint.m_DisallowFlags = c->constraint.m_DisallowFlags;
733
734 constraint.m_ZoneConnection = c->constraint.m_ZoneConnection;
735
736 constraint.SetParentRule( c->constraint.GetParentRule() );
737 };
738
739 // Local overrides take precedence over everything *except* board min clearance
740 if( aConstraintType == CLEARANCE_CONSTRAINT || aConstraintType == HOLE_CLEARANCE_CONSTRAINT )
741 {
742 int override_val = 0;
743 std::optional<int> overrideA;
744 std::optional<int> overrideB;
745
746 if( ac && !b_is_non_copper )
747 overrideA = ac->GetClearanceOverrides( nullptr );
748
749 if( bc && !a_is_non_copper )
750 overrideB = bc->GetClearanceOverrides( nullptr );
751
752 if( overrideA.has_value() || overrideB.has_value() )
753 {
754 wxString msg;
755
756 if( overrideA.has_value() )
757 {
758 REPORT( "" )
759 REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
760 EscapeHTML( a->GetItemDescription( this ) ),
761 MessageTextFromValue( overrideA.value() ) ) )
762
763 override_val = ac->GetClearanceOverrides( &msg ).value();
764 }
765
766 if( overrideB.has_value() )
767 {
768 REPORT( "" )
769 REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
770 EscapeHTML( b->GetItemDescription( this ) ),
771 EscapeHTML( MessageTextFromValue( overrideB.value() ) ) ) )
772
773 if( overrideB > override_val )
774 override_val = bc->GetClearanceOverrides( &msg ).value();
775 }
776
777 if( override_val )
778 {
779 if( aConstraintType == CLEARANCE_CONSTRAINT )
780 {
781 if( override_val < m_designSettings->m_MinClearance )
782 {
783 override_val = m_designSettings->m_MinClearance;
784 msg = _( "board minimum" );
785
786 REPORT( "" )
787 REPORT( wxString::Format( _( "Board minimum clearance: %s." ),
788 MessageTextFromValue( override_val ) ) )
789 }
790 }
791 else
792 {
793 if( override_val < m_designSettings->m_HoleClearance )
794 {
795 override_val = m_designSettings->m_HoleClearance;
796 msg = _( "board minimum hole" );
797
798 REPORT( "" )
799 REPORT( wxString::Format( _( "Board minimum hole clearance: %s." ),
800 MessageTextFromValue( override_val ) ) )
801 }
802 }
803
804 constraint.SetName( msg );
805 constraint.m_Value.SetMin( override_val );
806 return constraint;
807 }
808 }
809 }
810 else if( aConstraintType == ZONE_CONNECTION_CONSTRAINT )
811 {
812 if( pad && pad->GetLocalZoneConnection() != ZONE_CONNECTION::INHERITED )
813 {
814 wxString msg;
815 ZONE_CONNECTION override = pad->GetZoneConnectionOverrides( &msg );
816
817 REPORT( "" )
818 REPORT( wxString::Format( _( "Local override on %s; zone connection: %s." ),
819 EscapeHTML( pad->GetItemDescription( this ) ),
820 EscapeHTML( PrintZoneConnection( override ) ) ) )
821
822 constraint.SetName( msg );
823 constraint.m_ZoneConnection = override;
824 return constraint;
825 }
826 }
827 else if( aConstraintType == THERMAL_RELIEF_GAP_CONSTRAINT )
828 {
829 if( pad && pad->GetLocalThermalGapOverride( nullptr ) > 0 )
830 {
831 wxString msg;
832 int gap_override = pad->GetLocalThermalGapOverride( &msg );
833
834 REPORT( "" )
835 REPORT( wxString::Format( _( "Local override on %s; thermal relief gap: %s." ),
836 EscapeHTML( pad->GetItemDescription( this ) ),
837 EscapeHTML( MessageTextFromValue( gap_override ) ) ) )
838
839 constraint.SetName( msg );
840 constraint.m_Value.SetMin( gap_override );
841 return constraint;
842 }
843 }
844 else if( aConstraintType == THERMAL_SPOKE_WIDTH_CONSTRAINT )
845 {
846 if( pad && pad->GetLocalSpokeWidthOverride( nullptr ) > 0 )
847 {
848 wxString msg;
849 int spoke_override = pad->GetLocalSpokeWidthOverride( &msg );
850
851 REPORT( "" )
852 REPORT( wxString::Format( _( "Local override on %s; thermal spoke width: %s." ),
853 EscapeHTML( pad->GetItemDescription( this ) ),
854 EscapeHTML( MessageTextFromValue( spoke_override ) ) ) )
855
856 if( zone && zone->GetMinThickness() > spoke_override )
857 {
858 spoke_override = zone->GetMinThickness();
859
860 REPORT( "" )
861 REPORT( wxString::Format( _( "%s min thickness: %s." ),
862 EscapeHTML( zone->GetItemDescription( this ) ),
863 EscapeHTML( MessageTextFromValue( spoke_override ) ) ) )
864 }
865
866 constraint.SetName( msg );
867 constraint.m_Value.SetMin( spoke_override );
868 return constraint;
869 }
870 }
871
872 auto testAssertion =
873 [&]( const DRC_ENGINE_CONSTRAINT* c )
874 {
875 REPORT( wxString::Format( _( "Checking assertion \"%s\"." ),
876 EscapeHTML( c->constraint.m_Test->GetExpression() ) ) )
877
878 if( c->constraint.m_Test->EvaluateFor( a, b, c->constraint.m_Type, aLayer,
879 aReporter ) )
880 {
881 REPORT( _( "Assertion passed." ) )
882 }
883 else
884 {
885 REPORT( EscapeHTML( _( "--> Assertion failed. <--" ) ) )
886 }
887 };
888
889 auto processConstraint =
890 [&]( const DRC_ENGINE_CONSTRAINT* c )
891 {
892 bool implicit = c->parentRule && c->parentRule->m_Implicit;
893
894 REPORT( "" )
895
896 switch( c->constraint.m_Type )
897 {
905 REPORT( wxString::Format( _( "Checking %s clearance: %s." ),
906 EscapeHTML( c->constraint.GetName() ),
907 MessageTextFromValue( c->constraint.m_Value.Min() ) ) )
908 break;
909
911 REPORT( wxString::Format( _( "Checking %s max uncoupled length: %s." ),
912 EscapeHTML( c->constraint.GetName() ),
913 MessageTextFromValue( c->constraint.m_Value.Max() ) ) )
914 break;
915
916 case SKEW_CONSTRAINT:
917 REPORT( wxString::Format( _( "Checking %s max skew: %s." ),
918 EscapeHTML( c->constraint.GetName() ),
919 MessageTextFromValue( c->constraint.m_Value.Max() ) ) )
920 break;
921
923 REPORT( wxString::Format( _( "Checking %s gap: %s." ),
924 EscapeHTML( c->constraint.GetName() ),
925 MessageTextFromValue( c->constraint.m_Value.Min() ) ) )
926 break;
927
929 REPORT( wxString::Format( _( "Checking %s thermal spoke width: %s." ),
930 EscapeHTML( c->constraint.GetName() ),
931 MessageTextFromValue( c->constraint.m_Value.Opt() ) ) )
932 break;
933
935 REPORT( wxString::Format( _( "Checking %s min spoke count: %s." ),
936 EscapeHTML( c->constraint.GetName() ),
938 c->constraint.m_Value.Min() ) ) )
939 break;
940
942 REPORT( wxString::Format( _( "Checking %s zone connection: %s." ),
943 EscapeHTML( c->constraint.GetName() ),
944 EscapeHTML( PrintZoneConnection( c->constraint.m_ZoneConnection ) ) ) )
945 break;
946
957 {
958 if( aReporter )
959 {
960 wxString min = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
961 wxString opt = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
962 wxString max = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
963
964 if( implicit )
965 {
966 min = MessageTextFromValue( c->constraint.m_Value.Min() );
967 opt = MessageTextFromValue( c->constraint.m_Value.Opt() );
968
969 switch( c->constraint.m_Type )
970 {
972 if( c->constraint.m_Value.HasOpt() )
973 {
974 REPORT( wxString::Format( _( "Checking %s track width: opt %s." ),
975 EscapeHTML( c->constraint.GetName() ),
976 opt ) )
977 }
978 else if( c->constraint.m_Value.HasMin() )
979 {
980 REPORT( wxString::Format( _( "Checking %s track width: min %s." ),
981 EscapeHTML( c->constraint.GetName() ),
982 min ) )
983 }
984
985 break;
986
988 REPORT( wxString::Format( _( "Checking %s annular width: min %s." ),
989 EscapeHTML( c->constraint.GetName() ),
990 opt ) )
991 break;
992
994 if( c->constraint.m_Value.HasOpt() )
995 {
996 REPORT( wxString::Format( _( "Checking %s via diameter: opt %s." ),
997 EscapeHTML( c->constraint.GetName() ),
998 opt ) )
999 }
1000 else if( c->constraint.m_Value.HasMin() )
1001 {
1002 REPORT( wxString::Format( _( "Checking %s via diameter: min %s." ),
1003 EscapeHTML( c->constraint.GetName() ),
1004 min ) )
1005 }
1006 break;
1007
1009 if( c->constraint.m_Value.HasOpt() )
1010 {
1011 REPORT( wxString::Format( _( "Checking %s hole size: opt %s." ),
1012 EscapeHTML( c->constraint.GetName() ),
1013 opt ) )
1014 }
1015 else if( c->constraint.m_Value.HasMin() )
1016 {
1017 REPORT( wxString::Format( _( "Checking %s hole size: min %s." ),
1018 EscapeHTML( c->constraint.GetName() ),
1019 min ) )
1020 }
1021
1022 break;
1023
1027 REPORT( wxString::Format( _( "Checking %s: min %s." ),
1028 EscapeHTML( c->constraint.GetName() ),
1029 min ) )
1030 break;
1031
1033 if( c->constraint.m_Value.HasOpt() )
1034 {
1035 REPORT( wxString::Format( _( "Checking %s diff pair gap: opt %s." ),
1036 EscapeHTML( c->constraint.GetName() ),
1037 opt ) )
1038 }
1039 else if( c->constraint.m_Value.HasMin() )
1040 {
1041 REPORT( wxString::Format( _( "Checking %s clearance: min %s." ),
1042 EscapeHTML( c->constraint.GetName() ),
1043 min ) )
1044 }
1045
1046 break;
1047
1049 REPORT( wxString::Format( _( "Checking %s hole to hole: min %s." ),
1050 EscapeHTML( c->constraint.GetName() ),
1051 min ) )
1052 break;
1053
1054 default:
1055 REPORT( wxString::Format( _( "Checking %s." ),
1056 EscapeHTML( c->constraint.GetName() ) ) )
1057 }
1058 }
1059 else
1060 {
1061 if( c->constraint.m_Value.HasMin() )
1062 min = MessageTextFromValue( c->constraint.m_Value.Min() );
1063
1064 if( c->constraint.m_Value.HasOpt() )
1065 opt = MessageTextFromValue( c->constraint.m_Value.Opt() );
1066
1067 if( c->constraint.m_Value.HasMax() )
1068 max = MessageTextFromValue( c->constraint.m_Value.Max() );
1069
1070 REPORT( wxString::Format( _( "Checking %s: min %s; opt %s; max %s." ),
1071 EscapeHTML( c->constraint.GetName() ),
1072 min,
1073 opt,
1074 max ) )
1075 }
1076 }
1077 break;
1078 }
1079
1080 default:
1081 REPORT( wxString::Format( _( "Checking %s." ),
1082 EscapeHTML( c->constraint.GetName() ) ) )
1083 }
1084
1085 if( c->constraint.m_Type == CLEARANCE_CONSTRAINT )
1086 {
1087 if( a_is_non_copper || b_is_non_copper )
1088 {
1089 if( implicit )
1090 {
1091 REPORT( _( "Netclass clearances apply only between copper items." ) )
1092 }
1093 else if( a_is_non_copper )
1094 {
1095 REPORT( wxString::Format( _( "%s contains no copper. Rule ignored." ),
1096 EscapeHTML( a->GetItemDescription( this ) ) ) )
1097 }
1098 else if( b_is_non_copper )
1099 {
1100 REPORT( wxString::Format( _( "%s contains no copper. Rule ignored." ),
1101 EscapeHTML( b->GetItemDescription( this ) ) ) )
1102 }
1103
1104 return;
1105 }
1106 }
1107 else if( c->constraint.m_Type == DISALLOW_CONSTRAINT )
1108 {
1109 int mask;
1110
1111 if( a->GetFlags() & HOLE_PROXY )
1112 {
1113 mask = DRC_DISALLOW_HOLES;
1114 }
1115 else if( a->Type() == PCB_VIA_T )
1116 {
1117 mask = DRC_DISALLOW_VIAS;
1118
1119 switch( static_cast<const PCB_VIA*>( a )->GetViaType() )
1120 {
1121 case VIATYPE::BLIND_BURIED: mask |= DRC_DISALLOW_BB_VIAS; break;
1122 case VIATYPE::MICROVIA: mask |= DRC_DISALLOW_MICRO_VIAS; break;
1123 default: break;
1124 }
1125 }
1126 else
1127 {
1128 switch( a->Type() )
1129 {
1130 case PCB_TRACE_T: mask = DRC_DISALLOW_TRACKS; break;
1131 case PCB_ARC_T: mask = DRC_DISALLOW_TRACKS; break;
1132 case PCB_PAD_T: mask = DRC_DISALLOW_PADS; break;
1133 case PCB_FOOTPRINT_T: mask = DRC_DISALLOW_FOOTPRINTS; break;
1134 case PCB_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break;
1135 case PCB_FIELD_T: mask = DRC_DISALLOW_TEXTS; break;
1136 case PCB_TEXT_T: mask = DRC_DISALLOW_TEXTS; break;
1137 case PCB_TEXTBOX_T: mask = DRC_DISALLOW_TEXTS; break;
1138 case PCB_TABLE_T: mask = DRC_DISALLOW_TEXTS; break;
1139
1140 case PCB_ZONE_T:
1141 // Treat teardrop areas as tracks for DRC purposes
1142 if( static_cast<const ZONE*>( a )->IsTeardropArea() )
1143 mask = DRC_DISALLOW_TRACKS;
1144 else
1145 mask = DRC_DISALLOW_ZONES;
1146
1147 break;
1148
1149 case PCB_LOCATE_HOLE_T: mask = DRC_DISALLOW_HOLES; break;
1150 default: mask = 0; break;
1151 }
1152 }
1153
1154 if( ( c->constraint.m_DisallowFlags & mask ) == 0 )
1155 {
1156 if( implicit )
1157 REPORT( _( "Keepout constraint not met." ) )
1158 else
1159 REPORT( _( "Disallow constraint not met." ) )
1160
1161 return;
1162 }
1163
1164 LSET itemLayers = a->GetLayerSet();
1165
1166 if( a->Type() == PCB_FOOTPRINT_T )
1167 {
1168 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( a );
1169
1170 if( !footprint->GetCourtyard( F_CrtYd ).IsEmpty() )
1171 itemLayers |= LSET::FrontMask();
1172
1173 if( !footprint->GetCourtyard( B_CrtYd ).IsEmpty() )
1174 itemLayers |= LSET::BackMask();
1175 }
1176
1177 if( !( c->layerTest & itemLayers ).any() )
1178 {
1179 if( implicit )
1180 {
1181 REPORT( _( "Keepout layer(s) not matched." ) )
1182 }
1183 else if( c->parentRule )
1184 {
1185 REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule ignored." ),
1186 EscapeHTML( c->parentRule->m_LayerSource ) ) )
1187 }
1188 else
1189 {
1190 REPORT( _( "Rule layer not matched; rule ignored." ) )
1191 }
1192
1193 return;
1194 }
1195 }
1196
1197 if( ( aLayer != UNDEFINED_LAYER && !c->layerTest.test( aLayer ) )
1198 || ( m_board->GetEnabledLayers() & c->layerTest ).count() == 0 )
1199 {
1200 if( implicit )
1201 {
1202 REPORT( _( "Constraint layer not matched." ) )
1203 }
1204 else if( c->parentRule )
1205 {
1206 REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule ignored." ),
1207 EscapeHTML( c->parentRule->m_LayerSource ) ) )
1208 }
1209 else
1210 {
1211 REPORT( _( "Rule layer not matched; rule ignored." ) )
1212 }
1213 }
1214 else if( c->constraint.m_Type == HOLE_TO_HOLE_CONSTRAINT
1215 && ( !hasDrilledHole( a ) || !hasDrilledHole( b ) ) )
1216 {
1217 // Report non-drilled-holes as an implicit condition
1218 if( aReporter )
1219 {
1220 const BOARD_ITEM* x = !hasDrilledHole( a ) ? a : b;
1221
1222 REPORT( wxString::Format( _( "%s is not a drilled hole; rule ignored." ),
1223 x->GetItemDescription( this ) ) )
1224 }
1225 }
1226 else if( !c->condition || c->condition->GetExpression().IsEmpty() )
1227 {
1228 if( aReporter )
1229 {
1230 if( implicit )
1231 {
1232 REPORT( _( "Unconditional constraint applied." ) )
1233 }
1234 else if( constraint.m_Type == ASSERTION_CONSTRAINT )
1235 {
1236 REPORT( _( "Unconditional rule applied." ) )
1237 testAssertion( c );
1238 }
1239 else
1240 {
1241 REPORT( _( "Unconditional rule applied; overrides previous constraints." ) )
1242 }
1243 }
1244
1245 applyConstraint( c );
1246 }
1247 else
1248 {
1249 if( implicit )
1250 {
1251 // Don't report on implicit rule conditions; they're synthetic.
1252 }
1253 else
1254 {
1255 REPORT( wxString::Format( _( "Checking rule condition \"%s\"." ),
1256 EscapeHTML( c->condition->GetExpression() ) ) )
1257 }
1258
1259 if( c->condition->EvaluateFor( a, b, c->constraint.m_Type, aLayer, aReporter ) )
1260 {
1261 if( aReporter )
1262 {
1263 if( implicit )
1264 {
1265 REPORT( _( "Constraint applied." ) )
1266 }
1267 else if( constraint.m_Type == ASSERTION_CONSTRAINT )
1268 {
1269 REPORT( _( "Rule applied." ) )
1270 testAssertion( c );
1271 }
1272 else
1273 {
1274 REPORT( _( "Rule applied; overrides previous constraints." ) )
1275 }
1276 }
1277
1278 applyConstraint( c );
1279 }
1280 else
1281 {
1282 REPORT( implicit ? _( "Membership not satisfied; constraint ignored." )
1283 : _( "Condition not satisfied; rule ignored." ) )
1284 }
1285 }
1286 };
1287
1288 if( m_constraintMap.count( aConstraintType ) )
1289 {
1290 std::vector<DRC_ENGINE_CONSTRAINT*>* ruleset = m_constraintMap[ aConstraintType ];
1291
1292 for( int ii = 0; ii < (int) ruleset->size(); ++ii )
1293 processConstraint( ruleset->at( ii ) );
1294 }
1295
1296 if( constraint.GetParentRule() && !constraint.GetParentRule()->m_Implicit )
1297 return constraint;
1298
1299 // Special case for pad zone connections which can iherit from their parent footprints.
1300 // We've already checked for local overrides, and there were no rules targetting the pad
1301 // itself, so we know we're inheriting and need to see if there are any rules targetting
1302 // the parent footprint.
1303 if( pad && parentFootprint && ( aConstraintType == ZONE_CONNECTION_CONSTRAINT
1304 || aConstraintType == THERMAL_RELIEF_GAP_CONSTRAINT
1305 || aConstraintType == THERMAL_SPOKE_WIDTH_CONSTRAINT ) )
1306 {
1307 if( a == pad )
1308 a = parentFootprint;
1309 else
1310 b = parentFootprint;
1311
1312 if( m_constraintMap.count( aConstraintType ) )
1313 {
1314 std::vector<DRC_ENGINE_CONSTRAINT*>* ruleset = m_constraintMap[ aConstraintType ];
1315
1316 for( int ii = 0; ii < (int) ruleset->size(); ++ii )
1317 processConstraint( ruleset->at( ii ) );
1318
1319 if( constraint.GetParentRule() && !constraint.GetParentRule()->m_Implicit )
1320 return constraint;
1321 }
1322 }
1323
1324 // Unfortunately implicit rules don't work for local clearances (such as zones) because
1325 // they have to be max'ed with netclass values (which are already implicit rules), and our
1326 // rule selection paradigm is "winner takes all".
1327 if( aConstraintType == CLEARANCE_CONSTRAINT )
1328 {
1329 int global = constraint.m_Value.Min();
1330 int clearance = global;
1331 bool needBlankLine = true;
1332
1333 if( ac && ac->GetLocalClearance().has_value() )
1334 {
1335 int localA = ac->GetLocalClearance().value();
1336
1337 if( needBlankLine )
1338 {
1339 REPORT( "" )
1340 needBlankLine = false;
1341 }
1342
1343 REPORT( wxString::Format( _( "Local clearance on %s: %s." ),
1344 EscapeHTML( a->GetItemDescription( this ) ),
1345 MessageTextFromValue( localA ) ) )
1346
1347 if( localA > clearance )
1348 {
1349 wxString msg;
1350 clearance = ac->GetLocalClearance( &msg ).value();
1351 constraint.SetParentRule( nullptr );
1352 constraint.SetName( msg );
1353 constraint.m_Value.SetMin( clearance );
1354 }
1355 }
1356
1357 if( bc && bc->GetLocalClearance().has_value() )
1358 {
1359 int localB = bc->GetLocalClearance().value();
1360
1361 if( needBlankLine )
1362 {
1363 REPORT( "" )
1364 needBlankLine = false;
1365 }
1366
1367 REPORT( wxString::Format( _( "Local clearance on %s: %s." ),
1368 EscapeHTML( b->GetItemDescription( this ) ),
1369 MessageTextFromValue( localB ) ) )
1370
1371 if( localB > clearance )
1372 {
1373 wxString msg;
1374 clearance = bc->GetLocalClearance( &msg ).value();
1375 constraint.SetParentRule( nullptr );
1376 constraint.SetName( msg );
1377 constraint.m_Value.SetMin( clearance );
1378 }
1379 }
1380
1381 if( !a_is_non_copper && !b_is_non_copper )
1382 {
1383 if( needBlankLine )
1384 {
1385 REPORT( "" )
1386 needBlankLine = false;
1387 }
1388
1389 REPORT( wxString::Format( _( "Board minimum clearance: %s." ),
1391
1392 if( clearance < m_designSettings->m_MinClearance )
1393 {
1394 constraint.SetParentRule( nullptr );
1395 constraint.SetName( _( "board minimum" ) );
1397 }
1398 }
1399
1400 return constraint;
1401 }
1402 else if( aConstraintType == DIFF_PAIR_GAP_CONSTRAINT )
1403 {
1404 REPORT( "" )
1405 REPORT( wxString::Format( _( "Board minimum clearance: %s." ),
1407
1408 if( constraint.m_Value.Min() < m_designSettings->m_MinClearance )
1409 {
1410 constraint.SetParentRule( nullptr );
1411 constraint.SetName( _( "board minimum" ) );
1413 }
1414
1415 return constraint;
1416 }
1417 else if( aConstraintType == ZONE_CONNECTION_CONSTRAINT )
1418 {
1419 if( pad && parentFootprint )
1420 {
1421 ZONE_CONNECTION local = parentFootprint->GetLocalZoneConnection();
1422
1423 if( local != ZONE_CONNECTION::INHERITED )
1424 {
1425 REPORT( "" )
1426 REPORT( wxString::Format( _( "%s zone connection: %s." ),
1427 EscapeHTML( parentFootprint->GetItemDescription( this ) ),
1428 EscapeHTML( PrintZoneConnection( local ) ) ) )
1429
1430 constraint.SetParentRule( nullptr );
1431 constraint.SetName( _( "footprint" ) );
1432 constraint.m_ZoneConnection = local;
1433 return constraint;
1434 }
1435 }
1436
1437 if( zone )
1438 {
1439 ZONE_CONNECTION local = zone->GetPadConnection();
1440
1441 REPORT( "" )
1442 REPORT( wxString::Format( _( "%s pad connection: %s." ),
1443 EscapeHTML( zone->GetItemDescription( this ) ),
1444 EscapeHTML( PrintZoneConnection( local ) ) ) )
1445
1446 constraint.SetParentRule( nullptr );
1447 constraint.SetName( _( "zone" ) );
1448 constraint.m_ZoneConnection = local;
1449 return constraint;
1450 }
1451 }
1452 else if( aConstraintType == THERMAL_RELIEF_GAP_CONSTRAINT )
1453 {
1454 if( zone )
1455 {
1456 int local = zone->GetThermalReliefGap();
1457
1458 REPORT( "" )
1459 REPORT( wxString::Format( _( "%s thermal relief gap: %s." ),
1460 EscapeHTML( zone->GetItemDescription( this ) ),
1461 EscapeHTML( MessageTextFromValue( local ) ) ) )
1462
1463 constraint.SetParentRule( nullptr );
1464 constraint.SetName( _( "zone" ) );
1465 constraint.m_Value.SetMin( local );
1466 return constraint;
1467 }
1468 }
1469 else if( aConstraintType == THERMAL_SPOKE_WIDTH_CONSTRAINT )
1470 {
1471 if( zone )
1472 {
1473 int local = zone->GetThermalReliefSpokeWidth();
1474
1475 REPORT( "" )
1476 REPORT( wxString::Format( _( "%s thermal spoke width: %s." ),
1477 EscapeHTML( zone->GetItemDescription( this ) ),
1478 EscapeHTML( MessageTextFromValue( local ) ) ) )
1479
1480 constraint.SetParentRule( nullptr );
1481 constraint.SetName( _( "zone" ) );
1482 constraint.m_Value.SetMin( local );
1483 return constraint;
1484 }
1485 }
1486
1487 if( !constraint.GetParentRule() )
1488 {
1489 constraint.m_Type = NULL_CONSTRAINT;
1490 constraint.m_DisallowFlags = 0;
1491 }
1492
1493 return constraint;
1494}
1495
1496
1498 std::function<void( const DRC_CONSTRAINT* )> aFailureHandler,
1499 REPORTER* aReporter )
1500{
1501 /*
1502 * NOTE: all string manipulation MUST BE KEPT INSIDE the REPORT macro. It absolutely
1503 * kills performance when running bulk DRC tests (where aReporter is nullptr).
1504 */
1505
1506 auto testAssertion =
1507 [&]( const DRC_ENGINE_CONSTRAINT* c )
1508 {
1509 REPORT( wxString::Format( _( "Checking rule assertion \"%s\"." ),
1510 EscapeHTML( c->constraint.m_Test->GetExpression() ) ) )
1511
1512 if( c->constraint.m_Test->EvaluateFor( a, nullptr, c->constraint.m_Type,
1513 a->GetLayer(), aReporter ) )
1514 {
1515 REPORT( _( "Assertion passed." ) )
1516 }
1517 else
1518 {
1519 REPORT( EscapeHTML( _( "--> Assertion failed. <--" ) ) )
1520 aFailureHandler( &c->constraint );
1521 }
1522 };
1523
1524 auto processConstraint =
1525 [&]( const DRC_ENGINE_CONSTRAINT* c )
1526 {
1527 REPORT( "" )
1528 REPORT( wxString::Format( _( "Checking %s." ), c->constraint.GetName() ) )
1529
1530 if( !( a->GetLayerSet() & c->layerTest ).any() )
1531 {
1532 REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule ignored." ),
1533 EscapeHTML( c->parentRule->m_LayerSource ) ) )
1534 }
1535
1536 if( !c->condition || c->condition->GetExpression().IsEmpty() )
1537 {
1538 REPORT( _( "Unconditional rule applied." ) )
1539 testAssertion( c );
1540 }
1541 else
1542 {
1543 REPORT( wxString::Format( _( "Checking rule condition \"%s\"." ),
1544 EscapeHTML( c->condition->GetExpression() ) ) )
1545
1546 if( c->condition->EvaluateFor( a, nullptr, c->constraint.m_Type,
1547 a->GetLayer(), aReporter ) )
1548 {
1549 REPORT( _( "Rule applied." ) )
1550 testAssertion( c );
1551 }
1552 else
1553 {
1554 REPORT( _( "Condition not satisfied; rule ignored." ) )
1555 }
1556 }
1557 };
1558
1560 {
1561 std::vector<DRC_ENGINE_CONSTRAINT*>* ruleset = m_constraintMap[ ASSERTION_CONSTRAINT ];
1562
1563 for( int ii = 0; ii < (int) ruleset->size(); ++ii )
1564 processConstraint( ruleset->at( ii ) );
1565 }
1566}
1567
1568
1569#undef REPORT
1570
1571
1573{
1574 assert( error_code >= 0 && error_code <= DRCE_LAST );
1575 return m_errorLimits[ error_code ] <= 0;
1576}
1577
1578
1579void DRC_ENGINE::ReportViolation( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos,
1580 int aMarkerLayer )
1581{
1582 static std::mutex globalLock;
1583
1584 m_errorLimits[ aItem->GetErrorCode() ] -= 1;
1585
1586 if( m_violationHandler )
1587 {
1588 std::lock_guard<std::mutex> guard( globalLock );
1589 m_violationHandler( aItem, aPos, aMarkerLayer );
1590 }
1591
1592 if( m_reporter )
1593 {
1594 wxString msg = wxString::Format( wxT( "Test '%s': %s (code %d)" ),
1595 aItem->GetViolatingTest()->GetName(),
1596 aItem->GetErrorMessage(),
1597 aItem->GetErrorCode() );
1598
1599 DRC_RULE* rule = aItem->GetViolatingRule();
1600
1601 if( rule )
1602 msg += wxString::Format( wxT( ", violating rule: '%s'" ), rule->m_Name );
1603
1604 m_reporter->Report( msg );
1605
1606 wxString violatingItemsStr = wxT( "Violating items: " );
1607
1608 m_reporter->Report( wxString::Format( wxT( " |- violating position (%d, %d)" ),
1609 aPos.x,
1610 aPos.y ) );
1611 }
1612}
1613
1614
1615void DRC_ENGINE::ReportAux ( const wxString& aStr )
1616{
1617 if( !m_reporter )
1618 return;
1619
1621}
1622
1623
1625{
1626 if( !m_progressReporter )
1627 return true;
1628
1629 return m_progressReporter->KeepRefreshing( aWait );
1630}
1631
1632
1634{
1635 if( m_progressReporter )
1637}
1638
1639
1641{
1642 if( m_progressReporter )
1644}
1645
1646
1647bool DRC_ENGINE::ReportProgress( double aProgress )
1648{
1649 if( !m_progressReporter )
1650 return true;
1651
1653 return m_progressReporter->KeepRefreshing( false );
1654}
1655
1656
1657bool DRC_ENGINE::ReportPhase( const wxString& aMessage )
1658{
1659 if( !m_progressReporter )
1660 return true;
1661
1662 m_progressReporter->AdvancePhase( aMessage );
1663 return m_progressReporter->KeepRefreshing( false );
1664}
1665
1666
1668{
1670}
1671
1672
1674{
1675 //drc_dbg(10,"hascorrect id %d size %d\n", ruleID, m_ruleMap[ruleID]->sortedRules.size( ) );
1676 if( m_constraintMap.count( constraintID ) )
1677 return m_constraintMap[ constraintID ]->size() > 0;
1678
1679 return false;
1680}
1681
1682
1684{
1685 int worst = 0;
1686
1687 if( m_constraintMap.count( aConstraintId ) )
1688 {
1689 for( DRC_ENGINE_CONSTRAINT* c : *m_constraintMap[aConstraintId] )
1690 {
1691 int current = c->constraint.GetValue().Min();
1692
1693 if( current > worst )
1694 {
1695 worst = current;
1696 aConstraint = c->constraint;
1697 }
1698 }
1699 }
1700
1701 return worst > 0;
1702}
1703
1704
1706{
1707 std::set<int> distinctMinimums;
1708
1709 if( m_constraintMap.count( aConstraintId ) )
1710 {
1711 for( DRC_ENGINE_CONSTRAINT* c : *m_constraintMap[aConstraintId] )
1712 distinctMinimums.emplace( c->constraint.GetValue().Min() );
1713 }
1714
1715 return distinctMinimums;
1716}
1717
1718
1719// fixme: move two functions below to pcbcommon?
1720int DRC_ENGINE::MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
1721 wxString& aBaseDpName )
1722{
1723 int rv = 0;
1724 int count = 0;
1725
1726 for( auto it = aNetName.rbegin(); it != aNetName.rend() && rv == 0; ++it, ++count )
1727 {
1728 int ch = *it;
1729
1730 if( ( ch >= '0' && ch <= '9' ) || ch == '_' )
1731 {
1732 continue;
1733 }
1734 else if( ch == '+' )
1735 {
1736 aComplementNet = wxT( "-" );
1737 rv = 1;
1738 }
1739 else if( ch == '-' )
1740 {
1741 aComplementNet = wxT( "+" );
1742 rv = -1;
1743 }
1744 else if( ch == 'N' )
1745 {
1746 aComplementNet = wxT( "P" );
1747 rv = -1;
1748 }
1749 else if ( ch == 'P' )
1750 {
1751 aComplementNet = wxT( "N" );
1752 rv = 1;
1753 }
1754 else
1755 {
1756 break;
1757 }
1758 }
1759
1760 if( rv != 0 && count >= 1 )
1761 {
1762 aBaseDpName = aNetName.Left( aNetName.Length() - count );
1763 aComplementNet = wxString( aBaseDpName ) << aComplementNet << aNetName.Right( count - 1 );
1764 }
1765
1766 return rv;
1767}
1768
1769
1770bool DRC_ENGINE::IsNetADiffPair( BOARD* aBoard, NETINFO_ITEM* aNet, int& aNetP, int& aNetN )
1771{
1772 wxString refName = aNet->GetNetname();
1773 wxString dummy, coupledNetName;
1774
1775 if( int polarity = MatchDpSuffix( refName, coupledNetName, dummy ) )
1776 {
1777 NETINFO_ITEM* net = aBoard->FindNet( coupledNetName );
1778
1779 if( !net )
1780 return false;
1781
1782 if( polarity > 0 )
1783 {
1784 aNetP = aNet->GetNetCode();
1785 aNetN = net->GetNetCode();
1786 }
1787 else
1788 {
1789 aNetP = net->GetNetCode();
1790 aNetN = aNet->GetNetCode();
1791 }
1792
1793 return true;
1794 }
1795
1796 return false;
1797}
1798
1799
1804bool DRC_ENGINE::IsNetTieExclusion( int aTrackNetCode, PCB_LAYER_ID aTrackLayer,
1805 const VECTOR2I& aCollisionPos, BOARD_ITEM* aCollidingItem )
1806{
1807 FOOTPRINT* parentFootprint = aCollidingItem->GetParentFootprint();
1808
1809 if( parentFootprint && parentFootprint->IsNetTie() )
1810 {
1812 std::map<wxString, int> padToNetTieGroupMap = parentFootprint->MapPadNumbersToNetTieGroups();
1813
1814 for( PAD* pad : parentFootprint->Pads() )
1815 {
1816 if( padToNetTieGroupMap[ pad->GetNumber() ] >= 0 && aTrackNetCode == pad->GetNetCode() )
1817 {
1818 if( pad->GetEffectiveShape( aTrackLayer )->Collide( aCollisionPos, epsilon ) )
1819 return true;
1820 }
1821 }
1822 }
1823
1824 return false;
1825}
1826
1827
1829{
1830 for( DRC_TEST_PROVIDER* prov : m_testProviders )
1831 {
1832 if( name == prov->GetName() )
1833 return prov;
1834 }
1835
1836 return nullptr;
1837}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:111
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual std::optional< int > GetClearanceOverrides(wxString *aSource) const
Return any clearance overrides set in the "classic" (ie: pre-rule) system.
virtual std::optional< int > GetLocalClearance() const
Return any local clearances set in the "classic" (ie: pre-rule) system.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
bool Ignore(int aDRCErrorCode)
Return true if the DRC error code's severity is SEVERITY_IGNORE.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:248
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:231
virtual bool IsOnCopperLayer() const
Definition: board_item.h:151
virtual bool HasHole() const
Definition: board_item.h:156
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:677
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1803
const ZONES & Zones() const
Definition: board.h:327
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1936
void IncrementTimeStamp()
Definition: board.cpp:245
const FOOTPRINTS & Footprints() const
Definition: board.h:323
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
int GetTimeStamp() const
Definition: board.h:305
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
int m_DisallowFlags
Definition: drc_rule.h:173
void SetParentRule(DRC_RULE *aParentRule)
Definition: drc_rule.h:144
MINOPTMAX< int > & Value()
Definition: drc_rule.h:142
ZONE_CONNECTION m_ZoneConnection
Definition: drc_rule.h:174
void SetName(const wxString &aName)
Definition: drc_rule.h:147
MINOPTMAX< int > m_Value
Definition: drc_rule.h:172
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:171
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:145
std::map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:245
REPORTER * m_reporter
Definition: drc_engine.h:248
void AdvanceProgress()
bool m_testFootprints
Definition: drc_engine.h:242
void addRule(std::shared_ptr< DRC_RULE > &rule)
Definition: drc_engine.h:205
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:249
void loadRules(const wxFileName &aPath)
Load and parse a rule set from an sexpr text file.
Definition: drc_engine.cpp:466
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:238
void compileRules()
Definition: drc_engine.cpp:489
std::set< int > QueryDistinctConstraints(DRC_CONSTRAINT_T aConstraintId)
bool KeepRefreshing(bool aWait=false)
BOARD * m_board
Definition: drc_engine.h:232
bool m_reportAllTrackErrors
Definition: drc_engine.h:241
bool ReportProgress(double aProgress)
DRC_TEST_PROVIDER * GetTestProvider(const wxString &name) const
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
BOARD_DESIGN_SETTINGS * GetDesignSettings() const
Definition: drc_engine.h:92
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints)
Run the DRC tests.
Definition: drc_engine.cpp:573
void ReportViolation(const std::shared_ptr< DRC_ITEM > &aItem, const VECTOR2I &aPos, int aMarkerLayer)
void SetMaxProgress(int aSize)
void ReportAux(const wxString &aStr)
DRC_ENGINE(BOARD *aBoard=nullptr, BOARD_DESIGN_SETTINGS *aSettings=nullptr)
Definition: drc_engine.cpp:66
std::vector< int > m_errorLimits
Definition: drc_engine.h:240
bool IsErrorLimitExceeded(int error_code)
void ProcessAssertions(const BOARD_ITEM *a, std::function< void(const DRC_CONSTRAINT *)> aFailureHandler, REPORTER *aReporter=nullptr)
void loadImplicitRules()
Definition: drc_engine.cpp:138
DRC_VIOLATION_HANDLER m_violationHandler
Definition: drc_engine.h:247
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:675
std::vector< std::shared_ptr< DRC_RULE > > m_rules
Definition: drc_engine.h:236
std::shared_ptr< DRC_RULE > createImplicitRule(const wxString &name)
Definition: drc_engine.cpp:125
bool IsCancelled() const
static bool IsNetADiffPair(BOARD *aBoard, NETINFO_ITEM *aNet, int &aNetP, int &aNetN)
bool IsNetTieExclusion(int aTrackNetCode, PCB_LAYER_ID aTrackLayer, const VECTOR2I &aCollisionPos, BOARD_ITEM *aCollidingItem)
Check if the given collision between a track and another item occurs during the track's entry into a ...
virtual ~DRC_ENGINE()
Definition: drc_engine.cpp:85
bool QueryWorstConstraint(DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
Definition: drc_engine.cpp:520
DRC_CONSTRAINT EvalZoneConnection(const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:618
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Check if the given net is a diff pair, returning its polarity and complement if so.
bool ReportPhase(const wxString &aMessage)
bool m_rulesValid
Definition: drc_engine.h:237
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:231
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
bool Compile(REPORTER *aReporter, int aSourceLine=0, int aSourceOffset=0)
bool m_Implicit
Definition: drc_rule.h:110
wxString m_Name
Definition: drc_rule.h:112
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
static DRC_TEST_PROVIDER_REGISTRY & Instance()
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
void SetDRCEngine(DRC_ENGINE *engine)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:108
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:129
ZONE_CONNECTION GetLocalZoneConnection() const
Definition: footprint.h:273
std::map< wxString, int > MapPadNumbersToNetTieGroups() const
Definition: footprint.cpp:2929
PADS & Pads()
Definition: footprint.h:191
bool IsNetTie() const
Definition: footprint.h:282
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2812
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: footprint.cpp:1987
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:985
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:992
T Min() const
Definition: minoptmax.h:33
void SetMin(T v)
Definition: minoptmax.h:41
void SetOpt(T v)
Definition: minoptmax.h:43
Handle the data for a net.
Definition: netinfo.h:56
const wxString & GetNetname() const
Definition: netinfo.h:114
int GetNetCode() const
Definition: netinfo.h:108
Definition: pad.h:53
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void SetUserUnits(EDA_UNITS aUnits)
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: zone.cpp:821
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:710
bool GetDoNotAllowVias() const
Definition: zone.h:712
bool GetDoNotAllowPads() const
Definition: zone.h:714
bool GetDoNotAllowTracks() const
Definition: zone.h:713
int GetMinThickness() const
Definition: zone.h:269
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:266
int GetThermalReliefSpokeWidth() const
Definition: zone.h:213
bool GetDoNotAllowFootprints() const
Definition: zone.h:715
bool GetDoNotAllowCopperPour() const
Definition: zone.h:711
int GetThermalReliefGap() const
Definition: zone.h:202
void drcPrintDebugMessage(int level, const wxString &msg, const char *function, int line)
Definition: drc_engine.cpp:52
#define EXTENDED_ERROR_LIMIT
Definition: drc_engine.cpp:49
static bool isKeepoutZone(const BOARD_ITEM *aItem, bool aCheckFlags)
Definition: drc_engine.cpp:99
bool hasDrilledHole(const BOARD_ITEM *aItem)
Definition: drc_engine.cpp:652
#define ERROR_LIMIT
Definition: drc_engine.cpp:48
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_CLEARANCE
Definition: drc_item.h:43
@ DRCE_FIRST
Definition: drc_item.h:38
@ DRCE_LAST
Definition: drc_item.h:102
@ DRC_DISALLOW_PADS
Definition: drc_rule.h:83
@ DRC_DISALLOW_VIAS
Definition: drc_rule.h:79
@ DRC_DISALLOW_TEXTS
Definition: drc_rule.h:85
@ DRC_DISALLOW_ZONES
Definition: drc_rule.h:84
@ DRC_DISALLOW_HOLES
Definition: drc_rule.h:87
@ DRC_DISALLOW_GRAPHICS
Definition: drc_rule.h:86
@ DRC_DISALLOW_FOOTPRINTS
Definition: drc_rule.h:88
@ DRC_DISALLOW_TRACKS
Definition: drc_rule.h:82
@ DRC_DISALLOW_MICRO_VIAS
Definition: drc_rule.h:80
@ DRC_DISALLOW_BB_VIAS
Definition: drc_rule.h:81
DRC_CONSTRAINT_T
Definition: drc_rule.h:45
@ ANNULAR_WIDTH_CONSTRAINT
Definition: drc_rule.h:57
@ COURTYARD_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:52
@ VIA_DIAMETER_CONSTRAINT
Definition: drc_rule.h:63
@ ZONE_CONNECTION_CONSTRAINT
Definition: drc_rule.h:58
@ DIFF_PAIR_GAP_CONSTRAINT
Definition: drc_rule.h:66
@ DISALLOW_CONSTRAINT
Definition: drc_rule.h:62
@ TRACK_WIDTH_CONSTRAINT
Definition: drc_rule.h:56
@ SILK_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:53
@ EDGE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:50
@ MIN_RESOLVED_SPOKES_CONSTRAINT
Definition: drc_rule.h:61
@ TEXT_THICKNESS_CONSTRAINT
Definition: drc_rule.h:55
@ LENGTH_CONSTRAINT
Definition: drc_rule.h:64
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:71
@ CLEARANCE_CONSTRAINT
Definition: drc_rule.h:47
@ NULL_CONSTRAINT
Definition: drc_rule.h:46
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
Definition: drc_rule.h:60
@ CONNECTION_WIDTH_CONSTRAINT
Definition: drc_rule.h:73
@ THERMAL_RELIEF_GAP_CONSTRAINT
Definition: drc_rule.h:59
@ MAX_UNCOUPLED_CONSTRAINT
Definition: drc_rule.h:67
@ ASSERTION_CONSTRAINT
Definition: drc_rule.h:72
@ SKEW_CONSTRAINT
Definition: drc_rule.h:65
@ HOLE_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:48
@ HOLE_SIZE_CONSTRAINT
Definition: drc_rule.h:51
@ TEXT_HEIGHT_CONSTRAINT
Definition: drc_rule.h:54
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:70
@ HOLE_TO_HOLE_CONSTRAINT
Definition: drc_rule.h:49
#define _(s)
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
EDA_UNITS
Definition: eda_units.h:46
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:117
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ B_SilkS
Definition: layer_ids.h:103
#define REPORT(msg)
Definition: lib_symbol.cpp:237
KICOMMON_API wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
Definition: eda_units.cpp:408
@ RPT_SEVERITY_INFO
const double epsilon
std::vector< FAB_LAYER_COLOR > dummy
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
std::shared_ptr< DRC_RULE > parentRule
Definition: drc_engine.h:223
DRC_RULE_CONDITION * condition
Definition: drc_engine.h:222
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
@ 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_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ 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_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
@ PCB_LOCATE_HOLE_T
Definition: typeinfo.h:127
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
wxString PrintZoneConnection(ZONE_CONNECTION aConnection)
Definition: zones.h:56
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:47