KiCad PCB EDA Suite
DRC_TEST_PROVIDER_COURTYARD_CLEARANCE Class Reference
Inheritance diagram for DRC_TEST_PROVIDER_COURTYARD_CLEARANCE:
DRC_TEST_PROVIDER_CLEARANCE_BASE DRC_TEST_PROVIDER

Public Member Functions

 DRC_TEST_PROVIDER_COURTYARD_CLEARANCE ()
 
virtual ~DRC_TEST_PROVIDER_COURTYARD_CLEARANCE ()
 
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 std::set< DRC_CONSTRAINT_TGetConstraintTypes () const override
 
int GetNumPhases () 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

BOARDm_board
 
int m_largestClearance
 
bool m_boardOutlineValid
 
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 Member Functions

bool testFootprintCourtyardDefinitions ()
 
bool testCourtyardClearances ()
 

Detailed Description

Definition at line 46 of file drc_test_provider_courtyard_clearance.cpp.

Constructor & Destructor Documentation

◆ DRC_TEST_PROVIDER_COURTYARD_CLEARANCE()

DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::DRC_TEST_PROVIDER_COURTYARD_CLEARANCE ( )
inline

Definition at line 49 of file drc_test_provider_courtyard_clearance.cpp.

50  {
51  m_isRuleDriven = false;
52  }

References DRC_TEST_PROVIDER::m_isRuleDriven.

◆ ~DRC_TEST_PROVIDER_COURTYARD_CLEARANCE()

virtual DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::~DRC_TEST_PROVIDER_COURTYARD_CLEARANCE ( )
inlinevirtual

Definition at line 54 of file drc_test_provider_courtyard_clearance.cpp.

55  {
56  }

Member Function Documentation

◆ accountCheck() [1/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_RULE ruleToTest)
protectedvirtualinherited

Definition at line 103 of file drc_test_provider.cpp.

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

References DRC_TEST_PROVIDER::m_stats.

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

◆ accountCheck() [2/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_CONSTRAINT constraintToTest)
protectedvirtualinherited

Definition at line 114 of file drc_test_provider.cpp.

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

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

◆ Enable()

void DRC_TEST_PROVIDER::Enable ( bool  aEnable)
inlineinherited

Definition at line 106 of file drc_test_provider.h.

107  {
108  m_enabled = aEnable;
109  }

References DRC_TEST_PROVIDER::m_enabled.

◆ forEachGeometryItem()

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

Definition at line 139 of file drc_test_provider.cpp.

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

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

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

◆ GetConstraintTypes()

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

◆ GetDescription()

