KiCad PCB EDA Suite
drc_test_provider_hole_size.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2004-2022 KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <footprint.h>
26#include <pad.h>
27#include <pcb_track.h>
29#include <drc/drc_engine.h>
30#include <drc/drc_item.h>
31#include <drc/drc_rule.h>
33
34/*
35 Drilled hole size test. scans vias/through-hole pads and checks for min drill sizes
36 Errors generated:
37 - DRCE_DRILL_OUT_OF_RANGE
38 - DRCE_MICROVIA_DRILL_OUT_OF_RANGE
39 - DRCE_PADSTACK
40*/
41
43{
44public:
46 {
47 }
48
50 {
51 }
52
53 virtual bool Run() override;
54
55 virtual const wxString GetName() const override
56 {
57 return wxT( "hole_size" );
58 };
59
60 virtual const wxString GetDescription() const override
61 {
62 return wxT( "Tests sizes of drilled holes (via/pad drills)" );
63 }
64
65private:
66 void checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd );
67 void checkPadHole( PAD* aPad );
68};
69
70
72{
74 {
75 if( !reportPhase( _( "Checking pad holes..." ) ) )
76 return false; // DRC cancelled
77
78 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
79 {
80 for( PAD* pad : footprint->Pads() )
81 {
84 }
85 }
86 }
87
90 {
92 {
93 if( !reportPhase( _( "Checking via holes..." ) ) )
94 return false; // DRC cancelled
95 }
96 else
97 {
98 if( !reportPhase( _( "Checking micro-via holes..." ) ) )
99 return false; // DRC cancelled
100 }
101
102 for( PCB_TRACK* track : m_drcEngine->GetBoard()->Tracks() )
103 {
104 if( track->Type() == PCB_VIA_T )
105 {
108
109 if( exceedMicro && exceedStd )
110 break;
111
112 checkViaHole( static_cast<PCB_VIA*>( track ), exceedMicro, exceedStd );
113 }
114 }
115 }
116
118
119 return !m_drcEngine->IsCancelled();
120}
121
123{
124 int holeMinor = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
125 int holeMajor = std::max( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
126
127 if( holeMinor == 0 )
128 return;
129
130 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, aPad, nullptr,
131 UNDEFINED_LAYER /* holes are not layer-specific */ );
132 bool fail_min = false;
133 bool fail_max = false;
134 int constraintValue;
135
136 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
137 return;
138
139 if( constraint.Value().HasMin() && holeMinor < constraint.Value().Min() )
140 {
141 fail_min = true;
142 constraintValue = constraint.Value().Min();
143 }
144
145 if( constraint.Value().HasMax() && holeMajor > constraint.Value().Max() )
146 {
147 fail_max = true;
148 constraintValue = constraint.Value().Max();
149 }
150
151 if( fail_min || fail_max )
152 {
153 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DRILL_OUT_OF_RANGE );
154 wxString msg;
155
156 if( fail_min )
157 {
158 msg.Printf( _( "(%s min width %s; actual %s)" ),
159 constraint.GetName(),
160 MessageTextFromValue( constraintValue ),
161 MessageTextFromValue( holeMinor ) );
162 }
163 else
164 {
165 msg.Printf( _( "(%s max width %s; actual %s)" ),
166 constraint.GetName(),
167 MessageTextFromValue( constraintValue ),
168 MessageTextFromValue( holeMajor ) );
169 }
170
171 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
172 drcItem->SetItems( aPad );
173 drcItem->SetViolatingRule( constraint.GetParentRule() );
174
175 reportViolation( drcItem, aPad->GetPosition(), UNDEFINED_LAYER );
176 }
177}
178
179
180void DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd )
181{
182 int errorCode;
183
184 if( via->GetViaType() == VIATYPE::MICROVIA )
185 {
186 if( aExceedMicro )
187 return;
188
190 }
191 else
192 {
193 if( aExceedStd )
194 return;
195
196 errorCode = DRCE_DRILL_OUT_OF_RANGE;
197 }
198
199 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, via, nullptr,
200 UNDEFINED_LAYER /* holes are not layer-specific */ );
201 bool fail_min = false;
202 bool fail_max = false;
203 int constraintValue;
204
205 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
206 return;
207
208 if( constraint.Value().HasMin() && via->GetDrillValue() < constraint.Value().Min() )
209 {
210 fail_min = true;
211 constraintValue = constraint.Value().Min();
212 }
213
214 if( constraint.Value().HasMax() && via->GetDrillValue() > constraint.Value().Max() )
215 {
216 fail_max = true;
217 constraintValue = constraint.Value().Max();
218 }
219
220 if( fail_min || fail_max )
221 {
222 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
223 wxString msg;
224
225 if( fail_min )
226 {
227 msg.Printf( _( "(%s min width %s; actual %s)" ),
228 constraint.GetName(),
229 MessageTextFromValue( constraintValue ),
230 MessageTextFromValue( via->GetDrillValue() ) );
231 }
232 else
233 {
234 msg.Printf( _( "(%s max width %s; actual %s)" ),
235 constraint.GetName(),
236 MessageTextFromValue( constraintValue ),
237 MessageTextFromValue( via->GetDrillValue() ) );
238 }
239
240 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
241 drcItem->SetItems( via );
242 drcItem->SetViolatingRule( constraint.GetParentRule() );
243
244 reportViolation( drcItem, via->GetPosition(), UNDEFINED_LAYER );
245 }
246}
247
248
249namespace detail
250{
252}
FOOTPRINTS & Footprints()
Definition: board.h:307
TRACKS & Tracks()
Definition: board.h:304
MINOPTMAX< int > & Value()
Definition: drc_rule.h:140
BOARD * GetBoard() const
Definition: drc_engine.h:89
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:671
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 Run() override
Run this provider against the given PCB with configured options (if any).
void checkViaHole(PCB_VIA *via, bool aExceedMicro, bool aExceedStd)
virtual const wxString GetName() const override
virtual const wxString GetDescription() const override
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out #DRC_ITEMs and po...
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
DRC_ENGINE * m_drcEngine
virtual void reportRuleStatistics()
T Min() const
Definition: minoptmax.h:33
Definition: pad.h:58
const VECTOR2I & GetDrillSize() const
Definition: pad.h:261
VECTOR2I GetPosition() const override
Definition: pad.h:196
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
@ DRCE_DRILL_OUT_OF_RANGE
Definition: drc_item.h:57
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition: drc_item.h:60
@ HOLE_SIZE_CONSTRAINT
Definition: drc_rule.h:50
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102