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.

68 lines
2.2 KiB

11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include "grid_menu.h"
  25. #include <id.h>
  26. #include <draw_frame.h>
  27. #include <class_base_screen.h>
  28. #include <tools/common_actions.h>
  29. #include <boost/bind.hpp>
  30. GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) : m_parent( aParent )
  31. {
  32. BASE_SCREEN* screen = aParent->GetScreen();
  33. SetIcon( grid_select_xpm );
  34. SetMenuHandler( boost::bind( &GRID_MENU::EventHandler, this, _1 ) );
  35. SetUpdateHandler( boost::bind( &GRID_MENU::Update, this ) );
  36. wxArrayString gridsList;
  37. screen->BuildGridsChoiceList( gridsList, g_UserUnit != INCHES );
  38. for( unsigned int i = 0; i < gridsList.GetCount(); ++i )
  39. {
  40. GRID_TYPE& grid = screen->GetGrid( i );
  41. Append( grid.m_Id, gridsList[i], wxEmptyString, true );
  42. }
  43. }
  44. OPT_TOOL_EVENT GRID_MENU::EventHandler( const wxMenuEvent& aEvent )
  45. {
  46. OPT_TOOL_EVENT event( COMMON_ACTIONS::gridPreset.MakeEvent() );
  47. long idx = aEvent.GetId() - ID_POPUP_GRID_SELECT - 1;
  48. event->SetParameter( idx );
  49. return event;
  50. }
  51. void GRID_MENU::Update()
  52. {
  53. for( unsigned int i = 0; i < GetMenuItemCount(); ++i )
  54. Check( ID_POPUP_GRID_SELECT + 1 + i, false );
  55. Check( m_parent->GetScreen()->GetGridId(), true );
  56. }