KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_rule.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#ifndef DRC_RULE_H
21#define DRC_RULE_H
22
23#include <bitset>
24#include <kiid.h>
25#include <core/typeinfo.h>
26#include <optional>
27#include <core/minoptmax.h>
28#include <layer_ids.h>
29#include <lset.h>
30#include <eda_units.h>
31#include <zones.h>
33#include <wx/intl.h>
35
36class BOARD_ITEM;
37class PCBEXPR_UCODE;
38class DRC_CONSTRAINT;
40
41namespace kiapi::board
42{
43 class CustomRule;
44 class CustomRuleConstraint;
45}
46
47
93
94
109
110
120
121
124
125
127{
128public:
129 DRC_RULE();
130 DRC_RULE( const wxString& aName );
131
132 virtual ~DRC_RULE();
133
134 virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
135 {
136 return true;
137 };
138
139 void AddConstraint( DRC_CONSTRAINT& aConstraint );
140 std::optional<DRC_CONSTRAINT> FindConstraint( DRC_CONSTRAINT_T aType );
141
142 static wxString FormatRuleFromProto( const kiapi::board::CustomRule& aRule,
143 wxString* aErrorText = nullptr );
144
146
147 void SetImplicitSource( const DRC_IMPLICIT_SOURCE aImplicitSource ) { m_implicitSource = aImplicitSource; }
148
150
151public:
155 wxString m_Name;
160 std::vector<DRC_CONSTRAINT> m_Constraints;
162
163private:
165};
166
167
169{
170public:
172 const wxString& aName = wxEmptyString ) :
173 m_Type( aType ),
174 m_Value(),
175 m_DisallowFlags( 0 ),
177 m_Test( nullptr ),
178 m_ImplicitMin( false ),
179 m_name( aName ),
180 m_parentRule( nullptr ),
181 m_minRule( nullptr ),
182 m_optRule( nullptr ),
183 m_maxRule( nullptr )
184 {
185 }
186
187 enum class OPTIONS : std::size_t
188 {
192
193 // Keep this last value - used to statically size the options bitset
195 };
196
197 bool IsNull() const
198 {
199 return m_Type == NULL_CONSTRAINT;
200 }
201
202 bool IsUnary() const;
203
204 const MINOPTMAX<int>& GetValue() const { return m_Value; }
206
210 void SetParentRule( DRC_RULE *aParentRule )
211 {
212 m_parentRule = aParentRule;
213 m_minRule = m_Value.HasMin() ? aParentRule : nullptr;
214 m_optRule = m_Value.HasOpt() ? aParentRule : nullptr;
215 m_maxRule = m_Value.HasMax() ? aParentRule : nullptr;
216 }
217
223
224 void SetValueRules( DRC_RULE* aMinRule, DRC_RULE* aOptRule, DRC_RULE* aMaxRule )
225 {
226 m_minRule = aMinRule;
227 m_optRule = aOptRule;
228 m_maxRule = aMaxRule;
229 }
230
231 DRC_RULE* GetMinRule() const { return m_minRule; }
232 DRC_RULE* GetOptRule() const { return m_optRule; }
233 DRC_RULE* GetMaxRule() const { return m_maxRule; }
234
235 void SetName( const wxString& aName ) { m_name = aName; }
236
237 wxString GetName() const { return GetRuleName( m_parentRule ); }
238
243 wxString GetRuleName( const DRC_RULE* aRule ) const
244 {
245 if( aRule )
246 {
247 if( aRule->IsImplicit() )
248 return aRule->m_Name;
249 else
250 return wxString::Format( _( "rule '%s'" ), aRule->m_Name );
251 }
252
253 return m_name;
254 }
255
257 {
258 if( m_parentRule )
259 return m_parentRule->m_Severity;
260 else
262 }
263
264 void SetOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), true ); }
265
266 void ClearOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), false ); }
267
268 bool GetOption( OPTIONS option ) const
269 {
270 return m_options.test( static_cast<std::size_t>( option ) );
271 }
272
273 void SetOptionsFromOther( const DRC_CONSTRAINT& aOther ) { m_options = aOther.m_options; }
274
275 void ToProto( kiapi::board::CustomRuleConstraint& aProto ) const;
276
277public:
284
285 // Reference layer for NET_CHAIN_RETURN_PATH_CONSTRAINT. Empty means "no
286 // reference layer specified". Stored as a user-visible layer name so it
287 // can survive save/load without layer-id renumbering.
289
290 // Optional reference-zone net for NET_CHAIN_RETURN_PATH_CONSTRAINT. Empty
291 // accepts any zone on the reference layer; non-empty filters zones by net
292 // name (wildcards via WildCompareString).
294
295private:
296 wxString m_name; // For just-in-time constraints
297 DRC_RULE* m_parentRule; // For constraints found in rules
298 DRC_RULE* m_minRule; // Rules that supplied each value, which can differ
299 DRC_RULE* m_optRule; // from m_parentRule when several rules apply
301 std::bitset<static_cast<int>( OPTIONS::NUM_OPTIONS )> m_options; // Constraint-specific option bits
302 // (indexed from DRC_CONSTRAINT::OPTIONS)
303};
304
305
306const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
307 int aConstraint, PCB_LAYER_ID aLayer,
308 wxString* aRuleName = nullptr );
309
310
316bool IsComponentClassSelector( const wxString& aToken );
317
318
319#endif // DRC_RULE_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
DRC_RULE_CONDITION * m_Test
Definition drc_rule.h:282
DRC_RULE * GetOptRule() const
Definition drc_rule.h:232
wxString GetName() const
Definition drc_rule.h:237
void ToProto(kiapi::board::CustomRuleConstraint &aProto) const
Definition drc_rule.cpp:415
int m_DisallowFlags
Definition drc_rule.h:280
SEVERITY GetSeverity() const
Definition drc_rule.h:256
void SetOption(OPTIONS option)
Definition drc_rule.h:264
DRC_RULE * GetMinRule() const
Definition drc_rule.h:231
DRC_RULE * m_parentRule
Definition drc_rule.h:297
void SetParentRule(DRC_RULE *aParentRule)
Attribute the constraint, including each min, opt and max value it has, to aParentRule.
Definition drc_rule.h:210
MINOPTMAX< int > & Value()
Definition drc_rule.h:205
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:204
DRC_RULE * m_maxRule
Definition drc_rule.h:300
ZONE_CONNECTION m_ZoneConnection
Definition drc_rule.h:281
void SetName(const wxString &aName)
Definition drc_rule.h:235
wxString GetRuleName(const DRC_RULE *aRule) const
Definition drc_rule.h:243
MINOPTMAX< int > m_Value
Definition drc_rule.h:279
wxString m_ReferenceLayer
Definition drc_rule.h:288
DRC_CONSTRAINT_T m_Type
Definition drc_rule.h:278
bool IsUnary() const
Definition drc_rule.cpp:87
DRC_RULE * m_optRule
Definition drc_rule.h:299
DRC_RULE * m_minRule
Definition drc_rule.h:298
void SetOptionsFromOther(const DRC_CONSTRAINT &aOther)
Definition drc_rule.h:273
wxString m_name
Definition drc_rule.h:296
DRC_RULE * GetMaxRule() const
Definition drc_rule.h:233
bool GetOption(OPTIONS option) const
Definition drc_rule.h:268
void SetValueRules(DRC_RULE *aMinRule, DRC_RULE *aOptRule, DRC_RULE *aMaxRule)
Definition drc_rule.h:224
DRC_RULE * GetParentRule() const
Definition drc_rule.h:222
void ClearOption(OPTIONS option)
Definition drc_rule.h:266
DRC_CONSTRAINT(DRC_CONSTRAINT_T aType=NULL_CONSTRAINT, const wxString &aName=wxEmptyString)
Definition drc_rule.h:171
bool m_ImplicitMin
Definition drc_rule.h:283
std::bitset< static_cast< int >(OPTIONS::NUM_OPTIONS)> m_options
Definition drc_rule.h:301
wxString m_ReferenceNet
Definition drc_rule.h:293
bool IsNull() const
Definition drc_rule.h:197
SEVERITY m_Severity
Definition drc_rule.h:161
bool m_Unary
Definition drc_rule.h:152
DRC_RULE_CONDITION * m_Condition
Definition drc_rule.h:159
bool IsImplicit() const
Definition drc_rule.h:145
LSET m_LayerCondition
Definition drc_rule.h:158
static wxString FormatRuleFromProto(const kiapi::board::CustomRule &aRule, wxString *aErrorText=nullptr)
Definition drc_rule.cpp:121
virtual bool AppliesTo(const BOARD_ITEM *a, const BOARD_ITEM *b=nullptr) const
Definition drc_rule.h:134
KIID m_ImplicitItemId
Definition drc_rule.h:153
std::vector< DRC_CONSTRAINT > m_Constraints
Definition drc_rule.h:160
BOARD_ITEM * m_ImplicitItem
Definition drc_rule.h:154
wxString m_Name
Definition drc_rule.h:155
void AddConstraint(DRC_CONSTRAINT &aConstraint)
Definition drc_rule.cpp:68
wxString m_LayerSource
Definition drc_rule.h:157
wxString m_ImplicitNetclass
Netclass named by an implicit netclass rule's condition.
Definition drc_rule.h:156
void SetImplicitSource(const DRC_IMPLICIT_SOURCE aImplicitSource)
Definition drc_rule.h:147
virtual ~DRC_RULE()
Definition drc_rule.cpp:62
DRC_IMPLICIT_SOURCE GetImplicitSource() const
Definition drc_rule.h:149
std::optional< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition drc_rule.cpp:75
DRC_IMPLICIT_SOURCE m_implicitSource
Definition drc_rule.h:164
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
const DRC_CONSTRAINT * GetConstraint(const BOARD_ITEM *aItem, const BOARD_ITEM *bItem, int aConstraint, PCB_LAYER_ID aLayer, wxString *aRuleName=nullptr)
constexpr int DRC_DISALLOW_BB_VIAS
Definition drc_rule.h:123
DRC_IMPLICIT_SOURCE
Definition drc_rule.h:112
bool IsComponentClassSelector(const wxString &aToken)
${Class:X} inside a DRC rule is a component-class selector consumed by testFootprintSelector(),...
Definition drc_rule.cpp:31
DRC_DISALLOW_T
Definition drc_rule.h:96
@ DRC_DISALLOW_PADS
Definition drc_rule.h:102
@ DRC_DISALLOW_BURIED_VIAS
Definition drc_rule.h:100
@ DRC_DISALLOW_BLIND_VIAS
Definition drc_rule.h:99
@ DRC_DISALLOW_TEXTS
Definition drc_rule.h:104
@ DRC_DISALLOW_ZONES
Definition drc_rule.h:103
@ DRC_DISALLOW_HOLES
Definition drc_rule.h:106
@ DRC_DISALLOW_GRAPHICS
Definition drc_rule.h:105
@ DRC_DISALLOW_THROUGH_VIAS
Definition drc_rule.h:97
@ DRC_DISALLOW_FOOTPRINTS
Definition drc_rule.h:107
@ DRC_DISALLOW_TRACKS
Definition drc_rule.h:101
@ DRC_DISALLOW_MICRO_VIAS
Definition drc_rule.h:98
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ ANNULAR_WIDTH_CONSTRAINT
Definition drc_rule.h:63
@ BRIDGED_MASK_CONSTRAINT
Definition drc_rule.h:88
@ COURTYARD_CLEARANCE_CONSTRAINT
Definition drc_rule.h:57
@ VIA_DIAMETER_CONSTRAINT
Definition drc_rule.h:72
@ ZONE_CONNECTION_CONSTRAINT
Definition drc_rule.h:64
@ DIFF_PAIR_GAP_CONSTRAINT
Definition drc_rule.h:78
@ NET_CHAIN_LENGTH_CONSTRAINT
Definition drc_rule.h:74
@ VIA_DANGLING_CONSTRAINT
Definition drc_rule.h:87
@ SOLDER_MASK_SLIVER_CONSTRAINT
Definition drc_rule.h:89
@ NET_CHAIN_STUB_LENGTH_CONSTRAINT
Definition drc_rule.h:75
@ DISALLOW_CONSTRAINT
Definition drc_rule.h:71
@ TRACK_WIDTH_CONSTRAINT
Definition drc_rule.h:61
@ SILK_CLEARANCE_CONSTRAINT
Definition drc_rule.h:58
@ EDGE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:55
@ MIN_RESOLVED_SPOKES_CONSTRAINT
Definition drc_rule.h:67
@ TRACK_SEGMENT_LENGTH_CONSTRAINT
Definition drc_rule.h:62
@ TEXT_THICKNESS_CONSTRAINT
Definition drc_rule.h:60
@ LENGTH_CONSTRAINT
Definition drc_rule.h:73
@ VIA_COUNT_CONSTRAINT
Definition drc_rule.h:81
@ NET_CHAIN_RETURN_PATH_CONSTRAINT
Definition drc_rule.h:76
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:83
@ CLEARANCE_CONSTRAINT
Definition drc_rule.h:51
@ MICROVIA_ASPECT_RATIO_CONSTRAINT
Definition drc_rule.h:91
@ NULL_CONSTRAINT
Definition drc_rule.h:50
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
Definition drc_rule.h:66
@ CONNECTION_WIDTH_CONSTRAINT
Definition drc_rule.h:85
@ THERMAL_RELIEF_GAP_CONSTRAINT
Definition drc_rule.h:65
@ MAX_UNCOUPLED_CONSTRAINT
Definition drc_rule.h:79
@ ASSERTION_CONSTRAINT
Definition drc_rule.h:84
@ SKEW_CONSTRAINT
Definition drc_rule.h:77
@ MICROVIA_STACK_DEPTH_CONSTRAINT
Definition drc_rule.h:90
@ HOLE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:53
@ SOLDER_PASTE_ABS_MARGIN_CONSTRAINT
Definition drc_rule.h:69
@ SOLDER_MASK_EXPANSION_CONSTRAINT
Definition drc_rule.h:68
@ TRACK_ANGLE_CONSTRAINT
Definition drc_rule.h:86
@ HOLE_SIZE_CONSTRAINT
Definition drc_rule.h:56
@ TEXT_HEIGHT_CONSTRAINT
Definition drc_rule.h:59
@ CREEPAGE_CONSTRAINT
Definition drc_rule.h:52
@ DIFF_PAIR_INTRA_SKEW_CONSTRAINT
Definition drc_rule.h:80
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition drc_rule.h:82
@ SOLDER_PASTE_REL_MARGIN_CONSTRAINT
Definition drc_rule.h:70
@ HOLE_TO_HOLE_CONSTRAINT
Definition drc_rule.h:54
constexpr int DRC_DISALLOW_VIAS
Definition drc_rule.h:122
#define _(s)
@ NONE
Definition eda_fill.h:42
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
SEVERITY
@ RPT_SEVERITY_UNDEFINED
Represents a single line in the tuning profile configuration grid.
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition zones.h:43