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) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
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 <boost/optional/optional.hpp>
29 #include <math/vector2d.h>
30 #include <tool/tool_interactive.h>
31 
32 class EDA_DRAW_FRAME;
33 
34 
36 {
37 public:
38  PICKER_TOOL();
40 
42  bool Init() override;
43 
45  void Reset( RESET_REASON aReason ) override { }
46 
48  typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
49  typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
50  typedef std::function<void(void)> CANCEL_HANDLER;
51  typedef std::function<void(const int&)> FINALIZE_HANDLER;
52 
54  {
60  };
61 
63  int Main( const TOOL_EVENT& aEvent );
64 
65  inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; }
66 
72  inline void SetClickHandler( CLICK_HANDLER aHandler )
73  {
74  wxASSERT( !m_clickHandler );
75  m_clickHandler = aHandler;
76  }
77 
82  inline void SetMotionHandler( MOTION_HANDLER aHandler )
83  {
84  wxASSERT( !m_motionHandler );
85  m_motionHandler = aHandler;
86  }
87 
92  inline void SetCancelHandler( CANCEL_HANDLER aHandler )
93  {
94  wxASSERT( !m_cancelHandler );
95  m_cancelHandler = aHandler;
96  }
97 
102  inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
103  {
104  wxASSERT( !m_finalizeHandler );
105  m_finalizeHandler = aHandler;
106  }
107 
108 private:
110  void resetPicker();
111 
113  void setControls();
114 
116  void setTransitions() override;
117 
118 private:
120  wxCursor m_cursor;
121 
126 
128 };
129 
130 #endif /* PICKER_TOOL_H */
void SetCursor(const wxCursor &aCursor)
Definition: picker_tool.h:65
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: picker_tool.cpp:38
void SetMotionHandler(MOTION_HANDLER aHandler)
Function SetMotionHandler() Sets a handler for mouse motion.
Definition: picker_tool.h:82
int Main(const TOOL_EVENT &aEvent)
Main event loop.
Definition: picker_tool.cpp:55
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:72
wxCursor m_cursor
Definition: picker_tool.h:120
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Definition: picker_tool.h:45
std::function< void(void)> CANCEL_HANDLER
Definition: picker_tool.h:50
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
Event handler types.
Definition: picker_tool.h:48
The base class for create windows for drawing purpose.
OPT< VECTOR2D > m_picked
Definition: picker_tool.h:127
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
Definition: picker_tool.h:102
void setTransitions() override
OPT< MOTION_HANDLER > m_motionHandler
Definition: picker_tool.h:123
Class TOOL_EVENT.
Definition: tool_event.h:168
OPT< CLICK_HANDLER > m_clickHandler
Definition: picker_tool.h:122
void setControls()
Applies the requested VIEW_CONTROLS settings.
OPT< FINALIZE_HANDLER > m_finalizeHandler
Definition: picker_tool.h:125
void SetCancelHandler(CANCEL_HANDLER aHandler)
Function SetCancelHandler() Sets a handler for cancel events (ESC or context-menu Cancel).
Definition: picker_tool.h:92
std::function< void(const VECTOR2D &)> MOTION_HANDLER
Definition: picker_tool.h:49
EDA_DRAW_FRAME * m_frame
Definition: picker_tool.h:119
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
boost::optional< T > OPT
Definition: optional.h:7
OPT< CANCEL_HANDLER > m_cancelHandler
Definition: picker_tool.h:124
void resetPicker()
Reinitializes tool to its initial state.
std::function< void(const int &)> FINALIZE_HANDLER
Definition: picker_tool.h:51