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  wxASSERT( m_NetClass );
209  return m_NetClass->GetClearance();
210  }
211 
212 #endif
213 
219  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset ) override;
220 
225  int GetNet() const { return m_NetCode; }
226 
227  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
228 
233  const wxString& GetNetname() const { return m_Netname; }
234 
239  const wxString& GetShortNetname() const { return m_ShortNetname; }
240 
241  bool IsCurrent() const { return m_isCurrent; }
242 
243  void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
244 
252  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
253 
258  void Clear()
259  {
260  SetClass( NETCLASSPTR() );
261  }
262 
263  BOARD* GetParent() const
264  {
265  return m_parent;
266  }
267 };
268 
269 
271 {
272 public:
274  {
275  m_board = NULL;
276  }
277 
278 
283  void SetBoard( const BOARD* aBoard )
284  {
285  m_board = aBoard;
286  Update();
287  }
288 
294  void Update();
295 
303  int Translate( int aNetCode ) const;
304 
307  class iterator
308  {
309  public:
310  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
311  m_iterator( aIter ), m_mapping( aMapping )
312  {
313  }
314 
317  {
318  ++m_iterator;
319 
320  return *this;
321  }
322 
325  {
326  iterator ret = *this;
327  ++m_iterator;
328 
329  return ret;
330  }
331 
332  NETINFO_ITEM* operator*() const;
333 
334  NETINFO_ITEM* operator->() const;
335 
336  bool operator!=( const iterator& aOther ) const
337  {
338  return m_iterator != aOther.m_iterator;
339  }
340 
341  bool operator==( const iterator& aOther ) const
342  {
343  return m_iterator == aOther.m_iterator;
344  }
345 
346  private:
347  std::map<int, int>::const_iterator m_iterator;
349  };
350 
357  iterator begin() const
358  {
359  return iterator( m_netMapping.begin(), this );
360  }
361 
368  iterator end() const
369  {
370  return iterator( m_netMapping.end(), this );
371  }
372 
377  int GetSize() const
378  {
379  return m_netMapping.size();
380  }
381 
382 private:
384  const BOARD* m_board;
385 
387  std::map<int, int> m_netMapping;
388 };
389 
390 
391 #if 0
392 // waiting for swig to support std::unordered_map, see
393 // http://www.swig.org/Doc3.0/CPlusPlus11.html
394 // section 7.3.3
395 #include <hashtables.h>
396 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
397 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
398 #else
399 // use std::map for now
400 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
401 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
402 #endif
403 
410 {
411  friend class BOARD;
412 
413 public:
414  NETINFO_LIST( BOARD* aParent );
415  ~NETINFO_LIST();
416 
422  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
423 
429  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
430 
436  unsigned GetNetCount() const { return m_netNames.size(); }
437 
443  void AppendNet( NETINFO_ITEM* aNewElement );
444 
449  void RemoveNet( NETINFO_ITEM* aNet );
455  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
457 
459  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
460 
463  static const int UNCONNECTED;
464 
467  static const int ORPHANED;
468 
472 
473 #if defined(DEBUG)
474  void Show() const;
475 #endif
476 
477 #ifndef SWIG
478  class iterator
481  {
482  public:
483  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
484  {
485  }
486 
489  {
490  ++m_iterator;
491  return *this;
492  }
493 
496  {
497  iterator ret = *this;
498  ++m_iterator;
499  return ret;
500  }
501 
503  {
504  return m_iterator->second;
505  }
506 
508  {
509  return m_iterator->second;
510  }
511 
512  bool operator!=( const iterator& aOther ) const
513  {
514  return m_iterator != aOther.m_iterator;
515  }
516 
517  bool operator==( const iterator& aOther ) const
518  {
519  return m_iterator == aOther.m_iterator;
520  }
521 
522  private:
523  NETNAMES_MAP::const_iterator m_iterator;
524  };
525 
526  iterator begin() const
527  {
528  return iterator( m_netNames.begin() );
529  }
530 
531  iterator end() const
532  {
533  return iterator( m_netNames.end() );
534  }
535 #endif
536 
537  BOARD* GetParent() const
538  {
539  return m_Parent;
540  }
541 
542 private:
547  void clear();
548 
554  void buildListOfNets();
555 
560  int getFreeNetCode();
561 
563 
564  NETNAMES_MAP m_netNames;
565  NETCODES_MAP m_netCodes;
566 
568 };
569 
570 #endif // CLASS_NETINFO_
iterator end() const
Definition: netinfo.h:531
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:523
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:480
BOARD * GetParent() const
Definition: netinfo.h:537
NETINFO_ITEM * operator *() const
Definition: netinfo.h:502
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
BOARD * m_Parent
Definition: netinfo.h:562
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:512
NETCLASSPTR m_NetClass
Definition: netinfo.h:81
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:488
BOARD * GetParent() const
Definition: netinfo.h:263
Class 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:459
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:316
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:243
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:384
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:324
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:564
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:161
The base class for create windows for drawing purpose.
bool IsCurrent() const
Definition: netinfo.h:241
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:239
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:387
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:348
This file contains miscellaneous commonly used macros and functions.
const NETNAMES_MAP & NetsByName() const
Function GetPadCount.
Definition: netinfo.h:456
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:283
NETINFO_ITEM * operator->() const
Definition: netinfo.h:507
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:310
int GetSize() const
Function GetSize.
Definition: netinfo.h:377
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:368
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:409
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:526
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:567
iterator operator++(int)
post-increment operator
Definition: netinfo.h:495
void SetNetCode(int aNetCode)
Definition: netinfo.h:227
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:233
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros.h:159
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:307
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:467
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:341
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:483
void Clear()
Function Clear sets all fields to their defaults values.
Definition: netinfo.h:258
bool operator==(const iterator &aOther) const
Definition: netinfo.h:517
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:347
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
static NETINFO_ITEM ORPHANED_ITEM
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition: netinfo.h:471
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
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:103
NETINFO_ITEM * operator *() const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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:436
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:357
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)
Class 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:463
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:90
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
EDA_UNITS_T
Definition: common.h:133
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:336
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
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:565