KiCad PCB EDA Suite
common_tools.h
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) 2014-2016 CERN
5  * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef _COMMON_TOOLS_H
28 #define _COMMON_TOOLS_H
29 
30 #include <tool/tool_interactive.h>
31 
32 class EDA_DRAW_FRAME;
33 
38 {
39 public:
40  COMMON_TOOLS();
41 
42  ~COMMON_TOOLS() override { }
43 
45  void Reset( RESET_REASON aReason ) override;
46 
47  int SelectionTool( const TOOL_EVENT& aEvent );
48 
49  // View controls
50  int ZoomRedraw( const TOOL_EVENT& aEvent );
51  int ZoomInOut( const TOOL_EVENT& aEvent );
52  int ZoomInOutCenter( const TOOL_EVENT& aEvent );
53  int ZoomCenter( const TOOL_EVENT& aEvent );
54  int ZoomFitScreen( const TOOL_EVENT& aEvent );
55  int ZoomFitObjects( const TOOL_EVENT& aEvent );
56  int ZoomPreset( const TOOL_EVENT& aEvent );
57 
58  int CenterContents( const TOOL_EVENT& aEvent );
59 
60  int PanControl( const TOOL_EVENT& aEvent );
61 
62  // Cursor control
63  int CursorControl( const TOOL_EVENT& aEvent );
64  int ToggleCursor( const TOOL_EVENT& aEvent );
65  int ToggleCursorStyle( const TOOL_EVENT& aEvent );
66 
67  // Units control
68  int SwitchUnits( const TOOL_EVENT& aEvent );
69  int ToggleUnits( const TOOL_EVENT& aEvent );
70  int TogglePolarCoords( const TOOL_EVENT& aEvent );
71  int ResetLocalCoords( const TOOL_EVENT& aEvent );
72 
73  void SetLastUnits( EDA_UNITS aUnit );
76 
77  // Grid control
78  int GridNext( const TOOL_EVENT& aEvent );
79  int GridPrev( const TOOL_EVENT& aEvent );
80  int GridPreset( const TOOL_EVENT& aEvent );
81  int GridFast1( const TOOL_EVENT& aEvent );
82  int GridFast2( const TOOL_EVENT& aEvent );
83  int ToggleGrid( const TOOL_EVENT& aEvent );
84  int GridProperties( const TOOL_EVENT& aEvent );
85  int GridPreset( int idx );
86  int OnGridChanged();
87 
88 private:
93  {
96  };
97 
99  void setTransitions() override;
100 
103 
104  int doZoomInOut( bool aDirection, bool aCenterOnCursor );
105 
107  int doZoomToPreset( int idx, bool aCenterOnCursor );
108 
109  int doZoomFit( ZOOM_FIT_TYPE_T aFitType );
110 
111  std::vector<VECTOR2I> m_grids;
112 
114  // The last used units in each system (used for toggling between metric and imperial)
117 };
118 
119 #endif
EDA_DRAW_FRAME * m_frame
Definition: common_tools.h:102
~COMMON_TOOLS() override
Definition: common_tools.h:42
int ZoomFitScreen(const TOOL_EVENT &aEvent)
int GridFast1(const TOOL_EVENT &aEvent)
EDA_UNITS GetLastMetricUnits()
Definition: common_tools.h:74
int ToggleCursorStyle(const TOOL_EVENT &aEvent)
Zoom to fall all items in view INCLUDING page and border.
Definition: common_tools.h:94
void SetLastUnits(EDA_UNITS aUnit)
int GridPreset(const TOOL_EVENT &aEvent)
int ResetLocalCoords(const TOOL_EVENT &aEvent)
The base class for create windows for drawing purpose.
int doZoomToPreset(int idx, bool aCenterOnCursor)
int SwitchUnits(const TOOL_EVENT &aEvent)
int GridNext(const TOOL_EVENT &aEvent)
int GridFast2(const TOOL_EVENT &aEvent)
int ToggleUnits(const TOOL_EVENT &aEvent)
int ZoomInOutCenter(const TOOL_EVENT &aEvent)
int GridPrev(const TOOL_EVENT &aEvent)
int doZoomInOut(bool aDirection, bool aCenterOnCursor)
Note: idx == 0 is Auto; idx == 1 is first entry in zoomList.
Generic, UI-independent tool event.
Definition: tool_event.h:173
int ZoomCenter(const TOOL_EVENT &aEvent)
Zoom to fit all items in view EXCLUDING page and border.
Definition: common_tools.h:95
int ToggleGrid(const TOOL_EVENT &aEvent)
EDA_UNITS GetLastImperialUnits()
Definition: common_tools.h:75
int ZoomInOut(const TOOL_EVENT &aEvent)
EDA_UNITS m_imperialUnit
Definition: common_tools.h:115
int CursorControl(const TOOL_EVENT &aEvent)
int ToggleCursor(const TOOL_EVENT &aEvent)
Handles action that are shared between different applications.
Definition: common_tools.h:37
void setTransitions() override
Pointer to the currently used edit frame.
EDA_UNITS
Definition: eda_units.h:38
int CenterContents(const TOOL_EVENT &aEvent)
int SelectionTool(const TOOL_EVENT &aEvent)
std::vector< VECTOR2I > m_grids
Grids from #APP_SETTINGS converted to internal units and with the user grid appended.
Definition: common_tools.h:111
ZOOM_FIT_TYPE_T
The set of "Zoom to Fit" types that can be performed.
Definition: common_tools.h:92
int ZoomPreset(const TOOL_EVENT &aEvent)
int ZoomFitObjects(const TOOL_EVENT &aEvent)
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
EDA_UNITS m_metricUnit
Definition: common_tools.h:116
int TogglePolarCoords(const TOOL_EVENT &aEvent)
int PanControl(const TOOL_EVENT &aEvent)
int ZoomRedraw(const TOOL_EVENT &aEvent)
int GridProperties(const TOOL_EVENT &aEvent)
int doZoomFit(ZOOM_FIT_TYPE_T aFitType)