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.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  const 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 
122  NETCLASSPTR GetNetClass()
123  {
124  return m_NetClass;
125  }
126 
131  wxString GetClassName() const
132  {
133  return m_NetClass ? m_NetClass->GetName() : NETCLASS::Default;
134  }
135 
136 #if 1
137 
143  {
144  wxASSERT( m_NetClass );
145  return m_NetClass->GetTrackWidth();
146  }
147 
153  {
154  wxASSERT( m_NetClass );
155  return m_NetClass->GetViaDiameter();
156  }
157 
163  {
164  wxASSERT( m_NetClass );
165  return m_NetClass->GetuViaDiameter();
166  }
167 
173  {
174  wxASSERT( m_NetClass );
175  return m_NetClass->GetViaDrill();
176  }
177 
183  {
184  wxASSERT( m_NetClass );
185  return m_NetClass->GetuViaDrill();
186  }
187 
188 
189 #if 0
190 
195  int GetViaMinSize()
196  {
197  wxASSERT( m_NetClass );
198  return m_NetClass->GetViaMinSize();
199  }
200 
201 #endif
202 
207  {
208  return m_NetClass ? m_NetClass->GetClearance() : 0;
209  }
210 
211 #endif
212 
218  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset ) override;
219 
224  int GetNet() const { return m_NetCode; }
225 
226  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
227 
232  const wxString& GetNetname() const { return m_Netname; }
233 
238  const wxString& GetShortNetname() const { return m_ShortNetname; }
239 
240  bool IsCurrent() const { return m_isCurrent; }
241 
242  void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
243 
251  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
252 
257  void Clear()
258  {
259  SetClass( NETCLASSPTR() );
260  }
261 
262  BOARD* GetParent() const
263  {
264  return m_parent;
265  }
266 };
267 
268 
270 {
271 public:
273  {
274  m_board = NULL;
275  }
276 
277 
282  void SetBoard( const BOARD* aBoard )
283  {
284  m_board = aBoard;
285  Update();
286  }
287 
293  void Update();
294 
302  int Translate( int aNetCode ) const;
303 
306  class iterator
307  {
308  public:
309  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
310  m_iterator( aIter ), m_mapping( aMapping )
311  {
312  }
313 
316  {
317  ++m_iterator;
318 
319  return *this;
320  }
321 
324  {
325  iterator ret = *this;
326  ++m_iterator;
327 
328  return ret;
329  }
330 
331  NETINFO_ITEM* operator*() const;
332 
333  NETINFO_ITEM* operator->() const;
334 
335  bool operator!=( const iterator& aOther ) const
336  {
337  return m_iterator != aOther.m_iterator;
338  }
339 
340  bool operator==( const iterator& aOther ) const
341  {
342  return m_iterator == aOther.m_iterator;
343  }
344 
345  private:
346  std::map<int, int>::const_iterator m_iterator;
348  };
349 
356  iterator begin() const
357  {
358  return iterator( m_netMapping.begin(), this );
359  }
360 
367  iterator end() const
368  {
369  return iterator( m_netMapping.end(), this );
370  }
371 
376  int GetSize() const
377  {
378  return m_netMapping.size();
379  }
380 
381 private:
383  const BOARD* m_board;
384 
386  std::map<int, int> m_netMapping;
387 };
388 
389 
390 #if 0
391 // waiting for swig to support std::unordered_map, see
392 // http://www.swig.org/Doc3.0/CPlusPlus11.html
393 // section 7.3.3
394 #include <hashtables.h>
395 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
396 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
397 #else
398 // use std::map for now
399 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
400 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
401 #endif
402 
409 {
410  friend class BOARD;
411 
412 public:
413  NETINFO_LIST( BOARD* aParent );
414  ~NETINFO_LIST();
415 
421  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
422 
428  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
429 
435  unsigned GetNetCount() const { return m_netNames.size(); }
436 
442  void AppendNet( NETINFO_ITEM* aNewElement );
443 
448  void RemoveNet( NETINFO_ITEM* aNet );
454  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
456 
458  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
459 
462  static const int UNCONNECTED;
463 
466  static const int ORPHANED;
467 
471  {
472  static NETINFO_ITEM* g_orphanedItem;
473 
474  if( !g_orphanedItem )
475  g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
476 
477  return g_orphanedItem;
478  }
479 
480 #if defined(DEBUG)
481  void Show() const;
482 #endif
483 
484 #ifndef SWIG
485  class iterator
488  {
489  public:
490  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
491  {
492  }
493 
496  {
497  ++m_iterator;
498  return *this;
499  }
500 
503  {
504  iterator ret = *this;
505  ++m_iterator;
506  return ret;
507  }
508 
510  {
511  return m_iterator->second;
512  }
513 
515  {
516  return m_iterator->second;
517  }
518 
519  bool operator!=( const iterator& aOther ) const
520  {
521  return m_iterator != aOther.m_iterator;
522  }
523 
524  bool operator==( const iterator& aOther ) const
525  {
526  return m_iterator == aOther.m_iterator;
527  }
528 
529  private:
530  NETNAMES_MAP::const_iterator m_iterator;
531  };
532 
533  iterator begin() const
534  {
535  return iterator( m_netNames.begin() );
536  }
537 
538  iterator end() const
539  {
540  return iterator( m_netNames.end() );
541  }
542 #endif
543 
544  BOARD* GetParent() const
545  {
546  return m_Parent;
547  }
548 
549 private:
554  void clear();
555 
561  void buildListOfNets();
562 
567  int getFreeNetCode();
568 
570 
571  NETNAMES_MAP m_netNames;
572  NETCODES_MAP m_netCodes;
573 
575 };
576 
577 #endif // CLASS_NETINFO_
EDA_UNITS
Definition: common.h:184
iterator end() const
Definition: netinfo.h:538
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:530
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:487
BOARD * GetParent() const
Definition: netinfo.h:544
NETINFO_ITEM * operator *() const
Definition: netinfo.h:509
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
BOARD * m_Parent
Definition: netinfo.h:569
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:519
NETCLASSPTR m_NetClass
Definition: netinfo.h:81
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:495
BOARD * GetParent() const
Definition: netinfo.h:262
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:470
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:458
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:315
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:242
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:383
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:323
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:571
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:83
#define DECL_MAP_FOR_SWIG(TypeName, KeyType, ValueType)
Definition: macros.h:140
The base class for create windows for drawing purpose.
bool IsCurrent() const
Definition: netinfo.h:240
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:238
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:386
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:347
This file contains miscellaneous commonly used macros and functions.
const NETNAMES_MAP & NetsByName() const
Function GetPadCount.
Definition: netinfo.h:455
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:282
NETINFO_ITEM * operator->() const
Definition: netinfo.h:514
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:309
int GetSize() const
Function GetSize.
Definition: netinfo.h:376
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:367
#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:408
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:533
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:574
iterator operator++(int)
post-increment operator
Definition: netinfo.h:502
void SetNetCode(int aNetCode)
Definition: netinfo.h:226
int GetViaSize()
Function GetViaSize returns the size of vias used to route this net.
Definition: netinfo.h:152
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:232
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros.h:138
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:142
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:306
int GetClearance()
Function GetClearance.
Definition: netinfo.h:206
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:466
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:340
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:490
void Clear()
Function Clear sets all fields to their defaults values.
Definition: netinfo.h:257
bool operator==(const iterator &aOther) const
Definition: netinfo.h:524
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:346
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:224
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
NETCLASSPTR GetNetClass()
Definition: netinfo.h:122
const wxPoint GetPosition() const override
Definition: netinfo.h:106
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:104
NETINFO_ITEM * operator *() const
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
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:182
unsigned GetNetCount() const
Function GetNetCount.
Definition: netinfo.h:435
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:356
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:53
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:172
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:162
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:462
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:335
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
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:572