KiCad PCB EDA Suite
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 
38 
39 
40 const wxChar* const traceMask = wxT( "BOARD_CONNECTED_ITEM" );
41 
42 
44  BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED_ITEM )
45 {
47 }
48 
49 
50 bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
51 {
52  // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED )
53  // or no parent board,
54  // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
55 
56  BOARD* board = GetBoard();
57  //auto connectivity = board ? board->GetConnectivity() : nullptr;
58  //bool addRatsnest = false;
59 
60  //if( connectivity )
61  //addRatsnest = connectivity->Remove( this );
62 
63  if( ( aNetCode >= 0 ) && board )
64  m_netinfo = board->FindNet( aNetCode );
65  else
67 
68  if( !aNoAssert )
69  assert( m_netinfo );
70 
71  // Add only if it was previously added to the ratsnest
72  //if( addRatsnest )
73  // connectivity->Add( this );
74 
75  return ( m_netinfo != NULL );
76 }
77 
78 
80 {
81  int myClearance = m_netinfo->GetClearance();
82 
83  if( m_netinfo->GetNet() == 0 )
84  myClearance = GetBoard()->GetDesignSettings().GetDefault()->GetClearance();
85 
86  if( aItem )
87  return std::max( myClearance, aItem->GetClearance() );
88 
89  return myClearance;
90 }
91 
92 
94 {
95  NETCLASSPTR netclass = m_netinfo->GetNetClass();
96 
97  if( netclass )
98  return netclass;
99  else
100  return GetBoard()->GetDesignSettings().GetDefault();
101 }
102 
103 
105 {
106  return m_netinfo->GetClassName();
107 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
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)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:409
const wxChar *const traceMask
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
int GetClearance()
Function GetClearance.
Definition: netinfo.h:206
NETCLASSPTR GetDefault() const
Function GetDefault.
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...
Definition: netinfo.h:471
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
NETCLASSPTR GetNetClass()
Definition: netinfo.h:122
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
std::shared_ptr< NETCLASS > GetNetClass() const
Function GetNetClass returns the NETCLASS for this item.
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131