VTK  9.4.20241010
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
13VTK_ABI_NAMESPACE_BEGIN
15{
16 Unknown = -1,
21 Any,
23};
24
26
27// enumeration of possible device inputs
29{
30 Unknown = -1,
31 Any,
32 Trigger,
35 Grip,
38};
39
41
42// enumeration of actions that can happen
44{
45 Unknown = -1,
46 Any,
47 Press,
48 Release,
49 Touch,
50 Untouch,
52};
53
56
58{
59public:
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
75protected:
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
85private:
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
92{
93public:
96 {
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; }
108 void SetAction(vtkEventDataAction v) { this->Action = v; }
109
111 {
112 return val == this->Device || val == vtkEventDataDevice::Any ||
114 }
115
117
118protected:
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) &&
129 this->Input == edd->Input) &&
130 (this->Action == vtkEventDataAction::Any || edd->Action == vtkEventDataAction::Any ||
131 this->Action == edd->Action);
132 }
133
135 {
136 this->Device = vtkEventDataDevice::Unknown;
138 this->Action = vtkEventDataAction::Unknown;
139 }
140 ~vtkEventDataForDevice() override = default;
141
142private:
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.
150{
151public:
154 {
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
223protected:
224 double WorldPosition[3];
226 double WorldDirection[3];
228
230 ~vtkEventDataDevice3D() override = default;
231
232private:
234 void operator=(const vtkEventDataDevice3D&) = delete;
235};
236
237VTK_ABI_NAMESPACE_END
238#endif
239
240// VTK-HeaderTest-Exclude: vtkEventData.h
const double * GetTrackPadPosition() const
void SetWorldDirection(const double p[3])
void SetTrackPadPosition(const double p[2])
void SetWorldOrientation(const double p[4])
const double * GetWorldDirection() const
void GetTrackPadPosition(double v[2]) const
void SetTrackPadPosition(double x, double y)
const double * GetWorldOrientation() const
vtkEventDataDevice3D()=default
void GetWorldPosition(double v[3]) const
static vtkEventDataDevice3D * New()
vtkEventDataDevice3D * GetAsEventDataDevice3D() override
void SetWorldPosition(const double p[3])
const double * GetWorldPosition() const
void GetWorldOrientation(double v[4]) const
void GetWorldDirection(double v[3]) const
~vtkEventDataDevice3D() override=default
vtkEventDataForDevice * GetAsEventDataForDevice() override
void SetAction(vtkEventDataAction v)
~vtkEventDataForDevice() override=default
static vtkEventDataForDevice * New()
void SetInput(vtkEventDataDeviceInput v)
vtkEventDataDeviceInput Input
bool Equivalent(const vtkEventData *e) const override
vtkEventDataAction Action
vtkEventDataDevice GetDevice() const
vtkEventDataDevice Device
vtkEventDataDeviceInput GetInput() const
bool DeviceMatches(vtkEventDataDevice val)
vtkEventDataAction GetAction() const
void SetDevice(vtkEventDataDevice v)
void SetType(int val)
vtkEventData()=default
virtual bool Equivalent(const vtkEventData *ed) const =0
int GetType() const
bool operator==(const vtkEventData &a) const
~vtkEventData() override=default
virtual vtkEventDataForDevice * GetAsEventDataForDevice()
virtual vtkEventDataDevice3D * GetAsEventDataDevice3D()
vtkBaseTypeMacro(vtkEventData, vtkObjectBase)
abstract base class for most VTK objects
void InitializeObjectBase()
vtkEventDataDevice
platform-independent event data structures
const int vtkEventDataNumberOfDevices
vtkEventDataAction
vtkEventDataDeviceInput
const int vtkEventDataNumberOfInputs
#define VTK_SIZEHINT(...)