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)
 Initialize the DRC engine. More...
 
void RunTests (EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints)
 Run the DRC tests. More...
 
bool IsErrorLimitExceeded (int error_code)
 
DRC_CONSTRAINT EvalRules (DRC_CONSTRAINT_T aConstraintType, 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, const 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)
 Check 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)
 Load and parse 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 81 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 61 of file drc_engine.cpp.

61  :
62  m_designSettings ( aSettings ),
63  m_board( aBoard ),
64  m_drawingSheet( nullptr ),
65  m_schematicNetlist( nullptr ),
66  m_rulesValid( false ),
68  m_reportAllTrackErrors( false ),
69  m_testFootprints( false ),
70  m_reporter( nullptr ),
71  m_progressReporter( nullptr )
72 {
73  m_errorLimits.resize( DRCE_LAST + 1 );
74 
75  for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
76  m_errorLimits[ ii ] = INT_MAX;
77 }
EDA_UNITS m_userUnits
Definition: drc_engine.h:224
std::vector< int > m_errorLimits
Definition: drc_engine.h:225
NETLIST * m_schematicNetlist
Definition: drc_engine.h:218
bool m_testFootprints
Definition: drc_engine.h:227
bool m_rulesValid
Definition: drc_engine.h:221
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:215
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:234
REPORTER * m_reporter
Definition: drc_engine.h:233
BOARD * m_board
Definition: drc_engine.h:216
bool m_reportAllTrackErrors
Definition: drc_engine.h:226
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:217

References DRCE_FIRST, DRCE_LAST, and m_errorLimits.

◆ ~DRC_ENGINE()

DRC_ENGINE::~DRC_ENGINE ( )

Definition at line 80 of file drc_engine.cpp.

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

References m_constraintMap, and m_rules.

Member Function Documentation

◆ addRule()

void DRC_ENGINE::addRule ( DRC_RULE rule)
inlineprivate

Definition at line 189 of file drc_engine.h.

190  {
191  m_rules.push_back(rule);
192  }
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:220

References m_rules.

Referenced by createImplicitRule(), and loadImplicitRules().

◆ ClearViolationHandler()

void DRC_ENGINE::ClearViolationHandler ( )
inline

Definition at line 114 of file drc_engine.h.

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

References m_violationHandler.

◆ compileRules()

void DRC_ENGINE::compileRules ( )
private

Definition at line 553 of file drc_engine.cpp.

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

125 {
126  DRC_RULE *rule = new DRC_RULE;
127 
128  rule->m_Name = name;
129  rule->m_Implicit = true;
130 
131  addRule( rule );
132 
133  return rule;
134 }
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:189
const char * name
Definition: DXF_plotter.cpp:56

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

Referenced by loadImplicitRules().

◆ EvalRules()

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

Definition at line 765 of file drc_engine.cpp.

