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=false );
115 
120  const wxString& GetNetname() const
121  {
122  return m_netinfo->GetNetname();
123  }
124 
130  wxString GetNetnameMsg() const
131  {
132  if( !GetBoard() )
133  return wxT( "[** NO BOARD DEFINED **]" );
134 
135  wxString netname = GetNetname();
136 
137  if( !netname.length() )
138  return wxT( "[<no net>]" );
139  else if( GetNetCode() < 0 )
140  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
141  else
142  return wxT( "[" + UnescapeString( netname ) + "]" );
143  }
144 
149  const wxString& GetShortNetname() const
150  {
151  return m_netinfo->GetShortNetname();
152  }
153 
163  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
164 
169  std::shared_ptr<NETCLASS> GetNetClass() const;
170 
179  wxString GetNetClassName() const;
180 
181  void SetLocalRatsnestVisible( bool aVisible )
182  {
183  m_localRatsnestVisible = aVisible;
184  }
185 
187  {
188  return m_localRatsnestVisible;
189  }
190 
191 protected:
194 
195 private:
196 
198 };
199 
200 #endif // BOARD_CONNECTED_ITEM_H
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:470
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.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
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:238
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:55
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:232
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
const wxString & GetNetname() const
Function GetNetname.
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:224
#define _(s)
Definition: 3d_actions.cpp:33
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
std::shared_ptr< NETCLASS > GetNetClass() const
Function GetNetClass returns the NETCLASS for this item.
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:166
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxString & GetShortNetname() const
Function GetShortNetname.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212