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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <footprint.h>
22#include <pad.h>
23#include <pcb_track.h>
25#include <drc/drc_engine.h>
26#include <drc/drc_item.h>
27#include <drc/drc_rule.h>
29
30/*
31 Drilled hole size test. scans vias/through-hole pads and checks for min drill sizes
32 Errors generated:
33 - DRCE_DRILL_OUT_OF_RANGE
34 - DRCE_MICROVIA_DRILL_OUT_OF_RANGE
35 - DRCE_PADSTACK
36*/
37
39{
40public:
43
44 virtual ~DRC_TEST_PROVIDER_HOLE_SIZE() = default;
45
46 virtual bool Run() override;
47
48 virtual const wxString GetName() const override { return wxT( "hole_size" ); };
49
50private:
51 void checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd );
52 void checkPadHole( PAD* aPad );
53};
54
55
57{
58 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
59 {
60 if( !reportPhase( _( "Checking pad holes..." ) ) )
61 return false; // DRC cancelled
62
63 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
64 {
65 for( PAD* pad : footprint->Pads() )
66 {
67 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
69 }
70 }
71 }
72
73 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE )
74 || !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
75 {
76 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
77 {
78 if( !reportPhase( _( "Checking via holes..." ) ) )
79 return false; // DRC cancelled
80 }
81 else
82 {
83 if( !reportPhase( _( "Checking micro-via holes..." ) ) )
84 return false; // DRC cancelled
85 }
86
87 for( PCB_TRACK* track : m_drcEngine->GetBoard()->Tracks() )
88 {
89 if( track->Type() == PCB_VIA_T )
90 {
91 bool exceedMicro = m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE );
92 bool exceedStd = m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE );
93
94 if( exceedMicro && exceedStd )
95 break;
96
97 checkViaHole( static_cast<PCB_VIA*>( track ), exceedMicro, exceedStd );
98 }
99 }
100 }
101
102 return !m_drcEngine->IsCancelled();
103}
104
105
107{
108 int holeMinor = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
109 int holeMajor = std::max( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
110
111 if( holeMinor == 0 )
112 return;
113
114 auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, aPad, nullptr,
115 UNDEFINED_LAYER /* holes are not layer-specific */ );
116 bool fail_min = false;
117 bool fail_max = false;
118 int constraintValue = 0;
119 VECTOR2I ptA, ptB;
120
121 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
122 return;
123
124 if( constraint.Value().HasMax() && holeMajor > constraint.Value().Max() )
125 {
126 fail_max = true;
127 constraintValue = constraint.Value().Max();
128
129 ptA = aPad->GetPosition();
130
131 if( aPad->GetDrillSizeX() == aPad->GetDrillSizeY() )
132 ptB = ptA - VECTOR2I( aPad->GetDrillSize() ).Resize( aPad->GetDrillSizeX() / 2 );
133 else if( aPad->GetDrillSizeX() > aPad->GetDrillSizeY() )
134 ptB = ptA - VECTOR2I( aPad->GetDrillSizeX() / 2, 0 );
135 else
136 ptB = ptA - VECTOR2I( 0, aPad->GetDrillSizeY() / 2 );
137 }
138
139 if( constraint.Value().HasMin() && holeMinor < constraint.Value().Min() )
140 {
141 fail_min = true;
142 constraintValue = constraint.Value().Min();
143
144 ptA = aPad->GetPosition();
145
146 if( aPad->GetDrillSizeX() == aPad->GetDrillSizeY() )
147 ptB = ptA - VECTOR2I( aPad->GetDrillSize() ).Resize( aPad->GetDrillSizeX() / 2 );
148 else if( aPad->GetDrillSizeX() < aPad->GetDrillSizeY() )
149 ptB = ptA - VECTOR2I( aPad->GetDrillSizeX() / 2, 0 );
150 else
151 ptB = ptA - VECTOR2I( 0, aPad->GetDrillSizeY() / 2 );
152 }
153
154 if( fail_min || fail_max )
155 {
156 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DRILL_OUT_OF_RANGE );
157 wxString constraintName = constraint.GetName();
158
159 if( fail_min )
160 {
161 if( constraint.GetParentRule() && constraint.GetParentRule()->IsImplicit() )
162 constraintName = _( "board setup constraints" );
163
164 drcItem->SetErrorDetail( formatMsg( _( "(%s min hole %s; actual %s)" ),
165 constraintName,
166 constraintValue,
167 holeMinor ) );
168 }
169 else
170 {
171 drcItem->SetErrorDetail( formatMsg( _( "(%s max hole %s; actual %s)" ),
172 constraintName,
173 constraintValue,
174 holeMajor ) );
175 }
176
177 drcItem->SetItems( aPad );
178 drcItem->SetViolatingRule( constraint.GetParentRule() );
179 reportTwoPointGeometry( drcItem, ptA, ptA, ptB, 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 int drill = via->GetDrillValue();
209
210 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
211 return;
212
213 if( constraint.Value().HasMin() && drill < constraint.Value().Min() )
214 {
215 fail_min = true;
216 constraintValue = constraint.Value().Min();
217 }
218
219 if( constraint.Value().HasMax() && drill > constraint.Value().Max() )
220 {
221 fail_max = true;
222 constraintValue = constraint.Value().Max();
223 }
224
225 if( fail_min || fail_max )
226 {
227 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
228 wxString constraintName = constraint.GetName();
229
230 if( fail_min )
231 {
232 if( constraint.m_ImplicitMin )
233 constraintName = _( "board setup constraints" );
234
235 drcItem->SetErrorDetail( formatMsg( _( "(%s min hole %s; actual %s)" ),
236 constraintName,
237 constraintValue,
238 drill ) );
239 }
240 else
241 {
242 drcItem->SetErrorDetail( formatMsg( _( "(%s max hole %s; actual %s)" ),
243 constraintName,
244 constraintValue,
245 drill ) );
246 }
247
248 drcItem->SetItems( via );
249 drcItem->SetViolatingRule( constraint.GetParentRule() );
250
251 VECTOR2I ptA = via->GetPosition();
252
253 VECTOR2I ptB = ptA - VECTOR2I( drill, drill ).Resize( drill / 2 );
254 reportTwoPointGeometry( drcItem, ptA, ptA, ptB, UNDEFINED_LAYER );
255 }
256}
257
258
259namespace detail
260{
262}
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:417
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:61
int GetDrillSizeY() const
Definition pad.h:319
VECTOR2I GetPosition() const override
Definition pad.cpp:245
VECTOR2I GetDrillSize() const
Definition pad.h:315
int GetDrillSizeX() const
Definition pad.h:317
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:381
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:57
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition drc_item.h:61
@ HOLE_SIZE_CONSTRAINT
Definition drc_rule.h:56
#define _(s)
@ UNDEFINED_LAYER
Definition layer_ids.h:57
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:90
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683