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#ifndef CLASS_NETINFO_
26#define CLASS_NETINFO_
27
28#include <netclass.h>
29#include <board_item.h>
30
31
32class EDA_DRAW_FRAME;
33class PAD;
34class PCB_TRACK;
35class BOARD;
36class BOARD_ITEM;
37class BOARD_COMMIT;
38class MSG_PANEL_ITEM;
39class PCB_BASE_FRAME;
40
41
46{
47public:
48
49 NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
51
52 static inline bool ClassOf( const EDA_ITEM* aItem )
53 {
54 return aItem && PCB_NETINFO_T == aItem->Type();
55 }
56
57 wxString GetClass() const override
58 {
59 return wxT( "NETINFO_ITEM" );
60 }
61
62#if defined(DEBUG)
63 void Show( int nestLevel, std::ostream& os ) const override
64 {
65 }
66#endif
67
68 const BOX2I GetBoundingBox() const override;
69
70 VECTOR2I GetPosition() const override
71 {
72 static VECTOR2I dummy( 0, 0 );
73 return dummy;
74 }
75
76 void SetPosition( const VECTOR2I& aPos ) override
77 {
78 }
79
80 EDA_ITEM* Clone() const override
81 {
82 return new NETINFO_ITEM( *this );
83 }
84
85 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
86
91 NETCLASS* GetNetClass() { return m_netClass.get(); }
92 const NETCLASS* GetNetClass() const { return m_netClass.get(); }
93
94 int GetNetCode() const { return m_netCode; }
95 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
96
100 const wxString& GetNetname() const { return m_netname; }
101
105 const wxString& GetShortNetname() const { return m_shortNetname; }
106
110 const wxString& GetDisplayNetname() const { return m_displayNetname; }
111
112 const wxString& GetNetChain() const { return m_netChain; }
113 void SetNetChain( const wxString& aNetChain ) { m_netChain = aNetChain; }
114
115 PAD* GetTerminalPad( int aIndex ) const { return m_terminalPads[aIndex]; }
116 void SetTerminalPad( int aIndex, PAD* aPad ) { m_terminalPads[aIndex] = aPad; }
117 void SetTerminalPadUuid( int aIndex, const KIID& aUuid ) { m_terminalPadUuids[aIndex] = aUuid; }
118 const KIID& GetTerminalPadUuid( int aIndex ) const { return m_terminalPadUuids[aIndex]; }
119
124 void ClearTerminalPad( int aIndex )
125 {
126 m_terminalPads[aIndex] = nullptr;
127 m_terminalPadUuids[aIndex] = niluuid;
128 }
129
134 void SetTerminal( int aIndex, PAD* aPad );
135
136 void ResolveTerminalPads( BOARD* aBoard );
137
141 bool HasAutoGeneratedNetname() const;
142
147 void SetNetname( const wxString& aNewName );
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
165 void SetParent( BOARD* aParent ) { m_parent = aParent; }
166 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
167 {
168 return m_parent;
169 }
170
171 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
172
173 double Similarity( const BOARD_ITEM& aBoardItem ) const override
174 {
175 return 0.0;
176 }
177
178 bool operator==( const BOARD_ITEM& aBoardItem ) const override
179 {
180 return 0.0;
181 }
182
183protected:
184 // Hide base SetParent method to make the BOARD* method the prefered method for this class
186
187private:
188 friend class NETINFO_LIST;
189
191 wxString m_netname;
192 wxString m_shortNetname;
193
198
199 wxString m_netChain;
200
203
204 std::shared_ptr<NETCLASS> m_netClass;
205
209
211};
212
213
214typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
215typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
216
221{
222 friend class BOARD;
223
224public:
225 NETINFO_LIST( BOARD* aParent );
227
232 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
233
238 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
239
244 unsigned GetNetCount() const { return m_netNames.size(); }
245
247 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
248
250 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
251
252 void RebuildDisplayNetnames() const;
253
256 static const int UNCONNECTED;
257
260 static const int ORPHANED;
261
265 {
266 static NETINFO_ITEM* g_orphanedItem;
267
268 if( !g_orphanedItem )
269 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
270
271 return g_orphanedItem;
272 }
273
274#if defined(DEBUG)
275 void Show() const;
276#endif
277
281 {
282 public:
283 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
284 {
285 }
286
289 {
290 ++m_iterator;
291 return *this;
292 }
293
296 {
297 iterator ret = *this;
298 ++m_iterator;
299 return ret;
300 }
301
303 {
304 return m_iterator->second;
305 }
306
308 {
309 return m_iterator->second;
310 }
311
312 bool operator!=( const iterator& aOther ) const
313 {
314 return m_iterator != aOther.m_iterator;
315 }
316
317 bool operator==( const iterator& aOther ) const
318 {
319 return m_iterator == aOther.m_iterator;
320 }
321
322 private:
323 NETNAMES_MAP::const_iterator m_iterator;
324 };
325
327 {
328 return iterator( m_netNames.begin() );
329 }
330
331 iterator end() const
332 {
333 return iterator( m_netNames.end() );
334 }
335
337 {
338 return m_parent;
339 }
340
341protected: // Access is through the BOARD, which is a friend class
346 void AppendNet( NETINFO_ITEM* aNewElement );
347
351 void RemoveNet( NETINFO_ITEM* aNet );
352 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
353
354private:
358 void clear();
359
368 void detachAll();
369
375 void buildListOfNets();
376
380 int getFreeNetCode();
381
382public:
384
385private:
387
390
392};
393
394#endif // CLASS_NETINFO_
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:83
friend class BOARD
Definition board_item.h:512
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
Definition kiid.h:44
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:38
Handle the data for a net.
Definition netinfo.h:46
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:192
const wxString & GetNetChain() const
Definition netinfo.h:112
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:178
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:201
const KIID & GetTerminalPadUuid(int aIndex) const
Definition netinfo.h:118
wxString GetClass() const override
Return the class name.
Definition netinfo.h:57
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:173
const wxString & GetShortNetname() const
Definition netinfo.h:105
static bool ClassOf(const EDA_ITEM *aItem)
Definition netinfo.h:52
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:194
BOARD * GetParent() const
Definition netinfo.h:166
const wxString & GetNetname() const
Definition netinfo.h:100
void Clear()
Set all fields to their default values.
void SetNetCode(int aNetCode)
Definition netinfo.h:95
KIID m_terminalPadUuids[2]
Definition netinfo.h:202
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
Definition netinfo.h:117
NETCLASS * GetNetClass()
Definition netinfo.h:91
int GetNetCode() const
Definition netinfo.h:94
VECTOR2I GetPosition() const override
Definition netinfo.h:70
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:115
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:190
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:204
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:80
const wxString & GetDisplayNetname() const
Definition netinfo.h:110
void SetParent(BOARD *aParent)
Definition netinfo.h:165
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:113
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:191
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:124
friend class NETINFO_LIST
Definition netinfo.h:188
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:150
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
const NETCLASS * GetNetClass() const
Definition netinfo.h:92
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:116
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:206
bool IsCurrent() const
Definition netinfo.h:149
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:199
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:76
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:210
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:281
iterator operator++(int)
post-increment operator
Definition netinfo.h:295
bool operator==(const iterator &aOther) const
Definition netinfo.h:317
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:323
bool operator!=(const iterator &aOther) const
Definition netinfo.h:312
const iterator & operator++()
pre-increment operator
Definition netinfo.h:288
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:283
NETINFO_ITEM * operator->() const
Definition netinfo.h:307
NETINFO_ITEM * operator*() const
Definition netinfo.h:302
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:222
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:256
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:389
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:260
iterator begin() const
Definition netinfo.h:326
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:391
BOARD * GetParent() const
Definition netinfo.h:336
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:264
unsigned GetNetCount() const
Definition netinfo.h:244
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:386
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:250
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:388
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:383
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:247
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:331
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:61
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
KIID niluuid(0)
std::map< int, NETINFO_ITEM * > NETCODES_MAP
Definition netinfo.h:215
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:214
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:103
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683