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