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 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/*
28 Track width test. As the name says, checks width of the tracks (including segments and arcs)
29 Errors generated:
30 - DRCE_TRACK_WIDTH
31*/
32
34{
35public:
38
39 virtual ~DRC_TEST_PROVIDER_TRACK_WIDTH() = default;
40
41 virtual bool Run() override;
42
43 virtual const wxString GetName() const override { return wxT( "width" ); };
44};
45
46
48{
49 if( m_drcEngine->IsErrorLimitExceeded( DRCE_TRACK_WIDTH ) )
50 {
51 REPORT_AUX( wxT( "Track width violations ignored. Tests not run." ) );
52 return true; // continue with other tests
53 }
54
55 if( !m_drcEngine->HasRulesForConstraintType( TRACK_WIDTH_CONSTRAINT ) )
56 {
57 REPORT_AUX( wxT( "No track width constraints found. Tests not run." ) );
58 return true; // continue with other tests
59 }
60
61 if( !reportPhase( _( "Checking track widths..." ) ) )
62 return false; // DRC cancelled
63
64 auto checkTrackWidth =
65 [&]( BOARD_ITEM* item ) -> bool
66 {
67 if( m_drcEngine->IsErrorLimitExceeded( DRCE_TRACK_WIDTH ) )
68 return false;
69
70 int actual;
71 VECTOR2I p0;
72
73 if( item->Type() == PCB_ARC_T )
74 {
75 PCB_ARC* arc = static_cast<PCB_ARC*>( item );
76
77 actual = arc->GetWidth();
78 p0 = arc->GetStart();
79 }
80 else if( item->Type() == PCB_TRACE_T )
81 {
82 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
83
84 actual = track->GetWidth();
85 p0 = ( track->GetStart() + track->GetEnd() ) / 2;
86 }
87 else
88 {
89 return true;
90 }
91
92 auto constraint = m_drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, item, nullptr,
93 item->GetLayer() );
94 bool fail_min = false;
95 bool fail_max = false;
96 int constraintWidth = 0;
97
98 if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
99 {
100 if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
101 {
102 fail_min = true;
103 constraintWidth = constraint.Value().Min();
104 }
105
106 if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
107 {
108 fail_max = true;
109 constraintWidth = constraint.Value().Max();
110 }
111 }
112
113 if( fail_min || fail_max )
114 {
115 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TRACK_WIDTH );
116 wxString constraintName = constraint.GetName();
117
118 if( fail_min )
119 {
120 if( constraint.m_ImplicitMin )
121 constraintName = _( "board setup constraints" );
122
123 drcItem->SetErrorDetail( formatMsg( _( "(%s min width %s; actual %s)" ),
124 constraintName,
125 constraintWidth,
126 actual ) );
127 }
128 else
129 {
130 drcItem->SetErrorDetail( formatMsg( _( "(%s max width %s; actual %s)" ),
131 constraintName,
132 constraintWidth,
133 actual ) );
134 }
135
136 drcItem->SetItems( item );
137 drcItem->SetViolatingRule( constraint.GetParentRule() );
138
139 reportViolation( drcItem, p0, item->GetLayer() );
140 }
141
142 return true;
143 };
144
145 const int progressDelta = 250;
146 int ii = 0;
147
148 for( PCB_TRACK* item : m_drcEngine->GetBoard()->Tracks() )
149 {
150 if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), progressDelta ) )
151 break;
152
153 if( !checkTrackWidth( item ) )
154 break;
155 }
156
157 return !m_drcEngine->IsCancelled();
158}
159
160
161namespace detail
162{
164}
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 const wxString GetName() const override
virtual ~DRC_TEST_PROVIDER_TRACK_WIDTH()=default
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
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)
const VECTOR2I & GetStart() const
Definition pcb_track.h:93
const VECTOR2I & GetEnd() const
Definition pcb_track.h:90
virtual int GetWidth() const
Definition pcb_track.h:87
@ DRCE_TRACK_WIDTH
Definition drc_item.h:52
@ TRACK_WIDTH_CONSTRAINT
Definition drc_rule.h:61
#define REPORT_AUX(s)
#define _(s)
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE
int actual
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683