KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zoom_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/zoom_menu.h>
27#include <id.h>
28#include <eda_draw_frame.h>
30#include <tool/actions.h>
32#include <bitmaps.h>
33#include <functional>
34
35using namespace std::placeholders;
36
38 ACTION_MENU( true ),
39 m_parent( aParent )
40{
42 SetIcon( BITMAPS::zoom_selection );
43}
44
45
46OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
47{
48 OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
49 event->SetParameter<int>( aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
50 return event;
51}
52
53
55{
56 SetTitle( _( "Zoom" ) );
57}
58
59
61{
62 Clear();
63
64 int ii = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
65
66 for( double factor : m_parent->config()->m_Window.zoom_factors )
67 Append( ii++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
68
69 double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
70
71 const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
72
73 for( size_t jj = 0; jj < zoomList.size(); ++jj )
74 {
75 // Search for a value near the current zoom setting:
76 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
77 // IDs start with 1 (leaving 0 for auto-zoom)
78 Check( ID_POPUP_ZOOM_LEVEL_START + jj + 1, rel_error < 0.1 );
79 }
80}
static TOOL_ACTION zoomPreset
Definition: actions.h:128
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void Clear()
Remove all the entries from the menu (as well as its title).
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
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.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
double GetZoomFactor() const
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: zoom_menu.cpp:46
void UpdateTitle() override
Used by some menus to just-in-time translate their titles.
Definition: zoom_menu.cpp:54
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:48
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition: zoom_menu.cpp:37
void update() override
Update menu state stub.
Definition: zoom_menu.cpp:60
#define _(s)
@ ID_POPUP_ZOOM_LEVEL_START
Definition: id.h:155
std::vector< double > zoom_factors
Definition: app_settings.h:78
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:629