KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
6 * Copyright (C) 1992-2022 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>
30#include <lset.h>
32#include <string_utils.h>
33#include <i18n_utility.h>
34#include <netinfo.h>
35
36using namespace std::placeholders;
37
39 BOARD_ITEM( aParent, idtype ),
40 m_netinfo( NETINFO_LIST::OrphanedItem() )
41{
43}
44
45
46bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
47{
48 if( !IsOnCopperLayer() )
49 aNetCode = 0;
50
51 // if aNetCode < 0 (typically NETINFO_LIST::FORCE_ORPHANED) or no parent board,
52 // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
53
54 BOARD* board = GetBoard();
55
56 if( ( aNetCode >= 0 ) && board )
57 m_netinfo = board->FindNet( aNetCode );
58 else
60
61 if( !aNoAssert )
62 wxASSERT( m_netinfo );
63
64 return ( m_netinfo != nullptr );
65}
66
67
68int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
69{
70 DRC_CONSTRAINT constraint;
71
72 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
73 {
75
76 constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
77 }
78
79 if( constraint.Value().HasMin() )
80 {
81 if( aSource )
82 *aSource = constraint.GetName();
83
84 return constraint.Value().Min();
85 }
86
87 return 0;
88}
89
90
92{
93 return m_netinfo ? m_netinfo->GetNetCode() : -1;
94}
95
96
97// Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
98// std::shared_ptr stuff shows up large in performance profiling.
100{
102 return m_netinfo->GetNetClass();
103 else
104 return GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass().get();
105}
106
107
109{
110 return GetEffectiveNetClass()->GetName();
111}
112
113
115{
117}
118
119
121{
122 return m_netinfo ? m_netinfo->GetNetname() : wxString();
123}
124
125
127{
128 if( !GetBoard() )
129 return wxT( "[** NO BOARD DEFINED **]" );
130
131 wxString netname = GetNetname();
132
133 if( !netname.length() )
134 return wxT( "[<no net>]" );
135 else if( GetNetCode() < 0 )
136 return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
137 else
138 return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
139}
140
141
143{
144 static wxString emptyString;
145
147}
148
149
151{
152 static wxString emptyString;
153
154 if( !m_netinfo )
155 return emptyString;
156
157 if( const BOARD* board = GetBoard() )
158 {
159 if( board->GetNetInfo().m_DisplayNetnamesDirty )
160 board->GetNetInfo().RebuildDisplayNetnames();
161 }
162
164}
165
166
168{
170 {
172
173 if( layerEnum.Choices().GetCount() == 0 )
174 {
175 layerEnum.Undefined( UNDEFINED_LAYER );
176
177 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
178 layerEnum.Map( layer, LSET::Name( layer ) );
179 }
180
184
185 // Replace layer property as the properties panel will set a restriction for copper layers
186 // only for BOARD_CONNECTED_ITEM that we don't want to apply to BOARD_ITEM
188 _HKI( "Layer" ),
190 layer->SetChoices( layerEnum.Choices() );
191 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
192
198
206 propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "Net Class" ),
207 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
212
213 // Compatibility alias for DRC engine
215 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
219
220 // Used only in DRC engine
222 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
226
227 auto supportsTeardrops =
228 []( INSPECTABLE* aItem ) -> bool
229 {
230 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
231 {
232 if( bci->GetBoard()->LegacyTeardrops() )
233 return false;
234
235 return bci->Type() == PCB_PAD_T || bci->Type() == PCB_VIA_T;
236 }
237
238 return false;
239 };
240
241 auto supportsTeardropPreferZoneSetting =
242 []( INSPECTABLE* aItem ) -> bool
243 {
244 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
245 {
246 if( bci->GetBoard()->LegacyTeardrops() )
247 return false;
248
249 return bci->Type() == PCB_PAD_T;
250 }
251
252 return false;
253 };
254
255 const wxString groupTeardrops = _HKI( "Teardrops" );
256
257 auto enableTeardrops = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Enable Teardrops" ),
260 enableTeardrops->SetAvailableFunc( supportsTeardrops );
261 propMgr.AddProperty( enableTeardrops, groupTeardrops );
262
263 auto bestLength = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Length Ratio" ),
266 bestLength->SetAvailableFunc( supportsTeardrops );
267 bestLength->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
268 propMgr.AddProperty( bestLength, groupTeardrops );
269
270 auto maxLength = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Length" ),
272 &BOARD_CONNECTED_ITEM::GetTeardropMaxLength, PROPERTY_DISPLAY::PT_SIZE );
273 maxLength->SetAvailableFunc( supportsTeardrops );
274 propMgr.AddProperty( maxLength, groupTeardrops );
275
276 auto bestWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Width Ratio" ),
279 bestWidth->SetAvailableFunc( supportsTeardrops );
280 bestWidth->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
281 propMgr.AddProperty( bestWidth, groupTeardrops );
282
283 auto maxWidth = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Width" ),
285 &BOARD_CONNECTED_ITEM::GetTeardropMaxWidth, PROPERTY_DISPLAY::PT_SIZE );
286 maxWidth->SetAvailableFunc( supportsTeardrops );
287 propMgr.AddProperty( maxWidth, groupTeardrops );
288
289 auto curvePts = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Curved Teardrops" ),
292 curvePts->SetAvailableFunc( supportsTeardrops );
293 propMgr.AddProperty( curvePts, groupTeardrops );
294
295 auto preferZones = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Prefer Zone Connections" ),
298 preferZones->SetAvailableFunc( supportsTeardropPreferZoneSetting );
299 propMgr.AddProperty( preferZones, groupTeardrops );
300
301 auto twoTracks = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Allow Teardrops To Span Two Tracks" ),
304 twoTracks->SetAvailableFunc( supportsTeardrops );
305 propMgr.AddProperty( twoTracks, groupTeardrops );
306
307 auto maxTrackWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Max Width Ratio" ),
310 maxTrackWidth->SetAvailableFunc( supportsTeardrops );
311 propMgr.AddProperty( maxTrackWidth, groupTeardrops );
312 }
static struct BOARD_CONNECTED_ITEM_DESC _BOARD_CONNECTED_ITEM_DESC
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
wxString GetNetnameMsg() const
bool GetTeardropPreferZoneConnections() const
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
double GetTeardropBestLengthRatio() const
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetTeardropBestWidthRatio(double aRatio)
void SetTeardropMaxTrackWidth(double aRatio)
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
double GetTeardropMaxTrackWidth() const
wxString GetNetClassVariableSubstitutionName() const
void SetTeardropAllowSpanTwoTracks(bool aAllow)
const wxString & GetDisplayNetname() const
const wxString & GetShortNetname() const
double GetTeardropBestWidthRatio() const
wxString GetNetClassName() const
Returns the name of the effective netclass.
void SetTeardropCurved(bool aCurve)
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
void SetTeardropMaxWidth(int aMaxWidth)
void SetTeardropPreferZoneConnections(bool aPrefer)
void SetTeardropBestLengthRatio(double aRatio)
void SetTeardropMaxLength(int aMaxLength)
bool GetTeardropAllowSpanTwoTracks() const
void SetTeardropsEnabled(bool aEnable)
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:237
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
virtual bool IsOnCopperLayer() const
Definition: board_item.h:150
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1922
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
wxString GetName() const
Definition: drc_rule.h:160
MINOPTMAX< int > & Value()
Definition: drc_rule.h:153
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:669
static ENUM_MAP< T > & Instance()
Definition: property.h:663
ENUM_MAP & Undefined(T aValue)
Definition: property.h:676
wxPGChoices & Choices()
Definition: property.h:712
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
static LSET AllLayersMask()
Definition: lset.cpp:711
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:193
T Min() const
Definition: minoptmax.h:33
bool HasMin() const
Definition: minoptmax.h:37
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
const wxString GetName() const
Gets the consolidated name of this netclass (which may be an aggregate)
Definition: netclass.cpp:151
const wxString GetVariableSubstitutionName() const
Gets the name of this (maybe aggregate) netclass in a format for label variable substitutions.
Definition: netclass.cpp:179
const wxString & GetShortNetname() const
Definition: netinfo.h:119
const wxString & GetNetname() const
Definition: netinfo.h:114
NETCLASS * GetNetClass()
Definition: netinfo.h:101
int GetNetCode() const
Definition: netinfo.h:108
const wxString & GetDisplayNetname() const
Definition: netinfo.h:124
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:346
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:389
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:300
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:307
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:314
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
static VALIDATOR_RESULT PositiveRatioValidator(const wxAny &&aValue, EDA_ITEM *aItem)
#define _HKI(x)
@ CLEARANCE_CONSTRAINT
Definition: drc_rule.h:49
#define _(s)
Some functions to handle hotkeys in KiCad.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
#define TYPE_HASH(x)
Definition: property.h:71
#define NO_SETTER(owner, type)
Definition: property.h:774
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static const char * emptyString
wxString UnescapeString(const wxString &aSource)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87