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-2023 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
44 {}
45
46 virtual bool Run() override;
47
48 virtual const wxString GetName() const override
49 {
50 return wxT( "width" );
51 };
52
53 virtual const wxString GetDescription() const override
54 {
55 return wxT( "Tests track widths" );
56 }
57};
58
59
61{
63 {
64 reportAux( wxT( "Track width violations ignored. Tests not run." ) );
65 return true; // continue with other tests
66 }
67
69 {
70 reportAux( wxT( "No track width constraints found. Tests not run." ) );
71 return true; // continue with other tests
72 }
73
74 if( !reportPhase( _( "Checking track widths..." ) ) )
75 return false; // DRC cancelled
76
77 auto checkTrackWidth =
78 [&]( BOARD_ITEM* item ) -> bool
79 {
81 return false;
82
83 int actual;
84 VECTOR2I p0;
85
86 if( item->Type() == PCB_ARC_T )
87 {
88 PCB_ARC* arc = static_cast<PCB_ARC*>( item );
89
90 actual = arc->GetWidth();
91 p0 = arc->GetStart();
92 }
93 else if( item->Type() == PCB_TRACE_T )
94 {
95 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
96
97 actual = track->GetWidth();
98 p0 = ( track->GetStart() + track->GetEnd() ) / 2;
99 }
100 else
101 {
102 return true;
103 }
104
105 auto constraint = m_drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, item, nullptr,
106 item->GetLayer() );
107 bool fail_min = false;
108 bool fail_max = false;
109 int constraintWidth = 0;
110
111 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
112 {
113 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
114 {
115 fail_min = true;
116 constraintWidth = constraint.Value().Min();
117 }
118
119 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
120 {
121 fail_max = true;
122 constraintWidth = constraint.Value().Max();
123 }
124 }
125
126 if( fail_min || fail_max )
127 {
128 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TRACK_WIDTH );
129 wxString msg;
130
131 if( fail_min )
132 {
133 msg = formatMsg( _( "(%s min width %s; actual %s)" ),
134 constraint.GetName(),
135 constraintWidth,
136 actual );
137 }
138 else
139 {
140 msg = formatMsg( _( "(%s max width %s; actual %s)" ),
141 constraint.GetName(),
142 constraintWidth,
143 actual );
144 }
145
146 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
147 drcItem->SetItems( item );
148 drcItem->SetViolatingRule( constraint.GetParentRule() );
149
150 reportViolation( drcItem, p0, item->GetLayer() );
151 }
152
153 return true;
154 };
155
156 const int progressDelta = 250;
157 int ii = 0;
158
159 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
160 {
161 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
162 break;
163
164 if( !checkTrackWidth( item ) )
165 break;
166 }
167
169
170 return !m_drcEngine->IsCancelled();
171}
172
173
174namespace detail
175{
177}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
const TRACKS & Tracks() const
Definition: board.h:315
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:675
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:331
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...
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual)
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
DRC_ENGINE * m_drcEngine
void reportAux(const wxString &aMsg)
virtual void reportRuleStatistics()
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
T Min() const
Definition: minoptmax.h:33
int GetWidth() const
Definition: pcb_track.h:107
const VECTOR2I & GetStart() const
Definition: pcb_track.h:113
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:110
@ 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
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96