768 {
769 #define REPORT( s ) { if( aReporter ) { aReporter->Report( s ); } }
770 #define UNITS aReporter ? aReporter->GetUnits() : EDA_UNITS::MILLIMETRES
771 #define REPORT_VALUE( v ) MessageTextFromValue( UNITS, v )
772  /*
773  * NOTE: all string manipulation MUST BE KEPT INSIDE the REPORT macro. It absolutely
774  * kills performance when running bulk DRC tests (where aReporter is nullptr).
775  */
776 
777  const BOARD_CONNECTED_ITEM* ac = a && a->IsConnected() ?
778  static_cast<const BOARD_CONNECTED_ITEM*>( a ) : nullptr;
779  const BOARD_CONNECTED_ITEM* bc = b && b->IsConnected() ?
780  static_cast<const BOARD_CONNECTED_ITEM*>( b ) : nullptr;
781 
782  bool a_is_non_copper = a && ( !a->IsOnCopperLayer() || isKeepoutZone( a, false ) );
783  bool b_is_non_copper = b && ( !b->IsOnCopperLayer() || isKeepoutZone( b, false ) );
784 
785  DRC_CONSTRAINT constraint;
786  constraint.m_Type = aConstraintType;
787 
788  // Local overrides take precedence over everything *except* board min clearance
789  if( aConstraintType == CLEARANCE_CONSTRAINT || aConstraintType == HOLE_CLEARANCE_CONSTRAINT )
790  {
791  int override = 0;
792 
793  if( ac && !b_is_non_copper )
794  {
795  int overrideA = ac->GetLocalClearanceOverrides( nullptr );
796 
797  if( overrideA > 0 )
798  {
799  REPORT( "" )
800  REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
801  EscapeHTML( a->GetSelectMenuText( UNITS ) ),
802  REPORT_VALUE( overrideA ) ) )
803 
804  override = ac->GetLocalClearanceOverrides( &m_msg );
805  }
806  }
807 
808  if( bc && !a_is_non_copper )
809  {
810  int overrideB = bc->GetLocalClearanceOverrides( nullptr );
811 
812  if( overrideB > 0 )
813  {
814  REPORT( "" )
815  REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ),
816  EscapeHTML( b->GetSelectMenuText( UNITS ) ),
817  EscapeHTML( REPORT_VALUE( overrideB ) ) ) )
818 
819  if( overrideB > override )
820  override = bc->GetLocalClearanceOverrides( &m_msg );
821  }
822  }
823 
824  if( override )
825  {
826  if( aConstraintType == CLEARANCE_CONSTRAINT )
827  {
828  if( override < m_designSettings->m_MinClearance )
829  {
830  override = m_designSettings->m_MinClearance;
831  m_msg = _( "board minimum" );
832 
833  REPORT( "" )
834  REPORT( wxString::Format( _( "Board minimum clearance: %s." ),
835  REPORT_VALUE( override ) ) )
836  }
837  }
838  else
839  {
840  if( override < m_designSettings->m_HoleClearance )
841  {
842  override = m_designSettings->m_HoleClearance;
843  m_msg = _( "board minimum hole" );
844 
845  REPORT( "" )
846  REPORT( wxString::Format( _( "Board minimum hole clearance: %s." ),
847  REPORT_VALUE( override ) ) )
848  }
849  }
850 
851  constraint.SetName( m_msg );
852  constraint.m_Value.SetMin( override );
853  return constraint;
854  }
855  }
856 
857  auto processConstraint =
858  [&]( const DRC_ENGINE_CONSTRAINT* c ) -> bool
859  {
860  bool implicit = c->parentRule && c->parentRule->m_Implicit;
861 
862  REPORT( "" )
863 
864  switch( c->constraint.m_Type )
865  {
871  {
872  int val = c->constraint.m_Value.Min();
873  REPORT( wxString::Format( _( "Checking %s clearance: %s." ),
874  EscapeHTML( c->constraint.GetName() ),
875  REPORT_VALUE( val ) ) )
876  break;
877  }
878 
882  {
883  if( aReporter )
884  {
885  wxString min = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
886  wxString opt = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
887  wxString max = wxT( "<i>" ) + _( "undefined" ) + wxT( "</i>" );
888  wxString msg;
889 
890  if( implicit )
891  {
892  opt = StringFromValue( UNITS, c->constraint.m_Value.Opt(), true );
893 
894  switch( c->constraint.m_Type )
895  {
896  case TRACK_WIDTH_CONSTRAINT: msg = "track width"; break;
897  case ANNULAR_WIDTH_CONSTRAINT: msg = "annular width"; break;
898  case VIA_DIAMETER_CONSTRAINT: msg = "via diameter"; break;
899  default: msg = "constraint"; break;
900  }
901 
902  REPORT( wxString::Format( _( "Checking %s %s: %s." ),
903  EscapeHTML( c->constraint.GetName() ),
904  EscapeHTML( msg ),
905  opt ) )
906  }
907  else
908  {
909  if( c->constraint.m_Value.HasMin() )
910  min = StringFromValue( UNITS, c->constraint.m_Value.Min(), true );
911 
912  if( c->constraint.m_Value.HasOpt() )
913  opt = StringFromValue( UNITS, c->constraint.m_Value.Opt(), true );
914 
915  if( c->constraint.m_Value.HasMax() )
916  max = StringFromValue( UNITS, c->constraint.m_Value.Max(), true );
917 
918  REPORT( wxString::Format( _( "Checking %s: min %s; opt %s; max %s." ),
919  EscapeHTML( c->constraint.GetName() ),
920  min,
921  opt,
922  max ) )
923  }
924  }
925  break;
926  }
927 
928  default:
929  REPORT( wxString::Format( _( "Checking %s." ),
930  EscapeHTML( c->constraint.GetName() ) ) )
931  }
932 
933  if( c->constraint.m_Type == CLEARANCE_CONSTRAINT )
934  {
935  if( implicit && ( a_is_non_copper || b_is_non_copper ) )
936  {
937  REPORT( _( "Board and netclass clearances apply only between copper "
938  "items." ) );
939  return true;
940  }
941  }
942  else if( c->constraint.m_Type == DISALLOW_CONSTRAINT )
943  {
944  int mask;
945 
946  if( a->GetFlags() & HOLE_PROXY )
947  {
948  mask = DRC_DISALLOW_HOLES;
949  }
950  else if( a->Type() == PCB_VIA_T )
951  {
952  mask = DRC_DISALLOW_VIAS;
953 
954  switch( static_cast<const PCB_VIA*>( a )->GetViaType() )
955  {
956  case VIATYPE::BLIND_BURIED: mask |= DRC_DISALLOW_BB_VIAS; break;
957  case VIATYPE::MICROVIA: mask |= DRC_DISALLOW_MICRO_VIAS; break;
958  default: break;
959  }
960  }
961  else
962  {
963  switch( a->Type() )
964  {
965  case PCB_TRACE_T: mask = DRC_DISALLOW_TRACKS; break;
966  case PCB_ARC_T: mask = DRC_DISALLOW_TRACKS; break;
967  case PCB_PAD_T: mask = DRC_DISALLOW_PADS; break;
968  case PCB_FOOTPRINT_T: mask = DRC_DISALLOW_FOOTPRINTS; break;
969  case PCB_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break;
970  case PCB_FP_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break;
971  case PCB_TEXT_T: mask = DRC_DISALLOW_TEXTS; break;
972  case PCB_FP_TEXT_T: mask = DRC_DISALLOW_TEXTS; break;
973  case PCB_ZONE_T: mask = DRC_DISALLOW_ZONES; break;
974  case PCB_FP_ZONE_T: mask = DRC_DISALLOW_ZONES; break;
975  case PCB_LOCATE_HOLE_T: mask = DRC_DISALLOW_HOLES; break;
976  default: mask = 0; break;
977  }
978  }
979 
980  if( ( c->constraint.m_DisallowFlags & mask ) == 0 )
981  {
982  if( implicit )
983  REPORT( _( "Keepout constraint not met." ) )
984  else
985  REPORT( _( "Disallow constraint not met." ) )
986 
987  return false;
988  }
989 
990  LSET itemLayers = a->GetLayerSet();
991 
992  if( a->Type() == PCB_FOOTPRINT_T )
993  {
994  const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( a );
995 
996  if( !footprint->GetPolyCourtyard( F_CrtYd ).IsEmpty() )
997  itemLayers |= LSET::FrontMask();
998 
999  if( !footprint->GetPolyCourtyard( B_CrtYd ).IsEmpty() )
1000  itemLayers |= LSET::BackMask();
1001  }
1002 
1003  if( !( c->layerTest & itemLayers ).any() )
1004  {
1005  if( implicit )
1006  {
1007  REPORT( _( "Keepout layer(s) not matched." ) )
1008  }
1009  else if( c->parentRule )
1010  {
1011  REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule "
1012  "ignored." ),
1013  EscapeHTML( c->parentRule->m_LayerSource ) ) )
1014  }
1015  else
1016  {
1017  REPORT( _( "Rule layer not matched; rule ignored." ) )
1018  }
1019 
1020  return false;
1021  }
1022  }
1023 
1024  if( aLayer != UNDEFINED_LAYER && !c->layerTest.test( aLayer ) )
1025  {
1026  if( implicit )
1027  {
1028  REPORT( "Constraint layer not matched." )
1029  }
1030  else if( c->parentRule )
1031  {
1032  REPORT( wxString::Format( _( "Rule layer '%s' not matched; rule ignored." ),
1033  EscapeHTML( c->parentRule->m_LayerSource ) ) )
1034  }
1035  else
1036  {
1037  REPORT( _( "Rule layer not matched; rule ignored." ) )
1038  }
1039 
1040  return false;
1041  }
1042 
1043  if( !c->condition || c->condition->GetExpression().IsEmpty() )
1044  {
1045  REPORT( implicit ? _( "Unconditional constraint applied." )
1046  : _( "Unconditional rule applied." ) );
1047 
1048  constraint = c->constraint;
1049  return true;
1050  }
1051  else
1052  {
1053  if( implicit )
1054  {
1055  // Don't report on implicit rule conditions; they're synthetic.
1056  }
1057  else
1058  {
1059  REPORT( wxString::Format( _( "Checking rule condition '%s'." ),
1060  EscapeHTML( c->condition->GetExpression() ) ) )
1061  }
1062 
1063  if( c->condition->EvaluateFor( a, b, aLayer, aReporter ) )
1064  {
1065  REPORT( implicit ? _( "Constraint applied." )
1066  : _( "Rule applied; overrides previous constraints." ) )
1067 
1068  if( c->constraint.m_Value.HasMin() )
1069  constraint.m_Value.SetMin( c->constraint.m_Value.Min() );
1070 
1071  if( c->constraint.m_Value.HasOpt() )
1072  constraint.m_Value.SetOpt( c->constraint.m_Value.Opt() );
1073 
1074  if( c->constraint.m_Value.HasMax() )
1075  constraint .m_Value.SetMax( c->constraint.m_Value.Max() );
1076 
1077  // While the expectation would be to OR the disallow flags, we've already
1078  // masked them down to aItem's type -- so we're really only looking for a
1079  // boolean here.
1080  constraint.m_DisallowFlags = c->constraint.m_DisallowFlags;
1081 
1082  constraint.SetParentRule( c->constraint.GetParentRule() );
1083 
1084  return true;
1085  }
1086  else
1087  {
1088  REPORT( implicit ? _( "Membership not satisfied; constraint ignored." )
1089  : _( "Condition not satisfied; rule ignored." ) )
1090 
1091  return false;
1092  }
1093  }
1094  };
1095 
1096  if( m_constraintMap.count( aConstraintType ) )
1097  {
1098  std::vector<DRC_ENGINE_CONSTRAINT*>* ruleset = m_constraintMap[ aConstraintType ];
1099 
1100  for( int ii = 0; ii < (int) ruleset->size(); ++ii )
1101  processConstraint( ruleset->at( ii ) );
1102  }
1103 
1104  if( constraint.GetParentRule() && !constraint.GetParentRule()->m_Implicit )
1105  return constraint;
1106 
1107  // Unfortunately implicit rules don't work for local clearances (such as zones) because
1108  // they have to be max'ed with netclass values (which are already implicit rules), and our
1109  // rule selection paradigm is "winner takes all".
1110  if( aConstraintType == CLEARANCE_CONSTRAINT )
1111  {
1112  int global = constraint.m_Value.Min();
1113  int localA = ac ? ac->GetLocalClearance( nullptr ) : 0;
1114  int localB = bc ? bc->GetLocalClearance( nullptr ) : 0;
1115  int clearance = global;
1116 
1117  if( localA > 0 )
1118  {
1119  REPORT( "" )
1120  REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ),
1121  EscapeHTML( a->GetSelectMenuText( UNITS ) ),
1122  REPORT_VALUE( localA ) ) )
1123 
1124  if( localA > clearance )
1125  clearance = ac->GetLocalClearance( &m_msg );
1126  }
1127 
1128  if( localB > 0 )
1129  {
1130  REPORT( "" )
1131  REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ),
1132  EscapeHTML( b->GetSelectMenuText( UNITS ) ),
1133  REPORT_VALUE( localB ) ) )
1134 
1135  if( localB > clearance )
1136  clearance = bc->GetLocalClearance( &m_msg );
1137  }
1138 
1139  if( localA > global || localB > global )
1140  {
1141  constraint.SetName( m_msg );
1142  constraint.m_Value.SetMin( clearance );
1143  return constraint;
1144  }
1145  }
1146 
1147  if( !constraint.GetParentRule() )
1148  {
1149  constraint.m_Type = NULL_CONSTRAINT;
1150  constraint.m_DisallowFlags = 0;
1151  }
1152 
1153  return constraint;
1154 
1155 #undef REPORT
1156 #undef UNITS
1157 #undef REPORT_VALUE
1158 }
#define UNITS
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:215
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
#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:230
#define _(s)
const SHAPE_POLY_SET & GetPolyCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.h:695
class ZONE, a copper pour area
Definition: typeinfo.h:105
static bool isKeepoutZone(const BOARD_ITEM *aItem, bool aCheckFlags)
Definition: drc_engine.cpp:95
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
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
class ZONE, managed by a footprint
Definition: typeinfo.h:94
wxString m_msg
Definition: drc_engine.h:236
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:881
#define REPORT_VALUE(v)
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:144
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:111
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, ANNULAR_WIDTH_CONSTRAINT, B_CrtYd, 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(), F_CrtYd, Format(), LSET::FrontMask(), EDA_ITEM::GetFlags(), BOARD_ITEM::GetLayerSet(), BOARD_CONNECTED_ITEM::GetLocalClearance(), BOARD_CONNECTED_ITEM::GetLocalClearanceOverrides(), FOOTPRINT::GetPolyCourtyard(), EDA_ITEM::GetSelectMenuText(), HOLE_CLEARANCE_CONSTRAINT, HOLE_PROXY, BOARD_ITEM::IsConnected(), SHAPE_POLY_SET::IsEmpty(), isKeepoutZone(), BOARD_ITEM::IsOnCopperLayer(), m_constraintMap, m_designSettings, BOARD_DESIGN_SETTINGS::m_HoleClearance, BOARD_DESIGN_SETTINGS::m_MinClearance, m_msg, DRC_CONSTRAINT::m_Type, 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, REPORT_VALUE, SILK_CLEARANCE_CONSTRAINT, StringFromValue(), TRACK_WIDTH_CONSTRAINT, EDA_ITEM::Type(), UNDEFINED_LAYER, UNITS, and VIA_DIAMETER_CONSTRAINT.

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::testZonesToZones().

