KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PICKER_TOOL_H
22#define PICKER_TOOL_H
23
24#include <optional>
25#include <gal/cursors.h>
26#include <math/vector2d.h>
28
29class EDA_DRAW_FRAME;
30
31
33{
34public:
36 typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
37 typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
38 typedef std::function<void(void)> CANCEL_HANDLER;
39 typedef std::function<void(const int&)> FINALIZE_HANDLER;
40
49
51 m_frame( nullptr ),
52 m_snap( false ),
53 m_modifiers( 0 )
54 {
55 reset();
56 }
57
58 virtual ~PICKER_TOOL_BASE() = default;
59
60 inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; }
61
62 inline void SetSnapping( bool aSnap ) { m_snap = aSnap; }
63
65 {
66 m_clickHandler.reset();
67 m_motionHandler.reset();
68 m_cancelHandler.reset();
69 m_finalizeHandler.reset();
70 }
71
77 inline void SetClickHandler( CLICK_HANDLER aHandler )
78 {
79 wxASSERT( !m_clickHandler );
80 m_clickHandler = aHandler;
81 }
82
88 inline void SetMotionHandler( MOTION_HANDLER aHandler )
89 {
90 wxASSERT( !m_motionHandler );
91 m_motionHandler = aHandler;
92 }
93
97 inline void SetCancelHandler( CANCEL_HANDLER aHandler )
98 {
99 wxASSERT( !m_cancelHandler );
100 m_cancelHandler = aHandler;
101 }
102
108 inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
109 {
110 wxASSERT( !m_finalizeHandler );
111 m_finalizeHandler = aHandler;
112 }
113
114 int CurrentModifiers() const { return m_modifiers; }
115
116protected:
118 virtual void reset();
119
122 bool m_snap;
124
125 std::optional<CLICK_HANDLER> m_clickHandler;
126 std::optional<MOTION_HANDLER> m_motionHandler;
127 std::optional<CANCEL_HANDLER> m_cancelHandler;
128 std::optional<FINALIZE_HANDLER> m_finalizeHandler;
129
130 std::optional<VECTOR2D> m_picked;
131};
132
133
135{
136public:
137 PICKER_TOOL();
138
139 PICKER_TOOL( const std::string& aName );
140
141 virtual ~PICKER_TOOL() = default;
142
144 bool Init() override;
145
147 void Reset( RESET_REASON aReason ) override { }
148
150 int Main( const TOOL_EVENT& aEvent );
151
152protected:
154 void setControls();
155
157 void setTransitions() override;
158};
159
160#endif /* PICKER_TOOL_H */
The base class for create windows for drawing purpose.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition picker_tool.h:88
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition picker_tool.h:77
void SetSnapping(bool aSnap)
Definition picker_tool.h:62
virtual ~PICKER_TOOL_BASE()=default
int CurrentModifiers() const
std::optional< VECTOR2D > m_picked
std::function< void(void)> CANCEL_HANDLER
Definition picker_tool.h:38
std::optional< FINALIZE_HANDLER > m_finalizeHandler
void SetCursor(KICURSOR aCursor)
Definition picker_tool.h:60
EDA_DRAW_FRAME * m_frame
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
Event handler types.
Definition picker_tool.h:36
std::optional< MOTION_HANDLER > m_motionHandler
std::optional< CLICK_HANDLER > m_clickHandler
void SetCancelHandler(CANCEL_HANDLER aHandler)
Set a handler for cancel events (ESC or context-menu Cancel).
Definition picker_tool.h:97
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
std::optional< CANCEL_HANDLER > m_cancelHandler
std::function< void(const VECTOR2D &)> MOTION_HANDLER
Definition picker_tool.h:37
virtual void reset()
Reinitializes tool to its initial state.
std::function< void(const int &)> FINALIZE_HANDLER
Definition picker_tool.h:39
void setControls()
Applies the requested VIEW_CONTROLS settings.
virtual ~PICKER_TOOL()=default
bool Init() override
Init() is called once upon a registration of the tool.
int Main(const TOOL_EVENT &aEvent)
Main event loop.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
KICURSOR
Definition cursors.h:40
VECTOR2< double > VECTOR2D
Definition vector2d.h:682