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_VIA_T:
62  case PCB_ZONE_AREA_T:
63  return true;
64 
65  default:
66  return false;
67  }
68  }
69 
71  bool IsConnected() const override
72  {
73  return true;
74  }
75 
81  {
82  return m_netinfo;
83  }
84 
89  void SetNet( NETINFO_ITEM* aNetInfo )
90  {
91  assert( aNetInfo->GetBoard() == GetBoard() );
92  m_netinfo = aNetInfo;
93  }
94 
99  int GetNetCode() const
100  {
101  return m_netinfo ? m_netinfo->GetNet() : -1;
102  }
103 
113  bool SetNetCode( int aNetCode, bool aNoAssert=false );
114 
119  const wxString& GetNetname() const
120  {
121  return m_netinfo->GetNetname();
122  }
123 
129  wxString GetNetnameMsg() const
130  {
131  if( !GetBoard() )
132  return wxT( "[** NO BOARD DEFINED **]" );
133 
134  wxString netname = GetNetname();
135 
136  if( !netname.length() )
137  return wxT( "[<no net>]" );
138  else if( GetNetCode() < 0 )
139  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
140  else
141  return wxT( "[" + UnescapeString( netname ) + "]" );
142  }
143 
148  const wxString& GetShortNetname() const
149  {
150  return m_netinfo->GetShortNetname();
151  }
152 
162  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
163 
168  std::shared_ptr<NETCLASS> GetNetClass() const;
169 
178  wxString GetNetClassName() const;
179 
180  void SetLocalRatsnestVisible( bool aVisible )
181  {
182  m_localRatsnestVisible = aVisible;
183  }
184 
186  {
187  return m_localRatsnestVisible;
188  }
189 
190 protected:
193 
194 private:
195 
197 };
198 
199 
200 #if 0 // template for future
201 
205 class BOARD_ITEM_LIST : public BOARD_ITEM
206 {
207  typedef boost::ptr_vector<BOARD_ITEM> ITEM_ARRAY;
208 
209  ITEM_ARRAY myItems;
210 
211  BOARD_ITEM_LIST( const BOARD_ITEM_LIST& other ) :
212  BOARD_ITEM( NULL, PCB_ITEM_LIST_T )
213  {
214  // copy constructor is not supported, is private to cause compiler error
215  }
216 
217 public:
218 
219  BOARD_ITEM_LIST( BOARD_ITEM* aParent = NULL ) :
220  BOARD_ITEM( aParent, PCB_ITEM_LIST_T )
221  {}
222 
223  //-----< satisfy some virtual functions >------------------------------
224  const wxPoint GetPosition()
225  {
226  return wxPoint(0, 0); // dummy
227  }
228 
229  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset )
230  {
231  }
232 
233  void UnLink()
234  {
235  /* if it were needed:
236  DHEAD* list = GetList();
237 
238  wxASSERT( list );
239 
240  list->remove( this );
241  */
242  }
243 
244  //-----</ satisfy some virtual functions >-----------------------------
245 
250  int GetCount() const
251  {
252  return myItems.size();
253  }
254 
255  void Append( BOARD_ITEM* aItem )
256  {
257  myItems.push_back( aItem );
258  }
259 
260  BOARD_ITEM* Replace( int aIndex, BOARD_ITEM* aItem )
261  {
262  ITEM_ARRAY::auto_type ret = myItems.replace( aIndex, aItem );
263  return ret.release();
264  }
265 
266  BOARD_ITEM* Remove( int aIndex )
267  {
268  ITEM_ARRAY::auto_type ret = myItems.release( myItems.begin()+aIndex );
269  return ret.release();
270  }
271 
272  void Insert( int aIndex, BOARD_ITEM* aItem )
273  {
274  myItems.insert( myItems.begin()+aIndex, aItem );
275  }
276 
277  BOARD_ITEM* At( int aIndex ) const
278  {
279  // we have varying sized objects and are using polymorphism, so we
280  // must return a pointer not a reference.
281  return (BOARD_ITEM*) &myItems[aIndex];
282  }
283 
284  BOARD_ITEM* operator[]( int aIndex ) const override
285  {
286  return At( aIndex );
287  }
288 
289  void Delete( int aIndex )
290  {
291  myItems.erase( myItems.begin()+aIndex );
292  }
293 
294  void PushBack( BOARD_ITEM* aItem )
295  {
296  Append( aItem );
297  }
298 
299  BOARD_ITEM* PopBack()
300  {
301  if( GetCount() )
302  return Remove( GetCount()-1 );
303 
304  return NULL;
305  }
306 };
307 #endif // future
308 
309 #endif // BOARD_CONNECTED_ITEM_H
int GetNetCode() const
Function GetNetCode.
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &offset=ZeroOffset)=0
Function Print BOARD_ITEMs have their own color information.
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:101
bool GetLocalRatsnestVisible() const
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void SetLocalRatsnestVisible(bool aVisible)
bool IsConnected() const override
virtual void UnLink()
Function UnLink detaches this object from its owner.
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
const wxString & GetShortNetname() const
Function GetShortNetname.
Definition: netinfo.h:239
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
Class 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.
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:102
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
const wxString & GetNetname() const
Function GetNetname.
#define _(s)
static bool ClassOf(const EDA_ITEM *aItem)
virtual const wxPoint GetPosition() const =0
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
wxString GetNetnameMsg() const
Function GetNetnameMsg.
Class 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:225
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
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
const wxString & GetShortNetname() const
Function GetShortNetname.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210