KiCad PCB EDA Suite
drc_test_provider_via_diameter.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
24#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 Via diameter test.
32
33 Errors generated:
34 - DRCE_VIA_DIAMETER
35*/
36
38{
39public:
41 {
42 }
43
45 {
46 }
47
48 virtual bool Run() override;
49
50 virtual const wxString GetName() const override
51 {
52 return wxT( "diameter" );
53 };
54
55 virtual const wxString GetDescription() const override
56 {
57 return wxT( "Tests via diameters" );
58 }
59};
60
61
63{
65 {
66 reportAux( wxT( "Via diameter violations ignored. Tests not run." ) );
67 return true; // continue with other tests
68 }
69
71 {
72 reportAux( wxT( "No via diameter constraints found. Tests not run." ) );
73 return true; // continue with other tests
74 }
75
76 if( !reportPhase( _( "Checking via diameters..." ) ) )
77 return false; // DRC cancelled
78
79 auto checkViaDiameter =
80 [&]( BOARD_ITEM* item ) -> bool
81 {
83 return false;
84
85 PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
86
87 // fixme: move to pad stack check?
88 if( !via )
89 return true;
90
91 // TODO: once we have padstacks this will need to run per-layer...
92 auto constraint = m_drcEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, item, nullptr,
94 bool fail_min = false;
95 bool fail_max = false;
96 int constraintDiameter = 0;
97 int actual = via->GetWidth();
98
99 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
100 {
101 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
102 {
103 fail_min = true;
104 constraintDiameter = constraint.Value().Min();
105 }
106
107 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
108 {
109 fail_max = true;
110 constraintDiameter = constraint.Value().Max();
111 }
112 }
113
114 if( fail_min || fail_max )
115 {
116 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
117 wxString msg;
118
119 if( fail_min )
120 {
121 msg.Printf( _( "(%s min diameter %s; actual %s)" ),
122 constraint.GetName(),
123 MessageTextFromValue( constraintDiameter ),
124 MessageTextFromValue( actual ) );
125 }
126 else if( fail_max )
127 {
128 msg.Printf( _( "(%s max diameter %s; actual %s)" ),
129 constraint.GetName(),
130 MessageTextFromValue( constraintDiameter ),
131 MessageTextFromValue( actual ) );
132 }
133
134 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
135 drcItem->SetItems( item );
136 drcItem->SetViolatingRule( constraint.GetParentRule() );
137
138 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
139 }
140
141 return true;
142 };
143
144 const int progressDelta = 500;
145 int ii = 0;
146
147 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
148 {
149 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
150 break;
151
152 if( !checkViaDiameter( item ) )
153 break;
154 }
155
157
158 return !m_drcEngine->IsCancelled();
159}
160
161
162namespace detail
163{
165}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
TRACKS & Tracks()
Definition: board.h:304
BOARD * GetBoard() const
Definition: drc_engine.h:89
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)
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).
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 bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
virtual void reportAux(wxString fmt,...)
DRC_ENGINE * m_drcEngine
virtual void reportRuleStatistics()
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
@ DRCE_VIA_DIAMETER
Definition: drc_item.h:58
@ VIA_DIAMETER_CONSTRAINT
Definition: drc_rule.h:62
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE