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