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-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#include <string_utils.h>
37
38
39
40class wxDC;
41class LINE_READER;
42class EDA_DRAW_FRAME;
43class PAD;
44class PCB_TRACK;
45class BOARD;
46class BOARD_ITEM;
47class MSG_PANEL_ITEM;
48class PCB_BASE_FRAME;
49
50
51/*****************************/
52/* flags for a RATSNEST_ITEM */
53/*****************************/
54#define CH_VISIBLE 1 /* Visible */
55#define CH_UNROUTABLE 2 /* Don't use autorouter. */
56#define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */
57#define CH_ACTIF 8 /* Not routed. */
58#define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single footprint. */
59
60DECL_VEC_FOR_SWIG( PADS_VEC, PAD* )
61DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* )
62
63
67{
68public:
69
70 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
72
73 static inline bool ClassOf( const EDA_ITEM* aItem )
74 {
75 return aItem && PCB_NETINFO_T == aItem->Type();
76 }
77
78 wxString GetClass() const override
79 {
80 return wxT( "NETINFO_ITEM" );
81 }
82
83#if defined(DEBUG)
84 void Show( int nestLevel, std::ostream& os ) const override
85 {
86 }
87#endif
88
89 const BOX2I GetBoundingBox() const override;
90
91 VECTOR2I GetPosition() const override
92 {
93 static VECTOR2I dummy( 0, 0 );
94 return dummy;
95 }
96
97 void SetPosition( const VECTOR2I& aPos ) override
98 {
99 }
100
101 EDA_ITEM* Clone() const override
102 {
103 return new NETINFO_ITEM( *this );
104 }
105
106 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
107
112 NETCLASS* GetNetClass() { return m_netClass.get(); }
113
117 std::shared_ptr<NETCLASS> GetNetClassSlow() { return m_netClass; }
118
119 int GetNetCode() const { return m_netCode; }
120 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
121
125 const wxString& GetNetname() const { return m_netname; }
126
130 const wxString& GetShortNetname() const { return m_shortNetname; }
131
135 const wxString& GetUnescapedShortNetname() const { return m_unescapedShortNetname; }
136
141 {
142 return m_shortNetname.StartsWith( wxT( "Net-(" ) )
143 || m_shortNetname.StartsWith( wxT( "unconnected-(" ) );
144 }
145
150 void SetNetname( const wxString& aNewName )
151 {
152 m_netname = aNewName;
153
154 if( aNewName.Contains( wxT( "/" ) ) )
155 m_shortNetname = aNewName.AfterLast( '/' );
156 else
157 m_shortNetname = aNewName;
158
159 m_unescapedShortNetname = UnescapeString( m_shortNetname );
160 }
161
162 bool IsCurrent() const { return m_isCurrent; }
163 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
164
171 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
172
176 void Clear();
177
179 {
180 return m_parent;
181 }
182
183 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
184
185private:
186 friend class NETINFO_LIST;
187
189 wxString m_netname;
190 wxString m_shortNetname;
192
193 std::shared_ptr<NETCLASS> m_netClass;
194
198
200};
201
202
204{
205public:
207 {
208 m_board = nullptr;
209 }
210
211
215 void SetBoard( const BOARD* aBoard )
216 {
217 m_board = aBoard;
218 Update();
219 }
220
226 void Update();
227
236 int Translate( int aNetCode ) const;
237
241 {
242 public:
243 iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
244 m_iterator( aIter ), m_mapping( aMapping )
245 {
246 }
247
250 {
251 ++m_iterator;
252
253 return *this;
254 }
255
258 {
259 iterator ret = *this;
260 ++m_iterator;
261
262 return ret;
263 }
264
265 NETINFO_ITEM* operator*() const;
266
267 NETINFO_ITEM* operator->() const;
268
269 bool operator!=( const iterator& aOther ) const
270 {
271 return m_iterator != aOther.m_iterator;
272 }
273
274 bool operator==( const iterator& aOther ) const
275 {
276 return m_iterator == aOther.m_iterator;
277 }
278
279 private:
280 std::map<int, int>::const_iterator m_iterator;
282 };
283
291 {
292 return iterator( m_netMapping.begin(), this );
293 }
294
301 iterator end() const
302 {
303 return iterator( m_netMapping.end(), this );
304 }
305
309 int GetSize() const
310 {
311 return m_netMapping.size();
312 }
313
314private:
315 const BOARD* m_board;
316 std::map<int, int> m_netMapping;
318};
319
320
321#if 0
322// waiting for swig to support std::unordered_map, see
323// http://www.swig.org/Doc3.0/CPlusPlus11.html
324// section 7.3.3
325#include <hashtables.h>
326DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
327DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
328#else
329// use std::map for now
330DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
331DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
332#endif
333
338{
339 friend class BOARD;
340
341public:
342 NETINFO_LIST( BOARD* aParent );
344
349 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
350
355 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
356
361 unsigned GetNetCount() const { return m_netNames.size(); }
362
367 void AppendNet( NETINFO_ITEM* aNewElement );
368
372 void RemoveNet( NETINFO_ITEM* aNet );
373 void RemoveUnusedNets();
374
380 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
381
383 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
384
387 static const int UNCONNECTED;
388
391 static const int ORPHANED;
392
396 {
397 static NETINFO_ITEM* g_orphanedItem;
398
399 if( !g_orphanedItem )
400 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
401
402 return g_orphanedItem;
403 }
404
405#if defined(DEBUG)
406 void Show() const;
407#endif
408
409#ifndef SWIG
413 {
414 public:
415 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
416 {
417 }
418
421 {
422 ++m_iterator;
423 return *this;
424 }
425
428 {
429 iterator ret = *this;
430 ++m_iterator;
431 return ret;
432 }
433
435 {
436 return m_iterator->second;
437 }
438
440 {
441 return m_iterator->second;
442 }
443
444 bool operator!=( const iterator& aOther ) const
445 {
446 return m_iterator != aOther.m_iterator;
447 }
448
449 bool operator==( const iterator& aOther ) const
450 {
451 return m_iterator == aOther.m_iterator;
452 }
453
454 private:
455 NETNAMES_MAP::const_iterator m_iterator;
456 };
457
459 {
460 return iterator( m_netNames.begin() );
461 }
462
463 iterator end() const
464 {
465 return iterator( m_netNames.end() );
466 }
467#endif
468
470 {
471 return m_parent;
472 }
473
474private:
478 void clear();
479
485 void buildListOfNets();
486
490 int getFreeNetCode();
491
493
494 NETNAMES_MAP m_netNames;
495 NETCODES_MAP m_netCodes;
496
498};
499
500#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:71
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
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:93
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:67
bool HasAutoGeneratedNetname()
Definition: netinfo.h:140
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
Definition: netinfo.h:190
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:150
wxString GetClass() const override
Return the class name.
Definition: netinfo.h:78
const wxString & GetShortNetname() const
Definition: netinfo.h:130
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:73
BOARD * GetParent() const
Definition: netinfo.h:178
const wxString & GetNetname() const
Definition: netinfo.h:125
void SetNetCode(int aNetCode)
Definition: netinfo.h:120
NETCLASS * GetNetClass()
Definition: netinfo.h:112
std::shared_ptr< NETCLASS > GetNetClassSlow()
Definition: netinfo.h:117
int GetNetCode() const
Definition: netinfo.h:119
wxString m_unescapedShortNetname
Unescaped short net name.
Definition: netinfo.h:191
VECTOR2I GetPosition() const override
Definition: netinfo.h:91
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:188
std::shared_ptr< NETCLASS > m_netClass
Definition: netinfo.h:193
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: netinfo.h:101
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition: netinfo.h:189
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:163
bool m_isCurrent
Indicates the net is currently in use.
Definition: netinfo.h:195
bool IsCurrent() const
Definition: netinfo.h:162
const wxString & GetUnescapedShortNetname() const
Definition: netinfo.h:135
void SetPosition(const VECTOR2I &aPos) override
Definition: netinfo.h:97
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:199
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:413
iterator operator++(int)
post-increment operator
Definition: netinfo.h:427
bool operator==(const iterator &aOther) const
Definition: netinfo.h:449
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:455
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:444
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:420
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:415
NETINFO_ITEM * operator->() const
Definition: netinfo.h:439
NETINFO_ITEM * operator*() const
Definition: netinfo.h:434
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:338
int getFreeNetCode()
Return the first available net code that is not used by any other net.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:387
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:495
void RemoveUnusedNets()
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:391
iterator begin() const
Definition: netinfo.h:458
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:497
BOARD * GetParent() const
Definition: netinfo.h:469
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:395
unsigned GetNetCount() const
Definition: netinfo.h:361
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition: netinfo.h:492
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:383
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:494
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:380
iterator end() const
Definition: netinfo.h:463
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:241
NETINFO_ITEM * operator->() const
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:281
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:280
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:269
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition: netinfo.h:243
iterator operator++(int)
post-increment operator
Definition: netinfo.h:257
NETINFO_ITEM * operator*() const
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:249
bool operator==(const iterator &aOther) const
Definition: netinfo.h:274
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:215
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
int GetSize() const
Definition: netinfo.h:309
iterator end() const
Return iterator to the last entry in the mapping.
Definition: netinfo.h:301
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:315
iterator begin() const
Return iterator to the first entry in the mapping.
Definition: netinfo.h:290
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:316
Definition: pad.h:59
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:105