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.

151 lines
4.7 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
  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 <pcb_base_frame.h>
  31. #include <common.h>
  32. #include <kicad_string.h>
  33. #include <pcbnew.h>
  34. #include <richio.h>
  35. #include <macros.h>
  36. #include <msgpanel.h>
  37. #include <base_units.h>
  38. #include <class_board.h>
  39. #include <class_module.h>
  40. #include <class_track.h>
  41. /*********************************************************/
  42. /* class NETINFO_ITEM: handle data relative to a given net */
  43. /*********************************************************/
  44. NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
  45. BOARD_ITEM( aParent, PCB_NETINFO_T ),
  46. m_NetCode( aNetCode ),
  47. m_isCurrent( true ),
  48. m_Netname( aNetName ),
  49. m_ShortNetname( m_Netname.AfterLast( '/' ) )
  50. {
  51. m_parent = aParent;
  52. if( aParent )
  53. m_NetClass = aParent->GetDesignSettings().m_NetClasses.GetDefault();
  54. else
  55. m_NetClass = std::make_shared<NETCLASS>( "<invalid>" );
  56. }
  57. NETINFO_ITEM::~NETINFO_ITEM()
  58. {
  59. // m_NetClass is not owned by me.
  60. }
  61. /**
  62. * Function Print (TODO)
  63. */
  64. void NETINFO_ITEM::Print( PCB_BASE_FRAME* frame, wxDC* DC, const wxPoint& aOffset )
  65. {
  66. }
  67. void NETINFO_ITEM::SetClass( const NETCLASSPTR& aNetClass )
  68. {
  69. wxCHECK( m_parent, /* void */ );
  70. m_NetClass = aNetClass ? aNetClass : m_parent->GetDesignSettings().m_NetClasses.GetDefault();
  71. }
  72. void NETINFO_ITEM::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
  73. {
  74. wxString txt;
  75. double lengthnet = 0.0; // This is the length of tracks on pcb
  76. double lengthPadToDie = 0.0; // this is the length of internal ICs connections
  77. aList.push_back( MSG_PANEL_ITEM( _( "Net Name" ), GetNetname(), RED ) );
  78. txt.Printf( wxT( "%d" ), GetNet() );
  79. aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) );
  80. // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board
  81. // can be NULL
  82. BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
  83. if( board == NULL )
  84. return;
  85. int count = 0;
  86. for( auto mod : board->Modules() )
  87. {
  88. for( auto pad : mod->Pads() )
  89. {
  90. if( pad->GetNetCode() == GetNet() )
  91. {
  92. count++;
  93. lengthPadToDie += pad->GetPadToDieLength();
  94. }
  95. }
  96. }
  97. txt.Printf( wxT( "%d" ), count );
  98. aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
  99. count = 0;
  100. for( auto track : board->Tracks() )
  101. {
  102. if( track->Type() == PCB_VIA_T )
  103. {
  104. if( track->GetNetCode() == GetNet() )
  105. count++;
  106. }
  107. if( track->Type() == PCB_TRACE_T )
  108. {
  109. if( track->GetNetCode() == GetNet() )
  110. lengthnet += track->GetLength();
  111. }
  112. }
  113. txt.Printf( wxT( "%d" ), count );
  114. aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
  115. // Displays the full net length (tracks on pcb + internal ICs connections ):
  116. txt = MessageTextFromValue( aUnits, lengthnet + lengthPadToDie );
  117. aList.push_back( MSG_PANEL_ITEM( _( "Net Length" ), txt, RED ) );
  118. // Displays the net length of tracks only:
  119. txt = MessageTextFromValue( aUnits, lengthnet );
  120. aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
  121. // Displays the net length of internal ICs connections (wires inside ICs):
  122. txt = MessageTextFromValue( aUnits, lengthPadToDie, true );
  123. aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
  124. }