KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_line_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, 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_shape.h>
25#include <pcb_textbox.h>
26#include <drc/drc_engine.h>
27#include <drc/drc_item.h>
28#include <drc/drc_rule.h>
30
31/*
32 Stroke width of graphic shapes and text box borders, text strokes are in the text dimensions test
33 Errors generated:
34 - DRCE_LINE_WIDTH
35*/
36
38{
39public:
41
42 ~DRC_TEST_PROVIDER_LINE_WIDTH() override = default;
43
44 bool Run() override;
45
46 const wxString GetName() const override { return wxT( "line_width" ); }
47};
48
49
51{
52 const int progressDelta = 250;
53 int count = 0;
54 int ii = 0;
55
56 if( m_drcEngine->IsErrorLimitExceeded( DRCE_LINE_WIDTH ) )
57 {
58 REPORT_AUX( wxT( "Line width violations ignored. Tests not run." ) );
59 return true; // continue with other tests
60 }
61
62 if( !m_drcEngine->HasRulesForConstraintType( LINE_WIDTH_CONSTRAINT ) )
63 {
64 REPORT_AUX( wxT( "No line width constraints found. Tests not run." ) );
65 return true; // continue with other tests
66 }
67
68 if( !reportPhase( _( "Checking graphic line widths..." ) ) )
69 return false; // DRC cancelled
70
71 auto checkLineWidth =
72 [&]( BOARD_ITEM* aItem, int aWidth )
73 {
74 DRC_CONSTRAINT constraint = m_drcEngine->EvalRules( LINE_WIDTH_CONSTRAINT, aItem, nullptr,
75 aItem->GetLayer() );
76
77 if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
78 return;
79
80 auto report =
81 [&]( const wxString& aFormat, int aLimit )
82 {
83 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_LINE_WIDTH );
84 drcItem->SetErrorDetail( formatMsg( aFormat, constraint.GetName(), aLimit, aWidth ) );
85 drcItem->SetItems( aItem );
86 drcItem->SetViolatingRule( constraint.GetParentRule() );
87
88 reportViolation( drcItem, aItem->GetPosition(), aItem->GetLayer() );
89 };
90
91 if( constraint.Value().HasMin() && aWidth < constraint.Value().Min() )
92 report( _( "(%s min width %s; actual %s)" ), constraint.Value().Min() );
93
94 if( constraint.Value().HasMax() && aWidth > constraint.Value().Max() )
95 report( _( "(%s max width %s; actual %s)" ), constraint.Value().Max() );
96 };
97
98 static const std::vector<KICAD_T> itemTypes = { PCB_SHAPE_T, PCB_TEXTBOX_T };
99
101 [&]( BOARD_ITEM* item ) -> bool
102 {
103 ++count;
104 return true;
105 } );
106
108 [&]( BOARD_ITEM* item ) -> bool
109 {
110 if( m_drcEngine->IsErrorLimitExceeded( DRCE_LINE_WIDTH ) )
111 return false;
112
113 if( !reportProgress( ii++, count, progressDelta ) )
114 return false;
115
116 if( item->Type() == PCB_TEXTBOX_T )
117 {
118 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
119
120 if( textbox->IsBorderEnabled() )
121 checkLineWidth( textbox, textbox->GetBorderWidth() );
122
123 return true;
124 }
125
126 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
127
128 // A solid fill covers the stroke, so its width does not matter
129 if( !shape->IsSolidFill() )
130 checkLineWidth( shape, shape->GetWidth() );
131
132 return true;
133 } );
134
135 return !m_drcEngine->IsCancelled();
136}
137
138
139namespace detail
140{
142}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
wxString GetName() const
Definition drc_rule.h:162
SEVERITY GetSeverity() const
Definition drc_rule.h:181
MINOPTMAX< int > & Value()
Definition drc_rule.h:130
DRC_RULE * GetParentRule() const
Definition drc_rule.h:147
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:505
bool Run() override
Run this provider against the given PCB with configured options (if any).
~DRC_TEST_PROVIDER_LINE_WIDTH() override=default
const wxString GetName() const override
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, const LSET &aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
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)
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
bool IsSolidFill() const
Definition eda_shape.h:126
static const LSET & AllLayersMask()
Definition lset.cpp:637
T Min() const
Definition minoptmax.h:29
bool HasMax() const
Definition minoptmax.h:38
bool HasMin() const
Definition minoptmax.h:37
T Max() const
Definition minoptmax.h:30
int GetWidth() const override
bool IsBorderEnabled() const
Tests whether the border is disabled, as configured by the stroke.
int GetBorderWidth() const
@ LINE_WIDTH_CONSTRAINT
@ DRCE_LINE_WIDTH
Definition drc_item.h:117
#define REPORT_AUX(s)
#define _(s)
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ RPT_SEVERITY_IGNORE
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85