◆ GetBoard()

◆ GetDebugOverlay()

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

Definition at line 104 of file drc_engine.h.

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

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 91 of file drc_engine.h.

91 { return m_designSettings; }
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:215

References m_designSettings.

◆ GetDrawingSheet()

DS_PROXY_VIEW_ITEM* DRC_ENGINE::GetDrawingSheet ( ) const
inline

Definition at line 97 of file drc_engine.h.

97 { return m_drawingSheet; }
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:217

References m_drawingSheet.

Referenced by DRC_TEST_PROVIDER_MISC::testTextVars().

◆ GetProgressReporter()

PROGRESS_REPORTER* DRC_ENGINE::GetProgressReporter ( ) const
inline

Definition at line 123 of file drc_engine.h.

123 { return m_progressReporter; }
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:234

References m_progressReporter.

Referenced by DRC_TEST_PROVIDER_CONNECTIVITY::Run().

◆ GetReportAllTrackErrors()

bool DRC_ENGINE::GetReportAllTrackErrors ( ) const
inline

Definition at line 156 of file drc_engine.h.

156 { return m_reportAllTrackErrors; }
bool m_reportAllTrackErrors
Definition: drc_engine.h:226

References m_reportAllTrackErrors.

Referenced by DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem().

◆ GetSchematicNetlist()

