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 
31 #ifndef BOARD_CONNECTED_ITEM_H
32 #define BOARD_CONNECTED_ITEM_H
33 
34 #include <class_board_item.h>
35 #include <netinfo.h>
36 #include <kicad_string.h>
37 
38 class NETCLASS;
39 class TRACK;
40 class D_PAD;
41 
50 {
51 public:
52  BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
53 
54  // Do not create a copy constructor & operator=.
55  // The ones generated by the compiler are adequate.
56 
57  static inline bool ClassOf( const EDA_ITEM* aItem )
58  {
59  if( aItem == NULL )
60  return false;
61 
62  switch( aItem->Type() )
63  {
64  case PCB_PAD_T:
65  case PCB_TRACE_T:
66  case PCB_VIA_T:
67  case PCB_ZONE_AREA_T:
68  return true;
69 
70  default:
71  return false;
72  }
73  }
74 
76  bool IsConnected() const override
77  {
78  return true;
79  }
80 
86  {
87  return m_netinfo;
88  }
89 
94  void SetNet( NETINFO_ITEM* aNetInfo )
95  {
96  assert( aNetInfo->GetBoard() == GetBoard() );
97  m_netinfo = aNetInfo;
98  }
99 
104  int GetNetCode() const
105  {
106  return m_netinfo->GetNet();
107  }
108 
117  bool SetNetCode( int aNetCode, bool aNoAssert=false );
118 
123  const wxString& GetNetname() const
124  {
125  return m_netinfo->GetNetname();
126  }
127 
133  wxString GetNetnameMsg() const
134  {
135  if( !GetBoard() )
136  return wxT( "[** NO BOARD DEFINED **]" );
137 
138  wxString netname = GetNetname();
139 
140  if( !netname.length() )
141  return wxT( "[<no net>]" );
142  else if( GetNetCode() < 0 )
143  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
144  else
145  return wxT( "[" + UnescapeString( netname ) + "]" );
146  }
147 
152  const wxString& GetShortNetname() const
153  {
154  return m_netinfo->GetShortNetname();
155  }
156 
166  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
167 
172  std::shared_ptr<NETCLASS> GetNetClass() const;
173 
182  wxString GetNetClassName() const;
183 
184  void SetLocalRatsnestVisible( bool aVisible )
185  {
186  m_localRatsnestVisible = aVisible;
187  }
188 
190  {
191  return m_localRatsnestVisible;
192  }
193 
194 protected:
197 
198 private:
199 
201 };
202 
203 
204 #if 0 // template for future
205 
209 class BOARD_ITEM_LIST : public BOARD_ITEM
210 {
211  typedef boost::ptr_vector<BOARD_ITEM> ITEM_ARRAY;
212 
213  ITEM_ARRAY myItems;
214 
215  BOARD_ITEM_LIST( const BOARD_ITEM_LIST& other ) :
216  BOARD_ITEM( NULL, PCB_ITEM_LIST_T )
217  {
218  // copy constructor is not supported, is private to cause compiler error
219  }
220 
221 public:
222 
223  BOARD_ITEM_LIST( BOARD_ITEM* aParent = NULL ) :
224  BOARD_ITEM( aParent, PCB_ITEM_LIST_T )
225  {}
226 
227  //-----< satisfy some virtual functions >------------------------------
228  const wxPoint GetPosition()
229  {
230  return wxPoint(0, 0); // dummy
231  }
232 
233  void Draw( EDA_DRAW_PANEL* DrawPanel, wxDC* DC,
234  GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset )
235  {
236  }
237 
238  void UnLink()
239  {
240  /* if it were needed:
241  DHEAD* list = GetList();
242 
243  wxASSERT( list );
244 
245  list->remove( this );
246  */
247  }
248 
249  //-----</ satisfy some virtual functions >-----------------------------
250 
255  int GetCount() const
256  {
257  return myItems.size();
258  }
259 
260  void Append( BOARD_ITEM* aItem )
261  {
262  myItems.push_back( aItem );
263  }
264 
265  BOARD_ITEM* Replace( int aIndex, BOARD_ITEM* aItem )
266  {
267  ITEM_ARRAY::auto_type ret = myItems.replace( aIndex, aItem );
268  return ret.release();
269  }
270 
271  BOARD_ITEM* Remove( int aIndex )
272  {
273  ITEM_ARRAY::auto_type ret = myItems.release( myItems.begin()+aIndex );
274  return ret.release();
275  }
276 
277  void Insert( int aIndex, BOARD_ITEM* aItem )
278  {
279  myItems.insert( myItems.begin()+aIndex, aItem );
280  }
281 
282  BOARD_ITEM* At( int aIndex ) const
283  {
284  // we have varying sized objects and are using polymorphism, so we
285  // must return a pointer not a reference.
286  return (BOARD_ITEM*) &myItems[aIndex];
287  }
288 
289  BOARD_ITEM* operator[]( int aIndex ) const override
290  {
291  return At( aIndex );
292  }
293 
294  void Delete( int aIndex )
295  {
296  myItems.erase( myItems.begin()+aIndex );
297  }
298 
299  void PushBack( BOARD_ITEM* aItem )
300  {
301  Append( aItem );
302  }
303 
304  BOARD_ITEM* PopBack()
305  {
306  if( GetCount() )
307  return Remove( GetCount()-1 );
308 
309  return NULL;
310  }
311 };
312 #endif // future
313 
314 #endif // BOARD_CONNECTED_ITEM_H
int GetNetCode() const
Function GetNetCode.
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,...
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:100
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.
virtual void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)=0
Function Draw BOARD_ITEMs have their own color information.
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:241
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:95
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
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:101
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:235
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const wxString & GetNetname() const
Function GetNetname.
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:227
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:123
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
const wxString & GetShortNetname() const
Function GetShortNetname.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204