KiCad PCB EDA Suite
DRC_TEST_PROVIDER_MATCHED_LENGTH Class Reference
Inheritance diagram for DRC_TEST_PROVIDER_MATCHED_LENGTH:
DRC_TEST_PROVIDER

Public Member Functions

 DRC_TEST_PROVIDER_MATCHED_LENGTH ()
 
virtual ~DRC_TEST_PROVIDER_MATCHED_LENGTH ()
 
virtual bool Run () override
 Run this provider against the given PCB with configured options (if any). More...
 
virtual const wxString GetName () const override
 
virtual const wxString GetDescription () const override
 
virtual int GetNumPhases () const override
 
virtual std::set< DRC_CONSTRAINT_TGetConstraintTypes () const override
 
DRC_LENGTH_REPORT BuildLengthReport () const
 
void SetDRCEngine (DRC_ENGINE *engine)
 
virtual bool IsRuleDriven () const
 
bool IsEnabled () const
 
void Enable (bool aEnable)
 

Protected Member Functions

int forEachGeometryItem (const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
 
virtual void reportAux (wxString fmt,...)
 
virtual void reportViolation (std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
 
virtual bool reportProgress (int aCount, int aSize, int aDelta)
 
virtual bool reportPhase (const wxString &aStageName)
 
virtual void reportRuleStatistics ()
 
virtual void accountCheck (const DRC_RULE *ruleToTest)
 
virtual void accountCheck (const DRC_CONSTRAINT &constraintToTest)
 
bool isInvisibleText (const BOARD_ITEM *aItem) const
 
EDA_UNITS userUnits () const
 

Protected Attributes

DRC_ENGINEm_drcEngine
 
std::unordered_map< const DRC_RULE *, int > m_stats
 
bool m_isRuleDriven = true
 
bool m_enabled = true
 
wxString m_msg
 

Static Protected Attributes

static std::vector< KICAD_Ts_allBasicItems
 
static std::vector< KICAD_Ts_allBasicItemsButZones
 

Private Types

using CONNECTION = DRC_LENGTH_REPORT::ENTRY
 

Private Member Functions

bool runInternal (bool aDelayReportMode=false)
 
void checkLengths (DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
 
void checkSkews (DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
 
void checkViaCounts (DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
 

Private Attributes

BOARDm_board
 
DRC_LENGTH_REPORT m_report
 

Detailed Description

Definition at line 46 of file drc_test_provider_matched_length.cpp.

Member Typedef Documentation

◆ CONNECTION

Constructor & Destructor Documentation

◆ DRC_TEST_PROVIDER_MATCHED_LENGTH()

DRC_TEST_PROVIDER_MATCHED_LENGTH::DRC_TEST_PROVIDER_MATCHED_LENGTH ( )
inline

Definition at line 49 of file drc_test_provider_matched_length.cpp.

49  :
50  m_board( nullptr )
51  {
52  }

◆ ~DRC_TEST_PROVIDER_MATCHED_LENGTH()

virtual DRC_TEST_PROVIDER_MATCHED_LENGTH::~DRC_TEST_PROVIDER_MATCHED_LENGTH ( )
inlinevirtual

Definition at line 54 of file drc_test_provider_matched_length.cpp.

55  {
56  }

Member Function Documentation

◆ accountCheck() [1/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_RULE ruleToTest)
protectedvirtualinherited

Definition at line 103 of file drc_test_provider.cpp.

104 {
105  auto it = m_stats.find( ruleToTest );
106 
107  if( it == m_stats.end() )
108  m_stats[ ruleToTest ] = 1;
109  else
110  m_stats[ ruleToTest ] += 1;
111 }
std::unordered_map< const DRC_RULE *, int > m_stats

References DRC_TEST_PROVIDER::m_stats.

Referenced by DRC_TEST_PROVIDER::accountCheck(), and DRC_TEST_PROVIDER::reportViolation().

◆ accountCheck() [2/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_CONSTRAINT constraintToTest)
protectedvirtualinherited

Definition at line 114 of file drc_test_provider.cpp.

115 {
116  accountCheck( constraintToTest.GetParentRule() );
117 }
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
virtual void accountCheck(const DRC_RULE *ruleToTest)

References DRC_TEST_PROVIDER::accountCheck(), and DRC_CONSTRAINT::GetParentRule().

◆ BuildLengthReport()

DRC_LENGTH_REPORT DRC_TEST_PROVIDER_MATCHED_LENGTH::BuildLengthReport ( ) const

◆ checkLengths()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkLengths ( DRC_CONSTRAINT aConstraint,
std::vector< CONNECTION > &  aMatchedConnections 
)
private

Definition at line 93 of file drc_test_provider_matched_length.cpp.

95 {
96  for( const DRC_LENGTH_REPORT::ENTRY& ent : aMatchedConnections )
97  {
98  bool minViolation = false;
99  bool maxViolation = false;
100  int minLen = 0;
101  int maxLen = 0;
102 
103  if( aConstraint.GetValue().HasMin() && ent.total < aConstraint.GetValue().Min() )
104  {
105  minViolation = true;
106  minLen = aConstraint.GetValue().Min();
107  }
108  else if( aConstraint.GetValue().HasMax() && ent.total > aConstraint.GetValue().Max() )
109  {
110  maxViolation = true;
111  maxLen = aConstraint.GetValue().Max();
112  }
113 
114  if( ( minViolation || maxViolation ) )
115  {
116  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_LENGTH_OUT_OF_RANGE );
117 
118  if( minViolation )
119  {
120  m_msg.Printf( _( "(%s min length: %s; actual: %s)" ),
121  aConstraint.GetName(),
122  MessageTextFromValue( userUnits(), minLen ),
123  MessageTextFromValue( userUnits(), ent.total ) );
124  }
125  else if( maxViolation )
126  {
127  m_msg.Printf( _( "(%s max length: %s; actual: %s)" ),
128  aConstraint.GetName(),
129  MessageTextFromValue( userUnits(), maxLen ),
130  MessageTextFromValue( userUnits(), ent.total ) );
131  }
132 
133  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
134 
135  for( auto offendingTrack : ent.items )
136  drcItem->AddItem( offendingTrack );
137 
138  drcItem->SetViolatingRule( aConstraint.GetParentRule() );
139 
140  reportViolation( drcItem, (*ent.items.begin() )->GetPosition() );
141  }
142  }
143 }
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
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:266
bool HasMin() const
Definition: minoptmax.h:37
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
T Min() const
Definition: minoptmax.h:33
T Max() const
Definition: minoptmax.h:34
wxString GetName() const
Definition: drc_rule.h:130
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
#define _(s)
EDA_UNITS userUnits() const
bool HasMax() const
Definition: minoptmax.h:38
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122

References _, DRC_ITEM::Create(), DRCE_LENGTH_OUT_OF_RANGE, DRC_CONSTRAINT::GetName(), DRC_CONSTRAINT::GetParentRule(), DRC_CONSTRAINT::GetValue(), MINOPTMAX< T >::HasMax(), MINOPTMAX< T >::HasMin(), DRC_TEST_PROVIDER::m_msg, MINOPTMAX< T >::Max(), MessageTextFromValue(), MINOPTMAX< T >::Min(), DRC_TEST_PROVIDER::reportViolation(), and DRC_TEST_PROVIDER::userUnits().

Referenced by runInternal().

◆ checkSkews()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkews ( DRC_CONSTRAINT aConstraint,
std::vector< CONNECTION > &  aMatchedConnections 
)
private

Definition at line 145 of file drc_test_provider_matched_length.cpp.

147 {
148  int avgLength = 0;
149 
150  for( const DRC_LENGTH_REPORT::ENTRY& ent : aMatchedConnections )
151  avgLength += ent.total;
152 
153  avgLength /= aMatchedConnections.size();
154 
155  for( const auto& ent : aMatchedConnections )
156  {
157  int skew = ent.total - avgLength;
158  if( aConstraint.GetValue().HasMax() && abs( skew ) > aConstraint.GetValue().Max() )
159  {
160  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_SKEW_OUT_OF_RANGE );
161 
162  m_msg.Printf( _( "(%s max skew: %s; actual: %s; average net length: %s; actual: %s)" ),
163  aConstraint.GetName(),
164  MessageTextFromValue( userUnits(), aConstraint.GetValue().Max() ),
165  MessageTextFromValue( userUnits(), skew ),
166  MessageTextFromValue( userUnits(), avgLength ),
167  MessageTextFromValue( userUnits(), ent.total ) );
168 
169  drcItem->SetErrorMessage( drcItem->GetErrorText() + " " + m_msg );
170 
171  for( BOARD_CONNECTED_ITEM* offendingTrack : ent.items )
172  drcItem->SetItems( offendingTrack );
173 
174  drcItem->SetViolatingRule( aConstraint.GetParentRule() );
175 
176  reportViolation( drcItem, (*ent.items.begin() )->GetPosition() );
177  }
178  }
179 }
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
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:266
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
T Max() const
Definition: minoptmax.h:34
wxString GetName() const
Definition: drc_rule.h:130
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
#define _(s)
EDA_UNITS userUnits() const
bool HasMax() const
Definition: minoptmax.h:38
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122

References _, DRC_ITEM::Create(), DRCE_SKEW_OUT_OF_RANGE, DRC_CONSTRAINT::GetName(), DRC_CONSTRAINT::GetParentRule(), DRC_CONSTRAINT::GetValue(), MINOPTMAX< T >::HasMax(), DRC_TEST_PROVIDER::m_msg, MINOPTMAX< T >::Max(), MessageTextFromValue(), DRC_TEST_PROVIDER::reportViolation(), and DRC_TEST_PROVIDER::userUnits().

Referenced by runInternal().

◆ checkViaCounts()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkViaCounts ( DRC_CONSTRAINT aConstraint,
std::vector< CONNECTION > &  aMatchedConnections 
)
private

Definition at line 182 of file drc_test_provider_matched_length.cpp.

184 {
185  for( const auto& ent : aMatchedConnections )
186  {
187  if( aConstraint.GetValue().HasMax() && ent.viaCount > aConstraint.GetValue().Max() )
188  {
189  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_MANY_VIAS );
190 
191  m_msg.Printf( _( "(%s max count: %d; actual: %d)" ),
192  aConstraint.GetName(),
193  aConstraint.GetValue().Max(),
194  ent.viaCount );
195 
196  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
197 
198  for( auto offendingTrack : ent.items )
199  drcItem->SetItems( offendingTrack );
200 
201  drcItem->SetViolatingRule( aConstraint.GetParentRule() );
202 
203  reportViolation( drcItem, (*ent.items.begin() )->GetPosition() );
204  }
205  }
206 }
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:266
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
T Max() const
Definition: minoptmax.h:34
wxString GetName() const
Definition: drc_rule.h:130
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
#define _(s)
bool HasMax() const
Definition: minoptmax.h:38
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122

References _, DRC_ITEM::Create(), DRCE_TOO_MANY_VIAS, DRC_CONSTRAINT::GetName(), DRC_CONSTRAINT::GetParentRule(), DRC_CONSTRAINT::GetValue(), MINOPTMAX< T >::HasMax(), DRC_TEST_PROVIDER::m_msg, MINOPTMAX< T >::Max(), and DRC_TEST_PROVIDER::reportViolation().

Referenced by runInternal().

◆ Enable()

void DRC_TEST_PROVIDER::Enable ( bool  aEnable)
inlineinherited

Definition at line 106 of file drc_test_provider.h.

107  {
108  m_enabled = aEnable;
109  }

References DRC_TEST_PROVIDER::m_enabled.

◆ forEachGeometryItem()

int DRC_TEST_PROVIDER::forEachGeometryItem ( const std::vector< KICAD_T > &  aTypes,
LSET  aLayers,
const std::function< bool(BOARD_ITEM *)> &  aFunc 
)
protectedinherited

Definition at line 139 of file drc_test_provider.cpp.

141 {
142  BOARD *brd = m_drcEngine->GetBoard();
143  std::bitset<MAX_STRUCT_TYPE_ID> typeMask;
144  int n = 0;
145 
146  if( s_allBasicItems.size() == 0 )
147  {
148  for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
149  {
150  if( i != PCB_FOOTPRINT_T && i != PCB_GROUP_T )
151  {
152  s_allBasicItems.push_back( (KICAD_T) i );
153 
154  if( i != PCB_ZONE_T && i != PCB_FP_ZONE_T )
155  s_allBasicItemsButZones.push_back( (KICAD_T) i );
156  }
157  }
158  }
159 
160  if( aTypes.size() == 0 )
161  {
162  for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
163  typeMask[ i ] = true;
164  }
165  else
166  {
167  for( KICAD_T aType : aTypes )
168  typeMask[ aType ] = true;
169  }
170 
171  for( PCB_TRACK* item : brd->Tracks() )
172  {
173  if( (item->GetLayerSet() & aLayers).any() )
174  {
175  if( typeMask[ PCB_TRACE_T ] && item->Type() == PCB_TRACE_T )
176  {
177  aFunc( item );
178  n++;
179  }
180  else if( typeMask[ PCB_VIA_T ] && item->Type() == PCB_VIA_T )
181  {
182  aFunc( item );
183  n++;
184  }
185  else if( typeMask[ PCB_ARC_T ] && item->Type() == PCB_ARC_T )
186  {
187  aFunc( item );
188  n++;
189  }
190  }
191  }
192 
193  for( BOARD_ITEM* item : brd->Drawings() )
194  {
195  if( (item->GetLayerSet() & aLayers).any() )
196  {
197  if( typeMask[PCB_DIMENSION_T] && BaseType( item->Type() ) == PCB_DIMENSION_T )
198  {
199  if( !aFunc( item ) )
200  return n;
201 
202  n++;
203  }
204  else if( typeMask[ PCB_SHAPE_T ] && item->Type() == PCB_SHAPE_T )
205  {
206  if( !aFunc( item ) )
207  return n;
208 
209  n++;
210  }
211  else if( typeMask[ PCB_TEXT_T ] && item->Type() == PCB_TEXT_T )
212  {
213  if( !aFunc( item ) )
214  return n;
215 
216  n++;
217  }
218  else if( typeMask[ PCB_TARGET_T ] && item->Type() == PCB_TARGET_T )
219  {
220  if( !aFunc( item ) )
221  return n;
222 
223  n++;
224  }
225  }
226  }
227 
228  if( typeMask[ PCB_ZONE_T ] )
229  {
230  for( ZONE* item : brd->Zones() )
231  {
232  if( ( item->GetLayerSet() & aLayers ).any() )
233  {
234  if( !aFunc( item ) )
235  return n;
236 
237  n++;
238  }
239  }
240  }
241 
242  for( FOOTPRINT* footprint : brd->Footprints() )
243  {
244  if( typeMask[ PCB_FP_TEXT_T ] )
245  {
246  if( ( footprint->Reference().GetLayerSet() & aLayers ).any() )
247  {
248  if( !aFunc( &footprint->Reference() ) )
249  return n;
250 
251  n++;
252  }
253 
254  if( ( footprint->Value().GetLayerSet() & aLayers ).any() )
255  {
256  if( !aFunc( &footprint->Value() ) )
257  return n;
258 
259  n++;
260  }
261  }
262 
263  if( typeMask[ PCB_PAD_T ] )
264  {
265  for( PAD* pad : footprint->Pads() )
266  {
267  // Careful: if a pad has a hole then it pierces all layers
268  if( ( pad->GetDrillSizeX() > 0 && pad->GetDrillSizeY() > 0 )
269  || ( pad->GetLayerSet() & aLayers ).any() )
270  {
271  if( !aFunc( pad ) )
272  return n;
273 
274  n++;
275  }
276  }
277  }
278 
279  for( BOARD_ITEM* dwg : footprint->GraphicalItems() )
280  {
281  if( (dwg->GetLayerSet() & aLayers).any() )
282  {
283  if( typeMask[ PCB_FP_TEXT_T ] && dwg->Type() == PCB_FP_TEXT_T )
284  {
285  if( !aFunc( dwg ) )
286  return n;
287 
288  n++;
289  }
290  else if( typeMask[ PCB_FP_SHAPE_T ] && dwg->Type() == PCB_FP_SHAPE_T )
291  {
292  if( !aFunc( dwg ) )
293  return n;
294 
295  n++;
296  }
297  }
298  }
299 
300  if( typeMask[ PCB_FP_ZONE_T ] )
301  {
302  for( ZONE* zone : footprint->Zones() )
303  {
304  if( (zone->GetLayerSet() & aLayers).any() )
305  {
306  if( !aFunc( zone ) )
307  return n;
308 
309  n++;
310  }
311  }
312  }
313 
314  if( typeMask[ PCB_FOOTPRINT_T ] )
315  {
316  if( !aFunc( footprint ) )
317  return n;
318 
319  n++;
320  }
321  }
322 
323  return n;
324 }
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
ZONES & Zones()
Definition: board.h:240
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:231
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
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD * GetBoard() const
Definition: drc_engine.h:88
FOOTPRINTS & Footprints()
Definition: board.h:234
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:99
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
static std::vector< KICAD_T > s_allBasicItems
static std::vector< KICAD_T > s_allBasicItemsButZones
DRC_ENGINE * m_drcEngine
class ZONE, managed by a footprint
Definition: typeinfo.h:94
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
DRAWINGS & Drawings()
Definition: board.h:237
TRACKS & Tracks()
Definition: board.h:231

References BaseType(), BOARD::Drawings(), BOARD::Footprints(), DRC_ENGINE::GetBoard(), DRC_TEST_PROVIDER::m_drcEngine, MAX_STRUCT_TYPE_ID, pad, PCB_ARC_T, PCB_DIMENSION_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, DRC_TEST_PROVIDER::s_allBasicItems, DRC_TEST_PROVIDER::s_allBasicItemsButZones, BOARD::Tracks(), and BOARD::Zones().

Referenced by DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), runInternal(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), and DRC_TEST_PROVIDER_MISC::testTextVars().

◆ GetConstraintTypes()

std::set< DRC_CONSTRAINT_T > DRC_TEST_PROVIDER_MATCHED_LENGTH::GetConstraintTypes ( ) const
overridevirtual

◆ GetDescription()

virtual const wxString DRC_TEST_PROVIDER_MATCHED_LENGTH::GetDescription ( ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 65 of file drc_test_provider_matched_length.cpp.

66  {
67  return "Tests matched track lengths.";
68  }

◆ GetName()

virtual const wxString DRC_TEST_PROVIDER_MATCHED_LENGTH::GetName ( void  ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 60 of file drc_test_provider_matched_length.cpp.

61  {
62  return "length";
63  };

◆ GetNumPhases()

virtual int DRC_TEST_PROVIDER_MATCHED_LENGTH::GetNumPhases ( ) const
inlineoverridevirtual

Implements DRC_TEST_PROVIDER.

Definition at line 70 of file drc_test_provider_matched_length.cpp.

71  {
72  return 1;
73  }

◆ IsEnabled()

bool DRC_TEST_PROVIDER::IsEnabled ( ) const
inlineinherited

Definition at line 101 of file drc_test_provider.h.

102  {
103  return m_enabled;
104  }

References DRC_TEST_PROVIDER::m_enabled.

◆ isInvisibleText()

bool DRC_TEST_PROVIDER::isInvisibleText ( const BOARD_ITEM aItem) const
protectedinherited

Definition at line 327 of file drc_test_provider.cpp.

328 {
329 
330  if( const FP_TEXT* text = dyn_cast<const FP_TEXT*>( aItem ) )
331  {
332  if( !text->IsVisible() )
333  return true;
334  }
335 
336  if( const PCB_TEXT* text = dyn_cast<const PCB_TEXT*>( aItem ) )
337  {
338  if( !text->IsVisible() )
339  return true;
340  }
341 
342  return false;
343 }

References text.

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

◆ IsRuleDriven()

virtual bool DRC_TEST_PROVIDER::IsRuleDriven ( ) const
inlinevirtualinherited

Definition at line 96 of file drc_test_provider.h.

97  {
98  return m_isRuleDriven;
99  }

References DRC_TEST_PROVIDER::m_isRuleDriven.

◆ reportAux()

◆ reportPhase()

◆ reportProgress()

◆ reportRuleStatistics()

void DRC_TEST_PROVIDER::reportRuleStatistics ( )
protectedvirtualinherited

Definition at line 120 of file drc_test_provider.cpp.

121 {
122  if( !m_isRuleDriven )
123  return;
124 
125  m_drcEngine->ReportAux( "Rule hit statistics: " );
126 
127  for( const std::pair<const DRC_RULE* const, int>& stat : m_stats )
128  {
129  if( stat.first )
130  {
131  m_drcEngine->ReportAux( wxString::Format( " - rule '%s': %d hits ",
132  stat.first->m_Name,
133  stat.second ) );
134  }
135  }
136 }
std::unordered_map< const DRC_RULE *, int > m_stats
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
void ReportAux(const wxString &aStr)
DRC_ENGINE * m_drcEngine

References Format(), DRC_TEST_PROVIDER::m_drcEngine, DRC_TEST_PROVIDER::m_isRuleDriven, DRC_TEST_PROVIDER::m_stats, and DRC_ENGINE::ReportAux().

Referenced by DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_LVS::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), and runInternal().

◆ reportViolation()

void DRC_TEST_PROVIDER::reportViolation ( std::shared_ptr< DRC_ITEM > &  item,
const wxPoint &  aMarkerPos 
)
protectedvirtualinherited

Definition at line 56 of file drc_test_provider.cpp.

58 {
59  if( item->GetViolatingRule() )
60  accountCheck( item->GetViolatingRule() );
61 
62  item->SetViolatingTest( this );
63  m_drcEngine->ReportViolation( item, aMarkerPos );
64 }
virtual void accountCheck(const DRC_RULE *ruleToTest)
DRC_ENGINE * m_drcEngine
void ReportViolation(const std::shared_ptr< DRC_ITEM > &aItem, const wxPoint &aPos)

References DRC_TEST_PROVIDER::accountCheck(), DRC_TEST_PROVIDER::m_drcEngine, and DRC_ENGINE::ReportViolation().

Referenced by checkLengths(), DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), checkSkews(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), checkViaCounts(), 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_CONNECTIVITY::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_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_LVS::testFootprints(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_MISC::testOutline(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_MISC::testTextVars(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones().

◆ Run()

bool DRC_TEST_PROVIDER_MATCHED_LENGTH::Run ( )
overridevirtual

Run this provider against the given PCB with configured options (if any).

Implements DRC_TEST_PROVIDER.

Definition at line 209 of file drc_test_provider_matched_length.cpp.

210 {
211  return runInternal( false );
212 }
bool runInternal(bool aDelayReportMode=false)

References runInternal().

◆ runInternal()

bool DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal ( bool  aDelayReportMode = false)
private

Definition at line 215 of file drc_test_provider_matched_length.cpp.

216 {
218  m_report.Clear();
219 
220  if( !aDelayReportMode )
221  {
222  if( !reportPhase( _( "Gathering length-constrained connections..." ) ) )
223  return false;
224  }
225 
226  std::map<DRC_RULE*, std::set<BOARD_CONNECTED_ITEM*> > itemSets;
227 
228  auto evaluateLengthConstraints =
229  [&]( BOARD_ITEM *item ) -> bool
230  {
231  const DRC_CONSTRAINT_T constraintsToCheck[] = {
235  };
236 
237  for( int i = 0; i < 3; i++ )
238  {
239  auto constraint = m_drcEngine->EvalRules( constraintsToCheck[i], item, nullptr,
240  item->GetLayer() );
241 
242  if( constraint.IsNull() )
243  continue;
244 
245  auto citem = static_cast<BOARD_CONNECTED_ITEM*>( item );
246 
247  itemSets[ constraint.GetParentRule() ].insert( citem );
248  }
249 
250  return true;
251  };
252 
253  auto ftCache = m_board->GetConnectivity()->GetFromToCache();
254 
255  ftCache->Rebuild( m_board );
256 
258  evaluateLengthConstraints );
259 
260  std::map<DRC_RULE*, std::vector<CONNECTION> > matches;
261 
262  for( auto it : itemSets )
263  {
264  std::map<int, std::set<BOARD_CONNECTED_ITEM*> > netMap;
265 
266  for( auto citem : it.second )
267  netMap[ citem->GetNetCode() ].insert( citem );
268 
269 
270  for( auto nitem : netMap )
271  {
272  CONNECTION ent;
273  ent.items = nitem.second;
274  ent.netcode = nitem.first;
275  ent.netname = m_board->GetNetInfo().GetNetItem( ent.netcode )->GetNetname();
276 
277  ent.viaCount = 0;
278  ent.totalRoute = 0;
279  ent.totalVia = 0;
280  ent.totalPadToDie = 0;
281  ent.fromItem = nullptr;
282  ent.toItem = nullptr;
283 
284  for( BOARD_CONNECTED_ITEM* citem : nitem.second )
285  {
286  if( citem->Type() == PCB_VIA_T )
287  {
289 
290  ent.viaCount++;
291 
293  {
294  const PCB_VIA* v = static_cast<PCB_VIA*>( citem );
295 
296  ent.totalVia += ds.GetStackupDescriptor().GetLayerDistance(
297  v->TopLayer(), v->BottomLayer() );
298  }
299  }
300  else if( citem->Type() == PCB_TRACE_T )
301  {
302  ent.totalRoute += static_cast<PCB_TRACK*>( citem )->GetLength();
303  }
304  else if ( citem->Type() == PCB_ARC_T )
305  {
306  ent.totalRoute += static_cast<PCB_ARC*>( citem )->GetLength();
307  }
308  else if( citem->Type() == PCB_PAD_T )
309  {
310  ent.totalPadToDie += static_cast<PAD*>( citem )->GetPadToDieLength();
311  }
312  }
313 
314  ent.total = ent.totalRoute + ent.totalVia + ent.totalPadToDie;
315  ent.matchingRule = it.first;
316 
317  // fixme: doesn't seem to work ;-)
318  auto ftPath = ftCache->QueryFromToPath( ent.items );
319 
320  if( ftPath )
321  {
322  ent.from = ftPath->fromName;
323  ent.to = ftPath->toName;
324  }
325  else
326  {
327  ent.from = ent.to = _("<unconstrained>");
328  }
329 
330  m_report.Add( ent );
331  matches[ it.first ].push_back(ent);
332  }
333  }
334 
335  if( !aDelayReportMode )
336  {
337  for( auto it : matches )
338  {
339  DRC_RULE *rule = it.first;
340  auto& matchedConnections = it.second;
341 
342  std::sort( matchedConnections.begin(), matchedConnections.end(),
343  [] ( const CONNECTION&a, const CONNECTION&b ) -> int
344  {
345  return a.netname < b.netname;
346  } );
347 
348  reportAux( wxString::Format( "Length-constrained traces for rule '%s':",
349  it.first->m_Name ) );
350 
351  for( auto& ent : matchedConnections )
352  {
353  reportAux(wxString::Format( " - net: %s, from: %s, to: %s, "
354  "%d matching items, "
355  "total: %s (tracks: %s, vias: %s, pad-to-die: %s), "
356  "vias: %d",
357  ent.netname,
358  ent.from,
359  ent.to,
360  (int) ent.items.size(),
361  MessageTextFromValue( userUnits(), ent.total ),
362  MessageTextFromValue( userUnits(), ent.totalRoute ),
363  MessageTextFromValue( userUnits(), ent.totalVia ),
364  MessageTextFromValue( userUnits(), ent.totalPadToDie ),
365  ent.viaCount ) );
366  }
367 
368 
369  OPT<DRC_CONSTRAINT> lengthConstraint = rule->FindConstraint( LENGTH_CONSTRAINT );
370 
371  if( lengthConstraint )
372  checkLengths( *lengthConstraint, matchedConnections );
373 
374  OPT<DRC_CONSTRAINT> skewConstraint = rule->FindConstraint( SKEW_CONSTRAINT );
375 
376  if( skewConstraint )
377  checkSkews( *skewConstraint, matchedConnections );
378 
379  OPT<DRC_CONSTRAINT> viaCountConstraint = rule->FindConstraint( VIA_COUNT_CONSTRAINT );
380 
381  if( viaCountConstraint )
382  checkViaCounts( *viaCountConstraint, matchedConnections );
383  }
384 
386  }
387 
388  return true;
389 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:759
OPT< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition: drc_rule.cpp:53
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
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void checkSkews(DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:680
class PAD, a pad in a footprint
Definition: typeinfo.h:89
PCB_LAYER_ID BottomLayer() const
Definition: pcb_track.cpp:462
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
virtual void reportRuleStatistics()
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void checkLengths(DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
void Add(const ENTRY &ent)
BOARD_STACKUP & GetStackupDescriptor()
PCB_LAYER_ID TopLayer() const
Definition: pcb_track.cpp:456
BOARD * GetBoard() const
Definition: drc_engine.h:88
virtual bool reportPhase(const wxString &aStageName)
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:345
const wxString & GetNetname() const
Definition: netinfo.h:126
#define _(s)
void checkViaCounts(DRC_CONSTRAINT &aConstraint, std::vector< CONNECTION > &aMatchedConnections)
EDA_UNITS userUnits() const
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:760
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
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
bool m_UseHeightForLengthCalcs
Enable inclusion of stackup height in track length measurements and length tuning.
std::set< BOARD_CONNECTED_ITEM * > items
DRC_ENGINE * m_drcEngine
boost::optional< T > OPT
Definition: optional.h:7
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
NETINFO_ITEM * GetNetItem(int aNetCode) const
virtual void reportAux(wxString fmt,...)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
Container for design settings for a BOARD object.

References _, DRC_LENGTH_REPORT::Add(), LSET::AllCuMask(), PCB_VIA::BottomLayer(), checkLengths(), checkSkews(), checkViaCounts(), DRC_LENGTH_REPORT::Clear(), DRC_ENGINE::EvalRules(), DRC_RULE::FindConstraint(), DRC_TEST_PROVIDER::forEachGeometryItem(), Format(), DRC_LENGTH_REPORT::ENTRY::from, DRC_LENGTH_REPORT::ENTRY::fromItem, DRC_ENGINE::GetBoard(), BOARD::GetConnectivity(), BOARD::GetDesignSettings(), BOARD_STACKUP::GetLayerDistance(), BOARD::GetNetInfo(), NETINFO_LIST::GetNetItem(), NETINFO_ITEM::GetNetname(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), DRC_LENGTH_REPORT::ENTRY::items, LENGTH_CONSTRAINT, m_board, DRC_TEST_PROVIDER::m_drcEngine, m_report, BOARD_DESIGN_SETTINGS::m_UseHeightForLengthCalcs, DRC_LENGTH_REPORT::ENTRY::matchingRule, MessageTextFromValue(), DRC_LENGTH_REPORT::ENTRY::netcode, DRC_LENGTH_REPORT::ENTRY::netname, PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportPhase(), DRC_TEST_PROVIDER::reportRuleStatistics(), SKEW_CONSTRAINT, DRC_LENGTH_REPORT::ENTRY::to, DRC_LENGTH_REPORT::ENTRY::toItem, PCB_VIA::TopLayer(), DRC_LENGTH_REPORT::ENTRY::total, DRC_LENGTH_REPORT::ENTRY::totalPadToDie, DRC_LENGTH_REPORT::ENTRY::totalRoute, DRC_LENGTH_REPORT::ENTRY::totalVia, EDA_ITEM::Type(), DRC_TEST_PROVIDER::userUnits(), VIA_COUNT_CONSTRAINT, and DRC_LENGTH_REPORT::ENTRY::viaCount.

Referenced by Run().

◆ SetDRCEngine()

void DRC_TEST_PROVIDER::SetDRCEngine ( DRC_ENGINE engine)
inlineinherited

Definition at line 78 of file drc_test_provider.h.

79  {
80  m_drcEngine = engine;
81  m_stats.clear();
82  }
std::unordered_map< const DRC_RULE *, int > m_stats
DRC_ENGINE * m_drcEngine

References DRC_TEST_PROVIDER::m_drcEngine, and DRC_TEST_PROVIDER::m_stats.

◆ userUnits()

Member Data Documentation

◆ m_board

BOARD* DRC_TEST_PROVIDER_MATCHED_LENGTH::m_board
private

Definition at line 89 of file drc_test_provider_matched_length.cpp.

Referenced by runInternal().

◆ m_drcEngine

DRC_ENGINE* DRC_TEST_PROVIDER::m_drcEngine
protectedinherited

Definition at line 131 of file drc_test_provider.h.

Referenced by DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), DRC_TEST_PROVIDER::forEachGeometryItem(), DRC_TEST_PROVIDER_LVS::GetNumPhases(), DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportPhase(), DRC_TEST_PROVIDER::reportProgress(), DRC_TEST_PROVIDER::reportRuleStatistics(), DRC_TEST_PROVIDER::reportViolation(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::Run(), DRC_TEST_PROVIDER_MISC::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_LVS::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), runInternal(), DRC_TEST_PROVIDER::SetDRCEngine(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_LVS::testFootprints(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_MISC::testTextVars(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones(), and DRC_TEST_PROVIDER::userUnits().

◆ m_enabled

bool DRC_TEST_PROVIDER::m_enabled = true
protectedinherited

Definition at line 134 of file drc_test_provider.h.

Referenced by DRC_TEST_PROVIDER::Enable(), and DRC_TEST_PROVIDER::IsEnabled().

◆ m_isRuleDriven

◆ m_msg

◆ m_report

DRC_LENGTH_REPORT DRC_TEST_PROVIDER_MATCHED_LENGTH::m_report
private

Definition at line 90 of file drc_test_provider_matched_length.cpp.

Referenced by runInternal().

◆ m_stats

std::unordered_map<const DRC_RULE*, int> DRC_TEST_PROVIDER::m_stats
protectedinherited

◆ s_allBasicItems

std::vector< KICAD_T > DRC_TEST_PROVIDER::s_allBasicItems
staticprotectedinherited

◆ s_allBasicItemsButZones

std::vector< KICAD_T > DRC_TEST_PROVIDER::s_allBasicItemsButZones
staticprotectedinherited

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