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  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_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( 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  int GetClearance( BOARD_ITEM* aBoardItem )
208  {
209  wxASSERT( m_NetClass );
210  return m_NetClass->GetClearance();
211  }
212 
213 #endif
214 
220  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
221  const wxPoint& offset ) override;
222 
227  int GetNet() const { return m_NetCode; }
228 
229  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
230 
235  const wxString& GetNetname() const { return m_Netname; }
236 
241  const wxString& GetShortNetname() const { return m_ShortNetname; }
242 
250  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
251 
256  void Clear()
257  {
258  SetClass( NETCLASSPTR() );
259  }
260 
261  BOARD* GetParent() const
262  {
263  return m_parent;
264  }
265 };
266 
267 
269 {
270 public:
272  {
273  m_board = NULL;
274  }
275 
276 
281  void SetBoard( const BOARD* aBoard )
282  {
283  m_board = aBoard;
284  Update();
285  }
286 
292  void Update();
293 
301  int Translate( int aNetCode ) const;
302 
305  class iterator
306  {
307  public:
308  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
309  m_iterator( aIter ), m_mapping( aMapping )
310  {
311  }
312 
315  {
316  ++m_iterator;
317 
318  return *this;
319  }
320 
323  {
324  iterator ret = *this;
325  ++m_iterator;
326 
327  return ret;
328  }
329 
330  NETINFO_ITEM* operator*() const;
331 
332  NETINFO_ITEM* operator->() const;
333 
334  bool operator!=( const iterator& aOther ) const
335  {
336  return m_iterator != aOther.m_iterator;
337  }
338 
339  bool operator==( const iterator& aOther ) const
340  {
341  return m_iterator == aOther.m_iterator;
342  }
343 
344  private:
345  std::map<int, int>::const_iterator m_iterator;
347  };
348 
355  iterator begin() const
356  {
357  return iterator( m_netMapping.begin(), this );
358  }
359 
366  iterator end() const
367  {
368  return iterator( m_netMapping.end(), this );
369  }
370 
375  int GetSize() const
376  {
377  return m_netMapping.size();
378  }
379 
380 private:
382  const BOARD* m_board;
383 
385  std::map<int, int> m_netMapping;
386 };
387 
388 
389 #if 0
390 // waiting for swig to support std::unordered_map, see
391 // http://www.swig.org/Doc3.0/CPlusPlus11.html
392 // section 7.3.3
393 #include <hashtables.h>
394 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
395 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
396 #else
397 // use std::map for now
398 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
399 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
400 #endif
401 
408 {
409  friend class BOARD;
410 
411 public:
412  NETINFO_LIST( BOARD* aParent );
413  ~NETINFO_LIST();
414 
420  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
421 
427  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
428 
434  unsigned GetNetCount() const { return m_netNames.size(); }
435 
441  void AppendNet( NETINFO_ITEM* aNewElement );
442 
447  void RemoveNet( NETINFO_ITEM* aNet );
453  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
455 
457  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
458 
461  static const int UNCONNECTED;
462 
465  static const int ORPHANED;
466 
470 
471 #if defined(DEBUG)
472  void Show() const;
473 #endif
474 
475 #ifndef SWIG
476  class iterator
479  {
480  public:
481  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
482  {
483  }
484 
487  {
488  ++m_iterator;
489  return *this;
490  }
491 
494  {
495  iterator ret = *this;
496  ++m_iterator;
497  return ret;
498  }
499 
501  {
502  return m_iterator->second;
503  }
504 
506  {
507  return m_iterator->second;
508  }
509 
510  bool operator!=( const iterator& aOther ) const
511  {
512  return m_iterator != aOther.m_iterator;
513  }
514 
515  bool operator==( const iterator& aOther ) const
516  {
517  return m_iterator == aOther.m_iterator;
518  }
519 
520  private:
521  NETNAMES_MAP::const_iterator m_iterator;
522  };
523 
524  iterator begin() const
525  {
526  return iterator( m_netNames.begin() );
527  }
528 
529  iterator end() const
530  {
531  return iterator( m_netNames.end() );
532  }
533 #endif
534 
535  BOARD* GetParent() const
536  {
537  return m_Parent;
538  }
539 
540 private:
545  void clear();
546 
552  void buildListOfNets();
553 
562  void buildPadsFullList();
563 
568  int getFreeNetCode();
569 
571 
572  NETNAMES_MAP m_netNames;
573  NETCODES_MAP m_netCodes;
574 
576 };
577 
578 
579 /***********************************************************/
580 /* Description of a trace point for monitoring connections */
581 /***********************************************************/
582 #define START_ON_PAD 0x10
583 #define END_ON_PAD 0x20
584 #define START_ON_TRACK 0x40
585 #define END_ON_TRACK 0x80
586 
587 /* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */
589 
590  RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE ratsnest is Ok */
591  DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general
592  * ratsnest (used in module moves) */
593 };
594 
595 
596 #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:225
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:85
int GetClearance(BOARD_ITEM *aBoardItem)
Function GetClearance returns the clearance when routing near aBoardItem.
NETCLASSPTR m_NetClass
Definition: class_netinfo.h:81
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
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
wxString GetClassName() const
Function GetClassName returns the class name.
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:83
#define DECL_MAP_FOR_SWIG(TypeName, KeyType, ValueType)
Definition: macros.h:147
NETINFO_ITEM * operator*() const
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
int getFreeNetCode()
Function getFreeNetCode returns the first available net code that is not used by any other 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
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:95
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
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:178
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:90
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