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
123 bool NameEquals( const wxString& aName ) const;
124
128 const wxString GetHumanReadableName() const;
129
130 const wxString& GetDescription() const { return m_Description; }
131 void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
132
133 bool HasClearance() const { return (bool) m_Clearance; }
134 int GetClearance() const { return m_Clearance.value_or(-1); }
135 std::optional<int> GetClearanceOpt() const { return m_Clearance; }
136 void SetClearance( int aClearance ) { m_Clearance = aClearance; }
137 void SetClearance( std::optional<int> aClearance ) { m_Clearance = aClearance; }
138 void SetClearanceParent( NETCLASS* parent) { m_clearanceParent = parent; }
140
141 bool HasTrackWidth() const { return (bool) m_TrackWidth; }
142 int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); }
143 std::optional<int> GetTrackWidthOpt() const { return m_TrackWidth; }
144 void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
145 void SetTrackWidth( std::optional<int> aWidth ) { m_TrackWidth = aWidth; }
148
149 bool HasViaDiameter() const { return (bool) m_ViaDia; }
150 int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); }
151 std::optional<int> GetViaDiameterOpt() const { return m_ViaDia; }
152 void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
153 void SetViaDiameter( std::optional<int> aDia ) { m_ViaDia = aDia; }
156
157 int HasViaDrill() const { return (bool) m_ViaDrill; }
158 int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); }
159 std::optional<int> GetViaDrillOpt() const { return m_ViaDrill; }
160 void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
161 void SetViaDrill( std::optional<int> aSize ) { m_ViaDrill = aSize; }
162 void SetViaDrillParent( NETCLASS* parent) { m_viaDrillParent = parent; }
164
165 bool HasuViaDiameter() const { return (bool) m_uViaDia; }
166 int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); }
167 std::optional<int> GetuViaDiameterOpt() const { return m_uViaDia; }
168 void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
169 void SetuViaDiameter( std::optional<int> aSize ) { m_uViaDia = aSize; }
170 void SetuViaDiameterParent( NETCLASS* parent) { m_uViaDiaParent = parent; }
172
173 bool HasuViaDrill() const { return (bool) m_uViaDrill; }
174 int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); }
175 std::optional<int> GetuViaDrillOpt() const { return m_uViaDrill; }
176 void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
177 void SetuViaDrill( std::optional<int> aSize ) { m_uViaDrill = aSize; }
178 void SetuViaDrillParent( NETCLASS* parent) { m_uViaDrillParent = parent; }
180
181 bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; }
182 int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); }
183 std::optional<int> GetDiffPairWidthOpt() const { return m_diffPairWidth; }
184 void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
185 void SetDiffPairWidth( std::optional<int> aSize ) { m_diffPairWidth = aSize; }
188
189 bool HasDiffPairGap() const { return (bool) m_diffPairGap; }
190 int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); }
191 std::optional<int> GetDiffPairGapOpt() const { return m_diffPairGap; }
192 void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
193 void SetDiffPairGap( std::optional<int> aSize ) { m_diffPairGap = aSize; }
196
197 bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; }
198 int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); }
199 std::optional<int> GetDiffPairViaGapOpt() const { return m_diffPairViaGap; }
200 void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
201 void SetDiffPairViaGap( std::optional<int> aSize ) { m_diffPairViaGap = aSize; }
204
205 bool HasPcbColor() const { return m_isDefault ? false : m_pcbColor != COLOR4D::UNSPECIFIED; }
206 COLOR4D GetPcbColor( 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_pcbColor;
213
215 }
216 void SetPcbColor( const COLOR4D& aColor ) { m_pcbColor = aColor; }
217 void SetPcbColorParent( NETCLASS* parent) { m_pcbColorParent = parent; }
219
220 bool HasWireWidth() const { return (bool) m_wireWidth; }
221 int GetWireWidth() const { return m_wireWidth.value_or( -1 ); }
222 std::optional<int> GetWireWidthOpt() const { return m_wireWidth; }
223 void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
224 void SetWireWidth( std::optional<int> aWidth ) { m_wireWidth = aWidth; }
225 void SetWireWidthParent( NETCLASS* parent) { m_wireWidthParent = parent; }
227
228 bool HasBusWidth() const { return (bool) m_busWidth; }
229 int GetBusWidth() const { return m_busWidth.value_or( -1 ); }
230 std::optional<int> GetBusWidthOpt() const { return m_busWidth; }
231 void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
232 void SetBusWidth( std::optional<int> aWidth ) { m_busWidth = aWidth; }
233 void SetBusWidthParent( NETCLASS* parent) { m_busWidthParent = parent; }
235
236 COLOR4D GetSchematicColor( bool aIsForSave = false ) const
237 {
238 // If we are saving netclases, return the underlying color (which may be set from an old
239 // schematic with a default color set - this allows us to roll back the no-default-colors
240 // changes later if required)
241 if( aIsForSave || !m_isDefault )
242 return m_schematicColor;
243
245 }
246 void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
249
250 bool HasLineStyle() const { return (bool) m_lineStyle; }
251 int GetLineStyle() const { return m_lineStyle.value_or( 0 ); }
252 std::optional<int> GetLineStyleOpt() const { return m_lineStyle; }
253 void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
254 void SetLineStyle( std::optional<int> aStyle ) { m_lineStyle = aStyle; }
255 void SetLineStyleParent( NETCLASS* parent) { m_lineStyleParent = parent; }
257
258 void SetPriority( int aPriority ) { m_Priority = aPriority; }
259 int GetPriority() const { return m_Priority; }
260
261 bool HasTuningProfile() const { return !m_tuningProfile.empty(); }
262 void SetTuningProfile( const wxString& aTuningProfile ) { m_tuningProfile = aTuningProfile; }
263 wxString GetTuningProfile() const { return m_tuningProfile; }
266
267protected:
269
270 std::vector<NETCLASS*> m_constituents;
271
272 wxString m_Name;
274 wxString m_Description;
275
276 std::optional<int> m_Clearance;
277
278 std::optional<int> m_TrackWidth;
279 std::optional<int> m_ViaDia;
280 std::optional<int> m_ViaDrill;
281
282 std::optional<int> m_uViaDia;
283 std::optional<int> m_uViaDrill;
284
285 std::optional<int> m_diffPairWidth;
286 std::optional<int> m_diffPairGap;
287 std::optional<int> m_diffPairViaGap;
288
289 std::optional<int> m_wireWidth;
290 std::optional<int> m_busWidth;
292 std::optional<int> m_lineStyle;
293
295
297
298 // The NETCLASS providing each parameter
314};
315
316#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:400
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
void SetViaDiameter(int aDia)
Definition netclass.h:152
void SetViaDrill(int aSize)
Definition netclass.h:160
bool HasLineStyle() const
Definition netclass.h:250
int GetViaDiameter() const
Definition netclass.h:150
int GetViaDrill() const
Definition netclass.h:158
void SetWireWidthParent(NETCLASS *parent)
Definition netclass.h:225
void SetWireWidth(std::optional< int > aWidth)
Definition netclass.h:224
COLOR4D m_pcbColor
Optional PCB color override for this netclass.
Definition netclass.h:294
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:45
void SetuViaDrillParent(NETCLASS *parent)
Definition netclass.h:178
void SetPriority(int aPriority)
Definition netclass.h:258
void SetViaDrill(std::optional< int > aSize)
Definition netclass.h:161
void SetClearance(std::optional< int > aClearance)
Definition netclass.h:137
~NETCLASS()
Definition netclass.h:55
bool HasBusWidth() const
Definition netclass.h:228
bool HasuViaDrill() const
Definition netclass.h:173
NETCLASS * m_pcbColorParent
Definition netclass.h:308
void SetDiffPairWidthParent(NETCLASS *parent)
Definition netclass.h:186
void SetuViaDiameter(int aSize)
Definition netclass.h:168
void SetDiffPairWidth(int aSize)
Definition netclass.h:184
NETCLASS * m_diffPairWidthParent
Definition netclass.h:305
NETCLASS * m_uViaDrillParent
Definition netclass.h:304
std::optional< int > m_ViaDrill
via drill hole diameter
Definition netclass.h:280
int HasViaDrill() const
Definition netclass.h:157
int GetDiffPairViaGap() const
Definition netclass.h:198
void SetViaDrillParent(NETCLASS *parent)
Definition netclass.h:162
std::optional< int > m_wireWidth
Definition netclass.h:289
int GetPriority() const
Definition netclass.h:259
bool m_isDefault
Mark if this instance is the default netclass.
Definition netclass.h:268
wxString GetTuningProfile() const
Definition netclass.h:263
std::optional< int > m_busWidth
Definition netclass.h:290
void SetDiffPairGapParent(NETCLASS *parent)
Definition netclass.h:194
void SetTuningProfileParent(NETCLASS *aParent)
Definition netclass.h:264
NETCLASS * GetViaDrillParent() const
Definition netclass.h:163
int GetDiffPairGap() const
Definition netclass.h:190
NETCLASS * m_diffPairGapParent
Definition netclass.h:306
int GetuViaDrill() const
Definition netclass.h:174
std::optional< int > GetBusWidthOpt() const
Definition netclass.h:230
void SetViaDiameter(std::optional< int > aDia)
Definition netclass.h:153
void SetLineStyle(int aStyle)
Definition netclass.h:253
bool HasViaDiameter() const
Definition netclass.h:149
NETCLASS * GetBusWidthParent() const
Definition netclass.h:234
std::optional< int > m_TrackWidth
track width used to route nets
Definition netclass.h:278
NETCLASS * m_viaDiameterParent
Definition netclass.h:301
int GetLineStyle() const
Definition netclass.h:251
int m_Priority
The priority for multiple netclass resolution.
Definition netclass.h:273
NETCLASS(const wxString &aName, bool aInitWithDefaults=true)
Create a NETCLASS instance with aName.
Definition netclass.cpp:52
void SetSchematicColor(COLOR4D aColor)
Definition netclass.h:246
std::optional< int > m_diffPairWidth
Definition netclass.h:285
bool HasDiffPairWidth() const
Definition netclass.h:181
std::optional< int > GetTrackWidthOpt() const
Definition netclass.h:143
NETCLASS & operator=(const NETCLASS &)=delete
wxString m_tuningProfile
The tuning profile name being used by this netclass.
Definition netclass.h:296
COLOR4D m_schematicColor
Definition netclass.h:291
std::optional< int > m_diffPairViaGap
Definition netclass.h:287
void SetLineStyleParent(NETCLASS *parent)
Definition netclass.h:255
NETCLASS * GetTuningProfileParent() const
Definition netclass.h:265
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:279
void SetDiffPairViaGap(int aSize)
Definition netclass.h:200
std::optional< int > GetViaDiameterOpt() const
Definition netclass.h:151
std::optional< int > GetWireWidthOpt() const
Definition netclass.h:222
bool HasuViaDiameter() const
Definition netclass.h:165
void SetTrackWidthParent(NETCLASS *parent)
Definition netclass.h:146
std::optional< int > m_lineStyle
Definition netclass.h:292
int GetuViaDiameter() const
Definition netclass.h:166
wxString GetClass() const
Definition netclass.h:75
void SetDiffPairViaGap(std::optional< int > aSize)
Definition netclass.h:201
NETCLASS * GetTrackWidthParent() const
Definition netclass.h:147
NETCLASS * GetClearanceParent() const
Definition netclass.h:139
std::optional< int > GetClearanceOpt() const
Definition netclass.h:135
void SetLineStyle(std::optional< int > aStyle)
Definition netclass.h:254
std::optional< int > GetuViaDiameterOpt() const
Definition netclass.h:167
bool HasTrackWidth() const
Definition netclass.h:141
void SetViaDiameterParent(NETCLASS *parent)
Definition netclass.h:154
void SetPcbColor(const COLOR4D &aColor)
Definition netclass.h:216
NETCLASS * m_viaDrillParent
Definition netclass.h:302
NETCLASS * m_lineStyleParent
Definition netclass.h:312
void SetuViaDiameter(std::optional< int > aSize)
Definition netclass.h:169
std::optional< int > GetDiffPairViaGapOpt() const
Definition netclass.h:199
std::optional< int > m_Clearance
clearance when routing
Definition netclass.h:276
void SetTrackWidth(std::optional< int > aWidth)
Definition netclass.h:145
void SetDiffPairWidth(std::optional< int > aSize)
Definition netclass.h:185
std::optional< int > m_uViaDia
microvia diameter
Definition netclass.h:282
NETCLASS * GetLineStyleParent() const
Definition netclass.h:256
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:182
NETCLASS * m_tuningProfileParent
Definition netclass.h:313
void SetuViaDrill(int aSize)
Definition netclass.h:176
std::optional< int > GetViaDrillOpt() const
Definition netclass.h:159
int GetWireWidth() const
Definition netclass.h:221
NETCLASS * m_uViaDiaParent
Definition netclass.h:303
void SetDiffPairGap(int aSize)
Definition netclass.h:192
void SetBusWidthParent(NETCLASS *parent)
Definition netclass.h:233
NETCLASS * GetDiffPairWidthParent() const
Definition netclass.h:187
void SetClearance(int aClearance)
Definition netclass.h:136
NETCLASS * m_clearanceParent
Definition netclass.h:299
NETCLASS * GetuViaDrillParent() const
Definition netclass.h:179
NETCLASS * m_diffPairViaGapParent
Definition netclass.h:307
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition netclass.h:206
NETCLASS * GetDiffPairViaGapParent() const
Definition netclass.h:203
NETCLASS(const NETCLASS &)=delete
bool HasDiffPairGap() const
Definition netclass.h:189
void SetDescription(const wxString &aDesc)
Definition netclass.h:131
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:236
const wxString & GetDescription() const
Definition netclass.h:130
void SetPcbColorParent(NETCLASS *parent)
Definition netclass.h:217
NETCLASS * m_schematicColorParent
Definition netclass.h:311
void SetuViaDrill(std::optional< int > aSize)
Definition netclass.h:177
NETCLASS * m_busWidthParent
Definition netclass.h:310
std::optional< int > m_uViaDrill
microvia drill hole diameter
Definition netclass.h:283
void SetBusWidth(int aWidth)
Definition netclass.h:231
std::optional< int > GetDiffPairWidthOpt() const
Definition netclass.h:183
void SetClearanceParent(NETCLASS *parent)
Definition netclass.h:138
int GetTrackWidth() const
Definition netclass.h:142
void SetWireWidth(int aWidth)
Definition netclass.h:223
void SetDiffPairViaGapParent(NETCLASS *parent)
Definition netclass.h:202
void SetTuningProfile(const wxString &aTuningProfile)
Definition netclass.h:262
bool HasTuningProfile() const
Definition netclass.h:261
bool HasWireWidth() const
Definition netclass.h:220
NETCLASS * m_wireWidthParent
Definition netclass.h:309
int GetClearance() const
Definition netclass.h:134
std::optional< int > GetuViaDrillOpt() const
Definition netclass.h:175
void SetuViaDiameterParent(NETCLASS *parent)
Definition netclass.h:170
NETCLASS * m_trackWidthParent
Definition netclass.h:300
void SetSchematicColorParent(NETCLASS *parent)
Definition netclass.h:247
void SetBusWidth(std::optional< int > aWidth)
Definition netclass.h:232
void SetName(const wxString &aName)
Set the name of this netclass.
Definition netclass.h:109
std::optional< int > GetLineStyleOpt() const
Definition netclass.h:252
void SetTrackWidth(int aWidth)
Definition netclass.h:144
std::vector< NETCLASS * > m_constituents
NETCLASSes contributing to an aggregate.
Definition netclass.h:270
std::optional< int > GetDiffPairGapOpt() const
Definition netclass.h:191
void SetDiffPairGap(std::optional< int > aSize)
Definition netclass.h:193
NETCLASS * GetWireWidthParent() const
Definition netclass.h:226
NETCLASS * GetSchematicColorParent() const
Definition netclass.h:248
NETCLASS * GetDiffPairGapParent() const
Definition netclass.h:195
std::optional< int > m_diffPairGap
Definition netclass.h:286
bool HasDiffPairViaGap() const
Definition netclass.h:197
NETCLASS * GetPcbColorParent() const
Definition netclass.h:218
NETCLASS * GetViaDiameterParent() const
Definition netclass.h:155
int GetBusWidth() const
Definition netclass.h:229
bool HasClearance() const
Definition netclass.h:133
wxString m_Name
Name of the net class.
Definition netclass.h:272
NETCLASS * GetuViaDiameterParent() const
Definition netclass.h:171
wxString m_Description
what this NETCLASS is for.
Definition netclass.h:274
bool HasPcbColor() const
Definition netclass.h:205
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