KiCad PCB EDA Suite
DRC_ENGINE Class Reference

Design Rule Checker object that performs all the DRC tests. More...

#include <drc_engine.h>

Classes

struct  DRC_ENGINE_CONSTRAINT
 

Public Member Functions

 DRC_ENGINE (BOARD *aBoard=nullptr, BOARD_DESIGN_SETTINGS *aSettings=nullptr)
 
 ~DRC_ENGINE ()
 
void SetBoard (BOARD *aBoard)
 
BOARDGetBoard () const
 
void SetDesignSettings (BOARD_DESIGN_SETTINGS *aSettings)
 
BOARD_DESIGN_SETTINGSGetDesignSettings () const
 
void SetSchematicNetlist (NETLIST *aNetlist)
 
NETLISTGetSchematicNetlist () const
 
void SetDrawingSheet (DS_PROXY_VIEW_ITEM *aDrawingSheet)
 
DS_PROXY_VIEW_ITEMGetDrawingSheet () const
 
void SetDebugOverlay (std::shared_ptr< KIGFX::VIEW_OVERLAY > aOverlay)
 
std::shared_ptr< KIGFX::VIEW_OVERLAYGetDebugOverlay () const
 
void SetViolationHandler (DRC_VIOLATION_HANDLER aHandler)
 Set an optional DRC violation handler (receives DRC_ITEMs and positions). More...
 
void ClearViolationHandler ()
 
void SetProgressReporter (PROGRESS_REPORTER *aProgRep)
 Set an optional reporter for user-level progress info. More...
 
PROGRESS_REPORTERGetProgressReporter () const
 
void SetLogReporter (REPORTER *aReporter)
 
void InitEngine (const wxFileName &aRulePath)
 Initializes the DRC engine. More...
 
void RunTests (EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints)
 Runs the DRC tests. More...
 
bool IsErrorLimitExceeded (int error_code)
 
