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 
69 {
70 private:
71  int m_NetCode; // netcode ( = 1.. n , 0 is the value used for not connected items)
72 
73 public:
74  int m_Status; // State: see previous defines (CH_ ...)
75  D_PAD* m_PadStart; // pointer to the starting pad
76  D_PAD* m_PadEnd; // pointer to ending pad
77  int m_Length; // length of the line (used in some calculations)
78 
79  RATSNEST_ITEM();
80 
85  int GetNet() const
86  {
87  return m_NetCode;
88  }
89 
90  void SetNet( int aNetCode )
91  {
92  m_NetCode = aNetCode;
93  }
94 
95  bool IsVisible()
96  {
97  return (m_Status & CH_VISIBLE) != 0;
98  }
99 
100  bool IsActive()
101  {
102  return (m_Status & CH_ACTIF) != 0;
103  }
104 
105  bool IsLocal()
106  {
107  return (m_Status & LOCAL_RATSNEST_ITEM) != 0;
108  }
109 
113  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
114  const wxPoint& offset );
115 };
116 
117 
118 DECL_VEC_FOR_SWIG( D_PADS, D_PAD* )
119 
120 
124 class NETINFO_ITEM : public BOARD_ITEM
125 {
126  friend class NETINFO_LIST;
127 
128 private:
129  int m_NetCode;
130 
132  wxString m_Netname;
133 
134  wxString m_ShortNetname;
135 
136  wxString m_NetClassName; // Net Class name. if void this is equivalent
137  // to "default" (the first
138  // item of the net classes list
139  NETCLASSPTR m_NetClass;
140 
142 
143 public:
144 
145  D_PADS& Pads() { return m_PadInNetList; }
146 
151  int GetNodesCount() const { return m_PadInNetList.size(); }
152 
153 
154  D_PADS m_PadInNetList;
155 
156  unsigned m_RatsnestStartIdx; /* Starting point of ratsnests of this
157  * net (included) in a general buffer of
158  * ratsnest (a vector<RATSNEST_ITEM*>
159  * buffer) */
160 
161  unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net
162  // (excluded) in this buffer
163 
164  NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
165  ~NETINFO_ITEM();
166 
167  static inline bool ClassOf( const EDA_ITEM* aItem )
168  {
169  return aItem && PCB_T == aItem->Type();
170  }
171 
172  wxString GetClass() const override
173  {
174  return wxT( "NETINFO_ITEM" );
175  }
176 
177 #if defined(DEBUG)
178  void Show( int nestLevel, std::ostream& os ) const override
179  {
180  }
181 #endif
182 
183  const wxPoint& GetPosition() const override
184  {
185  static wxPoint dummy(0, 0);
186  return dummy;
187  }
188 
189  void SetPosition( const wxPoint& aPos ) override
190  {
191  }
192 
197  void SetClass( NETCLASSPTR aNetClass )
198  {
199  m_NetClass = aNetClass;
200 
201  if( aNetClass )
202  m_NetClassName = aNetClass->GetName();
203  else
204  m_NetClassName = NETCLASS::Default;
205  }
206 
207  NETCLASSPTR GetNetClass()
208  {
209  return m_NetClass;
210  }
211 
216  const wxString& GetClassName() const
217  {
218  return m_NetClassName;
219  }
220 
221 #if 1
222 
228  {
229  wxASSERT( m_NetClass );
230  return m_NetClass->GetTrackWidth();
231  }
232 
238  {
239  wxASSERT( m_NetClass );
240  return m_NetClass->GetViaDiameter();
241  }
242 
248  {
249  wxASSERT( m_NetClass );
250  return m_NetClass->GetuViaDiameter();
251  }
252 
258  {
259  wxASSERT( m_NetClass );
260  return m_NetClass->GetViaDrill();
261  }
262 
268  {
269  wxASSERT( m_NetClass );
270  return m_NetClass->GetuViaDrill();
271  }
272 
273 
274 #if 0
275 
280  int GetViaMinSize()
281  {
282  wxASSERT( m_NetClass );
283  return m_NetClass->GetViaMinSize();
284  }
285 
286 #endif
287 
292  int GetClearance( BOARD_ITEM* aBoardItem )
293  {
294  wxASSERT( m_NetClass );
295  return m_NetClass->GetClearance();
296  }
297 
298 #endif
299 
305  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
306  const wxPoint& offset ) override;
307 
312  int GetNet() const { return m_NetCode; }
313 
314  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
315 
320  const wxString& GetNetname() const { return m_Netname; }
321 
326  const wxString& GetShortNetname() const { return m_ShortNetname; }
327 
335  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
336 
341  void Clear()
342  {
343  m_PadInNetList.clear();
344 
345  m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
346  // general buffer of ratsnest
347  m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
348 
349  SetClass( NETCLASSPTR() );
350  }
351 
352  BOARD* GetParent() const
353  {
354  return m_parent;
355  }
356 };
357 
358 
360 {
361 public:
363  {
364  m_board = NULL;
365  }
366 
367 
372  void SetBoard( const BOARD* aBoard )
373  {
374  m_board = aBoard;
375  Update();
376  }
377 
383  void Update();
384 
392  int Translate( int aNetCode ) const;
393 
396  class iterator
397  {
398  public:
399  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
400  m_iterator( aIter ), m_mapping( aMapping )
401  {
402  }
403 
406  {
407  ++m_iterator;
408 
409  return *this;
410  }
411 
414  {
415  iterator ret = *this;
416  ++m_iterator;
417 
418  return ret;
419  }
420 
421  NETINFO_ITEM* operator*() const;
422 
423  NETINFO_ITEM* operator->() const;
424 
425  bool operator!=( const iterator& aOther ) const
426  {
427  return m_iterator != aOther.m_iterator;
428  }
429 
430  bool operator==( const iterator& aOther ) const
431  {
432  return m_iterator == aOther.m_iterator;
433  }
434 
435  private:
436  std::map<int, int>::const_iterator m_iterator;
438  };
439 
446  iterator begin() const
447  {
448  return iterator( m_netMapping.begin(), this );
449  }
450 
457  iterator end() const
458  {
459  return iterator( m_netMapping.end(), this );
460  }
461 
466  int GetSize() const
467  {
468  return m_netMapping.size();
469  }
470 
471 private:
473  const BOARD* m_board;
474 
476  std::map<int, int> m_netMapping;
477 };
478 
479 
480 #if 0
481 // waiting for swig to support std::unordered_map, see
482 // http://www.swig.org/Doc3.0/CPlusPlus11.html
483 // section 7.3.3
484 #include <hashtables.h>
485 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
486 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
487 #else
488 // use std::map for now
489 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
490 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
491 #endif
492 
499 {
500  friend class BOARD;
501 
502 public:
503  NETINFO_LIST( BOARD* aParent );
504  ~NETINFO_LIST();
505 
511  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
512 
518  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
519 
525  unsigned GetNetCount() const { return m_netNames.size(); }
526 
532  void AppendNet( NETINFO_ITEM* aNewElement );
533 
538  void RemoveNet( NETINFO_ITEM* aNet );
543  unsigned GetPadCount() const { return m_PadsFullList.size(); }
544 
551  const D_PADS& GetPads() const { return m_PadsFullList; }
552 
554  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
555 
557  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
558 
563  D_PAD* GetPad( unsigned aIdx ) const;
564 
565  bool DeletePad( D_PAD* aPad );
566 
569  static const int UNCONNECTED;
570 
573  static const int ORPHANED;
574 
578 
579 #if defined(DEBUG)
580  void Show() const;
581 #endif
582 
583 #ifndef SWIG
584  class iterator
587  {
588  public:
589  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
590  {
591  }
592 
595  {
596  ++m_iterator;
597  return *this;
598  }
599 
602  {
603  iterator ret = *this;
604  ++m_iterator;
605  return ret;
606  }
607 
609  {
610  return m_iterator->second;
611  }
612 
614  {
615  return m_iterator->second;
616  }
617 
618  bool operator!=( const iterator& aOther ) const
619  {
620  return m_iterator != aOther.m_iterator;
621  }
622 
623  bool operator==( const iterator& aOther ) const
624  {
625  return m_iterator == aOther.m_iterator;
626  }
627 
628  private:
629  NETNAMES_MAP::const_iterator m_iterator;
630  };
631 
632  iterator begin() const
633  {
634  return iterator( m_netNames.begin() );
635  }
636 
637  iterator end() const
638  {
639  return iterator( m_netNames.end() );
640  }
641 #endif
642 
643  BOARD* GetParent() const
644  {
645  return m_Parent;
646  }
647 
648 private:
653  void clear();
654 
660  void buildListOfNets();
661 
670  void buildPadsFullList();
671 
676  int getFreeNetCode();
677 
679 
680  NETNAMES_MAP m_netNames;
681  NETCODES_MAP m_netCodes;
682 
683  D_PADS m_PadsFullList;
684 
687 };
688 
689 
690 /***********************************************************/
691 /* Description of a trace point for monitoring connections */
692 /***********************************************************/
693 #define START_ON_PAD 0x10
694 #define END_ON_PAD 0x20
695 #define START_ON_TRACK 0x40
696 #define END_ON_TRACK 0x80
697 
698 
699 /* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */
701  LISTE_PAD_OK = 1, /* Pad list is Ok */
702  LISTE_RATSNEST_ITEM_OK = 2, /* General Ratsnest is Ok */
703  RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE ratsnest is Ok */
704  CONNEXION_OK = 8, /* List of connections exists. */
705  NET_CODES_OK = 0x10, /* Bit indicating that Netcode is OK,
706  * do not change net name. */
707  DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general
708  * ratsnest (used in module moves) */
709 };
710 
711 #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 GetNodesCount() const
Function GetNodesCount.
int GetClearance(BOARD_ITEM *aBoardItem)
Function GetClearance returns the clearance when routing near aBoardItem.
NETCLASSPTR m_NetClass
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
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
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.
const D_PADS & GetPads() const
Function GetPads returns a list of all the pads (so long as buildPadsFullList() has been recently cal...
D_PADS & Pads()
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.
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...
D_PADS m_PadInNetList
List of pads connected to this net.
void SetClass(NETCLASSPTR aNetClass)
Function SetClass sets aNetclass into this NET.
void SetNet(int aNetCode)
Definition: class_netinfo.h:90
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.
#define CH_ACTIF
Definition: class_netinfo.h:60
D_PAD * m_PadEnd
Definition: class_netinfo.h:76
const wxString & GetShortNetname() const
Function GetShortNetname.
void RemoveNet(NETINFO_ITEM *aNet)
Function RemoveNet Removes a new from the net list.
unsigned m_RatsnestStartIdx
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
#define LOCAL_RATSNEST_ITEM
Definition: class_netinfo.h:61
int GetSize() const
Function GetSize.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset)
Function Draw.
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)
D_PAD * GetPad(unsigned aIdx) const
Function GetPad.
int GetViaSize()
Function GetViaSize returns the size of vias used to route this net.
bool IsVisible()
Definition: class_netinfo.h:95
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros.h:146
#define CH_VISIBLE
Definition: class_netinfo.h:57
bool DeletePad(D_PAD *aPad)
int m_NetCode
A number equivalent to the net name.
int GetNet() const
Function GetNet.
Definition: class_netinfo.h:85
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.
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
bool operator!=(const iterator &aOther) const
unsigned GetPadCount() const
Function GetPadCount.
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
D_PAD * m_PadStart
Definition: class_netinfo.h:75
wxString m_Netname
Full net name like /mysheet/mysubsheet/vout used by Eeschema.
Class NETINFO_ITEM handles the data for a net.
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:166
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
void clear()
Function clear deletes the list of nets (and free memory)
Class RATSNEST_ITEM describes a ratsnest line: a straight line connecting 2 pads. ...
Definition: class_netinfo.h:68
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)
void buildListOfNets()
Function buildListOfNets builds or rebuilds the list of NETINFO_ITEMs The list is sorted by names...
const wxPoint & GetPosition() const override
unsigned m_RatsnestEndIdx
void SetPosition(const wxPoint &aPos) override
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
bool operator==(const iterator &aOther) const
NETCODES_MAP m_netCodes
map of is NOT owner