KiCad PCB EDA Suite
drc_test_provider_annulus.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 <common.h>
25 #include <track.h>
26 #include <drc/drc_item.h>
27 #include <drc/drc_rule.h>
28 #include <drc/drc_test_provider.h>
29 
30 /*
31  Via/pad annular ring width test. Checks if there's sufficient copper ring around
32  PTH/NPTH holes (vias/pads)
33  Errors generated:
34  - DRCE_ANNULUS
35 
36  Todo:
37  - check pad holes too.
38  - pad stack support (different IAR/OAR values depending on layer)
39 */
40 
42 {
43 public:
45  {
46  }
47 
49  {
50  }
51 
52  virtual bool Run() override;
53 
54  virtual const wxString GetName() const override
55  {
56  return "annulus";
57  };
58 
59  virtual const wxString GetDescription() const override
60  {
61  return "Tests pad/via annular rings";
62  }
63 
64  virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
65 
66  int GetNumPhases() const override;
67 };
68 
69 
71 {
73  {
74  reportAux( "Annular width violations ignored. Skipping check." );
75  return true; // continue with other tests
76  }
77 
78  const int delta = 250; // This is the number of tests between 2 calls to the progress bar
79 
81  {
82  reportAux( "No annulus constraints found. Tests not run." );
83  return true; // continue with other tests
84  }
85 
86  if( !reportPhase( _( "Checking via annular rings..." ) ) )
87  return false; // DRC cancelled
88 
89  auto checkAnnulus =
90  [&]( BOARD_ITEM* item ) -> bool
91  {
93  return false;
94 
95  int v_min = 0;
96  int v_max = 0;
97  VIA* via = dyn_cast<VIA*>( item );
98 
99  // fixme: check minimum IAR/OAR ring for THT pads too
100  if( !via )
101  return true;
102 
103  // PADSTACKS TODO: once we have padstacks we'll need to run this per-layer....
104  auto constraint = m_drcEngine->EvalRules( ANNULAR_WIDTH_CONSTRAINT, via, nullptr,
105  UNDEFINED_LAYER );
106  int annulus = ( via->GetWidth() - via->GetDrillValue() ) / 2;
107  bool fail_min = false;
108  bool fail_max = false;
109 
110  if( constraint.Value().HasMin() )
111  {
112  v_min = constraint.Value().Min();
113  fail_min = annulus < v_min;
114  }
115 
116  if( constraint.Value().HasMax() )
117  {
118  v_max = constraint.Value().Max();
119  fail_max = annulus > v_max;
120  }
121 
122  if( fail_min || fail_max )
123  {
124  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ANNULAR_WIDTH );
125 
126  if( fail_min )
127  m_msg.Printf( _( "(%s min annular width %s; actual %s)" ),
128  constraint.GetName(),
129  MessageTextFromValue( userUnits(), v_min ),
130  MessageTextFromValue( userUnits(), annulus ) );
131 
132  if( fail_max )
133  m_msg.Printf( _( "(%s max annular width %s; actual %s)" ),
134  constraint.GetName(),
135  MessageTextFromValue( userUnits(), v_max ),
136  MessageTextFromValue( userUnits(), annulus ) );
137 
138  drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
139  drcItem->SetItems( item );
140  drcItem->SetViolatingRule( constraint.GetParentRule() );
141 
142  reportViolation( drcItem, via->GetPosition() );
143  }
144 
145  return true;
146  };
147 
148  BOARD* board = m_drcEngine->GetBoard();
149  int ii = 0;
150 
151  for( TRACK* item : board->Tracks() )
152  {
153  if( !reportProgress( ii++, board->Tracks().size(), delta ) )
154  break;
155 
156  if( !checkAnnulus( item ) )
157  return false; // DRC cancelled
158  }
159 
161 
162  return true;
163 }
164 
165 
167 {
168  return 1;
169 }
170 
171 
172 std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_ANNULUS::GetConstraintTypes() const
173 {
174  return { ANNULAR_WIDTH_CONSTRAINT };
175 }
176 
177 
178 namespace detail
179 {
181 }
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:90
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
MINOPTMAX< int > & Value()
Definition: drc_rule.h:122
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULUS > dummy
bool IsErrorLimitExceeded(int error_code)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
T Min() const
Definition: minoptmax.h:33
virtual const wxString GetName() const override
virtual void reportRuleStatistics()
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
BOARD * GetBoard() const
Definition: drc_engine.h:87
virtual bool reportPhase(const wxString &aStageName)
virtual const wxString GetDescription() const override
EDA_UNITS userUnits() const
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:746
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
DRC_ENGINE * m_drcEngine
The common library.
virtual bool Run() override
Runs this provider against the given PCB with configured options (if any).
virtual std::set< DRC_CONSTRAINT_T > GetConstraintTypes() const override
TRACKS & Tracks()
Definition: board.h:302
virtual void reportAux(wxString fmt,...)
Definition: track.h:83