DRC_CONSTRAINT EvalRules (DRC_CONSTRAINT_T aConstraintId, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
 
bool HasRulesForConstraintType (DRC_CONSTRAINT_T constraintID)
 
EDA_UNITS UserUnits () const
 
bool GetReportAllTrackErrors () const
 
bool GetTestFootprints () const
 
bool RulesValid ()
 
void ReportViolation (const std::shared_ptr< DRC_ITEM > &aItem, wxPoint aPos)
 
bool ReportProgress (double aProgress)
 
bool ReportPhase (const wxString &aMessage)
 
void ReportAux (const wxString &aStr)
 
bool QueryWorstConstraint (DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
 
std::vector< DRC_TEST_PROVIDER * > GetTestProviders () const
 
DRC_TEST_PROVIDERGetTestProvider (const wxString &name) const
 

Static Public Member Functions

static bool IsNetADiffPair (BOARD *aBoard, NETINFO_ITEM *aNet, int &aNetP, int &aNetN)
 
static int MatchDpSuffix (const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
 Checks if the given net is a diff pair, returning its polarity and complement if so. More...
 
static bool IsNetTie (BOARD_ITEM *aItem)
 
static std::shared_ptr< SHAPEGetShape (BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
 

Protected Attributes

BOARD_DESIGN_SETTINGSm_designSettings
 
BOARDm_board
 
DS_PROXY_VIEW_ITEMm_drawingSheet
 
NETLISTm_schematicNetlist
 
std::vector< DRC_RULE * > m_rules
 
bool m_rulesValid
 
std::vector< DRC_TEST_PROVIDER * > m_testProviders
 
EDA_UNITS m_userUnits
 
std::vector< int > m_errorLimits
 
bool m_reportAllTrackErrors
 
bool m_testFootprints
 
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
 
DRC_VIOLATION_HANDLER m_violationHandler
 
REPORTERm_reporter
 
PROGRESS_REPORTERm_progressReporter
 
wxString m_msg
 
std::shared_ptr< KIGFX::VIEW_OVERLAYm_debugOverlay
 

Private Member Functions

void addRule (DRC_RULE *rule)
 
void loadRules (const wxFileName &aPath)
 Loads and parses a rule set from an sexpr text file. More...
 
void compileRules ()
 
void loadImplicitRules ()
 
DRC_RULEcreateImplicitRule (const wxString &name)
 

Detailed Description

Design Rule Checker object that performs all the DRC tests.

Optionally reports violations via a DRC_VIOLATION_HANDLER, user-level progress via a PROGRESS_REPORTER and rule parse errors via a REPORTER, all set through various setter calls.

Note that EvalRules() has yet another optional REPORTER for reporting resolution info to the user.

Definition at line 80 of file drc_engine.h.

Constructor & Destructor Documentation

◆ DRC_ENGINE()

DRC_ENGINE::DRC_ENGINE ( BOARD aBoard = nullptr,
BOARD_DESIGN_SETTINGS aSettings = nullptr 
)

Definition at line 60 of file drc_engine.cpp.

60  :
61  m_designSettings ( aSettings ),
62  m_board( aBoard ),
63  m_drawingSheet( nullptr ),
64  m_schematicNetlist( nullptr ),
65  m_rulesValid( false ),
67  m_reportAllTrackErrors( false ),
68  m_testFootprints( false ),
69  m_reporter( nullptr ),
70  m_progressReporter( nullptr )
71 {
72  m_errorLimits.resize( DRCE_LAST + 1 );
73 
74  for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
75  m_errorLimits[ ii ] = INT_MAX;
76 }
EDA_UNITS m_userUnits
Definition: drc_engine.h:220
std::vector< int > m_errorLimits
Definition: drc_engine.h:221
NETLIST * m_schematicNetlist
Definition: drc_engine.h:214
bool m_testFootprints
Definition: drc_engine.h:223
bool m_rulesValid
Definition: drc_engine.h:217
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:211
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:230
REPORTER * m_reporter
Definition: drc_engine.h:229
BOARD * m_board
Definition: drc_engine.h:212
bool m_reportAllTrackErrors
Definition: drc_engine.h:222
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:213

References DRCE_FIRST, DRCE_LAST, and m_errorLimits.

◆ ~DRC_ENGINE()

DRC_ENGINE::~DRC_ENGINE ( )

Definition at line 79 of file drc_engine.cpp.

80 {
81  for( DRC_RULE* rule : m_rules )
82  delete rule;
83 
84  for( std::pair<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> pair : m_constraintMap )
85  {
86  for( DRC_ENGINE_CONSTRAINT* constraint : *pair.second )
87  delete constraint;
88 
89  delete pair.second;
90  }
91 }
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:216
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226

References m_constraintMap, and m_rules.

Member Function Documentation

◆ addRule()

void DRC_ENGINE::addRule ( DRC_RULE rule)
inlineprivate

Definition at line 185 of file drc_engine.h.

186  {
187  m_rules.push_back(rule);
188  }
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:216

References m_rules.

Referenced by createImplicitRule(), and loadImplicitRules().

◆ ClearViolationHandler()

void DRC_ENGINE::ClearViolationHandler ( )
inline

Definition at line 110 of file drc_engine.h.

111  {
113  }
std::function< void(const std::shared_ptr< DRC_ITEM > &aItem, wxPoint aPos)> DRC_VIOLATION_HANDLER
Definition: drc_engine.h:63
DRC_VIOLATION_HANDLER m_violationHandler
Definition: drc_engine.h:228

References m_violationHandler.

◆ compileRules()

void DRC_ENGINE::compileRules ( )
private

Definition at line 552 of file drc_engine.cpp.

553 {
554  ReportAux( wxString::Format( "Compiling Rules (%d rules): ",
555  (int) m_rules.size() ) );
556 
557  for( DRC_TEST_PROVIDER* provider : m_testProviders )
558  {
559  ReportAux( wxString::Format( "- Provider: '%s': ", provider->GetName() ) );
560  drc_dbg( 7, "do prov %s", provider->GetName() );
561 
562  for( DRC_CONSTRAINT_T id : provider->GetConstraintTypes() )
563  {
564  drc_dbg( 7, "do id %d", id );
565 
566  if( m_constraintMap.find( id ) == m_constraintMap.end() )
567  m_constraintMap[ id ] = new std::vector<DRC_ENGINE_CONSTRAINT*>();
568 
569  for( DRC_RULE* rule : m_rules )
570  {
571  DRC_RULE_CONDITION* condition = nullptr;
572  bool compileOk = false;
573  std::vector<DRC_CONSTRAINT> matchingConstraints;
574  drc_dbg( 7, "Scan provider %s, rule %s", provider->GetName(), rule->m_Name );
575 
576  if( rule->m_Condition && !rule->m_Condition->GetExpression().IsEmpty() )
577  {
578  condition = rule->m_Condition;
579  compileOk = condition->Compile( nullptr, 0, 0 ); // fixme
580  }
581 
582  for( const DRC_CONSTRAINT& constraint : rule->m_Constraints )
583  {
584  drc_dbg(7, "scan constraint id %d\n", constraint.m_Type );
585 
586  if( constraint.m_Type != id )
587  continue;
588 
589  DRC_ENGINE_CONSTRAINT* rcons = new DRC_ENGINE_CONSTRAINT;
590 
591  rcons->layerTest = rule->m_LayerCondition;
592  rcons->condition = condition;
593 
594  matchingConstraints.push_back( constraint );
595 
596  rcons->constraint = constraint;
597  rcons->parentRule = rule;
598  m_constraintMap[ id ]->push_back( rcons );
599  }
600 
601  if( !matchingConstraints.empty() )
602  {
603  ReportAux( wxString::Format( " |- Rule: '%s' ",
604  rule->m_Name ) );
605 
606  if( condition )
607  {
608  ReportAux( wxString::Format( " |- condition: '%s' compile: %s",
609  condition->GetExpression(),
610  compileOk ? "OK" : "ERROR" ) );
611  }
612 
613  for (const DRC_CONSTRAINT& constraint : matchingConstraints )
614  {
615  ReportAux( wxString::Format( " |- constraint: %s",
616  formatConstraint( constraint ) ) );
617  }
618  }
619  }
620  }
621  }
622 }
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:218
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
wxString GetExpression() const
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:216
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226
static wxString formatConstraint(const DRC_CONSTRAINT &constraint)
Definition: drc_engine.cpp:464
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
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
void ReportAux(const wxString &aStr)
bool Compile(REPORTER *aReporter, int aSourceLine=0, int aSourceOffset=0)
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:142
#define drc_dbg(level, fmt,...)
Definition: drc_engine.h:57

References DRC_RULE_CONDITION::Compile(), DRC_ENGINE::DRC_ENGINE_CONSTRAINT::condition, DRC_ENGINE::DRC_ENGINE_CONSTRAINT::constraint, drc_dbg, Format(), formatConstraint(), DRC_RULE_CONDITION::GetExpression(), DRC_ENGINE::DRC_ENGINE_CONSTRAINT::layerTest, m_constraintMap, m_rules, m_testProviders, DRC_CONSTRAINT::m_Type, DRC_ENGINE::DRC_ENGINE_CONSTRAINT::parentRule, and ReportAux().

Referenced by InitEngine().

◆ createImplicitRule()

DRC_RULE * DRC_ENGINE::createImplicitRule ( const wxString &  name)
private

Definition at line 123 of file drc_engine.cpp.

124 {
125  DRC_RULE *rule = new DRC_RULE;
126 
127  rule->m_Name = name;
128  rule->m_Implicit = true;
129 
130  addRule( rule );
131 
132  return rule;
133 }
bool m_Implicit
Definition: drc_rule.h:95
wxString m_Name
Definition: drc_rule.h:96
void addRule(DRC_RULE *rule)
Definition: drc_engine.h:185
const char * name
Definition: DXF_plotter.cpp:59

References addRule(), DRC_RULE::m_Implicit, DRC_RULE::m_Name, and name.

Referenced by loadImplicitRules().

◆ EvalRules()

DRC_CONSTRAINT DRC_ENGINE::EvalRules ( DRC_CONSTRAINT_T  aConstraintId,
const BOARD_ITEM a,
const BOARD_ITEM b,
PCB_LAYER_ID  aLayer,
REPORTER aReporter = nullptr 
)

Definition at line 768 of file drc_engine.cpp.

771 {
772 #define REPORT( s ) { if( aReporter ) { aReporter->Report( s ); } }
773 #define UNITS aReporter ? aReporter->GetUnits() : EDA_UNITS::MILLIMETRES
774  /*
775  * NOTE: all string manipulation MUST BE KEPT INSIDE the REPORT macro. It absolutely
776  * kills performance when running bulk DRC tests (where aReporter is nullptr).
777  */
778 
779  const BOARD_CONNECTED_ITEM* ac = a && a->IsConnected() ?
780  static_cast<const BOARD_CONNECTED_ITEM*>( a ) : nullptr;
781  const BOARD_CONNECTED_ITEM* bc = b && b->IsConnected() ?
782  static_cast<const BOARD_CONNECTED_ITEM*>( b ) : nullptr;
783 
784  bool a_is_non_copper = a && ( !a->IsOnCopperLayer() || isKeepoutZone( a, false ) );
785  bool b_is_non_copper = b && ( !b->IsOnCopperLayer() || isKeepoutZone( b, false ) );
786 
787  const DRC_CONSTRAINT* constraintRef = nullptr;
788  bool implicit = false;
789 
790  // Local overrides take precedence over everything *except* board min clearance
791  if( aConstraintId == CLEARANCE_CONSTRAINT )
792  {
793  int overrideA = 0;
794  int overrideB = 0;
795 
796  if( ac && !b_is_non_copper && ac->GetLocalClearanceOverrides( nullptr ) > 0 )
797  {
798  overrideA = ac->GetLocalClearanceOverrides( &m_msg );
799 
800  REPORT( "" )
801  REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
802  EscapeHTML( a->GetSelectMenuText( UNITS ) ),
803  EscapeHTML( MessageTextFromValue( UNITS, overrideA ) ) ) )
804  }
805 
806  if( bc && !a_is_non_copper && bc->GetLocalClearanceOverrides( nullptr ) > 0 )
807  {
808  overrideB = bc->GetLocalClearanceOverrides( &m_msg );
809 
810  REPORT( "" )
811  REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
812  EscapeHTML( b->GetSelectMenuText( UNITS ) ),
813  EscapeHTML( MessageTextFromValue( UNITS, overrideB ) ) ) )
814  }
815 
816  if( overrideA || overrideB )
817  {
818  int override = std::max( overrideA, overrideB );
819 
820  if( override < m_designSettings->m_MinClearance )
821  {
822  override = m_designSettings->m_MinClearance;
823 
824  REPORT( "" )
825  REPORT( wxString::Format( _( "Board minimum clearance: %s." ),
826  EscapeHTML( MessageTextFromValue( UNITS, override ) ) ) )
827  }
828 
829  DRC_CONSTRAINT constraint( aConstraintId, m_msg );
830  constraint.m_Value.SetMin( override );
831  return constraint;
832  }
833  }
834 
835  auto processConstraint =
836  [&]( const DRC_ENGINE_CONSTRAINT* c ) -> bool
837  {
838  implicit = c->parentRule && c->parentRule->m_Implicit;
839 
840  REPORT( "" )
841 
842  if( aConstraintId == CLEARANCE_CONSTRAINT )
843  {
844  int val = c->constraint.m_Value.Min();
845  REPORT( wxString::Format( _( "Checking %s; clearance: %s." ),
846  EscapeHTML( c->constraint.GetName() ),
847  EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) )
848  }
849  else if( aConstraintId == COURTYARD_CLEARANCE_CONSTRAINT )
850  {
851  int val = c->constraint.m_Value.Min();
852  REPORT( wxString::Format( _( "Checking %s; courtyard clearance: %s." ),
853  EscapeHTML( c->constraint.GetName() ),
854  EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) )
855  }
856  else if( aConstraintId == SILK_CLEARANCE_CONSTRAINT )
857  {
858  int val = c->constraint.m_Value.Min();
859  REPORT( wxString::Format( _( "Checking %s; silk clearance: %s." ),
860  EscapeHTML( c->constraint.GetName() ),
861  EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) )
862  }
863  else if( aConstraintId == HOLE_CLEARANCE_CONSTRAINT )
864  {
865  int val = c->constraint.m_Value.Min();
866  REPORT( wxString::Format( _( "Checking %s; hole clearance: %s." ),
867  EscapeHTML( c->constraint.GetName() ),
868  EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) )
869  }
870  else if( aConstraintId == EDGE_CLEARANCE_CONSTRAINT )
871  {
872  int val = c->constraint.m_Value.Min();
873  REPORT( wxString::Format( _( "Checking %s; edge clearance: %s." ),
874  EscapeHTML( c->constraint.GetName() ),
875  EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) )
876  }
877  else
878  {
879  REPORT( wxString::Format( _( "Checking %s." ), c->constraint.GetName() ) )
880  }
881 
882  if( aConstraintId == CLEARANCE_CONSTRAINT )
883  {
884  if( implicit && ( a_is_non_copper || b_is_non_copper ) )
885  {
886  REPORT( _( "Board and netclass clearances apply only between copper "
887  "items." ) );
888  return true;
889  }
890  }
891  else if( aConstraintId == DISALLOW_CONSTRAINT )
892  {
893  int mask;
894 
895  if( a->GetFlags() & HOLE_PROXY )
896  {
897  mask = DRC_DISALLOW_HOLES;
898  }
899  else if( a->Type() == PCB_VIA_T )
900  {
901  if( static_cast<const PCB_VIA*>( a )->GetViaType() == VIATYPE::BLIND_BURIED )
903  else if( static_cast<const PCB_VIA*>( a )->GetViaType() == VIATYPE::MICROVIA )
905  else
906  mask = DRC_DISALLOW_VIAS;
907  }
908  else
909  {
910  switch( a->Type() )
911  {
912  case PCB_TRACE_T: mask = DRC_DISALLOW_TRACKS; break;
913  case PCB_ARC_T: mask = DRC_DISALLOW_TRACKS; break;
914  case PCB_PAD_T: mask = DRC_DISALLOW_PADS; break;
915  case PCB_FOOTPRINT_T: mask = DRC_DISALLOW_FOOTPRINTS; break;
916  case PCB_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break;
917  case PCB_FP_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break;
918  case PCB_TEXT_T: mask = DRC_DISALLOW_TEXTS; break;
919  case PCB_FP_TEXT_T: mask = DRC_DISALLOW_TEXTS; break;
920  case PCB_ZONE_T: mask = DRC_DISALLOW_ZONES; break;
921  case PCB_FP_ZONE_T: mask = DRC_DISALLOW_ZONES; break;
922  case PCB_LOCATE_HOLE_T: mask = DRC_DISALLOW_HOLES; break;
923  default: mask = 0; break;
924  }
925  }
926 
927  if( ( c->constraint.m_DisallowFlags & mask ) == 0 )
928  {
929  if( implicit )
930  REPORT( _( "Keepout constraint not met." ) )
931  else
932  REPORT( _( "Disallow constraint not met." ) )
933 
934  return false;
935  }
936 
937  LSET itemLayers = a->GetLayerSet();
938 
939  if( a->Type() == PCB_FOOTPRINT_T )
940  {
941  const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( a );
942 
943  if( !footprint->GetPolyCourtyardFront().IsEmpty() )
944  itemLayers |= LSET::FrontMask();
945 
946  if( !footprint->GetPolyCourtyardBack().IsEmpty() )
947  itemLayers |= LSET::BackMask();
948  }
949 
950  if( !( c->layerTest & itemLayers ).any() )
951  {
952  if( implicit )
953  {
954  REPORT( _( "Keepout layer(s) not matched." ) )
955  }
956  else if( c->parentRule )
957  {
958  REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule "
959  "ignored." ),
960  EscapeHTML( c->parentRule->m_LayerSource ) ) )
961  }
962  else
963  {
964  REPORT( _( "Rule layer not matched; rule ignored." ) )
965  }
966 
967  return false;
968  }
969  }
970 
971  if( aLayer != UNDEFINED_LAYER && !c->layerTest.test( aLayer ) )
972  {
973  if( implicit )
974  {
975  REPORT( "Constraint layer not matched." )
976  }
977  else if( c->parentRule )
978  {
979  REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule ignored." ),
980  EscapeHTML( c->parentRule->m_LayerSource ) ) )
981  }
982  else
983  {
984  REPORT( _( "Rule layer not matched; rule ignored." ) )
985  }
986 
987  return false;
988  }
989 
990  if( !c->condition || c->condition->GetExpression().IsEmpty() )
991  {
992  REPORT( implicit ? _( "Unconditional constraint applied." )
993  : _( "Unconditional rule applied." ) );
994 
995  constraintRef = &c->constraint;
996  return true;
997  }
998  else
999  {
1000  if( implicit )
1001  {
1002  // Don't report on implicit rule conditions; they're synthetic.
1003  }
1004  else
1005  {
1006  REPORT( wxString::Format( _( "Checking rule condition '%s'." ),
1007  EscapeHTML( c->condition->GetExpression() ) ) )
1008  }
1009 
1010  if( c->condition->EvaluateFor( a, b, aLayer, aReporter ) )
1011  {
1012  REPORT( implicit ? _( "Constraint applied." )
1013  : _( "Rule applied; overrides previous constraints." ) )
1014 
1015  constraintRef = &c->constraint;
1016  return true;
1017  }
1018  else
1019  {
1020  REPORT( implicit ? _( "Membership not satisfied; constraint ignored." )
1021  : _( "Condition not satisfied; rule ignored." ) )
1022 
1023  return false;
1024  }
1025  }
1026  };
1027 
1028  if( m_constraintMap.count( aConstraintId ) )
1029  {
1030  std::vector<DRC_ENGINE_CONSTRAINT*>* ruleset = m_constraintMap[ aConstraintId ];
1031 
1032  if( aReporter )
1033  {
1034  // We want to see all results so process in "natural" order
1035  for( int ii = 0; ii < (int) ruleset->size(); ++ii )
1036  {
1037  processConstraint( ruleset->at( ii ) );
1038  }
1039  }
1040  else
1041  {
1042  // Last matching rule wins, so process in reverse order and quit when match found
1043  for( int ii = (int) ruleset->size() - 1; ii >= 0; --ii )
1044  {
1045  if( processConstraint( ruleset->at( ii ) ) )
1046  break;
1047  }
1048  }
1049  }
1050 
1051  bool explicitConstraintFound = constraintRef && !implicit;
1052 
1053  // Unfortunately implicit rules don't work for local clearances (such as zones) because
1054  // they have to be max'ed with netclass values (which are already implicit rules), and our
1055  // rule selection paradigm is "winner takes all".
1056  if( aConstraintId == CLEARANCE_CONSTRAINT && !explicitConstraintFound )
1057  {
1058  int global = constraintRef ? constraintRef->m_Value.Min() : 0;
1059  int localA = ac ? ac->GetLocalClearance( nullptr ) : 0;
1060  int localB = bc ? bc->GetLocalClearance( nullptr ) : 0;
1061  int clearance = global;
1062 
1063  if( localA > 0 )
1064  {
1065  REPORT( "" )
1066  REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ),
1067  EscapeHTML( a->GetSelectMenuText( UNITS ) ),
1068  EscapeHTML( MessageTextFromValue( UNITS, localA ) ) ) )
1069 
1070  if( localA > clearance )
1071  clearance = ac->GetLocalClearance( &m_msg );
1072  }
1073 
1074  if( localB > 0 )
1075  {
1076  REPORT( "" )
1077  REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ),
1078  EscapeHTML( b->GetSelectMenuText( UNITS ) ),
1079  EscapeHTML( MessageTextFromValue( UNITS, localB ) ) ) )
1080 
1081  if( localB > clearance )
1082  clearance = bc->GetLocalClearance( &m_msg );
1083  }
1084 
1085  if( localA > global || localB > global )
1086  {
1087  DRC_CONSTRAINT constraint( CLEARANCE_CONSTRAINT, m_msg );
1088  constraint.m_Value.SetMin( clearance );
1089  return constraint;
1090  }
1091  }
1092 
1093  static DRC_CONSTRAINT nullConstraint( NULL_CONSTRAINT );
1094  nullConstraint.m_DisallowFlags = 0;
1095 
1096  return constraintRef ? *constraintRef : nullConstraint;
1097 
1098 #undef REPORT
1099 #undef UNITS
1100 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
#define UNITS
const SHAPE_POLY_SET & GetPolyCourtyardFront() const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.h:646
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
bool IsEmpty() const
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
virtual int GetLocalClearanceOverrides(wxString *aSource) const
Return any local clearance overrides set in the "classic" (ie: pre-rule) system.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:874
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:211
LSET is a set of PCB_LAYER_IDs.
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226
const SHAPE_POLY_SET & GetPolyCourtyardBack() const
Definition: footprint.h:647
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
static bool isKeepoutZone(const BOARD_ITEM *aItem, bool aCheckFlags)
Definition: drc_engine.cpp:94
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:155
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
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
class ZONE, managed by a footprint
Definition: typeinfo.h:94
wxString m_msg
Definition: drc_engine.h:232
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:881
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:442
virtual int GetLocalClearance(wxString *aSource) const
Return any local clearances set in the "classic" (ie: pre-rule) system.
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
virtual bool IsOnCopperLayer() const
Definition: board_item.h:142
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LSET::BackMask(), BLIND_BURIED, CLEARANCE_CONSTRAINT, COURTYARD_CLEARANCE_CONSTRAINT, DISALLOW_CONSTRAINT, DRC_DISALLOW_BB_VIAS, DRC_DISALLOW_FOOTPRINTS, DRC_DISALLOW_GRAPHICS, DRC_DISALLOW_HOLES, DRC_DISALLOW_MICRO_VIAS, DRC_DISALLOW_PADS, DRC_DISALLOW_TEXTS, DRC_DISALLOW_TRACKS, DRC_DISALLOW_VIAS, DRC_DISALLOW_ZONES, EDGE_CLEARANCE_CONSTRAINT, EscapeHTML(), Format(), LSET::FrontMask(), EDA_ITEM::GetFlags(), BOARD_ITEM::GetLayerSet(), BOARD_CONNECTED_ITEM::GetLocalClearance(), BOARD_CONNECTED_ITEM::GetLocalClearanceOverrides(), FOOTPRINT::GetPolyCourtyardBack(), FOOTPRINT::GetPolyCourtyardFront(), EDA_ITEM::GetSelectMenuText(), HOLE_CLEARANCE_CONSTRAINT, HOLE_PROXY, BOARD_ITEM::IsConnected(), SHAPE_POLY_SET::IsEmpty(), isKeepoutZone(), BOARD_ITEM::IsOnCopperLayer(), m_constraintMap, m_designSettings, DRC_CONSTRAINT::m_DisallowFlags, BOARD_DESIGN_SETTINGS::m_MinClearance, m_msg, DRC_CONSTRAINT::m_Value, MessageTextFromValue(), MICROVIA, NULL_CONSTRAINT, PCB_ARC_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_LOCATE_HOLE_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, REPORT, MINOPTMAX< T >::SetMin(), SILK_CLEARANCE_CONSTRAINT, EDA_ITEM::Type(), UNDEFINED_LAYER, and UNITS.

