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.

113 lines
3.4 KiB

18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file highlight.cpp
  27. * @brief Highlight nets.
  28. */
  29. #include <fctsys.h>
  30. #include <class_drawpanel.h>
  31. #include <pcb_edit_frame.h>
  32. #include <kicad_device_context.h>
  33. #include <class_board.h>
  34. #include <class_track.h>
  35. #include <class_zone.h>
  36. #include <pcbnew.h>
  37. #include <collectors.h>
  38. int PCB_EDIT_FRAME::SelectHighLight( wxDC* DC )
  39. {
  40. int netcode = -1;
  41. if( GetBoard()->IsHighLightNetON() )
  42. HighLight( DC );
  43. // use this scheme because a pad is a higher priority than a track in the
  44. // search, and finding a pad, instead of a track on a pad,
  45. // allows us to fire a message to Eeschema.
  46. GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();
  47. // optionally, modify the "guide" here as needed using its member functions
  48. m_Collector->Collect( GetBoard(), GENERAL_COLLECTOR::PadsOrTracks,
  49. RefPos( true ), guide );
  50. if( m_Collector->GetCount() == 0 )
  51. m_Collector->Collect( GetBoard(), GENERAL_COLLECTOR::Zones,
  52. RefPos( true ), guide );
  53. BOARD_ITEM* item = (*m_Collector)[0];
  54. if( item )
  55. {
  56. switch( item->Type() )
  57. {
  58. case PCB_PAD_T:
  59. netcode = ( (D_PAD*) item )->GetNetCode();
  60. SendMessageToEESCHEMA( item );
  61. break;
  62. case PCB_TRACE_T:
  63. case PCB_VIA_T:
  64. case PCB_SEGZONE_T:
  65. // since these classes are all derived from TRACK, use a common
  66. // GetNet() function:
  67. netcode = ( (TRACK*) item )->GetNetCode();
  68. break;
  69. case PCB_ZONE_AREA_T:
  70. netcode = ( (ZONE_CONTAINER*) item )->GetNetCode();
  71. break;
  72. default:
  73. ; // until somebody changes GENERAL_COLLECTOR::PadsOrTracks,
  74. // this should not happen.
  75. }
  76. }
  77. if( netcode >= 0 )
  78. {
  79. GetBoard()->SetHighLightNet( netcode );
  80. HighLight( DC );
  81. }
  82. return netcode; // HitTest() failed.
  83. }
  84. void PCB_EDIT_FRAME::HighLight( wxDC* DC )
  85. {
  86. if( GetBoard()->IsHighLightNetON() )
  87. GetBoard()->HighLightOFF();
  88. else
  89. GetBoard()->HighLightON();
  90. GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
  91. }