KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_track_width.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/*
32 Track width test. As the name says, checks width of the tracks (including segments and arcs)
33 Errors generated:
34 - DRCE_TRACK_WIDTH
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( "width" );
53 };
54
55 virtual const wxString GetDescription() const override
56 {
57 return wxT( "Tests track widths" );
58 }
59};
60
61
63{
65 {
66 reportAux( wxT( "Track width violations ignored. Tests not run." ) );
67 return true; // continue with other tests
68 }
69
71 {
72 reportAux( wxT( "No track width constraints found. Tests not run." ) );
73 return true; // continue with other tests
74 }
75
76 if( !reportPhase( _( "Checking track widths..." ) ) )
77 return false; // DRC cancelled
78
79 auto checkTrackWidth =
80 [&]( BOARD_ITEM* item ) -> bool
81 {
83 return false;
84
85 int actual;
86 VECTOR2I p0;
87
88 if( PCB_ARC* arc = dyn_cast<PCB_ARC*>( item ) )
89 {
90 actual = arc->GetWidth();
91 p0 = arc->GetStart();
92 }
93 else if( PCB_TRACK* trk = dyn_cast<PCB_TRACK*>( item ) )
94 {
95 actual = trk->GetWidth();
96 p0 = ( trk->GetStart() + trk->GetEnd() ) / 2;
97 }
98 else
99 {
100 return true;
101 }
102
103 auto constraint = m_drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, item, nullptr,
104 item->GetLayer() );
105 bool fail_min = false;
106 bool fail_max = false;
107 int constraintWidth = 0;
108
109 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
110 {
111 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
112 {
113 fail_min = true;
114 constraintWidth = constraint.Value().Min();
115 }
116
117 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
118 {
119 fail_max = true;
120 constraintWidth = constraint.Value().Max();
121 }
122 }
123
124 if( fail_min || fail_max )
125 {
126 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TRACK_WIDTH );
127 wxString msg;
128
129 if( fail_min )
130 {
131 msg = formatMsg( _( "(%s min width %s; actual %s)" ),
132 constraint.GetName(),
133 constraintWidth,
134 actual );
135 }
136 else
137 {
138 msg = formatMsg( _( "(%s max width %s; actual %s)" ),
139 constraint.GetName(),
140 constraintWidth,
141 actual );
142 }
143
144 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
145 drcItem->SetItems( item );
146 drcItem->SetViolatingRule( constraint.GetParentRule() );
147
148 reportViolation( drcItem, p0, item->GetLayer() );
149 }
150
151 return true;
152 };
153
154 const int progressDelta = 250;
155 int ii = 0;
156
157 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
158 {
159 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
160 break;
161
162 if( !checkTrackWidth( item ) )
163 break;
164 }
165
167
168 return !m_drcEngine->IsCancelled();
169}
170
171
172namespace detail
173{
175}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:71
TRACKS & Tracks()
Definition: board.h:309
MINOPTMAX< int > & Value()
Definition: drc_rule.h:142
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:666
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 const wxString GetName() const override
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual const wxString GetDescription() 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 bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
DRC_ENGINE * m_drcEngine
void reportAux(const wxString &aMsg)
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, int aConstraint, int aActual)
virtual void reportRuleStatistics()
T Min() const
Definition: minoptmax.h:33
@ DRCE_TRACK_WIDTH
Definition: drc_item.h:54
@ TRACK_WIDTH_CONSTRAINT
Definition: drc_rule.h:56
#define _(s)
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE