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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <tool/zoom_menu.h>
26 #include <id.h>
27 #include <draw_frame.h>
28 #include <class_base_screen.h>
29 #include <tool/actions.h>
30 #include <bitmaps.h>
31 
32 #include <functional>
33 using namespace std::placeholders;
34 
35 ZOOM_MENU::ZOOM_MENU( EDA_DRAW_FRAME* aParent ) : m_parent( aParent )
36 {
37  BASE_SCREEN* screen = aParent->GetScreen();
38 
39  SetTitle( _( "Zoom" ) );
40  SetIcon( zoom_selection_xpm );
41 
42  //int zoom = screen->GetZoom();
44  (int) screen->m_ZoomList.size() );
45 
46  for( int i = 0; i < maxZoomIds; ++i )
47  {
48  Append( ID_POPUP_ZOOM_LEVEL_START + i,
49  wxString::Format( _( "Zoom: %.2f" ), aParent->GetZoomLevelCoeff() / screen->m_ZoomList[i] ),
50  wxEmptyString, wxITEM_CHECK );
51  }
52 }
53 
54 
55 OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
56 {
57  OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
58  intptr_t idx = aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START;
59  event->SetParameter( idx );
60 
61  return event;
62 }
63 
64 
66 {
67  double zoom = m_parent->GetScreen()->GetZoom();
68  const std::vector<double>& zoomList = m_parent->GetScreen()->m_ZoomList;
69 
70  // Check the current zoom
71  for( unsigned int i = 0; i < GetMenuItemCount(); ++i )
72  Check( ID_POPUP_ZOOM_LEVEL_START + i, std::fabs( zoomList[i] - zoom ) < 1e-6 );
73 }
void update() override
Update menu state stub.
Definition: zoom_menu.cpp:65
static TOOL_ACTION zoomPreset
Definition: actions.h:57
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: zoom_menu.cpp:55
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
double GetZoomLevelCoeff() const
Function GetZoomLevelCoeff returns the coefficient to convert internal display scale factor to zoom l...
Definition: draw_frame.h:414
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:341
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition: zoom_menu.cpp:35
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
BASE_SCREEN class implementation.
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
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the context menu.
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:460
#define min(a, b)
Definition: auxiliary.h:85