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, 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
>
31
#include <
tool/tool_interactive.h
>
32
33
class
EDA_DRAW_FRAME
;
34
35
36
class
PICKER_TOOL_BASE
37
{
38
public
:
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
45
enum
pickerEndState
46
{
47
WAIT_CANCEL
,
48
CLICK_CANCEL
,
49
END_ACTIVATE
,
50
EVT_CANCEL
,
51
EXCEPTION_CANCEL
52
};
53
54
PICKER_TOOL_BASE
() :
55
m_frame
( nullptr ),
56
m_snap
( false ),
57
m_modifiers
( 0 )
58
{
59
reset
();
60
}
61
62
virtual
~PICKER_TOOL_BASE
() =
default
;
63
64
inline
void
SetCursor
(
KICURSOR
aCursor ) {
m_cursor
= aCursor; }
65
66
inline
void
SetSnapping
(
bool
aSnap ) {
m_snap
= aSnap; }
67
68
void
ClearHandlers
()
69
{
70
m_clickHandler
.reset();
71
m_motionHandler
.reset();
72
m_cancelHandler
.reset();
73
m_finalizeHandler
.reset();
74
}
75
81
inline
void
SetClickHandler
(
CLICK_HANDLER
aHandler )
82
{
83
wxASSERT( !
m_clickHandler
);
84
m_clickHandler
= aHandler;
85
}
86
92
inline
void
SetMotionHandler
(
MOTION_HANDLER
aHandler )
93
{
94
wxASSERT( !
m_motionHandler
);
95
m_motionHandler
= aHandler;
96
}
97
101
inline
void
SetCancelHandler
(
CANCEL_HANDLER
aHandler )
102
{
103
wxASSERT( !
m_cancelHandler
);
104
m_cancelHandler
= aHandler;
105
}
106
112
inline
void
SetFinalizeHandler
(
FINALIZE_HANDLER
aHandler )
113
{
114
wxASSERT( !
m_finalizeHandler
);
115
m_finalizeHandler
= aHandler;
116
}
117
118
int
CurrentModifiers
()
const
{
return
m_modifiers
; }
119
120
protected
:
122
virtual
void
reset
();
123
124
EDA_DRAW_FRAME
*
m_frame
;
125
KICURSOR
m_cursor
;
126
bool
m_snap
;
127
int
m_modifiers
;
128
129
std::optional<CLICK_HANDLER>
m_clickHandler
;
130
std::optional<MOTION_HANDLER>
m_motionHandler
;
131
std::optional<CANCEL_HANDLER>
m_cancelHandler
;
132
std::optional<FINALIZE_HANDLER>
m_finalizeHandler
;
133
134
std::optional<VECTOR2D>
m_picked
;
135
};
136
137
138
class
PICKER_TOOL
:
public
TOOL_INTERACTIVE
,
public
PICKER_TOOL_BASE
139
{
140
public
:
141
PICKER_TOOL
();
142
143
PICKER_TOOL
(
const
std::string& aName );
144
145
virtual
~PICKER_TOOL
() =
default
;
146
148
bool
Init
()
override
;
149
151
void
Reset
(
RESET_REASON
aReason )
override
{ }
152
154
int
Main
(
const
TOOL_EVENT
& aEvent );
155
156
protected
:
158
void
setControls
();
159
161
void
setTransitions
()
override
;
162
};
163
164
#endif
/* PICKER_TOOL_H */
EDA_DRAW_FRAME
The base class for create windows for drawing purpose.
Definition:
eda_draw_frame.h:84
PICKER_TOOL_BASE
Definition:
picker_tool.h:37
PICKER_TOOL_BASE::SetMotionHandler
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition:
picker_tool.h:92
PICKER_TOOL_BASE::m_modifiers
int m_modifiers
Definition:
picker_tool.h:127
PICKER_TOOL_BASE::SetClickHandler
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition:
picker_tool.h:81
PICKER_TOOL_BASE::SetSnapping
void SetSnapping(bool aSnap)
Definition:
picker_tool.h:66
PICKER_TOOL_BASE::~PICKER_TOOL_BASE
virtual ~PICKER_TOOL_BASE()=default
PICKER_TOOL_BASE::CurrentModifiers
int CurrentModifiers() const
Definition:
picker_tool.h:118
PICKER_TOOL_BASE::ClearHandlers
void ClearHandlers()
Definition:
picker_tool.h:68
PICKER_TOOL_BASE::m_picked
std::optional< VECTOR2D > m_picked
Definition:
picker_tool.h:134
PICKER_TOOL_BASE::CANCEL_HANDLER
std::function< void(void)> CANCEL_HANDLER
Definition:
picker_tool.h:42
PICKER_TOOL_BASE::m_snap
bool m_snap
Definition:
picker_tool.h:126
PICKER_TOOL_BASE::m_finalizeHandler
std::optional< FINALIZE_HANDLER > m_finalizeHandler
Definition:
picker_tool.h:132
PICKER_TOOL_BASE::SetCursor
void SetCursor(KICURSOR aCursor)
Definition:
picker_tool.h:64
PICKER_TOOL_BASE::m_frame
EDA_DRAW_FRAME * m_frame
Definition:
picker_tool.h:124
PICKER_TOOL_BASE::CLICK_HANDLER
std::function< bool(const VECTOR2D &)> CLICK_HANDLER
Event handler types.
Definition:
picker_tool.h:40
PICKER_TOOL_BASE::m_motionHandler
std::optional< MOTION_HANDLER > m_motionHandler
Definition:
picker_tool.h:130
PICKER_TOOL_BASE::m_clickHandler
std::optional< CLICK_HANDLER > m_clickHandler
Definition:
picker_tool.h:129
PICKER_TOOL_BASE::SetCancelHandler
void SetCancelHandler(CANCEL_HANDLER aHandler)
Set a handler for cancel events (ESC or context-menu Cancel).
Definition:
picker_tool.h:101
PICKER_TOOL_BASE::PICKER_TOOL_BASE
PICKER_TOOL_BASE()
Definition:
picker_tool.h:54
PICKER_TOOL_BASE::SetFinalizeHandler
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition:
picker_tool.h:112
PICKER_TOOL_BASE::m_cancelHandler
std::optional< CANCEL_HANDLER > m_cancelHandler
Definition:
picker_tool.h:131
PICKER_TOOL_BASE::MOTION_HANDLER
std::function< void(const VECTOR2D &)> MOTION_HANDLER
Definition:
picker_tool.h:41
PICKER_TOOL_BASE::m_cursor
KICURSOR m_cursor
Definition:
picker_tool.h:125
PICKER_TOOL_BASE::reset
virtual void reset()
Reinitializes tool to its initial state.
Definition:
picker_tool.cpp:32
PICKER_TOOL_BASE::pickerEndState
pickerEndState
Definition:
picker_tool.h:46
PICKER_TOOL_BASE::EXCEPTION_CANCEL
@ EXCEPTION_CANCEL
Definition:
picker_tool.h:51
PICKER_TOOL_BASE::WAIT_CANCEL
@ WAIT_CANCEL
Definition:
picker_tool.h:47
PICKER_TOOL_BASE::CLICK_CANCEL
@ CLICK_CANCEL
Definition:
picker_tool.h:48
PICKER_TOOL_BASE::END_ACTIVATE
@ END_ACTIVATE
Definition:
picker_tool.h:49
PICKER_TOOL_BASE::EVT_CANCEL
@ EVT_CANCEL
Definition:
picker_tool.h:50
PICKER_TOOL_BASE::FINALIZE_HANDLER
std::function< void(const int &)> FINALIZE_HANDLER
Definition:
picker_tool.h:43
PICKER_TOOL
Definition:
picker_tool.h:139
PICKER_TOOL::PICKER_TOOL
PICKER_TOOL()
Definition:
picker_tool.cpp:52
PICKER_TOOL::setControls
void setControls()
Applies the requested VIEW_CONTROLS settings.
Definition:
picker_tool.cpp:213
PICKER_TOOL::~PICKER_TOOL
virtual ~PICKER_TOOL()=default
PICKER_TOOL::Init
bool Init() override
Init() is called once upon a registration of the tool.
Definition:
picker_tool.cpp:59
PICKER_TOOL::Main
int Main(const TOOL_EVENT &aEvent)
Main event loop.
Definition:
picker_tool.cpp:76
PICKER_TOOL::setTransitions
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
Definition:
picker_tool.cpp:207
PICKER_TOOL::Reset
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition:
picker_tool.h:151
TOOL_BASE::RESET_REASON
RESET_REASON
Determine the reason of reset for a tool.
Definition:
tool_base.h:78
TOOL_EVENT
Generic, UI-independent tool event.
Definition:
tool_event.h:168
TOOL_INTERACTIVE
Definition:
tool_interactive.h:57
VECTOR2< double >
cursors.h
KICURSOR
KICURSOR
Definition:
cursors.h:44
tool_interactive.h
vector2d.h
src
include
tool
picker_tool.h
Generated on Tue Jul 8 2025 00:05:31 for KiCad PCB EDA Suite by
1.9.6