KiCad PCB EDA Suite
picker_tool.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) 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 #ifndef PICKER_TOOL_H
26 #define PICKER_TOOL_H
27 
28 #include <tool/tool_interactive.h>
29 #include <boost/optional/optional.hpp>
30 #include <boost/function.hpp>
31 
36 {
37 public:
38  PICKER_TOOL();
40 
42  typedef boost::function<bool(const VECTOR2D&)> CLICK_HANDLER;
43 
45  void Reset( RESET_REASON aReason ) override {}
46 
48  int Main( const TOOL_EVENT& aEvent );
49 
54  inline void SetSnapping( bool aEnable ) { m_cursorSnapping = aEnable; }
55 
60  inline void SetCursorVisible( bool aEnable ) { m_cursorVisible = aEnable; }
61 
66  inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; }
67 
72  inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; }
73 
79  {
80  assert( !m_picking );
81  return m_picked;
82  }
83 
88  bool IsPicking() const { return m_picking; }
89 
95  inline void SetClickHandler( CLICK_HANDLER aHandler )
96  {
97  assert( !m_clickHandler );
98  m_clickHandler = aHandler;
99  }
100 
102  void setTransitions() override;
103 
104 private:
105  // Tool settings.
110 
113 
116 
118  bool m_picking;
119 
121  void reset();
122 
124  void setControls();
125 };
126 
127 #endif /* PICKER_TOOL_H */
boost::optional< CLICK_HANDLER > m_clickHandler
Optional mouse click event handler.
Definition: picker_tool.h:112
void SetSnapping(bool aEnable)
Function SetSnapping() Sets cursor snapping to grid for the period when the tool is active...
Definition: picker_tool.h:54
bool m_picking
Activity status.
Definition: picker_tool.h:118
bool m_autoPanning
Definition: picker_tool.h:109
boost::function< bool(const VECTOR2D &)> CLICK_HANDLER
Mouse event click handler type.
Definition: picker_tool.h:42
int Main(const TOOL_EVENT &aEvent)
Main event loop.
Definition: picker_tool.cpp:42
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:95
bool m_cursorSnapping
Definition: picker_tool.h:106
void Reset(RESET_REASON aReason) override
>
Definition: picker_tool.h:45
bool m_cursorVisible
Definition: picker_tool.h:107
void SetAutoPanning(bool aEnable)
Function SetAutoPanning() Sets autopanning mode for the period when the tool is active.
Definition: picker_tool.h:66
Generic tool for picking a point.
Definition: picker_tool.h:35
boost::optional< VECTOR2D > GetPoint() const
Function GetPoint() Returns picked point.
Definition: picker_tool.h:78
void setTransitions() override
>
Definition: picker_tool.cpp:92
bool m_cursorCapture
Definition: picker_tool.h:108
Class TOOL_EVENT.
Definition: tool_event.h:162
void reset()
Reinitializes tool to its initial state.
Definition: picker_tool.cpp:98
boost::optional< VECTOR2D > m_picked
Picked point (if any).
Definition: picker_tool.h:115
void setControls()
Applies the requested VIEW_CONTROLS settings.
bool IsPicking() const
Function IsPicking() Returns information whether the tool is still active.
Definition: picker_tool.h:88
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
void SetCursorVisible(bool aEnable)
Function SetCursorVisible() Sets cursor visibility for the period when the tool is active...
Definition: picker_tool.h:60
void SetCursorCapture(bool aEnable)
Function SetAutoPanning() Toggles cursor capture mode for the period when the tool is active...
Definition: picker_tool.h:72