Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLAbstractWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Copyright (c) ProxSim ltd., Kwun Tong, Hong Kong. All Rights Reserved.
4 
5  See COPYRIGHT.txt
6  or http://www.slicer.org/copyright/copyright.txt for details.
7 
8  Unless required by applicable law or agreed to in writing, software
9  distributed under the License is distributed on an "AS IS" BASIS,
10  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  See the License for the specific language governing permissions and
12  limitations under the License.
13 
14  This file was originally developed by Davide Punzo, punzodavide@hotmail.it,
15  and development was supported by ProxSim ltd.
16 
17 =========================================================================*/
18 
41 #ifndef vtkMRMLAbstractWidget_h
42 #define vtkMRMLAbstractWidget_h
43 
44 #include "vtkMRMLDisplayableManagerExport.h"
45 #include "vtkObject.h"
46 #include "vtkSmartPointer.h"
47 #include "vtkWeakPointer.h"
48 #include <vector>
49 
54 class vtkMRMLNode;
56 class vtkRenderer;
57 class vtkWidgetEventTranslator;
58 
59 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLAbstractWidget : public vtkObject
60 {
61 public:
63  vtkTypeMacro(vtkMRMLAbstractWidget, vtkObject);
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65 
66  virtual void SetMRMLApplicationLogic(vtkMRMLApplicationLogic* applicationLogic);
67  vtkMRMLApplicationLogic* GetMRMLApplicationLogic();
68 
71  virtual void SetRepresentation(vtkMRMLAbstractWidgetRepresentation *r);
72 
74  virtual vtkMRMLAbstractWidgetRepresentation *GetRepresentation();
75 
77  virtual void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void *callData = nullptr);
78 
80  vtkSetMacro(WidgetState,int);
81 
83  vtkGetMacro(WidgetState,int);
84 
86  enum
87  {
88  WidgetStateAny, // this state is used for referring to any widget state (for defining event translations)
89  WidgetStateIdle, // mouse pointer is outside the widget, click does not do anything
90  WidgetStateOnWidget, // mouse pointer is over the widget, clicking will add a point or manipulate the line
91  WidgetStateTranslate, // mouse move transforms the entire widget
92  WidgetStateRotate, // mouse move transforms the entire widget
93  WidgetStateScale, // mouse move transforms the entire widget
94  WidgetStateUser // this is a starting index that can be used for widget-specific states
95  };
96 
99  {
108  // MRML events
109  WidgetEventPick, // generates a MRML Pick event (e.g., on left click)
110  WidgetEventJumpCursor, // jumps cursor to the selected position
111  WidgetEventAction, // generates a MRML Action event (e.g., left double-click)
112  WidgetEventCustomAction1, // generates a MRML CustomAction1 event (allows modules to define custom widget actions and get notification via MRML node event)
113  WidgetEventCustomAction2, // generates a MRML CustomAction1 event
114  WidgetEventCustomAction3, // generates a MRML CustomAction1 event
115  WidgetEventSelect, // change MRML node Selected attribute
116  WidgetEventUnselect, // change MRML node Selected attribute
117  WidgetEventToggleSelect, // change MRML node Selected attribute
118  // Other actions
119  WidgetEventMenu, // show context menu
120  WidgetEventReset, // reset widget to initial state (clear all points)
121  WidgetEventUser // this is a starting index that can be used for widget-specific events
122  };
123 
127  virtual bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2);
128 
131  virtual bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData);
132 
135  void SetEventTranslation(int widgetState, unsigned long interactionEvent, int modifiers, unsigned long widgetEvent);
136 
137  void SetEventTranslationClickAndDrag(int widgetState, unsigned long startInteractionEvent, int modifiers,
138  int widgetStateDragging, unsigned long widgetStartEvent, unsigned long widgetEndEvent);
139 
142  void SetEventTranslation(unsigned long interactionEvent, int modifiers, unsigned long widgetEvent);
143 
146  void SetKeyboardEventTranslation(int modifier, char keyCode, int repeatCount, const char* keySym, unsigned long widgetEvent);
147 
150  void SetKeyboardEventTranslation(int widgetState, int modifier, char keyCode, int repeatCount, const char* keySym, unsigned long widgetEvent);
151 
153  virtual unsigned long TranslateInteractionEventToWidgetEvent(vtkMRMLInteractionEventData* eventData);
154 
156  virtual void Leave(vtkMRMLInteractionEventData* eventData);
157 
158  void SetRenderer(vtkRenderer* renderer);
159  vtkRenderer* GetRenderer();
160 
161  vtkMRMLInteractionNode* GetInteractionNode();
162 
163  // Allows the widget to request a cursor shape
164  virtual int GetMouseCursor();
165 
166  // Allows the widget to request grabbing of all events (even when the mouse pointer moves out of view)
167  virtual bool GetGrabFocus();
168 
169  // Allows the widget to request interactive mode (faster updates)
170  virtual bool GetInteractive();
171 
172  // Allows the widget to request render
173  virtual bool GetNeedToRender();
174 
175  // Acknowledge rendering request (rendering completed)
176  virtual void NeedToRenderOff();
177 
178  virtual vtkWidgetEventTranslator* GetEventTranslator(int widgetState);
179 
180  virtual int GetNumberOfEventTranslators();
181 
182 protected:
184  ~vtkMRMLAbstractWidget() override;
185 
188  const char* GetAssociatedNodeID(vtkMRMLInteractionEventData* eventData);
189 
191  unsigned long TranslateInteractionEventToWidgetEvent(
192  vtkWidgetEventTranslator* translator, vtkMRMLInteractionEventData* eventData);
193 
194  vtkWeakPointer<vtkRenderer> Renderer;
195 
196  vtkWeakPointer<vtkMRMLApplicationLogic> ApplicationLogic;
197 
198  // Translates interaction event to widget event.
199  // In the future, a vector of event translators could be added
200  // (one for each state) to be able to define events
201  // that are only allowed in a specific state.
202  std::vector< vtkSmartPointer<vtkWidgetEventTranslator> > EventTranslators;
203 
205 
206  vtkSmartPointer<vtkMRMLAbstractWidgetRepresentation> WidgetRep;
207 
208 // bool NeedToRender;
209 
210 private:
212  void operator=(const vtkMRMLAbstractWidget&) = delete;
213 };
214 
215 #endif
std::vector< vtkSmartPointer< vtkWidgetEventTranslator > > EventTranslators
vtkSmartPointer< vtkMRMLAbstractWidgetRepresentation > WidgetRep
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D...
vtkWeakPointer< vtkRenderer > Renderer
Process interaction events to update state of MRML widget nodes.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
vtkWeakPointer< vtkMRMLApplicationLogic > ApplicationLogic