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.

124 lines
4.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file highlight_connection.cpp
  25. * @brief This file contains basic functions related to the command to
  26. * highlight a connection (wires and labels) in a schematic
  27. * (that can be a simple or a complex hierarchy)
  28. */
  29. #include <fctsys.h>
  30. #include <class_drawpanel.h>
  31. #include <schframe.h>
  32. #include <erc.h>
  33. #include <class_netlist_object.h>
  34. bool SCH_EDIT_FRAME::HighlightConnectionAtPosition( wxPoint aPosition )
  35. {
  36. m_SelectedNetName = "";
  37. bool buildNetlistOk = false;
  38. // find which connected item is selected
  39. EDA_ITEMS nodeList;
  40. wxPoint gridPosition = GetGridPosition( aPosition );
  41. if( GetScreen()->GetNode( gridPosition,nodeList ) )
  42. {
  43. if( TestDuplicateSheetNames( false ) > 0 )
  44. wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
  45. else
  46. {
  47. // Build netlist info to get the proper netnames of connected items
  48. std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
  49. buildNetlistOk = true;
  50. for( auto obj : *objectsConnectedList )
  51. {
  52. if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
  53. {
  54. m_SelectedNetName = obj->GetNetName( true );
  55. break;
  56. }
  57. }
  58. }
  59. }
  60. SetStatusText( "selected net: " + m_SelectedNetName );
  61. SetCurrentSheetHighlightFlags();
  62. m_canvas->Refresh();
  63. return buildNetlistOk;
  64. }
  65. bool SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags()
  66. {
  67. SCH_SCREEN* screen = m_CurrentSheet->LastScreen();
  68. // Disable highlight flag on all items in the current screen
  69. for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
  70. {
  71. ptr->SetState( BRIGHTENED, false );
  72. if( ptr->Type() == SCH_SHEET_T )
  73. {
  74. for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
  75. pin.SetState( BRIGHTENED, false );
  76. }
  77. }
  78. if( m_SelectedNetName == "" )
  79. return true;
  80. if( TestDuplicateSheetNames( false ) > 0 )
  81. return false;
  82. // Build netlist info to get the proper netnames
  83. std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
  84. // highlight the items belonging to this net
  85. for( auto obj1 : *objectsConnectedList )
  86. {
  87. if( obj1->m_SheetPath == *m_CurrentSheet &&
  88. obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
  89. {
  90. obj1->m_Comp->SetState( BRIGHTENED, true );
  91. //if a bus is associated with this net highlight it as well
  92. if( obj1->m_BusNetCode )
  93. {
  94. for( auto obj2 : *objectsConnectedList )
  95. {
  96. if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
  97. obj1->m_BusNetCode == obj2->m_BusNetCode )
  98. obj2->m_Comp->SetState( BRIGHTENED, true );
  99. }
  100. }
  101. }
  102. }
  103. return true;
  104. }