KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netinfo.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 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Classes to handle info on nets
27 */
28
29#ifndef CLASS_NETINFO_
30#define CLASS_NETINFO_
31
32#include <macros_swig.h>
33#include <netclass.h>
34#include <board_item.h>
35
36
37class EDA_DRAW_FRAME;
38class PAD;
39class PCB_TRACK;
40class BOARD;
41class BOARD_ITEM;
42class BOARD_COMMIT;
43class MSG_PANEL_ITEM;
44class PCB_BASE_FRAME;
45
46
47DECL_VEC_FOR_SWIG( PADS_VEC, PAD* )
48DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* )
49
50
54{
55public:
56
57 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
59
60 static inline bool ClassOf( const EDA_ITEM* aItem )
61 {
62 return aItem && PCB_NETINFO_T == aItem->Type();
63 }
64
65 wxString GetClass() const override
66 {
67 return wxT( "NETINFO_ITEM" );
68 }
69
70#if defined(DEBUG)
71 void Show( int nestLevel, std::ostream& os ) const override
72 {
73 }
74#endif
75
76 const BOX2I GetBoundingBox() const override;
77
78 VECTOR2I GetPosition() const override
79 {
80 static VECTOR2I dummy( 0, 0 );
81 return dummy;
82 }
83
84 void SetPosition( const VECTOR2I& aPos ) override
85 {
86 }
87
88 EDA_ITEM* Clone() const override
89 {
90 return new NETINFO_ITEM( *this );
91 }
92
93 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
94
99 NETCLASS* GetNetClass() { return m_netClass.get(); }
100
104 std::shared_ptr<NETCLASS> GetNetClassSlow() { return m_netClass; }
105
106 int GetNetCode() const { return m_netCode; }
107 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
108
112 const wxString& GetNetname() const { return m_netname; }
113
117 const wxString& GetShortNetname() const { return m_shortNetname; }
118
122 const wxString& GetDisplayNetname() const { return m_displayNetname; }
123
127 bool HasAutoGeneratedNetname() const;
128
133 void SetNetname( const wxString& aNewName );
134
135 bool IsCurrent() const { return m_isCurrent; }
136 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
137
144 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
145
149 void Clear();
150
151 void SetParent( BOARD* aParent ) { m_parent = aParent; }
152 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
153 {
154 return m_parent;
155 }
156
157 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
158
159 double Similarity( const BOARD_ITEM& aBoardItem ) const override
160 {
161 return 0.0;
162 }
163
164 bool operator==( const BOARD_ITEM& aBoardItem ) const override
165 {
166 return 0.0;
167 }
168
169protected:
170 // Hide base SetParent method to make the BOARD* method the prefered method for this class
172
173private:
174 friend class NETINFO_LIST;
175
177 wxString m_netname;
178 wxString m_shortNetname;
179
184
185 std::shared_ptr<NETCLASS> m_netClass;
186
190
192};
193
194
195#if 0
196// waiting for swig to support std::unordered_map, see
197// http://www.swig.org/Doc3.0/CPlusPlus11.html
198// section 7.3.3
199#include <hashtables.h>
200DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
201DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
202#else
203// use std::map for now
204DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
205DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
206#endif
207
212{
213 friend class BOARD;
214
215public:
216 NETINFO_LIST( BOARD* aParent );
218
223 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
224
229 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
230
235 unsigned GetNetCount() const { return m_netNames.size(); }
236
238 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
239
241 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
242
243 void RebuildDisplayNetnames() const;
244
247 static const int UNCONNECTED;
248
251 static const int ORPHANED;
252
256 {
257 static NETINFO_ITEM* g_orphanedItem;
258
259 if( !g_orphanedItem )
260 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
261
262 return g_orphanedItem;
263 }
264
265#if defined(DEBUG)
266 void Show() const;
267#endif
268
269#ifndef SWIG
273 {
274 public:
275 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
276 {
277 }
278
281 {
282 ++m_iterator;
283 return *this;
284 }
285
288 {
289 iterator ret = *this;
290 ++m_iterator;
291 return ret;
292 }
293
295 {
296 return m_iterator->second;
297 }
298
300 {
301 return m_iterator->second;
302 }
303
304 bool operator!=( const iterator& aOther ) const
305 {
306 return m_iterator != aOther.m_iterator;
307 }
308
309 bool operator==( const iterator& aOther ) const
310 {
311 return m_iterator == aOther.m_iterator;
312 }
313
314 private:
315 NETNAMES_MAP::const_iterator m_iterator;
316 };
317
319 {
320 return iterator( m_netNames.begin() );
321 }
322
323 iterator end() const
324 {
325 return iterator( m_netNames.end() );
326 }
327#endif
328
330 {
331 return m_parent;
332 }
333
334protected: // Access is through the BOARD, which is a friend class
339 void AppendNet( NETINFO_ITEM* aNewElement );
340
344 void RemoveNet( NETINFO_ITEM* aNet );
345 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
346
347private:
351 void clear();
352
358 void buildListOfNets();
359
363 int getFreeNetCode();
364
365public:
367
368private:
370
371 NETNAMES_MAP m_netNames;
372 NETCODES_MAP m_netCodes;
373
375};
376
377#endif // CLASS_NETINFO_
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.h:113
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:54
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:45
Handle the data for a net.
Definition netinfo.h:54
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
Definition netinfo.h:178
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:164
wxString GetClass() const override
Return the class name.
Definition netinfo.h:65
NETINFO_ITEM(BOARD *aParent, const wxString &aNetName=wxEmptyString, int aNetCode=-1)
NETINFO_ITEM class, to handle info on nets: netnames, net constraints.
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition netinfo.h:159
const wxString & GetShortNetname() const
Definition netinfo.h:117
static bool ClassOf(const EDA_ITEM *aItem)
Definition netinfo.h:60
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:180
BOARD * GetParent() const
Definition netinfo.h:152
const wxString & GetNetname() const
Definition netinfo.h:112
void SetNetCode(int aNetCode)
Definition netinfo.h:107
NETCLASS * GetNetClass()
Definition netinfo.h:99
std::shared_ptr< NETCLASS > GetNetClassSlow()
Definition netinfo.h:104
int GetNetCode() const
Definition netinfo.h:106
VECTOR2I GetPosition() const override
Definition netinfo.h:78
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:176
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:185
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition netinfo.h:88
const wxString & GetDisplayNetname() const
Definition netinfo.h:122
void SetParent(BOARD *aParent)
Definition netinfo.h:151
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:177
friend class NETINFO_LIST
Definition netinfo.h:174
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:136
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:187
bool IsCurrent() const
Definition netinfo.h:135
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:84
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:191
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:273
iterator operator++(int)
post-increment operator
Definition netinfo.h:287
bool operator==(const iterator &aOther) const
Definition netinfo.h:309
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:315
bool operator!=(const iterator &aOther) const
Definition netinfo.h:304
const iterator & operator++()
pre-increment operator
Definition netinfo.h:280
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:275
NETINFO_ITEM * operator->() const
Definition netinfo.h:299
NETINFO_ITEM * operator*() const
Definition netinfo.h:294
int getFreeNetCode()
Return the first available net code that is not used by any other net.
void RemoveUnusedNets(BOARD_COMMIT *aCommit)
friend class BOARD
Definition netinfo.h:213
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:247
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:372
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:251
iterator begin() const
Definition netinfo.h:318
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:374
BOARD * GetParent() const
Definition netinfo.h:329
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition netinfo.h:255
unsigned GetNetCount() const
Definition netinfo.h:235
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition netinfo.h:369
NETINFO_ITEM * GetNetItem(int aNetCode) const
NETINFO_LIST(BOARD *aParent)
void clear()
Delete the list of nets (and free memory).
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
Definition netinfo.h:241
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:371
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:366
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:238
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:323
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:54
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define DECL_HASH_FOR_SWIG(TypeName, KeyType, ValueType)
Declare a std::unordered_map but no swig template.
Definition hashtables.h:73
This file contains macros just for swig binding.
#define DECL_MAP_FOR_SWIG(TypeName, KeyType, ValueType)
Definition macros_swig.h:52
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition macros_swig.h:50
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:110
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695