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#pragma once
21
22#include <bitset>
23#include <optional>
24
25#include <wx/intl.h>
26
27#include <kiid.h>
28#include <core/typeinfo.h>
29#include <core/minoptmax.h>
31#include <layer_ids.h>
32#include <lset.h>
33#include <eda_units.h>
34#include <zones.h>
37
38
39class BOARD_ITEM;
40class PCBEXPR_UCODE;
41class DRC_CONSTRAINT;
43
44namespace kiapi::board
45{
46 class CustomRule;
47 class CustomRuleConstraint;
48}
49
50
52{
53public:
54 DRC_RULE();
55 DRC_RULE( const wxString& aName );
56
57 virtual ~DRC_RULE();
58
59 virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
60 {
61 return true;
62 };
63
64 void AddConstraint( DRC_CONSTRAINT& aConstraint );
65 std::optional<DRC_CONSTRAINT> FindConstraint( DRC_CONSTRAINT_T aType );
66
67 static wxString FormatRuleFromProto( const kiapi::board::CustomRule& aRule,
68 wxString* aErrorText = nullptr );
69
71
72 void SetImplicitSource( const DRC_IMPLICIT_SOURCE aImplicitSource ) { m_implicitSource = aImplicitSource; }
73
75
76public:
77 bool m_Unary;
80 wxString m_Name;
82 wxString m_LayerSource;
85 std::vector<DRC_CONSTRAINT> m_Constraints;
87
88private:
90};
91
92
94{
95public:
97 const wxString& aName = wxEmptyString ) :
98 m_Type( aType ),
99 m_Value(),
100 m_DisallowFlags( 0 ),
102 m_Test( nullptr ),
103 m_ImplicitMin( false ),
104 m_name( aName ),
105 m_parentRule( nullptr ),
106 m_minRule( nullptr ),
107 m_optRule( nullptr ),
108 m_maxRule( nullptr )
109 {
110 }
111
112 enum class OPTIONS : std::size_t
113 {
117
118 // Keep this last value - used to statically size the options bitset
120 };
121
122 bool IsNull() const
123 {
124 return m_Type == NULL_CONSTRAINT;
125 }
126
127 bool IsUnary() const;
128
129 const MINOPTMAX<int>& GetValue() const { return m_Value; }
131
135 void SetParentRule( DRC_RULE *aParentRule )
136 {
137 m_parentRule = aParentRule;
138 m_minRule = m_Value.HasMin() ? aParentRule : nullptr;
139 m_optRule = m_Value.HasOpt() ? aParentRule : nullptr;
140 m_maxRule = m_Value.HasMax() ? aParentRule : nullptr;
141 }
142
148
149 void SetValueRules( DRC_RULE* aMinRule, DRC_RULE* aOptRule, DRC_RULE* aMaxRule )
150 {
151 m_minRule = aMinRule;
152 m_optRule = aOptRule;
153 m_maxRule = aMaxRule;
154 }
155
156 DRC_RULE* GetMinRule() const { return m_minRule; }
157 DRC_RULE* GetOptRule() const { return m_optRule; }
158 DRC_RULE* GetMaxRule() const { return m_maxRule; }
159
160 void SetName( const wxString& aName ) { m_name = aName; }
161
162 wxString GetName() const { return GetRuleName( m_parentRule ); }
163
168 wxString GetRuleName( const DRC_RULE* aRule ) const
169 {
170 if( aRule )
171 {
172 if( aRule->IsImplicit() )
173 return aRule->m_Name;
174 else
175 return wxString::Format( _( "rule '%s'" ), aRule->m_Name );
176 }
177
178 return m_name;
179 }
180
182 {
183 if( m_parentRule )
184 return m_parentRule->m_Severity;
185 else
187 }
188
189 void SetOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), true ); }
190
191 void ClearOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), false ); }
192
193 bool GetOption( OPTIONS option ) const
194 {
195 return m_options.test( static_cast<std::size_t>( option ) );
196 }
197
198 void SetOptionsFromOther( const DRC_CONSTRAINT& aOther ) { m_options = aOther.m_options; }
199
200 void ToProto( kiapi::board::CustomRuleConstraint& aProto ) const;
201
202public:
209
210 // Reference layer for NET_CHAIN_RETURN_PATH_CONSTRAINT. Empty means "no
211 // reference layer specified". Stored as a user-visible layer name so it
212 // can survive save/load without layer-id renumbering.
214
215 // Optional reference-zone net for NET_CHAIN_RETURN_PATH_CONSTRAINT. Empty
216 // accepts any zone on the reference layer; non-empty filters zones by net
217 // name (wildcards via WildCompareString).
219
220private:
221 wxString m_name; // For just-in-time constraints
222 DRC_RULE* m_parentRule; // For constraints found in rules
223 DRC_RULE* m_minRule; // Rules that supplied each value, which can differ
224 DRC_RULE* m_optRule; // from m_parentRule when several rules apply
226 std::bitset<static_cast<int>( OPTIONS::NUM_OPTIONS )> m_options; // Constraint-specific option bits
227 // (indexed from DRC_CONSTRAINT::OPTIONS)
228};
229
230
231const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
232 int aConstraint, PCB_LAYER_ID aLayer,
233 wxString* aRuleName = nullptr );
234
235
241bool IsComponentClassSelector( const wxString& aToken );
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
DRC_RULE_CONDITION * m_Test
Definition drc_rule.h:207
DRC_RULE * GetOptRule() const
Definition drc_rule.h:157
wxString GetName() const
Definition drc_rule.h:162
void ToProto(kiapi::board::CustomRuleConstraint &aProto) const
Definition drc_rule.cpp:445
int m_DisallowFlags
Definition drc_rule.h:205
SEVERITY GetSeverity() const
Definition drc_rule.h:181
void SetOption(OPTIONS option)
Definition drc_rule.h:189
DRC_RULE * GetMinRule() const
Definition drc_rule.h:156
DRC_RULE * m_parentRule
Definition drc_rule.h:222
void SetParentRule(DRC_RULE *aParentRule)
Attribute the constraint, including each min, opt and max value it has, to aParentRule.
Definition drc_rule.h:135
MINOPTMAX< int > & Value()
Definition drc_rule.h:130
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:129
DRC_RULE * m_maxRule
Definition drc_rule.h:225
ZONE_CONNECTION m_ZoneConnection
Definition drc_rule.h:206
void SetName(const wxString &aName)
Definition drc_rule.h:160
wxString GetRuleName(const DRC_RULE *aRule) const
Definition drc_rule.h:168
MINOPTMAX< int > m_Value
Definition drc_rule.h:204
wxString m_ReferenceLayer
Definition drc_rule.h:213
DRC_CONSTRAINT_T m_Type
Definition drc_rule.h:203
bool IsUnary() const
Definition drc_rule.cpp:88
DRC_RULE * m_optRule
Definition drc_rule.h:224
DRC_RULE * m_minRule
Definition drc_rule.h:223
void SetOptionsFromOther(const DRC_CONSTRAINT &aOther)
Definition drc_rule.h:198
wxString m_name
Definition drc_rule.h:221
DRC_RULE * GetMaxRule() const
Definition drc_rule.h:158
bool GetOption(OPTIONS option) const
Definition drc_rule.h:193
void SetValueRules(DRC_RULE *aMinRule, DRC_RULE *aOptRule, DRC_RULE *aMaxRule)
Definition drc_rule.h:149
DRC_RULE * GetParentRule() const
Definition drc_rule.h:147
void ClearOption(OPTIONS option)
Definition drc_rule.h:191
DRC_CONSTRAINT(DRC_CONSTRAINT_T aType=NULL_CONSTRAINT, const wxString &aName=wxEmptyString)
Definition drc_rule.h:96
bool m_ImplicitMin
Definition drc_rule.h:208
std::bitset< static_cast< int >(OPTIONS::NUM_OPTIONS)> m_options
Definition drc_rule.h:226
wxString m_ReferenceNet
Definition drc_rule.h:218
bool IsNull() const
Definition drc_rule.h:122
SEVERITY m_Severity
Definition drc_rule.h:86
bool m_Unary
Definition drc_rule.h:77
DRC_RULE_CONDITION * m_Condition
Definition drc_rule.h:84
bool IsImplicit() const
Definition drc_rule.h:70
LSET m_LayerCondition
Definition drc_rule.h:83
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:59
KIID m_ImplicitItemId
Definition drc_rule.h:78
std::vector< DRC_CONSTRAINT > m_Constraints
Definition drc_rule.h:85
BOARD_ITEM * m_ImplicitItem
Definition drc_rule.h:79
wxString m_Name
Definition drc_rule.h:80
void AddConstraint(DRC_CONSTRAINT &aConstraint)
Definition drc_rule.cpp:69
wxString m_LayerSource
Definition drc_rule.h:82
wxString m_ImplicitNetclass
Netclass named by an implicit netclass rule's condition.
Definition drc_rule.h:81
void SetImplicitSource(const DRC_IMPLICIT_SOURCE aImplicitSource)
Definition drc_rule.h:72
virtual ~DRC_RULE()
Definition drc_rule.cpp:63
DRC_IMPLICIT_SOURCE GetImplicitSource() const
Definition drc_rule.h:74
std::optional< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition drc_rule.cpp:76
DRC_IMPLICIT_SOURCE m_implicitSource
Definition drc_rule.h:89
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
DRC_IMPLICIT_SOURCE
@ NULL_CONSTRAINT
const DRC_CONSTRAINT * GetConstraint(const BOARD_ITEM *aItem, const BOARD_ITEM *bItem, int aConstraint, PCB_LAYER_ID aLayer, wxString *aRuleName=nullptr)
bool IsComponentClassSelector(const wxString &aToken)
${Class:X} inside a DRC rule is a component-class selector consumed by testFootprintSelector(),...
Definition drc_rule.cpp:32
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
SEVERITY
@ RPT_SEVERITY_UNDEFINED
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition zones.h:43