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 The 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:
47
48 virtual ~DRC_TEST_PROVIDER_HOLE_SIZE() = default;
49
50 virtual bool Run() override;
51
52 virtual const wxString GetName() const override { return wxT( "hole_size" ); };
53
54private:
55 void checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd );
56 void checkPadHole( PAD* aPad );
57};
58
59
61{
62 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
63 {
64 if( !reportPhase( _( "Checking pad holes..." ) ) )
65 return false; // DRC cancelled
66
67 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
68 {
69 for( PAD* pad : footprint->Pads() )
70 {
71 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
73 }
74 }
75 }
76
77 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE )
78 || !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
79 {
80 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
81 {
82 if( !reportPhase( _( "Checking via holes..." ) ) )
83 return false; // DRC cancelled
84 }
85 else
86 {
87 if( !reportPhase( _( "Checking micro-via holes..." ) ) )
88 return false; // DRC cancelled
89 }
90
91 for( PCB_TRACK* track : m_drcEngine->GetBoard()->Tracks() )
92 {
93 if( track->Type() == PCB_VIA_T )
94 {
95 bool exceedMicro = m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE );
96 bool exceedStd = m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE );
97
98 if( exceedMicro && exceedStd )
99 break;
100
101 checkViaHole( static_cast<PCB_VIA*>( track ), exceedMicro, exceedStd );
102 }
103 }
104 }
105
106 return !m_drcEngine->IsCancelled();
107}
108
109
111{
112 int holeMinor = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
113 int holeMajor = std::max( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
114
115 if( holeMinor == 0 )
116 return;
117
118 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, aPad, nullptr,
119 UNDEFINED_LAYER /* holes are not layer-specific */ );
120 bool fail_min = false;
121 bool fail_max = false;
122 int constraintValue = 0;
123 VECTOR2I ptA, ptB;
124
125 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
126 return;
127
128 if( constraint.Value().HasMax() && holeMajor > constraint.Value().Max() )
129 {
130 fail_max = true;
131 constraintValue = constraint.Value().Max();
132
133 ptA = aPad->GetPosition();
134
135 if( aPad->GetDrillSizeX() == aPad->GetDrillSizeY() )
136 ptB = ptA - VECTOR2I( aPad->GetDrillSize() ).Resize( aPad->GetDrillSizeX() / 2 );
137 else if( aPad->GetDrillSizeX() > aPad->GetDrillSizeY() )
138 ptB = ptA - VECTOR2I( aPad->GetDrillSizeX() / 2, 0 );
139 else
140 ptB = ptA - VECTOR2I( 0, aPad->GetDrillSizeY() / 2 );
141 }
142
143 if( constraint.Value().HasMin() && holeMinor < constraint.Value().Min() )
144 {
145 fail_min = true;
146 constraintValue = constraint.Value().Min();
147
148 ptA = aPad->GetPosition();
149
150 if( aPad->GetDrillSizeX() == aPad->GetDrillSizeY() )
151 ptB = ptA - VECTOR2I( aPad->GetDrillSize() ).Resize( aPad->GetDrillSizeX() / 2 );
152 else if( aPad->GetDrillSizeX() < aPad->GetDrillSizeY() )
153 ptB = ptA - VECTOR2I( aPad->GetDrillSizeX() / 2, 0 );
154 else
155 ptB = ptA - VECTOR2I( 0, aPad->GetDrillSizeY() / 2 );
156 }
157
158 if( fail_min || fail_max )
159 {
160 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DRILL_OUT_OF_RANGE );
161 wxString constraintName = constraint.GetName();
162 wxString msg;
163
164 if( fail_min )
165 {
166 if( constraint.GetParentRule() && constraint.GetParentRule()->m_Implicit )
167 constraintName = _( "board setup constraints" );
168
169 msg = formatMsg( _( "(%s min hole %s; actual %s)" ),
170 constraintName,
171 constraintValue,
172 holeMinor );
173 }
174 else
175 {
176 msg = formatMsg( _( "(%s max hole %s; actual %s)" ),
177 constraintName,
178 constraintValue,
179 holeMajor );
180 }
181
182 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
183 drcItem->SetItems( aPad );
184 drcItem->SetViolatingRule( constraint.GetParentRule() );
185 reportTwoPointGeometry( drcItem, ptA, ptA, ptB, UNDEFINED_LAYER );
186 }
187}
188
189
190void DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd )
191{
192 int errorCode;
193
194 if( via->GetViaType() == VIATYPE::MICROVIA )
195 {
196 if( aExceedMicro )
197 return;
198
200 }
201 else
202 {
203 if( aExceedStd )
204 return;
205
206 errorCode = DRCE_DRILL_OUT_OF_RANGE;
207 }
208
209 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, via, nullptr,
210 UNDEFINED_LAYER /* holes are not layer-specific */ );
211 bool fail_min = false;
212 bool fail_max = false;
213 int constraintValue = 0;
214 int drill = via->GetDrillValue();
215
216 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
217 return;
218
219 if( constraint.Value().HasMin() && drill < constraint.Value().Min() )
220 {
221 fail_min = true;
222 constraintValue = constraint.Value().Min();
223 }
224
225 if( constraint.Value().HasMax() && drill > constraint.Value().Max() )
226 {
227 fail_max = true;
228 constraintValue = constraint.Value().Max();
229 }
230
231 if( fail_min || fail_max )
232 {
233 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
234 wxString constraintName = constraint.GetName();
235 wxString msg;
236
237 if( fail_min )
238 {
239 if( constraint.m_ImplicitMin )
240 constraintName = _( "board setup constraints" );
241
242 msg = formatMsg( _( "(%s min hole %s; actual %s)" ),
243 constraintName,
244 constraintValue,
245 drill );
246 }
247 else
248 {
249 msg = formatMsg( _( "(%s max hole %s; actual %s)" ),
250 constraintName,
251 constraintValue,
252 drill );
253 }
254
255 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
256 drcItem->SetItems( via );
257 drcItem->SetViolatingRule( constraint.GetParentRule() );
258
259 VECTOR2I ptA = via->GetPosition();
260
261 VECTOR2I ptB = ptA - VECTOR2I( drill, drill ).Resize( drill / 2 );
262 reportTwoPointGeometry( drcItem, ptA, ptA, ptB, UNDEFINED_LAYER );
263 }
264}
265
266
267namespace detail
268{
270}
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:381
virtual ~DRC_TEST_PROVIDER_HOLE_SIZE()=default
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 bool reportPhase(const wxString &aStageName)
void reportTwoPointGeometry(std::shared_ptr< DRC_ITEM > &aDrcItem, const VECTOR2I &aMarkerPos, const VECTOR2I &ptA, const VECTOR2I &ptB, PCB_LAYER_ID aLayer)
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Definition pad.h:54
int GetDrillSizeY() const
Definition pad.h:309
const VECTOR2I & GetDrillSize() const
Definition pad.h:305
VECTOR2I GetPosition() const override
Definition pad.h:208
int GetDrillSizeX() const
Definition pad.h:307
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:385
@ 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
@ MICROVIA
Definition pcb_track.h:71
@ RPT_SEVERITY_IGNORE
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695