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