1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkLineWidget2.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 // .NAME vtkLineWidget2 - 3D widget for manipulating a finite, straight line 16 // .SECTION Description 17 // This 3D widget defines a straight line that can be interactively placed in 18 // a scene. The widget is assumed to consist of two parts: 1) two end points 19 // and 2) a straight line connecting the two points. (The representation 20 // paired with this widget determines the actual geometry of the widget.) The 21 // positioning of the two end points is facilitated by using vtkHandleWidgets 22 // to position the points. 23 // 24 // To use this widget, you generally pair it with a vtkLineRepresentation 25 // (or a subclass). Various options are available in the representation for 26 // controlling how the widget appears, and how the widget functions. 27 // 28 // .SECTION Event Bindings 29 // By default, the widget responds to the following VTK events (i.e., it 30 // watches the vtkRenderWindowInteractor for these events): 31 // <pre> 32 // If one of the two end points are selected: 33 // LeftButtonPressEvent - activate the associated handle widget 34 // LeftButtonReleaseEvent - release the handle widget associated with the point 35 // MouseMoveEvent - move the point 36 // If the line is selected: 37 // LeftButtonPressEvent - activate a handle widget accociated with the line 38 // LeftButtonReleaseEvent - release the handle widget associated with the line 39 // MouseMoveEvent - translate the line 40 // In all the cases, independent of what is picked, the widget responds to the 41 // following VTK events: 42 // MiddleButtonPressEvent - translate the widget 43 // MiddleButtonReleaseEvent - release the widget 44 // RightButtonPressEvent - scale the widget's representation 45 // RightButtonReleaseEvent - stop scaling the widget 46 // MouseMoveEvent - scale (if right button) or move (if middle button) the widget 47 // </pre> 48 // 49 // Note that the event bindings described above can be changed using this 50 // class's vtkWidgetEventTranslator. This class translates VTK events 51 // into the vtkLineWidget2's widget events: 52 // <pre> 53 // vtkWidgetEvent::Select -- some part of the widget has been selected 54 // vtkWidgetEvent::EndSelect -- the selection process has completed 55 // vtkWidgetEvent::Move -- a request for slider motion has been invoked 56 // </pre> 57 // 58 // In turn, when these widget events are processed, the vtkLineWidget2 59 // invokes the following VTK events on itself (which observers can listen for): 60 // <pre> 61 // vtkCommand::StartInteractionEvent (on vtkWidgetEvent::Select) 62 // vtkCommand::EndInteractionEvent (on vtkWidgetEvent::EndSelect) 63 // vtkCommand::InteractionEvent (on vtkWidgetEvent::Move) 64 // </pre> 65 // 66 67 // 68 // This class, and vtkLineRepresentation, are next generation VTK widgets. An 69 // earlier version of this functionality was defined in the class 70 // vtkLineWidget. 71 72 // .SECTION See Also 73 // vtkLineRepresentation vtkLineWidget vtk3DWidget vtkImplicitPlaneWidget 74 // vtkImplicitPlaneWidget2 75 76 #ifndef vtkLineWidget2_h 77 #define vtkLineWidget2_h 78 79 #include "vtkInteractionWidgetsModule.h" // For export macro 80 #include "vtkAbstractWidget.h" 81 82 class vtkLineRepresentation; 83 class vtkHandleWidget; 84 85 86 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget2 : public vtkAbstractWidget 87 { 88 public: 89 // Description: 90 // Instantiate the object. 91 static vtkLineWidget2 *New(); 92 93 // Description: 94 // Standard vtkObject methods 95 vtkTypeMacro(vtkLineWidget2,vtkAbstractWidget); 96 void PrintSelf(ostream& os, vtkIndent indent); 97 98 // Description: 99 // Override superclasses' SetEnabled() method because the line 100 // widget must enable its internal handle widgets. 101 virtual void SetEnabled(int enabling); 102 103 // Description: 104 // Specify an instance of vtkWidgetRepresentation used to represent this 105 // widget in the scene. Note that the representation is a subclass of vtkProp 106 // so it can be added to the renderer independent of the widget. SetRepresentation(vtkLineRepresentation * r)107 void SetRepresentation(vtkLineRepresentation *r) 108 {this->Superclass::SetWidgetRepresentation(reinterpret_cast<vtkWidgetRepresentation*>(r));} 109 110 // Description: 111 // Return the representation as a vtkLineRepresentation. GetLineRepresentation()112 vtkLineRepresentation *GetLineRepresentation() 113 {return reinterpret_cast<vtkLineRepresentation*>(this->WidgetRep);} 114 115 // Description: 116 // Create the default widget representation if one is not set. 117 void CreateDefaultRepresentation(); 118 119 // Description: 120 // Methods to change the whether the widget responds to interaction. 121 // Overridden to pass the state to component widgets. 122 virtual void SetProcessEvents(int); 123 124 protected: 125 vtkLineWidget2(); 126 ~vtkLineWidget2(); 127 128 //BTX - manage the state of the widget 129 int WidgetState; 130 enum _WidgetState {Start=0,Active}; 131 //ETX 132 int CurrentHandle; 133 134 // These methods handle events 135 static void SelectAction(vtkAbstractWidget*); 136 static void TranslateAction(vtkAbstractWidget*); 137 static void ScaleAction(vtkAbstractWidget*); 138 static void EndSelectAction(vtkAbstractWidget*); 139 static void MoveAction(vtkAbstractWidget*); 140 141 // The positioning handle widgets 142 vtkHandleWidget *Point1Widget; //first end point 143 vtkHandleWidget *Point2Widget; //second end point 144 vtkHandleWidget *LineHandle; //used when selecting the line 145 146 private: 147 vtkLineWidget2(const vtkLineWidget2&); //Not implemented 148 void operator=(const vtkLineWidget2&); //Not implemented 149 }; 150 151 #endif 152