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_displayNetname( UnescapeString( m_shortNetname ) ),
48 m_isCurrent( true )
49{
50 m_parent = aParent;
51
52 if( aParent )
53 m_netClass = aParent->GetDesignSettings().m_NetSettings->GetDefaultNetclass();
54 else
55 m_netClass = std::make_shared<NETCLASS>( wxT( "Default" ) );
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->GetDefaultNetclass();
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->GetDefaultNetclass();
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 static const std::vector<KICAD_T> netItemTypes = { PCB_TRACE_T,
155 PCB_ARC_T,
156 PCB_VIA_T,
158 PCB_PAD_T,
159 PCB_SHAPE_T };
160
161 std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
162 BOX2I bbox;
163
164 for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, netItemTypes ) )
165 bbox.Merge( item->GetBoundingBox() );
166
167 return bbox;
168}
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:79
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
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:2298
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:475
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:377
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:201
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:207
Definition: pad.h:54
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:107
@ 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:109
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96