KiCad PCB EDA Suite
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 <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 
26 #include <tool/zoom_menu.h>
27 #include <id.h>
28 #include <eda_draw_frame.h>
29 #include <settings/app_settings.h>
30 #include <tool/actions.h>
32 #include <bitmaps.h>
33 #include <convert_to_biu.h>
34 #include <functional>
35 #include <zoom_defines.h>
36 
37 using namespace std::placeholders;
38 
40  ACTION_MENU( true ),
41  m_parent( aParent )
42 {
43  SetTitle( _( "Zoom" ) );
45 
46  int i = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
47 
48  for( double factor : m_parent->config()->m_Window.zoom_factors )
49  Append( i++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
50 }
51 
52 
53 OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
54 {
55  OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
56  event->SetParameter( (intptr_t) aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
57  return event;
58 }
59 
60 
62 {
63  double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
64 
65  const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
66 
67  for( size_t i = 0; i < zoomList.size(); ++i )
68  {
69  // Search for a value near the current zoom setting:
70  double rel_error = std::fabs( zoomList[i] - zoom ) / zoom;
71  // IDs start with 1 (leaving 0 for auto-zoom)
72  Check( ID_POPUP_ZOOM_LEVEL_START + i + 1, rel_error < 0.1 );
73  }
74 }
void update() override
Update menu state stub.
Definition: zoom_menu.cpp:61
static TOOL_ACTION zoomPreset
Definition: actions.h:98
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: zoom_menu.cpp:53
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
The base class for create windows for drawing purpose.
std::vector< double > zoom_factors
Definition: app_settings.h:86
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
#define _(s)
double GetZoomFactor() const
Get the zoom factor.
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition: zoom_menu.cpp:39
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:548