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