NETLIST* DRC_ENGINE::GetSchematicNetlist ( ) const
inline

Definition at line 94 of file drc_engine.h.

94 { return m_schematicNetlist; }
NETLIST * m_schematicNetlist
Definition: drc_engine.h:218

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 1340 of file drc_engine.cpp.

1341 {
1342  if( aItem->Type() == PCB_PAD_T && !static_cast<PAD*>( aItem )->FlashLayer( aLayer ) )
1343  {
1344  PAD* aPad = static_cast<PAD*>( aItem );
1345 
1346  if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
1347  {
1349 
1350  // Note: drill size represents finish size, which means the actual holes size is the
1351  // plating thickness larger.
1352  auto hole = static_cast<SHAPE_SEGMENT*>( aPad->GetEffectiveHoleShape()->Clone() );
1353  hole->SetWidth( hole->GetWidth() + bds.GetHolePlatingThickness() );
1354  return std::make_shared<SHAPE_SEGMENT>( *hole );
1355  }
1356 
1357  return std::make_shared<SHAPE_NULL>();
1358  }
1359 
1360  return aItem->GetEffectiveShape( aLayer );
1361 }
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:304
class PAD, a pad in a footprint
Definition: typeinfo.h:89
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
Plated through hole pad.
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_segment.h:57
PAD_ATTRIB GetAttribute() const
Definition: pad.h:371
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:167
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
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 157 of file drc_engine.h.

