KiCad PCB EDA Suite
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-2022 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
37
38
39class wxDC;
40class LINE_READER;
41class EDA_DRAW_FRAME;
42class PAD;
43class PCB_TRACK;
44class BOARD;
45class BOARD_ITEM;
46class MSG_PANEL_ITEM;
47class PCB_BASE_FRAME;
48
49
50/*****************************/
51/* flags for a RATSNEST_ITEM */
52/*****************************/
53#define CH_VISIBLE 1 /* Visible */
54#define CH_UNROUTABLE 2 /* Don't use autorouter. */
55#define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */
56#define CH_ACTIF 8 /* Not routed. */
57#define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single footprint. */
58
59DECL_VEC_FOR_SWIG( PADS_VEC, PAD* )
60DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* )
61
62
66{
67public:
68
69 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
71
72 static inline bool ClassOf( const EDA_ITEM* aItem )
73 {
74 return aItem && PCB_NETINFO_T == aItem->Type();
75 }
76
77 wxString GetClass() const override
78 {
79 return wxT( "NETINFO_ITEM" );
80 }
81
82#if defined(DEBUG)
83 void Show( int nestLevel, std::ostream& os ) const override
84 {
85 }
86#endif
87
88 const BOX2I GetBoundingBox() const override;
89
90 VECTOR2I GetPosition() const override
91 {
92 static VECTOR2I dummy( 0, 0 );
93 return dummy;
94 }
95
96 void SetPosition( const VECTOR2I& aPos ) override
97 {
98 }
99
100 EDA_ITEM* Clone() const override
101 {
102 return new NETINFO_ITEM( *this );
103 }
104
105 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
106
111 NETCLASS* GetNetClass() { return m_netClass.get(); }
112
113 int GetNetCode() const { return m_netCode; }
114 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
115
119 const wxString& GetNetname() const { return m_netname; }
120
124 const wxString& GetShortNetname() const { return m_shortNetname; }
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
149 bool IsCurrent() const { return m_isCurrent; }
150 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
151
158 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
159
163 void Clear();
164
166 {
167 return m_parent;
168 }
169
170 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
171
172private:
173 friend class NETINFO_LIST;
174
176 wxString m_netname;
177 wxString m_shortNetname;
178
179 std::shared_ptr<NETCLASS> m_netClass;
180
184
186};
187
188
190{
191public:
193 {
194 m_board = nullptr;
195 }
196
197
201 void SetBoard( const BOARD* aBoard )
202 {
203 m_board = aBoard;
204 Update();
205 }
206
212 void Update();
213
222 int Translate( int aNetCode ) const;
223
227 {
228 public:
229 iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
230 m_iterator( aIter ), m_mapping( aMapping )
231 {
232 }
233
236 {
237 ++m_iterator;
238
239 return *this;
240 }
241
244 {
245 iterator ret = *this;
246 ++m_iterator;
247
248 return ret;
249 }
250
251 NETINFO_ITEM* operator*() const;
252
253 NETINFO_ITEM* operator->() const;
254
255 bool operator!=( const iterator& aOther ) const
256 {
257 return m_iterator != aOther.m_iterator;
258 }
259
260 bool operator==( const iterator& aOther ) const
261 {
262 return m_iterator == aOther.m_iterator;
263 }
264
265 private:
266 std::map<int, int>::const_iterator m_iterator;
268 };
269
277 {
278 return iterator( m_netMapping.begin(), this );
279 }
280
287 iterator end() const
288 {
289 return iterator( m_netMapping.end(), this );
290 }
291
295 int GetSize() const
296 {
297 return m_netMapping.size();
298 }
299
300private:
301 const BOARD* m_board;
302 std::map<int, int> m_netMapping;
304};
305
306
307#if 0
308// waiting for swig to support std::unordered_map, see
309// http://www.swig.org/Doc3.0/CPlusPlus11.html
310// section 7.3.3
311#include <hashtables.h>
312DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
313DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
314#else
315// use std::map for now
316DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
317DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
318#endif
319
324{
325 friend class BOARD;
326
327public:
328 NETINFO_LIST( BOARD* aParent );
330
335 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
336
341 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
342
347 unsigned GetNetCount() const { return m_netNames.size(); }
348
353 void AppendNet( NETINFO_ITEM* aNewElement );
354
358 void RemoveNet( NETINFO_ITEM* aNet );
359 void RemoveUnusedNets();
360
366 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
367
369 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
370
373 static const int UNCONNECTED;
374
377 static const int ORPHANED;
378
382 {
383 static NETINFO_ITEM* g_orphanedItem;
384
385 if( !g_orphanedItem )
386 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
387
388 return g_orphanedItem;
389 }
390
391#if defined(DEBUG)
392 void Show() const;
393#endif
394
395#ifndef SWIG
399 {
400 public:
401 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
402 {
403 }
404
407 {
408 ++m_iterator;
409 return *this;
410 }
411
414 {
415 iterator ret = *this;
416 ++m_iterator;
417 return ret;
418 }
419
421 {
422 return m_iterator->second;
423 }
424
426 {
427 return m_iterator->second;
428 }
429
430 bool operator!=( const iterator& aOther ) const
431 {
432 return m_iterator != aOther.m_iterator;
433 }
434
435 bool operator==( const iterator& aOther ) const
436 {
437 return m_iterator == aOther.m_iterator;
438 }
439
440 private:
441 NETNAMES_MAP::const_iterator m_iterator;
442 };
443
445 {
446 return iterator( m_netNames.begin() );
447 }
448
449 iterator end() const
450 {
451 return iterator( m_netNames.end() );
452 }
453#endif
454
456 {
457 return m_parent;
458 }
459
460private:
464 void clear();
465
471 void buildListOfNets();
472
476 int getFreeNetCode();
477
479
480 NETNAMES_MAP m_netNames;
481 NETCODES_MAP m_netCodes;
482
484};
485
486#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:50
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
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:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
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:47
Handle the data for a net.
Definition: netinfo.h:66
bool HasAutoGeneratedNetname()
Definition: netinfo.h:129
wxString m_shortNetname
short net name, like vout from /sheet/subsheet/vout.
Definition: netinfo.h:177
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, and 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:77
const wxString & GetShortNetname() const
Definition: netinfo.h:124
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:72
BOARD * GetParent() const
Definition: netinfo.h:165
const wxString & GetNetname() const
Definition: netinfo.h:119
void SetNetCode(int aNetCode)
Definition: netinfo.h:114
NETCLASS * GetNetClass()
Definition: netinfo.h:111
int GetNetCode() const
Definition: netinfo.h:113
VECTOR2I GetPosition() const override
Definition: netinfo.h:90
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:175
std::shared_ptr< NETCLASS > m_netClass
Definition: netinfo.h:179
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: netinfo.h:100
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition: netinfo.h:176
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:150
bool m_isCurrent
Indicates the net is currently in use.
Definition: netinfo.h:181
bool IsCurrent() const
Definition: netinfo.h:149
void SetPosition(const VECTOR2I &aPos) override
Definition: netinfo.h:96
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:185
iterator operator++(int)
post-increment operator
Definition: netinfo.h:413
bool operator==(const iterator &aOther) const
Definition: netinfo.h:435
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:441
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:430
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:406
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:401
NETINFO_ITEM * operator->() const
Definition: netinfo.h:425
NETINFO_ITEM * operator*() const
Definition: netinfo.h:420
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:324
int getFreeNetCode()
Return the first available net code that is not used by any other net.
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:373
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:481
void RemoveUnusedNets()
static const int ORPHANED
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition: netinfo.h:377
iterator begin() const
Definition: netinfo.h:444
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:483
BOARD * GetParent() const
Definition: netinfo.h:455
static NETINFO_ITEM * OrphanedItem()
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:381
unsigned GetNetCount() const
Definition: netinfo.h:347
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition: netinfo.h:478
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:369
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:480
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition: netinfo.h:366
iterator end() const
Definition: netinfo.h:449
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
NETINFO_ITEM * operator->() const
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:267
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:266
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:255
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition: netinfo.h:229
iterator operator++(int)
post-increment operator
Definition: netinfo.h:243
NETINFO_ITEM * operator*() const
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:235
bool operator==(const iterator &aOther) const
Definition: netinfo.h:260
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:201
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
int GetSize() const
Definition: netinfo.h:295
iterator end() const
Return iterator to the last entry in the mapping.
Definition: netinfo.h:287
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:301
iterator begin() const
Return iterator to the first entry in the mapping.
Definition: netinfo.h:276
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:302
Definition: pad.h:58
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
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:114