1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkHandleWidget.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 =========================================================================*/ 15 /** 16 * @class vtkHandleWidget 17 * @brief a general widget for moving handles 18 * 19 * The vtkHandleWidget is used to position a handle. A handle is a widget 20 * with a position (in display and world space). Various appearances are 21 * available depending on its associated representation. The widget provides 22 * methods for translation, including constrained translation along 23 * coordinate axes. To use this widget, create and associate a representation 24 * with the widget. 25 * 26 * @par Event Bindings: 27 * By default, the widget responds to the following VTK events (i.e., it 28 * watches the vtkRenderWindowInteractor for these events): 29 * <pre> 30 * LeftButtonPressEvent - select focal point of widget 31 * LeftButtonReleaseEvent - end selection 32 * MiddleButtonPressEvent - translate widget 33 * MiddleButtonReleaseEvent - end translation 34 * RightButtonPressEvent - scale widget 35 * RightButtonReleaseEvent - end scaling 36 * MouseMoveEvent - interactive movement across widget 37 * </pre> 38 * 39 * @par Event Bindings: 40 * Note that the event bindings described above can be changed using this 41 * class's vtkWidgetEventTranslator. This class translates VTK events 42 * into the vtkHandleWidget's widget events: 43 * <pre> 44 * vtkWidgetEvent::Select -- focal point is being selected 45 * vtkWidgetEvent::EndSelect -- the selection process has completed 46 * vtkWidgetEvent::Translate -- translate the widget 47 * vtkWidgetEvent::EndTranslate -- end widget translation 48 * vtkWidgetEvent::Scale -- scale the widget 49 * vtkWidgetEvent::EndScale -- end scaling the widget 50 * vtkWidgetEvent::Move -- a request for widget motion 51 * </pre> 52 * 53 * @par Event Bindings: 54 * In turn, when these widget events are processed, the vtkHandleWidget 55 * invokes the following VTK events on itself (which observers can listen for): 56 * <pre> 57 * vtkCommand::StartInteractionEvent (on vtkWidgetEvent::Select) 58 * vtkCommand::EndInteractionEvent (on vtkWidgetEvent::EndSelect) 59 * vtkCommand::InteractionEvent (on vtkWidgetEvent::Move) 60 * </pre> 61 * 62 */ 63 64 #ifndef vtkHandleWidget_h 65 #define vtkHandleWidget_h 66 67 #include "vtkAbstractWidget.h" 68 #include "vtkInteractionWidgetsModule.h" // For export macro 69 70 class vtkHandleRepresentation; 71 72 class VTKINTERACTIONWIDGETS_EXPORT vtkHandleWidget : public vtkAbstractWidget 73 { 74 public: 75 /** 76 * Instantiate this class. 77 */ 78 static vtkHandleWidget* New(); 79 80 ///@{ 81 /** 82 * Standard VTK class macros. 83 */ 84 vtkTypeMacro(vtkHandleWidget, vtkAbstractWidget); 85 void PrintSelf(ostream& os, vtkIndent indent) override; 86 ///@} 87 88 /** 89 * Specify an instance of vtkWidgetRepresentation used to represent this 90 * widget in the scene. Note that the representation is a subclass of vtkProp 91 * so it can be added to the renderer independent of the widget. 92 */ SetRepresentation(vtkHandleRepresentation * r)93 void SetRepresentation(vtkHandleRepresentation* r) 94 { 95 this->Superclass::SetWidgetRepresentation(reinterpret_cast<vtkWidgetRepresentation*>(r)); 96 } 97 98 /** 99 * Return the representation as a vtkHandleRepresentation. 100 */ GetHandleRepresentation()101 vtkHandleRepresentation* GetHandleRepresentation() 102 { 103 return reinterpret_cast<vtkHandleRepresentation*>(this->WidgetRep); 104 } 105 106 /** 107 * Create the default widget representation if one is not set. By default 108 * an instance of vtkPointHandleRepresentation3D is created. 109 */ 110 void CreateDefaultRepresentation() override; 111 112 ///@{ 113 /** 114 * Enable / disable axis constrained motion of the handles. By default the 115 * widget responds to the shift modifier to constrain the handle along the 116 * axis closest aligned with the motion vector. 117 */ 118 vtkSetMacro(EnableAxisConstraint, vtkTypeBool); 119 vtkGetMacro(EnableAxisConstraint, vtkTypeBool); 120 vtkBooleanMacro(EnableAxisConstraint, vtkTypeBool); 121 ///@} 122 123 ///@{ 124 /** 125 * Enable moving of handles. By default, the handle can be moved. 126 */ 127 vtkSetMacro(EnableTranslation, vtkTypeBool); 128 vtkGetMacro(EnableTranslation, vtkTypeBool); 129 vtkBooleanMacro(EnableTranslation, vtkTypeBool); 130 ///@} 131 132 ///@{ 133 /** 134 * Allow resizing of handles ? By default the right mouse button scales 135 * the handle size. 136 */ 137 vtkSetMacro(AllowHandleResize, vtkTypeBool); 138 vtkGetMacro(AllowHandleResize, vtkTypeBool); 139 vtkBooleanMacro(AllowHandleResize, vtkTypeBool); 140 ///@} 141 142 ///@{ 143 /** 144 * Get the widget state. 145 */ 146 vtkGetMacro(WidgetState, int); 147 ///@} 148 149 ///@{ 150 /** 151 * Allow the widget to be visible as an inactive representation when disabled. 152 * By default, this is false i.e. the representation is not visible when the 153 * widget is disabled. 154 */ 155 vtkSetMacro(ShowInactive, vtkTypeBool); 156 vtkGetMacro(ShowInactive, vtkTypeBool); 157 vtkBooleanMacro(ShowInactive, vtkTypeBool); 158 ///@} 159 160 // Manage the state of the widget 161 enum _WidgetState 162 { 163 Start = 0, 164 Active, 165 Inactive 166 }; 167 168 /** 169 * Enable/disable widget. 170 * Custom override for the SetEnabled method to allow for the inactive state. 171 **/ 172 void SetEnabled(int enabling) override; 173 174 protected: 175 vtkHandleWidget(); 176 ~vtkHandleWidget() override; 177 178 // These are the callbacks for this widget 179 static void GenericAction(vtkHandleWidget*); 180 static void SelectAction(vtkAbstractWidget*); 181 static void EndSelectAction(vtkAbstractWidget*); 182 static void TranslateAction(vtkAbstractWidget*); 183 static void ScaleAction(vtkAbstractWidget*); 184 static void MoveAction(vtkAbstractWidget*); 185 static void SelectAction3D(vtkAbstractWidget*); 186 static void MoveAction3D(vtkAbstractWidget*); 187 static void ProcessKeyEvents(vtkObject*, unsigned long, void*, void*); 188 189 // helper methods for cursor management 190 void SetCursor(int state) override; 191 192 int WidgetState; 193 vtkTypeBool EnableAxisConstraint; 194 vtkTypeBool EnableTranslation; 195 196 // Allow resizing of handles. 197 vtkTypeBool AllowHandleResize; 198 199 // Keep representation visible when disabled 200 vtkTypeBool ShowInactive; 201 202 vtkCallbackCommand* KeyEventCallbackCommand; 203 204 private: 205 vtkHandleWidget(const vtkHandleWidget&) = delete; 206 void operator=(const vtkHandleWidget&) = delete; 207 }; 208 209 #endif 210