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  NETCLASSPTR myclass = GetNetClass();
82 
83  // DO NOT use wxASSERT, because GetClearance is called inside an OnPaint event
84  // and a call to wxASSERT can crash the application.
85  if( myclass )
86  {
87  int myClearance = myclass->GetClearance();
88  // @todo : after GetNetClass() is reliably not returning NULL, remove the
89  // tests for if( myclass )
90 
91  if( aItem )
92  {
93  int hisClearance = aItem->GetClearance();
94  return std::max( hisClearance, myClearance );
95  }
96 
97  return myClearance;
98  }
99  else
100  {
101  wxLogTrace( traceMask, "%s: NULL netclass,type %d", __func__, Type() );
102  }
103 
104  return 0;
105 }
106 
107 
109 {
110  // It is important that this be implemented without any sequential searching.
111  // Simple array lookups should be fine, performance-wise.
112  BOARD* board = GetBoard();
113 
114  // DO NOT use wxASSERT, because GetNetClass is called inside an OnPaint event
115  // and a call to wxASSERT can crash the application.
116 
117  if( board == NULL ) // Should not occur
118  {
119  wxLogTrace( traceMask, "%s: NULL board,type %d", __func__, Type() );
120 
121  return NETCLASSPTR();
122  }
123 
124  NETCLASSPTR netclass;
125  NETINFO_ITEM* net = board->FindNet( GetNetCode() );
126 
127  if( net )
128  {
129  netclass = net->GetNetClass();
130 
131  //DBG( if(!netclass) printf( "%s: NULL netclass,type %d", __func__, Type() );)
132  }
133 
134  if( netclass )
135  return netclass;
136  else
137  return board->GetDesignSettings().GetDefault();
138 }
139 
140 
142 {
143  wxString name;
144  NETCLASSPTR myclass = GetNetClass();
145 
146  if( myclass )
147  name = myclass->GetName();
148  else
150 
151  return name;
152 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
int GetNetCode() const
Function GetNetCode.
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)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:534
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
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:411
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.
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
const char * name
Definition: DXF_plotter.cpp:61
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:473
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204