KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netclass.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) 2009 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2009 Jean-Pierre Charras, [email protected]
6 * Copyright (C) 2009-2022 KiCad Developers, see change_log.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef CLASS_NETCLASS_H
27#define CLASS_NETCLASS_H
28
29#include <optional>
30
31#include <gal/color4d.h>
32#include <kicommon.h>
33#include <macros_swig.h>
34#include <stroke_params.h>
35
36using KIGFX::COLOR4D;
37
38DECL_SET_FOR_SWIG( STRINGSET, wxString )
39
40
44{
45public:
46 static const char Default[];
47
54 NETCLASS( const wxString& aName, bool aInitWithDefaults = true );
55
57
58 bool operator==( const NETCLASS& other ) const;
59
60 wxString GetClass() const
61 {
62 return wxT( "NETCLASS" );
63 }
64
66 void ResetParents();
67
69 void ResetParameters();
70
72 // For a root netcless, this is the netclass this pointer, for aggregate netclasses is contains
73 // all constituent netclasses, in order of priority.
74 const std::vector<NETCLASS*>& GetConstituentNetclasses() const;
75
77 void SetConstituentNetclasses( std::vector<NETCLASS*>&& constituents );
78
81 const wxString GetVariableSubstitutionName() const;
82
85 bool ContainsNetclassWithName( const wxString& netclass ) const;
86
88 bool IsDefault() const { return m_isDefault; }
89
91 const wxString GetName() const;
92 void SetName( const wxString& aName )
93 {
94 m_Name = aName;
95
96 if( aName == Default )
97 m_isDefault = true;
98 }
99
100 const wxString& GetDescription() const { return m_Description; }
101 void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
102
103 bool HasClearance() const { return (bool) m_Clearance; }
104 int GetClearance() const { return m_Clearance.value_or(-1); }
105 std::optional<int> GetClearanceOpt() const { return m_Clearance; }
106 void SetClearance( int aClearance ) { m_Clearance = aClearance; }
107 void SetClearance( std::optional<int> aClearance ) { m_Clearance = aClearance; }
108 void SetClearanceParent( NETCLASS* parent) { m_clearanceParent = parent; }
109 NETCLASS* GetClearanceParent() const { return m_clearanceParent; }
110
111 bool HasTrackWidth() const { return (bool) m_TrackWidth; }
112 int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); }
113 std::optional<int> GetTrackWidthOpt() const { return m_TrackWidth; }
114 void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
115 void SetTrackWidth( std::optional<int> aWidth ) { m_TrackWidth = aWidth; }
116 void SetTrackWidthParent( NETCLASS* parent) { m_trackWidthParent = parent; }
117 NETCLASS* GetTrackWidthParent() const { return m_trackWidthParent; }
118
119 bool HasViaDiameter() const { return (bool) m_ViaDia; }
120 int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); }
121 std::optional<int> GetViaDiameterOpt() const { return m_ViaDia; }
122 void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
123 void SetViaDiameter( std::optional<int> aDia ) { m_ViaDia = aDia; }
124 void SetViaDiameterParent( NETCLASS* parent) { m_viaDiameterParent = parent; }
125 NETCLASS* GetViaDiameterParent() const { return m_viaDiameterParent; }
126
127 int HasViaDrill() const { return (bool) m_ViaDrill; }
128 int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); }
129 std::optional<int> GetViaDrillOpt() const { return m_ViaDrill; }
130 void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
131 void SetViaDrill( std::optional<int> aSize ) { m_ViaDrill = aSize; }
132 void SetViaDrillParent( NETCLASS* parent) { m_viaDrillParent = parent; }
133 NETCLASS* GetViaDrillParent() const { return m_viaDrillParent; }
134
135 bool HasuViaDiameter() const { return (bool) m_uViaDia; }
136 int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); }
137 std::optional<int> GetuViaDiameterOpt() const { return m_uViaDia; }
138 void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
139 void SetuViaDiameter( std::optional<int> aSize ) { m_uViaDia = aSize; }
140 void SetuViaDiameterParent( NETCLASS* parent) { m_uViaDiaParent = parent; }
141 NETCLASS* GetuViaDiameterParent() const { return m_uViaDiaParent; }
142
143 bool HasuViaDrill() const { return (bool) m_uViaDrill; }
144 int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); }
145 std::optional<int> GetuViaDrillOpt() const { return m_uViaDrill; }
146 void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
147 void SetuViaDrill( std::optional<int> aSize ) { m_uViaDrill = aSize; }
148 void SetuViaDrillParent( NETCLASS* parent) { m_uViaDrillParent = parent; }
149 NETCLASS* GetuViaDrillParent() const { return m_uViaDrillParent; }
150
151 bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; }
152 int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); }
153 std::optional<int> GetDiffPairWidthOpt() const { return m_diffPairWidth; }
154 void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
155 void SetDiffPairWidth( std::optional<int> aSize ) { m_diffPairWidth = aSize; }
156 void SetDiffPairWidthParent( NETCLASS* parent) { m_diffPairWidthParent = parent; }
157 NETCLASS* GetDiffPairWidthParent() const { return m_diffPairWidthParent; }
158
159 bool HasDiffPairGap() const { return (bool) m_diffPairGap; }
160 int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); }
161 std::optional<int> GetDiffPairGapOpt() const { return m_diffPairGap; }
162 void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
163 void SetDiffPairGap( std::optional<int> aSize ) { m_diffPairGap = aSize; }
164 void SetDiffPairGapParent( NETCLASS* parent) { m_diffPairGapParent = parent; }
165 NETCLASS* GetDiffPairGapParent() const { return m_diffPairGapParent; }
166
167 bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; }
168 int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); }
169 std::optional<int> GetDiffPairViaGapOpt() const { return m_diffPairViaGap; }
170 void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
171 void SetDiffPairViaGap( std::optional<int> aSize ) { m_diffPairViaGap = aSize; }
172 void SetDiffPairViaGapParent( NETCLASS* parent) { m_diffPairViaGapParent = parent; }
173 NETCLASS* GetDiffPairViaGapParent() const { return m_diffPairViaGapParent; }
174
175 bool HasPcbColor() const { return m_isDefault ? false : m_pcbColor != COLOR4D::UNSPECIFIED; }
176 COLOR4D GetPcbColor( bool aIsForSave = false ) const
177 {
178 // If we are saving netclases, return the underlying color (which may be set from an old
179 // schematic with a default color set - this allows us to roll back the no-default-colors
180 // changes later if required)
181 if( aIsForSave || !m_isDefault )
182 return m_pcbColor;
183
185 }
186 void SetPcbColor( const COLOR4D& aColor ) { m_pcbColor = aColor; }
187 void SetPcbColorParent( NETCLASS* parent) { m_pcbColorParent = parent; }
188 NETCLASS* GetPcbColorParent() const { return m_pcbColorParent; }
189
190 bool HasWireWidth() const { return (bool) m_wireWidth; }
191 int GetWireWidth() const { return m_wireWidth.value_or( -1 ); }
192 std::optional<int> GetWireWidthOpt() const { return m_wireWidth; }
193 void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
194 void SetWireWidth( std::optional<int> aWidth ) { m_wireWidth = aWidth; }
195 void SetWireWidthParent( NETCLASS* parent) { m_wireWidthParent = parent; }
196 NETCLASS* GetWireWidthParent() const { return m_wireWidthParent; }
197
198 bool HasBusWidth() const { return (bool) m_busWidth; }
199 int GetBusWidth() const { return m_busWidth.value_or( -1 ); }
200 std::optional<int> GetBusWidthOpt() const { return m_busWidth; }
201 void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
202 void SetBusWidth( std::optional<int> aWidth ) { m_busWidth = aWidth; }
203 void SetBusWidthParent( NETCLASS* parent) { m_busWidthParent = parent; }
204 NETCLASS* GetBusWidthParent() const { return m_busWidthParent; }
205
206 COLOR4D GetSchematicColor( bool aIsForSave = false ) const
207 {
208 // If we are saving netclases, return the underlying color (which may be set from an old
209 // schematic with a default color set - this allows us to roll back the no-default-colors
210 // changes later if required)
211 if( aIsForSave || !m_isDefault )
212 return m_schematicColor;
213
215 }
216 void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
217 void SetSchematicColorParent( NETCLASS* parent) { m_schematicColorParent = parent; }
218 NETCLASS* GetSchematicColorParent() const { return m_schematicColorParent; }
219
220 bool HasLineStyle() const { return (bool) m_lineStyle; }
221 int GetLineStyle() const { return m_lineStyle.value_or( 0 ); }
222 std::optional<int> GetLineStyleOpt() const { return m_lineStyle; }
223 void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
224 void SetLineStyle( std::optional<int> aStyle ) { m_lineStyle = aStyle; }
225 void SetLineStyleParent( NETCLASS* parent) { m_lineStyleParent = parent; }
226 NETCLASS* GetLineStyleParent() const { return m_lineStyleParent; }
227
228 void SetPriority( int aPriority ) { m_Priority = aPriority; }
229 int GetPriority() const { return m_Priority; }
230
231protected:
233
234 std::vector<NETCLASS*> m_constituents;
235
236 wxString m_Name;
238 wxString m_Description;
239
240 std::optional<int> m_Clearance;
241
242 std::optional<int> m_TrackWidth;
243 std::optional<int> m_ViaDia;
244 std::optional<int> m_ViaDrill;
245
246 std::optional<int> m_uViaDia;
247 std::optional<int> m_uViaDrill;
248
249 std::optional<int> m_diffPairWidth;
250 std::optional<int> m_diffPairGap;
251 std::optional<int> m_diffPairViaGap;
252
253 std::optional<int> m_wireWidth;
254 std::optional<int> m_busWidth;
256 std::optional<int> m_lineStyle;
257
259
260 // The NETCLASS providing each parameter
275};
276
277#endif // CLASS_NETCLASS_H
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
void SetViaDiameter(int aDia)
Definition: netclass.h:122
void SetViaDrill(int aSize)
Definition: netclass.h:130
bool HasLineStyle() const
Definition: netclass.h:220
int GetViaDiameter() const
Definition: netclass.h:120
int GetViaDrill() const
Definition: netclass.h:128
void SetWireWidthParent(NETCLASS *parent)
Definition: netclass.h:195
void SetWireWidth(std::optional< int > aWidth)
Definition: netclass.h:194
COLOR4D m_pcbColor
Optional PCB color override for this netclass.
Definition: netclass.h:258
void SetuViaDrillParent(NETCLASS *parent)
Definition: netclass.h:148
void SetPriority(int aPriority)
Definition: netclass.h:228
void SetViaDrill(std::optional< int > aSize)
Definition: netclass.h:131
void SetClearance(std::optional< int > aClearance)
Definition: netclass.h:107
~NETCLASS()
Definition: netclass.h:56
bool HasBusWidth() const
Definition: netclass.h:198
bool HasuViaDrill() const
Definition: netclass.h:143
NETCLASS * m_pcbColorParent
Definition: netclass.h:270
void SetDiffPairWidthParent(NETCLASS *parent)
Definition: netclass.h:156
void SetuViaDiameter(int aSize)
Definition: netclass.h:138
void SetDiffPairWidth(int aSize)
Definition: netclass.h:154
NETCLASS * m_diffPairWidthParent
Definition: netclass.h:267
NETCLASS * m_uViaDrillParent
Definition: netclass.h:266
std::optional< int > m_ViaDrill
via drill hole diameter
Definition: netclass.h:244
int HasViaDrill() const
Definition: netclass.h:127
int GetDiffPairViaGap() const
Definition: netclass.h:168
void SetViaDrillParent(NETCLASS *parent)
Definition: netclass.h:132
std::optional< int > m_wireWidth
Definition: netclass.h:253
int GetPriority() const
Definition: netclass.h:229
bool m_isDefault
Mark if this instance is the default netclass.
Definition: netclass.h:232
std::optional< int > m_busWidth
Definition: netclass.h:254
void SetDiffPairGapParent(NETCLASS *parent)
Definition: netclass.h:164
NETCLASS * GetViaDrillParent() const
Definition: netclass.h:133
int GetDiffPairGap() const
Definition: netclass.h:160
NETCLASS * m_diffPairGapParent
Definition: netclass.h:268
int GetuViaDrill() const
Definition: netclass.h:144
std::optional< int > GetBusWidthOpt() const
Definition: netclass.h:200
void SetViaDiameter(std::optional< int > aDia)
Definition: netclass.h:123
void SetLineStyle(int aStyle)
Definition: netclass.h:223
bool HasViaDiameter() const
Definition: netclass.h:119
NETCLASS * GetBusWidthParent() const
Definition: netclass.h:204
std::optional< int > m_TrackWidth
track width used to route nets
Definition: netclass.h:242
NETCLASS * m_viaDiameterParent
Definition: netclass.h:263
int GetLineStyle() const
Definition: netclass.h:221
int m_Priority
The priority for multiple netclass resolution.
Definition: netclass.h:237
void SetSchematicColor(COLOR4D aColor)
Definition: netclass.h:216
std::optional< int > m_diffPairWidth
Definition: netclass.h:249
bool HasDiffPairWidth() const
Definition: netclass.h:151
std::optional< int > GetTrackWidthOpt() const
Definition: netclass.h:113
COLOR4D m_schematicColor
Definition: netclass.h:255
std::optional< int > m_diffPairViaGap
Definition: netclass.h:251
void SetLineStyleParent(NETCLASS *parent)
Definition: netclass.h:225
bool IsDefault() const
@ brief Determines if this is marked as the default netclass
Definition: netclass.h:88
std::optional< int > m_ViaDia
via diameter
Definition: netclass.h:243
void SetDiffPairViaGap(int aSize)
Definition: netclass.h:170
std::optional< int > GetViaDiameterOpt() const
Definition: netclass.h:121
std::optional< int > GetWireWidthOpt() const
Definition: netclass.h:192
bool HasuViaDiameter() const
Definition: netclass.h:135
void SetTrackWidthParent(NETCLASS *parent)
Definition: netclass.h:116
std::optional< int > m_lineStyle
Definition: netclass.h:256
int GetuViaDiameter() const
Definition: netclass.h:136
wxString GetClass() const
Definition: netclass.h:60
void SetDiffPairViaGap(std::optional< int > aSize)
Definition: netclass.h:171
NETCLASS * GetTrackWidthParent() const
Definition: netclass.h:117
NETCLASS * GetClearanceParent() const
Definition: netclass.h:109
std::optional< int > GetClearanceOpt() const
Definition: netclass.h:105
void SetLineStyle(std::optional< int > aStyle)
Definition: netclass.h:224
std::optional< int > GetuViaDiameterOpt() const
Definition: netclass.h:137
bool HasTrackWidth() const
Definition: netclass.h:111
void SetViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:124
void SetPcbColor(const COLOR4D &aColor)
Definition: netclass.h:186
NETCLASS * m_viaDrillParent
Definition: netclass.h:264
NETCLASS * m_lineStyleParent
Definition: netclass.h:274
void SetuViaDiameter(std::optional< int > aSize)
Definition: netclass.h:139
std::optional< int > GetDiffPairViaGapOpt() const
Definition: netclass.h:169
std::optional< int > m_Clearance
clearance when routing
Definition: netclass.h:240
void SetTrackWidth(std::optional< int > aWidth)
Definition: netclass.h:115
void SetDiffPairWidth(std::optional< int > aSize)
Definition: netclass.h:155
std::optional< int > m_uViaDia
microvia diameter
Definition: netclass.h:246
NETCLASS * GetLineStyleParent() const
Definition: netclass.h:226
int GetDiffPairWidth() const
Definition: netclass.h:152
void SetuViaDrill(int aSize)
Definition: netclass.h:146
std::optional< int > GetViaDrillOpt() const
Definition: netclass.h:129
int GetWireWidth() const
Definition: netclass.h:191
NETCLASS * m_uViaDiaParent
Definition: netclass.h:265
void SetDiffPairGap(int aSize)
Definition: netclass.h:162
void SetBusWidthParent(NETCLASS *parent)
Definition: netclass.h:203
NETCLASS * GetDiffPairWidthParent() const
Definition: netclass.h:157
void SetClearance(int aClearance)
Definition: netclass.h:106
NETCLASS * m_clearanceParent
Definition: netclass.h:261
NETCLASS * GetuViaDrillParent() const
Definition: netclass.h:149
NETCLASS * m_diffPairViaGapParent
Definition: netclass.h:269
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition: netclass.h:176
NETCLASS * GetDiffPairViaGapParent() const
Definition: netclass.h:173
bool HasDiffPairGap() const
Definition: netclass.h:159
void SetDescription(const wxString &aDesc)
Definition: netclass.h:101
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition: netclass.h:206
const wxString & GetDescription() const
Definition: netclass.h:100
void SetPcbColorParent(NETCLASS *parent)
Definition: netclass.h:187
NETCLASS * m_schematicColorParent
Definition: netclass.h:273
void SetuViaDrill(std::optional< int > aSize)
Definition: netclass.h:147
NETCLASS * m_busWidthParent
Definition: netclass.h:272
std::optional< int > m_uViaDrill
microvia drill hole diameter
Definition: netclass.h:247
void SetBusWidth(int aWidth)
Definition: netclass.h:201
std::optional< int > GetDiffPairWidthOpt() const
Definition: netclass.h:153
void SetClearanceParent(NETCLASS *parent)
Definition: netclass.h:108
int GetTrackWidth() const
Definition: netclass.h:112
void SetWireWidth(int aWidth)
Definition: netclass.h:193
void SetDiffPairViaGapParent(NETCLASS *parent)
Definition: netclass.h:172
bool HasWireWidth() const
Definition: netclass.h:190
NETCLASS * m_wireWidthParent
Definition: netclass.h:271
int GetClearance() const
Definition: netclass.h:104
std::optional< int > GetuViaDrillOpt() const
Definition: netclass.h:145
void SetuViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:140
NETCLASS * m_trackWidthParent
Definition: netclass.h:262
void SetSchematicColorParent(NETCLASS *parent)
Definition: netclass.h:217
void SetBusWidth(std::optional< int > aWidth)
Definition: netclass.h:202
void SetName(const wxString &aName)
Definition: netclass.h:92
std::optional< int > GetLineStyleOpt() const
Definition: netclass.h:222
void SetTrackWidth(int aWidth)
Definition: netclass.h:114
std::vector< NETCLASS * > m_constituents
NETCLASSes contributing to an aggregate.
Definition: netclass.h:234
std::optional< int > GetDiffPairGapOpt() const
Definition: netclass.h:161
void SetDiffPairGap(std::optional< int > aSize)
Definition: netclass.h:163
NETCLASS * GetWireWidthParent() const
Definition: netclass.h:196
NETCLASS * GetSchematicColorParent() const
Definition: netclass.h:218
NETCLASS * GetDiffPairGapParent() const
Definition: netclass.h:165
std::optional< int > m_diffPairGap
Definition: netclass.h:250
bool HasDiffPairViaGap() const
Definition: netclass.h:167
NETCLASS * GetPcbColorParent() const
Definition: netclass.h:188
NETCLASS * GetViaDiameterParent() const
Definition: netclass.h:125
int GetBusWidth() const
Definition: netclass.h:199
bool HasClearance() const
Definition: netclass.h:103
wxString m_Name
Name of the net class.
Definition: netclass.h:236
NETCLASS * GetuViaDiameterParent() const
Definition: netclass.h:141
wxString m_Description
what this NETCLASS is for.
Definition: netclass.h:238
bool HasPcbColor() const
Definition: netclass.h:175
#define KICOMMON_API
Definition: kicommon.h:28
This file contains macros just for swig binding.
#define DECL_SET_FOR_SWIG(TypeName, MemberType)
Definition: macros_swig.h:54