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 <[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>
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  UpdateTitle();
45 }
46 
47 
48 OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
49 {
50  OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
51  event->SetParameter( (intptr_t) aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
52  return event;
53 }
54 
55 
57 {
58  SetTitle( _( "Zoom" ) );
59 }
60 
61 
63 {
64  Clear();
65 
66  int ii = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
67 
68  for( double factor : m_parent->config()->m_Window.zoom_factors )
69  Append( ii++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
70 
71  double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
72 
73  const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
74 
75  for( size_t jj = 0; jj < zoomList.size(); ++jj )
76  {
77  // Search for a value near the current zoom setting:
78  double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
79  // IDs start with 1 (leaving 0 for auto-zoom)
80  Check( ID_POPUP_ZOOM_LEVEL_START + jj + 1, rel_error < 0.1 );
81  }
82 }
void update() override
Update menu state stub.
Definition: zoom_menu.cpp:62
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:48
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
void UpdateTitle() override
Used by some menus to just-in-time translate their titles.
Definition: zoom_menu.cpp:56
void Clear()
Remove all the entries from the menu (as well as its title).
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:48
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:548