You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.8 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
14 years ago
  1. /**
  2. * @brief NETINFO_ITEM class, to handle info on nets: netnames, net constraints
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  8. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  9. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <class_drawpanel.h>
  31. #include <wxBasePcbFrame.h>
  32. #include <common.h>
  33. #include <kicad_string.h>
  34. #include <pcbnew.h>
  35. #include <colors_selection.h>
  36. #include <richio.h>
  37. #include <macros.h>
  38. #include <msgpanel.h>
  39. #include <base_units.h>
  40. #include <class_board.h>
  41. #include <class_module.h>
  42. #include <class_track.h>
  43. /*********************************************************/
  44. /* class NETINFO_ITEM: handle data relative to a given net */
  45. /*********************************************************/
  46. NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
  47. BOARD_ITEM( aParent, PCB_NETINFO_T ),
  48. m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) )
  49. {
  50. m_parent = aParent;
  51. m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
  52. // general buffer of ratsnest
  53. m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
  54. m_NetClassName = NETCLASS::Default;
  55. }
  56. NETINFO_ITEM::~NETINFO_ITEM()
  57. {
  58. // m_NetClass is not owned by me.
  59. }
  60. /**
  61. * Function Draw (TODO)
  62. */
  63. void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel,
  64. wxDC* DC,
  65. GR_DRAWMODE aDrawMode,
  66. const wxPoint& aOffset )
  67. {
  68. }
  69. void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  70. {
  71. wxString txt;
  72. double lengthnet = 0.0; // This is the length of tracks on pcb
  73. double lengthPadToDie = 0.0; // this is the length of internal ICs connections
  74. aList.push_back( MSG_PANEL_ITEM( _( "Net Name" ), GetNetname(), RED ) );
  75. txt.Printf( wxT( "%d" ), GetNet() );
  76. aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) );
  77. // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board
  78. // can be NULL
  79. BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
  80. if( board == NULL )
  81. return;
  82. int count = 0;
  83. for( MODULE* module = board->m_Modules; module != NULL; module = module->Next() )
  84. {
  85. for( D_PAD* pad = module->Pads(); pad != 0; pad = pad->Next() )
  86. {
  87. if( pad->GetNetCode() == GetNet() )
  88. {
  89. count++;
  90. lengthPadToDie += pad->GetPadToDieLength();
  91. }
  92. }
  93. }
  94. txt.Printf( wxT( "%d" ), count );
  95. aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
  96. count = 0;
  97. for( const TRACK *track = board->m_Track; track != NULL; track = track->Next() )
  98. {
  99. if( track->Type() == PCB_VIA_T )
  100. {
  101. if( track->GetNetCode() == GetNet() )
  102. count++;
  103. }
  104. if( track->Type() == PCB_TRACE_T )
  105. {
  106. if( track->GetNetCode() == GetNet() )
  107. lengthnet += track->GetLength();
  108. }
  109. }
  110. txt.Printf( wxT( "%d" ), count );
  111. aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
  112. // Displays the full net length (tracks on pcb + internal ICs connections ):
  113. txt = ::LengthDoubleToString( lengthnet + lengthPadToDie );
  114. aList.push_back( MSG_PANEL_ITEM( _( "Net Length" ), txt, RED ) );
  115. // Displays the net length of tracks only:
  116. txt = ::LengthDoubleToString( lengthnet );
  117. aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
  118. // Displays the net length of internal ICs connections (wires inside ICs):
  119. txt = ::LengthDoubleToString( lengthPadToDie );
  120. aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
  121. }
  122. /***********************/
  123. /* class RATSNEST_ITEM */
  124. /***********************/
  125. RATSNEST_ITEM::RATSNEST_ITEM()
  126. {
  127. m_NetCode = 0; // netcode ( = 1.. n , 0 is the value used for not
  128. // connected items)
  129. m_Status = 0; // state
  130. m_PadStart = NULL; // pointer to the starting pad
  131. m_PadEnd = NULL; // pointer to ending pad
  132. m_Length = 0; // length of the line (temporary used in some
  133. // calculations)
  134. }
  135. /**
  136. * Function Draw
  137. * Draws a line (a ratsnest) from the starting pad to the ending pad
  138. */
  139. void RATSNEST_ITEM::Draw( EDA_DRAW_PANEL* panel,
  140. wxDC* DC,
  141. GR_DRAWMODE aDrawMode,
  142. const wxPoint& aOffset )
  143. {
  144. GRSetDrawMode( DC, aDrawMode );
  145. EDA_COLOR_T color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
  146. GRLine( panel->GetClipBox(), DC,
  147. m_PadStart->GetPosition() - aOffset,
  148. m_PadEnd->GetPosition() - aOffset, 0, color );
  149. }