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 (C) 2019-2020 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 <optional>
29#include <gal/cursors.h>
30#include <math/vector2d.h>
32
33class EDA_DRAW_FRAME;
34
35
37{
38public:
40 typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
41 typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
42 typedef std::function<void(void)> CANCEL_HANDLER;
43 typedef std::function<void(const int&)> FINALIZE_HANDLER;
44
46 {
52 };
53
55 m_frame( nullptr ),
56 m_snap( false )
57 {
58 reset();
59 }
60
61 virtual ~PICKER_TOOL_BASE() = default;
62
63 inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; }
64
65 inline void SetSnapping( bool aSnap ) { m_snap = aSnap; }
66
72 inline void SetClickHandler( CLICK_HANDLER aHandler )
73 {
74 wxASSERT( !m_clickHandler );
75 m_clickHandler = aHandler;
76 }
77
83 inline void SetMotionHandler( MOTION_HANDLER aHandler )
84 {
85 wxASSERT( !m_motionHandler );
86 m_motionHandler = aHandler;
87 }
88
92 inline void SetCancelHandler( CANCEL_HANDLER aHandler )
93 {
94 wxASSERT( !m_cancelHandler );
95 m_cancelHandler = aHandler;
96 }
97
103 inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
104 {
105 wxASSERT( !m_finalizeHandler );
106 m_finalizeHandler = aHandler;
107 }
108
109protected:
111 virtual void reset();
112
115 bool m_snap;
116
117 std::optional<CLICK_HANDLER> m_clickHandler;
118 std::optional<MOTION_HANDLER> m_motionHandler;
119 std::optional<CANCEL_HANDLER> m_cancelHandler;
120 std::optional<FINALIZE_HANDLER> m_finalizeHandler;
121
122 std::optional<VECTOR2D> m_picked;
123};
124
125
127{
128public:
129 PICKER_TOOL();
130
131 PICKER_TOOL( const std::string& aName );
132
133 virtual ~PICKER_TOOL() = default;
134
136 bool Init() override;
137
139 void Reset( RESET_REASON aReason ) override { }
140
142 int Main( const TOOL_EVENT& aEvent );
143
144protected:
146 void setControls();
147
149 void setTransitions() override;
150};
151
152#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:83
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:72
void SetSnapping(bool aSnap)
Definition: picker_tool.h:65
virtual ~PICKER_TOOL_BASE()=default
std::optional< VECTOR2D > m_picked
Definition: picker_tool.h:122
std::function< void(void)> CANCEL_HANDLER
Definition: picker_tool.h:42
std::optional< FINALIZE_HANDLER > m_finalizeHandler
Definition: picker_tool.h:120
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:63
EDA_DRAW_FRAME * m_frame
Definition: picker_tool.h:113
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
< Event handler types.
Definition: picker_tool.h:40
std::optional< MOTION_HANDLER > m_motionHandler
Definition: picker_tool.h:118
std::optional< CLICK_HANDLER > m_clickHandler
Definition: picker_tool.h:117
void SetCancelHandler(CANCEL_HANDLER aHandler)
Set a handler for cancel events (ESC or context-menu Cancel).
Definition: picker_tool.h:92
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:103
std::optional< CANCEL_HANDLER > m_cancelHandler
Definition: picker_tool.h:119
std::function< void(const VECTOR2D &)> MOTION_HANDLER
Definition: picker_tool.h:41
KICURSOR m_cursor
Definition: picker_tool.h:114
virtual void reset()
< Reinitializes tool to its initial state.
Definition: picker_tool.cpp:32
std::function< void(const int &)> FINALIZE_HANDLER
Definition: picker_tool.h:43
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.
Definition: picker_tool.cpp:59
int Main(const TOOL_EVENT &aEvent)
Definition: picker_tool.cpp:76
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.
Definition: picker_tool.h:139
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
KICURSOR
Definition: cursors.h:34