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 
36 using namespace std::placeholders;
37 
39  ACTION_MENU( true ),
40  m_parent( aParent )
41 {
42  SetTitle( _( "Zoom" ) );
44 
45  int i = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
46 
47  for( double factor : m_parent->config()->m_Window.zoom_factors )
48  Append( i++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
49 }
50 
51 
52 OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
53 {
54  OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
55  event->SetParameter( (intptr_t) aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
56  return event;
57 }
58 
59 
61 {
62  double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
63 
64  const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
65 
66  for( size_t i = 0; i < zoomList.size(); ++i )
67  {
68  // Search for a value near the current zoom setting:
69  double rel_error = std::fabs( zoomList[i] - zoom ) / zoom;
70  // IDs start with 1 (leaving 0 for auto-zoom)
71  Check( ID_POPUP_ZOOM_LEVEL_START + i + 1, rel_error < 0.1 );
72  }
73 }
void update() override
Update menu state stub.
Definition: zoom_menu.cpp:60
static TOOL_ACTION zoomPreset
Definition: actions.h:94
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
ACTION_MENU.
Definition: action_menu.h:44
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: zoom_menu.cpp:52
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.
#define ZOOM_COEFF
std::vector< double > zoom_factors
Definition: app_settings.h:78
const BITMAP_OPAQUE zoom_selection_xpm[1]
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
double GetZoomFactor() const
Get the zoom factor.
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition: zoom_menu.cpp:38
WINDOW_SETTINGS m_Window
Definition: app_settings.h:153
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556