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.

202 lines
6.0 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
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_ITEM* aParent, const wxString& aNetName, int aNetCode )
  47. {
  48. SetNet( aNetCode );
  49. if( aNetName.size() )
  50. SetNetname( aNetName );
  51. m_parent = aParent;
  52. m_NbNodes = 0;
  53. m_NbLink = 0;
  54. m_NbNoconn = 0;
  55. m_Flag = 0;
  56. m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
  57. // general buffer of ratsnest
  58. m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
  59. m_NetClassName = NETCLASS::Default;
  60. m_NetClass = 0;
  61. }
  62. NETINFO_ITEM::~NETINFO_ITEM()
  63. {
  64. // m_NetClass is not owned by me.
  65. }
  66. /**
  67. * Function SetNetname
  68. * @param aNetname : the new netname
  69. */
  70. void NETINFO_ITEM::SetNetname( const wxString& aNetname )
  71. {
  72. m_Netname = aNetname;
  73. m_ShortNetname = m_Netname.AfterLast( '/' );
  74. }
  75. /**
  76. * Function Draw (TODO)
  77. */
  78. void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel,
  79. wxDC* DC,
  80. GR_DRAWMODE aDrawMode,
  81. const wxPoint& aOffset )
  82. {
  83. }
  84. void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  85. {
  86. int count;
  87. EDA_ITEM* Struct;
  88. wxString txt;
  89. MODULE* module;
  90. D_PAD* pad;
  91. double lengthnet = 0; // This is the lenght of tracks on pcb
  92. double lengthPadToDie = 0; // this is the lenght of internal ICs connections
  93. aList.push_back( MSG_PANEL_ITEM( _( "Net Name" ), GetNetname(), RED ) );
  94. txt.Printf( wxT( "%d" ), GetNet() );
  95. aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) );
  96. count = 0;
  97. module = m_parent->GetBoard()->m_Modules;
  98. for( ; module != 0; module = module->Next() )
  99. {
  100. for( pad = module->Pads(); pad != 0; pad = pad->Next() )
  101. {
  102. if( pad->GetNet() == GetNet() )
  103. {
  104. count++;
  105. lengthPadToDie += pad->GetPadToDieLength();
  106. }
  107. }
  108. }
  109. txt.Printf( wxT( "%d" ), count );
  110. aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
  111. count = 0;
  112. Struct = m_parent->GetBoard()->m_Track;
  113. for( ; Struct != NULL; Struct = Struct->Next() )
  114. {
  115. if( Struct->Type() == PCB_VIA_T )
  116. {
  117. if( ( (SEGVIA*) Struct )->GetNet() == GetNet() )
  118. count++;
  119. }
  120. if( Struct->Type() == PCB_TRACE_T )
  121. {
  122. if( ( (TRACK*) Struct )->GetNet() == GetNet() )
  123. lengthnet += ( (TRACK*) Struct )->GetLength();
  124. }
  125. }
  126. txt.Printf( wxT( "%d" ), count );
  127. aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
  128. // Displays the full net length (tracks on pcb + internal ICs connections ):
  129. txt = ::CoordinateToString( lengthnet + lengthPadToDie );
  130. aList.push_back( MSG_PANEL_ITEM( _( "Net Length:" ), txt, RED ) );
  131. // Displays the net length of tracks only:
  132. txt = ::CoordinateToString( lengthnet );
  133. aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
  134. // Displays the net length of internal ICs connections (wires inside ICs):
  135. txt = ::CoordinateToString( lengthPadToDie );
  136. aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
  137. }
  138. /***********************/
  139. /* class RATSNEST_ITEM */
  140. /***********************/
  141. RATSNEST_ITEM::RATSNEST_ITEM()
  142. {
  143. m_NetCode = 0; // netcode ( = 1.. n , 0 is the value used for not
  144. // connected items)
  145. m_Status = 0; // state
  146. m_PadStart = NULL; // pointer to the starting pad
  147. m_PadEnd = NULL; // pointer to ending pad
  148. m_Lenght = 0; // length of the line (temporary used in some
  149. // calculations)
  150. }
  151. /**
  152. * Function Draw
  153. * Draws a line (a ratsnest) from the starting pad to the ending pad
  154. */
  155. void RATSNEST_ITEM::Draw( EDA_DRAW_PANEL* panel,
  156. wxDC* DC,
  157. GR_DRAWMODE aDrawMode,
  158. const wxPoint& aOffset )
  159. {
  160. GRSetDrawMode( DC, aDrawMode );
  161. EDA_COLOR_T color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
  162. GRLine( panel->GetClipBox(), DC,
  163. m_PadStart->GetPosition() - aOffset,
  164. m_PadEnd->GetPosition() - aOffset, 0, color );
  165. }