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-2020 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 <class_board.h>
27 #include <class_board_item.h>
29 #include <drc/drc_engine.h>
30 #include <kicad_string.h>
31 #include <i18n_utility.h>
32 
33 using namespace std::placeholders;
34 
36  BOARD_ITEM( aParent, idtype ), m_netinfo( NETINFO_LIST::OrphanedItem() )
37 {
39 }
40 
41 
42 bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
43 {
44  if( !IsOnCopperLayer() )
45  aNetCode = 0;
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 
53  if( ( aNetCode >= 0 ) && board )
54  m_netinfo = board->FindNet( aNetCode );
55  else
57 
58  if( !aNoAssert )
59  wxASSERT( m_netinfo );
60 
61  return ( m_netinfo != NULL );
62 }
63 
64 
65 // This method returns the Default netclass for nets which don't have their own.
67 {
68  // NB: we must check the net first, as when it is 0 GetNetClass() will return the
69  // orphaned net netclass, not the default netclass.
70  if( m_netinfo->GetNet() == 0 )
72  else
73  return GetNetClass();
74 }
75 
76 
77 /*
78  * Returns the item's "own" clearance (ie: that not affected by other items).
79  */
80 int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
81 {
82  DRC_CONSTRAINT constraint;
83 
84  if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
85  {
87 
88  constraint = bds.m_DRCEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, this,
89  nullptr, aLayer );
90  }
91 
92  if( constraint.Value().HasMin() )
93  {
94  if( aSource )
95  *aSource = constraint.GetName();
96 
97  return constraint.Value().Min();
98  }
99 
100  return 0;
101 }
102 
103 
104 // Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
105 // std::shared_ptr stuff shows up large in performance profiling.
107 {
108  NETCLASS* netclass = m_netinfo->GetNetClass();
109 
110  if( netclass )
111  return netclass;
112  else
113  return GetBoard()->GetDesignSettings().GetDefault();
114 }
115 
116 
118 {
119  return m_netinfo->GetClassName();
120 }
121 
122 
124 {
125  if( !GetBoard() )
126  return wxT( "[** NO BOARD DEFINED **]" );
127 
128  wxString netname = GetNetname();
129 
130  if( !netname.length() )
131  return wxT( "[<no net>]" );
132  else if( GetNetCode() < 0 )
133  return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
134  else
135  return wxT( "[" + UnescapeString( netname ) + "]" );
136 }
137 
138 
140 {
142  {
144 
145  if( layerEnum.Choices().GetCount() == 0 )
146  {
147  layerEnum.Undefined( UNDEFINED_LAYER );
148 
149  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
150  layerEnum.Map( *seq, LSET::Name( *seq ) );
151  }
152 
156 
157  propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
160 
163  propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetName" ),
165  propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetClass" ),
167  }
NETCLASS * GetNetClass()
Function GetNetClass.
Definition: netinfo.h:128
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:55
int GetNetCode() const
Function GetNetCode.
bool HasMin() const
Definition: minoptmax.h:35
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition: netinfo.h:486
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
MINOPTMAX< int > & Value()
Definition: drc_rule.h:122
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
ENUM_MAP & Undefined(T aValue)
Definition: property.h:532
NETCLASS * GetNetClass() const
Function GetNetClassPtr returns the NETCLASS for this item.
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
static ENUM_MAP< T > & Instance()
Definition: property.h:519
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
wxString GetNetname() const
Function GetNetname.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
static struct BOARD_CONNECTED_ITEM_DESC _BOARD_CONNECTED_ITEM_DESC
T Min() const
Definition: minoptmax.h:31
wxPGChoices & Choices()
Definition: property.h:558
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
Definition: property.h:613
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names
Definition: property_mgr.h:247
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
wxString GetName() const
Definition: drc_rule.h:127
PCB_LAYER_ID
A quick note on layer IDs:
#define NULL
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:422
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declares an inheritance relationship between types.
static LSET AllLayersMask()
Definition: lset.cpp:786
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
wxString GetNetnameMsg() const
Function GetNetnameMsg.
Some functions to handle hotkeys in KiCad.
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
NETINFO_ITEM * m_netinfo
Stores all informations about the net that item belongs to.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
void AddProperty(PROPERTY_BASE *aProperty)
Registers a property.
NETCLASS * GetDefault() const
Function GetDefault.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Function GetClearance returns an item's "own" clearance in internal units.
void ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew)
Replaces an existing property for a specific type.
Provides class metadata.
Definition: property_mgr.h:61
NETCLASS * GetEffectiveNetclass() const
Function GetEffectiveNetclass returns the NETCLASS for this item, or the default netclass if none is ...
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:525
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:137
#define _HKI(x)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
virtual bool IsOnCopperLayer() const
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.