58 virtual bool Run()
override;
60 virtual const wxString
GetName()
const override
62 return wxT(
"annular_width" );
67 return wxT(
"Tests pad/via annular rings" );
76 reportAux( wxT(
"Annular width violations ignored. Skipping check." ) );
80 const int progressDelta = 500;
84 reportAux( wxT(
"No annular width constraints found. Tests not run." ) );
88 if( !
reportPhase(
_(
"Checking pad & via annular rings..." ) ) )
94 switch( item->Type() )
103 if( !
pad->HasHole() ||
pad->GetAttribute() != PAD_ATTRIB::PTH )
108 pad->Padstack().ForEachUniqueLayer(
113 switch(
pad->GetShape( aLayer ) )
115 case PAD_SHAPE::CHAMFERED_RECT:
116 if(
pad->GetChamferRectRatio( aLayer ) > 0.30 )
121 case PAD_SHAPE::CIRCLE:
122 case PAD_SHAPE::OVAL:
123 case PAD_SHAPE::RECTANGLE:
124 case PAD_SHAPE::ROUNDRECT:
144 auto checkPadAnnularWidth =
146 const std::vector<const PAD*>& sameNumPads,
147 int* aMinAnnularWidth,
int* aMaxAnnularWidth )
149 int annularWidth = 0;
150 bool handled =
false;
156 switch(
pad->GetShape( aLayer ) )
158 case PAD_SHAPE::CIRCLE:
159 annularWidth = ( padSize.
x -
pad->GetDrillSizeX() ) / 2;
163 handled = sameNumPads.empty();
167 case PAD_SHAPE::CHAMFERED_RECT:
168 if(
pad->GetChamferRectRatio( aLayer ) > 0.30 )
173 case PAD_SHAPE::OVAL:
174 case PAD_SHAPE::RECTANGLE:
175 case PAD_SHAPE::ROUNDRECT:
176 annularWidth = std::min( padSize.
x -
pad->GetDrillSizeX(),
177 padSize.
y -
pad->GetDrillSizeY() ) / 2;
181 handled = sameNumPads.empty();
193 int maxError =
pad->GetBoard()->GetDesignSettings().m_MaxError;
196 std::shared_ptr<SHAPE_SEGMENT> slot =
pad->GetEffectiveHoleShape();
198 pad->TransformShapeToPolygon( padOutline, aLayer, 0, maxError,
ERROR_INSIDE );
200 if( sameNumPads.empty() )
202 if( !padOutline.
Collide(
pad->GetPosition() ) )
213 annularWidth = sqrt( dist_sq ) - slot->GetWidth() / 2;
216 else if( constraint.Value().HasMin()
217 && ( annularWidth < constraint.Value().Min() ) )
225 for(
const PAD* sameNumPad : sameNumPads )
228 sameNumPad->TransformShapeToPolygon( aggregatePadOutline,
232 sameNumPad->TransformHoleToPolygon( otherPadHoles, 0, maxError,
238 if( !aggregatePadOutline.
Collide(
pad->GetPosition() ) )
246 for(
int ii = 0; ii < aggregatePadOutline.
OutlineCount(); ++ii )
250 annularWidth = sqrt( dist_sq ) - slot->GetWidth() / 2;
255 *aMaxAnnularWidth = std::max( *aMaxAnnularWidth, annularWidth );
256 *aMinAnnularWidth = std::min( *aMinAnnularWidth, annularWidth );
259 auto checkAnnularWidth =
268 int minAnnularWidth = INT_MAX;
269 int maxAnnularWidth = 0;
272 bool fail_min =
false;
273 bool fail_max =
false;
275 switch( item->Type() )
280 int drill =
via->GetDrillValue();
282 via->Padstack().ForEachUniqueLayer(
285 int layerWidth = (
via->GetWidth( aLayer ) - drill ) / 2;
286 minAnnularWidth = std::min( minAnnularWidth, layerWidth );
287 maxAnnularWidth = std::max( maxAnnularWidth, layerWidth );
296 if( !
pad->HasHole() ||
pad->GetAttribute() != PAD_ATTRIB::PTH )
299 std::vector<const PAD*> sameNumPads;
302 sameNumPads = fp->GetPads(
pad->GetNumber(),
pad );
304 pad->Padstack().ForEachUniqueLayer(
307 checkPadAnnularWidth(
pad, aLayer, constraint, sameNumPads,
308 &minAnnularWidth, &maxAnnularWidth );
321 if( constraint.Value().HasMin() )
323 v_min = constraint.Value().Min();
324 fail_min = minAnnularWidth < v_min;
327 if( constraint.Value().HasMax() )
329 v_max = constraint.Value().Max();
330 fail_max = maxAnnularWidth > v_max;
333 if( fail_min || fail_max )
340 msg =
formatMsg(
_(
"(%s min annular width %s; actual %s)" ),
341 constraint.GetName(),
348 msg =
formatMsg(
_(
"(%s max annular width %s; actual %s)" ),
349 constraint.GetName(),
354 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg );
355 drcItem->SetItems( item );
356 drcItem->SetViolatingRule( constraint.GetParentRule() );
369 total += calcEffort( item );
373 for(
PAD*
pad : footprint->Pads() )
374 total += calcEffort(
pad );
379 ii += calcEffort( item );
384 if( !checkAnnularWidth( item ) )
390 for(
PAD*
pad : footprint->Pads() )
392 ii += calcEffort(
pad );
397 if( !checkAnnularWidth(
pad ) )
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
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)
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
DRC_TEST_PROVIDER_ANNULAR_WIDTH()
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual ~DRC_TEST_PROVIDER_ANNULAR_WIDTH()
virtual const wxString GetDescription() const override
virtual const wxString GetName() const override
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual)
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, DRC_CUSTOM_MARKER_HANDLER *aCustomHandler=nullptr)
void reportAux(const wxString &aMsg)
virtual void reportRuleStatistics()
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
VECTOR2I::extended_type ecoord
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
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,...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SEG::ecoord SquaredDistanceToSeg(const SEG &aSegment, VECTOR2I *aNearest=nullptr) const
Compute the minimum distance squared between aSegment and all the polygons in the set.
int OutlineCount() const
Return the number of outlines in the set.
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
Fills a SHAPE_POLY_SET with a polygon representation of this shape.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
@ ANNULAR_WIDTH_CONSTRAINT
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_PAD_T
class PAD, a pad in a footprint
VECTOR2< int32_t > VECTOR2I