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 <class_board.h>
35 #include <class_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_isCurrent( true ),
46  m_Netname( aNetName ),
47  m_ShortNetname( m_Netname.AfterLast( '/' ) )
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::SetClass( 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 txt;
74  double lengthnet = 0.0; // This is the length of tracks on pcb
75  double lengthPadToDie = 0.0; // this is the length of internal ICs connections
76 
77  aList.emplace_back( _( "Net Name" ), GetNetname(), RED );
78 
79  txt.Printf( wxT( "%d" ), GetNet() );
80  aList.emplace_back( _( "Net Code" ), txt, RED );
81 
82  // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board
83  // can be NULL
84  BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
85 
86  if( board == NULL )
87  return;
88 
89  int count = 0;
90 
91  for( MODULE* mod : board->Modules() )
92  {
93  for( D_PAD* pad : mod->Pads() )
94  {
95  if( pad->GetNetCode() == GetNet() )
96  {
97  count++;
98  lengthPadToDie += pad->GetPadToDieLength();
99  }
100  }
101  }
102 
103  txt.Printf( wxT( "%d" ), count );
104  aList.emplace_back( _( "Pads" ), txt, DARKGREEN );
105 
106  count = 0;
107 
108  for( TRACK* track : board->Tracks() )
109  {
110  if( track->Type() == PCB_VIA_T )
111  {
112  if( track->GetNetCode() == GetNet() )
113  count++;
114  }
115 
116  if( track->Type() == PCB_TRACE_T )
117  {
118  if( track->GetNetCode() == GetNet() )
119  lengthnet += track->GetLength();
120  }
121  }
122 
123  txt.Printf( wxT( "%d" ), count );
124  aList.emplace_back( _( "Vias" ), txt, BLUE );
125 
126  // Displays the full net length (tracks on pcb + internal ICs connections ):
127  txt = MessageTextFromValue( aFrame->GetUserUnits(), lengthnet + lengthPadToDie );
128  aList.emplace_back( _( "Net Length" ), txt, RED );
129 
130  // Displays the net length of tracks only:
131  txt = MessageTextFromValue( aFrame->GetUserUnits(), lengthnet );
132  aList.emplace_back( _( "On Board" ), txt, RED );
133 
134  // Displays the net length of internal ICs connections (wires inside ICs):
135  txt = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
136  aList.emplace_back( _( "In Package" ), txt, RED );
137 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Definition: base_units.cpp:123
NETCLASSPTR m_NetClass
Definition: netinfo.h:81
Implementation of conversion functions that require both schematic and board internal units.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
BOARD * m_parent
The parent board the net belongs to.
Definition: netinfo.h:83
The base class for create windows for drawing purpose.
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
Classes used in Pcbnew, CvPcb and GerbView.
#define NULL
MODULES & Modules()
Definition: class_board.h:284
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
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.
Definition: color4d.h:60
Definition: color4d.h:57
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:108
void SetClass(const NETCLASSPTR &aNetClass)
Function SetClass sets aNetclass into this NET.
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:266
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo returns the information about the NETINFO_ITEM in aList to display in the me...
Message panel definition file.
TRACKS & Tracks()
Definition: class_board.h:281
EDA_UNITS GetUserUnits() const
Return the user units currently in use.