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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <pcb_track.h>
21#include <drc/drc_engine.h>
22#include <drc/drc_item.h>
23#include <drc/drc_rule.h>
25
26/*
27 Via diameter test.
28
29 Errors generated:
30 - DRCE_VIA_DIAMETER
31*/
32
34{
35public:
38
40
41 virtual bool Run() override;
42
43 virtual const wxString GetName() const override { return wxT( "diameter" ); };
44};
45
46
48{
49 if( m_drcEngine->IsErrorLimitExceeded( DRCE_VIA_DIAMETER ) )
50 {
51 REPORT_AUX( wxT( "Via diameter violations ignored. Tests not run." ) );
52 return true; // continue with other tests
53 }
54
55 if( !m_drcEngine->HasRulesForConstraintType( VIA_DIAMETER_CONSTRAINT ) )
56 {
57 REPORT_AUX( wxT( "No via diameter constraints found. Tests not run." ) );
58 return true; // continue with other tests
59 }
60
61 if( !reportPhase( _( "Checking via diameters..." ) ) )
62 return false; // DRC cancelled
63
64 auto checkViaDiameter =
65 [&]( BOARD_ITEM* item ) -> bool
66 {
67 if( m_drcEngine->IsErrorLimitExceeded( DRCE_VIA_DIAMETER ) )
68 return false;
69
70 if( item->Type() != PCB_VIA_T )
71 return true;
72
73 PCB_VIA* via = static_cast<PCB_VIA*>( item );
74
75 // TODO: once we have padstacks this will need to run per-layer...
76 auto constraint = m_drcEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, item, nullptr,
78 bool fail_min = false;
79 bool fail_max = false;
80 int constraintDiameter = 0;
81 // TODO(JE) padstacks
82 int actual = via->GetWidth( PADSTACK::ALL_LAYERS );
83
84 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
85 {
86 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
87 {
88 fail_min = true;
89 constraintDiameter = constraint.Value().Min();
90 }
91
92 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
93 {
94 fail_max = true;
95 constraintDiameter = constraint.Value().Max();
96 }
97 }
98
99 if( fail_min || fail_max )
100 {
101 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
102 wxString constraintName = constraint.GetName();
103 wxString msg;
104
105 if( fail_min )
106 {
107 if( constraint.m_ImplicitMin )
108 constraintName = _( "board setup constraints" );
109
110 msg = formatMsg( _( "(%s min diameter %s; actual %s)" ),
111 constraintName,
112 constraintDiameter,
113 actual );
114 }
115 else if( fail_max )
116 {
117 msg = formatMsg( _( "(%s max diameter %s; actual %s)" ),
118 constraintName,
119 constraintDiameter,
120 actual );
121 }
122
123 drcItem->SetErrorDetail( msg );
124 drcItem->SetItems( item );
125 drcItem->SetViolatingRule( constraint.GetParentRule() );
126
127 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
128 }
129
130 return true;
131 };
132
133 const int progressDelta = 500;
134 int ii = 0;
135
136 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
137 {
138 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
139 break;
140
141 if( !checkViaDiameter( item ) )
142 break;
143 }
144
145 return !m_drcEngine->IsCancelled();
146}
147
148
149namespace detail
150{
152}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
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_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
virtual bool reportPhase(const wxString &aStageName)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
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:177
@ DRCE_VIA_DIAMETER
Definition drc_item.h:58
@ VIA_DIAMETER_CONSTRAINT
Definition drc_rule.h:72
#define REPORT_AUX(s)
#define _(s)
@ UNDEFINED_LAYER
Definition layer_ids.h:57
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:90