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 
30 #include "pcb_tool.h"
34 class PICKER_TOOL : public PCB_TOOL
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 SetSnapping( bool aEnable ) { m_cursorSnapping = aEnable; }
65 
70  inline void SetCursorVisible( bool aEnable ) { m_cursorVisible = aEnable; }
71 
76  inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; }
77 
82  inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; }
83 
88  inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; }
89 
95  inline void SetClickHandler( CLICK_HANDLER aHandler )
96  {
97  assert( !m_clickHandler );
98  m_clickHandler = aHandler;
99  }
100 
105  inline void SetCancelHandler( CANCEL_HANDLER aHandler )
106  {
107  assert( !m_cancelHandler );
108  m_cancelHandler = aHandler;
109  }
110 
115  inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
116  {
117  assert( !m_finalizeHandler );
118  m_finalizeHandler = aHandler;
119  }
120 
122  void setTransitions() override;
123 
124 private:
125  // Tool settings.
130 
133 
137 
140 
143 
145  void reset();
146 
148  void setControls();
149 };
150 
151 #endif /* PICKER_TOOL_H */
void SetSnapping(bool aEnable)
Function SetSnapping() Sets cursor snapping to grid for the period when the tool is active.
Definition: picker_tool.h:64
bool m_autoPanning
Definition: picker_tool.h:129
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:95
bool m_cursorSnapping
Definition: picker_tool.h:126
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
bool m_cursorVisible
Definition: picker_tool.h:127
void SetAutoPanning(bool aEnable)
Function SetAutoPanning() Sets autopanning mode for the period when the tool is active.
Definition: picker_tool.h:76
Generic tool for picking a point.
Definition: picker_tool.h:34
OPT< VECTOR2D > m_picked
Picked point (if any).
Definition: picker_tool.h:139
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
Definition: picker_tool.h:115
LSET m_layerMask
The layer set to use for optional snapping
Definition: picker_tool.h:132
Class LSET is a set of PCB_LAYER_IDs.
void setTransitions() override
bool m_cursorCapture
Definition: picker_tool.h:128
Class TOOL_EVENT.
Definition: tool_event.h:168
void reset()
Reinitializes tool to its initial state.
OPT< CLICK_HANDLER > m_clickHandler
Optional event handlers.
Definition: picker_tool.h:135
void setControls()
Applies the requested VIEW_CONTROLS settings.
OPT< FINALIZE_HANDLER > m_finalizeHandler
Optional finalize state handler.
Definition: picker_tool.h:142
void SetCancelHandler(CANCEL_HANDLER aHandler)
Function SetCancelHandler() Sets a handler for cancel events (ESC or context-menu Cancel).
Definition: picker_tool.h:105
void SetLayerSet(LSET aLayerSet)
Function SetLayerSet() Sets the tool's snap layer set.
Definition: picker_tool.h:88
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:136
std::function< void(const int &)> FINALIZE_HANDLER
Definition: picker_tool.h:43
void SetCursorVisible(bool aEnable)
Function SetCursorVisible() Sets cursor visibility for the period when the tool is active.
Definition: picker_tool.h:70
void SetCursorCapture(bool aEnable)
Function SetAutoPanning() Toggles cursor capture mode for the period when the tool is active.
Definition: picker_tool.h:82