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, 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#pragma once
26
27#include <board.h>
28#include <board_commit.h>
29#include <drc/drc_engine.h>
30#include <pcb_marker.h>
31
32#include <functional>
33#include <set>
34
35class DRC_ENGINE;
37class DRC_RULE;
38class DRC_CONSTRAINT;
39
41{
42public:
44
46
48 {
50 return self;
51 }
52
53 void RegisterTestProvider( DRC_TEST_PROVIDER* provider ) { m_providers.push_back( provider ); }
54 std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_providers; }
55
56private:
57 std::vector<DRC_TEST_PROVIDER*> m_providers;
58};
59
60template<class T> class DRC_REGISTER_TEST_PROVIDER
61{
62public:
68};
69
70
76{
77public:
79 virtual ~DRC_TEST_PROVIDER() = default;
80
81 static void Init();
82
83 void SetDRCEngine( DRC_ENGINE *engine )
84 {
85 m_drcEngine = engine;
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
101protected:
102 int forEachGeometryItem( const std::vector<KICAD_T>& aTypes, const LSET& aLayers,
103 const std::function<bool(BOARD_ITEM*)>& aFunc );
104
105 REPORTER* getLogReporter() const { return m_drcEngine->GetLogReporter(); }
106
107#define REPORT_AUX( s ) if( getLogReporter() ) getLogReporter()->Report( s, RPT_SEVERITY_INFO )
108
109 void reportViolation( std::shared_ptr<DRC_ITEM>& item, const VECTOR2I& aMarkerPos,
110 int aMarkerLayer,
111 const std::function<void( PCB_MARKER* )>& aPathGenerator = []( PCB_MARKER* ){} );
112
113 void reportTwoPointGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
114 const VECTOR2I& ptA, const VECTOR2I& ptB, PCB_LAYER_ID aLayer );
115
116 void reportTwoShapeGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
117 const SHAPE* aShape1, const SHAPE* aShape2, PCB_LAYER_ID aLayer,
118 int aDistance );
119
120 void reportTwoItemGeometry( std::shared_ptr<DRC_ITEM>& aDrcItem, const VECTOR2I& aMarkerPos,
121 const BOARD_ITEM* aItem1, const BOARD_ITEM* aItem2, PCB_LAYER_ID aLayer,
122 int aDistance );
123
124 virtual bool reportProgress( size_t aCount, size_t aSize, size_t aDelta = 1 );
125 virtual bool reportPhase( const wxString& aStageName );
126
127 bool isInvisibleText( const BOARD_ITEM* aItem ) const;
128
129 wxString formatMsg( const wxString& aFormatString, const wxString& aSource, double aConstraint,
130 double aActual, EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE );
131 wxString formatMsg( const wxString& aFormatString, const wxString& aSource,
132 const EDA_ANGLE& aConstraint, const EDA_ANGLE& aActual );
133
134 // List of basic (ie: non-compound) geometry items
135 static std::vector<KICAD_T> s_allBasicItems;
136 static std::vector<KICAD_T> s_allBasicItemsButZones;
137
138protected:
141 bool m_isRuleDriven = true;
142};
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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_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:73
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:38
EDA_UNITS
Definition eda_units.h:48
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695