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 The 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#include <api/board/board_types.pb.h>
36
37using namespace std::placeholders;
38
40 BOARD_ITEM( aParent, idtype ),
41 m_netinfo( NETINFO_LIST::OrphanedItem() )
42{
44}
45
46
47void BOARD_CONNECTED_ITEM::UnpackNet( const kiapi::board::types::Net& aProto )
48{
49 if( BOARD* board = GetBoard() )
50 {
51 wxString name = wxString::FromUTF8( aProto.name() );
52
53 if( NETINFO_ITEM* net = board->FindNet( name ) )
54 {
55 m_netinfo = net;
56 }
57 else
58 {
59 NETINFO_ITEM* newnet = new NETINFO_ITEM( board, name, 0 );
60 board->Add( newnet );
61 m_netinfo = newnet;
62 }
63 }
64}
65
66
67void BOARD_CONNECTED_ITEM::PackNet( kiapi::board::types::Net* aProto ) const
68{
69 aProto->set_name( GetNetname().ToUTF8() );
70}
71
72
73bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
74{
75 if( !IsOnCopperLayer() )
76 aNetCode = 0;
77
78 // if aNetCode < 0 (typically NETINFO_LIST::FORCE_ORPHANED) or no parent board,
79 // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
80
81 BOARD* board = GetBoard();
82
83 if( ( aNetCode >= 0 ) && board )
84 m_netinfo = board->FindNet( aNetCode );
85 else
87
88 if( !aNoAssert )
89 wxASSERT( m_netinfo );
90
91 return ( m_netinfo != nullptr );
92}
93
94
95int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
96{
97 DRC_CONSTRAINT constraint;
98
99 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
100 {
102
103 constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
104 }
105
106 if( constraint.Value().HasMin() )
107 {
108 if( aSource )
109 *aSource = constraint.GetName();
110
111 return constraint.Value().Min();
112 }
113
114 return 0;
115}
116
117
119{
120 return m_netinfo ? m_netinfo->GetNetCode() : -1;
121}
122
123
124// Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
125// std::shared_ptr stuff shows up large in performance profiling.
127{
129 return m_netinfo->GetNetClass();
130 else
131 return GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass().get();
132}
133
134
136{
137 return GetEffectiveNetClass()->GetName();
138}
139
140
142{
143 return m_netinfo ? m_netinfo->GetNetname() : wxString();
144}
145
146
148{
149 if( !GetBoard() )
150 return wxT( "[** NO BOARD DEFINED **]" );
151
152 wxString netname = GetNetname();
153
154 if( !netname.length() )
155 return wxT( "[<no net>]" );
156 else if( GetNetCode() < 0 )
157 return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
158 else
159 return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
160}
161
162
164{
165 static wxString emptyString;
166
168}
169
170
172{
173 static wxString emptyString;
174
175 if( !m_netinfo )
176 return emptyString;
177
178 if( const BOARD* board = GetBoard() )
179 {
180 if( board->GetNetInfo().m_DisplayNetnamesDirty )
181 board->GetNetInfo().RebuildDisplayNetnames();
182 }
183
185}
186
187
189{
191 {
193
194 if( layerEnum.Choices().GetCount() == 0 )
195 {
196 layerEnum.Undefined( UNDEFINED_LAYER );
197
198 for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
199 layerEnum.Map( layer, LSET::Name( layer ) );
200 }
201
205
206 // Replace layer property as the properties panel will set a restriction for copper layers
207 // only for BOARD_CONNECTED_ITEM that we don't want to apply to BOARD_ITEM
209 _HKI( "Layer" ),
211 layer->SetChoices( layerEnum.Choices() );
212 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
213
219
227 propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "Net Class" ),
228 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
233
234 // Compatibility alias for DRC engine
236 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
240
241 // Used only in DRC engine
243 NO_SETTER( BOARD_CONNECTED_ITEM, wxString ),
247
248 auto supportsTeardrops =
249 []( INSPECTABLE* aItem ) -> bool
250 {
251 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
252 {
253 if( !bci->GetBoard() || bci->GetBoard()->LegacyTeardrops() )
254 return false;
255
256 return bci->Type() == PCB_PAD_T || bci->Type() == PCB_VIA_T;
257 }
258
259 return false;
260 };
261
262 auto supportsTeardropPreferZoneSetting =
263 []( INSPECTABLE* aItem ) -> bool
264 {
265 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
266 {
267 if( !bci->GetBoard() || bci->GetBoard()->LegacyTeardrops() )
268 return false;
269
270 return bci->Type() == PCB_PAD_T;
271 }
272
273 return false;
274 };
275
276 const wxString groupTeardrops = _HKI( "Teardrops" );
277
278 auto enableTeardrops = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Enable Teardrops" ),
281 enableTeardrops->SetAvailableFunc( supportsTeardrops );
282 propMgr.AddProperty( enableTeardrops, groupTeardrops );
283
284 auto bestLength = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Length Ratio" ),
287 bestLength->SetAvailableFunc( supportsTeardrops );
288 bestLength->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
289 propMgr.AddProperty( bestLength, groupTeardrops );
290
291 auto maxLength = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Length" ),
293 &BOARD_CONNECTED_ITEM::GetTeardropMaxLength, PROPERTY_DISPLAY::PT_SIZE );
294 maxLength->SetAvailableFunc( supportsTeardrops );
295 propMgr.AddProperty( maxLength, groupTeardrops );
296
297 auto bestWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Best Width Ratio" ),
300 bestWidth->SetAvailableFunc( supportsTeardrops );
301 bestWidth->SetValidator( PROPERTY_VALIDATORS::PositiveRatioValidator );
302 propMgr.AddProperty( bestWidth, groupTeardrops );
303
304 auto maxWidth = new PROPERTY<BOARD_CONNECTED_ITEM, int>( _HKI( "Max Width" ),
306 &BOARD_CONNECTED_ITEM::GetTeardropMaxWidth, PROPERTY_DISPLAY::PT_SIZE );
307 maxWidth->SetAvailableFunc( supportsTeardrops );
308 propMgr.AddProperty( maxWidth, groupTeardrops );
309
310 auto curvePts = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Curved Teardrops" ),
313 curvePts->SetAvailableFunc( supportsTeardrops );
314 propMgr.AddProperty( curvePts, groupTeardrops );
315
316 auto preferZones = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Prefer Zone Connections" ),
319 preferZones->SetAvailableFunc( supportsTeardropPreferZoneSetting );
320 propMgr.AddProperty( preferZones, groupTeardrops );
321
322 auto twoTracks = new PROPERTY<BOARD_CONNECTED_ITEM, bool>( _HKI( "Allow Teardrops To Span Two Tracks" ),
325 twoTracks->SetAvailableFunc( supportsTeardrops );
326 propMgr.AddProperty( twoTracks, groupTeardrops );
327
328 auto maxTrackWidth = new PROPERTY<BOARD_CONNECTED_ITEM, double>( _HKI( "Max Width Ratio" ),
331 maxTrackWidth->SetAvailableFunc( supportsTeardrops );
332 propMgr.AddProperty( maxTrackWidth, groupTeardrops );
333 }
const char * name
Definition: DXF_plotter.cpp:62
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)
void PackNet(kiapi::board::types::Net *aProto) const
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)
void UnpackNet(const kiapi::board::types::Net &aProto)
Assigns a net to this item from an API message.
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:232
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:280
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:79
virtual bool IsOnCopperLayer() const
Definition: board_item.h:151
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2099
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:1024
wxString GetName() const
Definition: drc_rule.h:168
MINOPTMAX< int > & Value()
Definition: drc_rule.h:161
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:703
static ENUM_MAP< T > & Instance()
Definition: property.h:697
ENUM_MAP & Undefined(T aValue)
Definition: property.h:710
wxPGChoices & Choices()
Definition: property.h:746
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
static const LSET & AllLayersMask()
Definition: lset.cpp:624
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:188
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:45
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition: netclass.cpp:322
Handle the data for a net.
Definition: netinfo.h:56
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:315
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:322
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:329
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.
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:72
#define NO_SETTER(owner, type)
Definition: property.h:808
#define REGISTER_TYPE(x)
Definition: property_mgr.h:351
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