Referenced by DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones().

◆ GetBoard()

◆ GetDebugOverlay()

std::shared_ptr<KIGFX::VIEW_OVERLAY> DRC_ENGINE::GetDebugOverlay ( ) const
inline

Definition at line 99 of file drc_engine.h.

99 { return m_debugOverlay; }
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Definition: drc_engine.h:233

References m_debugOverlay.

Referenced by test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run().

◆ GetDesignSettings()

BOARD_DESIGN_SETTINGS* DRC_ENGINE::GetDesignSettings ( ) const
inline

Definition at line 90 of file drc_engine.h.

90 { return m_designSettings; }
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:211

References m_designSettings.

◆ GetDrawingSheet()

DS_PROXY_VIEW_ITEM* DRC_ENGINE::GetDrawingSheet ( ) const
inline

Definition at line 96 of file drc_engine.h.

96 { return m_drawingSheet; }
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:213

References m_drawingSheet.

Referenced by DRC_TEST_PROVIDER_MISC::testTextVars().

◆ GetProgressReporter()

PROGRESS_REPORTER* DRC_ENGINE::GetProgressReporter ( ) const
inline

Definition at line 119 of file drc_engine.h.

119 { return m_progressReporter; }
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:230

References m_progressReporter.

Referenced by DRC_TEST_PROVIDER_CONNECTIVITY::Run().

