KiCad PCB EDA Suite
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 <dick@softplc.com>
5  * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr
6  * Copyright (C) 2009-2020 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 <netclass.h>
27 #include <macros.h>
28 #include <base_units.h>
29 
30 // This will get mapped to "kicad_default" in the specctra_export.
31 const char NETCLASS::Default[] = "Default";
32 
33 // Initial values for netclass initialization
34 const int DEFAULT_CLEARANCE = PcbMillimeter2iu( 0.2 ); // track to track and track to pads clearance
43 
44 const int DEFAULT_WIRE_WIDTH = SchMils2iu( 6 );
45 const int DEFAULT_BUS_WIDTH = SchMils2iu( 12 );
46 
47 const int DEFAULT_LINE_STYLE = 0; // solid
48 
49 
50 NETCLASS::NETCLASS( const wxString& aName ) :
51  m_Name( aName ),
52  m_PcbColor( KIGFX::COLOR4D::UNSPECIFIED )
53 {
54  // Default settings
58  // These defaults will be overwritten by SetParams,
59  // from the board design parameters, later
66 
69  SetSchematicColor( COLOR4D::UNSPECIFIED );
71 }
72 
73 
75 {
76 }
77 
78 
80 {
81  m_default = std::make_shared<NETCLASS>( NETCLASS::Default );
82 }
83 
84 
86 {
87 }
88 
89 
90 bool NETCLASSES::Add( const NETCLASSPTR& aNetClass )
91 {
92  const wxString& name = aNetClass->GetName();
93 
94  if( name == NETCLASS::Default )
95  {
96  m_default = aNetClass;
97  return true;
98  }
99 
100  // Test for an existing netclass:
101  if( !Find( name ) )
102  {
103  // name not found, take ownership
104  m_NetClasses[name] = aNetClass;
105 
106  return true;
107  }
108  else
109  {
110  // name already exists
111  // do not "take ownership" and return false telling caller such.
112  return false;
113  }
114 }
115 
116 
117 NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName )
118 {
119  NETCLASS_MAP::iterator found = m_NetClasses.find( aNetName );
120 
121  if( found != m_NetClasses.end() )
122  {
123  std::shared_ptr<NETCLASS> netclass = found->second;
124  m_NetClasses.erase( found );
125  return netclass;
126  }
127 
128  return NETCLASSPTR();
129 }
130 
131 
132 NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const
133 {
134  if( aName == NETCLASS::Default )
135  return GetDefault();
136 
137  NETCLASS_MAP::const_iterator found = m_NetClasses.find( aName );
138 
139  if( found == m_NetClasses.end() )
140  return NETCLASSPTR();
141  else
142  return found->second;
143 }
144 
145 
146 #if defined(DEBUG)
147 
148 void NETCLASS::Show( int nestLevel, std::ostream& os ) const
149 {
150  // for now, make it look like XML:
151  //NestedSpace( nestLevel, os )
152 
153  os << '<' << GetClass().Lower().mb_str() << ">\n";
154 
155  for( const_iterator i = begin(); i!=end(); ++i )
156  {
157  // NestedSpace( nestLevel+1, os ) << *i;
158  os << TO_UTF8( *i );
159  }
160 
161  // NestedSpace( nestLevel, os )
162  os << "</" << GetClass().Lower().mb_str() << ">\n";
163 }
164 
165 #endif
const int DEFAULT_WIRE_WIDTH
Definition: netclass.cpp:44
void SetDiffPairWidth(int aSize)
Definition: netclass.h:184
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:132
NETCLASSPTR m_default
Definition: netclass.h:228
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
wxString GetClass() const
Definition: netclass.h:91
Implementation of conversion functions that require both schematic and board internal units.
const int DEFAULT_LINE_STYLE
Definition: netclass.cpp:47
const int DEFAULT_VIA_DIAMETER
Definition: netclass.cpp:35
void SetLineStyle(int aStyle)
Definition: netclass.h:207
void SetTrackWidth(int aWidth)
Definition: netclass.h:164
void SetWireWidth(int aWidth)
Definition: netclass.h:198
void SetViaDrill(int aSize)
Definition: netclass.h:172
iterator begin()
Definition: netclass.h:128
This file contains miscellaneous commonly used macros and functions.
void SetDiffPairGap(int aSize)
Definition: netclass.h:188
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
constexpr int PcbMillimeter2iu(double mm)
NETCLASS(const wxString &aName)
Constructor stuffs a NETCLASS instance with aParent, aName, and optionally the initialParameters.
Definition: netclass.cpp:50
iterator end()
Definition: netclass.h:129
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
void SetClearance(int aClearance)
Definition: netclass.h:160
~NETCLASS()
Definition: netclass.cpp:74
const int DEFAULT_UVIA_DIAMETER
Definition: netclass.cpp:37
const int DEFAULT_CLEARANCE
Definition: netclass.cpp:34
const int DEFAULT_DIFF_PAIR_VIAGAP
Definition: netclass.cpp:42
void SetSchematicColor(COLOR4D aColor)
Definition: netclass.h:204
const int DEFAULT_DIFF_PAIR_GAP
Definition: netclass.cpp:41
void SetuViaDiameter(int aSize)
Definition: netclass.h:176
NETCLASSPTR Remove(const wxString &aNetName)
Function Remove removes a NETCLASS from this container but does not destroy/delete it.
Definition: netclass.cpp:117
void SetBusWidth(int aWidth)
Definition: netclass.h:201
void SetDiffPairViaGap(int aSize)
Definition: netclass.h:192
const int DEFAULT_VIA_DRILL
Definition: netclass.cpp:36
bool Add(const NETCLASSPTR &aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:90
void SetuViaDrill(int aSize)
Definition: netclass.h:180
const int DEFAULT_DIFF_PAIR_WIDTH
Definition: netclass.cpp:40
const int DEFAULT_TRACK_WIDTH
Definition: netclass.cpp:39
const char * name
Definition: DXF_plotter.cpp:59
const int DEFAULT_BUS_WIDTH
Definition: netclass.cpp:45
STRINGSET::const_iterator const_iterator
Definition: netclass.h:131
void SetViaDiameter(int aDia)
Definition: netclass.h:168
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:266
constexpr int SchMils2iu(int mils)
NETCLASS_MAP m_NetClasses
Definition: netclass.h:227
const int DEFAULT_UVIA_DRILL
Definition: netclass.cpp:38
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100