KiCad PCB EDA Suite
test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING Class Reference
Inheritance diagram for test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING:
DRC_TEST_PROVIDER

Public Member Functions

 DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING ()
 
virtual ~DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING ()
 
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
 
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 Attributes

BOARDm_board
 

Detailed Description

Definition at line 52 of file drc_test_provider_diff_pair_coupling.cpp.

Constructor & Destructor Documentation

◆ DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING()

test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING ( )
inline

Definition at line 55 of file drc_test_provider_diff_pair_coupling.cpp.

◆ ~DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING()

virtual test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::~DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING ( )
inlinevirtual

Definition at line 60 of file drc_test_provider_diff_pair_coupling.cpp.

61  {
62  }

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

◆ 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(), Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), and DRC_TEST_PROVIDER_MISC::testTextVars().

◆ GetConstraintTypes()

std::set< DRC_CONSTRAINT_T > test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::GetConstraintTypes ( ) const
overridevirtual

◆ GetDescription()

virtual const wxString test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::GetDescription ( ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 71 of file drc_test_provider_diff_pair_coupling.cpp.

72  {
73  return "Tests differential pair coupling";
74  }

◆ GetName()

virtual const wxString test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::GetName ( void  ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 66 of file drc_test_provider_diff_pair_coupling.cpp.

67  {
68  return "diff_pair_coupling";
69  };

◆ GetNumPhases()

virtual int test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::GetNumPhases ( ) const
inlineoverridevirtual

Implements DRC_TEST_PROVIDER.

Definition at line 76 of file drc_test_provider_diff_pair_coupling.cpp.

77  {
78  return 1;
79  }

◆ 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(), Run(), and DRC_TEST_PROVIDER_MATCHED_LENGTH::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 DRC_TEST_PROVIDER_MATCHED_LENGTH::checkLengthViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkewViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), DRC_TEST_PROVIDER_MATCHED_LENGTH::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(), 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 test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run ( )
overridevirtual

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

Implements DRC_TEST_PROVIDER.

Definition at line 273 of file drc_test_provider_diff_pair_coupling.cpp.

274 {
276 
277 
278 
279  std::map<DIFF_PAIR_KEY, DIFF_PAIR_ITEMS> dpRuleMatches;
280 
281  auto evaluateDpConstraints =
282  [&]( BOARD_ITEM *item ) -> bool
283  {
284  DIFF_PAIR_KEY key;
285  BOARD_CONNECTED_ITEM* citem = static_cast<BOARD_CONNECTED_ITEM*>( item );
286  NETINFO_ITEM* refNet = citem->GetNet();
287 
288  if( refNet && DRC_ENGINE::IsNetADiffPair( m_board, refNet, key.netP, key.netN ) )
289  {
290  drc_dbg( 10, "eval dp %p\n", item );
291 
292  const DRC_CONSTRAINT_T constraintsToCheck[] = {
295  };
296 
297  for( int i = 0; i < 2; i++ )
298  {
299  auto constraint = m_drcEngine->EvalRules( constraintsToCheck[ i ], item,
300  nullptr, item->GetLayer() );
301 
302  if( constraint.IsNull() )
303  continue;
304 
305  drc_dbg( 10, "cns %d item %p\n", constraintsToCheck[i], item );
306 
307  key.parentRule = constraint.GetParentRule();
308 
309  if( refNet->GetNetCode() == key.netN )
310  dpRuleMatches[key].itemsN.insert( citem );
311  else
312  dpRuleMatches[key].itemsP.insert( citem );
313  }
314  }
315 
316  return true;
317  };
318 
319  m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board );
320 
322  LSET::AllCuMask(), evaluateDpConstraints );
323 
324  drc_dbg( 10, "dp rule matches %d\n", (int) dpRuleMatches.size() );
325 
326 
327  DRC_RTREE copperTree;
328 
329  auto addToTree =
330  [&copperTree]( BOARD_ITEM *item ) -> bool
331  {
332  copperTree.Insert( item );
333  return true;
334  };
335 
337  LSET::AllCuMask(), addToTree );
338 
339 
340  reportAux( wxString::Format( _("DPs evaluated:") ) );
341 
342  for( auto& it : dpRuleMatches )
343  {
344  NETINFO_ITEM *niP = m_board->GetNetInfo().GetNetItem( it.first.netP );
345  NETINFO_ITEM *niN = m_board->GetNetInfo().GetNetItem( it.first.netN );
346 
347  assert( niP );
348  assert( niN );
349 
350  wxString nameP = niP->GetNetname();
351  wxString nameN = niN->GetNetname();
352 
353  reportAux( wxString::Format( "Rule '%s', DP: (+) %s - (-) %s",
354  it.first.parentRule->m_Name, nameP, nameN ) );
355 
356  extractDiffPairCoupledItems( it.second, copperTree );
357 
358  it.second.totalCoupled = 0;
359  it.second.totalLengthN = 0;
360  it.second.totalLengthP = 0;
361 
362  drc_dbg(10, " coupled prims : %d\n", (int) it.second.coupled.size() );
363 
364  OPT<DRC_CONSTRAINT> gapConstraint =
365  it.first.parentRule->FindConstraint( DIFF_PAIR_GAP_CONSTRAINT );
366  OPT<DRC_CONSTRAINT> maxUncoupledConstraint =
367  it.first.parentRule->FindConstraint( DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT );
368 
369  for( auto& item : it.second.itemsN )
370  {
371  // fixme: include vias
372  if( auto track = dyn_cast<TRACK*>( item ) )
373  it.second.totalLengthN += track->GetLength();
374  }
375 
376  for( auto& item : it.second.itemsP )
377  {
378  // fixme: include vias
379  if( auto track = dyn_cast<TRACK*>( item ) )
380  it.second.totalLengthP += track->GetLength();
381  }
382 
383  for( auto& cpair : it.second.coupled )
384  {
385  int length = cpair.coupledN.Length();
386  int gap = cpair.coupledN.Distance( cpair.coupledP );
387 
388  gap -= cpair.parentN->GetWidth() / 2;
389  gap -= cpair.parentP->GetWidth() / 2;
390 
391  cpair.computedGap = gap;
392 
394 
395  if( overlay )
396  {
397  overlay->SetIsFill(false);
398  overlay->SetIsStroke(true);
399  overlay->SetStrokeColor( RED );
400  overlay->SetLineWidth( 100000 );
401  overlay->Line( cpair.coupledP );
402  overlay->SetStrokeColor( BLUE );
403  overlay->Line( cpair.coupledN );
404  }
405 
406  drc_dbg( 10, " len %d gap %d l %d\n", length, gap,
407  cpair.parentP->GetLayer() );
408 
409  if( gapConstraint )
410  {
411  auto val = gapConstraint->GetValue();
412  bool insideRange = true;
413  if ( val.HasMin() && gap < val.Min() )
414  insideRange = false;
415  if ( val.HasMax() && gap > val.Max() )
416  insideRange = false;
417 
418 // if(val.HasMin() && val.HasMax() )
419  // drc_dbg(10, "Vmin %d vmax %d\n", val.Min(), val.Max() );
420 
421  cpair.couplingOK = insideRange;
422 
423  if( insideRange )
424  it.second.totalCoupled += length;
425  }
426  }
427 
428  int totalLen = std::max( it.second.totalLengthN, it.second.totalLengthP );
429  reportAux( wxString::Format( " - coupled length: %s, total length: %s",
430 
431  MessageTextFromValue( userUnits(), it.second.totalCoupled ),
432  MessageTextFromValue( userUnits(), totalLen ) ) );
433 
434  int totalUncoupled = totalLen - it.second.totalCoupled;
435 
436  bool uncoupledViolation = false;
437 
438  if( maxUncoupledConstraint )
439  {
440  auto val = maxUncoupledConstraint->GetValue();
441 
442  if ( val.HasMax() && totalUncoupled > val.Max() )
443  {
445 
446  m_msg = wxString::Format( _( "(%s maximum uncoupled length: %s; actual: %s)" ),
447  maxUncoupledConstraint->GetParentRule()->m_Name,
448  MessageTextFromValue( userUnits(), val.Max() ),
449  MessageTextFromValue( userUnits(), totalUncoupled ) );
450 
451  drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
452 
453  for( BOARD_CONNECTED_ITEM* offendingTrack : it.second.itemsP )
454  drce->AddItem( offendingTrack );
455 
456  for( BOARD_CONNECTED_ITEM* offendingTrack : it.second.itemsN )
457  drce->AddItem( offendingTrack );
458 
459  uncoupledViolation = true;
460 
461  drce->SetViolatingRule( maxUncoupledConstraint->GetParentRule() );
462 
463  reportViolation( drce, ( *it.second.itemsP.begin() )->GetPosition() );
464  }
465  }
466 
467  if ( gapConstraint && ( uncoupledViolation || !maxUncoupledConstraint ) )
468  {
469  for( auto& cpair : it.second.coupled )
470  {
471  if( !cpair.couplingOK )
472  {
473  auto val = gapConstraint->GetValue();
475 
476  m_msg = drcItem->GetErrorText() + " (" +
477  gapConstraint->GetParentRule()->m_Name + " ";
478 
479  if( val.HasMin() )
480  m_msg += wxString::Format( _( "minimum gap: %s; " ),
481  MessageTextFromValue( userUnits(), val.Min() ) );
482 
483  if( val.HasMax() )
484  m_msg += wxString::Format( _( "maximum gap: %s; " ),
485  MessageTextFromValue( userUnits(), val.Max() ) );
486 
487  m_msg += wxString::Format( _( "actual: %s)" ),
488  MessageTextFromValue( userUnits(), cpair.computedGap ) );
489 
490  drcItem->SetErrorMessage( m_msg );
491 
492  drcItem->AddItem( cpair.parentP );
493  drcItem->AddItem( cpair.parentN );
494 
495  drcItem->SetViolatingRule( gapConstraint->GetParentRule() );
496 
497  reportViolation( drcItem, cpair.parentP->GetPosition() );
498  }
499  }
500  }
501  }
502 
504 
505  return true;
506 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
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:90
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
std::shared_ptr< KIGFX::VIEW_OVERLAY > GetDebugOverlay() const
Definition: drc_engine.h:99
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
static bool IsNetADiffPair(BOARD *aBoard, NETINFO_ITEM *aNet, int &aNetP, int &aNetN)
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
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()
void Insert(BOARD_ITEM *aItem, int aWorstClearance=0, int aLayer=UNDEFINED_LAYER)
Function Insert() Inserts an item into the tree.
Definition: drc_rtree.h:86
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
BOARD * GetBoard() const
Definition: drc_engine.h:87
static void extractDiffPairCoupledItems(DIFF_PAIR_ITEMS &aDp, DRC_RTREE &aTree)
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
class ZONE, a copper pour area
Definition: typeinfo.h:105
EDA_UNITS userUnits() const
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:746
Definition: color4d.h:59
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
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
Handle the data for a net.
Definition: netinfo.h:64
Definition: color4d.h:56
#define _(s)
Definition: 3d_actions.cpp:33
static std::shared_ptr< KIGFX::VIEW_OVERLAY > overlay
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
#define drc_dbg(level, fmt,...)
Definition: drc_engine.h:57
NETINFO_ITEM * GetNetItem(int aNetCode) const
DRC_RTREE - Implements an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:43
virtual void reportAux(wxString fmt,...)
int GetNetCode() const
Definition: netinfo.h:113

