KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_menu.cpp
Go to the documentation of this file.
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 <[email protected]>
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#include <tool/grid_menu.h>
27#include <id.h>
28#include <eda_draw_frame.h>
30#include <tool/actions.h>
31#include <bitmaps.h>
32#include <base_units.h>
33
34using namespace std::placeholders;
35
37 ACTION_MENU( true ),
38 m_parent( aParent )
39{
41 SetIcon( BITMAPS::grid_select );
42 update();
43}
44
45
46OPT_TOOL_EVENT GRID_MENU::eventHandler( const wxMenuEvent& aEvent )
47{
48 OPT_TOOL_EVENT event( ACTIONS::gridPreset.MakeEvent() );
49 event->SetParameter<int>( aEvent.GetId() - ID_POPUP_GRID_START );
50 return event;
51}
52
53
55{
56 SetTitle( _( "Grid" ) );
57}
58
59
61{
62 APP_SETTINGS_BASE* settings = m_parent->config();
63 unsigned int current = settings->m_Window.grid.last_size_idx + ID_POPUP_GRID_START;
64 wxArrayString gridsList;
65 int i = ID_POPUP_GRID_START;
66
67 GRID_MENU::BuildChoiceList( &gridsList, settings, m_parent );
68
69 while( GetMenuItemCount() > 0 )
70 Delete( FindItemByPosition( 0 ) );
71
73 AppendSeparator();
74
75 for( const wxString& grid : gridsList )
76 {
77 int idx = i++;
78 Append( idx, grid, wxEmptyString, wxITEM_CHECK )->Check( idx == (int) current );
79 }
80}
81
82
83void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg,
84 EDA_DRAW_FRAME* aParent )
85{
86 wxString msg;
87 EDA_IU_SCALE scale = aParent->GetIuScale();
88 EDA_UNITS primaryUnit;
89 EDA_UNITS secondaryUnit;
90
91 aParent->GetUnitPair( primaryUnit, secondaryUnit );
92
93 for( GRID& gridSize : aCfg->m_Window.grid.grids )
94 {
95 wxString name;
96
97 if( !gridSize.name.IsEmpty() )
98 name = gridSize.name + ": ";
99
100 msg.Printf( _( "%s%s (%s)" ), name, gridSize.MessageText( scale, primaryUnit, true ),
101 gridSize.MessageText( scale, secondaryUnit, true ) );
102
103 aGridsList->Add( msg );
104 }
105}
const char * name
Definition: DXF_plotter.cpp:57
static TOOL_ACTION gridPreset
Definition: actions.h:176
static TOOL_ACTION gridOrigin
Definition: actions.h:180
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:92
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:78
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:172
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
The base class for create windows for drawing purpose.
void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits) override
Get the pair or units in current use.
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: grid_menu.cpp:46
void update() override
Update menu state stub.
Definition: grid_menu.cpp:60
void UpdateTitle() override
Used by some menus to just-in-time translate their titles.
Definition: grid_menu.cpp:54
GRID_MENU(EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:36
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:83
EDA_DRAW_FRAME * m_parent
Definition: grid_menu.h:52
const EDA_IU_SCALE & GetIuScale() const
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
@ ID_POPUP_GRID_START
Definition: id.h:158
const int scale
std::vector< GRID > grids
Definition: grid_settings.h:66
Common grid settings, available to every frame.
Definition: grid_settings.h:34
wxString MessageText(EDA_IU_SCALE aScale, EDA_UNITS aUnits, bool aDisplayUnits=true) const
Returns a string representation of the grid in specified units.
wxString name
Definition: grid_settings.h:51
GRID_SETTINGS grid
Definition: app_settings.h:81
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:629