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->m_DefaultNetClass.get();
105}
106
107
109{
110 return GetEffectiveNetClass()->GetName();
111}
112
113
115{
116 return m_netinfo ? m_netinfo->GetNetname() : wxString();
117}
118
119
121{
122 if( !GetBoard() )
123 return wxT( "[** NO BOARD DEFINED **]" );
124
125 wxString netname = GetNetname();
126
127 if( !netname.length() )
128 return wxT( "[<no net>]" );
129 else if( GetNetCode() < 0 )
130 return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
131 else
132 return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
133}
134
135
137{
138 static wxString emptyString;
139
141}
142
143
145{
146 static wxString emptyString;
147
148 if( !m_netinfo )
149 return emptyString;
150
151 if( const BOARD* board = GetBoard() )
152 {
153 if( board->GetNetInfo().m_DisplayNetnamesDirty )
154 board->GetNetInfo().RebuildDisplayNetnames();
155 }
156
158}
159
160
162{
164 {
166
167 if( layerEnum.Choices().GetCount() == 0 )
168 {
169 layerEnum.Undefined( UNDEFINED_LAYER );
170
171 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
172 layerEnum.Map( layer, LSET::Name( layer ) );
173 }
174
178
179 // Replace layer property as the properties panel will set a restriction for copper layers
180 // only for BOARD_CONNECTED_ITEM that we don't want to apply to BOARD_ITEM
182 _HKI( "Layer" ),
184 layer->SetChoices( layerEnum.Choices() );
185 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
186
192
200 propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "Net Class" ),
201 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
206
207 // Compatibility alias for DRC engine
209 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
213
214 // Used only in DRC engine
216 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
220
221 auto supportsTeardrops =
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 || bci->Type() == PCB_VIA_T;
230 }
231
232 return false;
233 };
234
235 auto supportsTeardropPreferZoneSetting =
236 []( INSPECTABLE* aItem ) -> bool
237 {
238 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
239 {
240 if( bci->GetBoard()->LegacyTeardrops() )
241 return false;
242
243 return bci->Type() == PCB_PAD_T;
244 }
245
246 return false;
247 };
248
249 const wxString groupTeardrops = _HKI( "Teardrops" );
250
251 auto enableTeardrops = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Enable Teardrops" ),
254 enableTeardrops->SetAvailableFunc( supportsTeardrops );
255 propMgr.AddProperty( enableTeardrops, groupTeardrops );
256
257 auto bestLength = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Length Ratio" ),
260 bestLength->SetAvailableFunc( supportsTeardrops );
261 bestLength->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
262 propMgr.AddProperty( bestLength, groupTeardrops );
263
264 auto maxLength = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Length" ),
266 &BOARD_CONNECTED_ITEM::GetTeardropMaxLength, PROPERTY_DISPLAY::PT_SIZE );
267 maxLength->SetAvailableFunc( supportsTeardrops );
268 propMgr.AddProperty( maxLength, groupTeardrops );
269
270 auto bestWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Width Ratio" ),
273 bestWidth->SetAvailableFunc( supportsTeardrops );
274 bestWidth->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
275 propMgr.AddProperty( bestWidth, groupTeardrops );
276
277 auto maxWidth = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Width" ),
279 &BOARD_CONNECTED_ITEM::GetTeardropMaxWidth, PROPERTY_DISPLAY::PT_SIZE );
280 maxWidth->SetAvailableFunc( supportsTeardrops );
281 propMgr.AddProperty( maxWidth, groupTeardrops );
282
283 auto curvePts = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Curved Teardrops" ),
286 curvePts->SetAvailableFunc( supportsTeardrops );
287 propMgr.AddProperty( curvePts, groupTeardrops );
288
289 auto preferZones = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Prefer Zone Connections" ),
292 preferZones->SetAvailableFunc( supportsTeardropPreferZoneSetting );
293 propMgr.AddProperty( preferZones, groupTeardrops );
294
295 auto twoTracks = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Allow Teardrops To Span Two Tracks" ),
298 twoTracks->SetAvailableFunc( supportsTeardrops );
299 propMgr.AddProperty( twoTracks, groupTeardrops );
300
301 auto maxTrackWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Max Width Ratio" ),
304 maxTrackWidth->SetAvailableFunc( supportsTeardrops );
305 propMgr.AddProperty( maxTrackWidth, groupTeardrops );
306 }
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)
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:240
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:276
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:153
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1901
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:875
wxString GetName() const
Definition: drc_rule.h:150
MINOPTMAX< int > & Value()
Definition: drc_rule.h:143
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:768
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:64
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 & 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:48
#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