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
 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
 
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 Attributes

BOARDm_board
 

Detailed Description

Definition at line 53 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 56 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 61 of file drc_test_provider_diff_pair_coupling.cpp.

62  {
63  }

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

◆ 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(), Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::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 72 of file drc_test_provider_diff_pair_coupling.cpp.

73  {
74  return wxT( "Tests differential pair coupling" );
75  }

◆ GetName()

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

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 67 of file drc_test_provider_diff_pair_coupling.cpp.

68  {
69  return wxT( "diff_pair_coupling" );
70  };

◆ GetNumPhases()

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

Implements DRC_TEST_PROVIDER.

Definition at line 77 of file drc_test_provider_diff_pair_coupling.cpp.

78  {
79  return 1;
80  }

◆ 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( wxT( "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( wxT( " - 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(), Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), and DRC_TEST_PROVIDER_MATCHED_LENGTH::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 DRC_TEST_PROVIDER_MATCHED_LENGTH::checkLengths(), DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkews(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), DRC_TEST_PROVIDER_MATCHED_LENGTH::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(), 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 test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run ( )
overridevirtual

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

Implements DRC_TEST_PROVIDER.

Definition at line 276 of file drc_test_provider_diff_pair_coupling.cpp.

277 {
279 
280 
281 
282  std::map<DIFF_PAIR_KEY, DIFF_PAIR_ITEMS> dpRuleMatches;
283 
284  auto evaluateDpConstraints =
285  [&]( BOARD_ITEM *item ) -> bool
286  {
287  DIFF_PAIR_KEY key;
288  BOARD_CONNECTED_ITEM* citem = static_cast<BOARD_CONNECTED_ITEM*>( item );
289  NETINFO_ITEM* refNet = citem->GetNet();
290 
291  if( refNet && DRC_ENGINE::IsNetADiffPair( m_board, refNet, key.netP, key.netN ) )
292  {
293  drc_dbg( 10, wxT( "eval dp %p\n" ), item );
294 
295  const DRC_CONSTRAINT_T constraintsToCheck[] = {
298  };
299 
300  for( int i = 0; i < 2; i++ )
301  {
302  auto constraint = m_drcEngine->EvalRules( constraintsToCheck[ i ], item,
303  nullptr, item->GetLayer() );
304 
305  if( constraint.IsNull() )
306  continue;
307 
308  drc_dbg( 10, wxT( "cns %d item %p\n" ), constraintsToCheck[i], item );
309 
310  key.parentRule = constraint.GetParentRule();
311 
312  if( refNet->GetNetCode() == key.netN )
313  dpRuleMatches[key].itemsN.insert( citem );
314  else
315  dpRuleMatches[key].itemsP.insert( citem );
316  }
317  }
318 
319  return true;
320  };
321 
322  m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board );
323 
325  LSET::AllCuMask(), evaluateDpConstraints );
326 
327  drc_dbg( 10, wxT( "dp rule matches %d\n" ), (int) dpRuleMatches.size() );
328 
329 
330  DRC_RTREE copperTree;
331 
332  auto addToTree =
333  [&copperTree]( BOARD_ITEM *item ) -> bool
334  {
335  for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
336  {
337  if( IsCopperLayer( layer ) )
338  copperTree.Insert( item, layer );
339  }
340 
341  return true;
342  };
343 
345  LSET::AllCuMask(), addToTree );
346 
347 
348  reportAux( wxString::Format( _("DPs evaluated:") ) );
349 
350  for( auto& it : dpRuleMatches )
351  {
352  NETINFO_ITEM *niP = m_board->GetNetInfo().GetNetItem( it.first.netP );
353  NETINFO_ITEM *niN = m_board->GetNetInfo().GetNetItem( it.first.netN );
354 
355  assert( niP );
356  assert( niN );
357 
358  wxString nameP = niP->GetNetname();
359  wxString nameN = niN->GetNetname();
360 
361  reportAux( wxString::Format( wxT( "Rule '%s', DP: (+) %s - (-) %s" ),
362  it.first.parentRule->m_Name,
363  nameP,
364  nameN ) );
365 
366  extractDiffPairCoupledItems( it.second, copperTree );
367 
368  it.second.totalCoupled = 0;
369  it.second.totalLengthN = 0;
370  it.second.totalLengthP = 0;
371 
372  drc_dbg(10, wxT( " coupled prims : %d\n" ), (int) it.second.coupled.size() );
373 
374  OPT<DRC_CONSTRAINT> gapConstraint =
375  it.first.parentRule->FindConstraint( DIFF_PAIR_GAP_CONSTRAINT );
376  OPT<DRC_CONSTRAINT> maxUncoupledConstraint =
377  it.first.parentRule->FindConstraint( DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT );
378 
379  for( BOARD_CONNECTED_ITEM* item : it.second.itemsN )
380  {
381  // fixme: include vias
382  if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
383  it.second.totalLengthN += track->GetLength();
384  }
385 
386  for( BOARD_CONNECTED_ITEM* item : it.second.itemsP )
387  {
388  // fixme: include vias
389  if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
390  it.second.totalLengthP += track->GetLength();
391  }
392 
393  for( auto& cpair : it.second.coupled )
394  {
395  int length = cpair.coupledN.Length();
396  int gap = cpair.coupledN.Distance( cpair.coupledP );
397 
398  gap -= cpair.parentN->GetWidth() / 2;
399  gap -= cpair.parentP->GetWidth() / 2;
400 
401  cpair.computedGap = gap;
402 
404 
405  if( overlay )
406  {
407  overlay->SetIsFill(false);
408  overlay->SetIsStroke(true);
409  overlay->SetStrokeColor( RED );
410  overlay->SetLineWidth( 100000 );
411  overlay->Line( cpair.coupledP );
412  overlay->SetStrokeColor( BLUE );
413  overlay->Line( cpair.coupledN );
414  }
415 
416  drc_dbg( 10, wxT( " len %d gap %d l %d\n" ),
417  length,
418  gap,
419  cpair.parentP->GetLayer() );
420 
421  if( gapConstraint )
422  {
423  auto val = gapConstraint->GetValue();
424  bool insideRange = true;
425 
426  if( val.HasMin() && gap < val.Min() )
427  insideRange = false;
428 
429  if( val.HasMax() && gap > val.Max() )
430  insideRange = false;
431 
432 // if(val.HasMin() && val.HasMax() )
433  // drc_dbg(10, "Vmin %d vmax %d\n", val.Min(), val.Max() );
434 
435  cpair.couplingOK = insideRange;
436  }
437  else
438  {
439  cpair.couplingOK = true;
440  }
441 
442  if( cpair.couplingOK )
443  it.second.totalCoupled += length;
444  }
445 
446  int totalLen = std::max( it.second.totalLengthN, it.second.totalLengthP );
447  reportAux( wxString::Format( wxT( " - coupled length: %s, total length: %s" ),
448  MessageTextFromValue( userUnits(), it.second.totalCoupled ),
449  MessageTextFromValue( userUnits(), totalLen ) ) );
450 
451  int totalUncoupled = totalLen - it.second.totalCoupled;
452 
453  bool uncoupledViolation = false;
454 
455  if( maxUncoupledConstraint )
456  {
457  auto val = maxUncoupledConstraint->GetValue();
458 
459  if ( val.HasMax() && totalUncoupled > val.Max() )
460  {
462 
463  m_msg = wxString::Format( _( "(%s maximum uncoupled length: %s; actual: %s)" ),
464  maxUncoupledConstraint->GetParentRule()->m_Name,
465  MessageTextFromValue( userUnits(), val.Max() ),
466  MessageTextFromValue( userUnits(), totalUncoupled ) );
467 
468  drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
469 
470  auto pit = it.second.itemsP.begin();
471  auto nit = it.second.itemsN.begin();
472 
473  drce->AddItem( *pit );
474  drce->AddItem( *nit );
475 
476  for( pit++; pit != it.second.itemsP.end(); pit++ )
477  drce->AddItem( *pit );
478 
479  for( nit++; nit != it.second.itemsN.end(); nit++ )
480  drce->AddItem( *nit );
481 
482  uncoupledViolation = true;
483 
484  drce->SetViolatingRule( maxUncoupledConstraint->GetParentRule() );
485 
486  reportViolation( drce, ( *it.second.itemsP.begin() )->GetPosition() );
487  }
488  }
489 
490  if ( gapConstraint && ( uncoupledViolation || !maxUncoupledConstraint ) )
491  {
492  for( auto& cpair : it.second.coupled )
493  {
494  if( !cpair.couplingOK )
495  {
496  auto val = gapConstraint->GetValue();
498 
499  m_msg = drcItem->GetErrorText() + wxT( " (" ) +
500  gapConstraint->GetParentRule()->m_Name + wxS( " " );
501 
502  if( val.HasMin() )
503  m_msg += wxString::Format( _( "minimum gap: %s; " ),
504  MessageTextFromValue( userUnits(), val.Min() ) );
505 
506  if( val.HasMax() )
507  m_msg += wxString::Format( _( "maximum gap: %s; " ),
508  MessageTextFromValue( userUnits(), val.Max() ) );
509 
510  m_msg += wxString::Format( _( "actual: %s)" ),
511  MessageTextFromValue( userUnits(), cpair.computedGap ) );
512 
513  drcItem->SetErrorMessage( m_msg );
514 
515  drcItem->AddItem( cpair.parentP );
516  drcItem->AddItem( cpair.parentN );
517 
518  drcItem->SetViolatingRule( gapConstraint->GetParentRule() );
519 
520  reportViolation( drcItem, cpair.parentP->GetPosition() );
521  }
522  }
523  }
524  }
525 
527 
528  return true;
529 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:759
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
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
Definition: playground.cpp:36
std::shared_ptr< KIGFX::VIEW_OVERLAY > GetDebugOverlay() const
Definition: drc_engine.h:104
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
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 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
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual void reportRuleStatistics()
class PCB_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:88
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:345
const wxString & GetNetname() const
Definition: netinfo.h:126
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
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:759
Definition: color4d.h:59
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:808
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)
Handle the data for a net.
Definition: netinfo.h:66
Definition: color4d.h:56
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
DRC_ENGINE * m_drcEngine
void Insert(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, int aWorstClearance=0)
Insert an item into the tree on a particular layer with an optional worst clearance.
Definition: drc_rtree.h:93
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
#define drc_dbg(level, fmt,...)
Definition: drc_engine.h:57
NETINFO_ITEM * GetNetItem(int aNetCode) const
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:46
virtual void reportAux(wxString fmt,...)
int GetNetCode() const
Definition: netinfo.h:120

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(), IsCopperLayer(), 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 86 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_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_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_LVS::Run(), Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::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_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_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_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: