KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_engine.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#pragma once
25
26#include <memory>
27#include <vector>
28#include <unordered_map>
29
30#include <units_provider.h>
31#include <pcb_shape.h>
32#include <lset.h>
33#include <drc/drc_rule.h>
34
35
36class BOARD_COMMIT;
40class PCB_EDIT_FRAME;
42class BOARD_ITEM;
43class BOARD;
44class PCB_MARKER;
45class NETCLASS;
46class NETLIST;
47class NETINFO_ITEM;
49class REPORTER;
50class wxFileName;
51
52namespace KIGFX
53{
54 class VIEW_OVERLAY;
55};
56
57void drcPrintDebugMessage( int level, const wxString& msg, const char *function, int line );
58
59#define drc_dbg(level, fmt, ...) \
60 drcPrintDebugMessage( level, wxString::Format( fmt, __VA_ARGS__ ), __FUNCTION__, __LINE__ );
61
63class DRC_ITEM;
64class DRC_RULE;
65class DRC_CONSTRAINT;
66
67
68typedef std::function<void( const std::shared_ptr<DRC_ITEM>& aItem,
69 const VECTOR2I& aPos, int aLayer,
70 const std::function<void( PCB_MARKER* )>& aPathGenerator )> DRC_VIOLATION_HANDLER;
71
83{
84 // They need to change / restore the violation handler
86
87public:
88 DRC_ENGINE( BOARD* aBoard = nullptr, BOARD_DESIGN_SETTINGS* aSettings = nullptr );
89 virtual ~DRC_ENGINE();
90
91 // We own several lists of raw pointers. Don't let the compiler fill in copy c'tors that
92 // will only land us in trouble.
93 DRC_ENGINE( const DRC_ENGINE& ) = delete;
94 DRC_ENGINE& operator=( const DRC_ENGINE& ) = delete;
95
96 void SetBoard( BOARD* aBoard ) { m_board = aBoard; }
97 BOARD* GetBoard() const { return m_board; }
98
99 void SetDesignSettings( BOARD_DESIGN_SETTINGS* aSettings ) { m_designSettings = aSettings; }
101
102 void SetSchematicNetlist( NETLIST* aNetlist ) { m_schematicNetlist = aNetlist; }
104
105 void SetDrawingSheet( DS_PROXY_VIEW_ITEM* aDrawingSheet ) { m_drawingSheet = aDrawingSheet; }
107
108 void SetDebugOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
109 {
110 m_debugOverlay = aOverlay;
111 }
112
113 std::shared_ptr<KIGFX::VIEW_OVERLAY> GetDebugOverlay() const { return m_debugOverlay; }
114
119 {
120 m_violationHandler = std::move( aHandler );
121 }
122
127
133
134 /*
135 * Set an optional reporter for rule parse/compile/run-time errors and log-level progress
136 * information.
137 *
138 * Note: if no log reporter is installed rule parse/compile/run-time errors are returned
139 * via a thrown PARSE_ERROR exception.
140 */
141 void SetLogReporter( REPORTER* aReporter ) { m_logReporter = aReporter; }
142
148 void InitEngine( const wxFileName& aRulePath );
149
153 void RunTests( EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints,
154 BOARD_COMMIT* aCommit = nullptr );
155
156 bool IsErrorLimitExceeded( int error_code );
157
158 DRC_CONSTRAINT EvalRules( DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM* a,
159 const BOARD_ITEM* b, PCB_LAYER_ID aLayer,
160 REPORTER* aReporter = nullptr );
161
163 PCB_LAYER_ID aLayer, REPORTER* aReporter = nullptr );
164
165 void ProcessAssertions( const BOARD_ITEM* a,
166 std::function<void( const DRC_CONSTRAINT* )> aFailureHandler,
167 REPORTER* aReporter = nullptr );
168
169 bool HasRulesForConstraintType( DRC_CONSTRAINT_T constraintID );
170
172 bool GetTestFootprints() const { return m_testFootprints; }
173
174 bool RulesValid() { return m_rulesValid; }
175
176 void ReportViolation( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos,
177 int aMarkerLayer, const std::function<void( PCB_MARKER* )>& aPathGenerator = {} );
178
179 bool KeepRefreshing( bool aWait = false );
180 void AdvanceProgress();
181 void SetMaxProgress( int aSize );
182 bool ReportProgress( double aProgress );
183 bool ReportPhase( const wxString& aMessage );
184 bool IsCancelled() const;
185
187
188 bool QueryWorstConstraint( DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT& aConstraint );
189 std::set<int> QueryDistinctConstraints( DRC_CONSTRAINT_T aConstraintId );
190
191 std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_testProviders; };
192
193 DRC_TEST_PROVIDER* GetTestProvider( const wxString& name ) const;
194
202 std::vector<BOARD_ITEM*> GetItemsMatchingCondition( const wxString& aExpression,
204 REPORTER* aReporter = nullptr );
205
206 static bool IsNetADiffPair( BOARD* aBoard, NETINFO_ITEM* aNet, int& aNetP, int& aNetN );
207
215 static int MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
216 wxString& aBaseDpName );
217
222 bool IsNetTieExclusion( int aTrackNetCode, PCB_LAYER_ID aTrackLayer,
223 const VECTOR2I& aCollisionPos, BOARD_ITEM* aCollidingItem );
224
225private:
226 void addRule( std::shared_ptr<DRC_RULE>& rule )
227 {
228 m_rules.push_back(rule);
229 }
230
236 void loadRules( const wxFileName& aPath );
237
238 void compileRules();
239
247
248 void loadImplicitRules();
249 std::shared_ptr<DRC_RULE> createImplicitRule( const wxString& name );
250
251protected:
256
257 std::vector<std::shared_ptr<DRC_RULE>> m_rules;
259 std::vector<DRC_TEST_PROVIDER*> m_testProviders;
260
261 std::vector<int> m_errorLimits;
264
265 // constraint -> rule -> provider
266 std::map<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> m_constraintMap;
267
271
272 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_debugOverlay;
273};
const char * name
Container for design settings for a BOARD object.
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
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
Definition drc_engine.h:106
std::map< DRC_CONSTRAINT_T, std::vector< DRC_ENGINE_CONSTRAINT * > * > m_constraintMap
Definition drc_engine.h:266
friend class DRC_TEST_PROVIDER_CREEPAGE
Definition drc_engine.h:85
DRC_ENGINE & operator=(const DRC_ENGINE &)=delete
void AdvanceProgress()
bool GetTestFootprints() const
Definition drc_engine.h:172
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
bool m_testFootprints
Definition drc_engine.h:263
void addRule(std::shared_ptr< DRC_RULE > &rule)
Definition drc_engine.h:226
PROGRESS_REPORTER * m_progressReporter
Definition drc_engine.h:270
void loadRules(const wxFileName &aPath)
Load and parse a rule set from an sexpr text file.
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition drc_engine.h:259
REPORTER * m_logReporter
Definition drc_engine.h:269
BOARD * GetBoard() const
Definition drc_engine.h:97
std::shared_ptr< KIGFX::VIEW_OVERLAY > GetDebugOverlay() const
Definition drc_engine.h:113
void SetDesignSettings(BOARD_DESIGN_SETTINGS *aSettings)
Definition drc_engine.h:99
void SetProgressReporter(PROGRESS_REPORTER *aProgRep)
Set an optional reporter for user-level progress info.
Definition drc_engine.h:131
void SetDebugOverlay(std::shared_ptr< KIGFX::VIEW_OVERLAY > aOverlay)
Definition drc_engine.h:108
void SetDrawingSheet(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Definition drc_engine.h:105
bool GetReportAllTrackErrors() const
Definition drc_engine.h:171
void compileRules()
std::set< int > QueryDistinctConstraints(DRC_CONSTRAINT_T aConstraintId)
DS_PROXY_VIEW_ITEM * m_drawingSheet
Definition drc_engine.h:254
NETLIST * m_schematicNetlist
Definition drc_engine.h:255
bool KeepRefreshing(bool aWait=false)
void SetLogReporter(REPORTER *aReporter)
Definition drc_engine.h:141
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:118
BOARD * m_board
Definition drc_engine.h:253
bool m_reportAllTrackErrors
Definition drc_engine.h:262
bool ReportProgress(double aProgress)
DRC_TEST_PROVIDER * GetTestProvider(const wxString &name) const
bool HasRulesForConstraintType(DRC_CONSTRAINT_T constraintID)
BOARD_DESIGN_SETTINGS * GetDesignSettings() const
Definition drc_engine.h:100
bool RulesValid()
Definition drc_engine.h:174
void SetMaxProgress(int aSize)
DRC_ENGINE(BOARD *aBoard=nullptr, BOARD_DESIGN_SETTINGS *aSettings=nullptr)
DRC_ENGINE(const DRC_ENGINE &)=delete
std::vector< int > m_errorLimits
Definition drc_engine.h:261
bool IsErrorLimitExceeded(int error_code)
void ProcessAssertions(const BOARD_ITEM *a, std::function< void(const DRC_CONSTRAINT *)> aFailureHandler, REPORTER *aReporter=nullptr)
void loadImplicitRules()
DRC_VIOLATION_HANDLER m_violationHandler
Definition drc_engine.h:268
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
std::vector< std::shared_ptr< DRC_RULE > > m_rules
Definition drc_engine.h:257
std::shared_ptr< DRC_RULE > createImplicitRule(const wxString &name)
void ClearViolationHandler()
Definition drc_engine.h:123
void SetSchematicNetlist(NETLIST *aNetlist)
Definition drc_engine.h:102
PROGRESS_REPORTER * GetProgressReporter() const
Definition drc_engine.h:132
bool IsCancelled() const
std::vector< DRC_TEST_PROVIDER * > GetTestProviders() const
Definition drc_engine.h:191
static bool IsNetADiffPair(BOARD *aBoard, NETINFO_ITEM *aNet, int &aNetP, int &aNetN)
bool IsNetTieExclusion(int aTrackNetCode, PCB_LAYER_ID aTrackLayer, const VECTOR2I &aCollisionPos, BOARD_ITEM *aCollidingItem)
Check if the given collision between a track and another item occurs during the track's entry into a ...
virtual ~DRC_ENGINE()
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Definition drc_engine.h:272
bool QueryWorstConstraint(DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT &aConstraint)
NETLIST * GetSchematicNetlist() const
Definition drc_engine.h:103
std::vector< BOARD_ITEM * > GetItemsMatchingCondition(const wxString &aExpression, DRC_CONSTRAINT_T aConstraint=ASSERTION_CONSTRAINT, REPORTER *aReporter=nullptr)
Evaluate a DRC condition against all board items and return matches.
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
DRC_CONSTRAINT EvalZoneConnection(const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Check if the given net is a diff pair, returning its polarity and complement if so.
bool ReportPhase(const wxString &aMessage)
REPORTER * GetLogReporter() const
Definition drc_engine.h:186
bool m_rulesValid
Definition drc_engine.h:258
void SetBoard(BOARD *aBoard)
Definition drc_engine.h:96
BOARD_DESIGN_SETTINGS * m_designSettings
Definition drc_engine.h:252
void ReportViolation(const std::shared_ptr< DRC_ITEM > &aItem, const VECTOR2I &aPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator={})
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:45
Handle the data for a net.
Definition netinfo.h:54
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
The main frame for Pcbnew.
A progress reporter interface for use in multi-threaded environments.
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 drcPrintDebugMessage(int level, const wxString &msg, const char *function, int line)
std::function< void(const std::shared_ptr< DRC_ITEM > &aItem, const VECTOR2I &aPos, int aLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator)> DRC_VIOLATION_HANDLER
Definition drc_engine.h:70
DRC_CONSTRAINT_T
Definition drc_rule.h:47
@ ASSERTION_CONSTRAINT
Definition drc_rule.h:79
EDA_UNITS
Definition eda_units.h:48
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
std::shared_ptr< DRC_RULE > parentRule
Definition drc_engine.h:244
DRC_RULE_CONDITION * condition
Definition drc_engine.h:243
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695