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.

161 lines
5.2 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
  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-2021 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 <pcb_base_frame.h>
  29. #include <string_utils.h>
  30. #include <widgets/msgpanel.h>
  31. #include <base_units.h>
  32. #include <board.h>
  33. #include <board_design_settings.h>
  34. #include <connectivity/connectivity_data.h>
  35. #include <footprint.h>
  36. #include <pcb_track.h>
  37. #include <pad.h>
  38. NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
  39. BOARD_ITEM( aParent, PCB_NETINFO_T ),
  40. m_netCode( aNetCode ),
  41. m_netname( aNetName ),
  42. m_shortNetname( m_netname.AfterLast( '/' ) ),
  43. m_isCurrent( true )
  44. {
  45. m_parent = aParent;
  46. if( aParent )
  47. m_netClass = aParent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
  48. else
  49. m_netClass = std::make_shared<NETCLASS>( wxT( "<invalid>" ) );
  50. }
  51. NETINFO_ITEM::~NETINFO_ITEM()
  52. {
  53. // m_NetClass is not owned by me.
  54. }
  55. void NETINFO_ITEM::Clear()
  56. {
  57. m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
  58. }
  59. void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
  60. {
  61. wxCHECK( m_parent, /* void */ );
  62. if( aNetClass )
  63. m_netClass = aNetClass;
  64. else
  65. m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
  66. }
  67. void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  68. {
  69. wxString msg;
  70. aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
  71. aList.emplace_back( _( "Net Code" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
  72. // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
  73. BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
  74. if( board )
  75. {
  76. int count = 0;
  77. PCB_TRACK* startTrack = nullptr;
  78. for( FOOTPRINT* footprint : board->Footprints() )
  79. {
  80. for( PAD* pad : footprint->Pads() )
  81. {
  82. if( pad->GetNetCode() == GetNetCode() )
  83. count++;
  84. }
  85. }
  86. aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), count ) );
  87. count = 0;
  88. for( PCB_TRACK* track : board->Tracks() )
  89. {
  90. if( track->GetNetCode() == GetNetCode() )
  91. {
  92. if( track->Type() == PCB_VIA_T )
  93. count++;
  94. else if( !startTrack )
  95. startTrack = track;
  96. }
  97. }
  98. aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), count ) );
  99. if( startTrack )
  100. {
  101. double lengthNet = 0.0; // This is the length of tracks on pcb
  102. double lengthPadToDie = 0.0; // this is the length of internal ICs connections
  103. std::tie( count, lengthNet, lengthPadToDie ) = board->GetTrackLength( *startTrack );
  104. // Displays the full net length (tracks on pcb + internal ICs connections ):
  105. aList.emplace_back( _( "Net Length" ),
  106. aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
  107. // Displays the net length of tracks only:
  108. aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
  109. // Displays the net length of internal ICs connections (wires inside ICs):
  110. aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
  111. }
  112. }
  113. }
  114. bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  115. {
  116. return BOARD_ITEM::Matches( GetNetname(), aSearchData );
  117. }
  118. const BOX2I NETINFO_ITEM::GetBoundingBox() const
  119. {
  120. std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
  121. BOX2I bbox;
  122. for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
  123. PCB_ZONE_T, PCB_PAD_T } ) )
  124. {
  125. bbox.Merge( item->GetBoundingBox() );
  126. }
  127. return bbox;
  128. }