KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netinfo_item.cpp
Go to the documentation of this file.
1
4
5/*
6 * This program source code file is part of KiCad, a free EDA CAD application.
7 *
8 * Copyright (C) 2012 Jean-Pierre Charras, [email protected]
9 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
10 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, you may find one here:
24 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25 * or you may search the http://www.gnu.org website for the version 2 license,
26 * or you may write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 */
29
30#include "netinfo.h"
32
33#include <fmt/format.h>
34
35#include <pcb_base_frame.h>
36#include <string_utils.h>
37#include <widgets/msgpanel.h>
38#include <base_units.h>
39#include <board.h>
42#include <footprint.h>
43#include <pcb_track.h>
44#include <pad.h>
45
46
47NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
48 BOARD_ITEM( aParent, PCB_NETINFO_T ),
49 m_netCode( aNetCode ),
50 m_netname( aNetName ),
51 m_shortNetname( m_netname.AfterLast( '/' ) ),
53 m_netChain(),
54 m_isCurrent( true )
55{
56 m_parent = aParent;
57
58 m_terminalPads[0] = nullptr;
59 m_terminalPads[1] = nullptr;
62
63 if( aParent )
65 else
66 m_netClass = std::make_shared<NETCLASS>( wxT( "Default" ) );
67}
68
69
71{
72 // m_NetClass is not owned by me.
73}
74
75
77{
78 wxCHECK( m_parent, /* void */ );
79 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
80 m_netChain.clear();
81 m_terminalPads[0] = nullptr;
82 m_terminalPads[1] = nullptr;
85}
86
87
88void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
89{
90 wxCHECK( m_parent, /* void */ );
91
92 if( aNetClass )
93 m_netClass = aNetClass;
94 else
95 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
96}
97
98
100{
101 for( int i = 0; i < 2; ++i )
102 {
103 if( m_terminalPads[i] )
104 continue;
105
106 if( aBoard )
108 }
109}
110
111
112void NETINFO_ITEM::SetTerminal( int aIndex, PAD* aPad )
113{
114 m_terminalPads[aIndex] = aPad;
115 m_terminalPadUuids[aIndex] = aPad ? aPad->m_Uuid : niluuid;
116}
117
118
119void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
120{
121 aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
122
123 aList.emplace_back( _( "Net Code" ), fmt::format( "{}", GetNetCode() ) );
124
125 // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
126 BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
127
128 if( board )
129 {
130 int count = 0;
131 PCB_TRACK* startTrack = nullptr;
132
133 for( FOOTPRINT* footprint : board->Footprints() )
134 {
135 for( PAD* pad : footprint->Pads() )
136 {
137 if( pad->GetNetCode() == GetNetCode() )
138 count++;
139 }
140 }
141
142 aList.emplace_back( _( "Pads" ), fmt::format( "{}", count ) );
143
144 count = 0;
145
146 for( PCB_TRACK* track : board->Tracks() )
147 {
148 if( track->GetNetCode() == GetNetCode() )
149 {
150 if( track->Type() == PCB_VIA_T )
151 count++;
152 else if( !startTrack )
153 startTrack = track;
154 }
155 }
156
157 aList.emplace_back( _( "Vias" ), fmt::format( "{}", count ) );
158
159 if( startTrack )
160 {
161 double lengthNet = 0.0; // This is the length of tracks / vias on the pcb
162 double lengthPadToDie = 0.0; // This is the length of internal IC connections
163 double delayNet = 0.0; // This is the delay of tracks / vias on the pcb
164 double delayPadToDie = 0.0; // This is the delay of internal IC connections
165
166 std::tie( count, lengthNet, lengthPadToDie, delayNet, delayPadToDie ) =
167 board->GetTrackLength( *startTrack );
168
169 if( delayNet == 0.0 )
170 {
171 // Displays the full net length (tracks on pcb + internal ICs connections ):
172 aList.emplace_back( _( "Net Length" ), aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
173
174 // Displays the net length of tracks only:
175 aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
176
177 // Displays the net length of internal ICs connections (wires inside ICs):
178 aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
179 }
180 else
181 {
182 // Displays the full net length (tracks on pcb + internal ICs connections ):
183 aList.emplace_back( _( "Net Delay" ), aFrame->MessageTextFromValue( delayNet + delayPadToDie, true,
185
186 // Displays the net length of tracks only:
187 aList.emplace_back( _( "On Board" ),
188 aFrame->MessageTextFromValue( delayNet, true, EDA_DATA_TYPE::TIME ) );
189
190 // Displays the net length of internal ICs connections (wires inside ICs):
191 aList.emplace_back( _( "In Package" ),
192 aFrame->MessageTextFromValue( delayPadToDie, true, EDA_DATA_TYPE::TIME ) );
193 }
194 }
195 }
196}
197
198
199bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
200{
201 return BOARD_ITEM::Matches( GetNetname(), aSearchData );
202}
203
204
206{
207 static const std::vector<KICAD_T> netItemTypes = { PCB_TRACE_T,
208 PCB_ARC_T,
209 PCB_VIA_T,
211 PCB_PAD_T,
212 PCB_SHAPE_T };
213
214 std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
215 BOX2I bbox;
216
217 for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, netItemTypes ) )
218 bbox.Merge( item->GetBoundingBox() );
219
220 return bbox;
221}
222
223
225{
226 return m_shortNetname.StartsWith( wxT( "Net-(" ) )
227 || m_shortNetname.StartsWith( wxT( "unconnected-(" ) );
228}
229
230
231void NETINFO_ITEM::SetNetname( const wxString& aNewName )
232{
233 m_netname = aNewName;
234
235 if( aNewName.Contains( wxT( "/" ) ) )
236 m_shortNetname = aNewName.AfterLast( '/' );
237 else
238 m_shortNetname = aNewName;
239
241}
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
std::shared_ptr< NET_SETTINGS > m_NetSettings
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
friend class BOARD
Definition board_item.h:494
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
std::tuple< int, double, double, double, double > GetTrackLength(const PCB_TRACK &aTrack) const
Return data on the length and number of track segments connected to a given track.
Definition board.cpp:3187
PAD * FindPadByUuid(const KIID &aUuid) const
Definition board.cpp:2712
const FOOTPRINTS & Footprints() const
Definition board.h:364
const TRACKS & Tracks() const
Definition board.h:362
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1101
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:571
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:658
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:528
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:413
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
Definition netinfo.h:195
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
PAD * m_terminalPads[2]
Definition netinfo.h:204
NETINFO_ITEM(BOARD *aParent, const wxString &aNetName=wxEmptyString, int aNetCode=-1)
NETINFO_ITEM class, to handle info on nets: netnames, net constraints.
wxString m_displayNetname
Unescaped netname for display.
Definition netinfo.h:197
const wxString & GetNetname() const
Definition netinfo.h:103
void Clear()
Set all fields to their default values.
KIID m_terminalPadUuids[2]
Definition netinfo.h:205
int GetNetCode() const
Definition netinfo.h:97
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:193
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:207
void ResolveTerminalPads(BOARD *aBoard)
void SetTerminal(int aIndex, PAD *aPad)
Set the terminal-pad pointer and the persisted UUID at aIndex from a single pad, keeping the two view...
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Return the information about the NETINFO_ITEM in aList to display in the message panel.
bool HasAutoGeneratedNetname() const
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
Definition netinfo.h:194
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
bool m_isCurrent
Indicates the net is currently in use.
Definition netinfo.h:209
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:202
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:213
std::shared_ptr< NETCLASS > GetDefaultNetclass()
Gets the default netclass for the project.
Definition pad.h:55
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
#define _(s)
KIID niluuid(0)
Message panel definition file.
wxString UnescapeString(const wxString &aSource)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:85
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:94
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:105
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:84
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:95
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:107
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:93