KiCad PCB EDA Suite
class_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 <class_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 
131  const wxString& GetShortNetname() const
132  {
133  return m_netinfo->GetShortNetname();
134  }
135 
145  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
146 
151  std::shared_ptr<NETCLASS> GetNetClass() const;
152 
161  wxString GetNetClassName() const;
162 
163  void SetLocalRatsnestVisible( bool aVisible )
164  {
165  m_localRatsnestVisible = aVisible;
166  }
167 
169  {
170  return m_localRatsnestVisible;
171  }
172 
173 protected:
176 
177 private:
178 
180 };
181 
182 
183 #if 0 // template for future
184 
188 class BOARD_ITEM_LIST : public BOARD_ITEM
189 {
190  typedef boost::ptr_vector<BOARD_ITEM> ITEM_ARRAY;
191 
192  ITEM_ARRAY myItems;
193 
194  BOARD_ITEM_LIST( const BOARD_ITEM_LIST& other ) :
195  BOARD_ITEM( NULL, PCB_ITEM_LIST_T )
196  {
197  // copy constructor is not supported, is private to cause compiler error
198  }
199 
200 public:
201 
202  BOARD_ITEM_LIST( BOARD_ITEM* aParent = NULL ) :
203  BOARD_ITEM( aParent, PCB_ITEM_LIST_T )
204  {}
205 
206  //-----< satisfy some virtual functions >------------------------------
207  const wxPoint GetPosition()
208  {
209  return wxPoint(0, 0); // dummy
210  }
211 
212  void Draw( EDA_DRAW_PANEL* DrawPanel, wxDC* DC,
213  GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset )
214  {
215  }
216 
217  void UnLink()
218  {
219  /* if it were needed:
220  DHEAD* list = GetList();
221 
222  wxASSERT( list );
223 
224  list->remove( this );
225  */
226  }
227 
228  //-----</ satisfy some virtual functions >-----------------------------
229 
234  int GetCount() const
235  {
236  return myItems.size();
237  }
238 
239  void Append( BOARD_ITEM* aItem )
240  {
241  myItems.push_back( aItem );
242  }
243 
244  BOARD_ITEM* Replace( int aIndex, BOARD_ITEM* aItem )
245  {
246  ITEM_ARRAY::auto_type ret = myItems.replace( aIndex, aItem );
247  return ret.release();
248  }
249 
250  BOARD_ITEM* Remove( int aIndex )
251  {
252  ITEM_ARRAY::auto_type ret = myItems.release( myItems.begin()+aIndex );
253  return ret.release();
254  }
255 
256  void Insert( int aIndex, BOARD_ITEM* aItem )
257  {
258  myItems.insert( myItems.begin()+aIndex, aItem );
259  }
260 
261  BOARD_ITEM* At( int aIndex ) const
262  {
263  // we have varying sized objects and are using polymorphism, so we
264  // must return a pointer not a reference.
265  return (BOARD_ITEM*) &myItems[aIndex];
266  }
267 
268  BOARD_ITEM* operator[]( int aIndex ) const
269  {
270  return At( aIndex );
271  }
272 
273  void Delete( int aIndex )
274  {
275  myItems.erase( myItems.begin()+aIndex );
276  }
277 
278  void PushBack( BOARD_ITEM* aItem )
279  {
280  Append( aItem );
281  }
282 
283  BOARD_ITEM* PopBack()
284  {
285  if( GetCount() )
286  return Remove( GetCount()-1 );
287 
288  return NULL;
289  }
290 };
291 #endif // future
292 
293 #endif // BOARD_CONNECTED_ITEM_H
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
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:114
virtual const wxPoint & GetPosition() const =0
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
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:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
const wxString & GetShortNetname() const
Function GetShortNetname.
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:41
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:115
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
int GetNet() const
Function GetNet.
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
static bool ClassOf(const EDA_ITEM *aItem)
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
int GetNetCode() const
Function GetNetCode.
Class NETINFO_ITEM handles the data for a net.
Definition: class_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:165
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:108
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.
const wxString & GetNetname() const
Function GetNetname.
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxString & GetShortNetname() const
Function GetShortNetname.