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-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 <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  bool m_isCurrent;
78 
81  wxString m_Netname;
82 
83  wxString m_ShortNetname;
84 
85  NETCLASSPTR m_NetClass;
86 
88 
89 public:
90 
91  NETINFO_ITEM( BOARD* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
92  ~NETINFO_ITEM();
93 
94  static inline bool ClassOf( const EDA_ITEM* aItem )
95  {
96  return aItem && PCB_T == aItem->Type();
97  }
98 
99  wxString GetClass() const override
100  {
101  return wxT( "NETINFO_ITEM" );
102  }
103 
104 #if defined(DEBUG)
105  void Show( int nestLevel, std::ostream& os ) const override
106  {
107  }
108 #endif
109 
110  const wxPoint GetPosition() const override
111  {
112  static wxPoint dummy(0, 0);
113  return dummy;
114  }
115 
116  void SetPosition( const wxPoint& aPos ) override
117  {
118  }
119 
124  void SetClass( const NETCLASSPTR& aNetClass );
125 
126  NETCLASSPTR GetNetClass()
127  {
128  return m_NetClass;
129  }
130 
135  wxString GetClassName() const
136  {
137  return m_NetClass ? m_NetClass->GetName() : NETCLASS::Default;
138  }
139 
140 #if 1
141 
147  {
148  wxASSERT( m_NetClass );
149  return m_NetClass->GetTrackWidth();
150  }
151 
157  {
158  wxASSERT( m_NetClass );
159  return m_NetClass->GetViaDiameter();
160  }
161 
167  {
168  wxASSERT( m_NetClass );
169  return m_NetClass->GetuViaDiameter();
170  }
171 
177  {
178  wxASSERT( m_NetClass );
179  return m_NetClass->GetViaDrill();
180  }
181 
187  {
188  wxASSERT( m_NetClass );
189  return m_NetClass->GetuViaDrill();
190  }
191 
192 
193 #if 0
194 
199  int GetViaMinSize()
200  {
201  wxASSERT( m_NetClass );
202  return m_NetClass->GetViaMinSize();
203  }
204 
205 #endif
206 
211  int GetClearance( BOARD_ITEM* aBoardItem )
212  {
213  wxASSERT( m_NetClass );
214  return m_NetClass->GetClearance();
215  }
216 
217 #endif
218 
224  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
225  const wxPoint& offset ) override;
226 
231  int GetNet() const { return m_NetCode; }
232 
233  void SetNetCode( int aNetCode ) { m_NetCode = aNetCode; }
234 
239  const wxString& GetNetname() const { return m_Netname; }
240 
245  const wxString& GetShortNetname() const { return m_ShortNetname; }
246 
247  bool IsCurrent() const { return m_isCurrent; }
248 
249  void SetIsCurrent( bool isCurrent ) { m_isCurrent = isCurrent; }
250 
258  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
259 
264  void Clear()
265  {
266  SetClass( NETCLASSPTR() );
267  }
268 
269  BOARD* GetParent() const
270  {
271  return m_parent;
272  }
273 };
274 
275 
277 {
278 public:
280  {
281  m_board = NULL;
282  }
283 
284 
289  void SetBoard( const BOARD* aBoard )
290  {
291  m_board = aBoard;
292  Update();
293  }
294 
300  void Update();
301 
309  int Translate( int aNetCode ) const;
310 
313  class iterator
314  {
315  public:
316  iterator( std::map<int, int>::const_iterator aIter, const NETINFO_MAPPING* aMapping ) :
317  m_iterator( aIter ), m_mapping( aMapping )
318  {
319  }
320 
323  {
324  ++m_iterator;
325 
326  return *this;
327  }
328 
331  {
332  iterator ret = *this;
333  ++m_iterator;
334 
335  return ret;
336  }
337 
338  NETINFO_ITEM* operator*() const;
339 
340  NETINFO_ITEM* operator->() const;
341 
342  bool operator!=( const iterator& aOther ) const
343  {
344  return m_iterator != aOther.m_iterator;
345  }
346 
347  bool operator==( const iterator& aOther ) const
348  {
349  return m_iterator == aOther.m_iterator;
350  }
351 
352  private:
353  std::map<int, int>::const_iterator m_iterator;
355  };
356 
363  iterator begin() const
364  {
365  return iterator( m_netMapping.begin(), this );
366  }
367 
374  iterator end() const
375  {
376  return iterator( m_netMapping.end(), this );
377  }
378 
383  int GetSize() const
384  {
385  return m_netMapping.size();
386  }
387 
388 private:
390  const BOARD* m_board;
391 
393  std::map<int, int> m_netMapping;
394 };
395 
396 
397 #if 0
398 // waiting for swig to support std::unordered_map, see
399 // http://www.swig.org/Doc3.0/CPlusPlus11.html
400 // section 7.3.3
401 #include <hashtables.h>
402 DECL_HASH_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
403 DECL_HASH_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
404 #else
405 // use std::map for now
406 DECL_MAP_FOR_SWIG( NETNAMES_MAP, wxString, NETINFO_ITEM* )
407 DECL_MAP_FOR_SWIG( NETCODES_MAP, int, NETINFO_ITEM* )
408 #endif
409 
416 {
417  friend class BOARD;
418 
419 public:
420  NETINFO_LIST( BOARD* aParent );
421  ~NETINFO_LIST();
422 
428  NETINFO_ITEM* GetNetItem( int aNetCode ) const;
429 
435  NETINFO_ITEM* GetNetItem( const wxString& aNetName ) const;
436 
442  unsigned GetNetCount() const { return m_netNames.size(); }
443 
449  void AppendNet( NETINFO_ITEM* aNewElement );
450 
455  void RemoveNet( NETINFO_ITEM* aNet );
461  const NETNAMES_MAP& NetsByName() const { return m_netNames; }
463 
465  const NETCODES_MAP& NetsByNetcode() const { return m_netCodes; }
466 
469  static const int UNCONNECTED;
470 
473  static const int ORPHANED;
474 
478 
479 #if defined(DEBUG)
480  void Show() const;
481 #endif
482 
483 #ifndef SWIG
484  class iterator
487  {
488  public:
489  iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
490  {
491  }
492 
495  {
496  ++m_iterator;
497  return *this;
498  }
499 
502  {
503  iterator ret = *this;
504  ++m_iterator;
505  return ret;
506  }
507 
509  {
510  return m_iterator->second;
511  }
512 
514  {
515  return m_iterator->second;
516  }
517 
518  bool operator!=( const iterator& aOther ) const
519  {
520  return m_iterator != aOther.m_iterator;
521  }
522 
523  bool operator==( const iterator& aOther ) const
524  {
525  return m_iterator == aOther.m_iterator;
526  }
527 
528  private:
529  NETNAMES_MAP::const_iterator m_iterator;
530  };
531 
532  iterator begin() const
533  {
534  return iterator( m_netNames.begin() );
535  }
536 
537  iterator end() const
538  {
539  return iterator( m_netNames.end() );
540  }
541 #endif
542 
543  BOARD* GetParent() const
544  {
545  return m_Parent;
546  }
547 
548 private:
553  void clear();
554 
560  void buildListOfNets();
561 
570  void buildPadsFullList();
571 
576  int getFreeNetCode();
577 
579 
580  NETNAMES_MAP m_netNames;
581  NETCODES_MAP m_netCodes;
582 
584 };
585 
586 
587 /***********************************************************/
588 /* Description of a trace point for monitoring connections */
589 /***********************************************************/
590 #define START_ON_PAD 0x10
591 #define END_ON_PAD 0x20
592 #define START_ON_TRACK 0x40
593 #define END_ON_TRACK 0x80
594 
595 /* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */
597 
598  RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE ratsnest is Ok */
599  DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general
600  * ratsnest (used in module moves) */
601 };
602 
603 
604 #endif // CLASS_NETINFO_
NETNAMES_MAP::const_iterator m_iterator
Definition: netinfo.h:529
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:342
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:486
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:363
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:578
Definition: typeinfo.h:85
int GetClearance(BOARD_ITEM *aBoardItem)
Function GetClearance returns the clearance when routing near aBoardItem.
Definition: netinfo.h:211
NETCLASSPTR m_NetClass
Definition: netinfo.h:85
const iterator & operator++()
pre-increment operator
Definition: netinfo.h:494
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
Definition: netinfo.h:322
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:249
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:390
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
NETINFO_ITEM * operator->() const
Definition: netinfo.h:513
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:135
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
Definition: netinfo.h:465
unsigned GetNetCount() const
Function GetNetCount.
Definition: netinfo.h:442
bool m_isCurrent
Indicates the net is currently in use.
Definition: netinfo.h:77
iterator operator++(int)
post-increment operator
Definition: netinfo.h:330
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:580
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:87
#define DECL_MAP_FOR_SWIG(TypeName, KeyType, ValueType)
Definition: macros.h:147
NETINFO_ITEM * operator*() const
Definition: netinfo.h:508
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:374
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
Definition: netinfo.h:393
const NETINFO_MAPPING * m_mapping
Definition: netinfo.h:354
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.
Definition: netinfo.h:289
StatusPcbFlags
Definition: netinfo.h:596
const wxString & GetShortNetname() const
Function GetShortNetname.
Definition: netinfo.h:245
iterator(std::map< int, int >::const_iterator aIter, const NETINFO_MAPPING *aMapping)
Definition: netinfo.h:316
int GetSize() const
Function GetSize.
Definition: netinfo.h:383
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:415
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:37
BOARD * GetParent() const
Definition: netinfo.h:543
#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
Definition: netinfo.h:583
iterator operator++(int)
post-increment operator
Definition: netinfo.h:501
void SetNetCode(int aNetCode)
Definition: netinfo.h:233
int GetViaSize()
Function GetViaSize returns the size of vias used to route this net.
Definition: netinfo.h:156
#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: netinfo.h:74
int GetTrackWidth()
Function GetTrackWidth returns the width of tracks used to route this net.
Definition: netinfo.h:146
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
wxString GetClass() const override
Function GetClass returns the class name.
Definition: netinfo.h:99
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:313
bool operator!=(const iterator &aOther) const
Definition: netinfo.h:518
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:473
wxString m_Netname
Full net name like /mysheet/mysubsheet/vout used by Eeschema.
Definition: netinfo.h:81
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
iterator(NETNAMES_MAP::const_iterator aIter)
Definition: netinfo.h:489
iterator begin() const
Definition: netinfo.h:532
void Clear()
Function Clear sets all fields to their defaults values.
Definition: netinfo.h:264
std::map< int, int >::const_iterator m_iterator
Definition: netinfo.h:353
BOARD * GetParent() const
Definition: netinfo.h:269
iterator end() const
Definition: netinfo.h:537
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...
Definition: netinfo.h:477
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
bool IsCurrent() const
Definition: netinfo.h:247
NETCLASSPTR GetNetClass()
Definition: netinfo.h:126
bool operator==(const iterator &aOther) const
Definition: netinfo.h:523
const wxPoint GetPosition() const override
Definition: netinfo.h:110
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:154
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:186
wxString m_ShortNetname
short net name, like vout from /mysheet/mysubsheet/vout
Definition: netinfo.h:83
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
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.
Definition: netinfo.h:176
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:166
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:469
static bool ClassOf(const EDA_ITEM *aItem)
Definition: netinfo.h:94
EDA_UNITS_T
Definition: common.h:159
void SetPosition(const wxPoint &aPos) override
Definition: netinfo.h:116
bool operator==(const iterator &aOther) const
Definition: netinfo.h:347
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:581