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 <string_utils.h>
31#include <i18n_utility.h>
32#include <netinfo.h>
33
34using namespace std::placeholders;
35
37 BOARD_ITEM( aParent, idtype ),
38 m_netinfo( NETINFO_LIST::OrphanedItem() )
39{
41}
42
43
44bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
45{
46 if( !IsOnCopperLayer() )
47 aNetCode = 0;
48
49 // if aNetCode < 0 (typically NETINFO_LIST::FORCE_ORPHANED) or no parent board,
50 // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
51
52 BOARD* board = GetBoard();
53
54 if( ( aNetCode >= 0 ) && board )
55 m_netinfo = board->FindNet( aNetCode );
56 else
58
59 if( !aNoAssert )
60 wxASSERT( m_netinfo );
61
62 return ( m_netinfo != nullptr );
63}
64
65
66int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
67{
68 DRC_CONSTRAINT constraint;
69
70 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
71 {
73
74 constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
75 }
76
77 if( constraint.Value().HasMin() )
78 {
79 if( aSource )
80 *aSource = constraint.GetName();
81
82 return constraint.Value().Min();
83 }
84
85 return 0;
86}
87
88
90{
91 return m_netinfo ? m_netinfo->GetNetCode() : -1;
92}
93
94
95// Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
96// std::shared_ptr stuff shows up large in performance profiling.
98{
100 return m_netinfo->GetNetClass();
101 else
102 return GetBoard()->GetDesignSettings().m_NetSettings->m_DefaultNetClass.get();
103}
104
105
107{
108 return GetEffectiveNetClass()->GetName();
109}
110
111
113{
114 return m_netinfo ? m_netinfo->GetNetname() : wxString();
115}
116
117
119{
120 if( !GetBoard() )
121 return wxT( "[** NO BOARD DEFINED **]" );
122
123 wxString netname = GetNetname();
124
125 if( !netname.length() )
126 return wxT( "[<no net>]" );
127 else if( GetNetCode() < 0 )
128 return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
129 else
130 return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
131}
132
133
135{
136 return m_netinfo ? m_netinfo->GetShortNetname() : wxString();
137}
138
139
141{
142 return m_netinfo ? m_netinfo->GetUnescapedShortNetname() : wxString();
143}
144
145
147{
149 {
151
152 if( layerEnum.Choices().GetCount() == 0 )
153 {
154 layerEnum.Undefined( UNDEFINED_LAYER );
155
156 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
157 layerEnum.Map( *seq, LSET::Name( *seq ) );
158 }
159
163
164 // Replace layer property as the properties panel will set a restriction for copper layers
165 // only for BOARD_CONNECTED_ITEM that we don't want to apply to BOARD_ITEM
167 _HKI( "Layer" ),
169 layer->SetChoices( layerEnum.Choices() );
170 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
171
172 // Not really deprecated, but hidden from rule editor suggestions
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 propMgr.AddProperty( bestLength, groupTeardrops );
248
249 auto maxLength = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Length" ),
251 &BOARD_CONNECTED_ITEM::GetTeardropMaxLength, PROPERTY_DISPLAY::PT_SIZE );
252 maxLength->SetAvailableFunc( supportsTeardrops );
253 propMgr.AddProperty( maxLength, groupTeardrops );
254
255 auto bestWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Width Ratio" ),
258 bestWidth->SetAvailableFunc( supportsTeardrops );
259 propMgr.AddProperty( bestWidth, groupTeardrops );
260
261 auto maxWidth = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Width" ),
263 &BOARD_CONNECTED_ITEM::GetTeardropMaxWidth, PROPERTY_DISPLAY::PT_SIZE );
264 maxWidth->SetAvailableFunc( supportsTeardrops );
265 propMgr.AddProperty( maxWidth, groupTeardrops );
266
267 auto curvePts = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Curve Points" ),
270 curvePts->SetAvailableFunc( supportsTeardrops );
271 propMgr.AddProperty( curvePts, groupTeardrops );
272
273 auto preferZones = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Prefer zone connections" ),
276 preferZones->SetAvailableFunc( supportsTeardropPreferZoneSetting );
277 propMgr.AddProperty( preferZones, groupTeardrops );
278
279 auto twoTracks = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Allow teardrops to span two tracks" ),
282 twoTracks->SetAvailableFunc( supportsTeardrops );
283 propMgr.AddProperty( twoTracks, groupTeardrops );
284
285 auto maxTrackWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Max Width Ratio" ),
288 maxTrackWidth->SetAvailableFunc( supportsTeardrops );
289 propMgr.AddProperty( maxTrackWidth, groupTeardrops );
290 }
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:71
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:196
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:230
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:44
virtual bool IsOnCopperLayer() const
Definition: board_item.h:136
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1533
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:728
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:633
static ENUM_MAP< T > & Instance()
Definition: property.h:627
ENUM_MAP & Undefined(T aValue)
Definition: property.h:640
wxPGChoices & Choices()
Definition: property.h:676
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:497
static LSET AllLayersMask()
Definition: lset.cpp:808
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
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:47
const wxString GetName() const
Definition: netclass.h:65
const wxString & GetShortNetname() const
Definition: netinfo.h:130
const wxString & GetNetname() const
Definition: netinfo.h:125
NETCLASS * GetNetClass()
Definition: netinfo.h:112
int GetNetCode() const
Definition: netinfo.h:119
const wxString & GetUnescapedShortNetname() const
Definition: netinfo.h:135
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:338
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:395
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:284
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:291
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:298
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:74
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:76
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.
#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:59
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
#define TYPE_HASH(x)
Definition: property.h:63
#define NO_SETTER(owner, type)
Definition: property.h:738
#define REGISTER_TYPE(x)
Definition: property_mgr.h:328
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:93
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87