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
118 bool HasAutoGeneratedNetname() const;
119
124 void SetNetname( const wxString& aNewName );
125
126 bool IsCurrent() const { return m_isCurrent; }
127 void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
128
135 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
136
140 void Clear();
141
142 void SetParent( BOARD* aParent ) { m_parent = aParent; }
143 BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
144 {
145 return m_parent;
146 }
147
148 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
149
150 double Similarity( const BOARD_ITEM& aBoardItem ) const override
151 {
152 return 0.0;
153 }
154
155 bool operator==( const BOARD_ITEM& aBoardItem ) const override
156 {
157 return 0.0;
158 }
159
160protected:
161 // Hide base SetParent method to make the BOARD* method the prefered method for this class
163
164private:
165 friend class NETINFO_LIST;
166
168 wxString m_netname;
169 wxString m_shortNetname;
170
175
176 std::shared_ptr<NETCLASS> m_netClass;
177
181
183};
184
185
186typedef std::map<wxString, NETINFO_ITEM*> NETNAMES_MAP;
187typedef std::map<int, NETINFO_ITEM*> NETCODES_MAP;
188
193{
194 friend class BOARD;
195
196public:
197 NETINFO_LIST( BOARD* aParent );
199
204 NETINFO_ITEM* GetNetItem( int aNetCode ) const;
205
210 NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
211
216 unsigned GetNetCount() const { return m_netNames.size(); }
217
219 const NETNAMES_MAP& NetsByName() const { return m_netNames; }
220
222 const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
223
224 void RebuildDisplayNetnames() const;
225
228 static const int UNCONNECTED;
229
232 static const int ORPHANED;
233
237 {
238 static NETINFO_ITEM* g_orphanedItem;
239
240 if( !g_orphanedItem )
241 g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
242
243 return g_orphanedItem;
244 }
245
246#if defined(DEBUG)
247 void Show() const;
248#endif
249
253 {
254 public:
255 iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
256 {
257 }
258
261 {
262 ++m_iterator;
263 return *this;
264 }
265
268 {
269 iterator ret = *this;
270 ++m_iterator;
271 return ret;
272 }
273
275 {
276 return m_iterator->second;
277 }
278
280 {
281 return m_iterator->second;
282 }
283
284 bool operator!=( const iterator& aOther ) const
285 {
286 return m_iterator != aOther.m_iterator;
287 }
288
289 bool operator==( const iterator& aOther ) const
290 {
291 return m_iterator == aOther.m_iterator;
292 }
293
294 private:
295 NETNAMES_MAP::const_iterator m_iterator;
296 };
297
299 {
300 return iterator( m_netNames.begin() );
301 }
302
303 iterator end() const
304 {
305 return iterator( m_netNames.end() );
306 }
307
309 {
310 return m_parent;
311 }
312
313protected: // Access is through the BOARD, which is a friend class
318 void AppendNet( NETINFO_ITEM* aNewElement );
319
323 void RemoveNet( NETINFO_ITEM* aNet );
324 void RemoveUnusedNets( BOARD_COMMIT* aCommit );
325
326private:
330 void clear();
331
337 void buildListOfNets();
338
342 int getFreeNetCode();
343
344public:
346
347private:
349
352
354};
355
356#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
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:169
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition netinfo.h:155
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
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:150
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:171
BOARD * GetParent() const
Definition netinfo.h:143
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
NETCLASS * GetNetClass()
Definition netinfo.h:95
int GetNetCode() const
Definition netinfo.h:97
VECTOR2I GetPosition() const override
Definition netinfo.h:74
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:167
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:176
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:142
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.
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:168
friend class NETINFO_LIST
Definition netinfo.h:165
void SetIsCurrent(bool isCurrent)
Definition netinfo.h:127
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:178
bool IsCurrent() const
Definition netinfo.h:126
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
void SetPosition(const VECTOR2I &aPos) override
Definition netinfo.h:80
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:182
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition netinfo.h:253
iterator operator++(int)
post-increment operator
Definition netinfo.h:267
bool operator==(const iterator &aOther) const
Definition netinfo.h:289
NETNAMES_MAP::const_iterator m_iterator
Definition netinfo.h:295
bool operator!=(const iterator &aOther) const
Definition netinfo.h:284
const iterator & operator++()
pre-increment operator
Definition netinfo.h:260
iterator(NETNAMES_MAP::const_iterator aIter)
Definition netinfo.h:255
NETINFO_ITEM * operator->() const
Definition netinfo.h:279
NETINFO_ITEM * operator*() const
Definition netinfo.h:274
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:194
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:228
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition netinfo.h:351
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:232
iterator begin() const
Definition netinfo.h:298
int m_newNetCode
possible value for new net code assignment
Definition netinfo.h:353
BOARD * GetParent() const
Definition netinfo.h:308
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:236
unsigned GetNetCount() const
Definition netinfo.h:216
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
BOARD * m_parent
Definition netinfo.h:348
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:222
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition netinfo.h:350
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
Definition netinfo.h:345
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:219
void RebuildDisplayNetnames() const
iterator end() const
Definition netinfo.h:303
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
Definition pad.h:55
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
std::map< int, NETINFO_ITEM * > NETCODES_MAP
Definition netinfo.h:187
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:186
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