VTK  9.2.20221001
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
25 VTK_ABI_NAMESPACE_BEGIN
27 {
28  Unknown = -1,
33  Any,
35 };
36 
38 
39 // enumeration of possible device inputs
41 {
42  Unknown = -1,
43  Any,
44  Trigger,
45  TrackPad,
46  Joystick,
47  Grip,
50 };
51 
53 
54 // enumeration of actions that can happen
56 {
57  Unknown = -1,
58  Any,
59  Press,
60  Release,
61  Touch,
62  Untouch,
64 };
65 
68 
70 {
71 public:
73 
74  int GetType() const { return this->Type; }
75  void SetType(int val) { this->Type = val; }
76 
77  // are two events equivalent
78  bool operator==(const vtkEventData& a) const
79  {
80  return this->Type == a.Type && this->Equivalent(&a);
81  }
82 
83  // some convenience downcasts
84  virtual vtkEventDataForDevice* GetAsEventDataForDevice() { return nullptr; }
85  virtual vtkEventDataDevice3D* GetAsEventDataDevice3D() { return nullptr; }
86 
87 protected:
88  vtkEventData() = default;
89  ~vtkEventData() override = default;
90 
91  // subclasses override this to define their
92  // definition of equivalent
93  virtual bool Equivalent(const vtkEventData* ed) const = 0;
94 
95  int Type;
96 
97 private:
98  vtkEventData(const vtkEventData& c) = delete;
99 };
100 
101 // a subclass for events that may have one or more of
102 // device, input, and action
104 {
105 public:
108  {
110  ret->InitializeObjectBase();
111  return ret;
112  }
113 
114  vtkEventDataDevice GetDevice() const { return this->Device; }
115  vtkEventDataDeviceInput GetInput() const { return this->Input; }
116  vtkEventDataAction GetAction() const { return this->Action; }
117 
118  void SetDevice(vtkEventDataDevice v) { this->Device = v; }
119  void SetInput(vtkEventDataDeviceInput v) { this->Input = v; }
120  void SetAction(vtkEventDataAction v) { this->Action = v; }
121 
123  {
124  return val == this->Device || val == vtkEventDataDevice::Any ||
126  }
127 
128  vtkEventDataForDevice* GetAsEventDataForDevice() override { return this; }
129 
130 protected:
134 
135  bool Equivalent(const vtkEventData* e) const override
136  {
137  const vtkEventDataForDevice* edd = static_cast<const vtkEventDataForDevice*>(e);
138  return (this->Device == vtkEventDataDevice::Any || edd->Device == vtkEventDataDevice::Any ||
139  this->Device == edd->Device) &&
141  this->Input == edd->Input) &&
142  (this->Action == vtkEventDataAction::Any || edd->Action == vtkEventDataAction::Any ||
143  this->Action == edd->Action);
144  }
145 
147  {
148  this->Device = vtkEventDataDevice::Unknown;
149  this->Input = vtkEventDataDeviceInput::Unknown;
150  this->Action = vtkEventDataAction::Unknown;
151  }
152  ~vtkEventDataForDevice() override = default;
153 
154 private:
155  vtkEventDataForDevice(const vtkEventData& c) = delete;
156  void operator=(const vtkEventDataForDevice&) = delete;
157 };
158 
159 // a subclass for events that have a 3D world position
160 // direction and orientation.
162 {
163 public:
166  {
168  ret->InitializeObjectBase();
169  return ret;
170  }
171 
172  vtkEventDataDevice3D* GetAsEventDataDevice3D() override { return this; }
173 
174  void GetWorldPosition(double v[3]) const
175  {
176  v[0] = this->WorldPosition[0];
177  v[1] = this->WorldPosition[1];
178  v[2] = this->WorldPosition[2];
179  }
180  const double* GetWorldPosition() const VTK_SIZEHINT(3) { return this->WorldPosition; }
181  void SetWorldPosition(const double p[3])
182  {
183  this->WorldPosition[0] = p[0];
184  this->WorldPosition[1] = p[1];
185  this->WorldPosition[2] = p[2];
186  }
187 
188  void GetWorldDirection(double v[3]) const
189  {
190  v[0] = this->WorldDirection[0];
191  v[1] = this->WorldDirection[1];
192  v[2] = this->WorldDirection[2];
193  }
194  const double* GetWorldDirection() const VTK_SIZEHINT(3) { return this->WorldDirection; }
195  void SetWorldDirection(const double p[3])
196  {
197  this->WorldDirection[0] = p[0];
198  this->WorldDirection[1] = p[1];
199  this->WorldDirection[2] = p[2];
200  }
201 
202  void GetWorldOrientation(double v[4]) const
203  {
204  v[0] = this->WorldOrientation[0];
205  v[1] = this->WorldOrientation[1];
206  v[2] = this->WorldOrientation[2];
207  v[3] = this->WorldOrientation[3];
208  }
209  const double* GetWorldOrientation() const VTK_SIZEHINT(4) { return this->WorldOrientation; }
210  void SetWorldOrientation(const double p[4])
211  {
212  this->WorldOrientation[0] = p[0];
213  this->WorldOrientation[1] = p[1];
214  this->WorldOrientation[2] = p[2];
215  this->WorldOrientation[3] = p[3];
216  }
217 
218  void GetTrackPadPosition(double v[2]) const
219  {
220  v[0] = this->TrackPadPosition[0];
221  v[1] = this->TrackPadPosition[1];
222  }
223  const double* GetTrackPadPosition() const VTK_SIZEHINT(2) { return this->TrackPadPosition; }
224  void SetTrackPadPosition(const double p[2])
225  {
226  this->TrackPadPosition[0] = p[0];
227  this->TrackPadPosition[1] = p[1];
228  }
229  void SetTrackPadPosition(double x, double y)
230  {
231  this->TrackPadPosition[0] = x;
232  this->TrackPadPosition[1] = y;
233  }
234 
235 protected:
236  double WorldPosition[3];
237  double WorldOrientation[4];
238  double WorldDirection[3];
239  double TrackPadPosition[2];
240 
241  vtkEventDataDevice3D() = default;
242  ~vtkEventDataDevice3D() override = default;
243 
244 private:
245  vtkEventDataDevice3D(const vtkEventDataDevice3D& c) = delete;
246  void operator=(const vtkEventDataDevice3D&) = delete;
247 };
248 
249 VTK_ABI_NAMESPACE_END
250 #endif
251 
252 // VTK-HeaderTest-Exclude: vtkEventData.h
void SetWorldDirection(const double p[3])
Definition: vtkEventData.h:195
vtkEventDataDevice3D * GetAsEventDataDevice3D() override
Definition: vtkEventData.h:172
double TrackPadPosition[2]
Definition: vtkEventData.h:239
void SetTrackPadPosition(const double p[2])
Definition: vtkEventData.h:224
double WorldOrientation[4]
Definition: vtkEventData.h:237
void SetWorldOrientation(const double p[4])
Definition: vtkEventData.h:210
double WorldDirection[3]
Definition: vtkEventData.h:238
void GetTrackPadPosition(double v[2]) const
Definition: vtkEventData.h:218
void SetTrackPadPosition(double x, double y)
Definition: vtkEventData.h:229
const double * GetTrackPadPosition() const
Definition: vtkEventData.h:223
const double * GetWorldDirection() const
Definition: vtkEventData.h:194
const double * GetWorldOrientation() const
Definition: vtkEventData.h:209
vtkEventDataDevice3D()=default
const double * GetWorldPosition() const
Definition: vtkEventData.h:180
void GetWorldPosition(double v[3]) const
Definition: vtkEventData.h:174
static vtkEventDataDevice3D * New()
Definition: vtkEventData.h:165
void SetWorldPosition(const double p[3])
Definition: vtkEventData.h:181
void GetWorldOrientation(double v[4]) const
Definition: vtkEventData.h:202
void GetWorldDirection(double v[3]) const
Definition: vtkEventData.h:188
~vtkEventDataDevice3D() override=default
void SetAction(vtkEventDataAction v)
Definition: vtkEventData.h:120
~vtkEventDataForDevice() override=default
void SetInput(vtkEventDataDeviceInput v)
Definition: vtkEventData.h:119
vtkEventDataDeviceInput Input
Definition: vtkEventData.h:132
bool Equivalent(const vtkEventData *e) const override
Definition: vtkEventData.h:135
vtkEventDataAction Action
Definition: vtkEventData.h:133
vtkEventDataDevice GetDevice() const
Definition: vtkEventData.h:114
vtkEventDataDevice Device
Definition: vtkEventData.h:131
vtkEventDataDeviceInput GetInput() const
Definition: vtkEventData.h:115
bool DeviceMatches(vtkEventDataDevice val)
Definition: vtkEventData.h:122
vtkEventDataForDevice * GetAsEventDataForDevice() override
Definition: vtkEventData.h:128
vtkEventDataAction GetAction() const
Definition: vtkEventData.h:116
void SetDevice(vtkEventDataDevice v)
Definition: vtkEventData.h:118
static vtkEventDataForDevice * New()
Definition: vtkEventData.h:107
void SetType(int val)
Definition: vtkEventData.h:75
vtkEventData()=default
virtual bool Equivalent(const vtkEventData *ed) const =0
int GetType() const
Definition: vtkEventData.h:74
virtual vtkEventDataForDevice * GetAsEventDataForDevice()
Definition: vtkEventData.h:84
bool operator==(const vtkEventData &a) const
Definition: vtkEventData.h:78
~vtkEventData() override=default
virtual vtkEventDataDevice3D * GetAsEventDataDevice3D()
Definition: vtkEventData.h:85
vtkBaseTypeMacro(vtkEventData, vtkObjectBase)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:75
void InitializeObjectBase()
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:27
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:37
vtkEventDataAction
Definition: vtkEventData.h:56
vtkEventDataDeviceInput
Definition: vtkEventData.h:41
const int vtkEventDataNumberOfInputs
Definition: vtkEventData.h:52
#define VTK_SIZEHINT(...)