◆ GetReportAllTrackErrors()

bool DRC_ENGINE::GetReportAllTrackErrors ( ) const
inline

Definition at line 152 of file drc_engine.h.

152 { return m_reportAllTrackErrors; }
bool m_reportAllTrackErrors
Definition: drc_engine.h:222

References m_reportAllTrackErrors.

Referenced by DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem().

◆ GetSchematicNetlist()

NETLIST* DRC_ENGINE::GetSchematicNetlist ( ) const
inline

Definition at line 93 of file drc_engine.h.

93 { return m_schematicNetlist; }
NETLIST * m_schematicNetlist
Definition: drc_engine.h:214

References m_schematicNetlist.

Referenced by DRC_TEST_PROVIDER_LVS::Run().

◆ GetShape()

std::shared_ptr< SHAPE > DRC_ENGINE::GetShape ( BOARD_ITEM aItem,
PCB_LAYER_ID  aLayer 
)
static

Definition at line 1290 of file drc_engine.cpp.

1291 {
1292  if( aItem->Type() == PCB_PAD_T && !static_cast<PAD*>( aItem )->FlashLayer( aLayer ) )
1293  {
1294  PAD* aPad = static_cast<PAD*>( aItem );
1295 
1296  if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
1297  {
1299 
1300  // Note: drill size represents finish size, which means the actual holes size is the
1301  // plating thickness larger.
1302  auto hole = static_cast<SHAPE_SEGMENT*>( aPad->GetEffectiveHoleShape()->Clone() );
1303  hole->SetWidth( hole->GetWidth() + bds.GetHolePlatingThickness() );
1304  return std::make_shared<SHAPE_SEGMENT>( *hole );
1305  }
1306 
1307  return std::make_shared<SHAPE_NULL>();
1308  }
1309 
1310  return aItem->GetEffectiveShape( aLayer );
1311 }
int GetHolePlatingThickness() const
Pad & via drills are finish size.
const SHAPE_SEGMENT * GetEffectiveHoleShape() const
Return a SHAPE object representing the pad's hole.
Definition: pad.cpp:292
class PAD, a pad in a footprint
Definition: typeinfo.h:89
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:588
Plated through hole pad.
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:51
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_segment.h:57
PAD_ATTRIB GetAttribute() const
Definition: pad.h:368
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:168
Definition: pad.h:57
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.

References SHAPE_SEGMENT::Clone(), PAD::GetAttribute(), BOARD_ITEM::GetBoard(), BOARD::GetDesignSettings(), PAD::GetEffectiveHoleShape(), BOARD_ITEM::GetEffectiveShape(), BOARD_DESIGN_SETTINGS::GetHolePlatingThickness(), PCB_PAD_T, PTH, and EDA_ITEM::Type().

Referenced by DRAWING_TOOL::DrawVia(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem().

◆ GetTestFootprints()

bool DRC_ENGINE::GetTestFootprints ( ) const
inline

Definition at line 153 of file drc_engine.h.

153 { return m_testFootprints; }
bool m_testFootprints
Definition: drc_engine.h:223

References m_testFootprints.

Referenced by DRC_TEST_PROVIDER_LVS::GetNumPhases(), and DRC_TEST_PROVIDER_LVS::Run().

◆ GetTestProvider()

DRC_TEST_PROVIDER * DRC_ENGINE::GetTestProvider ( const wxString &  name) const

Definition at line 1323 of file drc_engine.cpp.

1324 {
1325  for( auto prov : m_testProviders )
1326  if( name == prov->GetName() )
1327  return prov;
1328 
1329  return nullptr;
1330 }
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:218
const char * name
Definition: DXF_plotter.cpp:59

References m_testProviders, and name.

◆ GetTestProviders()

std::vector<DRC_TEST_PROVIDER* > DRC_ENGINE::GetTestProviders ( ) const
inline

Definition at line 164 of file drc_engine.h.

164 { return m_testProviders; };
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:218

References m_testProviders.

◆ HasRulesForConstraintType()

bool DRC_ENGINE::HasRulesForConstraintType ( DRC_CONSTRAINT_T  constraintID)

Definition at line 1168 of file drc_engine.cpp.

1169 {
1170  //drc_dbg(10,"hascorrect id %d size %d\n", ruleID, m_ruleMap[ruleID]->sortedRules.size( ) );
1171  if( m_constraintMap.count( constraintID ) )
1172  return m_constraintMap[ constraintID ]->size() > 0;
1173 
1174  return false;
1175 }
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226

References m_constraintMap.

Referenced by DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), and DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run().

◆ InitEngine()

void DRC_ENGINE::InitEngine ( const wxFileName &  aRulePath)

Initializes the DRC engine.

Exceptions
PARSE_ERRORif the rules file contains errors
PARSE_ERROR

Definition at line 628 of file drc_engine.cpp.

629 {
631 
632  for( DRC_TEST_PROVIDER* provider : m_testProviders )
633  {
634  ReportAux( wxString::Format( "Create DRC provider: '%s'", provider->GetName() ) );
635  provider->SetDRCEngine( this );
636  }
637 
638  for( DRC_RULE* rule : m_rules )
639  delete rule;
640 
641  m_rules.clear();
642  m_rulesValid = false;
643 
644  for( std::pair<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> pair : m_constraintMap )
645  {
646  for( DRC_ENGINE_CONSTRAINT* constraint : *pair.second )
647  delete constraint;
648 
649  delete pair.second;
650  }
651 
652  m_constraintMap.clear();
653 
654  m_board->IncrementTimeStamp(); // Clear board-level caches
655 
656  try // attempt to load full set of rules (implicit + user rules)
657  {
659  loadRules( aRulePath );
660  compileRules();
661  }
662  catch( PARSE_ERROR& original_parse_error )
663  {
664  try // try again with just our implicit rules
665  {
667  compileRules();
668  }
669  catch( PARSE_ERROR& )
670  {
671  wxFAIL_MSG( "Compiling implicit rules failed." );
672  }
673 
674  throw original_parse_error;
675  }
676 
677  for( int ii = DRCE_FIRST; ii < DRCE_LAST; ++ii )
678  m_errorLimits[ ii ] = INT_MAX;
679 
680  m_rulesValid = true;
681 }
void loadRules(const wxFileName &aPath)
Loads and parses a rule set from an sexpr text file.
Definition: drc_engine.cpp:529
std::vector< int > m_errorLimits
Definition: drc_engine.h:221
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:218
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
static DRC_TEST_PROVIDER_REGISTRY & Instance()
void compileRules()
Definition: drc_engine.cpp:552
bool m_rulesValid
Definition: drc_engine.h:217
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:216
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226
void IncrementTimeStamp()
Definition: board.cpp:191
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
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
void ReportAux(const wxString &aStr)
BOARD * m_board
Definition: drc_engine.h:212
void loadImplicitRules()
Definition: drc_engine.cpp:136

References compileRules(), DRCE_FIRST, DRCE_LAST, Format(), DRC_TEST_PROVIDER_REGISTRY::GetTestProviders(), BOARD::IncrementTimeStamp(), DRC_TEST_PROVIDER_REGISTRY::Instance(), loadImplicitRules(), loadRules(), m_board, m_constraintMap, m_errorLimits, m_rules, m_rulesValid, m_testProviders, and ReportAux().

Referenced by DoCourtyardInvalidTest(), DoCourtyardOverlapTest(), BOARD_INSPECTION_TOOL::InspectConstraints(), and BOARD_INSPECTION_TOOL::reportClearance().

◆ IsErrorLimitExceeded()

◆ IsNetADiffPair()

bool DRC_ENGINE::IsNetADiffPair ( BOARD aBoard,
NETINFO_ITEM aNet,
int &  aNetP,
int &  aNetN 
)
static

Definition at line 1260 of file drc_engine.cpp.

