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 The KiCad Developers, see AUTHORS.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#include <api/serializable.h>
36
37using KIGFX::COLOR4D;
38
39DECL_SET_FOR_SWIG( STRINGSET, wxString )
40
41
45{
46public:
47 static const char Default[];
48
55 NETCLASS( const wxString& aName, bool aInitWithDefaults = true );
56
58
59 NETCLASS( const NETCLASS& ) = delete;
60 NETCLASS& operator=( const NETCLASS& ) = delete;
61
62 bool operator==( const NETCLASS& other ) const;
63
64 wxString GetClass() const
65 {
66 return wxT( "NETCLASS" );
67 }
68
69 void Serialize( google::protobuf::Any &aContainer ) const override;
70 bool Deserialize( const google::protobuf::Any &aContainer ) override;
71
73 void ResetParents();
74
76 void ResetParameters();
77
79 // For a root netcless, this is the netclass this pointer, for aggregate netclasses is contains
80 // all constituent netclasses, in order of priority.
81 const std::vector<NETCLASS*>& GetConstituentNetclasses() const;
82
84 void SetConstituentNetclasses( std::vector<NETCLASS*>&& constituents );
85
88 bool ContainsNetclassWithName( const wxString& netclass ) const;
89
91 bool IsDefault() const { return m_isDefault; }
92
95 void SetName( const wxString& aName )
96 {
97 m_Name = aName;
98
99 if( aName == Default )
100 m_isDefault = true;
101 }
102
106 const wxString GetName() const;
107
111 const wxString GetHumanReadableName() const;
112
113 const wxString& GetDescription() const { return m_Description; }
114 void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
115
116 bool HasClearance() const { return (bool) m_Clearance; }
117 int GetClearance() const { return m_Clearance.value_or(-1); }
118 std::optional<int> GetClearanceOpt() const { return m_Clearance; }
119 void SetClearance( int aClearance ) { m_Clearance = aClearance; }
120 void SetClearance( std::optional<int> aClearance ) { m_Clearance = aClearance; }
121 void SetClearanceParent( NETCLASS* parent) { m_clearanceParent = parent; }
122 NETCLASS* GetClearanceParent() const { return m_clearanceParent; }
123
124 bool HasTrackWidth() const { return (bool) m_TrackWidth; }
125 int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); }
126 std::optional<int> GetTrackWidthOpt() const { return m_TrackWidth; }
127 void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
128 void SetTrackWidth( std::optional<int> aWidth ) { m_TrackWidth = aWidth; }
129 void SetTrackWidthParent( NETCLASS* parent) { m_trackWidthParent = parent; }
130 NETCLASS* GetTrackWidthParent() const { return m_trackWidthParent; }
131
132 bool HasViaDiameter() const { return (bool) m_ViaDia; }
133 int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); }
134 std::optional<int> GetViaDiameterOpt() const { return m_ViaDia; }
135 void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
136 void SetViaDiameter( std::optional<int> aDia ) { m_ViaDia = aDia; }
137 void SetViaDiameterParent( NETCLASS* parent) { m_viaDiameterParent = parent; }
138 NETCLASS* GetViaDiameterParent() const { return m_viaDiameterParent; }
139
140 int HasViaDrill() const { return (bool) m_ViaDrill; }
141 int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); }
142 std::optional<int> GetViaDrillOpt() const { return m_ViaDrill; }
143 void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
144 void SetViaDrill( std::optional<int> aSize ) { m_ViaDrill = aSize; }
145 void SetViaDrillParent( NETCLASS* parent) { m_viaDrillParent = parent; }
146 NETCLASS* GetViaDrillParent() const { return m_viaDrillParent; }
147
148 bool HasuViaDiameter() const { return (bool) m_uViaDia; }
149 int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); }
150 std::optional<int> GetuViaDiameterOpt() const { return m_uViaDia; }
151 void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
152 void SetuViaDiameter( std::optional<int> aSize ) { m_uViaDia = aSize; }
153 void SetuViaDiameterParent( NETCLASS* parent) { m_uViaDiaParent = parent; }
154 NETCLASS* GetuViaDiameterParent() const { return m_uViaDiaParent; }
155
156 bool HasuViaDrill() const { return (bool) m_uViaDrill; }
157 int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); }
158 std::optional<int> GetuViaDrillOpt() const { return m_uViaDrill; }
159 void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
160 void SetuViaDrill( std::optional<int> aSize ) { m_uViaDrill = aSize; }
161 void SetuViaDrillParent( NETCLASS* parent) { m_uViaDrillParent = parent; }
162 NETCLASS* GetuViaDrillParent() const { return m_uViaDrillParent; }
163
164 bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; }
165 int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); }
166 std::optional<int> GetDiffPairWidthOpt() const { return m_diffPairWidth; }
167 void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
168 void SetDiffPairWidth( std::optional<int> aSize ) { m_diffPairWidth = aSize; }
169 void SetDiffPairWidthParent( NETCLASS* parent) { m_diffPairWidthParent = parent; }
170 NETCLASS* GetDiffPairWidthParent() const { return m_diffPairWidthParent; }
171
172 bool HasDiffPairGap() const { return (bool) m_diffPairGap; }
173 int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); }
174 std::optional<int> GetDiffPairGapOpt() const { return m_diffPairGap; }
175 void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
176 void SetDiffPairGap( std::optional<int> aSize ) { m_diffPairGap = aSize; }
177 void SetDiffPairGapParent( NETCLASS* parent) { m_diffPairGapParent = parent; }
178 NETCLASS* GetDiffPairGapParent() const { return m_diffPairGapParent; }
179
180 bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; }
181 int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); }
182 std::optional<int> GetDiffPairViaGapOpt() const { return m_diffPairViaGap; }
183 void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
184 void SetDiffPairViaGap( std::optional<int> aSize ) { m_diffPairViaGap = aSize; }
185 void SetDiffPairViaGapParent( NETCLASS* parent) { m_diffPairViaGapParent = parent; }
186 NETCLASS* GetDiffPairViaGapParent() const { return m_diffPairViaGapParent; }
187
188 bool HasPcbColor() const { return m_isDefault ? false : m_pcbColor != COLOR4D::UNSPECIFIED; }
189 COLOR4D GetPcbColor( bool aIsForSave = false ) const
190 {
191 // If we are saving netclases, return the underlying color (which may be set from an old
192 // schematic with a default color set - this allows us to roll back the no-default-colors
193 // changes later if required)
194 if( aIsForSave || !m_isDefault )
195 return m_pcbColor;
196
198 }
199 void SetPcbColor( const COLOR4D& aColor ) { m_pcbColor = aColor; }
200 void SetPcbColorParent( NETCLASS* parent) { m_pcbColorParent = parent; }
201 NETCLASS* GetPcbColorParent() const { return m_pcbColorParent; }
202
203 bool HasWireWidth() const { return (bool) m_wireWidth; }
204 int GetWireWidth() const { return m_wireWidth.value_or( -1 ); }
205 std::optional<int> GetWireWidthOpt() const { return m_wireWidth; }
206 void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
207 void SetWireWidth( std::optional<int> aWidth ) { m_wireWidth = aWidth; }
208 void SetWireWidthParent( NETCLASS* parent) { m_wireWidthParent = parent; }
209 NETCLASS* GetWireWidthParent() const { return m_wireWidthParent; }
210
211 bool HasBusWidth() const { return (bool) m_busWidth; }
212 int GetBusWidth() const { return m_busWidth.value_or( -1 ); }
213 std::optional<int> GetBusWidthOpt() const { return m_busWidth; }
214 void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
215 void SetBusWidth( std::optional<int> aWidth ) { m_busWidth = aWidth; }
216 void SetBusWidthParent( NETCLASS* parent) { m_busWidthParent = parent; }
217 NETCLASS* GetBusWidthParent() const { return m_busWidthParent; }
218
219 COLOR4D GetSchematicColor( bool aIsForSave = false ) const
220 {
221 // If we are saving netclases, return the underlying color (which may be set from an old
222 // schematic with a default color set - this allows us to roll back the no-default-colors
223 // changes later if required)
224 if( aIsForSave || !m_isDefault )
225 return m_schematicColor;
226
228 }
229 void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
230 void SetSchematicColorParent( NETCLASS* parent) { m_schematicColorParent = parent; }
231 NETCLASS* GetSchematicColorParent() const { return m_schematicColorParent; }
232
233 bool HasLineStyle() const { return (bool) m_lineStyle; }
234 int GetLineStyle() const { return m_lineStyle.value_or( 0 ); }
235 std::optional<int> GetLineStyleOpt() const { return m_lineStyle; }
236 void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
237 void SetLineStyle( std::optional<int> aStyle ) { m_lineStyle = aStyle; }
238 void SetLineStyleParent( NETCLASS* parent) { m_lineStyleParent = parent; }
239 NETCLASS* GetLineStyleParent() const { return m_lineStyleParent; }
240
241 void SetPriority( int aPriority ) { m_Priority = aPriority; }
242 int GetPriority() const { return m_Priority; }
243
244 bool HasDelayProfile() const { return !m_DelayProfile.empty(); }
245 void SetDelayProfile( const wxString& aDelayProfile ) { m_DelayProfile = aDelayProfile; }
246 wxString GetDelayProfile() const { return m_DelayProfile; }
247 void SetDelayProfileParent( NETCLASS* aParent ) { m_delayProfileParent = aParent; }
248 NETCLASS* GetDelayProfileParent() const { return m_delayProfileParent; }
249
250protected:
252
253 std::vector<NETCLASS*> m_constituents;
254
255 wxString m_Name;
257 wxString m_Description;
258
259 std::optional<int> m_Clearance;
260
261 std::optional<int> m_TrackWidth;
262 std::optional<int> m_ViaDia;
263 std::optional<int> m_ViaDrill;
264
265 std::optional<int> m_uViaDia;
266 std::optional<int> m_uViaDrill;
267
268 std::optional<int> m_diffPairWidth;
269 std::optional<int> m_diffPairGap;
270 std::optional<int> m_diffPairViaGap;
271
272 std::optional<int> m_wireWidth;
273 std::optional<int> m_busWidth;
275 std::optional<int> m_lineStyle;
276
278
279 wxString m_DelayProfile;
280
281 // The NETCLASS providing each parameter
297};
298
299#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:45
void SetViaDiameter(int aDia)
Definition: netclass.h:135
void SetViaDrill(int aSize)
Definition: netclass.h:143
bool HasLineStyle() const
Definition: netclass.h:233
void SetDelayProfileParent(NETCLASS *aParent)
Definition: netclass.h:247
int GetViaDiameter() const
Definition: netclass.h:133
int GetViaDrill() const
Definition: netclass.h:141
void SetWireWidthParent(NETCLASS *parent)
Definition: netclass.h:208
void SetWireWidth(std::optional< int > aWidth)
Definition: netclass.h:207
COLOR4D m_pcbColor
Optional PCB color override for this netclass.
Definition: netclass.h:277
void SetuViaDrillParent(NETCLASS *parent)
Definition: netclass.h:161
void SetPriority(int aPriority)
Definition: netclass.h:241
void SetViaDrill(std::optional< int > aSize)
Definition: netclass.h:144
bool HasDelayProfile() const
Definition: netclass.h:244
void SetClearance(std::optional< int > aClearance)
Definition: netclass.h:120
~NETCLASS()
Definition: netclass.h:57
bool HasBusWidth() const
Definition: netclass.h:211
bool HasuViaDrill() const
Definition: netclass.h:156
NETCLASS * m_pcbColorParent
Definition: netclass.h:291
void SetDiffPairWidthParent(NETCLASS *parent)
Definition: netclass.h:169
void SetuViaDiameter(int aSize)
Definition: netclass.h:151
void SetDiffPairWidth(int aSize)
Definition: netclass.h:167
NETCLASS * m_diffPairWidthParent
Definition: netclass.h:288
NETCLASS * m_uViaDrillParent
Definition: netclass.h:287
std::optional< int > m_ViaDrill
via drill hole diameter
Definition: netclass.h:263
int HasViaDrill() const
Definition: netclass.h:140
int GetDiffPairViaGap() const
Definition: netclass.h:181
void SetViaDrillParent(NETCLASS *parent)
Definition: netclass.h:145
std::optional< int > m_wireWidth
Definition: netclass.h:272
int GetPriority() const
Definition: netclass.h:242
bool m_isDefault
Mark if this instance is the default netclass.
Definition: netclass.h:251
std::optional< int > m_busWidth
Definition: netclass.h:273
void SetDiffPairGapParent(NETCLASS *parent)
Definition: netclass.h:177
NETCLASS * GetViaDrillParent() const
Definition: netclass.h:146
int GetDiffPairGap() const
Definition: netclass.h:173
NETCLASS * m_diffPairGapParent
Definition: netclass.h:289
int GetuViaDrill() const
Definition: netclass.h:157
std::optional< int > GetBusWidthOpt() const
Definition: netclass.h:213
void SetViaDiameter(std::optional< int > aDia)
Definition: netclass.h:136
void SetLineStyle(int aStyle)
Definition: netclass.h:236
bool HasViaDiameter() const
Definition: netclass.h:132
NETCLASS * GetBusWidthParent() const
Definition: netclass.h:217
std::optional< int > m_TrackWidth
track width used to route nets
Definition: netclass.h:261
NETCLASS * m_viaDiameterParent
Definition: netclass.h:284
int GetLineStyle() const
Definition: netclass.h:234
int m_Priority
The priority for multiple netclass resolution.
Definition: netclass.h:256
NETCLASS * m_delayProfileParent
Definition: netclass.h:296
void SetSchematicColor(COLOR4D aColor)
Definition: netclass.h:229
std::optional< int > m_diffPairWidth
Definition: netclass.h:268
bool HasDiffPairWidth() const
Definition: netclass.h:164
std::optional< int > GetTrackWidthOpt() const
Definition: netclass.h:126
NETCLASS & operator=(const NETCLASS &)=delete
COLOR4D m_schematicColor
Definition: netclass.h:274
std::optional< int > m_diffPairViaGap
Definition: netclass.h:270
void SetLineStyleParent(NETCLASS *parent)
Definition: netclass.h:238
bool IsDefault() const
@ brief Determines if this is marked as the default netclass
Definition: netclass.h:91
std::optional< int > m_ViaDia
via diameter
Definition: netclass.h:262
void SetDiffPairViaGap(int aSize)
Definition: netclass.h:183
std::optional< int > GetViaDiameterOpt() const
Definition: netclass.h:134
NETCLASS * GetDelayProfileParent() const
Definition: netclass.h:248
std::optional< int > GetWireWidthOpt() const
Definition: netclass.h:205
bool HasuViaDiameter() const
Definition: netclass.h:148
void SetTrackWidthParent(NETCLASS *parent)
Definition: netclass.h:129
std::optional< int > m_lineStyle
Definition: netclass.h:275
int GetuViaDiameter() const
Definition: netclass.h:149
wxString GetClass() const
Definition: netclass.h:64
void SetDiffPairViaGap(std::optional< int > aSize)
Definition: netclass.h:184
NETCLASS * GetTrackWidthParent() const
Definition: netclass.h:130
NETCLASS * GetClearanceParent() const
Definition: netclass.h:122
std::optional< int > GetClearanceOpt() const
Definition: netclass.h:118
void SetLineStyle(std::optional< int > aStyle)
Definition: netclass.h:237
std::optional< int > GetuViaDiameterOpt() const
Definition: netclass.h:150
bool HasTrackWidth() const
Definition: netclass.h:124
void SetViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:137
void SetPcbColor(const COLOR4D &aColor)
Definition: netclass.h:199
NETCLASS * m_viaDrillParent
Definition: netclass.h:285
NETCLASS * m_lineStyleParent
Definition: netclass.h:295
void SetuViaDiameter(std::optional< int > aSize)
Definition: netclass.h:152
std::optional< int > GetDiffPairViaGapOpt() const
Definition: netclass.h:182
std::optional< int > m_Clearance
clearance when routing
Definition: netclass.h:259
void SetTrackWidth(std::optional< int > aWidth)
Definition: netclass.h:128
void SetDiffPairWidth(std::optional< int > aSize)
Definition: netclass.h:168
std::optional< int > m_uViaDia
microvia diameter
Definition: netclass.h:265
NETCLASS * GetLineStyleParent() const
Definition: netclass.h:239
int GetDiffPairWidth() const
Definition: netclass.h:165
void SetuViaDrill(int aSize)
Definition: netclass.h:159
std::optional< int > GetViaDrillOpt() const
Definition: netclass.h:142
void SetDelayProfile(const wxString &aDelayProfile)
Definition: netclass.h:245
int GetWireWidth() const
Definition: netclass.h:204
NETCLASS * m_uViaDiaParent
Definition: netclass.h:286
void SetDiffPairGap(int aSize)
Definition: netclass.h:175
void SetBusWidthParent(NETCLASS *parent)
Definition: netclass.h:216
NETCLASS * GetDiffPairWidthParent() const
Definition: netclass.h:170
void SetClearance(int aClearance)
Definition: netclass.h:119
NETCLASS * m_clearanceParent
Definition: netclass.h:282
NETCLASS * GetuViaDrillParent() const
Definition: netclass.h:162
NETCLASS * m_diffPairViaGapParent
Definition: netclass.h:290
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition: netclass.h:189
NETCLASS * GetDiffPairViaGapParent() const
Definition: netclass.h:186
NETCLASS(const NETCLASS &)=delete
bool HasDiffPairGap() const
Definition: netclass.h:172
void SetDescription(const wxString &aDesc)
Definition: netclass.h:114
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition: netclass.h:219
const wxString & GetDescription() const
Definition: netclass.h:113
void SetPcbColorParent(NETCLASS *parent)
Definition: netclass.h:200
NETCLASS * m_schematicColorParent
Definition: netclass.h:294
void SetuViaDrill(std::optional< int > aSize)
Definition: netclass.h:160
NETCLASS * m_busWidthParent
Definition: netclass.h:293
std::optional< int > m_uViaDrill
microvia drill hole diameter
Definition: netclass.h:266
void SetBusWidth(int aWidth)
Definition: netclass.h:214
std::optional< int > GetDiffPairWidthOpt() const
Definition: netclass.h:166
wxString GetDelayProfile() const
Definition: netclass.h:246
void SetClearanceParent(NETCLASS *parent)
Definition: netclass.h:121
int GetTrackWidth() const
Definition: netclass.h:125
void SetWireWidth(int aWidth)
Definition: netclass.h:206
void SetDiffPairViaGapParent(NETCLASS *parent)
Definition: netclass.h:185
bool HasWireWidth() const
Definition: netclass.h:203
NETCLASS * m_wireWidthParent
Definition: netclass.h:292
int GetClearance() const
Definition: netclass.h:117
std::optional< int > GetuViaDrillOpt() const
Definition: netclass.h:158
void SetuViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:153
NETCLASS * m_trackWidthParent
Definition: netclass.h:283
void SetSchematicColorParent(NETCLASS *parent)
Definition: netclass.h:230
void SetBusWidth(std::optional< int > aWidth)
Definition: netclass.h:215
void SetName(const wxString &aName)
Set the name of this netclass.
Definition: netclass.h:95
std::optional< int > GetLineStyleOpt() const
Definition: netclass.h:235
void SetTrackWidth(int aWidth)
Definition: netclass.h:127
std::vector< NETCLASS * > m_constituents
NETCLASSes contributing to an aggregate.
Definition: netclass.h:253
std::optional< int > GetDiffPairGapOpt() const
Definition: netclass.h:174
void SetDiffPairGap(std::optional< int > aSize)
Definition: netclass.h:176
wxString m_DelayProfile
The tuning profile name being used by this netclass.
Definition: netclass.h:279
NETCLASS * GetWireWidthParent() const
Definition: netclass.h:209
NETCLASS * GetSchematicColorParent() const
Definition: netclass.h:231
NETCLASS * GetDiffPairGapParent() const
Definition: netclass.h:178
std::optional< int > m_diffPairGap
Definition: netclass.h:269
bool HasDiffPairViaGap() const
Definition: netclass.h:180
NETCLASS * GetPcbColorParent() const
Definition: netclass.h:201
NETCLASS * GetViaDiameterParent() const
Definition: netclass.h:138
int GetBusWidth() const
Definition: netclass.h:212
bool HasClearance() const
Definition: netclass.h:116
wxString m_Name
Name of the net class.
Definition: netclass.h:255
NETCLASS * GetuViaDiameterParent() const
Definition: netclass.h:154
wxString m_Description
what this NETCLASS is for.
Definition: netclass.h:257
bool HasPcbColor() const
Definition: netclass.h:188
Interface for objects that can be serialized to Protobuf messages.
Definition: serializable.h:37
#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