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
 
void SetDRCEngine (DRC_ENGINE *engine)
 

Static Public Member Functions

static void Init ()
 

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 VECTOR2I &aMarkerPos, int aMarkerLayer)
 
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
 
bool m_boardOutlineValid
 
DRC_ENGINEm_drcEngine
 
std::unordered_map< const DRC_RULE *, int > m_stats
 
bool m_isRuleDriven = true
 

Static Protected Attributes

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

Private Member Functions

bool testFootprintCourtyardDefinitions ()
 
bool testCourtyardClearances ()
 

Private Attributes

int m_largestCourtyardClearance
 

Detailed Description

Definition at line 43 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

◆ ~DRC_TEST_PROVIDER_COURTYARD_CLEARANCE()

virtual DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::~DRC_TEST_PROVIDER_COURTYARD_CLEARANCE ( )
inlinevirtual

Definition at line 53 of file drc_test_provider_courtyard_clearance.cpp.

54 {
55 }

Member Function Documentation

◆ accountCheck() [1/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_CONSTRAINT constraintToTest)
protectedvirtualinherited

Definition at line 132 of file drc_test_provider.cpp.

133{
134 accountCheck( constraintToTest.GetParentRule() );
135}
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:143
virtual void accountCheck(const DRC_RULE *ruleToTest)

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

◆ accountCheck() [2/2]

void DRC_TEST_PROVIDER::accountCheck ( const DRC_RULE ruleToTest)
protectedvirtualinherited

Definition at line 121 of file drc_test_provider.cpp.

122{
123 auto it = m_stats.find( ruleToTest );
124
125 if( it == m_stats.end() )
126 m_stats[ ruleToTest ] = 1;
127 else
128 m_stats[ ruleToTest ] += 1;
129}
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().

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

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

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_TEXTBOX_T, PCB_FP_ZONE_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, BOARD::Tracks(), and BOARD::Zones().

Referenced by DRC_TEST_PROVIDER_SOLDER_MASK::buildRTrees(), DRC_CACHE_GENERATOR::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_SLIVER_CHECKER::Run(), DRC_TEST_PROVIDER_TEXT_DIMS::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DRC_TEST_PROVIDER_MISC::testAssertions(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), DRC_TEST_PROVIDER_SOLDER_MASK::testMaskBridges(), DRC_TEST_PROVIDER_SOLDER_MASK::testSilkToMaskClearance(), and DRC_TEST_PROVIDER_MISC::testTextVars().

◆ GetDescription()

virtual const wxString DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::GetDescription ( ) const
inlineoverridevirtual

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 64 of file drc_test_provider_courtyard_clearance.cpp.

65 {
66 return wxT( "Tests footprints' courtyard clearance" );
67 }

◆ GetName()

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

Reimplemented from DRC_TEST_PROVIDER.

Definition at line 59 of file drc_test_provider_courtyard_clearance.cpp.

60 {
61 return wxT( "courtyard_clearance" );
62 }

◆ Init()

void DRC_TEST_PROVIDER::Init ( )
staticinherited

Definition at line 52 of file drc_test_provider.cpp.

53{
54 if( s_allBasicItems.size() == 0 )
55 {
56 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
57 {
58 if( i != PCB_FOOTPRINT_T && i != PCB_GROUP_T )
59 {
60 s_allBasicItems.push_back( (KICAD_T) i );
61
62 if( i != PCB_ZONE_T && i != PCB_FP_ZONE_T )
63 s_allBasicItemsButZones.push_back( (KICAD_T) i );
64 }
65 }
66 }
67}
static std::vector< KICAD_T > s_allBasicItemsButZones
static std::vector< KICAD_T > s_allBasicItems
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:117

References MAX_STRUCT_TYPE_ID, PCB_FOOTPRINT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_ZONE_T, DRC_TEST_PROVIDER::s_allBasicItems, and DRC_TEST_PROVIDER::s_allBasicItemsButZones.

Referenced by DRC_ENGINE::RunTests().

◆ isInvisibleText()

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

Definition at line 351 of file drc_test_provider.cpp.

352{
353
354 if( const FP_TEXT* text = dyn_cast<const FP_TEXT*>( aItem ) )
355 {
356 if( !text->IsVisible() )
357 return true;
358 }
359
360 if( const PCB_TEXT* text = dyn_cast<const PCB_TEXT*>( aItem ) )
361 {
362 if( !text->IsVisible() )
363 return true;
364 }
365
366 return false;
367}

References text.

Referenced by DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), and DRC_TEST_PROVIDER_SOLDER_MASK::testSilkToMaskClearance().

