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 const NETCLASS* GetNetClass() const { return m_netClass.get(); }
97
98 int GetNetCode() const { return m_netCode; }
99 void SetNetCode( int aNetCode ) { m_netCode = aNetCode; }
100
104 const wxString& GetNetname() const { return m_netname; }
105
109 const wxString& GetShortNetname() const { return m_shortNetname; }
110
114 const wxString& GetDisplayNetname() const { return m_displayNetname; }
115
116 const wxString& GetNetChain() const { return m_netChain; }
117 void SetNetChain( const wxString& aNetChain ) { m_netChain = aNetChain; }
118
119 PAD* GetTerminalPad( int aIndex ) const { return m_terminalPads[aIndex]; }
120 void SetTerminalPad( int aIndex, PAD* aPad ) { m_terminalPads[aIndex] = aPad; }
121 void SetTerminalPadUuid( int aIndex, const KIID& aUuid ) { m_terminalPadUuids[aIndex] = aUuid; }
122 const KIID& GetTerminalPadUuid( int aIndex ) const { return m_terminalPadUuids[aIndex]; }
123
128 void ClearTerminalPad( int aIndex )
129 {
130 m_terminalPads[aIndex] = nullptr;
131 m_terminalPadUuids[aIndex] = niluuid;
132 }
133
138 void SetTerminal( int aIndex, PAD* aPad );
139
140 void ResolveTerminalPads( BOARD* aBoard );
141
145 bool HasAutoGeneratedNetname() const;
146
151 void SetNetname( const wxString& aNewName );
152
153 bool IsCurrent() const { return m_isCurrent; }
154 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
155
162 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
163
167 void Clear();
168
169 void SetParent( BOARD* aParent ) { m_parent = aParent; }
170 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
171 {
172 return m_parent;
173 }
174
175 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
176
177 double Similarity( const BOARD_ITEM& aBoardItem ) const override
178 {
179 return 0.0;
180 }
181
182 bool operator==( const BOARD_ITEM& aBoardItem ) const override
183 {
184 return 0.0;
185 }
186
187protected:
188 // Hide base SetParent method to make the BOARD* method the prefered method for this class
190
191private:
192 friend class NETINFO_LIST;
193
195 wxString m_netname;
196 wxString m_shortNetname;
197
202
203 wxString m_netChain;
204
207
208 std::shared_ptr<NETCLASS> m_netClass;
209
213
215};
216
217
218typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
219typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
220
225{
226 friend class BOARD;
227
228public:
229 NETINFO_LIST( BOARD* aParent );
231
236 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
237
242 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
243
248 unsigned GetNetCount() const { return m_netNames.size(); }
249
251 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
252
254 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
255
256 void RebuildDisplayNetnames() const;
257
260 static const int UNCONNECTED;
261
264 static const int ORPHANED;
265
269 {
270 static NETINFO_ITEM* g_orphanedItem;
271
272 if( !g_orphanedItem )
273 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
274
275 return g_orphanedItem;
276 }
277
278#if defined(DEBUG)
279 void Show() const;
280#endif
281
285 {
286 public:
287 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
288 {
289 }
290
293 {
294 ++m_iterator;
295 return *this;
296 }
297
300 {
301 iterator ret = *this;
302 ++m_iterator;
303 return ret;
304 }
305
307 {
308 return m_iterator->second;
309 }
310
312 {
313 return m_iterator->second;
314 }
315
316 bool operator!=( const iterator& aOther ) const
317 {
318 return m_iterator != aOther.m_iterator;
319 }
320
321 bool operator==( const iterator& aOther ) const
322 {
323 return m_iterator == aOther.m_iterator;
324 }
325
326 private:
327 NETNAMES_MAP::const_iterator m_iterator;
328 };
329
331 {
332 return iterator( m_netNames.begin() );
333 }
334
335 iterator end() const
336 {
337 return iterator( m_netNames.end() );
338 }
339
341 {
342 return m_parent;
343 }
344
345protected: // Access is through the BOARD, which is a friend class
350 void AppendNet( NETINFO_ITEM* aNewElement );
351
355 void RemoveNet( NETINFO_ITEM* aNet );
356 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
357
358private:
362 void clear();
363
372 void detachAll();
373
379 void buildListOfNets();
380
384 int getFreeNetCode();
385
386public:
388
389private:
391
394
396};
397
398#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:196
const wxString & GetNetChain() const
Definition netinfo.h:116
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:182
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:205
const KIID & GetTerminalPadUuid(int aIndex) const
Definition netinfo.h:122
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:177
const wxString & GetShortNetname() const
Definition netinfo.h:109
static bool ClassOf(const EDA_ITEM *aItem)
Definition netinfo.h:56
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:198
BOARD * GetParent() const
Definition netinfo.h:170
const wxString & GetNetname() const
Definition netinfo.h:104
void Clear()
Set all fields to their default values.
void SetNetCode(int aNetCode)
Definition netinfo.h:99
KIID m_terminalPadUuids[2]
Definition netinfo.h:206
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
Definition netinfo.h:121
NETCLASS * GetNetClass()
Definition netinfo.h:95
int GetNetCode() const
Definition netinfo.h:98
VECTOR2I GetPosition() const override
Definition netinfo.h:74
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:119
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:194
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:208
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:114
void SetParent(BOARD *aParent)
Definition netinfo.h:169
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:117
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:195
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:128
friend class NETINFO_LIST
Definition netinfo.h:192
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:154
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
const NETCLASS * GetNetClass() const
Definition netinfo.h:96
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:120
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:210
bool IsCurrent() const
Definition netinfo.h:153
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:203
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:80
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:214
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:285
iterator operator++(int)
post-increment operator
Definition netinfo.h:299
bool operator==(const iterator &aOther) const
Definition netinfo.h:321
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:327
bool operator!=(const iterator &aOther) const
Definition netinfo.h:316
const iterator & operator++()
pre-increment operator
Definition netinfo.h:292
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:287
NETINFO_ITEM * operator->() const
Definition netinfo.h:311
NETINFO_ITEM * operator*() const
Definition netinfo.h:306
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:226
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:260
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:393
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:264
iterator begin() const
Definition netinfo.h:330
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:395
BOARD * GetParent() const
Definition netinfo.h:340
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:268
unsigned GetNetCount() const
Definition netinfo.h:248
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:390
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:254
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:392
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:387
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:251
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:335
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:65
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:219
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:218
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