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 (C) 1992-2023 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 <gr_basic.h>
34#include <netclass.h>
35#include <board_item.h>
36#include <string_utils.h>
37
38
39class EDA_DRAW_FRAME;
40class PAD;
41class PCB_TRACK;
42class BOARD;
43class BOARD_ITEM;
44class BOARD_COMMIT;
45class MSG_PANEL_ITEM;
46class PCB_BASE_FRAME;
47
48
49DECL_VEC_FOR_SWIG( PADS_VEC, PAD* )
50DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* )
51
52
56{
57public:
58
59 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
61
62 static inline bool ClassOf( const EDA_ITEM* aItem )
63 {
64 return aItem && PCB_NETINFO_T == aItem->Type();
65 }
66
67 wxString GetClass() const override
68 {
69 return wxT( "NETINFO_ITEM" );
70 }
71
72#if defined(DEBUG)
73 void Show( int nestLevel, std::ostream& os ) const override
74 {
75 }
76#endif
77
78 const BOX2I GetBoundingBox() const override;
79
80 VECTOR2I GetPosition() const override
81 {
82 static VECTOR2I dummy( 0, 0 );
83 return dummy;
84 }
85
86 void SetPosition( const VECTOR2I& aPos ) override
87 {
88 }
89
90 EDA_ITEM* Clone() const override
91 {
92 return new NETINFO_ITEM( *this );
93 }
94
95 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
96
101 NETCLASS* GetNetClass() { return m_netClass.get(); }
102
106 std::shared_ptr<NETCLASS> GetNetClassSlow() { return m_netClass; }
107
108 int GetNetCode() const { return m_netCode; }
109 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
110
114 const wxString& GetNetname() const { return m_netname; }
115
119 const wxString& GetShortNetname() const { return m_shortNetname; }
120
124 const wxString& GetDisplayNetname() const { return m_displayNetname; }
125
130 {
131 return m_shortNetname.StartsWith( wxT( "Net-(" ) )
132 || m_shortNetname.StartsWith( wxT( "unconnected-(" ) );
133 }
134
139 void SetNetname( const wxString& aNewName )
140 {
141 m_netname = aNewName;
142
143 if( aNewName.Contains( wxT( "/" ) ) )
144 m_shortNetname = aNewName.AfterLast( '/' );
145 else
146 m_shortNetname = aNewName;
147
148 m_displayNetname = UnescapeString( m_shortNetname );
149 }
150
151 bool IsCurrent() const { return m_isCurrent; }
152 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
153
160 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
161
165 void Clear();
166
167 void SetParent( BOARD* aParent ) { m_parent = aParent; }
168 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
169 {
170 return m_parent;
171 }
172
173 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
174
175 double Similarity( const BOARD_ITEM& aBoardItem ) const override
176 {
177 return 0.0;
178 }
179
180 bool operator==( const BOARD_ITEM& aBoardItem ) const override
181 {
182 return 0.0;
183 }
184
185protected:
186 // Hide base SetParent method to make the BOARD* method the prefered method for this class
188
189private:
190 friend class NETINFO_LIST;
191
193 wxString m_netname;
194 wxString m_shortNetname;
195
200
201 std::shared_ptr<NETCLASS> m_netClass;
202
206
208};
209
210
212{
213public:
215 {
216 m_board = nullptr;
217 }
218
219
223 void SetBoard( const BOARD* aBoard )
224 {
225 m_board = aBoard;
226 Update();
227 }
228
234 void Update();
235
244 int Translate( int aNetCode ) const;
245
249 {
250 public:
251 iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
252 m_iterator( aIter ), m_mapping( aMapping )
253 {
254 }
255
258 {
259 ++m_iterator;
260
261 return *this;
262 }
263
266 {
267 iterator ret = *this;
268 ++m_iterator;
269
270 return ret;
271 }
272
273 NETINFO_ITEM* operator*() const;
274
275 NETINFO_ITEM* operator->() const;
276
277 bool operator!=( const iterator& aOther ) const
278 {
279 return m_iterator != aOther.m_iterator;
280 }
281
282 bool operator==( const iterator& aOther ) const
283 {
284 return m_iterator == aOther.m_iterator;
285 }
286
287 private:
288 std::map<int, int>::const_iterator m_iterator;
290 };
291
299 {
300 return iterator( m_netMapping.begin(), this );
301 }
302
309 iterator end() const
310 {
311 return iterator( m_netMapping.end(), this );
312 }
313
317 int GetSize() const
318 {
319 return m_netMapping.size();
320 }
321
322private:
323 const BOARD* m_board;
324 std::map<int, int> m_netMapping;
326};
327
328
329#if 0
330// waiting for swig to support std::unordered_map, see
331// http://www.swig.org/Doc3.0/CPlusPlus11.html
332// section 7.3.3
333#include <hashtables.h>
334DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
335DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
336#else
337// use std::map for now
338DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
339DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
340#endif
341
346{
347 friend class BOARD;
348
349public:
350 NETINFO_LIST( BOARD* aParent );
352
357 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
358
363 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
364
369 unsigned GetNetCount() const { return m_netNames.size(); }
370
372 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
373
375 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
376
377 void RebuildDisplayNetnames() const;
378
381 static const int UNCONNECTED;
382
385 static const int ORPHANED;
386
390 {
391 static NETINFO_ITEM* g_orphanedItem;
392
393 if( !g_orphanedItem )
394 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
395
396 return g_orphanedItem;
397 }
398
399#if defined(DEBUG)
400 void Show() const;
401#endif
402
403#ifndef SWIG
407 {
408 public:
409 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
410 {
411 }
412
415 {
416 ++m_iterator;
417 return *this;
418 }
419
422 {
423 iterator ret = *this;
424 ++m_iterator;
425 return ret;
426 }
427
429 {
430 return m_iterator->second;
431 }
432
434 {
435 return m_iterator->second;
436 }
437
438 bool operator!=( const iterator& aOther ) const
439 {
440 return m_iterator != aOther.m_iterator;
441 }
442
443 bool operator==( const iterator& aOther ) const
444 {
445 return m_iterator == aOther.m_iterator;
446 }
447
448 private:
449 NETNAMES_MAP::const_iterator m_iterator;
450 };
451
453 {
454 return iterator( m_netNames.begin() );
455 }
456
457 iterator end() const
458 {
459 return iterator( m_netNames.end() );
460 }
461#endif
462
464 {
465 return m_parent;
466 }
467
468protected: // Access is through the BOARD, which is a friend class
473 void AppendNet( NETINFO_ITEM* aNewElement );
474
478 void RemoveNet( NETINFO_ITEM* aNet );
479 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
480
481private:
485 void clear();
486
492 void buildListOfNets();
493
497 int getFreeNetCode();
498
499public:
501
502private:
504
505 NETNAMES_MAP m_netNames;
506 NETCODES_MAP m_netCodes;
507
509};
510
511#endif // CLASS_NETINFO_
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
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:44
Handle the data for a net.
Definition: netinfo.h:56
bool HasAutoGeneratedNetname()
Definition: netinfo.h:129
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
Definition: netinfo.h:194
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition: netinfo.h:180
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
Definition: netinfo.h:139
wxString GetClass() const override
Return the class name.
Definition: netinfo.h:67
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:175
const wxString & GetShortNetname() const
Definition: netinfo.h:119
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:62
wxString m_displayNetname
Unescaped netname for display.
Definition: netinfo.h:196
BOARD * GetParent() const
Definition: netinfo.h:168
const wxString & GetNetname() const
Definition: netinfo.h:114
void SetNetCode(int aNetCode)
Definition: netinfo.h:109
NETCLASS * GetNetClass()
Definition: netinfo.h:101
std::shared_ptr< NETCLASS > GetNetClassSlow()
Definition: netinfo.h:106
int GetNetCode() const
Definition: netinfo.h:108
VECTOR2I GetPosition() const override
Definition: netinfo.h:80
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:192
std::shared_ptr< NETCLASS > m_netClass
Definition: netinfo.h:201
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: netinfo.h:90
const wxString & GetDisplayNetname() const
Definition: netinfo.h:124
void SetParent(BOARD *aParent)
Definition: netinfo.h:167
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition: netinfo.h:193
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:152
bool m_isCurrent
Indicates the net is currently in use.
Definition: netinfo.h:203
bool IsCurrent() const
Definition: netinfo.h:151
void SetPosition(const VECTOR2I &aPos) override
Definition: netinfo.h:86
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:207
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:407
iterator operator++(int)
post-increment operator
Definition: netinfo.h:421
bool operator==(const iterator &aOther) const
Definition: netinfo.h:443
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:449
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:438
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:414
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:409
NETINFO_ITEM * operator->() const
Definition: netinfo.h:433
NETINFO_ITEM * operator*() const
Definition: netinfo.h:428
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:346
int getFreeNetCode()
Return the first available net code that is not used by any other net.
void RemoveUnusedNets(BOARD_COMMIT *aCommit)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:381
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:506
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:385
iterator begin() const
Definition: netinfo.h:452
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:508
BOARD * GetParent() const
Definition: netinfo.h:463
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:389
unsigned GetNetCount() const
Definition: netinfo.h:369
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition: netinfo.h:503
NETINFO_ITEM * GetNetItem(int aNetCode) const
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:375
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:505
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition: netinfo.h:500
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition: netinfo.h:372
void RebuildDisplayNetnames() const
iterator end() const
Definition: netinfo.h:457
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:249
NETINFO_ITEM * operator->() const
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:289
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:288
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:277
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition: netinfo.h:251
iterator operator++(int)
post-increment operator
Definition: netinfo.h:265
NETINFO_ITEM * operator*() const
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:257
bool operator==(const iterator &aOther) const
Definition: netinfo.h:282
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:223
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
int GetSize() const
Definition: netinfo.h:317
iterator end() const
Return iterator to the last entry in the mapping.
Definition: netinfo.h:309
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:323
iterator begin() const
Return iterator to the first entry in the mapping.
Definition: netinfo.h:298
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:324
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
wxString UnescapeString(const wxString &aSource)
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:109