KiCad PCB EDA Suite
class_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 <fctsys.h>
31 #include <gr_basic.h>
32 #include <class_drawpanel.h>
33 #include <wxBasePcbFrame.h>
34 #include <common.h>
35 #include <kicad_string.h>
36 #include <pcbnew.h>
37 #include <colors_selection.h>
38 #include <richio.h>
39 #include <macros.h>
40 #include <msgpanel.h>
41 #include <base_units.h>
42 
43 #include <class_board.h>
44 #include <class_module.h>
45 #include <class_track.h>
46 
47 
48 /*********************************************************/
49 /* class NETINFO_ITEM: handle data relative to a given net */
50 /*********************************************************/
51 
52 NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
53  BOARD_ITEM( aParent, PCB_NETINFO_T ),
54  m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) )
55 {
56  m_parent = aParent;
57  m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
58  // general buffer of ratsnest
59  m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
60 
62 }
63 
64 
66 {
67  // m_NetClass is not owned by me.
68 }
69 
70 
75  wxDC* DC,
76  GR_DRAWMODE aDrawMode,
77  const wxPoint& aOffset )
78 {
79 }
80 
81 
82 void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
83 {
84  wxString txt;
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  aList.push_back( MSG_PANEL_ITEM( _( "Net Name" ), GetNetname(), RED ) );
89 
90  txt.Printf( wxT( "%d" ), GetNet() );
91  aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) );
92 
93  // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board
94  // can be NULL
95  BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
96 
97  if( board == NULL )
98  return;
99 
100  int count = 0;
101  for( MODULE* module = board->m_Modules; module != NULL; module = module->Next() )
102  {
103  for( D_PAD* pad = module->Pads(); pad != 0; pad = pad->Next() )
104  {
105  if( pad->GetNetCode() == GetNet() )
106  {
107  count++;
108  lengthPadToDie += pad->GetPadToDieLength();
109  }
110  }
111  }
112 
113  txt.Printf( wxT( "%d" ), count );
114  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
115 
116  count = 0;
117 
118  for( const TRACK *track = board->m_Track; track != NULL; track = track->Next() )
119  {
120  if( track->Type() == PCB_VIA_T )
121  {
122  if( track->GetNetCode() == GetNet() )
123  count++;
124  }
125 
126  if( track->Type() == PCB_TRACE_T )
127  {
128  if( track->GetNetCode() == GetNet() )
129  lengthnet += track->GetLength();
130  }
131  }
132 
133  txt.Printf( wxT( "%d" ), count );
134  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
135 
136  // Displays the full net length (tracks on pcb + internal ICs connections ):
137  txt = ::LengthDoubleToString( lengthnet + lengthPadToDie );
138  aList.push_back( MSG_PANEL_ITEM( _( "Net Length" ), txt, RED ) );
139 
140  // Displays the net length of tracks only:
141  txt = ::LengthDoubleToString( lengthnet );
142  aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
143 
144  // Displays the net length of internal ICs connections (wires inside ICs):
145  txt = ::LengthDoubleToString( lengthPadToDie );
146  aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
147 }
148 
149 
150 /***********************/
151 /* class RATSNEST_ITEM */
152 /***********************/
153 
155 {
156  m_NetCode = 0; // netcode ( = 1.. n , 0 is the value used for not
157  // connected items)
158  m_Status = 0; // state
159  m_PadStart = NULL; // pointer to the starting pad
160  m_PadEnd = NULL; // pointer to ending pad
161  m_Length = 0; // length of the line (temporary used in some
162  // calculations)
163 }
164 
165 
171  wxDC* DC,
172  GR_DRAWMODE aDrawMode,
173  const wxPoint& aOffset )
174 {
175  GRSetDrawMode( DC, aDrawMode );
176 
178 
179  GRLine( panel->GetClipBox(), DC,
180  m_PadStart->GetPosition() - aOffset,
181  m_PadEnd->GetPosition() - aOffset, 0, color );
182 }
Definition: colors.h:57
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
wxString m_NetClassName
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
Class BOARD to handle a board.
MODULE * Next() const
Definition: class_module.h:99
BOARD * m_parent
The parent board the net belongs to.
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo returns the information about the NETINFO_ITEM in aList to display in the me...
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
This file contains miscellaneous commonly used macros and functions.
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
D_PAD * m_PadEnd
Definition: class_netinfo.h:76
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset) override
Function Draw.
unsigned m_RatsnestStartIdx
Classes used in Pcbnew, CvPcb and GerbView.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset)
Function Draw.
static const char Default[]
the name of the default NETCLASS
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
D_PAD * Next() const
Definition: class_pad.h:106
EDA_RECT * GetClipBox()
wxString LengthDoubleToString(double aValue, bool aConvertToMils)
Function LengthDoubleToString is a helper to convert the double length aValue to a string in inches...
Definition: base_units.cpp:122
Definition: colors.h:60
int GetNet() const
Function GetNet.
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
NETINFO_ITEM(BOARD *aParent, const wxString &aNetName=wxEmptyString, int aNetCode=-1)
NETINFO_ITEM class, to handle info on nets: netnames, net constraints.
D_PAD * m_PadStart
Definition: class_netinfo.h:75
TRACK * Next() const
Definition: class_track.h:97
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
DLIST< MODULE > m_Modules
Definition: class_board.h:243
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:116
The common library.
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
DLIST< TRACK > m_Track
Definition: class_board.h:244
Module description (excepted pads)
const wxString & GetNetname() const
Function GetNetname.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Message panel definition file.
unsigned m_RatsnestEndIdx
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39