157 { return m_testFootprints; }
bool m_testFootprints
Definition: drc_engine.h:227

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 1373 of file drc_engine.cpp.

1374 {
1375  for( auto prov : m_testProviders )
1376  {
1377  if( name == prov->GetName() )
1378  return prov;
1379  }
1380 
1381  return nullptr;
1382 }
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:222
const char * name
Definition: DXF_plotter.cpp:56

References m_testProviders, and name.

◆ GetTestProviders()

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

Definition at line 168 of file drc_engine.h.

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

References m_testProviders.

◆ HasRulesForConstraintType()

bool DRC_ENGINE::HasRulesForConstraintType ( DRC_CONSTRAINT_T  constraintID)

Definition at line 1227 of file drc_engine.cpp.

1228 {
1229  //drc_dbg(10,"hascorrect id %d size %d\n", ruleID, m_ruleMap[ruleID]->sortedRules.size( ) );
1230  if( m_constraintMap.count( constraintID ) )
1231  return m_constraintMap[ constraintID ]->size() > 0;
1232 
1233  return false;
1234 }
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:230

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)

Initialize the DRC engine.

Exceptions
PARSE_ERRORif the rules file contains errors

Definition at line 626 of file drc_engine.cpp.

627 {
629 
630  for( DRC_TEST_PROVIDER* provider : m_testProviders )
631  {
632  ReportAux( wxString::Format( "Create DRC provider: '%s'", provider->GetName() ) );
633  provider->SetDRCEngine( this );
634  }
635 
636  for( DRC_RULE* rule : m_rules )
637  delete rule;
638 
639  m_rules.clear();
640  m_rulesValid = false;
641 
642  for( std::pair<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> pair : m_constraintMap )
643  {
644  for( DRC_ENGINE_CONSTRAINT* constraint : *pair.second )
645  delete constraint;
646 
647  delete pair.second;
648  }
649 
650  m_constraintMap.clear();
651 
652  m_board->IncrementTimeStamp(); // Clear board-level caches
653 
654  try // attempt to load full set of rules (implicit + user rules)
655  {
657  loadRules( aRulePath );
658  compileRules();
659  }
660  catch( PARSE_ERROR& original_parse_error )
661  {
662  try // try again with just our implicit rules
663  {
665  compileRules();
666  }
667  catch( PARSE_ERROR& )
668  {
669  wxFAIL_MSG( "Compiling implicit rules failed." );
670  }
671 
672  throw original_parse_error;
673  }
674 
675  for( int ii = DRCE_FIRST; ii < DRCE_LAST; ++ii )
676  m_errorLimits[ ii ] = INT_MAX;
677 
678  m_rulesValid = true;
679 }
void loadRules(const wxFileName &aPath)
Load and parse a rule set from an sexpr text file.
Definition: drc_engine.cpp:530
std::vector< int > m_errorLimits
Definition: drc_engine.h:225
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:222
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
static DRC_TEST_PROVIDER_REGISTRY & Instance()
void compileRules()
Definition: drc_engine.cpp:553
bool m_rulesValid
Definition: drc_engine.h:221
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:220
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:230
void IncrementTimeStamp()
Definition: board.cpp:192
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
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out #DRC_ITEMs and po...
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:216
void loadImplicitRules()
Definition: drc_engine.cpp:137

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(), and BOARD_INSPECTION_TOOL::reportClearance().

