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 {
43 }
44 
45 
46 bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
47 {
48  // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED )
49  // or no parent board,
50  // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
51 
52  BOARD* board = GetBoard();
53  //auto connectivity = board ? board->GetConnectivity() : nullptr;
54  //bool addRatsnest = false;
55 
56  //if( connectivity )
57  //addRatsnest = connectivity->Remove( this );
58 
59  if( ( aNetCode >= 0 ) && board )
60  m_netinfo = board->FindNet( aNetCode );
61  else
63 
64  if( !aNoAssert )
65  assert( m_netinfo );
66 
67  // Add only if it was previously added to the ratsnest
68  //if( addRatsnest )
69  // connectivity->Add( this );
70 
71  return ( m_netinfo != NULL );
72 }
73 
74 
76 {
77  NETCLASSPTR myclass = GetNetClass();
78 
79  // DO NOT use wxASSERT, because GetClearance is called inside an OnPaint event
80  // and a call to wxASSERT can crash the application.
81  if( myclass )
82  {
83  int myClearance = myclass->GetClearance();
84  // @todo : after GetNetClass() is reliably not returning NULL, remove the
85  // tests for if( myclass )
86 
87  if( aItem )
88  {
89  int hisClearance = aItem->GetClearance();
90  return std::max( hisClearance, myClearance );
91  }
92 
93  return myClearance;
94  }
95  else
96  {
97  DBG(printf( "%s: NULL netclass,type %d", __func__, Type() );)
98  }
99 
100  return 0;
101 }
102 
103 
105 {
106  // It is important that this be implemented without any sequential searching.
107  // Simple array lookups should be fine, performance-wise.
108  BOARD* board = GetBoard();
109 
110  // DO NOT use wxASSERT, because GetNetClass is called inside an OnPaint event
111  // and a call to wxASSERT can crash the application.
112 
113  if( board == NULL ) // Should not occur
114  {
115  DBG(printf( "%s: NULL board,type %d", __func__, Type() );)
116 
117  return NETCLASSPTR();
118  }
119 
120  NETCLASSPTR netclass;
121  NETINFO_ITEM* net = board->FindNet( GetNetCode() );
122 
123  if( net )
124  {
125  netclass = net->GetNetClass();
126 
127  //DBG( if(!netclass) printf( "%s: NULL netclass,type %d", __func__, Type() );)
128  }
129 
130  if( netclass )
131  return netclass;
132  else
133  return board->GetDesignSettings().GetDefault();
134 }
135 
136 
138 {
139  wxString name;
140  NETCLASSPTR myclass = GetNetClass();
141 
142  if( myclass )
143  name = myclass->GetName();
144  else
145  name = NETCLASS::Default;
146 
147  return name;
148 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
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:532
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.