60 int aClearance,
int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
66 int dist = std::numeric_limits<int>::max();
99 int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
103 int tmp = std::numeric_limits<int>::max();
124 for(
int j = 0; j < aLhs.
HoleCount( i ); i++ )
126 if(
collide( aLhs.
CHole( i, j ), aRhs, aClearance, &tmp, &pt1 ) )
159 virtual bool Run()
override;
161 virtual const wxString
GetName()
const override
163 return wxT(
"annular_width" );
168 return wxT(
"Tests pad/via annular rings" );
177 reportAux( wxT(
"Annular width violations ignored. Skipping check." ) );
181 const int progressDelta = 500;
185 reportAux( wxT(
"No annular width constraints found. Tests not run." ) );
189 if( !
reportPhase(
_(
"Checking pad & via annular rings..." ) ) )
197 switch( item->Type() )
206 if( !
pad->HasHole() ||
pad->GetAttribute() != PAD_ATTRIB::PTH )
211 pad->Padstack().ForEachUniqueLayer(
216 switch(
pad->GetShape( aLayer ) )
218 case PAD_SHAPE::CHAMFERED_RECT:
219 if(
pad->GetChamferRectRatio( aLayer ) > 0.30 )
224 case PAD_SHAPE::CIRCLE:
225 case PAD_SHAPE::OVAL:
226 case PAD_SHAPE::RECTANGLE:
227 case PAD_SHAPE::ROUNDRECT:
247 auto checkAnnularWidth =
256 int minAnnularWidth = INT_MAX;
257 int maxAnnularWidth = 0;
260 bool fail_min =
false;
261 bool fail_max =
false;
264 switch( item->Type() )
269 int drill =
via->GetDrillValue();
271 via->Padstack().ForEachUniqueLayer(
274 int layerWidth = (
via->GetWidth( aLayer ) - drill ) / 2;
275 minAnnularWidth = std::min( minAnnularWidth, layerWidth );
276 maxAnnularWidth = std::max( maxAnnularWidth, layerWidth );
284 bool handled =
false;
286 if( !
pad->HasHole() ||
pad->GetAttribute() != PAD_ATTRIB::PTH )
289 std::vector<const PAD*> sameNumPads;
296 pad->Padstack().ForEachUniqueLayer(
299 int annularWidth = 0;
305 switch(
pad->GetShape( aLayer ) )
307 case PAD_SHAPE::CIRCLE:
308 annularWidth = ( padSize.
x -
pad->GetDrillSizeX() ) / 2;
312 if( sameNumPads.empty() )
317 case PAD_SHAPE::CHAMFERED_RECT:
318 if(
pad->GetChamferRectRatio( aLayer ) > 0.30 )
323 case PAD_SHAPE::OVAL:
324 case PAD_SHAPE::RECTANGLE:
325 case PAD_SHAPE::ROUNDRECT:
326 annularWidth = std::min( padSize.
x -
pad->GetDrillSizeX(),
327 padSize.
y -
pad->GetDrillSizeY() ) / 2;
331 if( sameNumPads.empty() )
346 std::shared_ptr<SHAPE_SEGMENT> slot =
pad->GetEffectiveHoleShape();
348 pad->TransformShapeToPolygon( padOutline, aLayer, 0, maxError,
351 if( sameNumPads.empty() )
353 if( !padOutline.
Collide(
pad->GetPosition() ) )
364 annularWidth = sqrt( dist_sq ) - slot->GetWidth() / 2;
367 else if( constraint.Value().HasMin()
368 && ( minAnnularWidth < constraint.Value().Min() ) )
375 for(
const PAD* sameNumPad : sameNumPads )
378 sameNumPad->TransformShapeToPolygon(
382 sameNumPad->TransformHoleToPolygon(
388 bool intersects =
false;
401 j < otherPadOutline.
HoleCount( i ) && !intersects;
405 otherPadOutline.
CHole( i, j ) );
417 int effectiveWidth = std::numeric_limits<int>::max();
420 effectiveWidth, &effectiveWidth ) )
422 if( effectiveWidth > annularWidth )
423 annularWidth = effectiveWidth;
429 maxAnnularWidth = std::max( maxAnnularWidth, annularWidth );
430 minAnnularWidth = std::min( minAnnularWidth, annularWidth );
443 if( constraint.Value().HasMin() )
445 v_min = constraint.Value().Min();
446 fail_min = minAnnularWidth < v_min;
449 if( constraint.Value().HasMax() )
451 v_max = constraint.Value().Max();
452 fail_max = maxAnnularWidth > v_max;
455 if( fail_min || fail_max )
462 msg =
formatMsg(
_(
"(%s min annular width %s; actual %s)" ),
463 constraint.GetName(),
470 msg =
formatMsg(
_(
"(%s max annular width %s; actual %s)" ),
471 constraint.GetName(),
476 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg );
477 drcItem->SetItems( item );
478 drcItem->SetViolatingRule( constraint.GetParentRule() );
491 total += calcEffort( item );
495 for(
PAD*
pad : footprint->Pads() )
496 total += calcEffort(
pad );
501 ii += calcEffort( item );
506 if( !checkAnnularWidth( item ) )
512 for(
PAD*
pad : footprint->Pads() )
514 ii += calcEffort(
pad );
519 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
BOARD_DESIGN_SETTINGS & GetDesignSettings() 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)
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
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
bool Intersects(const SHAPE_LINE_CHAIN &aChain) const
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
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 HoleCount(int aOutline) const
Returns the number of holes in a given outline.
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.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
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.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
@ ANNULAR_WIDTH_CONSTRAINT
static bool collide(const SHAPE_LINE_CHAIN &aLhs, const SHAPE_LINE_CHAIN &aRhs, int aClearance, int *aDistance=nullptr, VECTOR2I *aPt1=nullptr)
Find the nearest collision point between two shape line chains.
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