◆ IsErrorLimitExceeded()

◆ IsNetADiffPair()

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

Definition at line 1310 of file drc_engine.cpp.

1311 {
1312  wxString refName = aNet->GetNetname();
1313  wxString dummy, coupledNetName;
1314 
1315  if( int polarity = MatchDpSuffix( refName, coupledNetName, dummy ) )
1316  {
1317  NETINFO_ITEM* net = aBoard->FindNet( coupledNetName );
1318 
1319  if( !net )
1320  return false;
1321 
1322  if( polarity > 0 )
1323  {
1324  aNetP = aNet->GetNetCode();
1325  aNetN = net->GetNetCode();
1326  }
1327  else
1328  {
1329  aNetP = net->GetNetCode();
1330  aNetN = aNet->GetNetCode();
1331  }
1332 
1333  return true;
1334  }
1335 
1336  return false;
1337 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1325
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.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
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 1364 of file drc_engine.cpp.

1365 {
1366  if( aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T )
1367  return static_cast<FOOTPRINT*>( aItem->GetParent() )->IsNetTie();
1368 
1369  return false;
1370 }
static bool IsNetTie(BOARD_ITEM *aItem)
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
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 137 of file drc_engine.cpp.

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

Load and parse a rule set from an sexpr text file.

Exceptions
PARSE_ERROR

Definition at line 530 of file drc_engine.cpp.

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

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

Check 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 1260 of file drc_engine.cpp.

1262 {
1263  int rv = 0;
1264  int count = 0;
1265 
1266  for( auto it = aNetName.rbegin(); it != aNetName.rend() && rv == 0; ++it, ++count )
1267  {
1268  int ch = *it;
1269 
1270  if( ( ch >= '0' && ch <= '9' ) || ch == '_' )
1271  {
1272  continue;
1273  }
1274  else if( ch == '+' )
1275  {
1276  aComplementNet = "-";
1277  rv = 1;
1278  }
1279  else if( ch == '-' )
1280  {
1281  aComplementNet = "+";
1282  rv = -1;
1283  }
1284  else if( ch == 'N' )
1285  {
1286  aComplementNet = "P";
1287  rv = -1;
1288  }
1289  else if ( ch == 'P' )
1290  {
1291  aComplementNet = "N";
1292  rv = 1;
1293  }
1294  else
1295  {
1296  break;
1297  }
1298  }
1299 
1300  if( rv != 0 && count >= 1 )
1301  {
1302  aBaseDpName = aNetName.Left( aNetName.Length() - count );
1303  aComplementNet = aBaseDpName + aComplementNet + aNetName.Right( count - 1 );
1304  }
1305 
1306  return rv;
1307 }

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

◆ QueryWorstConstraint()

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

Definition at line 1237 of file drc_engine.cpp.

1238 {
1239  int worst = 0;
1240 
1241  if( m_constraintMap.count( aConstraintId ) )
1242  {
1243  for( DRC_ENGINE_CONSTRAINT* c : *m_constraintMap[aConstraintId] )
1244  {
1245  int current = c->constraint.GetValue().Min();
1246 
1247  if( current > worst )
1248  {
1249  worst = current;
1250  aConstraint = c->constraint;
1251  }
1252  }
1253  }
1254 
1255  return worst > 0;
1256 }
std::unordered_map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition: drc_engine.h:230

References m_constraintMap.

Referenced by DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::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 1198 of file drc_engine.cpp.

1199 {
1200  if( !m_reporter )
1201  return;
1202 
1204 }
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:233

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 1217 of file drc_engine.cpp.

1218 {
1219  if( !m_progressReporter )
1220  return true;
1221 
1222  m_progressReporter->AdvancePhase( aMessage );
1223  return m_progressReporter->KeepRefreshing( false );
1224 }
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:234
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).

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 1207 of file drc_engine.cpp.

