KiCad PCB EDA Suite
pcbnew_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 
35 {
36 public:
38  ~PCBNEW_PICKER_TOOL() override { }
39 
41  typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
42  typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
43  typedef std::function<void(void)> CANCEL_HANDLER;
44  typedef std::function<void(const int&)> FINALIZE_HANDLER;
45 
47  {
53  };
54 
56  void Reset( RESET_REASON aReason ) override {}
57 
59  int Main( const TOOL_EVENT& aEvent );
60 
65  inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; }
66 
67  inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; }
68 
74  inline void SetClickHandler( CLICK_HANDLER aHandler )
75  {
76  wxASSERT( !m_clickHandler );
77  m_clickHandler = aHandler;
78  }
79 
84  inline void SetMotionHandler( MOTION_HANDLER aHandler )
85  {
86  wxASSERT( !m_motionHandler );
87  m_motionHandler = aHandler;
88  }
89 
94  inline void SetCancelHandler( CANCEL_HANDLER aHandler )
95  {
96  wxASSERT( !m_cancelHandler );
97  m_cancelHandler = aHandler;
98  }
99 
104  inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
105  {
106  wxASSERT( !m_finalizeHandler );
107  m_finalizeHandler = aHandler;
108  }
109 
110 private:
112  void setTransitions() override;
113 
115  void reset();
116 
118  void setControls();
119 
120 private:
123  wxCursor m_cursor;
124 
129 
131 };
132 
133 #endif /* PICKER_TOOL_H */
OPT< MOTION_HANDLER > m_motionHandler
void Reset(RESET_REASON aReason) override
OPT< VECTOR2D > m_picked
LSET m_layerMask
The layer set to use for optional snapping
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
void setTransitions() override
~PCBNEW_PICKER_TOOL() override
OPT< CANCEL_HANDLER > m_cancelHandler
Generic tool for picking a point.
Class LSET is a set of PCB_LAYER_IDs.
Class TOOL_EVENT.
Definition: tool_event.h:168
std::function< void(void)> CANCEL_HANDLER
std::function< void(const VECTOR2D &)> MOTION_HANDLER
int Main(const TOOL_EVENT &aEvent)
Main event loop.
OPT< CLICK_HANDLER > m_clickHandler
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
Event handler types.
void SetLayerSet(LSET aLayerSet)
Function SetLayerSet() Sets the tool's snap layer set.
std::function< void(const int &)> FINALIZE_HANDLER
void SetMotionHandler(MOTION_HANDLER aHandler)
Function SetMotionHandler() Sets a handler for mouse motion.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
boost::optional< T > OPT
Definition: optional.h:7
void setControls()
Applies the requested VIEW_CONTROLS settings.
OPT< FINALIZE_HANDLER > m_finalizeHandler
void SetCancelHandler(CANCEL_HANDLER aHandler)
Function SetCancelHandler() Sets a handler for cancel events (ESC or context-menu Cancel).
void SetCursor(const wxCursor &aCursor)
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
void reset()
Reinitializes tool to its initial state.