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.

105 lines
3.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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. * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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. #include <tool/grid_menu.h>
  26. #include <id.h>
  27. #include <eda_draw_frame.h>
  28. #include <settings/app_settings.h>
  29. #include <tool/actions.h>
  30. #include <bitmaps.h>
  31. #include <base_units.h>
  32. using namespace std::placeholders;
  33. GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) :
  34. ACTION_MENU( true ),
  35. m_parent( aParent )
  36. {
  37. UpdateTitle();
  38. SetIcon( BITMAPS::grid_select );
  39. update();
  40. }
  41. OPT_TOOL_EVENT GRID_MENU::eventHandler( const wxMenuEvent& aEvent )
  42. {
  43. OPT_TOOL_EVENT event( ACTIONS::gridPreset.MakeEvent() );
  44. event->SetParameter<int>( aEvent.GetId() - ID_POPUP_GRID_START );
  45. return event;
  46. }
  47. void GRID_MENU::UpdateTitle()
  48. {
  49. SetTitle( _( "Grid" ) );
  50. }
  51. void GRID_MENU::update()
  52. {
  53. APP_SETTINGS_BASE* settings = m_parent->config();
  54. unsigned int current = settings->m_Window.grid.last_size_idx + ID_POPUP_GRID_START;
  55. wxArrayString gridsList;
  56. int i = ID_POPUP_GRID_START;
  57. GRID_MENU::BuildChoiceList( &gridsList, settings, m_parent );
  58. while( GetMenuItemCount() > 0 )
  59. Delete( FindItemByPosition( 0 ) );
  60. Add( ACTIONS::gridOrigin );
  61. AppendSeparator();
  62. for( const wxString& grid : gridsList )
  63. {
  64. int idx = i++;
  65. Append( idx, grid, wxEmptyString, wxITEM_CHECK )->Check( idx == (int) current );
  66. }
  67. }
  68. void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg,
  69. EDA_DRAW_FRAME* aParent )
  70. {
  71. wxString msg;
  72. EDA_IU_SCALE scale = aParent->GetIuScale();
  73. EDA_UNITS primaryUnit;
  74. EDA_UNITS secondaryUnit;
  75. aParent->GetUnitPair( primaryUnit, secondaryUnit );
  76. for( GRID& gridSize : aCfg->m_Window.grid.grids )
  77. {
  78. wxString name;
  79. if( !gridSize.name.IsEmpty() )
  80. name = gridSize.name + ": ";
  81. msg.Printf( _( "%s%s (%s)" ), name, gridSize.MessageText( scale, primaryUnit, true ),
  82. gridSize.MessageText( scale, secondaryUnit, true ) );
  83. aGridsList->Add( msg );
  84. }
  85. }