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
 Runs 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, 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 LENGTH_ENTRY = DRC_LENGTH_REPORT::ENTRY
 
typedef std::set< BOARD_CONNECTED_ITEM * > CITEMS
 
typedef std::vector< LENGTH_ENTRYLENGTH_ENTRIES
 

Private Member Functions

bool runInternal (bool aDelayReportMode=false)
 
void checkLengthViolations (DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
 
void checkSkewViolations (DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
 
void checkViaCountViolations (DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
 

Private Attributes

BOARDm_board
 
DRC_LENGTH_REPORT m_report
 

Detailed Description

Definition at line 44 of file drc_test_provider_matched_length.cpp.

Member Typedef Documentation

◆ CITEMS

◆ LENGTH_ENTRIES

◆ LENGTH_ENTRY

Constructor & Destructor Documentation

◆ DRC_TEST_PROVIDER_MATCHED_LENGTH()

DRC_TEST_PROVIDER_MATCHED_LENGTH::DRC_TEST_PROVIDER_MATCHED_LENGTH ( )
inline

Definition at line 47 of file drc_test_provider_matched_length.cpp.

47  :
48  m_board( nullptr )
49  {
50  }

◆ ~DRC_TEST_PROVIDER_MATCHED_LENGTH()

virtual DRC_TEST_PROVIDER_MATCHED_LENGTH::~DRC_TEST_PROVIDER_MATCHED_LENGTH ( )
inlinevirtual

Definition at line 52 of file drc_test_provider_matched_length.cpp.

53  {
54  }

Member Function Documentation

◆ accountCheck() [1/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_RULE ruleToTest)
protectedvirtualinherited

Definition at line 102 of file drc_test_provider.cpp.

103 {
104  auto it = m_stats.find( ruleToTest );
105 
106  if( it == m_stats.end() )
107  m_stats[ ruleToTest ] = 1;
108  else
109  m_stats[ ruleToTest ] += 1;
110 }
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 113 of file drc_test_provider.cpp.

114 {
115  accountCheck( constraintToTest.GetParentRule() );
116 }
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:125
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

◆ checkLengthViolations()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkLengthViolations ( DRC_CONSTRAINT aConstraint,
LENGTH_ENTRIES aMatchedConnections 
)
private

Definition at line 100 of file drc_test_provider_matched_length.cpp.

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

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

◆ checkSkewViolations()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkewViolations ( DRC_CONSTRAINT aConstraint,
LENGTH_ENTRIES aMatchedConnections 
)
private

Definition at line 152 of file drc_test_provider_matched_length.cpp.

154 {
155  int avgLength = 0;
156 
157  for( const DRC_LENGTH_REPORT::ENTRY& ent : matchedConnections )
158  avgLength += ent.total;
159 
160  avgLength /= matchedConnections.size();
161 
162  for( const auto& ent : matchedConnections )
163  {
164  int skew = ent.total - avgLength;
165  if( aConstraint.GetValue().HasMax() && abs( skew ) > aConstraint.GetValue().Max() )
166  {
167  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_SKEW_OUT_OF_RANGE );
168 
169  m_msg.Printf( _( "(%s max skew: %s; actual: %s; average net length: %s; actual: %s)" ),
170  aConstraint.GetName(),
171  MessageTextFromValue( userUnits(), aConstraint.GetValue().Max() ),
172  MessageTextFromValue( userUnits(), skew ),
173  MessageTextFromValue( userUnits(), avgLength ),
174  MessageTextFromValue( userUnits(), ent.total ) );
175 
176  drcItem->SetErrorMessage( drcItem->GetErrorText() + " " + m_msg );
177 
178  for( BOARD_CONNECTED_ITEM* offendingTrack : ent.items )
179  drcItem->SetItems( offendingTrack );
180 
181  drcItem->SetViolatingRule( aConstraint.GetParentRule() );
182 
183  reportViolation( drcItem, (*ent.items.begin() )->GetPosition() );
184  }
185  }
186 }
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:125
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
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:127
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:125
EDA_UNITS userUnits() const
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
bool HasMax() const
Definition: minoptmax.h:38
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:121
#define _(s)
Definition: 3d_actions.cpp:33

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

◆ checkViaCountViolations()

void DRC_TEST_PROVIDER_MATCHED_LENGTH::checkViaCountViolations ( DRC_CONSTRAINT aConstraint,
LENGTH_ENTRIES aMatchedConnections 
)
private

Definition at line 189 of file drc_test_provider_matched_length.cpp.

191 {
192  for( const auto& ent : matchedConnections )
193  {
194  if( aConstraint.GetValue().HasMax() && ent.viaCount > aConstraint.GetValue().Max() )
195  {
196  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_MANY_VIAS );
197 
198  m_msg.Printf( _( "(%s max count: %d; actual: %d)" ),
199  aConstraint.GetName(),
200  aConstraint.GetValue().Max(),
201  ent.viaCount );
202 
203  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
204 
205  for( auto offendingTrack : ent.items )
206  drcItem->SetItems( offendingTrack );
207 
208  drcItem->SetViolatingRule( aConstraint.GetParentRule() );
209 
210  reportViolation( drcItem, (*ent.items.begin() )->GetPosition() );
211  }
212  }
213 }
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
T Max() const
Definition: minoptmax.h:34
wxString GetName() const
Definition: drc_rule.h:127
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:125
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
bool HasMax() const
Definition: minoptmax.h:38
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:121
#define _(s)
Definition: 3d_actions.cpp:33

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 138 of file drc_test_provider.cpp.

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

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_HOLE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::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 63 of file drc_test_provider_matched_length.cpp.

64  {
65  return "Tests matched track lengths.";
66  }

◆ GetName()

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

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 58 of file drc_test_provider_matched_length.cpp.

59  {
60  return "length";
61  };

◆ GetNumPhases()

virtual int DRC_TEST_PROVIDER_MATCHED_LENGTH::GetNumPhases ( ) const
inlineoverridevirtual

Implements DRC_TEST_PROVIDER.

Definition at line 68 of file drc_test_provider_matched_length.cpp.

69  {
70  return 1;
71  }

◆ 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 326 of file drc_test_provider.cpp.

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

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 119 of file drc_test_provider.cpp.

120 {
121  if( !m_isRuleDriven )
122  return;
123 
124  m_drcEngine->ReportAux( "Rule hit statistics: " );
125 
126  for( const std::pair<const DRC_RULE* const, int>& stat : m_stats )
127  {
128  if( stat.first )
129  {
130  m_drcEngine->ReportAux( wxString::Format( " - rule '%s': %d hits ",
131  stat.first->m_Name,
132  stat.second ) );
133  }
134  }
135 }
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_DISALLOW::Run(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_ANNULUS::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_HOLE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_LVS::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), and runInternal().

◆ reportViolation()

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

Definition at line 56 of file drc_test_provider.cpp.

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

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

Referenced by checkLengthViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), checkSkewViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), checkViaCountViolations(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_ANNULUS::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_CLEARANCE::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::testZones().

◆ Run()

bool DRC_TEST_PROVIDER_MATCHED_LENGTH::Run ( )
overridevirtual

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

Implements DRC_TEST_PROVIDER.

Definition at line 216 of file drc_test_provider_matched_length.cpp.

217 {
218  return runInternal( false );
219 }
bool runInternal(bool aDelayReportMode=false)

References runInternal().

◆ runInternal()

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

Definition at line 222 of file drc_test_provider_matched_length.cpp.

223 {
225  m_report.Clear();
226 
227  if( !aDelayReportMode )
228  {
229  if( !reportPhase( _( "Gathering length-constrained connections..." ) ) )
230  return false;
231  }
232 
233  std::map<DRC_RULE*, CITEMS> itemSets;
234 
235  auto evaluateLengthConstraints =
236  [&]( BOARD_ITEM *item ) -> bool
237  {
238  const DRC_CONSTRAINT_T constraintsToCheck[] = {
242  };
243 
244  for( int i = 0; i < 3; i++ )
245  {
246  auto constraint = m_drcEngine->EvalRules( constraintsToCheck[i], item, nullptr,
247  item->GetLayer() );
248 
249  if( constraint.IsNull() )
250  continue;
251 
252  auto citem = static_cast<BOARD_CONNECTED_ITEM*>( item );
253 
254  itemSets[ constraint.GetParentRule() ].insert( citem );
255  }
256 
257  return true;
258  };
259 
260  auto ftCache = m_board->GetConnectivity()->GetFromToCache();
261 
262  ftCache->Rebuild( m_board );
263 
265  evaluateLengthConstraints );
266 
267  std::map<DRC_RULE*, LENGTH_ENTRIES> matches;
268 
269  for( auto it : itemSets )
270  {
271  std::map<int, CITEMS> netMap;
272 
273  for( auto citem : it.second )
274  netMap[ citem->GetNetCode() ].insert( citem );
275 
276 
277  for( auto nitem : netMap )
278  {
279  LENGTH_ENTRY ent;
280  ent.items = nitem.second;
281  ent.netcode = nitem.first;
282  ent.netname = m_board->GetNetInfo().GetNetItem( ent.netcode )->GetNetname();
283 
284  ent.viaCount = 0;
285  ent.totalRoute = 0;
286  ent.totalVia = 0;
287  ent.totalPadToDie = 0;
288  ent.fromItem = nullptr;
289  ent.toItem = nullptr;
290 
291  for( BOARD_CONNECTED_ITEM* citem : nitem.second )
292  {
293  if( citem->Type() == PCB_VIA_T )
294  {
295  ent.viaCount++;
296  ent.totalVia += computeViaThruLength( static_cast<VIA*>( citem ), nitem.second );
297  }
298  else if( citem->Type() == PCB_TRACE_T )
299  {
300  ent.totalRoute += static_cast<TRACK*>( citem )->GetLength();
301  }
302  else if ( citem->Type() == PCB_ARC_T )
303  {
304  ent.totalRoute += static_cast<ARC*>( citem )->GetLength();
305  }
306  else if( citem->Type() == PCB_PAD_T )
307  {
308  ent.totalPadToDie += static_cast<PAD*>( citem )->GetPadToDieLength();
309  }
310  }
311 
312  ent.total = ent.totalRoute + ent.totalVia + ent.totalPadToDie;
313  ent.matchingRule = it.first;
314 
315  // fixme: doesn't seem to work ;-)
316  auto ftPath = ftCache->QueryFromToPath( ent.items );
317 
318  if( ftPath )
319  {
320  ent.from = ftPath->fromName;
321  ent.to = ftPath->toName;
322  }
323  else
324  {
325  ent.from = ent.to = _("<unconstrained>");
326  }
327 
328  m_report.Add( ent );
329  matches[ it.first ].push_back(ent);
330  }
331  }
332 
333  if( !aDelayReportMode )
334  {
335  for( auto it : matches )
336  {
337  DRC_RULE *rule = it.first;
338  auto& matchedConnections = it.second;
339 
340  std::sort( matchedConnections.begin(), matchedConnections.end(),
341  [] ( const LENGTH_ENTRY&a, const LENGTH_ENTRY&b ) -> int
342  {
343  return a.netname < b.netname;
344  } );
345 
346  reportAux( wxString::Format( "Length-constrained traces for rule '%s':",
347  it.first->m_Name ) );
348 
349  for( auto& ent : matchedConnections )
350  {
351  reportAux(wxString::Format( " - net: %s, from: %s, to: %s, "
352  "%d matching items, "
353  "total: %s (tracks: %s, vias: %s, pad-to-die: %s), "
354  "vias: %d",
355  ent.netname,
356  ent.from,
357  ent.to,
358  (int) ent.items.size(),
359  MessageTextFromValue( userUnits(), ent.total ),
360  MessageTextFromValue( userUnits(), ent.totalRoute ),
361  MessageTextFromValue( userUnits(), ent.totalVia ),
362  MessageTextFromValue( userUnits(), ent.totalPadToDie ),
363  ent.viaCount ) );
364  }
365 
366 
367  OPT<DRC_CONSTRAINT> lengthConstraint = rule->FindConstraint( LENGTH_CONSTRAINT );
368 
369  if( lengthConstraint )
370  checkLengthViolations( *lengthConstraint, matchedConnections );
371 
372  OPT<DRC_CONSTRAINT> skewConstraint = rule->FindConstraint( SKEW_CONSTRAINT );
373 
374  if( skewConstraint )
375  checkSkewViolations( *skewConstraint, matchedConnections );
376 
377  OPT<DRC_CONSTRAINT> viaCountConstraint = rule->FindConstraint( VIA_COUNT_CONSTRAINT );
378 
379  if( viaCountConstraint )
380  checkViaCountViolations( *viaCountConstraint, matchedConnections );
381  }
382 
384  }
385 
386  return true;
387 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
OPT< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition: drc_rule.cpp:52
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:125
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
void checkSkewViolations(DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
void checkViaCountViolations(DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
static int computeViaThruLength(VIA *aVia, const std::set< BOARD_CONNECTED_ITEM * > &conns)
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:754
class PAD, a pad in a footprint
Definition: typeinfo.h:89
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual void reportRuleStatistics()
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
void Add(const ENTRY &ent)
BOARD * GetBoard() const
Definition: drc_engine.h:87
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:416
const wxString & GetNetname() const
Definition: netinfo.h:119
EDA_UNITS userUnits() const
void checkLengthViolations(DRC_CONSTRAINT &aConstraint, LENGTH_ENTRIES &aMatchedConnections)
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintId, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:758
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)
#define _(s)
Definition: 3d_actions.cpp:33
DRC_ENGINE * m_drcEngine
boost::optional< T > OPT
Definition: optional.h:7
class 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:163

References _, DRC_LENGTH_REPORT::Add(), LSET::AllCuMask(), checkLengthViolations(), checkSkewViolations(), checkViaCountViolations(), DRC_LENGTH_REPORT::Clear(), computeViaThruLength(), 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::GetNetInfo(), NETINFO_LIST::GetNetItem(), NETINFO_ITEM::GetNetname(), DRC_LENGTH_REPORT::ENTRY::items, LENGTH_CONSTRAINT, m_board, DRC_TEST_PROVIDER::m_drcEngine, m_report, 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, 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_DISALLOW::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_ANNULUS::Run(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_HOLE_CLEARANCE::Run(), DRC_TEST_PROVIDER_MISC::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_LVS::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::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_CLEARANCE::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::testZones(), 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: