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
169 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
170
174 void Clear();
175
176 void SetParent( BOARD* aParent ) { m_parent = aParent; }
177 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
178 {
179 return m_parent;
180 }
181
182 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
183
184 double Similarity( const BOARD_ITEM& aBoardItem ) const override
185 {
186 return 0.0;
187 }
188
189 bool operator==( const BOARD_ITEM& aBoardItem ) const override
190 {
191 return 0.0;
192 }
193
194protected:
195 // Hide base SetParent method to make the BOARD* method the prefered method for this class
197
198private:
199 friend class NETINFO_LIST;
200
202 wxString m_netname;
203 wxString m_shortNetname;
204
209
210 wxString m_netChain;
211
214
215 std::shared_ptr<NETCLASS> m_netClass;
216
220
222};
223
224
225typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
226typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
227
232{
233 friend class BOARD;
234
235public:
236 NETINFO_LIST( BOARD* aParent );
238
243 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
244
249 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
250
255 unsigned GetNetCount() const { return m_netNames.size(); }
256
258 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
259
261 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
262
263 void RebuildDisplayNetnames() const;
264
277 bool RenameNets( const std::map<wxString, wxString>& aNewNames, REPORTER& aReporter );
278
281 static const int UNCONNECTED;
282
285 static const int ORPHANED;
286
290 {
291 static NETINFO_ITEM* g_orphanedItem;
292
293 if( !g_orphanedItem )
294 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
295
296 return g_orphanedItem;
297 }
298
299#if defined(DEBUG)
300 void Show() const;
301#endif
302
306 {
307 public:
308 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
309 {
310 }
311
314 {
315 ++m_iterator;
316 return *this;
317 }
318
321 {
322 iterator ret = *this;
323 ++m_iterator;
324 return ret;
325 }
326
328 {
329 return m_iterator->second;
330 }
331
333 {
334 return m_iterator->second;
335 }
336
337 bool operator!=( const iterator& aOther ) const
338 {
339 return m_iterator != aOther.m_iterator;
340 }
341
342 bool operator==( const iterator& aOther ) const
343 {
344 return m_iterator == aOther.m_iterator;
345 }
346
347 private:
348 NETNAMES_MAP::const_iterator m_iterator;
349 };
350
352 {
353 return iterator( m_netNames.begin() );
354 }
355
356 iterator end() const
357 {
358 return iterator( m_netNames.end() );
359 }
360
362 {
363 return m_parent;
364 }
365
366protected: // Access is through the BOARD, which is a friend class
371 void AppendNet( NETINFO_ITEM* aNewElement );
372
376 void RemoveNet( NETINFO_ITEM* aNet );
377 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
378
379private:
383 void clear();
384
393 void detachAll();
394
400 void buildListOfNets();
401
405 int getFreeNetCode();
406
407public:
409
410private:
412
415
417};
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
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:593
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
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:203
const wxString & GetNetChain() const
Definition netinfo.h:122
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:189
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:212
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:184
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:205
BOARD * GetParent() const
Definition netinfo.h:177
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:213
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:201
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:215
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:176
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:202
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:199
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:217
bool IsCurrent() const
Definition netinfo.h:159
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:210
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:86
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:221
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:306
iterator operator++(int)
post-increment operator
Definition netinfo.h:320
bool operator==(const iterator &aOther) const
Definition netinfo.h:342
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:348
bool operator!=(const iterator &aOther) const
Definition netinfo.h:337
const iterator & operator++()
pre-increment operator
Definition netinfo.h:313
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:308
NETINFO_ITEM * operator->() const
Definition netinfo.h:332
NETINFO_ITEM * operator*() const
Definition netinfo.h:327
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:233
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:414
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:285
iterator begin() const
Definition netinfo.h:351
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:416
BOARD * GetParent() const
Definition netinfo.h:361
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:289
unsigned GetNetCount() const
Definition netinfo.h:255
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:411
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:261
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:413
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:408
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:258
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:356
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:226
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:225
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:708