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-2012 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 <kicad_string.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 /*********************************************************/
42 /* class NETINFO_ITEM: handle data relative to a given net */
43 /*********************************************************/
44 
45 NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
46  BOARD_ITEM( aParent, PCB_NETINFO_T ),
47  m_netCode( aNetCode ),
48  m_netname( aNetName ),
49  m_shortNetname( m_netname.AfterLast( '/' ) ),
50  m_isCurrent( true )
51 {
52  m_parent = aParent;
53 
54  if( aParent )
56  else
57  m_netClass = std::make_shared<NETCLASS>( "<invalid>" );
58 }
59 
60 
62 {
63  // m_NetClass is not owned by me.
64 }
65 
66 
67 void NETINFO_ITEM::SetNetClass( const NETCLASSPTR& aNetClass )
68 {
69  wxCHECK( m_parent, /* void */ );
70  m_netClass = aNetClass ? aNetClass : m_parent->GetDesignSettings().GetNetClasses().GetDefault();
71 }
72 
73 
74 void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
75 {
76  wxString msg;
77 
78  aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
79 
80  aList.emplace_back( _( "Net Code" ), wxString::Format( "%d", GetNetCode() ) );
81 
82  // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
83  BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
84 
85  if( board )
86  {
87  int count = 0;
88  PCB_TRACK* startTrack = nullptr;
89 
90  for( FOOTPRINT* footprint : board->Footprints() )
91  {
92  for( PAD* pad : footprint->Pads() )
93  {
94  if( pad->GetNetCode() == GetNetCode() )
95  count++;
96  }
97  }
98 
99  aList.emplace_back( _( "Pads" ), wxString::Format( "%d", count ) );
100 
101  count = 0;
102 
103  for( PCB_TRACK* track : board->Tracks() )
104  {
105  if( track->GetNetCode() == GetNetCode() )
106  {
107  if( track->Type() == PCB_VIA_T )
108  count++;
109  else if( !startTrack )
110  startTrack = track;
111  }
112  }
113 
114  aList.emplace_back( _( "Vias" ), wxString::Format( "%d", count ) );
115 
116  if( startTrack )
117  {
118  double lengthNet = 0.0; // This is the length of tracks on pcb
119  double lengthPadToDie = 0.0; // this is the length of internal ICs connections
120 
121  std::tie( count, lengthNet, lengthPadToDie ) = board->GetTrackLength( *startTrack );
122 
123  // Displays the full net length (tracks on pcb + internal ICs connections ):
124  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet + lengthPadToDie );
125  aList.emplace_back( _( "Net Length" ), msg );
126 
127  // Displays the net length of tracks only:
128  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet );
129  aList.emplace_back( _( "On Board" ), msg );
130 
131  // Displays the net length of internal ICs connections (wires inside ICs):
132  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
133  aList.emplace_back( _( "In Package" ), msg );
134  }
135  }
136 }
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:103
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:588
Classes used in Pcbnew, CvPcb and GerbView.
NETCLASSPTR m_netClass
Definition: netinfo.h:171
#define NULL
FOOTPRINTS & Footprints()
Definition: board.h:233
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:50
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.
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
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:214
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:107
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
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:1737
int GetNetCode() const
Definition: netinfo.h:113