KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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
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
44
45 virtual bool Run() override;
46
47 virtual const wxString GetName() const override { return wxT( "diameter" ); };
48};
49
50
52{
54 {
55 REPORT_AUX( wxT( "Via diameter violations ignored. Tests not run." ) );
56 return true; // continue with other tests
57 }
58
60 {
61 REPORT_AUX( wxT( "No via diameter constraints found. Tests not run." ) );
62 return true; // continue with other tests
63 }
64
65 if( !reportPhase( _( "Checking via diameters..." ) ) )
66 return false; // DRC cancelled
67
68 auto checkViaDiameter =
69 [&]( BOARD_ITEM* item ) -> bool
70 {
72 return false;
73
74 if( item->Type() != PCB_VIA_T )
75 return true;
76
77 PCB_VIA* via = static_cast<PCB_VIA*>( item );
78
79 // TODO: once we have padstacks this will need to run per-layer...
80 auto constraint = m_drcEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, item, nullptr,
82 bool fail_min = false;
83 bool fail_max = false;
84 int constraintDiameter = 0;
85 // TODO(JE) padstacks
86 int actual = via->GetWidth( PADSTACK::ALL_LAYERS );
87
88 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
89 {
90 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
91 {
92 fail_min = true;
93 constraintDiameter = constraint.Value().Min();
94 }
95
96 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
97 {
98 fail_max = true;
99 constraintDiameter = constraint.Value().Max();
100 }
101 }
102
103 if( fail_min || fail_max )
104 {
105 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
106 wxString constraintName = constraint.GetName();
107 wxString msg;
108
109 if( fail_min )
110 {
111 if( constraint.m_ImplicitMin )
112 constraintName = _( "board setup constraints" );
113
114 msg = formatMsg( _( "(%s min diameter %s; actual %s)" ),
115 constraintName,
116 constraintDiameter,
117 actual );
118 }
119 else if( fail_max )
120 {
121 msg = formatMsg( _( "(%s max diameter %s; actual %s)" ),
122 constraintName,
123 constraintDiameter,
124 actual );
125 }
126
127 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
128 drcItem->SetItems( item );
129 drcItem->SetViolatingRule( constraint.GetParentRule() );
130
131 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
132 }
133
134 return true;
135 };
136
137 const int progressDelta = 500;
138 int ii = 0;
139
140 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
141 {
142 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
143 break;
144
145 if( !checkViaDiameter( item ) )
146 break;
147 }
148
149 return !m_drcEngine->IsCancelled();
150}
151
152
153namespace detail
154{
156}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
const TRACKS & Tracks() const
Definition: board.h:353
BOARD * GetBoard() const
Definition: drc_engine.h:95
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: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:393
virtual ~DRC_TEST_PROVIDER_VIA_DIAMETER()=default
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual const wxString GetName() const override
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
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
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
@ DRCE_VIA_DIAMETER
Definition: drc_item.h:61
@ VIA_DIAMETER_CONSTRAINT
Definition: drc_rule.h:70
#define REPORT_AUX(s)
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE
int actual
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97