virtual const wxString DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::GetDescription ( ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 65 of file drc_test_provider_courtyard_clearance.cpp.

66  {
67  return "Tests footprints' courtyard clearance";
68  }

◆ GetName()

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

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 60 of file drc_test_provider_courtyard_clearance.cpp.

61  {
62  return "courtyard_clearance";
63  }

◆ GetNumPhases()

int DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::GetNumPhases ( ) const
overridevirtual

Implements DRC_TEST_PROVIDER.

Definition at line 322 of file drc_test_provider_courtyard_clearance.cpp.

323 {
324  return 2;
325 }

◆ IsEnabled()

bool DRC_TEST_PROVIDER::IsEnabled ( ) const
inlineinherited

Definition at line 101 of file drc_test_provider.h.

102  {
103  return m_enabled;
104  }

References DRC_TEST_PROVIDER::m_enabled.

◆ isInvisibleText()

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

Definition at line 327 of file drc_test_provider.cpp.

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

References text.

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

◆ IsRuleDriven()

virtual bool DRC_TEST_PROVIDER::IsRuleDriven ( ) const
inlinevirtualinherited

Definition at line 96 of file drc_test_provider.h.

97  {
98  return m_isRuleDriven;
99  }

References DRC_TEST_PROVIDER::m_isRuleDriven.

◆ reportAux()

◆ reportPhase()

◆ reportProgress()

◆ reportRuleStatistics()

void DRC_TEST_PROVIDER::reportRuleStatistics ( )
protectedvirtualinherited

Definition at line 120 of file drc_test_provider.cpp.

121 {
122  if( !m_isRuleDriven )
123  return;
124 
125  m_drcEngine->ReportAux( "Rule hit statistics: " );
126 
127  for( const std::pair<const DRC_RULE* const, int>& stat : m_stats )
128  {
129  if( stat.first )
130  {
131  m_drcEngine->ReportAux( wxString::Format( " - rule '%s': %d hits ",
132  stat.first->m_Name,
133  stat.second ) );
134  }
135  }
136 }
std::unordered_map< const DRC_RULE *, int > m_stats
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportAux(const wxString &aStr)
DRC_ENGINE * m_drcEngine

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

Referenced by DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_LVS::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), and 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(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), testCourtyardClearances(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_LVS::testFootprints(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_MISC::testOutline(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_MISC::testTextVars(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones().

◆ Run()

bool DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::Run ( )
overridevirtual

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

Implements DRC_TEST_PROVIDER.

Definition at line 302 of file drc_test_provider_courtyard_clearance.cpp.

303 {
305  DRC_CONSTRAINT constraint;
306 
308  m_largestClearance = constraint.GetValue().Min();
309 
310  reportAux( "Worst courtyard clearance : %d nm", m_largestClearance );
311 
313  return false;
314 
315  if( !testCourtyardClearances() )
316  return false;
317 
318  return true;
319 }
T Min() const
Definition: minoptmax.h:33
bool QueryWorstConstraint(DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
BOARD * GetBoard() const
Definition: drc_engine.h:88
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122
DRC_ENGINE * m_drcEngine
virtual void reportAux(wxString fmt,...)

References COURTYARD_CLEARANCE_CONSTRAINT, DRC_ENGINE::GetBoard(), DRC_CONSTRAINT::GetValue(), DRC_TEST_PROVIDER_CLEARANCE_BASE::m_board, DRC_TEST_PROVIDER::m_drcEngine, DRC_TEST_PROVIDER_CLEARANCE_BASE::m_largestClearance, MINOPTMAX< T >::Min(), DRC_ENGINE::QueryWorstConstraint(), DRC_TEST_PROVIDER::reportAux(), testCourtyardClearances(), and testFootprintCourtyardDefinitions().

◆ 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.

◆ testCourtyardClearances()

bool DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances ( )
private

Definition at line 148 of file drc_test_provider_courtyard_clearance.cpp.

149 {
150  const int delta = 100; // This is the number of tests between 2 calls to the progress bar
151 
152  if( !reportPhase( _( "Checking footprints for overlapping courtyards..." ) ) )
153  return false; // DRC cancelled
154 
155  int ii = 0;
156 
157  for( auto itA = m_board->Footprints().begin(); itA != m_board->Footprints().end(); itA++ )
158  {
159  if( !reportProgress( ii++, m_board->Footprints().size(), delta ) )
160  return false; // DRC cancelled
161 
165  {
166  return true; // continue with other tests
167  }
168 
169  FOOTPRINT* fpA = *itA;
170  const SHAPE_POLY_SET& frontA = fpA->GetPolyCourtyard( F_CrtYd );
171  const SHAPE_POLY_SET& backA = fpA->GetPolyCourtyard( B_CrtYd );
172 
173  if( frontA.OutlineCount() == 0 && backA.OutlineCount() == 0
176  {
177  // No courtyards defined and no hole testing against other footprint's courtyards
178  continue;
179  }
180 
181  BOX2I frontBBox = frontA.BBoxFromCaches();
182  BOX2I backBBox = backA.BBoxFromCaches();
183 
184  frontBBox.Inflate( m_largestClearance );
185  backBBox.Inflate( m_largestClearance );
186 
187  EDA_RECT fpABBox = fpA->GetBoundingBox();
188 
189  for( auto itB = itA + 1; itB != m_board->Footprints().end(); itB++ )
190  {
191  FOOTPRINT* fpB = *itB;
192  EDA_RECT fpBBBox = fpB->GetBoundingBox();
193  const SHAPE_POLY_SET& frontB = fpB->GetPolyCourtyard( F_CrtYd );
194  const SHAPE_POLY_SET& backB = fpB->GetPolyCourtyard( B_CrtYd );
195  DRC_CONSTRAINT constraint;
196  int clearance;
197  int actual;
198  VECTOR2I pos;
199 
200  if( frontA.OutlineCount() > 0 && frontB.OutlineCount() > 0
201  && frontBBox.Intersects( frontB.BBoxFromCaches() ) )
202  {
203  constraint = m_drcEngine->EvalRules( COURTYARD_CLEARANCE_CONSTRAINT, fpA, fpB,
204  F_Cu );
205  clearance = constraint.GetValue().Min();
206 
207  if( clearance >= 0 && frontA.Collide( &frontB, clearance, &actual, &pos ) )
208  {
210 
211  if( clearance > 0 )
212  {
213  m_msg.Printf( _( "(%s clearance %s; actual %s)" ),
214  constraint.GetName(),
215  MessageTextFromValue( userUnits(), clearance ),
216  MessageTextFromValue( userUnits(), actual ) );
217 
218  drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
219  drce->SetViolatingRule( constraint.GetParentRule() );
220  }
221 
222  drce->SetItems( fpA, fpB );
223  reportViolation( drce, (wxPoint) pos );
224  }
225  }
226 
227  if( backA.OutlineCount() > 0 && backB.OutlineCount() > 0
228  && backBBox.Intersects( backB.BBoxFromCaches() ) )
229  {
230  constraint = m_drcEngine->EvalRules( COURTYARD_CLEARANCE_CONSTRAINT, fpA, fpB,
231  B_Cu );
232  clearance = constraint.GetValue().Min();
233 
234  if( clearance >= 0 && backA.Collide( &backB, clearance, &actual, &pos ) )
235  {
237 
238  if( clearance > 0 )
239  {
240  m_msg.Printf( _( "(%s clearance %s; actual %s)" ),
241  constraint.GetName(),
242  MessageTextFromValue( userUnits(), clearance ),
243  MessageTextFromValue( userUnits(), actual ) );
244 
245  drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
246  drce->SetViolatingRule( constraint.GetParentRule() );
247  }
248 
249  drce->SetItems( fpA, fpB );
250  reportViolation( drce, (wxPoint) pos );
251  }
252  }
253 
254  auto testPadAgainstCourtyards =
255  [&]( const PAD* pad, const FOOTPRINT* footprint )
256  {
257  int errorCode = 0;
258 
259  if( pad->GetAttribute() == PAD_ATTRIB::PTH )
260  errorCode = DRCE_PTH_IN_COURTYARD;
261  else if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
262  errorCode = DRCE_NPTH_IN_COURTYARD;
263  else
264  return;
265 
266  if( m_drcEngine->IsErrorLimitExceeded( errorCode ) )
267  return;
268 
269  const SHAPE_SEGMENT* hole = pad->GetEffectiveHoleShape();
270  const SHAPE_POLY_SET& front = footprint->GetPolyCourtyard( F_CrtYd );
271  const SHAPE_POLY_SET& back = footprint->GetPolyCourtyard( B_CrtYd );
272 
273  if( ( front.OutlineCount() > 0 && front.Collide( hole, 0 ) )
274  || ( back.OutlineCount() > 0 && back.Collide( hole, 0 ) ) )
275  {
276  std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( errorCode );
277  drce->SetItems( pad, footprint );
278  reportViolation( drce, pad->GetPosition() );
279  }
280  };
281 
282  if( ( frontA.OutlineCount() > 0 && frontA.BBoxFromCaches().Intersects( fpBBBox ) )
283  || ( backA.OutlineCount() > 0 && backA.BBoxFromCaches().Intersects( fpBBBox ) ) )
284  {
285  for( const PAD* padB : fpB->Pads() )
286  testPadAgainstCourtyards( padB, fpA );
287  }
288 
289  if( ( frontB.OutlineCount() > 0 && frontB.BBoxFromCaches().Intersects( fpABBox ) )
290  || ( backB.OutlineCount() > 0 && backB.BBoxFromCaches().Intersects( fpABBox ) ) )
291  {
292  for( const PAD* padA : fpA->Pads() )
293  testPadAgainstCourtyards( padA, fpB );
294  }
295  }
296  }
297 
298  return true;
299 }
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
int OutlineCount() const
Return the number of vertices in a given outline/hole.
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:266
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
const BOX2I BBoxFromCaches() const
bool IsErrorLimitExceeded(int error_code)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
T Min() const
Definition: minoptmax.h:33
wxString GetName() const
Definition: drc_rule.h:130
PADS & Pads()
Definition: footprint.h:169
Plated through hole pad.
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:217
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
like PAD_PTH, but not plated
virtual bool reportPhase(const wxString &aStageName)
Represent a set of closed polygons.
FOOTPRINTS & Footprints()
Definition: board.h:234
#define _(s)
const SHAPE_POLY_SET & GetPolyCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.h:696
EDA_UNITS userUnits() const
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:760
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122
DRC_ENGINE * m_drcEngine
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:736
Definition: layer_ids.h:71
Handle the component boundary box.
Definition: eda_rect.h:42
constexpr int delta
Definition: pad.h:57

References _, B_CrtYd, B_Cu, SHAPE_POLY_SET::BBoxFromCaches(), SHAPE_POLY_SET::Collide(), COURTYARD_CLEARANCE_CONSTRAINT, DRC_ITEM::Create(), delta, DRCE_NPTH_IN_COURTYARD, DRCE_OVERLAPPING_FOOTPRINTS, DRCE_PTH_IN_COURTYARD, DRC_ENGINE::EvalRules(), F_CrtYd, F_Cu, BOARD::Footprints(), FOOTPRINT::GetBoundingBox(), DRC_CONSTRAINT::GetName(), DRC_CONSTRAINT::GetParentRule(), FOOTPRINT::GetPolyCourtyard(), DRC_CONSTRAINT::GetValue(), BOX2< Vec >::Inflate(), BOX2< Vec >::Intersects(), DRC_ENGINE::IsErrorLimitExceeded(), DRC_TEST_PROVIDER_CLEARANCE_BASE::m_board, DRC_TEST_PROVIDER::m_drcEngine, DRC_TEST_PROVIDER_CLEARANCE_BASE::m_largestClearance, DRC_TEST_PROVIDER::m_msg, MessageTextFromValue(), MINOPTMAX< T >::Min(), NPTH, SHAPE_POLY_SET::OutlineCount(), pad, FOOTPRINT::Pads(), PTH, DRC_TEST_PROVIDER::reportPhase(), DRC_TEST_PROVIDER::reportProgress(), DRC_TEST_PROVIDER::reportViolation(), and DRC_TEST_PROVIDER::userUnits().

Referenced by Run().

◆ testFootprintCourtyardDefinitions()

bool DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions ( )
private

Definition at line 81 of file drc_test_provider_courtyard_clearance.cpp.

82 {
83  const int delta = 100; // This is the number of tests between 2 calls to the progress bar
84 
85  // Detects missing (or malformed) footprint courtyards
88  {
89  if( !reportPhase( _( "Checking footprint courtyard definitions..." ) ) )
90  return false; // DRC cancelled
91  }
93  {
94  if( !reportPhase( _( "Gathering footprint courtyards..." ) ) )
95  return false; // DRC cancelled
96  }
97  else
98  {
99  reportAux( "All courtyard violations ignored. Tests not run." );
100  return true; // continue with other tests
101  }
102 
103  int ii = 0;
104 
105  for( FOOTPRINT* footprint : m_board->Footprints() )
106  {
107  if( !reportProgress( ii++, m_board->Footprints().size(), delta ) )
108  return false; // DRC cancelled
109 
110  if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
111  {
113  continue;
114 
115  OUTLINE_ERROR_HANDLER errorHandler =
116  [&]( const wxString& msg, BOARD_ITEM* , BOARD_ITEM* , const wxPoint& pt )
117  {
118  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
119  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
120  drcItem->SetItems( footprint );
121  reportViolation( drcItem, pt );
122  };
123 
124  // Re-run courtyard tests to generate DRC_ITEMs
125  footprint->BuildPolyCourtyards( &errorHandler );
126  }
127  else if( footprint->GetPolyCourtyard( F_CrtYd ).OutlineCount() == 0
128  && footprint->GetPolyCourtyard( B_CrtYd ).OutlineCount() == 0 )
129  {
131  continue;
132 
133  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MISSING_COURTYARD );
134  drcItem->SetItems( footprint );
135  reportViolation( drcItem, footprint->GetPosition() );
136  }
137  else
138  {
139  footprint->GetPolyCourtyard( F_CrtYd ).BuildBBoxCaches();
140  footprint->GetPolyCourtyard( B_CrtYd ).BuildBBoxCaches();
141  }
142  }
143 
144  return true;
145 }
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:266
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)
bool IsErrorLimitExceeded(int error_code)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
virtual bool reportPhase(const wxString &aStageName)
FOOTPRINTS & Footprints()
Definition: board.h:234
#define _(s)
DRC_ENGINE * m_drcEngine
constexpr int delta
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const wxPoint &pt)> OUTLINE_ERROR_HANDLER
#define MALFORMED_COURTYARDS
virtual void reportAux(wxString fmt,...)

References _, B_CrtYd, DRC_ITEM::Create(), delta, DRCE_MALFORMED_COURTYARD, DRCE_MISSING_COURTYARD, DRCE_OVERLAPPING_FOOTPRINTS, F_CrtYd, BOARD::Footprints(), DRC_ENGINE::IsErrorLimitExceeded(), DRC_TEST_PROVIDER_CLEARANCE_BASE::m_board, DRC_TEST_PROVIDER::m_drcEngine, MALFORMED_COURTYARDS, DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportPhase(), DRC_TEST_PROVIDER::reportProgress(), and DRC_TEST_PROVIDER::reportViolation().

Referenced by Run().

◆ userUnits()

Member Data Documentation

◆ m_board

◆ m_boardOutlineValid

bool DRC_TEST_PROVIDER_CLEARANCE_BASE::m_boardOutlineValid
protectedinherited

Definition at line 53 of file drc_test_provider_clearance_base.h.

◆ 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(), Run(), DRC_TEST_PROVIDER_MISC::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_LVS::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DRC_TEST_PROVIDER::SetDRCEngine(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), testCourtyardClearances(), 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_largestClearance

◆ 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: