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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef CLASS_NETCLASS_H
23#define CLASS_NETCLASS_H
24
25#include <optional>
26
27#include <gal/color4d.h>
28#include <kicommon.h>
29#include <stroke_params.h>
30#include <api/serializable.h>
31
32using KIGFX::COLOR4D;
33
35{
36 class NetClass;
37}
38
43{
44public:
45 static const char Default[];
46
53 NETCLASS( const wxString& aName, bool aInitWithDefaults = true );
54
56
57 NETCLASS( const NETCLASS& ) = delete;
58 NETCLASS& operator=( const NETCLASS& ) = delete;
59
60 bool operator==( const NETCLASS& other ) const;
61
73 bool EqualsByPersistedFields( const NETCLASS& aOther ) const;
74
75 wxString GetClass() const
76 {
77 return wxT( "NETCLASS" );
78 }
79
80 void Serialize( google::protobuf::Any &aContainer ) const override;
81 bool Deserialize( const google::protobuf::Any &aContainer ) override;
82
83 void Serialize( kiapi::common::project::NetClass& aOutput ) const;
84 bool Deserialize( const kiapi::common::project::NetClass& aInput );
85
87 void ResetParents();
88
90 void ResetParameters();
91
93 // For a root netcless, this is the netclass this pointer, for aggregate netclasses is contains
94 // all constituent netclasses, in order of priority.
95 const std::vector<NETCLASS*>& GetConstituentNetclasses() const;
96
98 void SetConstituentNetclasses( std::vector<NETCLASS*>&& constituents );
99
102 bool ContainsNetclassWithName( const wxString& netclass ) const;
103
105 bool IsDefault() const { return m_isDefault; }
106
109 void SetName( const wxString& aName )
110 {
111 m_Name = aName;
112
113 if( aName == Default )
114 m_isDefault = true;
115 }
116
120 const wxString GetName() const;
121
125 const wxString GetHumanReadableName() const;
126
127 const wxString& GetDescription() const { return m_Description; }
128 void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
129
130 bool HasClearance() const { return (bool) m_Clearance; }
131 int GetClearance() const { return m_Clearance.value_or(-1); }
132 std::optional<int> GetClearanceOpt() const { return m_Clearance; }
133 void SetClearance( int aClearance ) { m_Clearance = aClearance; }
134 void SetClearance( std::optional<int> aClearance ) { m_Clearance = aClearance; }
135 void SetClearanceParent( NETCLASS* parent) { m_clearanceParent = parent; }
137
138 bool HasTrackWidth() const { return (bool) m_TrackWidth; }
139 int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); }
140 std::optional<int> GetTrackWidthOpt() const { return m_TrackWidth; }
141 void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
142 void SetTrackWidth( std::optional<int> aWidth ) { m_TrackWidth = aWidth; }
145
146 bool HasViaDiameter() const { return (bool) m_ViaDia; }
147 int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); }
148 std::optional<int> GetViaDiameterOpt() const { return m_ViaDia; }
149 void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
150 void SetViaDiameter( std::optional<int> aDia ) { m_ViaDia = aDia; }
153
154 int HasViaDrill() const { return (bool) m_ViaDrill; }
155 int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); }
156 std::optional<int> GetViaDrillOpt() const { return m_ViaDrill; }
157 void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
158 void SetViaDrill( std::optional<int> aSize ) { m_ViaDrill = aSize; }
159 void SetViaDrillParent( NETCLASS* parent) { m_viaDrillParent = parent; }
161
162 bool HasuViaDiameter() const { return (bool) m_uViaDia; }
163 int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); }
164 std::optional<int> GetuViaDiameterOpt() const { return m_uViaDia; }
165 void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
166 void SetuViaDiameter( std::optional<int> aSize ) { m_uViaDia = aSize; }
167 void SetuViaDiameterParent( NETCLASS* parent) { m_uViaDiaParent = parent; }
169
170 bool HasuViaDrill() const { return (bool) m_uViaDrill; }
171 int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); }
172 std::optional<int> GetuViaDrillOpt() const { return m_uViaDrill; }
173 void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
174 void SetuViaDrill( std::optional<int> aSize ) { m_uViaDrill = aSize; }
175 void SetuViaDrillParent( NETCLASS* parent) { m_uViaDrillParent = parent; }
177
178 bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; }
179 int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); }
180 std::optional<int> GetDiffPairWidthOpt() const { return m_diffPairWidth; }
181 void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
182 void SetDiffPairWidth( std::optional<int> aSize ) { m_diffPairWidth = aSize; }
185
186 bool HasDiffPairGap() const { return (bool) m_diffPairGap; }
187 int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); }
188 std::optional<int> GetDiffPairGapOpt() const { return m_diffPairGap; }
189 void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
190 void SetDiffPairGap( std::optional<int> aSize ) { m_diffPairGap = aSize; }
193
194 bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; }
195 int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); }
196 std::optional<int> GetDiffPairViaGapOpt() const { return m_diffPairViaGap; }
197 void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
198 void SetDiffPairViaGap( std::optional<int> aSize ) { m_diffPairViaGap = aSize; }
201
202 bool HasPcbColor() const { return m_isDefault ? false : m_pcbColor != COLOR4D::UNSPECIFIED; }
203 COLOR4D GetPcbColor( bool aIsForSave = false ) const
204 {
205 // If we are saving netclases, return the underlying color (which may be set from an old
206 // schematic with a default color set - this allows us to roll back the no-default-colors
207 // changes later if required)
208 if( aIsForSave || !m_isDefault )
209 return m_pcbColor;
210
212 }
213 void SetPcbColor( const COLOR4D& aColor ) { m_pcbColor = aColor; }
214 void SetPcbColorParent( NETCLASS* parent) { m_pcbColorParent = parent; }
216
217 bool HasWireWidth() const { return (bool) m_wireWidth; }
218 int GetWireWidth() const { return m_wireWidth.value_or( -1 ); }
219 std::optional<int> GetWireWidthOpt() const { return m_wireWidth; }
220 void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
221 void SetWireWidth( std::optional<int> aWidth ) { m_wireWidth = aWidth; }
222 void SetWireWidthParent( NETCLASS* parent) { m_wireWidthParent = parent; }
224
225 bool HasBusWidth() const { return (bool) m_busWidth; }
226 int GetBusWidth() const { return m_busWidth.value_or( -1 ); }
227 std::optional<int> GetBusWidthOpt() const { return m_busWidth; }
228 void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
229 void SetBusWidth( std::optional<int> aWidth ) { m_busWidth = aWidth; }
230 void SetBusWidthParent( NETCLASS* parent) { m_busWidthParent = parent; }
232
233 COLOR4D GetSchematicColor( bool aIsForSave = false ) const
234 {
235 // If we are saving netclases, return the underlying color (which may be set from an old
236 // schematic with a default color set - this allows us to roll back the no-default-colors
237 // changes later if required)
238 if( aIsForSave || !m_isDefault )
239 return m_schematicColor;
240
242 }
243 void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
246
247 bool HasLineStyle() const { return (bool) m_lineStyle; }
248 int GetLineStyle() const { return m_lineStyle.value_or( 0 ); }
249 std::optional<int> GetLineStyleOpt() const { return m_lineStyle; }
250 void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
251 void SetLineStyle( std::optional<int> aStyle ) { m_lineStyle = aStyle; }
252 void SetLineStyleParent( NETCLASS* parent) { m_lineStyleParent = parent; }
254
255 void SetPriority( int aPriority ) { m_Priority = aPriority; }
256 int GetPriority() const { return m_Priority; }
257
258 bool HasTuningProfile() const { return !m_tuningProfile.empty(); }
259 void SetTuningProfile( const wxString& aTuningProfile ) { m_tuningProfile = aTuningProfile; }
260 wxString GetTuningProfile() const { return m_tuningProfile; }
263
264protected:
266
267 std::vector<NETCLASS*> m_constituents;
268
269 wxString m_Name;
271 wxString m_Description;
272
273 std::optional<int> m_Clearance;
274
275 std::optional<int> m_TrackWidth;
276 std::optional<int> m_ViaDia;
277 std::optional<int> m_ViaDrill;
278
279 std::optional<int> m_uViaDia;
280 std::optional<int> m_uViaDrill;
281
282 std::optional<int> m_diffPairWidth;
283 std::optional<int> m_diffPairGap;
284 std::optional<int> m_diffPairViaGap;
285
286 std::optional<int> m_wireWidth;
287 std::optional<int> m_busWidth;
289 std::optional<int> m_lineStyle;
290
292
294
295 // The NETCLASS providing each parameter
311};
312
313#endif // CLASS_NETCLASS_H
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:399
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
void SetViaDiameter(int aDia)
Definition netclass.h:149
void SetViaDrill(int aSize)
Definition netclass.h:157
bool HasLineStyle() const
Definition netclass.h:247
int GetViaDiameter() const
Definition netclass.h:147
int GetViaDrill() const
Definition netclass.h:155
void SetWireWidthParent(NETCLASS *parent)
Definition netclass.h:222
void SetWireWidth(std::optional< int > aWidth)
Definition netclass.h:221
COLOR4D m_pcbColor
Optional PCB color override for this netclass.
Definition netclass.h:291
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:45
void SetuViaDrillParent(NETCLASS *parent)
Definition netclass.h:175
void SetPriority(int aPriority)
Definition netclass.h:255
void SetViaDrill(std::optional< int > aSize)
Definition netclass.h:158
void SetClearance(std::optional< int > aClearance)
Definition netclass.h:134
~NETCLASS()
Definition netclass.h:55
bool HasBusWidth() const
Definition netclass.h:225
bool HasuViaDrill() const
Definition netclass.h:170
NETCLASS * m_pcbColorParent
Definition netclass.h:305
void SetDiffPairWidthParent(NETCLASS *parent)
Definition netclass.h:183
void SetuViaDiameter(int aSize)
Definition netclass.h:165
void SetDiffPairWidth(int aSize)
Definition netclass.h:181
NETCLASS * m_diffPairWidthParent
Definition netclass.h:302
NETCLASS * m_uViaDrillParent
Definition netclass.h:301
std::optional< int > m_ViaDrill
via drill hole diameter
Definition netclass.h:277
int HasViaDrill() const
Definition netclass.h:154
int GetDiffPairViaGap() const
Definition netclass.h:195
void SetViaDrillParent(NETCLASS *parent)
Definition netclass.h:159
std::optional< int > m_wireWidth
Definition netclass.h:286
int GetPriority() const
Definition netclass.h:256
bool m_isDefault
Mark if this instance is the default netclass.
Definition netclass.h:265
wxString GetTuningProfile() const
Definition netclass.h:260
std::optional< int > m_busWidth
Definition netclass.h:287
void SetDiffPairGapParent(NETCLASS *parent)
Definition netclass.h:191
void SetTuningProfileParent(NETCLASS *aParent)
Definition netclass.h:261
NETCLASS * GetViaDrillParent() const
Definition netclass.h:160
int GetDiffPairGap() const
Definition netclass.h:187
NETCLASS * m_diffPairGapParent
Definition netclass.h:303
int GetuViaDrill() const
Definition netclass.h:171
std::optional< int > GetBusWidthOpt() const
Definition netclass.h:227
void SetViaDiameter(std::optional< int > aDia)
Definition netclass.h:150
void SetLineStyle(int aStyle)
Definition netclass.h:250
bool HasViaDiameter() const
Definition netclass.h:146
NETCLASS * GetBusWidthParent() const
Definition netclass.h:231
std::optional< int > m_TrackWidth
track width used to route nets
Definition netclass.h:275
NETCLASS * m_viaDiameterParent
Definition netclass.h:298
int GetLineStyle() const
Definition netclass.h:248
int m_Priority
The priority for multiple netclass resolution.
Definition netclass.h:270
NETCLASS(const wxString &aName, bool aInitWithDefaults=true)
Create a NETCLASS instance with aName.
Definition netclass.cpp:52
void SetSchematicColor(COLOR4D aColor)
Definition netclass.h:243
std::optional< int > m_diffPairWidth
Definition netclass.h:282
bool HasDiffPairWidth() const
Definition netclass.h:178
std::optional< int > GetTrackWidthOpt() const
Definition netclass.h:140
NETCLASS & operator=(const NETCLASS &)=delete
wxString m_tuningProfile
The tuning profile name being used by this netclass.
Definition netclass.h:293
COLOR4D m_schematicColor
Definition netclass.h:288
std::optional< int > m_diffPairViaGap
Definition netclass.h:284
void SetLineStyleParent(NETCLASS *parent)
Definition netclass.h:252
NETCLASS * GetTuningProfileParent() const
Definition netclass.h:262
bool IsDefault() const
@ brief Determines if this is marked as the default netclass
Definition netclass.h:105
std::optional< int > m_ViaDia
via diameter
Definition netclass.h:276
void SetDiffPairViaGap(int aSize)
Definition netclass.h:197
std::optional< int > GetViaDiameterOpt() const
Definition netclass.h:148
std::optional< int > GetWireWidthOpt() const
Definition netclass.h:219
bool HasuViaDiameter() const
Definition netclass.h:162
void SetTrackWidthParent(NETCLASS *parent)
Definition netclass.h:143
std::optional< int > m_lineStyle
Definition netclass.h:289
int GetuViaDiameter() const
Definition netclass.h:163
wxString GetClass() const
Definition netclass.h:75
void SetDiffPairViaGap(std::optional< int > aSize)
Definition netclass.h:198
NETCLASS * GetTrackWidthParent() const
Definition netclass.h:144
NETCLASS * GetClearanceParent() const
Definition netclass.h:136
std::optional< int > GetClearanceOpt() const
Definition netclass.h:132
void SetLineStyle(std::optional< int > aStyle)
Definition netclass.h:251
std::optional< int > GetuViaDiameterOpt() const
Definition netclass.h:164
bool HasTrackWidth() const
Definition netclass.h:138
void SetViaDiameterParent(NETCLASS *parent)
Definition netclass.h:151
void SetPcbColor(const COLOR4D &aColor)
Definition netclass.h:213
NETCLASS * m_viaDrillParent
Definition netclass.h:299
NETCLASS * m_lineStyleParent
Definition netclass.h:309
void SetuViaDiameter(std::optional< int > aSize)
Definition netclass.h:166
std::optional< int > GetDiffPairViaGapOpt() const
Definition netclass.h:196
std::optional< int > m_Clearance
clearance when routing
Definition netclass.h:273
void SetTrackWidth(std::optional< int > aWidth)
Definition netclass.h:142
void SetDiffPairWidth(std::optional< int > aSize)
Definition netclass.h:182
std::optional< int > m_uViaDia
microvia diameter
Definition netclass.h:279
NETCLASS * GetLineStyleParent() const
Definition netclass.h:253
bool EqualsByPersistedFields(const NETCLASS &aOther) const
Compare every persisted field (name, priority, sized fields, colors, line style, tuning profile) to d...
Definition netclass.cpp:132
int GetDiffPairWidth() const
Definition netclass.h:179
NETCLASS * m_tuningProfileParent
Definition netclass.h:310
void SetuViaDrill(int aSize)
Definition netclass.h:173
std::optional< int > GetViaDrillOpt() const
Definition netclass.h:156
int GetWireWidth() const
Definition netclass.h:218
NETCLASS * m_uViaDiaParent
Definition netclass.h:300
void SetDiffPairGap(int aSize)
Definition netclass.h:189
void SetBusWidthParent(NETCLASS *parent)
Definition netclass.h:230
NETCLASS * GetDiffPairWidthParent() const
Definition netclass.h:184
void SetClearance(int aClearance)
Definition netclass.h:133
NETCLASS * m_clearanceParent
Definition netclass.h:296
NETCLASS * GetuViaDrillParent() const
Definition netclass.h:176
NETCLASS * m_diffPairViaGapParent
Definition netclass.h:304
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition netclass.h:203
NETCLASS * GetDiffPairViaGapParent() const
Definition netclass.h:200
NETCLASS(const NETCLASS &)=delete
bool HasDiffPairGap() const
Definition netclass.h:186
void SetDescription(const wxString &aDesc)
Definition netclass.h:128
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:233
const wxString & GetDescription() const
Definition netclass.h:127
void SetPcbColorParent(NETCLASS *parent)
Definition netclass.h:214
NETCLASS * m_schematicColorParent
Definition netclass.h:308
void SetuViaDrill(std::optional< int > aSize)
Definition netclass.h:174
NETCLASS * m_busWidthParent
Definition netclass.h:307
std::optional< int > m_uViaDrill
microvia drill hole diameter
Definition netclass.h:280
void SetBusWidth(int aWidth)
Definition netclass.h:228
std::optional< int > GetDiffPairWidthOpt() const
Definition netclass.h:180
void SetClearanceParent(NETCLASS *parent)
Definition netclass.h:135
int GetTrackWidth() const
Definition netclass.h:139
void SetWireWidth(int aWidth)
Definition netclass.h:220
void SetDiffPairViaGapParent(NETCLASS *parent)
Definition netclass.h:199
void SetTuningProfile(const wxString &aTuningProfile)
Definition netclass.h:259
bool HasTuningProfile() const
Definition netclass.h:258
bool HasWireWidth() const
Definition netclass.h:217
NETCLASS * m_wireWidthParent
Definition netclass.h:306
int GetClearance() const
Definition netclass.h:131
std::optional< int > GetuViaDrillOpt() const
Definition netclass.h:172
void SetuViaDiameterParent(NETCLASS *parent)
Definition netclass.h:167
NETCLASS * m_trackWidthParent
Definition netclass.h:297
void SetSchematicColorParent(NETCLASS *parent)
Definition netclass.h:244
void SetBusWidth(std::optional< int > aWidth)
Definition netclass.h:229
void SetName(const wxString &aName)
Set the name of this netclass.
Definition netclass.h:109
std::optional< int > GetLineStyleOpt() const
Definition netclass.h:249
void SetTrackWidth(int aWidth)
Definition netclass.h:141
std::vector< NETCLASS * > m_constituents
NETCLASSes contributing to an aggregate.
Definition netclass.h:267
std::optional< int > GetDiffPairGapOpt() const
Definition netclass.h:188
void SetDiffPairGap(std::optional< int > aSize)
Definition netclass.h:190
NETCLASS * GetWireWidthParent() const
Definition netclass.h:223
NETCLASS * GetSchematicColorParent() const
Definition netclass.h:245
NETCLASS * GetDiffPairGapParent() const
Definition netclass.h:192
std::optional< int > m_diffPairGap
Definition netclass.h:283
bool HasDiffPairViaGap() const
Definition netclass.h:194
NETCLASS * GetPcbColorParent() const
Definition netclass.h:215
NETCLASS * GetViaDiameterParent() const
Definition netclass.h:152
int GetBusWidth() const
Definition netclass.h:226
bool HasClearance() const
Definition netclass.h:130
wxString m_Name
Name of the net class.
Definition netclass.h:269
NETCLASS * GetuViaDiameterParent() const
Definition netclass.h:168
wxString m_Description
what this NETCLASS is for.
Definition netclass.h:271
bool HasPcbColor() const
Definition netclass.h:202
Interface for objects that can be serialized to Protobuf messages.
virtual void Serialize(google::protobuf::Any &aContainer) const
Serializes this object to the given Any message.
virtual bool Deserialize(const google::protobuf::Any &aContainer)
Deserializes the given protobuf message into this object.
#define KICOMMON_API
Definition kicommon.h:27