KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netclass.cpp
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 (C) 2009-2022 KiCad Developers, see change_log.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#include <algorithm>
27#include <netclass.h>
28#include <macros.h>
29#include <base_units.h>
30
31// This will get mapped to "kicad_default" in the specctra_export.
32const char NETCLASS::Default[] = "Default";
33
34// Initial values for netclass initialization
35const int DEFAULT_CLEARANCE = pcbIUScale.mmToIU( 0.2 ); // track to track and track to pads clearance
44
47
48const int DEFAULT_LINE_STYLE = 0; // solid
49
50
51NETCLASS::NETCLASS( const wxString& aName, bool aInitWithDefaults ) : m_isDefault( false )
52{
53 m_constituents.push_back( this );
54
55 SetName( aName );
56 SetPriority( -1 );
57
58 // Colors are a special optional case - always set, but UNSPECIFIED used in place of optional
59 SetPcbColor( COLOR4D::UNSPECIFIED );
60 SetSchematicColor( COLOR4D::UNSPECIFIED );
61
62 if( aInitWithDefaults )
63 {
73
77 }
78
80}
81
82
84{
85 SetClearanceParent( this );
86 SetTrackWidthParent( this );
88 SetViaDrillParent( this );
90 SetuViaDrillParent( this );
94 SetPcbColorParent( this );
95 SetWireWidthParent( this );
96 SetBusWidthParent( this );
98 SetLineStyleParent( this );
99}
100
101
103{
104 SetPcbColor( COLOR4D::UNSPECIFIED );
105 SetSchematicColor( COLOR4D::UNSPECIFIED );
106 SetClearance( std::optional<int>() );
107 SetViaDrill( std::optional<int>() );
108 SetuViaDrill( std::optional<int>() );
109 SetTrackWidth( std::optional<int>() );
110 SetViaDiameter( std::optional<int>() );
111 SetuViaDiameter( std::optional<int>() );
112 SetDiffPairWidth( std::optional<int>() );
113 SetDiffPairGap( std::optional<int>() );
114 SetDiffPairViaGap( std::optional<int>() );
115 SetWireWidth( std::optional<int>() );
116 SetBusWidth( std::optional<int>() );
117 SetLineStyle( std::optional<int>() );
118
119 ResetParents();
120}
121
122
123bool NETCLASS::operator==( const NETCLASS& other ) const
124{
125 return m_constituents == other.m_constituents;
126}
127
128
129const std::vector<NETCLASS*>& NETCLASS::GetConstituentNetclasses() const
130{
131 return m_constituents;
132}
133
134
135void NETCLASS::SetConstituentNetclasses( std::vector<NETCLASS*>&& constituents )
136{
137 m_constituents = std::move( constituents );
138}
139
140
141bool NETCLASS::ContainsNetclassWithName( const wxString& netclass ) const
142{
143 return std::any_of( m_constituents.begin(), m_constituents.end(),
144 [&netclass]( const NETCLASS* nc )
145 {
146 return nc->GetName() == netclass;
147 } );
148}
149
150
151const wxString NETCLASS::GetName() const
152{
153 if( m_constituents.size() == 1 )
154 return m_Name;
155
156 wxASSERT( m_constituents.size() >= 2 );
157
158 wxString name;
159
160 if( m_constituents.size() == 2 )
161 {
162 name.Printf( _( "%s and %s" ), m_constituents[0]->GetName(), m_constituents[1]->GetName() );
163 }
164 else if( m_constituents.size() == 3 )
165 {
166 name.Printf( _( "%s, %s and %s" ), m_constituents[0]->GetName(),
168 }
169 else if( m_constituents.size() > 3 )
170 {
171 name.Printf( _( "%s, %s and %d more" ), m_constituents[0]->GetName(),
172 m_constituents[1]->GetName(), static_cast<int>( m_constituents.size() - 2 ) );
173 }
174
175 return name;
176}
177
178
180{
181 if( m_constituents.size() == 1 )
182 return m_Name;
183
184 wxASSERT( m_constituents.size() >= 2 );
185
186 wxString name = m_constituents[0]->GetName();
187
188 for( std::size_t i = 1; i < m_constituents.size(); ++i )
189 {
190 name += ",";
191 name += m_constituents[i]->GetName();
192 }
193
194 return name;
195}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
void SetViaDiameter(int aDia)
Definition: netclass.h:122
void SetViaDrill(int aSize)
Definition: netclass.h:130
void SetWireWidthParent(NETCLASS *parent)
Definition: netclass.h:195
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:46
void SetuViaDrillParent(NETCLASS *parent)
Definition: netclass.h:148
void SetPriority(int aPriority)
Definition: netclass.h:228
void SetDiffPairWidthParent(NETCLASS *parent)
Definition: netclass.h:156
void SetuViaDiameter(int aSize)
Definition: netclass.h:138
void SetDiffPairWidth(int aSize)
Definition: netclass.h:154
void SetViaDrillParent(NETCLASS *parent)
Definition: netclass.h:132
void SetDiffPairGapParent(NETCLASS *parent)
Definition: netclass.h:164
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition: netclass.cpp:141
void ResetParents()
Resets all parent fields to point to this netclass.
Definition: netclass.cpp:83
void SetLineStyle(int aStyle)
Definition: netclass.h:223
NETCLASS(const wxString &aName, bool aInitWithDefaults=true)
Create a NETCLASS instance with aName.
Definition: netclass.cpp:51
void SetSchematicColor(COLOR4D aColor)
Definition: netclass.h:216
const wxString GetName() const
Gets the consolidated name of this netclass (which may be an aggregate)
Definition: netclass.cpp:151
void SetConstituentNetclasses(std::vector< NETCLASS * > &&constituents)
Sets the netclasses which make up this netclass.
Definition: netclass.cpp:135
void SetLineStyleParent(NETCLASS *parent)
Definition: netclass.h:225
void SetDiffPairViaGap(int aSize)
Definition: netclass.h:170
void ResetParameters()
Resets all parameters (except Name and Description)
Definition: netclass.cpp:102
void SetTrackWidthParent(NETCLASS *parent)
Definition: netclass.h:116
const std::vector< NETCLASS * > & GetConstituentNetclasses() const
Gets the netclasses which make up this netclass.
Definition: netclass.cpp:129
void SetViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:124
void SetPcbColor(const COLOR4D &aColor)
Definition: netclass.h:186
void SetuViaDrill(int aSize)
Definition: netclass.h:146
const wxString GetVariableSubstitutionName() const
Gets the name of this (maybe aggregate) netclass in a format for label variable substitutions.
Definition: netclass.cpp:179
void SetDiffPairGap(int aSize)
Definition: netclass.h:162
void SetBusWidthParent(NETCLASS *parent)
Definition: netclass.h:203
void SetClearance(int aClearance)
Definition: netclass.h:106
bool operator==(const NETCLASS &other) const
Definition: netclass.cpp:123
void SetPcbColorParent(NETCLASS *parent)
Definition: netclass.h:187
void SetBusWidth(int aWidth)
Definition: netclass.h:201
void SetClearanceParent(NETCLASS *parent)
Definition: netclass.h:108
void SetWireWidth(int aWidth)
Definition: netclass.h:193
void SetDiffPairViaGapParent(NETCLASS *parent)
Definition: netclass.h:172
void SetuViaDiameterParent(NETCLASS *parent)
Definition: netclass.h:140
void SetSchematicColorParent(NETCLASS *parent)
Definition: netclass.h:217
void SetName(const wxString &aName)
Definition: netclass.h:92
void SetTrackWidth(int aWidth)
Definition: netclass.h:114
std::vector< NETCLASS * > m_constituents
NETCLASSes contributing to an aggregate.
Definition: netclass.h:234
wxString m_Name
Name of the net class.
Definition: netclass.h:236
#define _(s)
This file contains miscellaneous commonly used macros and functions.
const int DEFAULT_UVIA_DIAMETER
Definition: netclass.cpp:38
const int DEFAULT_DIFF_PAIR_WIDTH
Definition: netclass.cpp:41
const int DEFAULT_DIFF_PAIR_GAP
Definition: netclass.cpp:42
const int DEFAULT_DIFF_PAIR_VIAGAP
Definition: netclass.cpp:43
const int DEFAULT_LINE_STYLE
Definition: netclass.cpp:48
const int DEFAULT_CLEARANCE
Definition: netclass.cpp:35
const int DEFAULT_UVIA_DRILL
Definition: netclass.cpp:39
const int DEFAULT_TRACK_WIDTH
Definition: netclass.cpp:40
const int DEFAULT_WIRE_WIDTH
Definition: netclass.cpp:45
const int DEFAULT_VIA_DRILL
Definition: netclass.cpp:37
const int DEFAULT_VIA_DIAMETER
Definition: netclass.cpp:36
const int DEFAULT_BUS_WIDTH
Definition: netclass.cpp:46
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
constexpr int mmToIU(double mm) const
Definition: base_units.h:88