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