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 <track.h>
36 
37 
38 /*********************************************************/
39 /* class NETINFO_ITEM: handle data relative to a given net */
40 /*********************************************************/
41 
42 NETINFO_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_isCurrent( true )
48 {
49  m_parent = aParent;
50 
51  if( aParent )
53  else
54  m_netClass = std::make_shared<NETCLASS>( "<invalid>" );
55 }
56 
57 
59 {
60  // m_NetClass is not owned by me.
61 }
62 
63 
64 void NETINFO_ITEM::SetNetClass( const NETCLASSPTR& aNetClass )
65 {
66  wxCHECK( m_parent, /* void */ );
67  m_netClass = aNetClass ? aNetClass : m_parent->GetDesignSettings().GetNetClasses().GetDefault();
68 }
69 
70 
71 void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
72 {
73  wxString msg;
74 
75  aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
76 
77  aList.emplace_back( _( "Net Code" ), wxString::Format( "%d", GetNetCode() ) );
78 
79  // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
80  BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
81 
82  if( board )
83  {
84  int count = 0;
85  double lengthNet = 0.0; // This is the length of tracks on pcb
86  double lengthPadToDie = 0.0; // this is the length of internal ICs connections
87 
88  for( FOOTPRINT* footprint : board->Footprints() )
89  {
90  for( PAD* pad : footprint->Pads() )
91  {
92  if( pad->GetNetCode() == GetNetCode() )
93  {
94  count++;
95  lengthPadToDie += pad->GetPadToDieLength();
96  }
97  }
98  }
99 
100  aList.emplace_back( _( "Pads" ), wxString::Format( "%d", count ) );
101 
102  count = 0;
103 
104  for( TRACK* track : board->Tracks() )
105  {
106  if( track->Type() == PCB_VIA_T )
107  {
108  if( track->GetNetCode() == GetNetCode() )
109  count++;
110  }
111 
112  if( track->Type() == PCB_TRACE_T )
113  {
114  if( track->GetNetCode() == GetNetCode() )
115  lengthNet += track->GetLength();
116  }
117  }
118 
119  aList.emplace_back( _( "Vias" ), wxString::Format( "%d", count ) );
120 
121  // Displays the full net length (tracks on pcb + internal ICs connections ):
122  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet + lengthPadToDie );
123  aList.emplace_back( _( "Net Length" ), msg );
124 
125  // Displays the net length of tracks only:
126  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet );
127  aList.emplace_back( _( "On Board" ), msg );
128 
129  // Displays the net length of internal ICs connections (wires inside ICs):
130  msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
131  aList.emplace_back( _( "In Package" ), msg );
132  }
133 }
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:125
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:82
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:591
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:177
The base class for create windows for drawing purpose.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
Classes used in Pcbnew, CvPcb and GerbView.
NETCLASSPTR m_netClass
Definition: netinfo.h:171
#define NULL
FOOTPRINTS & Footprints()
Definition: board.h:303
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
const wxString & GetNetname() const
Definition: netinfo.h:119
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
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:150
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:107
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
class 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:60
Message panel definition file.
void SetNetClass(const NETCLASSPTR &aNetClass)
TRACKS & Tracks()
Definition: board.h:300
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Definition: track.h:83
int GetNetCode() const
Definition: netinfo.h:113