VTK: Common/Core/vtkEventData.h Source File

| VTK 9.3.1

vtkEventData.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
7 #ifndef vtkEventData_h
8 #define vtkEventData_h
9
10 #include "vtkCommand.h"
11
12 // enumeration of possible devices
13 VTK_ABI_NAMESPACE_BEGIN
14 enum class vtkEventDataDevice
15 {
16 Unknown = -1,
17 HeadMountedDisplay,
18 RightController,
19 LeftController,
20 GenericTracker,
21 Any,
22 NumberOfDevices
23 };
24
25 const int vtkEventDataNumberOfDevices = (static_cast<int>(vtkEventDataDevice::NumberOfDevices));
26
27 // enumeration of possible device inputs
28 enum class vtkEventDataDeviceInput
29 {
30 Unknown = -1,
31 Any,
32 Trigger,
33 TrackPad,
34 Joystick,
35 Grip,
36 ApplicationMenu,
37 NumberOfInputs
38 };
39
40 const int vtkEventDataNumberOfInputs = (static_cast<int>(vtkEventDataDeviceInput::NumberOfInputs));
41
42 // enumeration of actions that can happen
43 enum class vtkEventDataAction
44 {
45 Unknown = -1,
46 Any,
47 Press,
48 Release,
49 Touch,
50 Untouch,
51 NumberOfActions
52 };
53
54 class vtkEventDataForDevice;
55 class vtkEventDataDevice3D;
56
57 class vtkEventData : public vtkObjectBase
58 {
59 public:
60 vtkBaseTypeMacro(vtkEventData, vtkObjectBase);
61
62 int GetType() const { return this->Type; }
63 void SetType(int val) { this->Type = val; }
64
65 // are two events equivalent
66 bool operator==(const vtkEventData& a) const
67 {
68 return this->Type == a.Type && this->Equivalent(&a);
69 }
70
71 // some convenience downcasts
72 virtual vtkEventDataForDevice* GetAsEventDataForDevice() { return nullptr; }
73 virtual vtkEventDataDevice3D* GetAsEventDataDevice3D() { return nullptr; }
74
75 protected:
76 vtkEventData() = default;
77 ~vtkEventData() override = default;
78
79 // subclasses override this to define their
80 // definition of equivalent
81 virtual bool Equivalent(const vtkEventData* ed) const = 0;
82
83 int Type;
84
85 private:
86 vtkEventData(const vtkEventData& c) = delete;
87 };
88
89 // a subclass for events that may have one or more of
90 // device, input, and action
91 class vtkEventDataForDevice : public vtkEventData
92 {
93 public:
94 vtkTypeMacro(vtkEventDataForDevice, vtkEventData);
95 static vtkEventDataForDevice* New()
96 {
97 vtkEventDataForDevice* ret = new vtkEventDataForDevice;
98 ret->InitializeObjectBase();
99 return ret;
100 }
101
102 vtkEventDataDevice GetDevice() const { return this->Device; }
103 vtkEventDataDeviceInput GetInput() const { return this->Input; }
104 vtkEventDataAction GetAction() const { return this->Action; }
105
106 void SetDevice(vtkEventDataDevice v) { this->Device = v; }
107 void SetInput(vtkEventDataDeviceInput v) { this->Input = v; }
108 void SetAction(vtkEventDataAction v) { this->Action = v; }
109
110 bool DeviceMatches(vtkEventDataDevice val)
111 {
112 return val == this->Device || val == vtkEventDataDevice::Any ||
113 this->Device == vtkEventDataDevice::Any;
114 }
115
116 vtkEventDataForDevice* GetAsEventDataForDevice() override { return this; }
117
118 protected:
119 vtkEventDataDevice Device;
120 vtkEventDataDeviceInput Input;
121 vtkEventDataAction Action;
122
123 bool Equivalent(const vtkEventData* e) const override
124 {
125 const vtkEventDataForDevice* edd = static_cast<const vtkEventDataForDevice*>(e);
126 return (this->Device == vtkEventDataDevice::Any || edd->Device == vtkEventDataDevice::Any ||
127 this->Device == edd->Device) &&
128 (this->Input == vtkEventDataDeviceInput::Any || edd->Input == vtkEventDataDeviceInput::Any ||
129 this->Input == edd->Input) &&
130 (this->Action == vtkEventDataAction::Any || edd->Action == vtkEventDataAction::Any ||
131 this->Action == edd->Action);
132 }
133
134 vtkEventDataForDevice()
135 {
136 this->Device = vtkEventDataDevice::Unknown;
137 this->Input = vtkEventDataDeviceInput::Unknown;
138 this->Action = vtkEventDataAction::Unknown;
139 }
140 ~vtkEventDataForDevice() override = default;
141
142 private:
143 vtkEventDataForDevice(const vtkEventData& c) = delete;
144 void operator=(const vtkEventDataForDevice&) = delete;
145 };
146
147 // a subclass for events that have a 3D world position
148 // direction and orientation.
149 class vtkEventDataDevice3D : public vtkEventDataForDevice
150 {
151 public:
152 vtkTypeMacro(vtkEventDataDevice3D, vtkEventDataForDevice);
153 static vtkEventDataDevice3D* New()
154 {
155 vtkEventDataDevice3D* ret = new vtkEventDataDevice3D;
156 ret->InitializeObjectBase();
157 return ret;
158 }
159
160 vtkEventDataDevice3D* GetAsEventDataDevice3D() override { return this; }
161
162 void GetWorldPosition(double v[3]) const
163 {
164 v[0] = this->WorldPosition[0];
165 v[1] = this->WorldPosition[1];
166 v[2] = this->WorldPosition[2];
167 }
168 const double* GetWorldPosition() const VTK_SIZEHINT(3) { return this->WorldPosition; }
169 void SetWorldPosition(const double p[3])
170 {
171 this->WorldPosition[0] = p[0];
172 this->WorldPosition[1] = p[1];
173 this->WorldPosition[2] = p[2];
174 }
175
176 void GetWorldDirection(double v[3]) const
177 {
178 v[0] = this->WorldDirection[0];
179 v[1] = this->WorldDirection[1];
180 v[2] = this->WorldDirection[2];
181 }
182 const double* GetWorldDirection() const VTK_SIZEHINT(3) { return this->WorldDirection; }
183 void SetWorldDirection(const double p[3])
184 {
185 this->WorldDirection[0] = p[0];
186 this->WorldDirection[1] = p[1];
187 this->WorldDirection[2] = p[2];
188 }
189
190 void GetWorldOrientation(double v[4]) const
191 {
192 v[0] = this->WorldOrientation[0];
193 v[1] = this->WorldOrientation[1];
194 v[2] = this->WorldOrientation[2];
195 v[3] = this->WorldOrientation[3];
196 }
197 const double* GetWorldOrientation() const VTK_SIZEHINT(4) { return this->WorldOrientation; }
198 void SetWorldOrientation(const double p[4])
199 {
200 this->WorldOrientation[0] = p[0];
201 this->WorldOrientation[1] = p[1];
202 this->WorldOrientation[2] = p[2];
203 this->WorldOrientation[3] = p[3];
204 }
205
206 void GetTrackPadPosition(double v[2]) const
207 {
208 v[0] = this->TrackPadPosition[0];
209 v[1] = this->TrackPadPosition[1];
210 }
211 const double* GetTrackPadPosition() const VTK_SIZEHINT(2) { return this->TrackPadPosition; }
212 void SetTrackPadPosition(const double p[2])
213 {
214 this->TrackPadPosition[0] = p[0];
215 this->TrackPadPosition[1] = p[1];
216 }
217 void SetTrackPadPosition(double x, double y)
218 {
219 this->TrackPadPosition[0] = x;
220 this->TrackPadPosition[1] = y;
221 }
222
223 protected:
224 double WorldPosition[3];
225 double WorldOrientation[4];
226 double WorldDirection[3];
227 double TrackPadPosition[2];
228
229 vtkEventDataDevice3D() = default;
230 ~vtkEventDataDevice3D() override = default;
231
232 private:
233 vtkEventDataDevice3D(const vtkEventDataDevice3D& c) = delete;
234 void operator=(const vtkEventDataDevice3D&) = delete;
235 };
236
237 VTK_ABI_NAMESPACE_END
238 #endif
239
240 // VTK-HeaderTest-Exclude: vtkEventData.h
vtkEventDataDevice3D
Definition: vtkEventData.h:150
vtkEventDataDevice3D::SetWorldDirection
void SetWorldDirection(const double p[3])
Definition: vtkEventData.h:183
vtkEventDataDevice3D::WorldPosition
double WorldPosition[3]
Definition: vtkEventData.h:224
vtkEventDataDevice3D::GetAsEventDataDevice3D
vtkEventDataDevice3D * GetAsEventDataDevice3D() override
Definition: vtkEventData.h:160
vtkEventDataDevice3D::TrackPadPosition
double TrackPadPosition[2]
Definition: vtkEventData.h:227
vtkEventDataDevice3D::SetTrackPadPosition
void SetTrackPadPosition(const double p[2])
Definition: vtkEventData.h:212
vtkEventDataDevice3D::WorldOrientation
double WorldOrientation[4]
Definition: vtkEventData.h:225
vtkEventDataDevice3D::SetWorldOrientation
void SetWorldOrientation(const double p[4])
Definition: vtkEventData.h:198
vtkEventDataDevice3D::WorldDirection
double WorldDirection[3]
Definition: vtkEventData.h:226
vtkEventDataDevice3D::GetTrackPadPosition
void GetTrackPadPosition(double v[2]) const
Definition: vtkEventData.h:206
vtkEventDataDevice3D::SetTrackPadPosition
void SetTrackPadPosition(double x, double y)
Definition: vtkEventData.h:217
vtkEventDataDevice3D::GetTrackPadPosition
const double * GetTrackPadPosition() const
Definition: vtkEventData.h:211
vtkEventDataDevice3D::GetWorldDirection
const double * GetWorldDirection() const
Definition: vtkEventData.h:182
vtkEventDataDevice3D::GetWorldOrientation
const double * GetWorldOrientation() const
Definition: vtkEventData.h:197
vtkEventDataDevice3D::vtkEventDataDevice3D
vtkEventDataDevice3D()=default
vtkEventDataDevice3D::GetWorldPosition
const double * GetWorldPosition() const
Definition: vtkEventData.h:168
vtkEventDataDevice3D::GetWorldPosition
void GetWorldPosition(double v[3]) const
Definition: vtkEventData.h:162
vtkEventDataDevice3D::New
static vtkEventDataDevice3D * New()
Definition: vtkEventData.h:153
vtkEventDataDevice3D::SetWorldPosition
void SetWorldPosition(const double p[3])
Definition: vtkEventData.h:169
vtkEventDataDevice3D::GetWorldOrientation
void GetWorldOrientation(double v[4]) const
Definition: vtkEventData.h:190
vtkEventDataDevice3D::GetWorldDirection
void GetWorldDirection(double v[3]) const
Definition: vtkEventData.h:176
vtkEventDataDevice3D::~vtkEventDataDevice3D
~vtkEventDataDevice3D() override=default
vtkEventDataForDevice
Definition: vtkEventData.h:92
vtkEventDataForDevice::SetAction
void SetAction(vtkEventDataAction v)
Definition: vtkEventData.h:108
vtkEventDataForDevice::~vtkEventDataForDevice
~vtkEventDataForDevice() override=default
vtkEventDataForDevice::SetInput
void SetInput(vtkEventDataDeviceInput v)
Definition: vtkEventData.h:107
vtkEventDataForDevice::Input
vtkEventDataDeviceInput Input
Definition: vtkEventData.h:120
vtkEventDataForDevice::Equivalent
bool Equivalent(const vtkEventData *e) const override
Definition: vtkEventData.h:123
vtkEventDataForDevice::Action
vtkEventDataAction Action
Definition: vtkEventData.h:121
vtkEventDataForDevice::GetDevice
vtkEventDataDevice GetDevice() const
Definition: vtkEventData.h:102
vtkEventDataForDevice::Device
vtkEventDataDevice Device
Definition: vtkEventData.h:119
vtkEventDataForDevice::GetInput
vtkEventDataDeviceInput GetInput() const
Definition: vtkEventData.h:103
vtkEventDataForDevice::DeviceMatches
bool DeviceMatches(vtkEventDataDevice val)
Definition: vtkEventData.h:110
vtkEventDataForDevice::GetAsEventDataForDevice
vtkEventDataForDevice * GetAsEventDataForDevice() override
Definition: vtkEventData.h:116
vtkEventDataForDevice::GetAction
vtkEventDataAction GetAction() const
Definition: vtkEventData.h:104
vtkEventDataForDevice::vtkEventDataForDevice
vtkEventDataForDevice()
Definition: vtkEventData.h:134
vtkEventDataForDevice::SetDevice
void SetDevice(vtkEventDataDevice v)
Definition: vtkEventData.h:106
vtkEventDataForDevice::New
static vtkEventDataForDevice * New()
Definition: vtkEventData.h:95
vtkEventData
Definition: vtkEventData.h:58
vtkEventData::SetType
void SetType(int val)
Definition: vtkEventData.h:63
vtkEventData::vtkEventData
vtkEventData()=default
vtkEventData::Equivalent
virtual bool Equivalent(const vtkEventData *ed) const =0
vtkEventData::Type
int Type
Definition: vtkEventData.h:83
vtkEventData::GetType
int GetType() const
Definition: vtkEventData.h:62
vtkEventData::GetAsEventDataForDevice
virtual vtkEventDataForDevice * GetAsEventDataForDevice()
Definition: vtkEventData.h:72
vtkEventData::operator==
bool operator==(const vtkEventData &a) const
Definition: vtkEventData.h:66
vtkEventData::~vtkEventData
~vtkEventData() override=default
vtkEventData::GetAsEventDataDevice3D
virtual vtkEventDataDevice3D * GetAsEventDataDevice3D()
Definition: vtkEventData.h:73
vtkEventData::vtkBaseTypeMacro
vtkBaseTypeMacro(vtkEventData, vtkObjectBase)
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:72
vtkObjectBase::InitializeObjectBase
void InitializeObjectBase()
vtkCommand.h
vtkEventDataDevice
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:15
vtkEventDataDevice::NumberOfDevices
@ NumberOfDevices
vtkEventDataDevice::RightController
@ RightController
vtkEventDataDevice::Unknown
@ Unknown
vtkEventDataDevice::GenericTracker
@ GenericTracker
vtkEventDataDevice::HeadMountedDisplay
@ HeadMountedDisplay
vtkEventDataDevice::Any
@ Any
vtkEventDataDevice::LeftController
@ LeftController
vtkEventDataNumberOfDevices
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:25
vtkEventDataAction
vtkEventDataAction
Definition: vtkEventData.h:44
vtkEventDataAction::Press
@ Press
vtkEventDataAction::NumberOfActions
@ NumberOfActions
vtkEventDataAction::Untouch
@ Untouch
vtkEventDataAction::Unknown
@ Unknown
vtkEventDataAction::Release
@ Release
vtkEventDataAction::Any
@ Any
vtkEventDataAction::Touch
@ Touch
vtkEventDataDeviceInput
vtkEventDataDeviceInput
Definition: vtkEventData.h:29
vtkEventDataDeviceInput::Joystick
@ Joystick
vtkEventDataDeviceInput::ApplicationMenu
@ ApplicationMenu
vtkEventDataDeviceInput::NumberOfInputs
@ NumberOfInputs
vtkEventDataDeviceInput::Unknown
@ Unknown
vtkEventDataDeviceInput::TrackPad
@ TrackPad
vtkEventDataDeviceInput::Grip
@ Grip
vtkEventDataDeviceInput::Any
@ Any
vtkEventDataDeviceInput::Trigger
@ Trigger
vtkEventDataNumberOfInputs
const int vtkEventDataNumberOfInputs
Definition: vtkEventData.h:40
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:36