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.

123 lines
3.6 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 <wxPcbStruct.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::PadsTracksOrZones,
  49. RefPos( true ), guide );
  50. BOARD_ITEM* item = (*m_Collector)[0];
  51. if( item )
  52. {
  53. switch( item->Type() )
  54. {
  55. case PCB_PAD_T:
  56. netcode = ( (D_PAD*) item )->GetNetCode();
  57. SendMessageToEESCHEMA( item );
  58. break;
  59. case PCB_TRACE_T:
  60. case PCB_VIA_T:
  61. case PCB_ZONE_T:
  62. // since these classes are all derived from TRACK, use a common
  63. // GetNet() function:
  64. netcode = ( (TRACK*) item )->GetNetCode();
  65. break;
  66. case PCB_ZONE_AREA_T:
  67. netcode = ( (ZONE_CONTAINER*) item )->GetNetCode();
  68. break;
  69. default:
  70. ; // until somebody changes GENERAL_COLLECTOR::PadsOrTracks,
  71. // this should not happen.
  72. }
  73. }
  74. if( netcode >= 0 )
  75. {
  76. GetBoard()->SetHighLightNet( netcode );
  77. HighLight( DC );
  78. }
  79. return netcode; // HitTest() failed.
  80. }
  81. void PCB_EDIT_FRAME::HighLight( wxDC* DC )
  82. {
  83. if( GetBoard()->IsHighLightNetON() )
  84. GetBoard()->HighLightOFF();
  85. else
  86. GetBoard()->HighLightON();
  87. GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
  88. }
  89. void PCB_EDIT_FRAME::HighlightUnconnectedPads( wxDC* DC )
  90. {
  91. for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ )
  92. {
  93. RATSNEST_ITEM* net = &GetBoard()->m_FullRatsnest[ii];
  94. if( (net->m_Status & CH_ACTIF) == 0 )
  95. continue;
  96. net->m_PadStart->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT );
  97. net->m_PadEnd->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT );
  98. }
  99. }