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, see <https://www.gnu.org/licenses/>.
24 */
25
26#include "netinfo.h"
28
29#include <fmt/format.h>
30
31#include <pcb_base_frame.h>
32#include <string_utils.h>
33#include <widgets/msgpanel.h>
34#include <base_units.h>
35#include <board.h>
38#include <footprint.h>
39#include <pcb_track.h>
40#include <pad.h>
41
42
43NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
44 BOARD_ITEM( aParent, PCB_NETINFO_T ),
45 m_netCode( aNetCode ),
46 m_netname( aNetName ),
47 m_shortNetname( m_netname.AfterLast( '/' ) ),
49 m_netChain(),
50 m_isCurrent( true )
51{
52 m_parent = aParent;
53
54 m_terminalPads[0] = nullptr;
55 m_terminalPads[1] = nullptr;
58
59 if( aParent )
61 else
62 m_netClass = std::make_shared<NETCLASS>( wxT( "Default" ) );
63}
64
65
67{
68 // m_NetClass is not owned by me.
69}
70
71
73{
74 wxCHECK( m_parent, /* void */ );
75 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
76 m_netChain.clear();
77 m_terminalPads[0] = nullptr;
78 m_terminalPads[1] = nullptr;
81}
82
83
84void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
85{
86 wxCHECK( m_parent, /* void */ );
87
88 if( aNetClass )
89 m_netClass = aNetClass;
90 else
91 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
92}
93
94
96{
97 for( int i = 0; i < 2; ++i )
98 {
99 if( m_terminalPads[i] )
100 continue;
101
102 if( aBoard )
104 }
105}
106
107
108void NETINFO_ITEM::SetTerminal( int aIndex, PAD* aPad )
109{
110 m_terminalPads[aIndex] = aPad;
111 m_terminalPadUuids[aIndex] = aPad ? aPad->m_Uuid : niluuid;
112}
113
114
115void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
116{
117 aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
118
119 aList.emplace_back( _( "Net Code" ), fmt::format( "{}", GetNetCode() ) );
120
121 // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
122 BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
123
124 if( board )
125 {
126 int count = 0;
127 PCB_TRACK* startTrack = nullptr;
128
129 for( FOOTPRINT* footprint : board->Footprints() )
130 {
131 for( PAD* pad : footprint->Pads() )
132 {
133 if( pad->GetNetCode() == GetNetCode() )
134 count++;
135 }
136 }
137
138 aList.emplace_back( _( "Pads" ), fmt::format( "{}", count ) );
139
140 count = 0;
141
142 for( PCB_TRACK* track : board->Tracks() )
143 {
144 if( track->GetNetCode() == GetNetCode() )
145 {
146 if( track->Type() == PCB_VIA_T )
147 count++;
148 else if( !startTrack )
149 startTrack = track;
150 }
151 }
152
153 aList.emplace_back( _( "Vias" ), fmt::format( "{}", count ) );
154
155 if( startTrack )
156 {
157 double lengthNet = 0.0; // This is the length of tracks / vias on the pcb
158 double lengthPadToDie = 0.0; // This is the length of internal IC connections
159 double delayNet = 0.0; // This is the delay of tracks / vias on the pcb
160 double delayPadToDie = 0.0; // This is the delay of internal IC connections
161
162 std::tie( count, lengthNet, lengthPadToDie, delayNet, delayPadToDie ) =
163 board->GetTrackLength( *startTrack );
164
165 if( delayNet == 0.0 )
166 {
167 // Displays the full net length (tracks on pcb + internal ICs connections ):
168 aList.emplace_back( _( "Net Length" ), aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
169
170 // Displays the net length of tracks only:
171 aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
172
173 // Displays the net length of internal ICs connections (wires inside ICs):
174 aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
175 }
176 else
177 {
178 // Displays the full net length (tracks on pcb + internal ICs connections ):
179 aList.emplace_back( _( "Net Delay" ), aFrame->MessageTextFromValue( delayNet + delayPadToDie, true,
181
182 // Displays the net length of tracks only:
183 aList.emplace_back( _( "On Board" ),
184 aFrame->MessageTextFromValue( delayNet, true, EDA_DATA_TYPE::TIME ) );
185
186 // Displays the net length of internal ICs connections (wires inside ICs):
187 aList.emplace_back( _( "In Package" ),
188 aFrame->MessageTextFromValue( delayPadToDie, true, EDA_DATA_TYPE::TIME ) );
189 }
190 }
191 }
192}
193
194
195bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
196{
197 return BOARD_ITEM::Matches( GetNetname(), aSearchData );
198}
199
200
202{
203 static const std::vector<KICAD_T> netItemTypes = { PCB_TRACE_T,
204 PCB_ARC_T,
205 PCB_VIA_T,
207 PCB_PAD_T,
208 PCB_SHAPE_T };
209
210 std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
211 BOX2I bbox;
212
213 for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, netItemTypes ) )
214 bbox.Merge( item->GetBoundingBox() );
215
216 return bbox;
217}
218
219
221{
222 return m_shortNetname.StartsWith( wxT( "Net-(" ) )
223 || m_shortNetname.StartsWith( wxT( "unconnected-(" ) );
224}
225
226
227void NETINFO_ITEM::SetNetname( const wxString& aNewName )
228{
229 m_netname = aNewName;
230
231 if( aNewName.Contains( wxT( "/" ) ) )
232 m_shortNetname = aNewName.AfterLast( '/' );
233 else
234 m_shortNetname = aNewName;
235
237}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
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:83
friend class BOARD
Definition board_item.h:512
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:3238
PAD * FindPadByUuid(const KIID &aUuid) const
Definition board.cpp:2763
const FOOTPRINTS & Footprints() const
Definition board.h:420
const TRACKS & Tracks() const
Definition board.h:418
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:634
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:654
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:531
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:416
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:192
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:201
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:194
const wxString & GetNetname() const
Definition netinfo.h:100
void Clear()
Set all fields to their default values.
KIID m_terminalPadUuids[2]
Definition netinfo.h:202
int GetNetCode() const
Definition netinfo.h:94
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:190
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:204
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:191
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:206
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
wxString m_netChain
Definition netinfo.h:199
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:210
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
Definition pad.h:61
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:81
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:101
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89