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
14 #ifndef vtkSMVRInteractorStyleProxy_h
15 #define vtkSMVRInteractorStyleProxy_h
16 
17 #include "vtkCommand.h" // For UserEvent
18 #include "vtkPVIncubatorCAVEInteractionStylesModule.h" // for export macro
19 #include <vtkSMProxy.h>
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 class vtkCamera;
27 class vtkMatrix4x4;
28 class vtkPVXMLElement;
29 class vtkSMProxyLocator;
30 class vtkSMProxy;
33 class vtkStringList;
34 struct vtkVREvent;
35 
36 class VTKPVINCUBATORCAVEINTERACTIONSTYLES_EXPORT vtkSMVRInteractorStyleProxy : public vtkSMProxy
37 {
38 public:
41  void PrintSelf(ostream& os, vtkIndent indent) override;
42 
43  // Description:
44  // Get the vector size of the controlled property this style expects, e.g. a
45  // 4x4 matrix will be 16, a 3D vector will be 3, etc. This is used to limit
46  // the number of options presented to the user when prompting for a property.
47  // This is NOT checked internally by SetControlledPropertyName.
48  //
49  // A value of -1 means no filtering will be done, and all available properties
50  // will be shown.
51  virtual int GetControlledPropertySize() { return -1; }
52 
53  virtual void SetControlledProxy(vtkSMProxy*);
54  vtkGetObjectMacro(ControlledProxy, vtkSMProxy);
55 
56  vtkSetStringMacro(ControlledPropertyName);
57  vtkGetStringMacro(ControlledPropertyName);
58 
59  // An internal interactor style proxy should not be shown in the
60  // UI, but can still be used by the CAVEInteraction plugin for
61  // internal purposes.
62  vtkSetMacro(IsInternal, bool);
63  vtkGetMacro(IsInternal, bool);
64  vtkBooleanMacro(IsInternal, bool);
65 
66  virtual bool HandleEvent(const vtkVREvent& event);
67 
72  virtual bool Update();
73 
74  // Description:
75  // Get a list of defined roles for each output type.
76  void GetValuatorRoles(vtkStringList*);
77  void GetButtonRoles(vtkStringList*);
78  void GetTrackerRoles(vtkStringList*);
79 
80  // Description:
81  // Get the number of roles defined for each output type.
82  int GetNumberOfValuatorRoles();
83  int GetNumberOfButtonRoles();
84  int GetNumberOfTrackerRoles();
85 
86  // Description:
87  // Get the role of the input with the given name. If the name is not
88  // set or recognized, an empty string is returned.
89  std::string GetButtonRole(const std::string& name);
90  std::string GetTrackerRole(const std::string& name);
91 
92  // Description:
93  // Valuators are special in that data from all channels is
94  // delivered in an array in a single event. This method allows
95  // finding that index for any named role which the user has
96  // bound to an event
97  unsigned int GetChannelIndexForValuatorRole(const std::string& role);
98 
99  // Description:
100  // Add a new input role to the interactor style.
101  void AddValuatorRole(const std::string& role);
102  void AddButtonRole(const std::string& role);
103  void AddTrackerRole(const std::string& role);
104 
105  void ClearAllRoles();
106 
107  // Description:
108  // Set/Get the name of the input that fulfills the specified role.
109  bool SetValuatorName(const std::string& role, const std::string& name);
110  std::string GetValuatorName(const std::string& role);
111  bool SetButtonName(const std::string& role, const std::string& name);
112  std::string GetButtonName(const std::string& role);
113  bool SetTrackerName(const std::string& role, const std::string& name);
114  std::string GetTrackerName(const std::string& role);
115 
117  virtual bool Configure(vtkPVXMLElement* child, vtkSMProxyLocator*);
118 
120  virtual vtkPVXMLElement* SaveConfiguration();
121 
122  enum
123  {
124  INTERACTOR_STYLE_REQUEST_CONFIGURE = vtkCommand::UserEvent + 7370,
125  INTERACTOR_STYLE_NAVIGATION = vtkCommand::UserEvent + 7371
126  };
127 
128  // Description:
129  // Get active objects or return nullptr
130  static vtkSMRenderViewProxy* GetActiveViewProxy();
131  static vtkCamera* GetActiveCamera();
132 
133  // Description:
134  // Get/Set the matrix used to navigate the scene. If no proxy argument
135  // is provided, the active view proxy will be used.
136  vtkMatrix4x4* GetNavigationMatrix(vtkSMRenderViewProxy* proxy = nullptr);
137  void SetNavigationMatrix(vtkMatrix4x4*, vtkSMRenderViewProxy* proxy = nullptr);
138 
139  // Description:
140  // Update a matrix property on a proxy. If the proxy is a render view
141  // proxy and the property name is "ModelTransformMatrix", then internally
142  // the steps required for proper navigation are taken (inverting the matrix
143  // and storing it in the PhysicalToWorldMatrix, as well as invoking the
144  // navigation event).
145  void UpdateMatrixProperty(vtkSMProxy* proxy, const char* propertyName, vtkMatrix4x4* matrix);
146 
147  typedef std::map<std::string, std::string> StringMap;
148  typedef std::map<std::string, StringMap> StringMapMap;
149 
150  void SetValuatorLookupTable(std::shared_ptr<StringMapMap>);
151 
152 protected:
154  virtual ~vtkSMVRInteractorStyleProxy();
155 
156  virtual void HandleButton(const vtkVREvent& event);
157  virtual void HandleValuator(const vtkVREvent& event);
158  virtual void HandleTracker(const vtkVREvent& event);
159 
160  static std::vector<std::string> Tokenize(std::string input);
161 
164 
165  StringMap Valuators;
166  StringMap Buttons;
167  StringMap Trackers;
168  void MapKeysToStringList(const StringMap& source, vtkStringList* target);
169  bool SetValueInMap(StringMap& map_, const std::string& key, const std::string& value);
170  std::string GetValueInMap(const StringMap& map_, const std::string& key);
171  std::string GetKeyInMap(const StringMap& map_, const std::string& value);
172 
174 
175  std::shared_ptr<StringMapMap> valuatorLookupTable;
176 
177 private:
179  void operator=(const vtkSMVRInteractorStyleProxy&) = delete;
180 
181  vtkNew<vtkMatrix4x4> NavigationMatrix;
182 };
183 
184 #endif
the base class for all interactor styles
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:20
std::shared_ptr< StringMapMap > valuatorLookupTable