References _, LSET::AllCuMask(), BLUE, DRC_ITEM::Create(), DIFF_PAIR_GAP_CONSTRAINT, DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT, drc_dbg, DRCE_DIFF_PAIR_GAP_OUT_OF_RANGE, DRCE_DIFF_PAIR_UNCOUPLED_LENGTH_TOO_LONG, DRC_ENGINE::EvalRules(), extractDiffPairCoupledItems(), DRC_TEST_PROVIDER::forEachGeometryItem(), Format(), DRC_ENGINE::GetBoard(), BOARD::GetConnectivity(), DRC_ENGINE::GetDebugOverlay(), BOARD_CONNECTED_ITEM::GetNet(), NETINFO_ITEM::GetNetCode(), BOARD::GetNetInfo(), NETINFO_LIST::GetNetItem(), NETINFO_ITEM::GetNetname(), DRC_RTREE::Insert(), DRC_ENGINE::IsNetADiffPair(), m_board, DRC_TEST_PROVIDER::m_drcEngine, DRC_TEST_PROVIDER::m_msg, MessageTextFromValue(), DIFF_PAIR_KEY::netN, DIFF_PAIR_KEY::netP, overlay, DIFF_PAIR_KEY::parentRule, PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, RED, DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportRuleStatistics(), DRC_TEST_PROVIDER::reportViolation(), and DRC_TEST_PROVIDER::userUnits().

◆ 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* test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::m_board
private

Definition at line 85 of file drc_test_provider_diff_pair_coupling.cpp.

Referenced by Run().

◆ 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(), Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::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_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: