KiCad PCB EDA Suite
class_board_connected_item.cpp
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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2015 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 #include <fctsys.h>
32 #include <pcbnew.h>
33 
34 #include <class_board.h>
35 #include <class_board_item.h>
36 
37 #include <connectivity.h>
38 
40  BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED_ITEM )
41 {
42 }
43 
44 
45 bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
46 {
47  // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED )
48  // or no parent board,
49  // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
50 
51  BOARD* board = GetBoard();
52  //auto connectivity = board ? board->GetConnectivity() : nullptr;
53  //bool addRatsnest = false;
54 
55  //if( connectivity )
56  //addRatsnest = connectivity->Remove( this );
57 
58  if( ( aNetCode >= 0 ) && board )
59  m_netinfo = board->FindNet( aNetCode );
60  else
62 
63  if( !aNoAssert )
64  assert( m_netinfo );
65 
66  // Add only if it was previously added to the ratsnest
67  //if( addRatsnest )
68  // connectivity->Add( this );
69 
70  return ( m_netinfo != NULL );
71 }
72 
73 
75 {
76  NETCLASSPTR myclass = GetNetClass();
77 
78  // DO NOT use wxASSERT, because GetClearance is called inside an OnPaint event
79  // and a call to wxASSERT can crash the application.
80  if( myclass )
81  {
82  int myClearance = myclass->GetClearance();
83  // @todo : after GetNetClass() is reliably not returning NULL, remove the
84  // tests for if( myclass )
85 
86  if( aItem )
87  {
88  int hisClearance = aItem->GetClearance();
89  return std::max( hisClearance, myClearance );
90  }
91 
92  return myClearance;
93  }
94  else
95  {
96  DBG(printf( "%s: NULL netclass,type %d", __func__, Type() );)
97  }
98 
99  return 0;
100 }
101 
102 
104 {
105  // It is important that this be implemented without any sequential searching.
106  // Simple array lookups should be fine, performance-wise.
107  BOARD* board = GetBoard();
108 
109  // DO NOT use wxASSERT, because GetNetClass is called inside an OnPaint event
110  // and a call to wxASSERT can crash the application.
111 
112  if( board == NULL ) // Should not occur
113  {
114  DBG(printf( "%s: NULL board,type %d", __func__, Type() );)
115 
116  return NETCLASSPTR();
117  }
118 
119  NETCLASSPTR netclass;
120  NETINFO_ITEM* net = board->FindNet( GetNetCode() );
121 
122  if( net )
123  {
124  netclass = net->GetNetClass();
125 
126  //DBG( if(!netclass) printf( "%s: NULL netclass,type %d", __func__, Type() );)
127  }
128 
129  if( netclass )
130  return netclass;
131  else
132  return board->GetDesignSettings().GetDefault();
133 }
134 
135 
137 {
138  wxString name;
139  NETCLASSPTR myclass = GetNetClass();
140 
141  if( myclass )
142  name = myclass->GetName();
143  else
144  name = NETCLASS::Default;
145 
146  return name;
147 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
NETCLASSPTR GetDefault() const
Function GetDefault.
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.
Class BOARD to handle a board.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
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
std::shared_ptr< NETCLASS > GetNetClass() const
Function GetNetClass returns the NETCLASS for this item.
static const char Default[]
the name of the default NETCLASS
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:533
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
int GetNetCode() const
Function GetNetCode.
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
static NETINFO_ITEM ORPHANED_ITEM
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
NETCLASSPTR GetNetClass()
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const char * name
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
#define DBG(x)
Definition: fctsys.h:33
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.