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, 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 <netclass.h>
33#include <board_item.h>
34
35
36class EDA_DRAW_FRAME;
37class PAD;
38class PCB_TRACK;
39class BOARD;
40class BOARD_ITEM;
41class BOARD_COMMIT;
42class MSG_PANEL_ITEM;
43class PCB_BASE_FRAME;
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#if defined(DEBUG)
67 void Show( int nestLevel, std::ostream& os ) const override
68 {
69 }
70#endif
71
72 const BOX2I GetBoundingBox() const override;
73
74 VECTOR2I GetPosition() const override
75 {
76 static VECTOR2I dummy( 0, 0 );
77 return dummy;
78 }
79
80 void SetPosition( const VECTOR2I& aPos ) override
81 {
82 }
83
84 EDA_ITEM* Clone() const override
85 {
86 return new NETINFO_ITEM( *this );
87 }
88
89 void SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass );
90
95 NETCLASS* GetNetClass() { return m_netClass.get(); }
96
97 int GetNetCode() const { return m_netCode; }
98 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
99
103 const wxString& GetNetname() const { return m_netname; }
104
108 const wxString& GetShortNetname() const { return m_shortNetname; }
109
113 const wxString& GetDisplayNetname() const { return m_displayNetname; }
114
115 const wxString& GetNetChain() const { return m_netChain; }
116 void SetNetChain( const wxString& aNetChain ) { m_netChain = aNetChain; }
117
118 PAD* GetTerminalPad( int aIndex ) const { return m_terminalPads[aIndex]; }
119 void SetTerminalPad( int aIndex, PAD* aPad ) { m_terminalPads[aIndex] = aPad; }
120 void SetTerminalPadUuid( int aIndex, const KIID& aUuid ) { m_terminalPadUuids[aIndex] = aUuid; }
121 const KIID& GetTerminalPadUuid( int aIndex ) const { return m_terminalPadUuids[aIndex]; }
122
127 void ClearTerminalPad( int aIndex )
128 {
129 m_terminalPads[aIndex] = nullptr;
130 m_terminalPadUuids[aIndex] = niluuid;
131 }
132
137 void SetTerminal( int aIndex, PAD* aPad );
138
139 void ResolveTerminalPads( BOARD* aBoard );
140
144 bool HasAutoGeneratedNetname() const;
145
150 void SetNetname( const wxString& aNewName );
151
152 bool IsCurrent() const { return m_isCurrent; }
153 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
154
161 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
162
166 void Clear();
167
168 void SetParent( BOARD* aParent ) { m_parent = aParent; }
169 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
170 {
171 return m_parent;
172 }
173
174 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
175
176 double Similarity( const BOARD_ITEM& aBoardItem ) const override
177 {
178 return 0.0;
179 }
180
181 bool operator==( const BOARD_ITEM& aBoardItem ) const override
182 {
183 return 0.0;
184 }
185
186protected:
187 // Hide base SetParent method to make the BOARD* method the prefered method for this class
189
190private:
191 friend class NETINFO_LIST;
192
194 wxString m_netname;
195 wxString m_shortNetname;
196
201
202 wxString m_netChain;
203
206
207 std::shared_ptr<NETCLASS> m_netClass;
208
212
214};
215
216
217typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
218typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
219
224{
225 friend class BOARD;
226
227public:
228 NETINFO_LIST( BOARD* aParent );
230
235 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
236
241 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
242
247 unsigned GetNetCount() const { return m_netNames.size(); }
248
250 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
251
253 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
254
255 void RebuildDisplayNetnames() const;
256
259 static const int UNCONNECTED;
260
263 static const int ORPHANED;
264
268 {
269 static NETINFO_ITEM* g_orphanedItem;
270
271 if( !g_orphanedItem )
272 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
273
274 return g_orphanedItem;
275 }
276
277#if defined(DEBUG)
278 void Show() const;
279#endif
280
284 {
285 public:
286 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
287 {
288 }
289
292 {
293 ++m_iterator;
294 return *this;
295 }
296
299 {
300 iterator ret = *this;
301 ++m_iterator;
302 return ret;
303 }
304
306 {
307 return m_iterator->second;
308 }
309
311 {
312 return m_iterator->second;
313 }
314
315 bool operator!=( const iterator& aOther ) const
316 {
317 return m_iterator != aOther.m_iterator;
318 }
319
320 bool operator==( const iterator& aOther ) const
321 {
322 return m_iterator == aOther.m_iterator;
323 }
324
325 private:
326 NETNAMES_MAP::const_iterator m_iterator;
327 };
328
330 {
331 return iterator( m_netNames.begin() );
332 }
333
334 iterator end() const
335 {
336 return iterator( m_netNames.end() );
337 }
338
340 {
341 return m_parent;
342 }
343
344protected: // Access is through the BOARD, which is a friend class
349 void AppendNet( NETINFO_ITEM* aNewElement );
350
354 void RemoveNet( NETINFO_ITEM* aNet );
355 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
356
357private:
361 void clear();
362
371 void detachAll();
372
378 void buildListOfNets();
379
383 int getFreeNetCode();
384
385public:
387
388private:
390
393
395};
396
397#endif // CLASS_NETINFO_
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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:494
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
Definition kiid.h:48
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:42
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:195
const wxString & GetNetChain() const
Definition netinfo.h:115
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:181
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:204
const KIID & GetTerminalPadUuid(int aIndex) const
Definition netinfo.h:121
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:176
const wxString & GetShortNetname() const
Definition netinfo.h:108
static bool ClassOf(const EDA_ITEM *aItem)
Definition netinfo.h:56
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:197
BOARD * GetParent() const
Definition netinfo.h:169
const wxString & GetNetname() const
Definition netinfo.h:103
void Clear()
Set all fields to their default values.
void SetNetCode(int aNetCode)
Definition netinfo.h:98
KIID m_terminalPadUuids[2]
Definition netinfo.h:205
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
Definition netinfo.h:120
NETCLASS * GetNetClass()
Definition netinfo.h:95
int GetNetCode() const
Definition netinfo.h:97
VECTOR2I GetPosition() const override
Definition netinfo.h:74
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:118
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:193
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:207
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:84
const wxString & GetDisplayNetname() const
Definition netinfo.h:113
void SetParent(BOARD *aParent)
Definition netinfo.h:168
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:116
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:194
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:127
friend class NETINFO_LIST
Definition netinfo.h:191
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:153
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:119
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:209
bool IsCurrent() const
Definition netinfo.h:152
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:202
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:80
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:213
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:284
iterator operator++(int)
post-increment operator
Definition netinfo.h:298
bool operator==(const iterator &aOther) const
Definition netinfo.h:320
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:326
bool operator!=(const iterator &aOther) const
Definition netinfo.h:315
const iterator & operator++()
pre-increment operator
Definition netinfo.h:291
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:286
NETINFO_ITEM * operator->() const
Definition netinfo.h:310
NETINFO_ITEM * operator*() const
Definition netinfo.h:305
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:225
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:259
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:392
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:263
iterator begin() const
Definition netinfo.h:329
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:394
BOARD * GetParent() const
Definition netinfo.h:339
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:267
unsigned GetNetCount() const
Definition netinfo.h:247
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:389
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:253
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:391
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:386
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:250
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:334
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:55
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:218
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:217
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:107
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687