1261 {
1262  wxString refName = aNet->GetNetname();
1263  wxString dummy, coupledNetName;
1264 
1265  if( int polarity = MatchDpSuffix( refName, coupledNetName, dummy ) )
1266  {
1267  NETINFO_ITEM* net = aBoard->FindNet( coupledNetName );
1268 
1269  if( !net )
1270  return false;
1271 
1272  if( polarity > 0 )
1273  {
1274  aNetP = aNet->GetNetCode();
1275  aNetN = net->GetNetCode();
1276  }
1277  else
1278  {
1279  aNetP = net->GetNetCode();
1280  aNetN = aNet->GetNetCode();
1281  }
1282 
1283  return true;
1284  }
1285 
1286  return false;
1287 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1343
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Checks if the given net is a diff pair, returning its polarity and complement if so.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
const wxString & GetNetname() const
Definition: netinfo.h:119
Handle the data for a net.
Definition: netinfo.h:64
int GetNetCode() const
Definition: netinfo.h:113

References dummy(), BOARD::FindNet(), NETINFO_ITEM::GetNetCode(), NETINFO_ITEM::GetNetname(), and MatchDpSuffix().

Referenced by test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run().

◆ IsNetTie()

bool DRC_ENGINE::IsNetTie ( BOARD_ITEM aItem)
static

Definition at line 1314 of file drc_engine.cpp.

1315 {
1316  if( aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T )
1317  return static_cast<FOOTPRINT*>( aItem->GetParent() )->IsNetTie();
1318 
1319  return false;
1320 }
static bool IsNetTie(BOARD_ITEM *aItem)
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References BOARD_ITEM::GetParent(), PCB_FOOTPRINT_T, and EDA_ITEM::Type().

Referenced by DRAWING_TOOL::DrawVia(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances().

◆ loadImplicitRules()

void DRC_ENGINE::loadImplicitRules ( )
private

Definition at line 136 of file drc_engine.cpp.

137 {
138  ReportAux( wxString::Format( "Building implicit rules (per-item/class overrides, etc...)" ) );
139 
141 
142  // 1) global defaults
143 
144  DRC_RULE* rule = createImplicitRule( _( "board setup constraints" ) );
145 
146  DRC_CONSTRAINT clearanceConstraint( CLEARANCE_CONSTRAINT );
147  clearanceConstraint.Value().SetMin( bds.m_MinClearance );
148  rule->AddConstraint( clearanceConstraint );
149 
150  DRC_CONSTRAINT widthConstraint( TRACK_WIDTH_CONSTRAINT );
151  widthConstraint.Value().SetMin( bds.m_TrackMinWidth );
152  rule->AddConstraint( widthConstraint );
153 
154  DRC_CONSTRAINT drillConstraint( HOLE_SIZE_CONSTRAINT );
155  drillConstraint.Value().SetMin( bds.m_MinThroughDrill );
156  rule->AddConstraint( drillConstraint );
157 
158  DRC_CONSTRAINT annulusConstraint( ANNULAR_WIDTH_CONSTRAINT );
159  annulusConstraint.Value().SetMin( bds.m_ViasMinAnnularWidth );
160  rule->AddConstraint( annulusConstraint );
161 
162  DRC_CONSTRAINT diameterConstraint( VIA_DIAMETER_CONSTRAINT );
163  diameterConstraint.Value().SetMin( bds.m_ViasMinSize );
164  rule->AddConstraint( diameterConstraint );
165 
166  DRC_CONSTRAINT edgeClearanceConstraint( EDGE_CLEARANCE_CONSTRAINT );
167  edgeClearanceConstraint.Value().SetMin( bds.m_CopperEdgeClearance );
168  rule->AddConstraint( edgeClearanceConstraint );
169 
170  DRC_CONSTRAINT holeClearanceConstraint( HOLE_CLEARANCE_CONSTRAINT );
171  holeClearanceConstraint.Value().SetMin( bds.m_HoleClearance );
172  rule->AddConstraint( holeClearanceConstraint );
173 
174  DRC_CONSTRAINT holeToHoleConstraint( HOLE_TO_HOLE_CONSTRAINT );
175  holeToHoleConstraint.Value().SetMin( bds.m_HoleToHoleMin );
176  rule->AddConstraint( holeToHoleConstraint );
177 
178  DRC_CONSTRAINT courtyardClearanceConstraint( COURTYARD_CLEARANCE_CONSTRAINT );
179  holeToHoleConstraint.Value().SetMin( 0 );
180  rule->AddConstraint( courtyardClearanceConstraint );
181 
182  DRC_CONSTRAINT diffPairGapConstraint( DIFF_PAIR_GAP_CONSTRAINT );
183  diffPairGapConstraint.Value().SetMin( bds.m_MinClearance );
184  rule->AddConstraint( diffPairGapConstraint );
185 
186  rule = createImplicitRule( _( "board setup constraints" ) );
187  rule->m_LayerCondition = LSET( 2, F_SilkS, B_SilkS );
188  DRC_CONSTRAINT silkClearanceConstraint( SILK_CLEARANCE_CONSTRAINT );
189  silkClearanceConstraint.Value().SetMin( bds.m_SilkClearance );
190  rule->AddConstraint( silkClearanceConstraint );
191 
192 
193  // 2) micro-via specific defaults (new DRC doesn't treat microvias in any special way)
194 
195  DRC_RULE* uViaRule = createImplicitRule( _( "board setup micro-via constraints" ) );
196 
197  uViaRule->m_Condition = new DRC_RULE_CONDITION( "A.Via_Type == 'Micro'" );
198 
199  DRC_CONSTRAINT uViaDrillConstraint( HOLE_SIZE_CONSTRAINT );
200  uViaDrillConstraint.Value().SetMin( bds.m_MicroViasMinDrill );
201  uViaRule->AddConstraint( uViaDrillConstraint );
202 
203  DRC_CONSTRAINT uViaDiameterConstraint( VIA_DIAMETER_CONSTRAINT );
204  uViaDiameterConstraint.Value().SetMin( bds.m_MicroViasMinSize );
205  uViaRule->AddConstraint( uViaDiameterConstraint );
206 
207  if( !bds.m_MicroViasAllowed )
208  {
209  DRC_CONSTRAINT disallowConstraint( DISALLOW_CONSTRAINT );
210  disallowConstraint.m_DisallowFlags = DRC_DISALLOW_MICRO_VIAS;
211  uViaRule->AddConstraint( disallowConstraint );
212  }
213 
214  if( !bds.m_BlindBuriedViaAllowed )
215  {
216  DRC_RULE* bbViaRule = createImplicitRule( _( "board setup constraints" ) );
217 
218  bbViaRule->m_Condition = new DRC_RULE_CONDITION( "A.Via_Type == 'Blind/buried'" );
219 
220  DRC_CONSTRAINT disallowConstraint( DISALLOW_CONSTRAINT );
221  disallowConstraint.m_DisallowFlags = DRC_DISALLOW_BB_VIAS;
222  bbViaRule->AddConstraint( disallowConstraint );
223  }
224 
225  // 3) per-netclass rules
226 
227  std::vector<DRC_RULE*> netclassClearanceRules;
228  std::vector<DRC_RULE*> netclassItemSpecificRules;
229 
230  auto makeNetclassRules =
231  [&]( const NETCLASSPTR& nc, bool isDefault )
232  {
233  wxString ncName = nc->GetName();
234 
235  DRC_RULE* netclassRule;
236  wxString expr;
237 
238  if( nc->GetClearance() || nc->GetTrackWidth() )
239  {
240  netclassRule = new DRC_RULE;
241  netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), ncName );
242  netclassRule->m_Implicit = true;
243 
244  expr = wxString::Format( "A.NetClass == '%s'", ncName );
245  netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
246  netclassClearanceRules.push_back( netclassRule );
247 
248  if( nc->GetClearance() )
249  {
250  DRC_CONSTRAINT constraint( CLEARANCE_CONSTRAINT );
251  constraint.Value().SetMin( std::max( bds.m_MinClearance,
252  nc->GetClearance() ) );
253  netclassRule->AddConstraint( constraint );
254  }
255 
256  if( nc->GetTrackWidth() )
257  {
259  constraint.Value().SetMin( bds.m_TrackMinWidth );
260  constraint.Value().SetOpt( nc->GetTrackWidth() );
261  netclassRule->AddConstraint( constraint );
262  }
263  }
264 
265  if( nc->GetDiffPairWidth() )
266  {
267  netclassRule = new DRC_RULE;
268  netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
269  ncName );
270  netclassRule->m_Implicit = true;
271 
272  expr = wxString::Format( "A.NetClass == '%s' && A.inDiffPair('*')", 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  netclassRule = new DRC_RULE;
285  netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
286  ncName );
287  netclassRule->m_Implicit = true;
288 
289  expr = wxString::Format( "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 (but is still
299  // trimmed to the board min clearance, which is absolute).
300  if( nc->GetDiffPairGap() < nc->GetClearance() )
301  {
302  netclassRule = new DRC_RULE;
303  netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
304  ncName );
305  netclassRule->m_Implicit = true;
306 
307  expr = wxString::Format( "A.NetClass == '%s' && AB.isCoupledDiffPair()",
308  ncName );
309  netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
310  netclassItemSpecificRules.push_back( netclassRule );
311 
312  DRC_CONSTRAINT min_clearanceConstraint( CLEARANCE_CONSTRAINT );
313  min_clearanceConstraint.Value().SetMin( std::max( bds.m_MinClearance,
314  nc->GetDiffPairGap() ) );
315  netclassRule->AddConstraint( min_clearanceConstraint );
316  }
317  }
318 
319  if( nc->GetViaDiameter() || nc->GetViaDrill() )
320  {
321  netclassRule = new DRC_RULE;
322  netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), ncName );
323  netclassRule->m_Implicit = true;
324 
325  expr = wxString::Format( "A.NetClass == '%s' && A.Via_Type != 'Micro'",
326  ncName );
327  netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
328  netclassItemSpecificRules.push_back( netclassRule );
329 
330  if( nc->GetViaDiameter() )
331  {
333  constraint.Value().SetMin( bds.m_ViasMinSize );
334  constraint.Value().SetOpt( nc->GetViaDiameter() );
335  netclassRule->AddConstraint( constraint );
336  }
337 
338  if( nc->GetViaDrill() )
339  {
340  DRC_CONSTRAINT constraint( HOLE_SIZE_CONSTRAINT );
341  constraint.Value().SetMin( bds.m_MinThroughDrill );
342  constraint.Value().SetOpt( nc->GetViaDrill() );
343  netclassRule->AddConstraint( constraint );
344  }
345  }
346 
347  if( nc->GetuViaDiameter() || nc->GetuViaDrill() )
348  {
349  netclassRule = new DRC_RULE;
350  netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), ncName );
351  netclassRule->m_Implicit = true;
352 
353  expr = wxString::Format( "A.NetClass == '%s' && A.Via_Type == 'Micro'",
354  ncName );
355  netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
356  netclassItemSpecificRules.push_back( netclassRule );
357 
358  if( nc->GetuViaDiameter() )
359  {
361  constraint.Value().SetMin( bds.m_MicroViasMinSize );
362  constraint.Value().SetMin( nc->GetuViaDiameter() );
363  netclassRule->AddConstraint( constraint );
364  }
365 
366  if( nc->GetuViaDrill() )
367  {
368  DRC_CONSTRAINT constraint( HOLE_SIZE_CONSTRAINT );
369  constraint.Value().SetMin( bds.m_MicroViasMinDrill );
370  constraint.Value().SetOpt( nc->GetuViaDrill() );
371  netclassRule->AddConstraint( constraint );
372  }
373  }
374  };
375 
377  makeNetclassRules( bds.GetNetClasses().GetDefault(), true );
378 
379  for( const std::pair<const wxString, NETCLASSPTR>& netclass : bds.GetNetClasses() )
380  makeNetclassRules( netclass.second, false );
381 
382  // The netclass clearance rules have to be sorted by min clearance so the right one fires
383  // if 'A' and 'B' belong to two different netclasses.
384  //
385  // The item-specific netclass rules are all unary, so there's no 'A' vs 'B' issue.
386 
387  std::sort( netclassClearanceRules.begin(), netclassClearanceRules.end(),
388  []( DRC_RULE* lhs, DRC_RULE* rhs )
389  {
390  return lhs->m_Constraints[0].m_Value.Min()
391  < rhs->m_Constraints[0].m_Value.Min();
392  } );
393 
394  for( DRC_RULE* ncRule : netclassClearanceRules )
395  addRule( ncRule );
396 
397  for( DRC_RULE* ncRule : netclassItemSpecificRules )
398  addRule( ncRule );
399 
400  // 3) keepout area rules
401 
402  std::vector<ZONE*> keepoutZones;
403 
404  for( ZONE* zone : m_board->Zones() )
405  {
406  if( isKeepoutZone( zone, true ) )
407  keepoutZones.push_back( zone );
408  }
409 
410  for( FOOTPRINT* footprint : m_board->Footprints() )
411  {
412  for( ZONE* zone : footprint->Zones() )
413  {
414  if( isKeepoutZone( zone, true ) )
415  keepoutZones.push_back( zone );
416  }
417  }
418 
419  for( ZONE* zone : keepoutZones )
420  {
421  wxString name = zone->GetZoneName();
422 
423  if( name.IsEmpty() )
424  {
425  rule = createImplicitRule( _( "keepout area" ) );
426  name = zone->m_Uuid.AsString();
427  }
428  else
429  {
430  rule = createImplicitRule( wxString::Format( _( "keepout area '%s'" ), name ) );
431  }
432 
433  rule->m_Condition = new DRC_RULE_CONDITION( wxString::Format( "A.insideArea('%s')",
434  name ) );
435 
436  rule->m_LayerCondition = zone->GetLayerSet();
437 
438  int disallowFlags = 0;
439 
440  if( zone->GetDoNotAllowTracks() )
441  disallowFlags |= DRC_DISALLOW_TRACKS;
442 
443  if( zone->GetDoNotAllowVias() )
444  disallowFlags |= DRC_DISALLOW_VIAS;
445 
446  if( zone->GetDoNotAllowPads() )
447  disallowFlags |= DRC_DISALLOW_PADS;
448 
449  if( zone->GetDoNotAllowCopperPour() )
450  disallowFlags |= DRC_DISALLOW_ZONES;
451 
452  if( zone->GetDoNotAllowFootprints() )
453  disallowFlags |= DRC_DISALLOW_FOOTPRINTS;
454 
455  DRC_CONSTRAINT disallowConstraint( DISALLOW_CONSTRAINT );
456  disallowConstraint.m_DisallowFlags = disallowFlags;
457  rule->AddConstraint( disallowConstraint );
458  }
459 
460  ReportAux( wxString::Format( "Building %d implicit netclass rules",
461  (int) netclassClearanceRules.size() ) );
462 }
ZONES & Zones()
Definition: board.h:239
DRC_RULE_CONDITION * m_Condition
Definition: drc_rule.h:99
bool m_Implicit
Definition: drc_rule.h:95
wxString m_Name
Definition: drc_rule.h:96
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:588
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1409
LSET is a set of PCB_LAYER_IDs.
void addRule(DRC_RULE *rule)
Definition: drc_engine.h:185
std::vector< DRC_CONSTRAINT > m_Constraints
Definition: drc_rule.h:100
FOOTPRINTS & Footprints()
Definition: board.h:233
#define _(s)
NETCLASSES & GetNetClasses() const
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
static bool isKeepoutZone(const BOARD_ITEM *aItem, bool aCheckFlags)
Definition: drc_engine.cpp:94
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
DRC_RULE * createImplicitRule(const wxString &name)
Definition: drc_engine.cpp:123
const char * name
Definition: DXF_plotter.cpp:59
LSET m_LayerCondition
Definition: drc_rule.h:98
void ReportAux(const wxString &aStr)
void AddConstraint(DRC_CONSTRAINT &aConstraint)
Definition: drc_rule.cpp:46
BOARD * m_board
Definition: drc_engine.h:212
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
bool m_MicroViasAllowed
true to allow micro vias
Container for design settings for a BOARD object.

