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 <boost/optional/optional.hpp>
29 #include <tools/pcb_tool_base.h>
30 
34 class PICKER_TOOL : public PCB_TOOL_BASE
35 {
36 public:
37  PICKER_TOOL();
39 
41  typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
42  typedef std::function<void(void)> CANCEL_HANDLER;
43  typedef std::function<void(const int&)> FINALIZE_HANDLER;
44 
46  {
52  };
53 
55  void Reset( RESET_REASON aReason ) override {}
56 
58  int Main( const TOOL_EVENT& aEvent );
59 
64  inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; }
65 
70  inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; }
71 
76  inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; }
77 
83  inline void SetClickHandler( CLICK_HANDLER aHandler )
84  {
85  assert( !m_clickHandler );
86  m_clickHandler = aHandler;
87  }
88 
93  inline void SetCancelHandler( CANCEL_HANDLER aHandler )
94  {
95  assert( !m_cancelHandler );
96  m_cancelHandler = aHandler;
97  }
98 
103  inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
104  {
105  assert( !m_finalizeHandler );
106  m_finalizeHandler = aHandler;
107  }
108 
110  void setTransitions() override;
111 
112 private:
115 
118 
122 
124 
126  void reset();
127 
129  void setControls();
130 };
131 
132 #endif /* PICKER_TOOL_H */
bool m_autoPanning
Definition: picker_tool.h:114
int Main(const TOOL_EVENT &aEvent)
Main event loop.
Definition: picker_tool.cpp:43
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:83
void Reset(RESET_REASON aReason) override
Definition: picker_tool.h:55
std::function< void(void)> CANCEL_HANDLER
Definition: picker_tool.h:42
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
Event handler types.
Definition: picker_tool.h:41
void SetAutoPanning(bool aEnable)
Function SetAutoPanning() Sets autopanning mode for the period when the tool is active.
Definition: picker_tool.h:64
Generic tool for picking a point.
Definition: picker_tool.h:34
OPT< VECTOR2D > m_picked
Definition: picker_tool.h:123
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
Definition: picker_tool.h:103
LSET m_layerMask
The layer set to use for optional snapping
Definition: picker_tool.h:117
Class LSET is a set of PCB_LAYER_IDs.
void setTransitions() override
bool m_cursorCapture
Definition: picker_tool.h:113
Class TOOL_EVENT.
Definition: tool_event.h:167
void reset()
Reinitializes tool to its initial state.
OPT< CLICK_HANDLER > m_clickHandler
Definition: picker_tool.h:119
void setControls()
Applies the requested VIEW_CONTROLS settings.
OPT< FINALIZE_HANDLER > m_finalizeHandler
Definition: picker_tool.h:121
void SetCancelHandler(CANCEL_HANDLER aHandler)
Function SetCancelHandler() Sets a handler for cancel events (ESC or context-menu Cancel).
Definition: picker_tool.h:93
void SetLayerSet(LSET aLayerSet)
Function SetLayerSet() Sets the tool's snap layer set.
Definition: picker_tool.h:76
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
boost::optional< T > OPT
Definition: optional.h:7
OPT< CANCEL_HANDLER > m_cancelHandler
Definition: picker_tool.h:120
std::function< void(const int &)> FINALIZE_HANDLER
Definition: picker_tool.h:43
void SetCursorCapture(bool aEnable)
Function SetAutoPanning() Toggles cursor capture mode for the period when the tool is active.
Definition: picker_tool.h:70