KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netinfo_item.cpp
Go to the documentation of this file.
1
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 (C) 1992-2021 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 <pcb_base_frame.h>
31#include <string_utils.h>
32#include <widgets/msgpanel.h>
33#include <base_units.h>
34#include <board.h>
37#include <footprint.h>
38#include <pcb_track.h>
39#include <pad.h>
40
41
42NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
43 BOARD_ITEM( aParent, PCB_NETINFO_T ),
44 m_netCode( aNetCode ),
45 m_netname( aNetName ),
46 m_shortNetname( m_netname.AfterLast( '/' ) ),
47 m_unescapedShortNetname( UnescapeString( m_shortNetname ) ),
48 m_isCurrent( true )
49{
50 m_parent = aParent;
51
52 if( aParent )
53 m_netClass = aParent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
54 else
55 m_netClass = std::make_shared<NETCLASS>( wxT( "<invalid>" ) );
56}
57
58
60{
61 // m_NetClass is not owned by me.
62}
63
64
66{
67 wxCHECK( m_parent, /* void */ );
68 m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
69}
70
71
72void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
73{
74 wxCHECK( m_parent, /* void */ );
75
76 if( aNetClass )
77 m_netClass = aNetClass;
78 else
79 m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
80}
81
82
83void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
84{
85 wxString msg;
86
87 aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
88
89 aList.emplace_back( _( "Net Code" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
90
91 // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
92 BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
93
94 if( board )
95 {
96 int count = 0;
97 PCB_TRACK* startTrack = nullptr;
98
99 for( FOOTPRINT* footprint : board->Footprints() )
100 {
101 for( PAD* pad : footprint->Pads() )
102 {
103 if( pad->GetNetCode() == GetNetCode() )
104 count++;
105 }
106 }
107
108 aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), count ) );
109
110 count = 0;
111
112 for( PCB_TRACK* track : board->Tracks() )
113 {
114 if( track->GetNetCode() == GetNetCode() )
115 {
116 if( track->Type() == PCB_VIA_T )
117 count++;
118 else if( !startTrack )
119 startTrack = track;
120 }
121 }
122
123 aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), count ) );
124
125 if( startTrack )
126 {
127 double lengthNet = 0.0; // This is the length of tracks on pcb
128 double lengthPadToDie = 0.0; // this is the length of internal ICs connections
129
130 std::tie( count, lengthNet, lengthPadToDie ) = board->GetTrackLength( *startTrack );
131
132 // Displays the full net length (tracks on pcb + internal ICs connections ):
133 aList.emplace_back( _( "Net Length" ),
134 aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
135
136 // Displays the net length of tracks only:
137 aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
138
139 // Displays the net length of internal ICs connections (wires inside ICs):
140 aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
141 }
142 }
143}
144
145
146bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
147{
148 return BOARD_ITEM::Matches( GetNetname(), aSearchData );
149}
150
151
153{
154 std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
155 BOX2I bbox;
156
157 for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
158 PCB_ZONE_T, PCB_PAD_T } ) )
159 {
160 bbox.Merge( item->GetBoundingBox() );
161 }
162
163 return bbox;
164}
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
FOOTPRINTS & Footprints()
Definition: board.h:318
TRACKS & Tracks()
Definition: board.h:315
std::tuple< int, 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:2047
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:806
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:441
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:589
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:372
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
NETINFO_ITEM(BOARD *aParent, const wxString &aNetName=wxEmptyString, int aNetCode=-1)
NETINFO_ITEM class, to handle info on nets: netnames, net constraints.
const wxString & GetNetname() const
Definition: netinfo.h:114
void Clear()
Set all fields to their default values.
int GetNetCode() const
Definition: netinfo.h:108
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:192
std::shared_ptr< NETCLASS > m_netClass
Definition: netinfo.h:197
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.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:203
Definition: pad.h:59
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_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:109