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>
31#include <string_utils.h>
32#include <i18n_utility.h>
33#include <netinfo.h>
34
35using namespace std::placeholders;
36
38 BOARD_ITEM( aParent, idtype ),
39 m_netinfo( NETINFO_LIST::OrphanedItem() )
40{
42}
43
44
45bool 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
67int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
68{
69 DRC_CONSTRAINT constraint;
70
71 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
72 {
74
75 constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
76 }
77
78 if( constraint.Value().HasMin() )
79 {
80 if( aSource )
81 *aSource = constraint.GetName();
82
83 return constraint.Value().Min();
84 }
85
86 return 0;
87}
88
89
91{
92 return m_netinfo ? m_netinfo->GetNetCode() : -1;
93}
94
95
96// Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
97// std::shared_ptr stuff shows up large in performance profiling.
99{
101 return m_netinfo->GetNetClass();
102 else
103 return GetBoard()->GetDesignSettings().m_NetSettings->m_DefaultNetClass.get();
104}
105
106
108{
109 return GetEffectiveNetClass()->GetName();
110}
111
112
114{
115 return m_netinfo ? m_netinfo->GetNetname() : wxString();
116}
117
118
120{
121 if( !GetBoard() )
122 return wxT( "[** NO BOARD DEFINED **]" );
123
124 wxString netname = GetNetname();
125
126 if( !netname.length() )
127 return wxT( "[<no net>]" );
128 else if( GetNetCode() < 0 )
129 return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
130 else
131 return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
132}
133
134
136{
137 return m_netinfo ? m_netinfo->GetShortNetname() : wxString();
138}
139
140
142{
143 return m_netinfo ? m_netinfo->GetUnescapedShortNetname() : wxString();
144}
145
146
148{
150 {
152
153 if( layerEnum.Choices().GetCount() == 0 )
154 {
155 layerEnum.Undefined( UNDEFINED_LAYER );
156
157 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
158 layerEnum.Map( *seq, LSET::Name( *seq ) );
159 }
160
164
165 // Replace layer property as the properties panel will set a restriction for copper layers
166 // only for BOARD_CONNECTED_ITEM that we don't want to apply to BOARD_ITEM
168 _HKI( "Layer" ),
170 layer->SetChoices( layerEnum.Choices() );
171 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
172
178
186 propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "Net Class" ),
187 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
192
193 // Compatibility alias for DRC engine
195 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
199
200 // Used only in DRC engine
202 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
206
207 auto supportsTeardrops =
208 []( INSPECTABLE* aItem ) -> bool
209 {
210 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
211 {
212 if( bci->GetBoard()->LegacyTeardrops() )
213 return false;
214
215 return bci->Type() == PCB_PAD_T || bci->Type() == PCB_VIA_T;
216 }
217
218 return false;
219 };
220
221 auto supportsTeardropPreferZoneSetting =
222 []( INSPECTABLE* aItem ) -> bool
223 {
224 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
225 {
226 if( bci->GetBoard()->LegacyTeardrops() )
227 return false;
228
229 return bci->Type() == PCB_PAD_T;
230 }
231
232 return false;
233 };
234
235 const wxString groupTeardrops = _HKI( "Teardrops" );
236
237 auto enableTeardrops = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Enable Teardrops" ),
240 enableTeardrops->SetAvailableFunc( supportsTeardrops );
241 propMgr.AddProperty( enableTeardrops, groupTeardrops );
242
243 auto bestLength = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Length Ratio" ),
246 bestLength->SetAvailableFunc( supportsTeardrops );
247 bestLength->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
248 propMgr.AddProperty( bestLength, groupTeardrops );
249
250 auto maxLength = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Length" ),
252 &BOARD_CONNECTED_ITEM::GetTeardropMaxLength, PROPERTY_DISPLAY::PT_SIZE );
253 maxLength->SetAvailableFunc( supportsTeardrops );
254 propMgr.AddProperty( maxLength, groupTeardrops );
255
256 auto bestWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Width Ratio" ),
259 bestWidth->SetAvailableFunc( supportsTeardrops );
260 bestWidth->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
261 propMgr.AddProperty( bestWidth, groupTeardrops );
262
263 auto maxWidth = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Width" ),
265 &BOARD_CONNECTED_ITEM::GetTeardropMaxWidth, PROPERTY_DISPLAY::PT_SIZE );
266 maxWidth->SetAvailableFunc( supportsTeardrops );
267 propMgr.AddProperty( maxWidth, groupTeardrops );
268
269 auto curvePts = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Curve Points" ),
272 curvePts->SetAvailableFunc( supportsTeardrops );
273 propMgr.AddProperty( curvePts, groupTeardrops );
274
275 auto preferZones = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Prefer Zone Connections" ),
278 preferZones->SetAvailableFunc( supportsTeardropPreferZoneSetting );
279 propMgr.AddProperty( preferZones, groupTeardrops );
280
281 auto twoTracks = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Allow Teardrops To Span Two Tracks" ),
284 twoTracks->SetAvailableFunc( supportsTeardrops );
285 propMgr.AddProperty( twoTracks, groupTeardrops );
286
287 auto maxTrackWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Max Width Ratio" ),
290 maxTrackWidth->SetAvailableFunc( supportsTeardrops );
291 propMgr.AddProperty( maxTrackWidth, groupTeardrops );
292 }
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
void SetTeardropAllowSpanTwoTracks(bool aAllow)
double GetTeardropBestWidthRatio() const
wxString GetNetClassName() const
Returns the name of the effective netclass.
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 SetTeardropCurvePts(int aPointCount)
void SetTeardropMaxWidth(int aMaxWidth)
wxString GetShortNetname() const
void SetTeardropPreferZoneConnections(bool aPrefer)
void SetTeardropBestLengthRatio(double aRatio)
void SetTeardropMaxLength(int aMaxLength)
bool GetTeardropAllowSpanTwoTracks() const
wxString GetUnescapedShortNetname() 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:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
virtual bool IsOnCopperLayer() const
Definition: board_item.h:151
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1810
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
wxString GetName() const
Definition: drc_rule.h:149
MINOPTMAX< int > & Value()
Definition: drc_rule.h:142
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
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:520
static LSET AllLayersMask()
Definition: lset.cpp:898
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:89
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
Definition: netclass.h:62
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 & GetUnescapedShortNetname() const
Definition: netinfo.h:124
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:342
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:383
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:47
#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:366
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