1208 {
1209  if( !m_progressReporter )
1210  return true;
1211 
1212  m_progressReporter->SetCurrentProgress( aProgress );
1213  return m_progressReporter->KeepRefreshing( false );
1214 }
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:234
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).

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,
const wxPoint &  aPos 
)

Definition at line 1168 of file drc_engine.cpp.

1169 {
1170  m_errorLimits[ aItem->GetErrorCode() ] -= 1;
1171 
1172  if( m_violationHandler )
1173  m_violationHandler( aItem, aPos );
1174 
1175  if( m_reporter )
1176  {
1177  wxString msg = wxString::Format( "Test '%s': %s (code %d)",
1178  aItem->GetViolatingTest()->GetName(),
1179  aItem->GetErrorMessage(),
1180  aItem->GetErrorCode() );
1181 
1182  DRC_RULE* rule = aItem->GetViolatingRule();
1183 
1184  if( rule )
1185  msg += wxString::Format( ", violating rule: '%s'", rule->m_Name );
1186 
1187  m_reporter->Report( msg );
1188 
1189  wxString violatingItemsStr = "Violating items: ";
1190 
1191  m_reporter->Report( wxString::Format( " |- violating position (%d, %d)",
1192  aPos.x,
1193  aPos.y ) );
1194  }
1195 }
std::vector< int > m_errorLimits
Definition: drc_engine.h:225
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:233
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:232

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 159 of file drc_engine.h.

