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  friend class CONNECTIONS;
51 
52 public:
53  // These 2 members are used for temporary storage during connections calculations:
54  std::vector<TRACK*> m_TracksConnected; // list of other tracks connected to me
55  std::vector<D_PAD*> m_PadsConnected; // list of other pads connected to me
56 
57  BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
58 
59  // Do not create a copy constructor & operator=.
60  // The ones generated by the compiler are adequate.
61 
62  static inline bool ClassOf( const EDA_ITEM* aItem )
63  {
64  if( aItem == NULL )
65  return false;
66 
67  switch( aItem->Type() )
68  {
69  case PCB_PAD_T:
70  case PCB_TRACE_T:
71  case PCB_VIA_T:
72  case PCB_ZONE_AREA_T:
73  return true;
74 
75  default:
76  return false;
77  }
78  }
79 
81  bool IsConnected() const override
82  {
83  return true;
84  }
85 
91  {
92  return m_netinfo;
93  }
94 
99  void SetNet( NETINFO_ITEM* aNetInfo )
100  {
101  assert( aNetInfo->GetBoard() == GetBoard() );
102  m_netinfo = aNetInfo;
103  }
104 
109  int GetNetCode() const
110  {
111  return m_netinfo->GetNet();
112  }
113 
122  bool SetNetCode( int aNetCode, bool aNoAssert=false );
123 
128  int GetSubNet() const
129  {
130  return m_Subnet;
131  }
132 
133  void SetSubNet( int aSubNetCode )
134  {
135  m_Subnet = aSubNetCode;
136  }
137 
142  int GetZoneSubNet() const
143  {
144  return m_ZoneSubnet;
145  }
146 
147  void SetZoneSubNet( int aSubNetCode )
148  {
149  m_ZoneSubnet = aSubNetCode;
150  }
151 
156  const wxString& GetNetname() const
157  {
158  return m_netinfo->GetNetname();
159  }
160 
165  const wxString& GetShortNetname() const
166  {
167  return m_netinfo->GetShortNetname();
168  }
169 
179  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
180 
185  std::shared_ptr<NETCLASS> GetNetClass() const;
186 
195  wxString GetNetClassName() const;
196 
197 protected:
200 
201 private:
202  int m_Subnet; /* In rastnest routines : for the current net, block number
203  * (number common to the current connected items found)
204  */
205 
206  int m_ZoneSubnet; // used in rastnest computations : for the current net,
207  // handle cluster number in zone connection
208 };
209 
210 
211 #if 0 // template for future
212 
216 class BOARD_ITEM_LIST : public BOARD_ITEM
217 {
218  typedef boost::ptr_vector<BOARD_ITEM> ITEM_ARRAY;
219 
220  ITEM_ARRAY myItems;
221 
222  BOARD_ITEM_LIST( const BOARD_ITEM_LIST& other ) :
223  BOARD_ITEM( NULL, PCB_ITEM_LIST_T )
224  {
225  // copy constructor is not supported, is private to cause compiler error
226  }
227 
228 public:
229 
230  BOARD_ITEM_LIST( BOARD_ITEM* aParent = NULL ) :
231  BOARD_ITEM( aParent, PCB_ITEM_LIST_T )
232  {}
233 
234  //-----< satisfy some virtual functions >------------------------------
235  const wxPoint GetPosition()
236  {
237  return wxPoint(0, 0); // dummy
238  }
239 
240  void Draw( EDA_DRAW_PANEL* DrawPanel, wxDC* DC,
241  GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset )
242  {
243  }
244 
245  void UnLink()
246  {
247  /* if it were needed:
248  DHEAD* list = GetList();
249 
250  wxASSERT( list );
251 
252  list->remove( this );
253  */
254  }
255 
256  //-----</ satisfy some virtual functions >-----------------------------
257 
262  int GetCount() const
263  {
264  return myItems.size();
265  }
266 
267  void Append( BOARD_ITEM* aItem )
268  {
269  myItems.push_back( aItem );
270  }
271 
272  BOARD_ITEM* Replace( int aIndex, BOARD_ITEM* aItem )
273  {
274  ITEM_ARRAY::auto_type ret = myItems.replace( aIndex, aItem );
275  return ret.release();
276  }
277 
278  BOARD_ITEM* Remove( int aIndex )
279  {
280  ITEM_ARRAY::auto_type ret = myItems.release( myItems.begin()+aIndex );
281  return ret.release();
282  }
283 
284  void Insert( int aIndex, BOARD_ITEM* aItem )
285  {
286  myItems.insert( myItems.begin()+aIndex, aItem );
287  }
288 
289  BOARD_ITEM* At( int aIndex ) const
290  {
291  // we have varying sized objects and are using polymorphism, so we
292  // must return a pointer not a reference.
293  return (BOARD_ITEM*) &myItems[aIndex];
294  }
295 
296  BOARD_ITEM* operator[]( int aIndex ) const
297  {
298  return At( aIndex );
299  }
300 
301  void Delete( int aIndex )
302  {
303  myItems.erase( myItems.begin()+aIndex );
304  }
305 
306  void PushBack( BOARD_ITEM* aItem )
307  {
308  Append( aItem );
309  }
310 
311  BOARD_ITEM* PopBack()
312  {
313  if( GetCount() )
314  return Remove( GetCount()-1 );
315 
316  return NULL;
317  }
318 };
319 #endif // future
320 
321 #endif // BOARD_CONNECTED_ITEM_H
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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
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
int GetZoneSubNet() const
Function GetZoneSubNet.
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 1/10000 inches.
std::vector< D_PAD * > m_PadsConnected
static bool ClassOf(const EDA_ITEM *aItem)
void SetSubNet(int aSubNetCode)
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
int GetNetCode() const
Function GetNetCode.
Class NETINFO_ITEM handles the data for a net.
void SetNet(NETINFO_ITEM *aNetInfo)
Function SetNet Sets a NET_INFO object for the item.
const wxString & GetNetname() const
Function GetNetname.
void SetZoneSubNet(int aSubNetCode)
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
int GetSubNet() const
Function GetSubNet.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
std::vector< TRACK * > m_TracksConnected
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.