KiCad PCB EDA Suite
board_connected_item.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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef BOARD_CONNECTED_ITEM_H
27 #define BOARD_CONNECTED_ITEM_H
28 
29 #include <class_board_item.h>
30 #include <netinfo.h>
31 #include <reporter.h>
32 #include <kicad_string.h>
33 
34 class NETCLASS;
35 class TRACK;
36 class D_PAD;
37 
46 {
47 public:
48  BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
49 
50  // Do not create a copy constructor & operator=.
51  // The ones generated by the compiler are adequate.
52 
53  static inline bool ClassOf( const EDA_ITEM* aItem )
54  {
55  if( aItem == NULL )
56  return false;
57 
58  switch( aItem->Type() )
59  {
60  case PCB_PAD_T:
61  case PCB_TRACE_T:
62  case PCB_ARC_T:
63  case PCB_VIA_T:
64  case PCB_ZONE_AREA_T:
65  return true;
66 
67  default:
68  return false;
69  }
70  }
71 
73  bool IsConnected() const override
74  {
75  return true;
76  }
77 
83  {
84  return m_netinfo;
85  }
86 
91  void SetNet( NETINFO_ITEM* aNetInfo )
92  {
93  m_netinfo = aNetInfo;
94  }
95 
100  int GetNetCode() const
101  {
102  return m_netinfo ? m_netinfo->GetNet() : -1;
103  }
104 
114  bool SetNetCode( int aNetCode, bool aNoAssert );
115 
116  void SetNetCode( int aNetCode )
117  {
118  SetNetCode( aNetCode, false );
119  }
120 
125  wxString GetNetname() const
126  {
127  return m_netinfo ? m_netinfo->GetNetname() : wxString();
128  }
129 
135  wxString GetNetnameMsg() const
136  {
137  if( !GetBoard() )
138  return wxT( "[** NO BOARD DEFINED **]" );
139 
140  wxString netname = GetNetname();
141 
142  if( !netname.length() )
143  return wxT( "[<no net>]" );
144  else if( GetNetCode() < 0 )
145  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
146  else
147  return wxT( "[" + UnescapeString( netname ) + "]" );
148  }
149 
154  wxString GetShortNetname() const
155  {
156  return m_netinfo->GetShortNetname();
157  }
158 
170  virtual int GetClearance( PCB_LAYER_ID aLayer, BOARD_ITEM* aItem = nullptr,
171  wxString* aSource = nullptr ) const;
172 
179  virtual int GetLocalClearanceOverrides( wxString* aSource ) const { return 0; }
180 
188  virtual int GetLocalClearance( wxString* aSource ) const { return 0; }
189 
197  NETCLASS* GetNetClass() const;
198 
207 
216  wxString GetNetClassName() const;
217 
218  void SetLocalRatsnestVisible( bool aVisible )
219  {
220  m_localRatsnestVisible = aVisible;
221  }
222 
224  {
225  return m_localRatsnestVisible;
226  }
227 
228 protected:
231 
232 private:
233 
235 };
236 
237 #endif // BOARD_CONNECTED_ITEM_H
int GetNetCode() const
Function GetNetCode.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
NETCLASS * GetNetClass() const
Function GetNetClassPtr returns the NETCLASS for this item.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
bool GetLocalRatsnestVisible() const
wxString GetNetname() const
Function GetNetname.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void SetLocalRatsnestVisible(bool aVisible)
virtual int GetLocalClearanceOverrides(wxString *aSource) const
Function GetLocalClearanceOverrides returns any local clearance overrides set in the "classic" (ie: p...
bool IsConnected() const override
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
const wxString & GetShortNetname() const
Function GetShortNetname.
Definition: netinfo.h:237
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
virtual int GetClearance(PCB_LAYER_ID aLayer, BOARD_ITEM *aItem=nullptr, wxString *aSource=nullptr) const
Function GetClearance returns the clearance in internal units.
PCB_LAYER_ID
A quick note on layer IDs:
wxString GetShortNetname() const
Function GetShortNetname.
#define NULL
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
static bool ClassOf(const EDA_ITEM *aItem)
wxString GetNetnameMsg() const
Function GetNetnameMsg.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
void SetNet(NETINFO_ITEM *aNetInfo)
Function SetNet Sets a NET_INFO object for the item.
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
#define _(s)
Definition: 3d_actions.cpp:33
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
NETCLASS * GetEffectiveNetclass() const
Function GetEffectiveNetclass returns the NETCLASS for this item, or the default netclass if none is ...
virtual int GetLocalClearance(wxString *aSource) const
Function GetLocalClearance returns any local clearances set in the "classic" (ie: pre-rule) system.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
void SetNetCode(int aNetCode)