KiCad PCB EDA Suite
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 (C) 1992-2019 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 <macros_swig.h>
33 #include <gr_basic.h>
34 #include <netclass.h>
35 #include <class_board_item.h>
36 
37 
38 
39 class wxDC;
40 class wxPoint;
41 class LINE_READER;
42 class EDA_DRAW_FRAME;
43 class D_PAD;
44 class BOARD;
45 class BOARD_ITEM;
46 class MSG_PANEL_ITEM;
47 class PCB_BASE_FRAME;
48 
49 
50 /*****************************/
51 /* flags for a RATSNEST_ITEM */
52 /*****************************/
53 #define CH_VISIBLE 1 /* Visible */
54 #define CH_UNROUTABLE 2 /* Don't use autorouter. */
55 #define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */
56 #define CH_ACTIF 8 /* Not routed. */
57 #define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single module. */
58 
59 DECL_VEC_FOR_SWIG( D_PADS, D_PAD* )
60 
61 
65 class NETINFO_ITEM : public BOARD_ITEM
66 {
67  friend class NETINFO_LIST;
68 
69 private:
70  int m_NetCode;
71 
73  bool m_isCurrent;
74 
77  wxString m_Netname;
78 
79  wxString m_ShortNetname;
80 
81  NETCLASSPTR m_NetClass;
82 
84 
85 public:
86 
87  NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
88  ~NETINFO_ITEM();
89 
90  static inline bool ClassOf( const EDA_ITEM* aItem )
91  {
92  return aItem && PCB_NETINFO_T == aItem->Type();
93  }
94 
95  wxString GetClass() const override
96  {
97  return wxT( "NETINFO_ITEM" );
98  }
99 
100 #if defined(DEBUG)
101  void Show( int nestLevel, std::ostream& os ) const override
102  {
103  }
104 #endif
105 
106  wxPoint GetPosition() const override
107  {
108  static wxPoint dummy(0, 0);
109  return dummy;
110  }
111 
112  void SetPosition( const wxPoint& aPos ) override
113  {
114  }
115 
120  void SetClass( const NETCLASSPTR& aNetClass );
121 
129  {
130  return m_NetClass.get();
131  }
132 
137  wxString GetClassName() const
138  {
139  return m_NetClass ? m_NetClass->GetName() : NETCLASS::Default;
140  }
141 
142 #if 1
143 
149  {
150  wxASSERT( m_NetClass );
151  return m_NetClass->GetTrackWidth();
152  }
153 
159  {
160  wxASSERT( m_NetClass );
161  return m_NetClass->GetViaDiameter();
162  }
163 
169  {
170  wxASSERT( m_NetClass );
171  return m_NetClass->GetuViaDiameter();
172  }
173 
179  {
180  wxASSERT( m_NetClass );
181  return m_NetClass->GetViaDrill();
182  }
183 
189  {
190  wxASSERT( m_NetClass );
191  return m_NetClass->GetuViaDrill();
192  }
193 
194 
195 #if 0
196 
201  int GetViaMinSize()
202  {
203  wxASSERT( m_NetClass );
204  return m_NetClass->GetViaMinSize();
205  }
206 
207 #endif
208 
213  {
214  return m_NetClass ? m_NetClass->GetClearance() : 0;
215  }
216 
217 #endif
218 
223  int GetNet() const { return m_NetCode; }
224 
225  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
226 
231  const wxString& GetNetname() const { return m_Netname; }
232 
237  const wxString& GetShortNetname() const { return m_ShortNetname; }
238 
244  void SetNetname( const wxString& aNewName )
245  {
246  m_Netname = aNewName;
247 
248  if( aNewName.Contains( "/" ) )
249  m_ShortNetname = aNewName.AfterLast( '/' );
250  else
251  m_ShortNetname = aNewName;
252  }
253 
254  bool IsCurrent() const { return m_isCurrent; }
255 
256  void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
257 
265  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
266 
271  void Clear()
272  {
273  SetClass( NETCLASSPTR() );
274  }
275 
276  BOARD* GetParent() const
277  {
278  return m_parent;
279  }
280 };
281 
282 
284 {
285 public:
287  {
288  m_board = NULL;
289  }
290 
291 
296  void SetBoard( const BOARD* aBoard )
297  {
298  m_board = aBoard;
299  Update();
300  }
301 
307  void Update();
308 
316  int Translate( int aNetCode ) const;
317 
320  class iterator
321  {
322  public:
323  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
324  m_iterator( aIter ), m_mapping( aMapping )
325  {
326  }
327 
330  {
331  ++m_iterator;
332 
333  return *this;
334  }
335 
338  {
339  iterator ret = *this;
340  ++m_iterator;
341 
342  return ret;
343  }
344 
345  NETINFO_ITEM* operator*() const;
346 
347  NETINFO_ITEM* operator->() const;
348 
349  bool operator!=( const iterator& aOther ) const
350  {
351  return m_iterator != aOther.m_iterator;
352  }
353 
354  bool operator==( const iterator& aOther ) const
355  {
356  return m_iterator == aOther.m_iterator;
357  }
358 
359  private:
360  std::map<int, int>::const_iterator m_iterator;
362  };
363 
370  iterator begin() const
371  {
372  return iterator( m_netMapping.begin(), this );
373  }
374 
381  iterator end() const
382  {
383  return iterator( m_netMapping.end(), this );
384  }
385 
390  int GetSize() const
391  {
392  return m_netMapping.size();
393  }
394 
395 private:
397  const BOARD* m_board;
398 
400  std::map<int, int> m_netMapping;
401 };
402 
403 
404 #if 0
405 // waiting for swig to support std::unordered_map, see
406 // http://www.swig.org/Doc3.0/CPlusPlus11.html
407 // section 7.3.3
408 #include <hashtables.h>
409 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
410 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
411 #else
412 // use std::map for now
413 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
414 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
415 #endif
416 
423 {
424  friend class BOARD;
425 
426 public:
427  NETINFO_LIST( BOARD* aParent );
428  ~NETINFO_LIST();
429 
435  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
436 
442  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
443 
449  unsigned GetNetCount() const { return m_netNames.size(); }
450 
456  void AppendNet( NETINFO_ITEM* aNewElement );
457 
462  void RemoveNet( NETINFO_ITEM* aNet );
463  void RemoveUnusedNets();
464 
470  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
472 
474  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
475 
478  static const int UNCONNECTED;
479 
482  static const int ORPHANED;
483 
487  {
488  static NETINFO_ITEM* g_orphanedItem;
489 
490  if( !g_orphanedItem )
491  g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
492 
493  return g_orphanedItem;
494  }
495 
496 #if defined(DEBUG)
497  void Show() const;
498 #endif
499 
500 #ifndef SWIG
501  class iterator
504  {
505  public:
506  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
507  {
508  }
509 
512  {
513  ++m_iterator;
514  return *this;
515  }
516 
519  {
520  iterator ret = *this;
521  ++m_iterator;
522  return ret;
523  }
524 
526  {
527  return m_iterator->second;
528  }
529 
531  {
532  return m_iterator->second;
533  }
534 
535  bool operator!=( const iterator& aOther ) const
536  {
537  return m_iterator != aOther.m_iterator;
538  }
539 
540  bool operator==( const iterator& aOther ) const
541  {
542  return m_iterator == aOther.m_iterator;
543  }
544 
545  private:
546  NETNAMES_MAP::const_iterator m_iterator;
547  };
548 
549  iterator begin() const
550  {
551  return iterator( m_netNames.begin() );
552  }
553 
554  iterator end() const
555  {
556  return iterator( m_netNames.end() );
557  }
558 #endif
559 
560  BOARD* GetParent() const
561  {
562  return m_Parent;
563  }
564 
565 private:
570  void clear();
571 
577  void buildListOfNets();
578 
583  int getFreeNetCode();
584 
586 
587  NETNAMES_MAP m_netNames;
588  NETCODES_MAP m_netCodes;
589 
591 };
592 
593 #endif // CLASS_NETINFO_
NETCLASS * GetNetClass()
Function GetNetClass.
Definition: netinfo.h:128
iterator end() const
Definition: netinfo.h:554
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:546
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:503
BOARD * GetParent() const
Definition: netinfo.h:560
NETINFO_ITEM * operator *() const
Definition: netinfo.h:525
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:82
BOARD * m_Parent
Definition: netinfo.h:585
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:535
NETCLASSPTR m_NetClass
Definition: netinfo.h:81
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:511
BOARD * GetParent() const
Definition: netinfo.h:276
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:486
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
Definition: netinfo.h:474
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:329
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:256
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:397
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
bool m_isCurrent
Indicates the net is currently in use.
Definition: netinfo.h:73
iterator operator++(int)
post-increment operator
Definition: netinfo.h:337
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:83
void RemoveUnusedNets()
The base class for create windows for drawing purpose.
bool IsCurrent() const
Definition: netinfo.h:254
int getFreeNetCode()
Function getFreeNetCode returns the first available net code that is not used by any other net.
const wxString & GetShortNetname() const
Function GetShortNetname.
Definition: netinfo.h:237
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:361
const NETNAMES_MAP & NetsByName() const
Function GetPadCount.
Definition: netinfo.h:471
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:296
NETINFO_ITEM * operator->() const
Definition: netinfo.h:530
void AppendNet(NETINFO_ITEM *aNewElement)
Function AppendNet adds aNewElement to the end of the net list.
void RemoveNet(NETINFO_ITEM *aNet)
Function RemoveNet Removes a new from the net list.
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition: netinfo.h:323
int GetSize() const
Function GetSize.
Definition: netinfo.h:390
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:381
#define NULL
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:422
NETINFO_ITEM * operator->() const
#define DECL_HASH_FOR_SWIG(TypeName, KeyType, ValueType)
Declare a std::unordered_map but no swig template.
Definition: hashtables.h:111
iterator begin() const
Definition: netinfo.h:549
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:590
iterator operator++(int)
post-increment operator
Definition: netinfo.h:518
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
void SetNetCode(int aNetCode)
Definition: netinfo.h:225
int GetViaSize()
Function GetViaSize returns the size of vias used to route this net.
Definition: netinfo.h:158
#define DECL_MAP_FOR_SWIG(TypeName, KeyType, ValueType)
Definition: macros_swig.h:52
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
int m_NetCode
A number equivalent to the net name.
Definition: netinfo.h:70
int GetTrackWidth()
Function GetTrackWidth returns the width of tracks used to route this net.
Definition: netinfo.h:148
void SetNetname(const wxString &aNewName)
Function SetNetname Sets the long netname to aNetName, and the short netname to the last token in the...
Definition: netinfo.h:244
wxString GetClass() const override
Function GetClass returns the class name.
Definition: netinfo.h:95
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:320
int GetClearance()
Function GetClearance.
Definition: netinfo.h:212
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:482
wxString m_Netname
Full net name like /mysheet/mysubsheet/vout used by Eeschema.
Definition: netinfo.h:77
bool operator==(const iterator &aOther) const
Definition: netinfo.h:354
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:506
void Clear()
Function Clear sets all fields to their defaults values.
Definition: netinfo.h:271
bool operator==(const iterator &aOther) const
Definition: netinfo.h:540
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:360
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
wxPoint GetPosition() const override
Definition: netinfo.h:106
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:108
NETINFO_ITEM * operator *() const
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
void Update()
Function Update Prepares a mapping for net codes so they can be saved as consecutive numbers.
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:188
unsigned GetNetCount() const
Function GetNetCount.
Definition: netinfo.h:449
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:370
This file contains macros just for swig binding.
wxString m_ShortNetname
short net name, like vout from /mysheet/mysubsheet/vout
Definition: netinfo.h:79
void clear()
Function clear deletes the list of nets (and free memory)
NETINFO_LIST(BOARD *aParent)
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros_swig.h:50
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
int GetViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:178
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:168
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:137
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:90
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void buildListOfNets()
Function buildListOfNets builds or rebuilds the list of NETINFO_ITEMs The list is sorted by names.
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:349
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
void SetPosition(const wxPoint &aPos) override
Definition: netinfo.h:112
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588