KiCad PCB EDA Suite
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 (C) 2019-2020 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 #ifndef DRC_ENGINE_H
25 #define DRC_ENGINE_H
26 
27 #include <board_commit.h>
28 #include <class_board.h>
29 #include <class_marker_pcb.h>
30 #include <class_track.h>
31 #include <geometry/seg.h>
33 #include <memory>
34 #include <tools/pcb_tool_base.h>
35 #include <vector>
36 
37 
38 #include <drc_proto/drc_rule.h>
39 
41 class PCB_EDIT_FRAME;
42 class DIALOG_DRC;
43 class BOARD_ITEM;
44 class BOARD;
45 class D_PAD;
46 class ZONE_CONTAINER;
47 class TRACK;
48 class MARKER_PCB;
49 class NETCLASS;
50 class EDA_TEXT;
51 class DRAWSEGMENT;
52 class NETLIST;
53 class PROGRESS_REPORTER;
54 class REPORTER;
55 
56 namespace test
57 {
58 
59 class DRC_RULE_CONDITION;
60 class DRC_ITEM;
61 class DRC_RULE;
62 class DRC_TEST_PROVIDER;
63 class DRC_CONSTRAINT;
64 
67 {
100 
102 
104 };
105 
106 
116 {
117 
118 public:
119  DRC_ENGINE( BOARD* aBoard, BOARD_DESIGN_SETTINGS* aSettings );
120  ~DRC_ENGINE();
121 
123  {
124  m_progressReporter = aProgRep;
125  }
126 
127  void SetLogReporter( REPORTER* aReporter )
128  {
129  m_reporter = aReporter;
130  }
131 
132  bool LoadRules( wxFileName aPath );
133  void RunTests();
134 
135  void SetErrorLimit( int aLimit );
136 
138  {
139  return m_designSettings;
140  }
141  BOARD* GetBoard() const
142  {
143  return m_board;
144  }
145 
147  DRC_RULE_ID_T ruleID, BOARD_ITEM* a, BOARD_ITEM* b = nullptr );
148 
149  std::vector<DRC_RULE*> QueryRulesById( test::DRC_RULE_ID_T ruleID );
150 
152 
154  {
155  return EDA_UNITS::MILLIMETRES;
156  }
157 
158  bool CompileRules();
159 
160  void Report( DRC_ITEM* aItem, ::MARKER_PCB *Marker );
161  void ReportProgress( double aProgress );
162  void ReportStage ( const wxString& aStageName, int index, int total );
163  void ReportAux( const wxString& aStr );
164 
165 private:
166 
167  void freeCompiledRules();
168 
170  {
171  std::vector<test::DRC_RULE_CONDITION*> conditions;
173  };
174 
175  struct RULE_SET
176  {
177  std::vector<RULE_WITH_CONDITIONS*> sortedRules;
180  };
181 
182  typedef std::unordered_map<test::DRC_RULE_ID_T, RULE_SET*> RULE_MAP;
183 
184 
185  void inferImplicitRules();
186  void loadTestProviders();
187 
190  std::vector<DRC_ITEM*> m_drcItems;
191 
192  std::vector<DRC_RULE_CONDITION*> m_ruleConditions;
193  std::vector<DRC_RULE*> m_rules;
194  std::vector<DRC_TEST_PROVIDER*> m_testProviders;
195  std::unordered_map<EDA_ITEM*, RULE_SET*> m_implicitRules;
196  std::vector<::MARKER_PCB*> m_markers;
200 
201  // condition -> rule -> provider
202 };
203 
204 void drc_dbg( int level, const char* fmt, ... );
205 
206 }; // namespace test
207 
208 #endif // DRC_H
std::vector< RULE_WITH_CONDITIONS * > sortedRules
Definition: drc_engine.h:177
EDA_UNITS
Definition: common.h:198
a copper item is too close to the board edge
Definition: drc_engine.h:74
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
overlapping drilled holes break drill bits
Definition: drc_engine.h:79
void inferImplicitRules()
Definition: drc_engine.cpp:108
Via size and drill leave annulus too small or too large.
Definition: drc_engine.h:82
void drc_dbg(int level, const char *fmt,...)
Definition: drc_engine.cpp:116
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void freeCompiledRules()
std::unordered_map< EDA_ITEM *, RULE_SET * > m_implicitRules
Definition: drc_engine.h:195
REPORTER * m_reporter
Definition: drc_engine.h:198
A progress reporter for use in multi-threaded environments.
footprint not found for netlist item
Definition: drc_engine.h:97
void SetLogReporter(REPORTER *aReporter)
Definition: drc_engine.h:127
std::vector< DRC_RULE_CONDITION * > m_ruleConditions
Definition: drc_engine.h:192
Too small via or pad drill.
Definition: drc_engine.h:83
bool LoadRules(wxFileName aPath)
Definition: drc_engine.cpp:66
BOARD_DESIGN_SETTINGS * m_designSettings
Definition: drc_engine.h:188
item on a disabled layer
Definition: drc_engine.h:95
items are too close together
Definition: drc_engine.h:72
std::vector< DRC_TEST_PROVIDER * > m_testProviders
Definition: drc_engine.h:194
std::vector< DRC_RULE * > QueryRulesById(test::DRC_RULE_ID_T ruleID)
Definition: drc_engine.cpp:334
netlist item not found for footprint
Definition: drc_engine.h:99
items shorting two nets but not a net-tie
Definition: drc_engine.h:70
A disallowed object is inside a keepout.
Definition: drc_engine.h:88
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
std::vector< DRC_ITEM * > m_drcItems
Definition: drc_engine.h:190
DRC_ENGINE(BOARD *aBoard, BOARD_DESIGN_SETTINGS *aSettings)
Definition: drc_engine.cpp:40
Too small micro via drill.
Definition: drc_engine.h:87
void ReportProgress(double aProgress)
Definition: drc_engine.cpp:298
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
items are unconnected
Definition: drc_engine.h:69
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
std::vector<::MARKER_PCB * > m_markers
Definition: drc_engine.h:196
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:113
track with at least one end not connected to anything
Definition: drc_engine.h:78
Markers used to show a drc problem on boards.
DRC_TEST_PROVIDER * provider
Definition: drc_engine.h:179
void loadTestProviders()
via's hole is bigger than its diameter
Definition: drc_engine.h:84
Design Rule Checker object that performs all the DRC tests.
Definition: drc_engine.h:115
PCB_DRC_CODE
DRC error codes:
Definition: drc_engine.h:66
footprint has a courtyard but malformed (not convertible to a closed polygon with holes)
Definition: drc_engine.h:91
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:186
Too small micro via size.
Definition: drc_engine.h:86
void ReportStage(const wxString &aStageName, int index, int total)
Definition: drc_engine.cpp:306
invalid board outline
Definition: drc_engine.h:96
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
std::unordered_map< test::DRC_RULE_ID_T, RULE_SET * > RULE_MAP
Definition: drc_engine.h:182
void ReportAux(const wxString &aStr)
Definition: drc_engine.cpp:289
void SetProgressReporter(PROGRESS_REPORTER *aProgRep)
Definition: drc_engine.h:122
void Report(DRC_ITEM *aItem, ::MARKER_PCB *Marker)
Definition: drc_engine.cpp:270
something is wrong with a pad or via stackup
Definition: drc_engine.h:85
Track width is too small or too large.
Definition: drc_engine.h:80
copper area has a net but no pads in nets, which is suspicious
Definition: drc_engine.h:76
DRC_RULE * EvalRulesForItems(DRC_RULE_ID_T ruleID, BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
Definition: drc_engine.cpp:236
std::vector< DRC_RULE * > m_rules
Definition: drc_engine.h:193
footprint has no courtyard defined
Definition: drc_engine.h:90
RULE_MAP m_ruleMap
Definition: drc_engine.h:197
Too small via size.
Definition: drc_engine.h:81
EDA_UNITS UserUnits() const
Definition: drc_engine.h:153
footprint courtyards overlap
Definition: drc_engine.h:89
void SetErrorLimit(int aLimit)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
more than one footprints found for netlist item
Definition: drc_engine.h:98
std::vector< test::DRC_RULE_CONDITION * > conditions
Definition: drc_engine.h:171
PCB_EDIT_FRAME is the main frame for Pcbnew.
PROGRESS_REPORTER * m_progressReporter
Definition: drc_engine.h:199
BOARD * GetBoard() const
Definition: drc_engine.h:141
tracks are crossing
Definition: drc_engine.h:73
a disallowed item has been used
Definition: drc_engine.h:71
BOARD_DESIGN_SETTINGS * GetDesignSettings() const
Definition: drc_engine.h:137
copper area outlines intersect
Definition: drc_engine.h:75
via which isn't connected to anything
Definition: drc_engine.h:77
bool HasCorrectRulesForId(test::DRC_RULE_ID_T ruleID)
Definition: drc_engine.cpp:355
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.