KiCad PCB EDA Suite
drc_test_provider_disallow.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 <drc/drc_engine.h>
26 #include <drc/drc_item.h>
27 #include <drc/drc_rule.h>
28 #include <drc/drc_test_provider.h>
29 
30 /*
31  "Disallow" test. Goes through all items, matching types/conditions drop errors.
32  Errors generated:
33  - DRCE_ALLOWED_ITEMS
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 "disallow";
52  };
53 
54  virtual const wxString GetDescription() const override
55  {
56  return "Tests for disallowed items (e.g. keepouts)";
57  }
58 
59  virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
60 
61  int GetNumPhases() const override;
62 };
63 
64 
66 {
68  {
69  reportAux( "Disallow violations ignored. Tests not run." );
70  return true; // continue with other tests
71  }
72 
74  {
75  reportAux( "No disallow constraints found. Skipping check." );
76  return true; // continue with other tests
77  }
78 
79  if( !reportPhase( _( "Checking keepouts & disallow constraints..." ) ) )
80  return false; // DRC cancelled
81 
82  auto doCheckItem =
83  [&]( BOARD_ITEM* item )
84  {
85  auto constraint = m_drcEngine->EvalRules( DISALLOW_CONSTRAINT, item, nullptr,
87 
88  if( constraint.m_DisallowFlags )
89  {
90  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS );
91 
92  m_msg.Printf( drcItem->GetErrorText() + wxS( " (%s)" ),
93  constraint.GetName() );
94 
95  drcItem->SetErrorMessage( m_msg );
96  drcItem->SetItems( item );
97  drcItem->SetViolatingRule( constraint.GetParentRule() );
98 
99  reportViolation( drcItem, item->GetPosition() );
100  }
101  };
102 
103  auto checkItem =
104  [&]( BOARD_ITEM* item ) -> bool
105  {
107  return false;
108 
109  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
110  {
111  ZONE* zone = static_cast<ZONE*>( item );
112 
113  if( zone->GetIsRuleArea() )
114  return true;
115  }
116 
117  item->ClearFlags( HOLE_PROXY );
118  doCheckItem( item );
119 
120  bool hasHole;
121 
122  switch( item->Type() )
123  {
124  case PCB_VIA_T: hasHole = true; break;
125  case PCB_PAD_T: hasHole = static_cast<PAD*>( item )->GetDrillSizeX() > 0; break;
126  default: hasHole = false; break;
127  }
128 
129  if( hasHole )
130  {
131  item->SetFlags( HOLE_PROXY );
132  doCheckItem( item );
133  item->ClearFlags( HOLE_PROXY );
134  }
135 
136  return true;
137  };
138 
139  forEachGeometryItem( {}, LSET::AllLayersMask(), checkItem );
140 
142 
143  return true;
144 }
145 
146 
148 {
149  return 1;
150 }
151 
152 
153 std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_DISALLOW::GetConstraintTypes() const
154 {
155  return { DISALLOW_CONSTRAINT };
156 }
157 
158 
159 namespace detail
160 {
162 }
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
virtual std::set< DRC_CONSTRAINT_T > GetConstraintTypes() const override
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:730
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)
class PAD, a pad in a footprint
Definition: typeinfo.h:89
virtual void reportRuleStatistics()
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
virtual const wxString GetName() const override
virtual bool reportPhase(const wxString &aStageName)
virtual const wxString GetDescription() const override
static LSET AllLayersMask()
Definition: lset.cpp:787
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
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
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
Definition: eda_item.h:129
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, wxPoint aMarkerPos)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
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
class ZONE, managed by a footprint
Definition: typeinfo.h:94
The common library.
virtual bool Run() override
Runs this provider against the given PCB with configured options (if any).
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
virtual void reportAux(wxString fmt,...)