KiCad PCB EDA Suite
class_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-2012 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 
29 /*
30  * Classes to handle info on nets
31  */
32 
33 #ifndef CLASS_NETINFO_
34 #define CLASS_NETINFO_
35 
36 #include <macros.h>
37 #include <gr_basic.h>
38 #include <class_netclass.h>
39 #include <class_board_item.h>
40 
41 
42 
43 class wxDC;
44 class wxPoint;
45 class LINE_READER;
46 class EDA_DRAW_PANEL;
47 class EDA_DRAW_FRAME;
48 class D_PAD;
49 class BOARD;
50 class BOARD_ITEM;
51 class MSG_PANEL_ITEM;
52 
53 
54 /*****************************/
55 /* flags for a RATSNEST_ITEM */
56 /*****************************/
57 #define CH_VISIBLE 1 /* Visible */
58 #define CH_UNROUTABLE 2 /* Don't use autorouter. */
59 #define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */
60 #define CH_ACTIF 8 /* Not routed. */
61 #define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single module. */
62 
63 DECL_VEC_FOR_SWIG( D_PADS, D_PAD* )
64 
65 
69 class NETINFO_ITEM : public BOARD_ITEM
70 {
71  friend class NETINFO_LIST;
72 
73 private:
74  int m_NetCode;
75 
77  wxString m_Netname;
78 
79  wxString m_ShortNetname;
80 
81  wxString m_NetClassName; // Net Class name. if void this is equivalent
82  // to "default" (the first
83  // item of the net classes list
84  NETCLASSPTR m_NetClass;
85 
87 
88 public:
89 
90  NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
91  ~NETINFO_ITEM();
92 
93  static inline bool ClassOf( const EDA_ITEM* aItem )
94  {
95  return aItem && PCB_T == aItem->Type();
96  }
97 
98  wxString GetClass() const override
99  {
100  return wxT( "NETINFO_ITEM" );
101  }
102 
103 #if defined(DEBUG)
104  void Show( int nestLevel, std::ostream& os ) const override
105  {
106  }
107 #endif
108 
109  const wxPoint& GetPosition() const override
110  {
111  static wxPoint dummy(0, 0);
112  return dummy;
113  }
114 
115  void SetPosition( const wxPoint& aPos ) override
116  {
117  }
118 
123  void SetClass( NETCLASSPTR aNetClass )
124  {
125  m_NetClass = aNetClass;
126 
127  if( aNetClass )
128  m_NetClassName = aNetClass->GetName();
129  else
130  m_NetClassName = NETCLASS::Default;
131  }
132 
133  NETCLASSPTR GetNetClass()
134  {
135  return m_NetClass;
136  }
137 
142  const wxString& GetClassName() const
143  {
144  return m_NetClassName;
145  }
146 
147 #if 1
148 
154  {
155  wxASSERT( m_NetClass );
156  return m_NetClass->GetTrackWidth();
157  }
158 
164  {
165  wxASSERT( m_NetClass );
166  return m_NetClass->GetViaDiameter();
167  }
168 
174  {
175  wxASSERT( m_NetClass );
176  return m_NetClass->GetuViaDiameter();
177  }
178 
184  {
185  wxASSERT( m_NetClass );
186  return m_NetClass->GetViaDrill();
187  }
188 
194  {
195  wxASSERT( m_NetClass );
196  return m_NetClass->GetuViaDrill();
197  }
198 
199 
200 #if 0
201 
206  int GetViaMinSize()
207  {
208  wxASSERT( m_NetClass );
209  return m_NetClass->GetViaMinSize();
210  }
211 
212 #endif
213 
218  int GetClearance( BOARD_ITEM* aBoardItem )
219  {
220  wxASSERT( m_NetClass );
221  return m_NetClass->GetClearance();
222  }
223 
224 #endif
225 
231  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
232  const wxPoint& offset ) override;
233 
238  int GetNet() const { return m_NetCode; }
239 
240  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
241 
246  const wxString& GetNetname() const { return m_Netname; }
247 
252  const wxString& GetShortNetname() const { return m_ShortNetname; }
253 
261  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
262 
267  void Clear()
268  {
269  SetClass( NETCLASSPTR() );
270  }
271 
272  BOARD* GetParent() const
273  {
274  return m_parent;
275  }
276 };
277 
278 
280 {
281 public:
283  {
284  m_board = NULL;
285  }
286 
287 
292  void SetBoard( const BOARD* aBoard )
293  {
294  m_board = aBoard;
295  Update();
296  }
297 
303  void Update();
304 
312  int Translate( int aNetCode ) const;
313 
316  class iterator
317  {
318  public:
319  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
320  m_iterator( aIter ), m_mapping( aMapping )
321  {
322  }
323 
326  {
327  ++m_iterator;
328 
329  return *this;
330  }
331 
334  {
335  iterator ret = *this;
336  ++m_iterator;
337 
338  return ret;
339  }
340 
341  NETINFO_ITEM* operator*() const;
342 
343  NETINFO_ITEM* operator->() const;
344 
345  bool operator!=( const iterator& aOther ) const
346  {
347  return m_iterator != aOther.m_iterator;
348  }
349 
350  bool operator==( const iterator& aOther ) const
351  {
352  return m_iterator == aOther.m_iterator;
353  }
354 
355  private:
356  std::map<int, int>::const_iterator m_iterator;
358  };
359 
366  iterator begin() const
367  {
368  return iterator( m_netMapping.begin(), this );
369  }
370 
377  iterator end() const
378  {
379  return iterator( m_netMapping.end(), this );
380  }
381 
386  int GetSize() const
387  {
388  return m_netMapping.size();
389  }
390 
391 private:
393  const BOARD* m_board;
394 
396  std::map<int, int> m_netMapping;
397 };
398 
399 
400 #if 0
401 // waiting for swig to support std::unordered_map, see
402 // http://www.swig.org/Doc3.0/CPlusPlus11.html
403 // section 7.3.3
404 #include <hashtables.h>
405 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
406 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
407 #else
408 // use std::map for now
409 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
410 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
411 #endif
412 
419 {
420  friend class BOARD;
421 
422 public:
423  NETINFO_LIST( BOARD* aParent );
424  ~NETINFO_LIST();
425 
431  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
432 
438  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
439 
445  unsigned GetNetCount() const { return m_netNames.size(); }
446 
452  void AppendNet( NETINFO_ITEM* aNewElement );
453 
458  void RemoveNet( NETINFO_ITEM* aNet );
464  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
466 
468  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
469 
472  static const int UNCONNECTED;
473 
476  static const int ORPHANED;
477 
481 
482 #if defined(DEBUG)
483  void Show() const;
484 #endif
485 
486 #ifndef SWIG
487  class iterator
490  {
491  public:
492  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
493  {
494  }
495 
498  {
499  ++m_iterator;
500  return *this;
501  }
502 
505  {
506  iterator ret = *this;
507  ++m_iterator;
508  return ret;
509  }
510 
512  {
513  return m_iterator->second;
514  }
515 
517  {
518  return m_iterator->second;
519  }
520 
521  bool operator!=( const iterator& aOther ) const
522  {
523  return m_iterator != aOther.m_iterator;
524  }
525 
526  bool operator==( const iterator& aOther ) const
527  {
528  return m_iterator == aOther.m_iterator;
529  }
530 
531  private:
532  NETNAMES_MAP::const_iterator m_iterator;
533  };
534 
535  iterator begin() const
536  {
537  return iterator( m_netNames.begin() );
538  }
539 
540  iterator end() const
541  {
542  return iterator( m_netNames.end() );
543  }
544 #endif
545 
546  BOARD* GetParent() const
547  {
548  return m_Parent;
549  }
550 
551 private:
556  void clear();
557 
563  void buildListOfNets();
564 
573  void buildPadsFullList();
574 
579  int getFreeNetCode();
580 
582 
583  NETNAMES_MAP m_netNames;
584  NETCODES_MAP m_netCodes;
585 
587 };
588 
589 
590 /***********************************************************/
591 /* Description of a trace point for monitoring connections */
592 /***********************************************************/
593 #define START_ON_PAD 0x10
594 #define END_ON_PAD 0x20
595 #define START_ON_TRACK 0x40
596 #define END_ON_TRACK 0x80
597 
598 /* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */
600 
601  RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE ratsnest is Ok */
602  DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general
603  * ratsnest (used in module moves) */
604 };
605 
606 
607 #endif // CLASS_NETINFO_
NETNAMES_MAP::const_iterator m_iterator
bool operator!=(const iterator &aOther) const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
BOARD * m_Parent
Definition: typeinfo.h:97
int GetClearance(BOARD_ITEM *aBoardItem)
Function GetClearance returns the clearance when routing near aBoardItem.
NETCLASSPTR m_NetClass
Definition: class_netinfo.h:84
const iterator & operator++()
pre-increment operator
NETINFO_ITEM * operator->() const
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
const iterator & operator++()
pre-increment operator
wxString m_NetClassName
Definition: class_netinfo.h:81
const NETNAMES_MAP & NetsByName() const
Function GetPadCount.
const BOARD * m_board
Board for which mapping is prepared
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
NETINFO_ITEM * operator->() const
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
unsigned GetNetCount() const
Function GetNetCount.
iterator operator++(int)
post-increment operator
void buildPadsFullList()
Function buildPadsFullList creates the pad list, and initializes: m_Pads (list of pads) set m_Status_...
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
BOARD * m_parent
The parent board the net belongs to.
Definition: class_netinfo.h:86
NETINFO_ITEM * operator*() const
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
int getFreeNetCode()
Function getFreeNetCode returns the first available net code that is not used by any other net...
void SetClass(NETCLASSPTR aNetClass)
Function SetClass sets aNetclass into this NET.
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
const NETINFO_MAPPING * m_mapping
This file contains miscellaneous commonly used macros and functions.
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
void AppendNet(NETINFO_ITEM *aNewElement)
Function AppendNet adds aNewElement to the end of the net list.
const wxString & GetShortNetname() const
Function GetShortNetname.
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)
int GetSize() const
Function GetSize.
static const char Default[]
the name of the default NETCLASS
DECL_MAP_FOR_SWIG(NETCLASS_MAP, wxString, NETCLASSPTR)
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
BOARD * GetParent() const
#define DECL_HASH_FOR_SWIG(TypeName, KeyType, ValueType)
Declare a std::unordered_map but no swig template.
Definition: hashtables.h:111
int m_newNetCode
possible value for new net code assignment
iterator operator++(int)
post-increment operator
void SetNetCode(int aNetCode)
int GetViaSize()
Function GetViaSize returns the size of vias used to route this net.
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros.h:146
int m_NetCode
A number equivalent to the net name.
Definition: class_netinfo.h:74
int GetTrackWidth()
Function GetTrackWidth returns the width of tracks used to route this net.
int GetNet() const
Function GetNet.
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_netinfo.h:98
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
bool operator!=(const iterator &aOther) const
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
wxString m_Netname
Full net name like /mysheet/mysubsheet/vout used by Eeschema.
Definition: class_netinfo.h:77
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
iterator(NETNAMES_MAP::const_iterator aIter)
iterator begin() const
void Clear()
Function Clear sets all fields to their defaults values.
std::map< int, int >::const_iterator m_iterator
const wxString & GetClassName() const
Function GetClassName returns the class name.
BOARD * GetParent() const
iterator end() const
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
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...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
NETCLASSPTR GetNetClass()
bool operator==(const iterator &aOther) const
StatusPcbFlags
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:151
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.
wxString m_ShortNetname
short net name, like vout from /mysheet/mysubsheet/vout
Definition: class_netinfo.h:79
void clear()
Function clear deletes the list of nets (and free memory)
const wxString & GetNetname() const
Function GetNetname.
NETINFO_LIST(BOARD *aParent)
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
int GetViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static bool ClassOf(const EDA_ITEM *aItem)
Definition: class_netinfo.h:93
void buildListOfNets()
Function buildListOfNets builds or rebuilds the list of NETINFO_ITEMs The list is sorted by names...
const wxPoint & GetPosition() const override
void SetPosition(const wxPoint &aPos) override
bool operator==(const iterator &aOther) const
NETCODES_MAP m_netCodes
map of is NOT owner