vtkSMVRInteractorStyleProxy.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef vtkSMVRInteractorStyleProxy_h
5 #define vtkSMVRInteractorStyleProxy_h
6 
7 #include "vtkCommand.h" // For UserEvent
8 #include "vtkPVIncubatorCAVEInteractionStylesModule.h" // for export macro
9 #include <vtkSMProxy.h>
10 
11 #include <map>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 class vtkCamera;
17 class vtkMatrix4x4;
18 class vtkPVXMLElement;
19 class vtkSMProxyLocator;
20 class vtkSMProxy;
23 class vtkStringList;
24 struct vtkVREvent;
25 
26 class VTKPVINCUBATORCAVEINTERACTIONSTYLES_EXPORT vtkSMVRInteractorStyleProxy : public vtkSMProxy
27 {
28 public:
31  void PrintSelf(ostream& os, vtkIndent indent) override;
32 
33  // Description:
34  // Get the vector size of the controlled property this style expects, e.g. a
35  // 4x4 matrix will be 16, a 3D vector will be 3, etc. This is used to limit
36  // the number of options presented to the user when prompting for a property.
37  // This is NOT checked internally by SetControlledPropertyName.
38  //
39  // A value of -1 means no filtering will be done, and all available properties
40  // will be shown.
41  virtual int GetControlledPropertySize() { return -1; }
42 
43  virtual void SetControlledProxy(vtkSMProxy*);
44  vtkGetObjectMacro(ControlledProxy, vtkSMProxy);
45 
46  vtkSetStringMacro(ControlledPropertyName);
47  vtkGetStringMacro(ControlledPropertyName);
48 
49  // An internal interactor style proxy should not be shown in the
50  // UI, but can still be used by the CAVEInteraction plugin for
51  // internal purposes.
52  vtkSetMacro(IsInternal, bool);
53  vtkGetMacro(IsInternal, bool);
54  vtkBooleanMacro(IsInternal, bool);
55 
56  virtual bool HandleEvent(const vtkVREvent& event);
57 
62  virtual bool Update();
63 
64  // Description:
65  // Get a list of defined roles for each output type.
66  void GetValuatorRoles(vtkStringList*);
67  void GetButtonRoles(vtkStringList*);
68  void GetTrackerRoles(vtkStringList*);
69 
70  // Description:
71  // Get the number of roles defined for each output type.
72  int GetNumberOfValuatorRoles();
73  int GetNumberOfButtonRoles();
74  int GetNumberOfTrackerRoles();
75 
76  // Description:
77  // Get the role of the input with the given name. If the name is not
78  // set or recognized, an empty string is returned.
79  std::string GetButtonRole(const std::string& name);
80  std::string GetTrackerRole(const std::string& name);
81 
82  // Description:
83  // Valuators are special in that data from all channels is
84  // delivered in an array in a single event. This method allows
85  // finding that index for any named role which the user has
86  // bound to an event
87  unsigned int GetChannelIndexForValuatorRole(const std::string& role);
88 
89  // Description:
90  // Add a new input role to the interactor style.
91  void AddValuatorRole(const std::string& role);
92  void AddButtonRole(const std::string& role);
93  void AddTrackerRole(const std::string& role);
94 
95  void ClearAllRoles();
96 
97  // Description:
98  // Set/Get the name of the input that fulfills the specified role.
99  bool SetValuatorName(const std::string& role, const std::string& name);
100  std::string GetValuatorName(const std::string& role);
101  bool SetButtonName(const std::string& role, const std::string& name);
102  std::string GetButtonName(const std::string& role);
103  bool SetTrackerName(const std::string& role, const std::string& name);
104  std::string GetTrackerName(const std::string& role);
105 
107  virtual bool Configure(vtkPVXMLElement* child, vtkSMProxyLocator*);
108 
110  virtual vtkPVXMLElement* SaveConfiguration();
111 
112  enum
113  {
114  INTERACTOR_STYLE_REQUEST_CONFIGURE = vtkCommand::UserEvent + 7370,
115  INTERACTOR_STYLE_NAVIGATION = vtkCommand::UserEvent + 7371
116  };
117 
118  // Description:
119  // Get active objects or return nullptr
120  static vtkSMRenderViewProxy* GetActiveViewProxy();
121  static vtkCamera* GetActiveCamera();
122 
123  // Description:
124  // Get/Set the matrix used to navigate the scene.
125  vtkMatrix4x4* GetNavigationMatrix();
126  void SetNavigationMatrix(vtkMatrix4x4*);
127 
128  typedef std::map<std::string, std::string> StringMap;
129  typedef std::map<std::string, StringMap> StringMapMap;
130 
131  void SetValuatorLookupTable(std::shared_ptr<StringMapMap>);
132 
133 protected:
135  virtual ~vtkSMVRInteractorStyleProxy();
136 
137  virtual void HandleButton(const vtkVREvent& event);
138  virtual void HandleValuator(const vtkVREvent& event);
139  virtual void HandleTracker(const vtkVREvent& event);
140 
141  static std::vector<std::string> Tokenize(std::string input);
142 
145 
146  StringMap Valuators;
147  StringMap Buttons;
148  StringMap Trackers;
149  void MapKeysToStringList(const StringMap& source, vtkStringList* target);
150  bool SetValueInMap(StringMap& map_, const std::string& key, const std::string& value);
151  std::string GetValueInMap(const StringMap& map_, const std::string& key);
152  std::string GetKeyInMap(const StringMap& map_, const std::string& value);
153 
155 
156  std::shared_ptr<StringMapMap> valuatorLookupTable;
157 
158 private:
160  void operator=(const vtkSMVRInteractorStyleProxy&) = delete;
161 };
162 
163 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void Update()
std::map< std::string, std::string > StringMap
name
implementation for View that includes render window and renderers.
property representing a vector of doubles
static vtkSMProxy * New()
proxy for a VTK object(s) on a server
Definition: vtkSMProxy.h:140
is used to locate proxies referred to in state xmls while loading state files.
void operator=(const vtkSMProxy &)=delete
This is used by vtkPVXMLParser to represent an XML document starting at the root element.
std::map< std::string, StringMap > StringMapMap
Manages allocation and freeing for a string list.
Definition: vtkStringList.h:18
std::shared_ptr< StringMapMap > valuatorLookupTable