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-2021 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 
26 #include <board.h>
27 #include <board_connected_item.h>
28 #include <board_design_settings.h>
30 #include <drc/drc_engine.h>
31 #include <kicad_string.h>
32 #include <i18n_utility.h>
33 #include <netinfo.h>
34 
35 using namespace std::placeholders;
36 
38  BOARD_ITEM( aParent, idtype ),
39  m_netinfo( NETINFO_LIST::OrphanedItem() )
40 {
42 }
43 
44 
45 bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
46 {
47  if( !IsOnCopperLayer() )
48  aNetCode = 0;
49 
50  // if aNetCode < 0 (typically NETINFO_LIST::FORCE_ORPHANED) or no parent board,
51  // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
52 
53  BOARD* board = GetBoard();
54 
55  if( ( aNetCode >= 0 ) && board )
56  m_netinfo = board->FindNet( aNetCode );
57  else
59 
60  if( !aNoAssert )
61  wxASSERT( m_netinfo );
62 
63  return ( m_netinfo != nullptr );
64 }
65 
66 
68 {
69  // NB: we must check the net first, as when it is 0 GetNetClass() will return the
70  // orphaned net netclass, not the default netclass.
71  if( !m_netinfo || m_netinfo->GetNetCode() == 0 )
73  else
74  return GetNetClass();
75 }
76 
77 
78 int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
79 {
80  DRC_CONSTRAINT constraint;
81 
82  if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
83  {
85 
86  constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
87  }
88 
89  if( constraint.Value().HasMin() )
90  {
91  if( aSource )
92  *aSource = constraint.GetName();
93 
94  return constraint.Value().Min();
95  }
96 
97  return 0;
98 }
99 
100 
102 {
103  return m_netinfo ? m_netinfo->GetNetCode() : -1;
104 }
105 
106 
107 // Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
108 // std::shared_ptr stuff shows up large in performance profiling.
110 {
111  if( m_netinfo && m_netinfo->GetNetClass() )
112  return m_netinfo->GetNetClass();
113  else
114  return GetBoard()->GetDesignSettings().GetDefault();
115 }
116 
117 
119 {
120  if( m_netinfo )
121  return m_netinfo->GetNetClassName();
122  else
123  return wxEmptyString;
124 }
125 
126 
128 {
129  return m_netinfo ? m_netinfo->GetNetname() : wxString();
130 }
131 
132 
134 {
135  if( !GetBoard() )
136  return wxT( "[** NO BOARD DEFINED **]" );
137 
138  wxString netname = GetNetname();
139 
140  if( !netname.length() )
141  return wxT( "[<no net>]" );
142  else if( GetNetCode() < 0 )
143  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
144  else
145  return wxT( "[" + UnescapeString( netname ) + "]" );
146 }
147 
148 
150 {
151  return m_netinfo->GetShortNetname();
152 }
153 
154 
156 {
158  {
160 
161  if( layerEnum.Choices().GetCount() == 0 )
162  {
163  layerEnum.Undefined( UNDEFINED_LAYER );
164 
165  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
166  layerEnum.Map( *seq, LSET::Name( *seq ) );
167  }
168 
172 
173  propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
176 
179  propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetName" ),
181  propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetClass" ),
183  }
NETCLASS * GetNetClass()
Definition: netinfo.h:103
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1343
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
bool HasMin() const
Definition: minoptmax.h:37
static NETINFO_ITEM * OrphanedItem()
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:373
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
wxString GetNetClassName() const
Definition: netinfo.h:108
MINOPTMAX< int > & Value()
Definition: drc_rule.h:123
ENUM_MAP & Undefined(T aValue)
Definition: property.h:523
virtual NETCLASS * GetNetClass() const
Return the NETCLASS for this item.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
static ENUM_MAP< T > & Instance()
Definition: property.h:510
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
static struct BOARD_CONNECTED_ITEM_DESC _BOARD_CONNECTED_ITEM_DESC
T Min() const
Definition: minoptmax.h:33
wxPGChoices & Choices()
Definition: property.h:559
#define NO_SETTER(owner, type)
Definition: property.h:621
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:588
#define REGISTER_TYPE(x)
Definition: property_mgr.h:248
const wxString & GetShortNetname() const
Definition: netinfo.h:124
virtual wxString GetNetClassName() const
Returns the netclass of the zone.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
wxString GetName() const
Definition: drc_rule.h:128
PCB_LAYER_ID
A quick note on layer IDs:
wxString GetShortNetname() const
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:315
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:51
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
const wxString & GetNetname() const
Definition: netinfo.h:119
#define _(s)
static LSET AllLayersMask()
Definition: lset.cpp:787
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
wxString GetNetnameMsg() const
Some functions to handle hotkeys in KiCad.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
NETCLASS * GetDefault() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
void ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew)
Replace an existing property for a specific type.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
virtual NETCLASS * GetEffectiveNetclass() const
Return the NETCLASS for this item, or the default netclass if none is defined.
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:516
#define _HKI(x)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
std::shared_ptr< DRC_ENGINE > m_DRCEngine
virtual bool IsOnCopperLayer() const
Definition: board_item.h:142
Container for design settings for a BOARD object.
int GetNetCode() const
Definition: netinfo.h:113