Slicer  5.0
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  {
94  WidgetStateUser
95  };
96 
99  {
108  // MRML events
111  WidgetEventAction, // generates a MRML Action event (e.g., left double-click)
121  // Other actions
124  WidgetEventUser
125  };
126 
130  virtual bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2);
131 
134  virtual bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData);
135 
138  void SetEventTranslation(int widgetState, unsigned long interactionEvent, int modifiers, unsigned long widgetEvent);
139 
140  void SetEventTranslationClickAndDrag(int widgetState, unsigned long startInteractionEvent, int modifiers,
141  int widgetStateDragging, unsigned long widgetStartEvent, unsigned long widgetEndEvent);
142 
145  void SetEventTranslation(unsigned long interactionEvent, int modifiers, unsigned long widgetEvent);
146 
149  void SetKeyboardEventTranslation(int modifier, char keyCode, int repeatCount, const char* keySym, unsigned long widgetEvent);
150 
153  void SetKeyboardEventTranslation(int widgetState, int modifier, char keyCode, int repeatCount, const char* keySym, unsigned long widgetEvent);
154 
156  virtual unsigned long TranslateInteractionEventToWidgetEvent(vtkMRMLInteractionEventData* eventData);
157 
159  virtual void Leave(vtkMRMLInteractionEventData* eventData);
160 
161  void SetRenderer(vtkRenderer* renderer);
162  vtkRenderer* GetRenderer();
163 
164  vtkMRMLInteractionNode* GetInteractionNode();
165 
166  // Allows the widget to request a cursor shape
167  virtual int GetMouseCursor();
168 
169  // Allows the widget to request grabbing of all events (even when the mouse pointer moves out of view)
170  virtual bool GetGrabFocus();
171 
172  // Allows the widget to request interactive mode (faster updates)
173  virtual bool GetInteractive();
174 
175  // Allows the widget to request render
176  virtual bool GetNeedToRender();
177 
178  // Acknowledge rendering request (rendering completed)
179  virtual void NeedToRenderOff();
180 
181  virtual vtkWidgetEventTranslator* GetEventTranslator(int widgetState);
182 
183  virtual int GetNumberOfEventTranslators();
184 
185 protected:
187  ~vtkMRMLAbstractWidget() override;
188 
191  const char* GetAssociatedNodeID(vtkMRMLInteractionEventData* eventData);
192 
194  unsigned long TranslateInteractionEventToWidgetEvent(
195  vtkWidgetEventTranslator* translator, vtkMRMLInteractionEventData* eventData);
196 
198  bool CanProcessButtonClickEvent(vtkMRMLInteractionEventData* eventData, double& distance2);
199 
202  virtual int ProcessButtonClickEvent(vtkMRMLInteractionEventData* eventData);
203 
204  vtkWeakPointer<vtkRenderer> Renderer;
205 
206  vtkWeakPointer<vtkMRMLApplicationLogic> ApplicationLogic;
207 
208  // Translates interaction event to widget event.
209  // In the future, a vector of event translators could be added
210  // (one for each state) to be able to define events
211  // that are only allowed in a specific state.
212  std::vector< vtkSmartPointer<vtkWidgetEventTranslator> > EventTranslators;
213 
215 
216  vtkSmartPointer<vtkMRMLAbstractWidgetRepresentation> WidgetRep;
217 
218 // bool NeedToRender;
219 
220 private:
222  void operator=(const vtkMRMLAbstractWidget&) = delete;
223 };
224 
225 #endif
jumps cursor to the selected position
allows modules to define custom widget actions and get notification via MRML node event ...
allows modules to define custom widget actions and get notification via MRML node event ...
allows modules to define custom widget actions and get notification via MRML node event ...
mouse move transforms the entire widget
mouse pointer is outside the widget, click does not do anything
mouse pointer is over the widget, clicking will add a point or manipulate the line ...
std::vector< vtkSmartPointer< vtkWidgetEventTranslator > > EventTranslators
vtkSmartPointer< vtkMRMLAbstractWidgetRepresentation > WidgetRep
reset widget to initial state (clear all points)
change MRML node Selected attribute
allows modules to define custom widget actions and get notification via MRML node event ...
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D...
allows modules to define custom widget actions and get notification via MRML node event ...
generates a MRML Pick event (e.g., on left click)
mouse move transforms the entire widget
vtkWeakPointer< vtkRenderer > Renderer
allows modules to define custom widget actions and get notification via MRML node event ...
change MRML node Selected attribute
Process interaction events to update state of MRML widget nodes.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
this state is used for referring to any widget state (for defining event translations) ...
mouse move transforms the entire widget
vtkWeakPointer< vtkMRMLApplicationLogic > ApplicationLogic