KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 = 0;
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 constraintName = constraint.GetName();
155 wxString msg;
156
157 if( fail_min )
158 {
159 if( constraint.GetParentRule() && constraint.GetParentRule()->m_Implicit )
160 constraintName = _( "board setup constraints" );
161
162 msg = formatMsg( _( "(%s min hole %s; actual %s)" ),
163 constraintName,
164 constraintValue,
165 holeMinor );
166 }
167 else
168 {
169 msg = formatMsg( _( "(%s max hole %s; actual %s)" ),
170 constraintName,
171 constraintValue,
172 holeMajor );
173 }
174
175 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
176 drcItem->SetItems( aPad );
177 drcItem->SetViolatingRule( constraint.GetParentRule() );
178
179 reportViolation( drcItem, aPad->GetPosition(), UNDEFINED_LAYER );
180 }
181}
182
183
184void DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd )
185{
186 int errorCode;
187
188 if( via->GetViaType() == VIATYPE::MICROVIA )
189 {
190 if( aExceedMicro )
191 return;
192
194 }
195 else
196 {
197 if( aExceedStd )
198 return;
199
200 errorCode = DRCE_DRILL_OUT_OF_RANGE;
201 }
202
203 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, via, nullptr,
204 UNDEFINED_LAYER /* holes are not layer-specific */ );
205 bool fail_min = false;
206 bool fail_max = false;
207 int constraintValue = 0;
208
209 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
210 return;
211
212 if( constraint.Value().HasMin() && via->GetDrillValue() < constraint.Value().Min() )
213 {
214 fail_min = true;
215 constraintValue = constraint.Value().Min();
216 }
217
218 if( constraint.Value().HasMax() && via->GetDrillValue() > constraint.Value().Max() )
219 {
220 fail_max = true;
221 constraintValue = constraint.Value().Max();
222 }
223
224 if( fail_min || fail_max )
225 {
226 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
227 wxString constraintName = constraint.GetName();
228 wxString msg;
229
230 if( fail_min )
231 {
232 if( constraint.m_ImplicitMin )
233 constraintName = _( "board setup constraints" );
234
235 msg = formatMsg( _( "(%s min hole %s; actual %s)" ),
236 constraintName,
237 constraintValue,
238 via->GetDrillValue() );
239 }
240 else
241 {
242 msg = formatMsg( _( "(%s max hole %s; actual %s)" ),
243 constraintName,
244 constraintValue,
245 via->GetDrillValue() );
246 }
247
248 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
249 drcItem->SetItems( via );
250 drcItem->SetViolatingRule( constraint.GetParentRule() );
251
252 reportViolation( drcItem, via->GetPosition(), UNDEFINED_LAYER );
253 }
254}
255
256
257namespace detail
258{
260}
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
MINOPTMAX< int > & Value()
Definition: drc_rule.h:153
BOARD * GetBoard() const
Definition: drc_engine.h:96
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:693
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:395
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_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)
DRC_ENGINE * m_drcEngine
virtual void reportRuleStatistics()
T Min() const
Definition: minoptmax.h:33
Definition: pad.h:54
const VECTOR2I & GetDrillSize() const
Definition: pad.h:307
VECTOR2I GetPosition() const override
Definition: pad.h:210
@ DRCE_DRILL_OUT_OF_RANGE
Definition: drc_item.h:60
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition: drc_item.h:64
@ HOLE_SIZE_CONSTRAINT
Definition: drc_rule.h:54
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
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:97