KiCad PCB EDA Suite
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, jean-pierre.charras@ujf-grenoble.fr
9  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
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>
35 #include <board_design_settings.h>
36 #include <footprint.h>
37 #include <pcb_track.h>
38 #include <pad.h>
39 
40 
41 NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
42  BOARD_ITEM( aParent, PCB_NETINFO_T ),
43  m_netCode( aNetCode ),
44  m_netname( aNetName ),
45  m_shortNetname( m_netname.AfterLast( '/' ) ),
46  m_isCurrent( true )
47 {
48  m_parent = aParent;
49 
50  if( aParent )
52  else
53  m_netClass = std::make_shared<NETCLASS>( "<invalid>" );
54 }
55 
56 
58 {
59  // m_NetClass is not owned by me.
60 }
61 
62 
63 void NETINFO_ITEM::SetNetClass( const NETCLASSPTR& aNetClass )
64 {
65  wxCHECK( m_parent, /* void */ );
66  m_netClass = aNetClass ? aNetClass : m_parent->GetDesignSettings().GetNetClasses().GetDefault();
67 }
68 
69 
70 void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
71 {
72  wxString msg;
73 
74  aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
75 
76  aList.emplace_back( _( "Net Code" ), wxString::Format( "%d", GetNetCode() ) );
77 
78  // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
79  BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
80 
81  if( board )
82  {
83  int count = 0;
84  PCB_TRACK* startTrack = nullptr;
85 
86  for( FOOTPRINT* footprint : board->Footprints() )
87  {
88  for( PAD* pad : footprint->Pads() )
89  {
90  if( pad->GetNetCode() == GetNetCode() )
91  count++;
92  }
93  }
94 
95  aList.emplace_back( _( "Pads" ), wxString::Format( "%d", count ) );
96 
97  count = 0;
98 
99  for( PCB_TRACK* track : board->Tracks() )
100  {
101  if( track->GetNetCode() == GetNetCode() )
102  {
103  if( track->Type() == PCB_VIA_T )
104  count++;
105  else if( !startTrack )
106  startTrack = track;
107  }
108  }
109 
110  aList.emplace_back( _( "Vias" ), wxString::Format( "%d", count ) );
111 
112  if( startTrack )
113  {
114  double lengthNet = 0.0; // This is the length of tracks on pcb
115  double lengthPadToDie = 0.0; // this is the length of internal ICs connections
116 
117  std::tie( count, lengthNet, lengthPadToDie ) = board->GetTrackLength( *startTrack );
118 
119  // Displays the full net length (tracks on pcb + internal ICs connections ):
120  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet + lengthPadToDie );
121  aList.emplace_back( _( "Net Length" ), msg );
122 
123  // Displays the net length of tracks only:
124  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet );
125  aList.emplace_back( _( "On Board" ), msg );
126 
127  // Displays the net length of internal ICs connections (wires inside ICs):
128  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
129  aList.emplace_back( _( "In Package" ), msg );
130  }
131  }
132 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
Implementation of conversion functions that require both schematic and board internal units.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:177
The base class for create windows for drawing purpose.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:589
Classes used in Pcbnew, CvPcb and GerbView.
NETCLASSPTR m_netClass
Definition: netinfo.h:171
FOOTPRINTS & Footprints()
Definition: board.h:233
const wxString & GetNetname() const
Definition: netinfo.h:119
#define _(s)
NETCLASSES & GetNetClasses() const
NETINFO_ITEM(BOARD *aParent, const wxString &aNetName=wxEmptyString, int aNetCode=-1)
NETINFO_ITEM class, to handle info on nets: netnames, net constraints.
wxString UnescapeString(const wxString &aSource)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:107
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:50
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
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.
Definition: pad.h:57
Message panel definition file.
void SetNetClass(const NETCLASSPTR &aNetClass)
TRACKS & Tracks()
Definition: board.h:230
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
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:1659
int GetNetCode() const
Definition: netinfo.h:113