◆ reportAux()

◆ reportPhase()

◆ reportProgress()

bool DRC_TEST_PROVIDER::reportProgress ( int  aCount,
int  aSize,
int  aDelta 
)
protectedvirtualinherited

◆ reportRuleStatistics()

void DRC_TEST_PROVIDER::reportRuleStatistics ( )
protectedvirtualinherited

Definition at line 138 of file drc_test_provider.cpp.

139{
140 if( !m_isRuleDriven )
141 return;
142
143 m_drcEngine->ReportAux( wxT( "Rule hit statistics: " ) );
144
145 for( const std::pair<const DRC_RULE* const, int>& stat : m_stats )
146 {
147 if( stat.first )
148 {
149 m_drcEngine->ReportAux( wxString::Format( wxT( " - rule '%s': %d hits " ),
150 stat.first->m_Name,
151 stat.second ) );
152 }
153 }
154}
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

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_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_SCHEMATIC_PARITY::Run(), DRC_TEST_PROVIDER_SOLDER_MASK::Run(), DRC_TEST_PROVIDER_TEXT_DIMS::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), and DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal().

◆ reportViolation()

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

Definition at line 74 of file drc_test_provider.cpp.

76{
77 if( item->GetViolatingRule() )
78 accountCheck( item->GetViolatingRule() );
79
80 item->SetViolatingTest( this );
81 m_drcEngine->ReportViolation( item, aMarkerPos, aMarkerLayer );
82}
void ReportViolation(const std::shared_ptr< DRC_ITEM > &aItem, const VECTOR2I &aPos, int aMarkerLayer)

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::checkPadHole(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkews(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkViaCounts(), DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_FOOTPRINT_CHECKS::Run(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_SLIVER_CHECKER::Run(), DRC_TEST_PROVIDER_TEXT_DIMS::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_MISC::testAssertions(), testCourtyardClearances(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem(), DRC_TEST_PROVIDER_SOLDER_MASK::testItemAgainstItems(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZone(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_SOLDER_MASK::testMaskItemAgainstZones(), DRC_TEST_PROVIDER_SCHEMATIC_PARITY::testNetlist(), DRC_TEST_PROVIDER_MISC::testOutline(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testShapeLineChain(), DRC_TEST_PROVIDER_MISC::testTextVars(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), DRC_TEST_PROVIDER_ZONE_CONNECTIONS::testZoneLayer(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testZoneLayer(), 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 318 of file drc_test_provider_courtyard_clearance.cpp.

319{
321 DRC_CONSTRAINT constraint;
322
325
326 reportAux( wxT( "Worst courtyard clearance : %d nm" ), m_largestCourtyardClearance );
327
329 return false;
330
332 return false;
333
334 return true;
335}
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:139
bool QueryWorstConstraint(DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
T Min() const
Definition: minoptmax.h:33
@ COURTYARD_CLEARANCE_CONSTRAINT
Definition: drc_rule.h:51

References COURTYARD_CLEARANCE_CONSTRAINT, DRC_ENGINE::GetBoard(), DRC_CONSTRAINT::GetValue(), DRC_TEST_PROVIDER_CLEARANCE_BASE::m_board, DRC_TEST_PROVIDER::m_drcEngine, m_largestCourtyardClearance, 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 80 of file drc_test_provider.h.

81 {
82 m_drcEngine = engine;
83 m_stats.clear();
84 }

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

Referenced by EDIT_TOOL::doMoveSelection(), and DRC_ENGINE::RunTests().

◆ testCourtyardClearances()

bool DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances ( )
private

Definition at line 148 of file drc_test_provider_courtyard_clearance.cpp.

149{
150 if( !reportPhase( _( "Checking footprints for overlapping courtyards..." ) ) )
151 return false; // DRC cancelled
152
153 const int progressDelta = 100;
154 int ii = 0;
155
156 for( auto itA = m_board->Footprints().begin(); itA != m_board->Footprints().end(); itA++ )
157 {
158 if( !reportProgress( ii++, m_board->Footprints().size(), progressDelta ) )
159 return false; // DRC cancelled
160
164 {
165 return true; // continue with other tests
166 }
167
168 FOOTPRINT* fpA = *itA;
169 const SHAPE_POLY_SET& frontA = fpA->GetCourtyard( F_CrtYd );
170 const SHAPE_POLY_SET& backA = fpA->GetCourtyard( B_CrtYd );
171
172 if( frontA.OutlineCount() == 0 && backA.OutlineCount() == 0
175 {
176 // No courtyards defined and no hole testing against other footprint's courtyards
177 continue;
178 }
179
180 BOX2I frontBBox = frontA.BBoxFromCaches();
181 BOX2I backBBox = backA.BBoxFromCaches();
182
185
186 EDA_RECT fpABBox = fpA->GetBoundingBox();
187
188 for( auto itB = itA + 1; itB != m_board->Footprints().end(); itB++ )
189 {
190 FOOTPRINT* fpB = *itB;
191 EDA_RECT fpBBBox = fpB->GetBoundingBox();
192 const SHAPE_POLY_SET& frontB = fpB->GetCourtyard( F_CrtYd );
193 const SHAPE_POLY_SET& backB = fpB->GetCourtyard( B_CrtYd );
194 DRC_CONSTRAINT constraint;
195 int clearance;
196 int actual;
197 VECTOR2I pos;
198
199 if( frontA.OutlineCount() > 0 && frontB.OutlineCount() > 0
200 && frontBBox.Intersects( frontB.BBoxFromCaches() ) )
201 {
202 constraint = m_drcEngine->EvalRules( COURTYARD_CLEARANCE_CONSTRAINT, fpA, fpB, F_Cu );
203 clearance = constraint.GetValue().Min();
204
205 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance >= 0 )
206 {
207 if( frontA.Collide( &frontB, clearance, &actual, &pos ) )
208 {
210
211 if( clearance > 0 )
212 {
213 wxString msg;
214 msg.Printf( _( "(%s clearance %s; actual %s)" ),
215 constraint.GetName(),
216 MessageTextFromValue( userUnits(), clearance ),
217 MessageTextFromValue( userUnits(), actual ) );
218
219 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
220 drce->SetViolatingRule( constraint.GetParentRule() );
221 }
222
223 drce->SetItems( fpA, fpB );
224 reportViolation( drce, pos, F_CrtYd );
225 }
226 }
227 }
228
229 if( backA.OutlineCount() > 0 && backB.OutlineCount() > 0
230 && backBBox.Intersects( backB.BBoxFromCaches() ) )
231 {
232 constraint = m_drcEngine->EvalRules( COURTYARD_CLEARANCE_CONSTRAINT, fpA, fpB, B_Cu );
233 clearance = constraint.GetValue().Min();
234
235 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance >= 0 )
236 {
237 if( backA.Collide( &backB, clearance, &actual, &pos ) )
238 {
240
241 if( clearance > 0 )
242 {
243 wxString msg;
244 msg.Printf( _( "(%s clearance %s; actual %s)" ),
245 constraint.GetName(),
246 MessageTextFromValue( userUnits(), clearance ),
247 MessageTextFromValue( userUnits(), actual ) );
248
249 drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
250 drce->SetViolatingRule( constraint.GetParentRule() );
251 }
252
253 drce->SetItems( fpA, fpB );
254 reportViolation( drce, pos, B_CrtYd );
255 }
256 }
257 }
258
259 auto testPadAgainstCourtyards =
260 [&]( const PAD* pad, const FOOTPRINT* fp )
261 {
262 int errorCode = 0;
263
264 if( pad->GetAttribute() == PAD_ATTRIB::PTH )
265 errorCode = DRCE_PTH_IN_COURTYARD;
266 else if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
267 errorCode = DRCE_NPTH_IN_COURTYARD;
268 else
269 return;
270
271 if( m_drcEngine->IsErrorLimitExceeded( errorCode ) )
272 return;
273
274 if( pad->HasHole() )
275 {
276 std::shared_ptr<SHAPE_SEGMENT> hole = pad->GetEffectiveHoleShape();
277 const SHAPE_POLY_SET& front = fp->GetCourtyard( F_CrtYd );
278 const SHAPE_POLY_SET& back = fp->GetCourtyard( B_CrtYd );
279
280 if( front.OutlineCount() > 0 && front.Collide( hole.get(), 0 ) )
281 {
282 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( errorCode );
283 drce->SetItems( pad, fp );
284 reportViolation( drce, pad->GetPosition(), F_CrtYd );
285 }
286 else if( back.OutlineCount() > 0 && back.Collide( hole.get(), 0 ) )
287 {
288 std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( errorCode );
289 drce->SetItems( pad, fp );
290 reportViolation( drce, pad->GetPosition(), B_CrtYd );
291 }
292 }
293 };
294
295 if( ( frontA.OutlineCount() > 0 && frontA.BBoxFromCaches().Intersects( fpBBBox ) )
296 || ( backA.OutlineCount() > 0 && backA.BBoxFromCaches().Intersects( fpBBBox ) ) )
297 {
298 for( const PAD* padB : fpB->Pads() )
299 testPadAgainstCourtyards( padB, fpA );
300 }
301
302 if( ( frontB.OutlineCount() > 0 && frontB.BBoxFromCaches().Intersects( fpABBox ) )
303 || ( backB.OutlineCount() > 0 && backB.BBoxFromCaches().Intersects( fpABBox ) ) )
304 {
305 for( const PAD* padA : fpA->Pads() )
306 testPadAgainstCourtyards( padA, fpB );
307 }
308
309 if( m_drcEngine->IsCancelled() )
310 return false;
311 }
312 }
313
314 return !m_drcEngine->IsCancelled();
315}
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:103
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:217
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281
wxString GetName() const
Definition: drc_rule.h:147
SEVERITY GetSeverity() const
Definition: drc_rule.h:160
bool IsErrorLimitExceeded(int error_code)
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:646
bool IsCancelled() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:325
virtual bool reportPhase(const wxString &aStageName)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
EDA_UNITS userUnits() const
Handle the component boundary box.
Definition: eda_rect.h:44
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:753
PADS & Pads()
Definition: footprint.h:175
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2213
Represent a set of closed polygons.
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,...
int OutlineCount() const
Return the number of vertices in a given outline/hole.
const BOX2I BBoxFromCaches() const
@ DRCE_OVERLAPPING_FOOTPRINTS
Definition: drc_item.h:61
@ DRCE_PTH_IN_COURTYARD
Definition: drc_item.h:65
@ DRCE_NPTH_IN_COURTYARD
Definition: drc_item.h:66
#define _(s)
@ F_CrtYd
Definition: layer_ids.h:117
@ B_Cu
Definition: layer_ids.h:95
@ B_CrtYd
Definition: layer_ids.h:116
@ F_Cu
Definition: layer_ids.h:64
@ NPTH
like PAD_PTH, but not plated
@ PTH
Plated through hole pad.
@ RPT_SEVERITY_IGNORE

References _, B_CrtYd, B_Cu, SHAPE_POLY_SET::BBoxFromCaches(), SHAPE_POLY_SET::Collide(), COURTYARD_CLEARANCE_CONSTRAINT, DRC_ITEM::Create(), DRCE_NPTH_IN_COURTYARD, DRCE_OVERLAPPING_FOOTPRINTS, DRCE_PTH_IN_COURTYARD, DRC_ENGINE::EvalRules(), F_CrtYd, F_Cu, BOARD::Footprints(), FOOTPRINT::GetBoundingBox(), FOOTPRINT::GetCourtyard(), DRC_CONSTRAINT::GetName(), DRC_CONSTRAINT::GetParentRule(), DRC_CONSTRAINT::GetSeverity(), DRC_CONSTRAINT::GetValue(), BOX2< Vec >::Inflate(), BOX2< Vec >::Intersects(), DRC_ENGINE::IsCancelled(), DRC_ENGINE::IsErrorLimitExceeded(), DRC_TEST_PROVIDER_CLEARANCE_BASE::m_board, DRC_TEST_PROVIDER::m_drcEngine, m_largestCourtyardClearance, 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(), RPT_SEVERITY_IGNORE, and DRC_TEST_PROVIDER::userUnits().

Referenced by Run().

◆ testFootprintCourtyardDefinitions()

bool DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions ( )
private

Definition at line 79 of file drc_test_provider_courtyard_clearance.cpp.

80{
81 // Detects missing (or malformed) footprint courtyards
84 {
85 if( !reportPhase( _( "Checking footprint courtyard definitions..." ) ) )
86 return false; // DRC cancelled
87 }
89 {
90 if( !reportPhase( _( "Gathering footprint courtyards..." ) ) )
91 return false; // DRC cancelled
92 }
93 else
94 {
95 reportAux( wxT( "All courtyard violations ignored. Tests not run." ) );
96 return true; // continue with other tests
97 }
98
99 const int progressDelta = 500;
100 int ii = 0;
101
102 for( FOOTPRINT* footprint : m_board->Footprints() )
103 {
104 if( !reportProgress( ii++, m_board->Footprints().size(), progressDelta ) )
105 return false; // DRC cancelled
106
107 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
108 {
110 continue;
111
112 OUTLINE_ERROR_HANDLER errorHandler =
113 [&]( const wxString& msg, BOARD_ITEM*, BOARD_ITEM*, const VECTOR2I& pt )
114 {
115 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
116 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
117 drcItem->SetItems( footprint );
118 reportViolation( drcItem, pt, UNDEFINED_LAYER );
119 };
120
121 // Re-run courtyard tests to generate DRC_ITEMs
122 footprint->BuildCourtyardCaches( &errorHandler );
123 }
124 else if( footprint->GetCourtyard( F_CrtYd ).OutlineCount() == 0
125 && footprint->GetCourtyard( B_CrtYd ).OutlineCount() == 0 )
126 {
128 continue;
129
130 if( footprint->GetAttributes() & FP_ALLOW_MISSING_COURTYARD )
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(), UNDEFINED_LAYER );
136 }
137 else
138 {
139 footprint->GetCourtyard( F_CrtYd ).BuildBBoxCaches();
140 footprint->GetCourtyard( B_CrtYd ).BuildBBoxCaches();
141 }
142 }
143
144 return !m_drcEngine->IsCancelled();
145}
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
@ DRCE_MISSING_COURTYARD
Definition: drc_item.h:62
@ DRCE_MALFORMED_COURTYARD
Definition: drc_item.h:63
#define MALFORMED_COURTYARDS
@ FP_ALLOW_MISSING_COURTYARD
Definition: footprint.h:75
@ UNDEFINED_LAYER
Definition: layer_ids.h:60

References _, B_CrtYd, DRC_ITEM::Create(), DRCE_MALFORMED_COURTYARD, DRCE_MISSING_COURTYARD, DRCE_OVERLAPPING_FOOTPRINTS, F_CrtYd, BOARD::Footprints(), FP_ALLOW_MISSING_COURTYARD, DRC_ENGINE::IsCancelled(), 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(), DRC_TEST_PROVIDER::reportViolation(), and UNDEFINED_LAYER.

Referenced by Run().

◆ userUnits()

Member Data Documentation

◆ m_board

◆ m_boardOutlineValid

bool DRC_TEST_PROVIDER_CLEARANCE_BASE::m_boardOutlineValid
protectedinherited

Definition at line 51 of file drc_test_provider_clearance_base.h.

◆ m_drcEngine

DRC_ENGINE* DRC_TEST_PROVIDER::m_drcEngine
protectedinherited

Definition at line 117 of file drc_test_provider.h.

Referenced by DRC_TEST_PROVIDER_HOLE_SIZE::checkPadHole(), DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole(), DRC_TEST_PROVIDER::forEachGeometryItem(), DRC_TEST_PROVIDER_CONNECTION_WIDTH::layerDesc(), DRC_TEST_PROVIDER_SLIVER_CHECKER::layerDesc(), DRC_TEST_PROVIDER::reportAux(), DRC_TEST_PROVIDER::reportPhase(), DRC_TEST_PROVIDER::reportProgress(), DRC_TEST_PROVIDER::reportRuleStatistics(), DRC_TEST_PROVIDER::reportViolation(), DRC_CACHE_GENERATOR::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_FOOTPRINT_CHECKS::Run(), DRC_TEST_PROVIDER_HOLE_SIZE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), DRC_TEST_PROVIDER_MISC::Run(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run(), DRC_TEST_PROVIDER_SCHEMATIC_PARITY::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_SLIVER_CHECKER::Run(), DRC_TEST_PROVIDER_SOLDER_MASK::Run(), DRC_TEST_PROVIDER_TEXT_DIMS::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE_ON_MOVE::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DRC_TEST_PROVIDER::SetDRCEngine(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_MISC::testAssertions(), testCourtyardClearances(), DRC_TEST_PROVIDER_MISC::testDisabledLayers(), testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem(), DRC_TEST_PROVIDER_SOLDER_MASK::testItemAgainstItems(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZone(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_SOLDER_MASK::testMaskBridges(), DRC_TEST_PROVIDER_SOLDER_MASK::testMaskItemAgainstZones(), DRC_TEST_PROVIDER_SCHEMATIC_PARITY::testNetlist(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances(), DRC_TEST_PROVIDER_SOLDER_MASK::testSilkToMaskClearance(), DRC_TEST_PROVIDER_MISC::testTextVars(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances(), DRC_TEST_PROVIDER_ZONE_CONNECTIONS::testZoneLayer(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testZoneLayer(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones(), and DRC_TEST_PROVIDER::userUnits().

◆ m_isRuleDriven

◆ m_largestCourtyardClearance

int DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::m_largestCourtyardClearance
private

Definition at line 75 of file drc_test_provider_courtyard_clearance.cpp.

Referenced by Run(), and testCourtyardClearances().

◆ m_stats

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

◆ s_allBasicItems

◆ s_allBasicItemsButZones

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

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