159 { return m_rulesValid; }
bool m_rulesValid
Definition: drc_engine.h:221

References m_rulesValid.

◆ RunTests()

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

Run the DRC tests.

Definition at line 682 of file drc_engine.cpp.

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

References _, delta, 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 87 of file drc_engine.h.

87 { m_board = aBoard; }
BOARD * m_board
Definition: drc_engine.h:216

References m_board.

◆ SetDebugOverlay()

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

Definition at line 99 of file drc_engine.h.

100  {
101  m_debugOverlay = aOverlay;
102  }
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Definition: drc_engine.h:237

References m_debugOverlay.

◆ SetDesignSettings()

void DRC_ENGINE::SetDesignSettings ( BOARD_DESIGN_SETTINGS aSettings)
inline

Definition at line 90 of file drc_engine.h.

90 { m_designSettings = aSettings; }
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:215

References m_designSettings.

◆ SetDrawingSheet()

void DRC_ENGINE::SetDrawingSheet ( DS_PROXY_VIEW_ITEM aDrawingSheet)
inline

Definition at line 96 of file drc_engine.h.

96 { m_drawingSheet = aDrawingSheet; }
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition: drc_engine.h:217

References m_drawingSheet.

◆ SetLogReporter()

void DRC_ENGINE::SetLogReporter ( REPORTER aReporter)
inline

Definition at line 132 of file drc_engine.h.

132 { m_reporter = aReporter; }
REPORTER * m_reporter
Definition: drc_engine.h:233

References m_reporter.

◆ SetProgressReporter()

void DRC_ENGINE::SetProgressReporter ( PROGRESS_REPORTER aProgRep)
inline

Set an optional reporter for user-level progress info.

Definition at line 122 of file drc_engine.h.

122 { m_progressReporter = aProgRep; }
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:234

References m_progressReporter.

◆ SetSchematicNetlist()

void DRC_ENGINE::SetSchematicNetlist ( NETLIST aNetlist)
inline

Definition at line 93 of file drc_engine.h.

93 { m_schematicNetlist = aNetlist; }
NETLIST * m_schematicNetlist
Definition: drc_engine.h:218

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 109 of file drc_engine.h.

110  {
111  m_violationHandler = std::move( aHandler );
112  }
DRC_VIOLATION_HANDLER m_violationHandler
Definition: drc_engine.h:232

References m_violationHandler.

◆ UserUnits()

EDA_UNITS DRC_ENGINE::UserUnits ( ) const
inline

Definition at line 155 of file drc_engine.h.

155 { return m_userUnits; }
EDA_UNITS m_userUnits
Definition: drc_engine.h:224

References m_userUnits.

Referenced by DRC_TEST_PROVIDER::userUnits().

Member Data Documentation

◆ m_board

BOARD* DRC_ENGINE::m_board
protected

Definition at line 216 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 237 of file drc_engine.h.

Referenced by GetDebugOverlay(), and SetDebugOverlay().

◆ m_designSettings

BOARD_DESIGN_SETTINGS* DRC_ENGINE::m_designSettings
protected

Definition at line 215 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 217 of file drc_engine.h.

Referenced by GetDrawingSheet(), and SetDrawingSheet().

◆ m_errorLimits

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

Definition at line 225 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 236 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 226 of file drc_engine.h.

Referenced by GetReportAllTrackErrors(), and RunTests().

◆ m_reporter

REPORTER* DRC_ENGINE::m_reporter
protected

Definition at line 233 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 220 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 221 of file drc_engine.h.

Referenced by InitEngine(), and RulesValid().

◆ m_schematicNetlist

NETLIST* DRC_ENGINE::m_schematicNetlist
protected

Definition at line 218 of file drc_engine.h.

Referenced by GetSchematicNetlist(), and SetSchematicNetlist().

◆ m_testFootprints

bool DRC_ENGINE::m_testFootprints
protected

Definition at line 227 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 222 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 224 of file drc_engine.h.

Referenced by RunTests(), and UserUnits().

◆ m_violationHandler

DRC_VIOLATION_HANDLER DRC_ENGINE::m_violationHandler
protected

Definition at line 232 of file drc_engine.h.

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


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