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 <kicad_string.h>
32 
33 class NETCLASS;
34 class TRACK;
35 class D_PAD;
36 
45 {
46 public:
47  BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
48 
49  // Do not create a copy constructor & operator=.
50  // The ones generated by the compiler are adequate.
51 
52  static inline bool ClassOf( const EDA_ITEM* aItem )
53  {
54  if( aItem == NULL )
55  return false;
56 
57  switch( aItem->Type() )
58  {
59  case PCB_PAD_T:
60  case PCB_TRACE_T:
61  case PCB_ARC_T:
62  case PCB_VIA_T:
63  case PCB_ZONE_AREA_T:
64  return true;
65 
66  default:
67  return false;
68  }
69  }
70 
72  bool IsConnected() const override
73  {
74  return true;
75  }
76 
82  {
83  return m_netinfo;
84  }
85 
90  void SetNet( NETINFO_ITEM* aNetInfo )
91  {
92  wxASSERT( aNetInfo->GetBoard() == GetBoard() || aNetInfo == NETINFO_LIST::OrphanedItem() );
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  const wxString& GetNetname() const
126  {
127  return m_netinfo->GetNetname();
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  const wxString& GetShortNetname() const
155  {
156  return m_netinfo->GetShortNetname();
157  }
158 
169  virtual int GetClearance( BOARD_ITEM* aItem = nullptr, wxString* aSource = nullptr ) const;
170 
178  virtual bool GetRuleClearance( BOARD_ITEM* aItem, int* aClearance, wxString* aSource ) const;
179 
186  virtual int GetLocalClearanceOverrides( wxString* aSource = nullptr ) const { return 0; }
187 
195  virtual int GetLocalClearance( wxString* aSource = nullptr ) const { return 0; }
196 
204  NETCLASS* GetNetClass() const;
205 
214 
223  wxString GetNetClassName() const;
224 
225  void SetLocalRatsnestVisible( bool aVisible )
226  {
227  m_localRatsnestVisible = aVisible;
228  }
229 
231  {
232  return m_localRatsnestVisible;
233  }
234 
235 protected:
238 
239 private:
240 
242 };
243 
244 #endif // BOARD_CONNECTED_ITEM_H
virtual int GetLocalClearance(wxString *aSource=nullptr) const
Function GetLocalClearance returns any local clearances set in the "classic" (ie: pre-rule) system.
int GetNetCode() const
Function GetNetCode.
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition: netinfo.h:486
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:102
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
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void SetLocalRatsnestVisible(bool aVisible)
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
#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
const wxString & GetNetname() const
Function GetNetname.
static bool ClassOf(const EDA_ITEM *aItem)
wxString GetNetnameMsg() const
Function GetNetnameMsg.
virtual int GetClearance(BOARD_ITEM *aItem=nullptr, wxString *aSource=nullptr) const
Function GetClearance returns the clearance in internal units.
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.
virtual int GetLocalClearanceOverrides(wxString *aSource=nullptr) const
Function GetLocalClearanceOverrides returns any local clearance overrides set in the "classic" (ie: p...
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:131
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 bool GetRuleClearance(BOARD_ITEM *aItem, int *aClearance, wxString *aSource) const
Function GetRuleClearance returns any rule-based clearance.
const wxString & GetShortNetname() const
Function GetShortNetname.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
void SetNetCode(int aNetCode)