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, 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_RULE_H
25#define DRC_RULE_H
26
27#include <bitset>
28#include <kiid.h>
29#include <core/typeinfo.h>
30#include <optional>
31#include <core/minoptmax.h>
32#include <layer_ids.h>
33#include <lset.h>
34#include <eda_units.h>
35#include <zones.h>
37#include <wx/intl.h>
39
40class BOARD_ITEM;
41class PCBEXPR_UCODE;
42class DRC_CONSTRAINT;
44
45namespace kiapi::board
46{
47 class CustomRule;
48 class CustomRuleConstraint;
49}
50
51
92
93
108
109
119
120
123
124
126{
127public:
128 DRC_RULE();
129 DRC_RULE( const wxString& aName );
130
131 virtual ~DRC_RULE();
132
133 virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
134 {
135 return true;
136 };
137
138 void AddConstraint( DRC_CONSTRAINT& aConstraint );
139 std::optional<DRC_CONSTRAINT> FindConstraint( DRC_CONSTRAINT_T aType );
140
141 static wxString FormatRuleFromProto( const kiapi::board::CustomRule& aRule,
142 wxString* aErrorText = nullptr );
143
145
146 void SetImplicitSource( const DRC_IMPLICIT_SOURCE aImplicitSource ) { m_implicitSource = aImplicitSource; }
147
149
150public:
153 wxString m_Name;
157 std::vector<DRC_CONSTRAINT> m_Constraints;
159
160private:
162};
163
164
166{
167public:
169 const wxString& aName = wxEmptyString ) :
170 m_Type( aType ),
171 m_Value(),
172 m_DisallowFlags( 0 ),
174 m_Test( nullptr ),
175 m_ImplicitMin( false ),
176 m_name( aName ),
177 m_parentRule( nullptr )
178 {
179 }
180
181 enum class OPTIONS : std::size_t
182 {
186
187 // Keep this last value - used to statically size the options bitset
189 };
190
191 bool IsNull() const
192 {
193 return m_Type == NULL_CONSTRAINT;
194 }
195
196 const MINOPTMAX<int>& GetValue() const { return m_Value; }
198
199 void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; }
201
202 void SetName( const wxString& aName ) { m_name = aName; }
203
204 wxString GetName() const
205 {
206 if( m_parentRule )
207 {
208 if( m_parentRule->IsImplicit() )
209 return m_parentRule->m_Name;
210 else
211 return wxString::Format( _( "rule '%s'" ), m_parentRule->m_Name );
212 }
213
214 return m_name;
215 }
216
218 {
219 if( m_parentRule )
220 return m_parentRule->m_Severity;
221 else
223 }
224
225 void SetOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), true ); }
226
227 void ClearOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), false ); }
228
229 bool GetOption( OPTIONS option ) const
230 {
231 return m_options.test( static_cast<std::size_t>( option ) );
232 }
233
234 void SetOptionsFromOther( const DRC_CONSTRAINT& aOther ) { m_options = aOther.m_options; }
235
236 void ToProto( kiapi::board::CustomRuleConstraint& aProto ) const;
237
238public:
245
246private:
247 wxString m_name; // For just-in-time constraints
248 DRC_RULE* m_parentRule; // For constraints found in rules
249 std::bitset<static_cast<int>( OPTIONS::NUM_OPTIONS )> m_options; // Constraint-specific option bits
250 // (indexed from DRC_CONSTRAINT::OPTIONS)
251};
252
253
254const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
255 int aConstraint, PCB_LAYER_ID aLayer,
256 wxString* aRuleName = nullptr );
257
258
259#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:243
wxString GetName() const
Definition drc_rule.h:204
void ToProto(kiapi::board::CustomRuleConstraint &aProto) const
Definition drc_rule.cpp:376
int m_DisallowFlags
Definition drc_rule.h:241
SEVERITY GetSeverity() const
Definition drc_rule.h:217
void SetOption(OPTIONS option)
Definition drc_rule.h:225
DRC_RULE * m_parentRule
Definition drc_rule.h:248
void SetParentRule(DRC_RULE *aParentRule)
Definition drc_rule.h:199
MINOPTMAX< int > & Value()
Definition drc_rule.h:197
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:196
ZONE_CONNECTION m_ZoneConnection
Definition drc_rule.h:242
void SetName(const wxString &aName)
Definition drc_rule.h:202
MINOPTMAX< int > m_Value
Definition drc_rule.h:240
DRC_CONSTRAINT_T m_Type
Definition drc_rule.h:239
void SetOptionsFromOther(const DRC_CONSTRAINT &aOther)
Definition drc_rule.h:234
wxString m_name
Definition drc_rule.h:247
bool GetOption(OPTIONS option) const
Definition drc_rule.h:229
DRC_RULE * GetParentRule() const
Definition drc_rule.h:200
void ClearOption(OPTIONS option)
Definition drc_rule.h:227
DRC_CONSTRAINT(DRC_CONSTRAINT_T aType=NULL_CONSTRAINT, const wxString &aName=wxEmptyString)
Definition drc_rule.h:168
bool m_ImplicitMin
Definition drc_rule.h:244
std::bitset< static_cast< int >(OPTIONS::NUM_OPTIONS)> m_options
Definition drc_rule.h:249
bool IsNull() const
Definition drc_rule.h:191
SEVERITY m_Severity
Definition drc_rule.h:158
bool m_Unary
Definition drc_rule.h:151
DRC_RULE_CONDITION * m_Condition
Definition drc_rule.h:156
bool IsImplicit() const
Definition drc_rule.h:144
LSET m_LayerCondition
Definition drc_rule.h:155
static wxString FormatRuleFromProto(const kiapi::board::CustomRule &aRule, wxString *aErrorText=nullptr)
Definition drc_rule.cpp:82
virtual bool AppliesTo(const BOARD_ITEM *a, const BOARD_ITEM *b=nullptr) const
Definition drc_rule.h:133
KIID m_ImplicitItemId
Definition drc_rule.h:152
std::vector< DRC_CONSTRAINT > m_Constraints
Definition drc_rule.h:157
wxString m_Name
Definition drc_rule.h:153
void AddConstraint(DRC_CONSTRAINT &aConstraint)
Definition drc_rule.cpp:63
wxString m_LayerSource
Definition drc_rule.h:154
void SetImplicitSource(const DRC_IMPLICIT_SOURCE aImplicitSource)
Definition drc_rule.h:146
virtual ~DRC_RULE()
Definition drc_rule.cpp:57
DRC_IMPLICIT_SOURCE GetImplicitSource() const
Definition drc_rule.h:148
std::optional< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition drc_rule.cpp:70
DRC_IMPLICIT_SOURCE m_implicitSource
Definition drc_rule.h:161
Definition kiid.h:48
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:122
DRC_IMPLICIT_SOURCE
Definition drc_rule.h:111
DRC_DISALLOW_T
Definition drc_rule.h:95
@ DRC_DISALLOW_PADS
Definition drc_rule.h:101
@ DRC_DISALLOW_BURIED_VIAS
Definition drc_rule.h:99
@ DRC_DISALLOW_BLIND_VIAS
Definition drc_rule.h:98
@ DRC_DISALLOW_TEXTS
Definition drc_rule.h:103
@ DRC_DISALLOW_ZONES
Definition drc_rule.h:102
@ DRC_DISALLOW_HOLES
Definition drc_rule.h:105
@ DRC_DISALLOW_GRAPHICS
Definition drc_rule.h:104
@ DRC_DISALLOW_THROUGH_VIAS
Definition drc_rule.h:96
@ DRC_DISALLOW_FOOTPRINTS
Definition drc_rule.h:106
@ DRC_DISALLOW_TRACKS
Definition drc_rule.h:100
@ DRC_DISALLOW_MICRO_VIAS
Definition drc_rule.h:97
DRC_CONSTRAINT_T
Definition drc_rule.h:53
@ ANNULAR_WIDTH_CONSTRAINT
Definition drc_rule.h:67
@ BRIDGED_MASK_CONSTRAINT
Definition drc_rule.h:89
@ COURTYARD_CLEARANCE_CONSTRAINT
Definition drc_rule.h:61
@ VIA_DIAMETER_CONSTRAINT
Definition drc_rule.h:76
@ ZONE_CONNECTION_CONSTRAINT
Definition drc_rule.h:68
@ DIFF_PAIR_GAP_CONSTRAINT
Definition drc_rule.h:79
@ VIA_DANGLING_CONSTRAINT
Definition drc_rule.h:88
@ SOLDER_MASK_SLIVER_CONSTRAINT
Definition drc_rule.h:90
@ DISALLOW_CONSTRAINT
Definition drc_rule.h:75
@ TRACK_WIDTH_CONSTRAINT
Definition drc_rule.h:65
@ SILK_CLEARANCE_CONSTRAINT
Definition drc_rule.h:62
@ EDGE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:59
@ MIN_RESOLVED_SPOKES_CONSTRAINT
Definition drc_rule.h:71
@ TRACK_SEGMENT_LENGTH_CONSTRAINT
Definition drc_rule.h:66
@ TEXT_THICKNESS_CONSTRAINT
Definition drc_rule.h:64
@ LENGTH_CONSTRAINT
Definition drc_rule.h:77
@ VIA_COUNT_CONSTRAINT
Definition drc_rule.h:82
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:84
@ CLEARANCE_CONSTRAINT
Definition drc_rule.h:55
@ NULL_CONSTRAINT
Definition drc_rule.h:54
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
Definition drc_rule.h:70
@ CONNECTION_WIDTH_CONSTRAINT
Definition drc_rule.h:86
@ THERMAL_RELIEF_GAP_CONSTRAINT
Definition drc_rule.h:69
@ MAX_UNCOUPLED_CONSTRAINT
Definition drc_rule.h:80
@ ASSERTION_CONSTRAINT
Definition drc_rule.h:85
@ SKEW_CONSTRAINT
Definition drc_rule.h:78
@ HOLE_CLEARANCE_CONSTRAINT
Definition drc_rule.h:57
@ SOLDER_PASTE_ABS_MARGIN_CONSTRAINT
Definition drc_rule.h:73
@ SOLDER_MASK_EXPANSION_CONSTRAINT
Definition drc_rule.h:72
@ TRACK_ANGLE_CONSTRAINT
Definition drc_rule.h:87
@ HOLE_SIZE_CONSTRAINT
Definition drc_rule.h:60
@ TEXT_HEIGHT_CONSTRAINT
Definition drc_rule.h:63
@ CREEPAGE_CONSTRAINT
Definition drc_rule.h:56
@ DIFF_PAIR_INTRA_SKEW_CONSTRAINT
Definition drc_rule.h:81
@ PHYSICAL_CLEARANCE_CONSTRAINT
Definition drc_rule.h:83
@ SOLDER_PASTE_REL_MARGIN_CONSTRAINT
Definition drc_rule.h:74
@ HOLE_TO_HOLE_CONSTRAINT
Definition drc_rule.h:58
constexpr int DRC_DISALLOW_VIAS
Definition drc_rule.h:121
#define _(s)
@ NONE
Definition eda_shape.h:71
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
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:47