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
196{
197public:
199 {
200 m_board = nullptr;
201 }
202
203
207 void SetBoard( const BOARD* aBoard )
208 {
209 m_board = aBoard;
210 Update();
211 }
212
218 void Update();
219
228 int Translate( int aNetCode ) const;
229
233 {
234 public:
235 iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
236 m_iterator( aIter ), m_mapping( aMapping )
237 {
238 }
239
242 {
243 ++m_iterator;
244
245 return *this;
246 }
247
250 {
251 iterator ret = *this;
252 ++m_iterator;
253
254 return ret;
255 }
256
257 NETINFO_ITEM* operator*() const;
258
259 NETINFO_ITEM* operator->() const;
260
261 bool operator!=( const iterator& aOther ) const
262 {
263 return m_iterator != aOther.m_iterator;
264 }
265
266 bool operator==( const iterator& aOther ) const
267 {
268 return m_iterator == aOther.m_iterator;
269 }
270
271 private:
272 std::map<int, int>::const_iterator m_iterator;
274 };
275
283 {
284 return iterator( m_netMapping.begin(), this );
285 }
286
293 iterator end() const
294 {
295 return iterator( m_netMapping.end(), this );
296 }
297
301 int GetSize() const
302 {
303 return m_netMapping.size();
304 }
305
306private:
307 const BOARD* m_board;
308 std::map<int, int> m_netMapping;
310};
311
312
313#if 0
314// waiting for swig to support std::unordered_map, see
315// http://www.swig.org/Doc3.0/CPlusPlus11.html
316// section 7.3.3
317#include <hashtables.h>
318DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
319DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
320#else
321// use std::map for now
322DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
323DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
324#endif
325
330{
331 friend class BOARD;
332
333public:
334 NETINFO_LIST( BOARD* aParent );
336
341 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
342
347 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
348
353 unsigned GetNetCount() const { return m_netNames.size(); }
354
356 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
357
359 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
360
361 void RebuildDisplayNetnames() const;
362
365 static const int UNCONNECTED;
366
369 static const int ORPHANED;
370
374 {
375 static NETINFO_ITEM* g_orphanedItem;
376
377 if( !g_orphanedItem )
378 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
379
380 return g_orphanedItem;
381 }
382
383#if defined(DEBUG)
384 void Show() const;
385#endif
386
387#ifndef SWIG
391 {
392 public:
393 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
394 {
395 }
396
399 {
400 ++m_iterator;
401 return *this;
402 }
403
406 {
407 iterator ret = *this;
408 ++m_iterator;
409 return ret;
410 }
411
413 {
414 return m_iterator->second;
415 }
416
418 {
419 return m_iterator->second;
420 }
421
422 bool operator!=( const iterator& aOther ) const
423 {
424 return m_iterator != aOther.m_iterator;
425 }
426
427 bool operator==( const iterator& aOther ) const
428 {
429 return m_iterator == aOther.m_iterator;
430 }
431
432 private:
433 NETNAMES_MAP::const_iterator m_iterator;
434 };
435
437 {
438 return iterator( m_netNames.begin() );
439 }
440
441 iterator end() const
442 {
443 return iterator( m_netNames.end() );
444 }
445#endif
446
448 {
449 return m_parent;
450 }
451
452protected: // Access is through the BOARD, which is a friend class
457 void AppendNet( NETINFO_ITEM* aNewElement );
458
462 void RemoveNet( NETINFO_ITEM* aNet );
463 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
464
465private:
469 void clear();
470
476 void buildListOfNets();
477
481 int getFreeNetCode();
482
483public:
485
486private:
488
489 NETNAMES_MAP m_netNames;
490 NETCODES_MAP m_netCodes;
491
493};
494
495#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:317
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:391
iterator operator++(int)
post-increment operator
Definition netinfo.h:405
bool operator==(const iterator &aOther) const
Definition netinfo.h:427
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:433
bool operator!=(const iterator &aOther) const
Definition netinfo.h:422
const iterator & operator++()
pre-increment operator
Definition netinfo.h:398
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:393
NETINFO_ITEM * operator->() const
Definition netinfo.h:417
NETINFO_ITEM * operator*() const
Definition netinfo.h:412
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:331
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:365
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:490
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:369
iterator begin() const
Definition netinfo.h:436
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:492
BOARD * GetParent() const
Definition netinfo.h:447
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:373
unsigned GetNetCount() const
Definition netinfo.h:353
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition netinfo.h:487
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:359
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:489
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:484
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:356
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:441
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:233
NETINFO_ITEM * operator->() const
const NETINFO_MAPPING * m_mapping
Definition netinfo.h:273
std::map< int, int >::const_iterator m_iterator
Definition netinfo.h:272
bool operator!=(const iterator &aOther) const
Definition netinfo.h:261
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition netinfo.h:235
iterator operator++(int)
post-increment operator
Definition netinfo.h:249
NETINFO_ITEM * operator*() const
const iterator & operator++()
pre-increment operator
Definition netinfo.h:241
bool operator==(const iterator &aOther) const
Definition netinfo.h:266
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition netinfo.h:207
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
int GetSize() const
Definition netinfo.h:301
iterator end() const
Return iterator to the last entry in the mapping.
Definition netinfo.h:293
void Update()
Prepare a mapping for net codes so they can be saved as consecutive numbers.
const BOARD * m_board
Board for which mapping is prepared.
Definition netinfo.h:307
iterator begin() const
Return iterator to the first entry in the mapping.
Definition netinfo.h:282
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition netinfo.h:308
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:109
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695