KiCad PCB EDA Suite
drc_test_provider.h
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) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
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 
25 #ifndef DRC_TEST_PROVIDER__H
26 #define DRC_TEST_PROVIDER__H
27 
28 #include <board.h>
29 #include <pcb_marker.h>
30 
31 #include <functional>
32 #include <set>
33 
34 class DRC_ENGINE;
35 class DRC_TEST_PROVIDER;
36 
38 {
39 public:
41 
43 
45  {
46  static DRC_TEST_PROVIDER_REGISTRY self;
47  return self;
48  }
49 
50  void RegisterTestProvider( DRC_TEST_PROVIDER* provider ) { m_providers.push_back( provider ); }
51  std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_providers; }
52 
53 private:
54  std::vector<DRC_TEST_PROVIDER*> m_providers;
55 };
56 
57 template<class T> class DRC_REGISTER_TEST_PROVIDER
58 {
59 public:
61  {
62  T* provider = new T;
64  }
65 };
66 
67 
73 {
74 public:
76  virtual ~DRC_TEST_PROVIDER() = default;
77 
78  void SetDRCEngine( DRC_ENGINE *engine )
79  {
80  m_drcEngine = engine;
81  m_stats.clear();
82  }
83 
87  virtual bool Run() = 0;
88 
89  virtual const wxString GetName() const;
90  virtual const wxString GetDescription() const;
91 
92  virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const = 0;
93 
94  virtual int GetNumPhases() const = 0;
95 
96  virtual bool IsRuleDriven() const
97  {
98  return m_isRuleDriven;
99  }
100 
101  bool IsEnabled() const
102  {
103  return m_enabled;
104  }
105 
106  void Enable( bool aEnable )
107  {
108  m_enabled = aEnable;
109  }
110 
111 protected:
112  int forEachGeometryItem( const std::vector<KICAD_T>& aTypes, LSET aLayers,
113  const std::function<bool(BOARD_ITEM*)>& aFunc );
114 
115  virtual void reportAux( wxString fmt, ... );
116  virtual void reportViolation( std::shared_ptr<DRC_ITEM>& item, const wxPoint& aMarkerPos );
117  virtual bool reportProgress( int aCount, int aSize, int aDelta );
118  virtual bool reportPhase( const wxString& aStageName );
119 
120  virtual void reportRuleStatistics();
121  virtual void accountCheck( const DRC_RULE* ruleToTest );
122  virtual void accountCheck( const DRC_CONSTRAINT& constraintToTest );
123 
124  bool isInvisibleText( const BOARD_ITEM* aItem ) const;
125 
126  // List of basic (ie: non-compound) geometry items
127  static std::vector<KICAD_T> s_allBasicItems;
128  static std::vector<KICAD_T> s_allBasicItemsButZones;
129 
130  EDA_UNITS userUnits() const;
132  std::unordered_map<const DRC_RULE*, int> m_stats;
133  bool m_isRuleDriven = true;
134  bool m_enabled = true;
135 
136  wxString m_msg; // Allocating strings gets expensive enough to want to avoid it
137 };
138 
139 #endif // DRC_TEST_PROVIDER__H
bool IsEnabled() const
Design Rule Checker object that performs all the DRC tests.
Definition: drc_engine.h:81
bool isInvisibleText(const BOARD_ITEM *aItem) const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const wxPoint &aMarkerPos)
std::vector< DRC_TEST_PROVIDER * > m_providers
static DRC_TEST_PROVIDER_REGISTRY & Instance()
virtual bool reportProgress(int aCount, int aSize, int aDelta)
void SetDRCEngine(DRC_ENGINE *engine)
virtual const wxString GetName() const
virtual bool Run()=0
Run this provider against the given PCB with configured options (if any).
virtual void reportRuleStatistics()
virtual int GetNumPhases() const =0
virtual std::set< DRC_CONSTRAINT_T > GetConstraintTypes() const =0
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:505
virtual bool reportPhase(const wxString &aStageName)
std::unordered_map< const DRC_RULE *, int > m_stats
void Enable(bool aEnable)
virtual void accountCheck(const DRC_RULE *ruleToTest)
EDA_UNITS userUnits() const
virtual const wxString GetDescription() const
virtual ~DRC_TEST_PROVIDER()=default
EDA_UNITS
Definition: eda_units.h:38
void RegisterTestProvider(DRC_TEST_PROVIDER *provider)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out #DRC_ITEMs and po...
static std::vector< KICAD_T > s_allBasicItems
static std::vector< KICAD_T > s_allBasicItemsButZones
DRC_ENGINE * m_drcEngine
virtual bool IsRuleDriven() const
virtual void reportAux(wxString fmt,...)