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-2022 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
34class DRC_ENGINE;
36class DRC_RULE;
37class DRC_CONSTRAINT;
38
40{
41public:
43
45
47 {
49 return self;
50 }
51
52 void RegisterTestProvider( DRC_TEST_PROVIDER* provider ) { m_providers.push_back( provider ); }
53 std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_providers; }
54
55private:
56 std::vector<DRC_TEST_PROVIDER*> m_providers;
57};
58
59template<class T> class DRC_REGISTER_TEST_PROVIDER
60{
61public:
63 {
64 T* provider = new T;
66 }
67};
68
69
75{
76public:
78 virtual ~DRC_TEST_PROVIDER() = default;
79
80 static void Init();
81
82 void SetDRCEngine( DRC_ENGINE *engine )
83 {
84 m_drcEngine = engine;
85 m_stats.clear();
86 }
87
88 bool RunTests( EDA_UNITS aUnits )
89 {
90 SetUserUnits( aUnits );
91 return Run();
92 }
93
97 virtual bool Run() = 0;
98
99 virtual const wxString GetName() const;
100 virtual const wxString GetDescription() const;
101
102protected:
103 int forEachGeometryItem( const std::vector<KICAD_T>& aTypes, LSET aLayers,
104 const std::function<bool(BOARD_ITEM*)>& aFunc );
105
106 virtual void reportAux( wxString fmt, ... );
107 virtual void reportViolation( std::shared_ptr<DRC_ITEM>& item, const VECTOR2I& aMarkerPos,
108 int aMarkerLayer );
109 virtual bool reportProgress( int aCount, int aSize, int aDelta );
110 virtual bool reportPhase( const wxString& aStageName );
111
112 virtual void reportRuleStatistics();
113 virtual void accountCheck( const DRC_RULE* ruleToTest );
114 virtual void accountCheck( const DRC_CONSTRAINT& constraintToTest );
115
116 bool isInvisibleText( const BOARD_ITEM* aItem ) const;
117
118 wxString formatMsg( const wxString& aFormatString, const wxString& aSource, int aConstraint,
119 int aActual );
120
121 // List of basic (ie: non-compound) geometry items
122 static std::vector<KICAD_T> s_allBasicItems;
123 static std::vector<KICAD_T> s_allBasicItemsButZones;
124
126
127protected:
129 std::unordered_map<const DRC_RULE*, int> m_stats;
130 bool m_isRuleDriven = true;
131};
132
133#endif // DRC_TEST_PROVIDER__H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
Design Rule Checker object that performs all the DRC tests.
Definition: drc_engine.h:83
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
static DRC_TEST_PROVIDER_REGISTRY & Instance()
void RegisterTestProvider(DRC_TEST_PROVIDER *provider)
std::vector< DRC_TEST_PROVIDER * > m_providers
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_allBasicItemsButZones
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, LSET aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
virtual bool reportProgress(int aCount, int aSize, int aDelta)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
bool RunTests(EDA_UNITS aUnits)
virtual void reportAux(wxString fmt,...)
static std::vector< KICAD_T > s_allBasicItems
virtual const wxString GetDescription() const
EDA_UNITS userUnits() const
DRC_ENGINE * m_drcEngine
bool isInvisibleText(const BOARD_ITEM *aItem) const
std::unordered_map< const DRC_RULE *, int > m_stats
virtual ~DRC_TEST_PROVIDER()=default
virtual void accountCheck(const DRC_RULE *ruleToTest)
virtual bool Run()=0
Run this provider against the given PCB with configured options (if any).
void SetDRCEngine(DRC_ENGINE *engine)
virtual const wxString GetName() const
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, int aConstraint, int aActual)
virtual void reportRuleStatistics()
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
void SetUserUnits(EDA_UNITS aUnits)
EDA_UNITS
Definition: eda_units.h:43