KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21#pragma once
22
23#include <board.h>
24#include <board_commit.h>
25#include <drc/drc_engine.h>
26#include <pcb_marker.h>
27
28#include <functional>
29#include <set>
30
31class DRC_ENGINE;
33class DRC_RULE;
34class DRC_CONSTRAINT;
35
37{
38public:
40
42
44 {
46 return self;
47 }
48
49 void RegisterTestProvider( DRC_TEST_PROVIDER* provider ) { m_providers.push_back( provider ); }
50 std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_providers; }
51
52private:
53 std::vector<DRC_TEST_PROVIDER*> m_providers;
54};
55
56template<class T> class DRC_REGISTER_TEST_PROVIDER
57{
58public:
64};
65
66
68{
69public:
71
73
75 {
77 return self;
78 }
79
80 void RegisterShowMatchesProvider( DRC_TEST_PROVIDER* provider ) { m_providers.push_back( provider ); }
81 std::vector<DRC_TEST_PROVIDER*> GetShowMatchesProviders() const { return m_providers; }
82
83private:
84 std::vector<DRC_TEST_PROVIDER*> m_providers;
85};
86
87template<class T> class DRC_REGISTER_SHOWMATCHES_PROVIDER
88{
89public:
95};
96
97
103{
104public:
106 virtual ~DRC_TEST_PROVIDER() = default;
107
108 static void Init();
109
110 void SetDRCEngine( DRC_ENGINE *engine )
111 {
112 m_drcEngine = engine;
113 }
114
115 bool RunTests( EDA_UNITS aUnits )
116 {
117 SetUserUnits( aUnits );
118 return Run();
119 }
120
124 virtual bool Run() = 0;
125
126 virtual const wxString GetName() const;
127
128protected:
129 int forEachGeometryItem( const std::vector<KICAD_T>& aTypes, const LSET& aLayers,
130 const std::function<bool(BOARD_ITEM*)>& aFunc );
131
132 REPORTER* getLogReporter() const { return m_drcEngine->GetLogReporter(); }
133
134#define REPORT_AUX( s ) if( getLogReporter() ) getLogReporter()->Report( s, RPT_SEVERITY_INFO )
135
136 void reportViolation( std::shared_ptr<DRC_ITEM>& item, const VECTOR2I& aMarkerPos,
137 int aMarkerLayer,
138 const std::function<void( PCB_MARKER* )>& aPathGenerator = []( PCB_MARKER* ){} );
139
140 void reportTwoPointGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
141 const VECTOR2I& ptA, const VECTOR2I& ptB, PCB_LAYER_ID aLayer );
142
143 void reportTwoShapeGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
144 const SHAPE* aShape1, const SHAPE* aShape2, PCB_LAYER_ID aLayer,
145 int aDistance );
146
147 void reportTwoItemGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
148 const BOARD_ITEM* aItem1, const BOARD_ITEM* aItem2, PCB_LAYER_ID aLayer,
149 int aDistance );
150
151 virtual bool reportProgress( size_t aCount, size_t aSize, size_t aDelta = 1 );
152 virtual bool reportPhase( const wxString& aStageName );
153
154 bool isInvisibleText( const BOARD_ITEM* aItem ) const;
155
156 wxString formatMsg( const wxString& aFormatString, const wxString& aSource, double aConstraint,
157 double aActual, EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE );
158 wxString formatMsg( const wxString& aFormatString, const wxString& aSource,
159 const EDA_ANGLE& aConstraint, const EDA_ANGLE& aActual );
160
161 // List of basic (ie: non-compound) geometry items
162 static std::vector<KICAD_T> s_allBasicItems;
163 static std::vector<KICAD_T> s_allBasicItemsButZones;
164
165protected:
168 bool m_isRuleDriven = true;
169};
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
std::vector< DRC_TEST_PROVIDER * > m_providers
std::vector< DRC_TEST_PROVIDER * > GetShowMatchesProviders() const
void RegisterShowMatchesProvider(DRC_TEST_PROVIDER *provider)
static DRC_SHOWMATCHES_PROVIDER_REGISTRY & Instance()
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_ITEM and posi...
static std::vector< KICAD_T > s_allBasicItemsButZones
virtual bool reportPhase(const wxString &aStageName)
void reportTwoShapeGeometry(std::shared_ptr< DRC_ITEM > &aDrcItem, const VECTOR2I &aMarkerPos, const SHAPE *aShape1, const SHAPE *aShape2, PCB_LAYER_ID aLayer, int aDistance)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, const LSET &aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
void reportTwoItemGeometry(std::shared_ptr< DRC_ITEM > &aDrcItem, const VECTOR2I &aMarkerPos, const BOARD_ITEM *aItem1, const BOARD_ITEM *aItem2, PCB_LAYER_ID aLayer, int aDistance)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
REPORTER * getLogReporter() const
bool RunTests(EDA_UNITS aUnits)
void reportTwoPointGeometry(std::shared_ptr< DRC_ITEM > &aDrcItem, const VECTOR2I &aMarkerPos, const VECTOR2I &ptA, const VECTOR2I &ptB, PCB_LAYER_ID aLayer)
static std::vector< KICAD_T > s_allBasicItems
bool isInvisibleText(const BOARD_ITEM *aItem) const
virtual ~DRC_TEST_PROVIDER()=default
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, double aConstraint, double aActual, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
void SetUserUnits(EDA_UNITS aUnits)
EDA_DATA_TYPE
The type of unit.
Definition eda_units.h:34
EDA_UNITS
Definition eda_units.h:44
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683