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, see <https://www.gnu.org/licenses/>.
19 */
20
21/*
22 * Classes to handle info on nets
23 */
24
25#pragma once
26
27#include <netclass.h>
28#include <board_item.h>
29
30
31class EDA_DRAW_FRAME;
32class PAD;
33class PCB_TRACK;
34class BOARD;
35class BOARD_ITEM;
36class BOARD_COMMIT;
37class MSG_PANEL_ITEM;
38class PCB_BASE_FRAME;
39class REPORTER;
40
41
42#define NO_NET _( "<no net>" )
43#define CREATE_NET _( "<create net>" )
44
45
50{
51public:
52
53 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
55
56 static inline bool ClassOf( const EDA_ITEM* aItem )
57 {
58 return aItem && PCB_NETINFO_T == aItem->Type();
59 }
60
61 wxString GetClass() const override
62 {
63 return wxT( "NETINFO_ITEM" );
64 }
65
66 PCB_LAYER_ID GetLayer() const override
67 {
68 wxFAIL_MSG( wxT( "NETINFO_ITEM::GetLayer() desn't have meaning. Don't call it." ) );
69 return UNDEFINED_LAYER;
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 const NETCLASS* GetNetClass() const { return m_netClass.get(); }
103
104 int GetNetCode() const { return m_netCode; }
105 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
106
110 const wxString& GetNetname() const { return m_netname; }
111
115 const wxString& GetShortNetname() const { return m_shortNetname; }
116
120 const wxString& GetDisplayNetname() const { return m_displayNetname; }
121
122 const wxString& GetNetChain() const { return m_netChain; }
123 void SetNetChain( const wxString& aNetChain ) { m_netChain = aNetChain; }
124
125 PAD* GetTerminalPad( int aIndex ) const { return m_terminalPads[aIndex]; }
126 void SetTerminalPad( int aIndex, PAD* aPad ) { m_terminalPads[aIndex] = aPad; }
127 void SetTerminalPadUuid( int aIndex, const KIID& aUuid ) { m_terminalPadUuids[aIndex] = aUuid; }
128 const KIID& GetTerminalPadUuid( int aIndex ) const { return m_terminalPadUuids[aIndex]; }
129
134 void ClearTerminalPad( int aIndex )
135 {
136 m_terminalPads[aIndex] = nullptr;
137 m_terminalPadUuids[aIndex] = niluuid;
138 }
139
144 void SetTerminal( int aIndex, PAD* aPad );
145
146 void ResolveTerminalPads( BOARD* aBoard );
147
151 bool HasAutoGeneratedNetname() const;
152
157 void SetNetname( const wxString& aNewName );
158
159 bool IsCurrent() const { return m_isCurrent; }
160 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
161
168 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
169
173 void Clear();
174
175 void SetParent( BOARD* aParent ) { m_parent = aParent; }
176 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
177 {
178 return m_parent;
179 }
180
181 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
182
183 double Similarity( const BOARD_ITEM& aBoardItem ) const override
184 {
185 return 0.0;
186 }
187
188 bool operator==( const BOARD_ITEM& aBoardItem ) const override
189 {
190 return 0.0;
191 }
192
193protected:
194 // Hide base SetParent method to make the BOARD* method the prefered method for this class
196
197private:
198 friend class NETINFO_LIST;
199
201 wxString m_netname;
202 wxString m_shortNetname;
203
208
209 wxString m_netChain;
210
213
214 std::shared_ptr<NETCLASS> m_netClass;
215
219
221};
222
223
224typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
225typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
226
231{
232 friend class BOARD;
233
234public:
235 NETINFO_LIST( BOARD* aParent );
237
242 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
243
248 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
249
254 unsigned GetNetCount() const { return m_netNames.size(); }
255
257 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
258
260 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
261
262 void RebuildDisplayNetnames() const;
263
276 bool RenameNets( const std::map<wxString, wxString>& aNewNames, REPORTER& aReporter );
277
280 static const int UNCONNECTED;
281
284 static const int ORPHANED;
285
289 {
290 static NETINFO_ITEM* g_orphanedItem;
291
292 if( !g_orphanedItem )
293 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
294
295 return g_orphanedItem;
296 }
297
298#if defined(DEBUG)
299 void Show() const;
300#endif
301
305 {
306 public:
307 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
308 {
309 }
310
313 {
314 ++m_iterator;
315 return *this;
316 }
317
320 {
321 iterator ret = *this;
322 ++m_iterator;
323 return ret;
324 }
325
327 {
328 return m_iterator->second;
329 }
330
332 {
333 return m_iterator->second;
334 }
335
336 bool operator!=( const iterator& aOther ) const
337 {
338 return m_iterator != aOther.m_iterator;
339 }
340
341 bool operator==( const iterator& aOther ) const
342 {
343 return m_iterator == aOther.m_iterator;
344 }
345
346 private:
347 NETNAMES_MAP::const_iterator m_iterator;
348 };
349
351 {
352 return iterator( m_netNames.begin() );
353 }
354
355 iterator end() const
356 {
357 return iterator( m_netNames.end() );
358 }
359
361 {
362 return m_parent;
363 }
364
365protected: // Access is through the BOARD, which is a friend class
370 void AppendNet( NETINFO_ITEM* aNewElement );
371
375 void RemoveNet( NETINFO_ITEM* aNet );
376 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
377
378private:
382 void clear();
383
392 void detachAll();
393
399 void buildListOfNets();
400
404 int getFreeNetCode();
405
406public:
408
409private:
411
414
416};
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
friend class BOARD
Definition board_item.h:578
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
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.cpp:153
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
Definition kiid.h:46
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:50
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:43
Handle the data for a net.
Definition netinfo.h:50
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
Definition netinfo.h:202
const wxString & GetNetChain() const
Definition netinfo.h:122
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:188
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
PAD * m_terminalPads[2]
Definition netinfo.h:211
const KIID & GetTerminalPadUuid(int aIndex) const
Definition netinfo.h:128
wxString GetClass() const override
Return the class name.
Definition netinfo.h:61
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:183
const wxString & GetShortNetname() const
Definition netinfo.h:115
static bool ClassOf(const EDA_ITEM *aItem)
Definition netinfo.h:56
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:204
BOARD * GetParent() const
Definition netinfo.h:176
const wxString & GetNetname() const
Definition netinfo.h:110
void Clear()
Set all fields to their default values.
void SetNetCode(int aNetCode)
Definition netinfo.h:105
KIID m_terminalPadUuids[2]
Definition netinfo.h:212
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
Definition netinfo.h:127
NETCLASS * GetNetClass()
Definition netinfo.h:101
int GetNetCode() const
Definition netinfo.h:104
VECTOR2I GetPosition() const override
Definition netinfo.h:80
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:125
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:200
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:214
void ResolveTerminalPads(BOARD *aBoard)
void SetTerminal(int aIndex, PAD *aPad)
Set the terminal-pad pointer and the persisted UUID at aIndex from a single pad, keeping the two view...
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:120
void SetParent(BOARD *aParent)
Definition netinfo.h:175
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Return the information about the NETINFO_ITEM in aList to display in the message panel.
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:123
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:201
void ClearTerminalPad(int aIndex)
Reset the terminal-pad pointer and UUID at aIndex to their empty state so the pair stays in lockstep.
Definition netinfo.h:134
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition netinfo.h:66
friend class NETINFO_LIST
Definition netinfo.h:198
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:160
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
const NETCLASS * GetNetClass() const
Definition netinfo.h:102
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:126
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:216
bool IsCurrent() const
Definition netinfo.h:159
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:209
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:86
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:220
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:305
iterator operator++(int)
post-increment operator
Definition netinfo.h:319
bool operator==(const iterator &aOther) const
Definition netinfo.h:341
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:347
bool operator!=(const iterator &aOther) const
Definition netinfo.h:336
const iterator & operator++()
pre-increment operator
Definition netinfo.h:312
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:307
NETINFO_ITEM * operator->() const
Definition netinfo.h:331
NETINFO_ITEM * operator*() const
Definition netinfo.h:326
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:232
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:280
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:413
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:284
iterator begin() const
Definition netinfo.h:350
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:415
BOARD * GetParent() const
Definition netinfo.h:360
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:288
unsigned GetNetCount() const
Definition netinfo.h:254
void detachAll()
Drop all entries from the lookup maps without freeing the items.
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition netinfo.h:410
bool RenameNets(const std::map< wxString, wxString > &aNewNames, REPORTER &aReporter)
Rename nets in place, keeping the name lookup in sync.
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:260
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:412
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:407
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:257
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:355
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:61
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
KIID niluuid(0)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
std::map< int, NETINFO_ITEM * > NETCODES_MAP
Definition netinfo.h:225
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:224
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:102
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683