VTK  9.1.0
vtkEventData.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkEventData.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
19#ifndef vtkEventData_h
20#define vtkEventData_h
21
22#include "vtkCommand.h"
23
24// enumeration of possible devices
26{
27 Unknown = -1,
32 Any,
34};
35
37
38// enumeration of possible device inputs
40{
41 Unknown = -1,
42 Any,
43 Trigger,
46 Grip,
49};
50
52
53// enumeration of actions that can happen
55{
56 Unknown = -1,
57 Any,
58 Press,
59 Release,
60 Touch,
61 Untouch,
63};
64
67
69{
70public:
72
73 int GetType() const { return this->Type; }
74 void SetType(int val) { this->Type = val; }
75
76 // are two events equivalent
77 bool operator==(const vtkEventData& a) const
78 {
79 return this->Type == a.Type && this->Equivalent(&a);
80 }
81
82 // some convenience downcasts
83 virtual vtkEventDataForDevice* GetAsEventDataForDevice() { return nullptr; }
84 virtual vtkEventDataDevice3D* GetAsEventDataDevice3D() { return nullptr; }
85
86protected:
87 vtkEventData() = default;
88 ~vtkEventData() override = default;
89
90 // subclasses override this to define their
91 // definition of equivalent
92 virtual bool Equivalent(const vtkEventData* ed) const = 0;
93
94 int Type;
95
96private:
97 vtkEventData(const vtkEventData& c) = delete;
98};
99
100// a subclass for events that may have one or more of
101// device, input, and action
103{
104public:
107 {
110 return ret;
111 }
112
113 vtkEventDataDevice GetDevice() const { return this->Device; }
114 vtkEventDataDeviceInput GetInput() const { return this->Input; }
115 vtkEventDataAction GetAction() const { return this->Action; }
116
117 void SetDevice(vtkEventDataDevice v) { this->Device = v; }
119 void SetAction(vtkEventDataAction v) { this->Action = v; }
120
122 {
123 return val == this->Device || val == vtkEventDataDevice::Any ||
124 this->Device == vtkEventDataDevice::Any;
125 }
126
128
129protected:
133
134 bool Equivalent(const vtkEventData* e) const override
135 {
136 const vtkEventDataForDevice* edd = static_cast<const vtkEventDataForDevice*>(e);
137 return (this->Device == vtkEventDataDevice::Any || edd->Device == vtkEventDataDevice::Any ||
138 this->Device == edd->Device) &&
139 (this->Input == vtkEventDataDeviceInput::Any || edd->Input == vtkEventDataDeviceInput::Any ||
140 this->Input == edd->Input) &&
141 (this->Action == vtkEventDataAction::Any || edd->Action == vtkEventDataAction::Any ||
142 this->Action == edd->Action);
143 }
144
146 {
147 this->Device = vtkEventDataDevice::Unknown;
148 this->Input = vtkEventDataDeviceInput::Unknown;
149 this->Action = vtkEventDataAction::Unknown;
150 }
151 ~vtkEventDataForDevice() override = default;
152
153private:
154 vtkEventDataForDevice(const vtkEventData& c) = delete;
155 void operator=(const vtkEventDataForDevice&) = delete;
156};
157
158// a subclass for events that have a 3D world position
159// direction and orientation.
161{
162public:
165 {
168 return ret;
169 }
170
171 vtkEventDataDevice3D* GetAsEventDataDevice3D() override { return this; }
172
173 void GetWorldPosition(double v[3]) const
174 {
175 v[0] = this->WorldPosition[0];
176 v[1] = this->WorldPosition[1];
177 v[2] = this->WorldPosition[2];
178 }
179 const double* GetWorldPosition() const VTK_SIZEHINT(3) { return this->WorldPosition; }
180 void SetWorldPosition(const double p[3])
181 {
182 this->WorldPosition[0] = p[0];
183 this->WorldPosition[1] = p[1];
184 this->WorldPosition[2] = p[2];
185 }
186
187 void GetWorldDirection(double v[3]) const
188 {
189 v[0] = this->WorldDirection[0];
190 v[1] = this->WorldDirection[1];
191 v[2] = this->WorldDirection[2];
192 }
193 const double* GetWorldDirection() const VTK_SIZEHINT(3) { return this->WorldDirection; }
194 void SetWorldDirection(const double p[3])
195 {
196 this->WorldDirection[0] = p[0];
197 this->WorldDirection[1] = p[1];
198 this->WorldDirection[2] = p[2];
199 }
200
201 void GetWorldOrientation(double v[4]) const
202 {
203 v[0] = this->WorldOrientation[0];
204 v[1] = this->WorldOrientation[1];
205 v[2] = this->WorldOrientation[2];
206 v[3] = this->WorldOrientation[3];
207 }
208 const double* GetWorldOrientation() const VTK_SIZEHINT(4) { return this->WorldOrientation; }
209 void SetWorldOrientation(const double p[4])
210 {
211 this->WorldOrientation[0] = p[0];
212 this->WorldOrientation[1] = p[1];
213 this->WorldOrientation[2] = p[2];
214 this->WorldOrientation[3] = p[3];
215 }
216
217 void GetTrackPadPosition(double v[2]) const
218 {
219 v[0] = this->TrackPadPosition[0];
220 v[1] = this->TrackPadPosition[1];
221 }
222 const double* GetTrackPadPosition() const VTK_SIZEHINT(2) { return this->TrackPadPosition; }
223 void SetTrackPadPosition(const double p[2])
224 {
225 this->TrackPadPosition[0] = p[0];
226 this->TrackPadPosition[1] = p[1];
227 }
228 void SetTrackPadPosition(double x, double y)
229 {
230 this->TrackPadPosition[0] = x;
231 this->TrackPadPosition[1] = y;
232 }
233
234protected:
235 double WorldPosition[3];
237 double WorldDirection[3];
239
241 ~vtkEventDataDevice3D() override = default;
242
243private:
245 void operator=(const vtkEventDataDevice3D&) = delete;
246};
247
248#endif
249
250// VTK-HeaderTest-Exclude: vtkEventData.h
const double * GetTrackPadPosition() const
Definition: vtkEventData.h:222
void SetWorldDirection(const double p[3])
Definition: vtkEventData.h:194
double TrackPadPosition[2]
Definition: vtkEventData.h:238
void SetTrackPadPosition(const double p[2])
Definition: vtkEventData.h:223
double WorldOrientation[4]
Definition: vtkEventData.h:236
void SetWorldOrientation(const double p[4])
Definition: vtkEventData.h:209
const double * GetWorldDirection() const
Definition: vtkEventData.h:193
double WorldDirection[3]
Definition: vtkEventData.h:237
void GetTrackPadPosition(double v[2]) const
Definition: vtkEventData.h:217
void SetTrackPadPosition(double x, double y)
Definition: vtkEventData.h:228
const double * GetWorldOrientation() const
Definition: vtkEventData.h:208
vtkEventDataDevice3D()=default
void GetWorldPosition(double v[3]) const
Definition: vtkEventData.h:173
static vtkEventDataDevice3D * New()
Definition: vtkEventData.h:164
vtkEventDataDevice3D * GetAsEventDataDevice3D() override
Definition: vtkEventData.h:171
void SetWorldPosition(const double p[3])
Definition: vtkEventData.h:180
const double * GetWorldPosition() const
Definition: vtkEventData.h:179
void GetWorldOrientation(double v[4]) const
Definition: vtkEventData.h:201
void GetWorldDirection(double v[3]) const
Definition: vtkEventData.h:187
~vtkEventDataDevice3D() override=default
vtkEventDataForDevice * GetAsEventDataForDevice() override
Definition: vtkEventData.h:127
void SetAction(vtkEventDataAction v)
Definition: vtkEventData.h:119
~vtkEventDataForDevice() override=default
static vtkEventDataForDevice * New()
Definition: vtkEventData.h:106
void SetInput(vtkEventDataDeviceInput v)
Definition: vtkEventData.h:118
vtkEventDataDeviceInput Input
Definition: vtkEventData.h:131
bool Equivalent(const vtkEventData *e) const override
Definition: vtkEventData.h:134
vtkEventDataAction Action
Definition: vtkEventData.h:132
vtkEventDataDevice GetDevice() const
Definition: vtkEventData.h:113
vtkEventDataDevice Device
Definition: vtkEventData.h:130
vtkEventDataDeviceInput GetInput() const
Definition: vtkEventData.h:114
bool DeviceMatches(vtkEventDataDevice val)
Definition: vtkEventData.h:121
vtkEventDataAction GetAction() const
Definition: vtkEventData.h:115
void SetDevice(vtkEventDataDevice v)
Definition: vtkEventData.h:117
void SetType(int val)
Definition: vtkEventData.h:74
vtkEventData()=default
virtual bool Equivalent(const vtkEventData *ed) const =0
int GetType() const
Definition: vtkEventData.h:73
bool operator==(const vtkEventData &a) const
Definition: vtkEventData.h:77
~vtkEventData() override=default
virtual vtkEventDataForDevice * GetAsEventDataForDevice()
Definition: vtkEventData.h:83
virtual vtkEventDataDevice3D * GetAsEventDataDevice3D()
Definition: vtkEventData.h:84
vtkBaseTypeMacro(vtkEventData, vtkObjectBase)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
void InitializeObjectBase()
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36
vtkEventDataAction
Definition: vtkEventData.h:55
vtkEventDataDeviceInput
Definition: vtkEventData.h:40
const int vtkEventDataNumberOfInputs
Definition: vtkEventData.h:51
#define VTK_SIZEHINT(...)