KiCad PCB EDA Suite
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 (C) 2004-2020 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 <track.h>
25 #include <drc/drc_item.h>
26 #include <drc/drc_rule.h>
27 #include <drc/drc_test_provider.h>
28 
29 /*
30  Via diameter test.
31 
32  Errors generated:
33  - DRCE_VIA_DIAMETER
34 */
35 
37 {
38 public:
40  {
41  }
42 
44  {
45  }
46 
47  virtual bool Run() override;
48 
49  virtual const wxString GetName() const override
50  {
51  return "diameter";
52  };
53 
54  virtual const wxString GetDescription() const override
55  {
56  return "Tests via diameters";
57  }
58 
59  virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
60 
61  int GetNumPhases() const override;
62 };
63 
64 
66 {
67  const int delta = 100; // This is the number of tests between 2 calls to the progress bar
68 
70  {
71  reportAux( "Via diameter violations ignored. Tests not run." );
72  return true; // continue with other tests
73  }
74 
76  {
77  reportAux( "No via diameter constraints found. Tests not run." );
78  return true; // continue with other tests
79  }
80 
81  if( !reportPhase( _( "Checking via diameters..." ) ) )
82  return false; // DRC cancelled
83 
84  auto checkViaDiameter =
85  [&]( BOARD_ITEM* item ) -> bool
86  {
88  return false;
89 
90  VIA* via = dyn_cast<VIA*>( item );
91 
92  // fixme: move to pad stack check?
93  if( !via )
94  return true;
95 
96  // TODO: once we have padstacks this will need to run per-layer...
97  auto constraint = m_drcEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, item, nullptr,
99  bool fail_min = false;
100  bool fail_max = false;
101  int constraintDiameter = 0;
102  int actual = via->GetWidth();
103 
104  if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
105  {
106  fail_min = true;
107  constraintDiameter = constraint.Value().Min();
108  }
109 
110  if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
111  {
112  fail_max = true;
113  constraintDiameter = constraint.Value().Max();
114  }
115 
116  if( fail_min )
117  {
118  m_msg.Printf( _( "(%s min diameter %s; actual %s)" ),
119  constraint.GetName(),
120  MessageTextFromValue( userUnits(), constraintDiameter ),
121  MessageTextFromValue( userUnits(), actual ) );
122  }
123  else if( fail_max )
124  {
125  m_msg.Printf( _( "(%s max diameter %s; actual %s)" ),
126  constraint.GetName(),
127  MessageTextFromValue( userUnits(), constraintDiameter ),
128  MessageTextFromValue( userUnits(), actual ) );
129  }
130 
131  if( fail_min || fail_max )
132  {
133  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
134 
135  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
136  drcItem->SetItems( item );
137  drcItem->SetViolatingRule( constraint.GetParentRule() );
138 
139  reportViolation( drcItem, via->GetPosition() );
140  }
141 
142  return true;
143  };
144 
145  int ii = 0;
146 
147  for( TRACK* item : m_drcEngine->GetBoard()->Tracks() )
148  {
149  if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), delta ) )
150  break;
151 
152  if( !checkViaDiameter( item ) )
153  break;
154  }
155 
157 
158  return true;
159 }
160 
161 
163 {
164  return 1;
165 }
166 
167 
168 std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_VIA_DIAMETER::GetConstraintTypes() const
169 {
170  return { VIA_DIAMETER_CONSTRAINT };
171 }
172 
173 
174 namespace detail
175 {
177 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:125
Definition: track.h:343
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULUS > dummy
bool IsErrorLimitExceeded(int error_code)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportRuleStatistics()
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
BOARD * GetBoard() const
Definition: drc_engine.h:87
virtual bool reportPhase(const wxString &aStageName)
EDA_UNITS userUnits() const
virtual std::set< DRC_CONSTRAINT_T > GetConstraintTypes() const override
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintId, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Definition: drc_engine.cpp:747
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
virtual const wxString GetDescription() const override
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
#define _(s)
Definition: 3d_actions.cpp:33
DRC_ENGINE * m_drcEngine
virtual const wxString GetName() const override
TRACKS & Tracks()
Definition: board.h:302
virtual void reportAux(wxString fmt,...)
Definition: track.h:83
virtual bool Run() override
Runs this provider against the given PCB with configured options (if any).