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_isCurrent( true )
54{
55 m_parent = aParent;
56
57 if( aParent )
59 else
60 m_netClass = std::make_shared<NETCLASS>( wxT( "Default" ) );
61}
62
63
65{
66 // m_NetClass is not owned by me.
67}
68
69
71{
72 wxCHECK( m_parent, /* void */ );
73 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
74}
75
76
77void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
78{
79 wxCHECK( m_parent, /* void */ );
80
81 if( aNetClass )
82 m_netClass = aNetClass;
83 else
84 m_netClass = m_parent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
85}
86
87
88void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
89{
90 aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
91
92 aList.emplace_back( _( "Net Code" ), fmt::format( "{}", GetNetCode() ) );
93
94 // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
95 BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
96
97 if( board )
98 {
99 int count = 0;
100 PCB_TRACK* startTrack = nullptr;
101
102 for( FOOTPRINT* footprint : board->Footprints() )
103 {
104 for( PAD* pad : footprint->Pads() )
105 {
106 if( pad->GetNetCode() == GetNetCode() )
107 count++;
108 }
109 }
110
111 aList.emplace_back( _( "Pads" ), fmt::format( "{}", count ) );
112
113 count = 0;
114
115 for( PCB_TRACK* track : board->Tracks() )
116 {
117 if( track->GetNetCode() == GetNetCode() )
118 {
119 if( track->Type() == PCB_VIA_T )
120 count++;
121 else if( !startTrack )
122 startTrack = track;
123 }
124 }
125
126 aList.emplace_back( _( "Vias" ), fmt::format( "{}", count ) );
127
128 if( startTrack )
129 {
130 double lengthNet = 0.0; // This is the length of tracks / vias on the pcb
131 double lengthPadToDie = 0.0; // This is the length of internal IC connections
132 double delayNet = 0.0; // This is the delay of tracks / vias on the pcb
133 double delayPadToDie = 0.0; // This is the delay of internal IC connections
134
135 std::tie( count, lengthNet, lengthPadToDie, delayNet, delayPadToDie ) =
136 board->GetTrackLength( *startTrack );
137
138 if( delayNet == 0.0 )
139 {
140 // Displays the full net length (tracks on pcb + internal ICs connections ):
141 aList.emplace_back( _( "Net Length" ), aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
142
143 // Displays the net length of tracks only:
144 aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
145
146 // Displays the net length of internal ICs connections (wires inside ICs):
147 aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
148 }
149 else
150 {
151 // Displays the full net length (tracks on pcb + internal ICs connections ):
152 aList.emplace_back( _( "Net Delay" ), aFrame->MessageTextFromValue( delayNet + delayPadToDie, true,
154
155 // Displays the net length of tracks only:
156 aList.emplace_back( _( "On Board" ),
157 aFrame->MessageTextFromValue( delayNet, true, EDA_DATA_TYPE::TIME ) );
158
159 // Displays the net length of internal ICs connections (wires inside ICs):
160 aList.emplace_back( _( "In Package" ),
161 aFrame->MessageTextFromValue( delayPadToDie, true, EDA_DATA_TYPE::TIME ) );
162 }
163 }
164 }
165}
166
167
168bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
169{
170 return BOARD_ITEM::Matches( GetNetname(), aSearchData );
171}
172
173
175{
176 static const std::vector<KICAD_T> netItemTypes = { PCB_TRACE_T,
177 PCB_ARC_T,
178 PCB_VIA_T,
180 PCB_PAD_T,
181 PCB_SHAPE_T };
182
183 std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
184 BOX2I bbox;
185
186 for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, netItemTypes ) )
187 bbox.Merge( item->GetBoundingBox() );
188
189 return bbox;
190}
191
192
194{
195 return m_shortNetname.StartsWith( wxT( "Net-(" ) )
196 || m_shortNetname.StartsWith( wxT( "unconnected-(" ) );
197}
198
199
200void NETINFO_ITEM::SetNetname( const wxString& aNewName )
201{
202 m_netname = aNewName;
203
204 if( aNewName.Contains( wxT( "/" ) ) )
205 m_shortNetname = aNewName.AfterLast( '/' );
206 else
207 m_shortNetname = aNewName;
208
210}
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
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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:2911
const FOOTPRINTS & Footprints() const
Definition board.h:363
const TRACKS & Tracks() const
Definition board.h:361
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1082
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:563
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.
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:407
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:178
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
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:180
const wxString & GetNetname() const
Definition netinfo.h:112
void Clear()
Set all fields to their default values.
int GetNetCode() const
Definition netinfo.h:106
int m_netCode
A number equivalent to the net name.
Definition netinfo.h:176
std::shared_ptr< NETCLASS > m_netClass
Definition netinfo.h:185
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:177
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:187
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
BOARD * m_parent
The parent board the net belongs to.
Definition netinfo.h:191
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)
Message panel definition file.
wxString UnescapeString(const wxString &aSource)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:108
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:110
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96