References _, DRC_RULE::AddConstraint(), addRule(), ANNULAR_WIDTH_CONSTRAINT, B_SilkS, CLEARANCE_CONSTRAINT, COURTYARD_CLEARANCE_CONSTRAINT, createImplicitRule(), DIFF_PAIR_GAP_CONSTRAINT, DISALLOW_CONSTRAINT, DRC_DISALLOW_BB_VIAS, DRC_DISALLOW_FOOTPRINTS, DRC_DISALLOW_MICRO_VIAS, DRC_DISALLOW_PADS, DRC_DISALLOW_TRACKS, DRC_DISALLOW_VIAS, DRC_DISALLOW_ZONES, EDGE_CLEARANCE_CONSTRAINT, F_SilkS, BOARD::Footprints(), Format(), NETCLASSES::GetDefault(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetNetClasses(), HOLE_CLEARANCE_CONSTRAINT, HOLE_SIZE_CONSTRAINT, HOLE_TO_HOLE_CONSTRAINT, isKeepoutZone(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, m_board, DRC_RULE::m_Condition, DRC_RULE::m_Constraints, BOARD_DESIGN_SETTINGS::m_CopperEdgeClearance, DRC_CONSTRAINT::m_DisallowFlags, BOARD_DESIGN_SETTINGS::m_HoleClearance, BOARD_DESIGN_SETTINGS::m_HoleToHoleMin, DRC_RULE::m_Implicit, DRC_RULE::m_LayerCondition, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_MinClearance, BOARD_DESIGN_SETTINGS::m_MinThroughDrill, DRC_RULE::m_Name, BOARD_DESIGN_SETTINGS::m_SilkClearance, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinAnnularWidth, BOARD_DESIGN_SETTINGS::m_ViasMinSize, name, ReportAux(), MINOPTMAX< T >::SetMin(), MINOPTMAX< T >::SetOpt(), SILK_CLEARANCE_CONSTRAINT, BOARD::SynchronizeNetsAndNetClasses(), TRACK_WIDTH_CONSTRAINT, DRC_CONSTRAINT::Value(), VIA_DIAMETER_CONSTRAINT, and BOARD::Zones().

Referenced by InitEngine().

◆ loadRules()

void DRC_ENGINE::loadRules ( const wxFileName &  aPath)
private

Loads and parses a rule set from an sexpr text file.

Exceptions
PARSE_ERROR

Definition at line 529 of file drc_engine.cpp.

530 {
531  if( aPath.FileExists() )
532  {
533  std::vector<DRC_RULE*> rules;
534 
535  FILE* fp = wxFopen( aPath.GetFullPath(), wxT( "rt" ) );
536 
537  if( fp )
538  {
539  DRC_RULES_PARSER parser( fp, aPath.GetFullPath() );
540  parser.Parse( rules, m_reporter );
541  }
542 
543  // Copy the rules into the member variable afterwards so that if Parse() throws then
544  // the possibly malformed rules won't contaminate the current ruleset.
545 
546  for( DRC_RULE* rule : rules )
547  m_rules.push_back( rule );
548  }
549 }
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:216
void Parse(std::vector< DRC_RULE * > &aRules, REPORTER *aReporter)
REPORTER * m_reporter
Definition: drc_engine.h:229

References m_reporter, m_rules, and DRC_RULES_PARSER::Parse().

Referenced by InitEngine().

◆ MatchDpSuffix()

int DRC_ENGINE::MatchDpSuffix ( const wxString &  aNetName,
wxString &  aComplementNet,
wxString &  aBaseDpName 
)
static

Checks if the given net is a diff pair, returning its polarity and complement if so.

Parameters
aNetNameis the input net name, like DIFF_P
aComplementNetwill be filled with the complement, like DIFF_N
aBaseDpNamewill be filled with the base name, like DIFF
Returns
1 if aNetName is the positive half of a pair, -1 if negative, 0 if not a diff pair

Definition at line 1201 of file drc_engine.cpp.

1203 {
1204  int rv = 0;
1205 
1206  if( aNetName.EndsWith( "+" ) )
1207  {
1208  aComplementNet = "-";
1209  rv = 1;
1210  }
1211  else if( aNetName.EndsWith( "P" ) )
1212  {
1213  aComplementNet = "N";
1214  rv = 1;
1215  }
1216  else if( aNetName.EndsWith( "-" ) )
1217  {
1218  aComplementNet = "+";
1219  rv = -1;
1220  }
1221  else if( aNetName.EndsWith( "N" ) )
1222  {
1223  aComplementNet = "P";
1224  rv = -1;
1225  }
1226  // Match P followed by 2 digits
1227  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
1228  {
1229  aComplementNet = "N" + aNetName.Right( 2 );
1230  rv = 1;
1231  }
1232  // Match P followed by 1 digit
1233  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
1234  {
1235  aComplementNet = "N" + aNetName.Right( 1 );
1236  rv = 1;
1237  }
1238  // Match N followed by 2 digits
1239  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
1240  {
1241  aComplementNet = "P" + aNetName.Right( 2 );
1242  rv = -1;
1243  }
1244  // Match N followed by 1 digit
1245  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
1246  {
1247  aComplementNet = "P" + aNetName.Right( 1 );
1248  rv = -1;
1249  }
1250  if( rv != 0 )
1251  {
1252  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
1253  aComplementNet = aBaseDpName + aComplementNet;
1254  }
1255 
1256  return rv;
1257 }

Referenced by inDiffPair(), isCoupledDiffPair(), and IsNetADiffPair().

◆ QueryWorstConstraint()

bool DRC_ENGINE::QueryWorstConstraint ( DRC_CONSTRAINT_T  aRuleId,
DRC_CONSTRAINT aConstraint 
)

Definition at line 1178 of file drc_engine.cpp.

1179 {
1180  int worst = 0;
1181 
1182  if( m_constraintMap.count( aConstraintId ) )
1183  {
1184  for( DRC_ENGINE_CONSTRAINT* c : *m_constraintMap[aConstraintId] )
1185  {
1186  int current = c->constraint.GetValue().Min();
1187 
1188  if( current > worst )
1189  {
1190  worst = current;
1191  aConstraint = c->constraint;
1192  }
1193  }
1194  }
1195 
1196  return worst > 0;
1197 }
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:226

References m_constraintMap.

Referenced by DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run().

◆ ReportAux()

void DRC_ENGINE::ReportAux ( const wxString &  aStr)

Definition at line 1139 of file drc_engine.cpp.

1140 {
1141  if( !m_reporter )
1142  return;
1143 
1145 }
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
REPORTER * m_reporter
Definition: drc_engine.h:229

References m_reporter, REPORTER::Report(), and RPT_SEVERITY_INFO.

Referenced by compileRules(), InitEngine(), loadImplicitRules(), DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportRuleStatistics(), and RunTests().

◆ ReportPhase()

bool DRC_ENGINE::ReportPhase ( const wxString &  aMessage)

Definition at line 1158 of file drc_engine.cpp.

1159 {
1160  if( !m_progressReporter )
1161  return true;
1162 
1163  m_progressReporter->AdvancePhase( aMessage );
1164  return m_progressReporter->KeepRefreshing( false );
1165 }
virtual void AdvancePhase()
Use the next available virtual zone of the dialog progress bar.
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:230
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.

References PROGRESS_REPORTER::AdvancePhase(), PROGRESS_REPORTER::KeepRefreshing(), and m_progressReporter.

Referenced by DRC_TEST_PROVIDER::reportPhase(), and RunTests().

◆ ReportProgress()

bool DRC_ENGINE::ReportProgress ( double  aProgress)

Definition at line 1148 of file drc_engine.cpp.

1149 {
1150  if( !m_progressReporter )
1151  return true;
1152 
1153  m_progressReporter->SetCurrentProgress( aProgress );
1154  return m_progressReporter->KeepRefreshing( false );
1155 }
virtual void SetCurrentProgress(double aProgress)
Set the progress value to aProgress (0..1).
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:230
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.

References PROGRESS_REPORTER::KeepRefreshing(), m_progressReporter, and PROGRESS_REPORTER::SetCurrentProgress().

Referenced by DRC_TEST_PROVIDER::reportProgress(), and RunTests().

◆ ReportViolation()

void DRC_ENGINE::ReportViolation ( const std::shared_ptr< DRC_ITEM > &  aItem,
wxPoint  aPos 
)

Definition at line 1110 of file drc_engine.cpp.

1111 {
1112  m_errorLimits[ aItem->GetErrorCode() ] -= 1;
1113 
1114  if( m_violationHandler )
1115  m_violationHandler( aItem, aPos );
1116 
1117  if( m_reporter )
1118  {
1119  wxString msg = wxString::Format( "Test '%s': %s (code %d)",
1120  aItem->GetViolatingTest()->GetName(),
1121  aItem->GetErrorMessage(),
1122  aItem->GetErrorCode() );
1123 
1124  DRC_RULE* rule = aItem->GetViolatingRule();
1125 
1126  if( rule )
1127  msg += wxString::Format( ", violating rule: '%s'", rule->m_Name );
1128 
1129  m_reporter->Report( msg );
1130 
1131  wxString violatingItemsStr = "Violating items: ";
1132 
1133  m_reporter->Report( wxString::Format( " |- violating position (%d, %d)",
1134  aPos.x,
1135  aPos.y ) );
1136  }
1137 }
std::vector< int > m_errorLimits
Definition: drc_engine.h:221
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
REPORTER * m_reporter
Definition: drc_engine.h:229
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
DRC_VIOLATION_HANDLER m_violationHandler
Definition: drc_engine.h:228

References Format(), m_errorLimits, m_reporter, m_violationHandler, and REPORTER::Report().

Referenced by DRC_TEST_PROVIDER::reportViolation().

◆ RulesValid()

bool DRC_ENGINE::RulesValid ( )
inline

Definition at line 155 of file drc_engine.h.

155 { return m_rulesValid; }
bool m_rulesValid
Definition: drc_engine.h:217

References m_rulesValid.

◆ RunTests()

void DRC_ENGINE::RunTests ( EDA_UNITS  aUnits,
bool  aReportAllTrackErrors,
bool  aTestFootprints 
)

Runs the DRC tests.

Definition at line 684 of file drc_engine.cpp.

685 {
686  m_userUnits = aUnits;
687 
688  // Note: set these first. The phase counts may be dependent on some of them.
689  m_reportAllTrackErrors = aReportAllTrackErrors;
690  m_testFootprints = aTestFootprints;
691 
692  for( int ii = DRCE_FIRST; ii < DRCE_LAST; ++ii )
693  {
694  if( m_designSettings->Ignore( ii ) )
695  m_errorLimits[ ii ] = 0;
696  else
697  m_errorLimits[ ii ] = INT_MAX;
698  }
699 
700  m_board->IncrementTimeStamp(); // Invalidate all caches
701 
702  if( !ReportPhase( _( "Tessellating copper zones..." ) ) )
703  return;
704 
705  // Number of zones between progress bar updates
706  int delta = 5;
707  std::vector<ZONE*> copperZones;
708 
709  for( ZONE* zone : m_board->Zones() )
710  {
711  zone->CacheBoundingBox();
712  zone->CacheTriangulation();
713 
714  if( !zone->GetIsRuleArea() )
715  copperZones.push_back( zone );
716  }
717 
718  for( FOOTPRINT* footprint : m_board->Footprints() )
719  {
720  for( ZONE* zone : footprint->Zones() )
721  {
722  zone->CacheBoundingBox();
723  zone->CacheTriangulation();
724 
725  if( !zone->GetIsRuleArea() )
726  copperZones.push_back( zone );
727  }
728 
729  footprint->BuildPolyCourtyards();
730  }
731 
732  int zoneCount = copperZones.size();
733 
734  for( int ii = 0; ii < zoneCount; ++ii )
735  {
736  ZONE* zone = copperZones[ ii ];
737 
738  if( ( ii % delta ) == 0 || ii == zoneCount - 1 )
739  {
740  if( !ReportProgress( (double) ii / (double) zoneCount ) )
741  return;
742  }
743 
744  m_board->m_CopperZoneRTrees[ zone ] = std::make_unique<DRC_RTREE>();
745 
746  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
747  {
748  if( IsCopperLayer( layer ) )
749  m_board->m_CopperZoneRTrees[ zone ]->Insert( zone, layer );
750  }
751  }
752 
753  for( DRC_TEST_PROVIDER* provider : m_testProviders )
754  {
755  if( !provider->IsEnabled() )
756  continue;
757 
758  drc_dbg( 0, "Running test provider: '%s'\n", provider->GetName() );
759 
760  ReportAux( wxString::Format( "Run DRC provider: '%s'", provider->GetName() ) );
761 
762  if( !provider->Run() )
763  break;
764  }
765 }
EDA_UNITS m_userUnits
Definition: drc_engine.h:220
std::vector< int > m_errorLimits
Definition: drc_engine.h:221
ZONES & Zones()
Definition: board.h:239
bool ReportPhase(const wxString &aMessage)
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:218
bool Ignore(int aDRCErrorCode)
Return true if the DRC error code's severity is SEVERITY_IGNORE.
bool m_testFootprints
Definition: drc_engine.h:223
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:291
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:211
PCB_LAYER_ID
A quick note on layer IDs:
FOOTPRINTS & Footprints()
Definition: board.h:233
bool ReportProgress(double aProgress)
#define _(s)
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
void IncrementTimeStamp()
Definition: board.cpp:191
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
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
void ReportAux(const wxString &aStr)
std::map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTrees
Definition: board.h:1088
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
BOARD * m_board
Definition: drc_engine.h:212
#define drc_dbg(level, fmt,...)
Definition: drc_engine.h:57
bool m_reportAllTrackErrors
Definition: drc_engine.h:222

References _, drc_dbg, DRCE_FIRST, DRCE_LAST, BOARD::Footprints(), Format(), ZONE::GetLayerSet(), BOARD_DESIGN_SETTINGS::Ignore(), BOARD::IncrementTimeStamp(), IsCopperLayer(), m_board, BOARD::m_CopperZoneRTrees, m_designSettings, m_errorLimits, m_reportAllTrackErrors, m_testFootprints, m_testProviders, m_userUnits, ReportAux(), ReportPhase(), ReportProgress(), LSET::Seq(), and BOARD::Zones().

◆ SetBoard()

void DRC_ENGINE::SetBoard ( BOARD aBoard)
inline

Definition at line 86 of file drc_engine.h.

86 { m_board = aBoard; }
BOARD * m_board
Definition: drc_engine.h:212

References m_board.

◆ SetDebugOverlay()

void DRC_ENGINE::SetDebugOverlay ( std::shared_ptr< KIGFX::VIEW_OVERLAY aOverlay)
inline

Definition at line 98 of file drc_engine.h.

98 { m_debugOverlay = aOverlay; }
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Definition: drc_engine.h:233

References m_debugOverlay.

◆ SetDesignSettings()

void DRC_ENGINE::SetDesignSettings ( BOARD_DESIGN_SETTINGS aSettings)
inline

Definition at line 89 of file drc_engine.h.

89 { m_designSettings = aSettings; }
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:211

References m_designSettings.

◆ SetDrawingSheet()

void DRC_ENGINE::SetDrawingSheet ( DS_PROXY_VIEW_ITEM aDrawingSheet)
inline

Definition at line 95 of file drc_engine.h.

95 { m_drawingSheet = aDrawingSheet; }
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:213

References m_drawingSheet.

◆ SetLogReporter()

void DRC_ENGINE::SetLogReporter ( REPORTER aReporter)
inline

Definition at line 128 of file drc_engine.h.

128 { m_reporter = aReporter; }
REPORTER * m_reporter
Definition: drc_engine.h:229

References m_reporter.

◆ SetProgressReporter()

void DRC_ENGINE::SetProgressReporter ( PROGRESS_REPORTER aProgRep)
inline

Set an optional reporter for user-level progress info.

Definition at line 118 of file drc_engine.h.

118 { m_progressReporter = aProgRep; }
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:230

References m_progressReporter.

◆ SetSchematicNetlist()

void DRC_ENGINE::SetSchematicNetlist ( NETLIST aNetlist)
inline

Definition at line 92 of file drc_engine.h.

92 { m_schematicNetlist = aNetlist; }
NETLIST * m_schematicNetlist
Definition: drc_engine.h:214

References m_schematicNetlist.

◆ SetViolationHandler()

void DRC_ENGINE::SetViolationHandler ( DRC_VIOLATION_HANDLER  aHandler)
inline

Set an optional DRC violation handler (receives DRC_ITEMs and positions).

Definition at line 105 of file drc_engine.h.

106  {
107  m_violationHandler = std::move( aHandler );
108  }
DRC_VIOLATION_HANDLER m_violationHandler
Definition: drc_engine.h:228

References m_violationHandler.

◆ UserUnits()

EDA_UNITS DRC_ENGINE::UserUnits ( ) const
inline

Definition at line 151 of file drc_engine.h.

151 { return m_userUnits; }
EDA_UNITS m_userUnits
Definition: drc_engine.h:220

References m_userUnits.

Referenced by DRC_TEST_PROVIDER::userUnits().

Member Data Documentation

◆ m_board

BOARD* DRC_ENGINE::m_board
protected

Definition at line 212 of file drc_engine.h.

Referenced by GetBoard(), InitEngine(), loadImplicitRules(), RunTests(), and SetBoard().

◆ m_constraintMap

std::unordered_map<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> DRC_ENGINE::m_constraintMap
protected

◆ m_debugOverlay

std::shared_ptr<KIGFX::VIEW_OVERLAY> DRC_ENGINE::m_debugOverlay
protected

Definition at line 233 of file drc_engine.h.

Referenced by GetDebugOverlay(), and SetDebugOverlay().

◆ m_designSettings

BOARD_DESIGN_SETTINGS* DRC_ENGINE::m_designSettings
protected

Definition at line 211 of file drc_engine.h.

Referenced by EvalRules(), GetDesignSettings(), RunTests(), and SetDesignSettings().

◆ m_drawingSheet

DS_PROXY_VIEW_ITEM* DRC_ENGINE::m_drawingSheet
protected

Definition at line 213 of file drc_engine.h.

Referenced by GetDrawingSheet(), and SetDrawingSheet().

◆ m_errorLimits

std::vector<int> DRC_ENGINE::m_errorLimits
protected

Definition at line 221 of file drc_engine.h.

Referenced by DRC_ENGINE(), InitEngine(), IsErrorLimitExceeded(), ReportViolation(), and RunTests().

◆ m_msg

wxString DRC_ENGINE::m_msg
protected

Definition at line 232 of file drc_engine.h.

Referenced by EvalRules().

◆ m_progressReporter

PROGRESS_REPORTER* DRC_ENGINE::m_progressReporter
protected

◆ m_reportAllTrackErrors

bool DRC_ENGINE::m_reportAllTrackErrors
protected

Definition at line 222 of file drc_engine.h.

Referenced by GetReportAllTrackErrors(), and RunTests().

◆ m_reporter

REPORTER* DRC_ENGINE::m_reporter
protected

Definition at line 229 of file drc_engine.h.

Referenced by loadRules(), ReportAux(), ReportViolation(), and SetLogReporter().

◆ m_rules

std::vector<DRC_RULE*> DRC_ENGINE::m_rules
protected

Definition at line 216 of file drc_engine.h.

Referenced by addRule(), compileRules(), InitEngine(), loadRules(), and ~DRC_ENGINE().

◆ m_rulesValid

bool DRC_ENGINE::m_rulesValid
protected

Definition at line 217 of file drc_engine.h.

Referenced by InitEngine(), and RulesValid().

◆ m_schematicNetlist

NETLIST* DRC_ENGINE::m_schematicNetlist
protected

Definition at line 214 of file drc_engine.h.

Referenced by GetSchematicNetlist(), and SetSchematicNetlist().

◆ m_testFootprints

bool DRC_ENGINE::m_testFootprints
protected

Definition at line 223 of file drc_engine.h.

Referenced by GetTestFootprints(), and RunTests().

◆ m_testProviders

std::vector<DRC_TEST_PROVIDER*> DRC_ENGINE::m_testProviders
protected

Definition at line 218 of file drc_engine.h.

Referenced by compileRules(), GetTestProvider(), GetTestProviders(), InitEngine(), and RunTests().

◆ m_userUnits

EDA_UNITS DRC_ENGINE::m_userUnits
protected

Definition at line 220 of file drc_engine.h.

Referenced by RunTests(), and UserUnits().

◆ m_violationHandler

DRC_VIOLATION_HANDLER DRC_ENGINE::m_violationHandler
protected

Definition at line 228 of file drc_engine.h.

Referenced by ClearViolationHandler(), ReportViolation(), and SetViolationHandler().


The documentation for this class was generated from the following files: