Developer documentation | Axl-2.5.1

axlInteractorStyleSwitch.cpp
Go to the documentation of this file.
1 /* axlInteractorStyleSwitch.h ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Feb 18 17:25:39 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Thu Mar 17 14:09:36 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 22
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
20 
21 #include "vtkCallbackCommand.h"
22 #include "vtkCommand.h"
23 #include "vtkInteractorStyleJoystickActor.h"
24 #include "vtkInteractorStyleJoystickCamera.h"
25 #include "vtkInteractorStyleTrackballActor.h"
26 #include "vtkInteractorStyleTrackballCamera.h"
27 #include "vtkObjectFactory.h"
28 #include "vtkRenderWindowInteractor.h"
29 
31 
32 class axlInteractorStyleSwitchPrivate
33 {
34 public:
35 };
36 
37 //----------------------------------------------------------------------------
38 axlInteractorStyleSwitch::axlInteractorStyleSwitch(QObject *parent) : QObject(parent), d(new axlInteractorStyleSwitchPrivate)
39 {
40  this->JoystickActor = vtkInteractorStyleJoystickActor::New();
41  this->JoystickCamera = vtkInteractorStyleJoystickCamera::New();
42  this->TrackballActor = vtkInteractorStyleTrackballActor::New();
43  this->TrackballCamera = vtkInteractorStyleTrackballCamera::New();
46  this->CurrentStyle = 0;
47 }
48 
49 //----------------------------------------------------------------------------
51 {
52  this->JoystickActor->Delete();
53  this->JoystickActor = NULL;
54 
55  this->JoystickCamera->Delete();
56  this->JoystickCamera = NULL;
57 
58  this->TrackballActor->Delete();
59  this->TrackballActor = NULL;
60 
61  this->TrackballCamera->Delete();
62  this->TrackballCamera = NULL;
63 
64  delete d;
65 
66  d = NULL;
67 }
68 
69 //----------------------------------------------------------------------------
71 {
72  if ( value == this->AutoAdjustCameraClippingRange )
73  {
74  return;
75  }
76 
77  if ( value < 0 || value > 1 )
78  {
79  vtkErrorMacro("Value must be between 0 and 1 for" <<
80  " SetAutoAdjustCameraClippingRange");
81  return;
82  }
83 
84  this->AutoAdjustCameraClippingRange = value;
85  this->JoystickActor->SetAutoAdjustCameraClippingRange( value );
86  this->JoystickCamera->SetAutoAdjustCameraClippingRange( value );
87  this->TrackballActor->SetAutoAdjustCameraClippingRange( value );
88  this->TrackballCamera->SetAutoAdjustCameraClippingRange( value );
89 
90  this->Modified();
91 }
92 
93 //----------------------------------------------------------------------------
95 {
97  this->CameraOrActor = VTKIS_ACTOR;
98  this->SetCurrentStyle();
99 }
100 
101 //----------------------------------------------------------------------------
103 {
105  this->CameraOrActor = VTKIS_CAMERA;
106  this->SetCurrentStyle();
107 }
108 
109 //----------------------------------------------------------------------------
111 {
113  this->CameraOrActor = VTKIS_ACTOR;
114  this->SetCurrentStyle();
115 }
116 
117 //----------------------------------------------------------------------------
119 {
121  this->CameraOrActor = VTKIS_CAMERA;
122  this->SetCurrentStyle();
123 }
124 
125 //----------------------------------------------------------------------------
127 {
128  switch (this->Interactor->GetKeyCode())
129  {
130  case 'j':
131  case 'J':
133  this->EventCallbackCommand->SetAbortFlag(1);
134  break;
135  case 't':
136  case 'T':
138  this->EventCallbackCommand->SetAbortFlag(1);
139  break;
140  case 'c':
141  case 'C':
142  this->CameraOrActor = VTKIS_CAMERA;
143  this->EventCallbackCommand->SetAbortFlag(1);
144  break;
145  case 'a':
146  case 'A':
147  this->CameraOrActor = VTKIS_ACTOR;
148  this->EventCallbackCommand->SetAbortFlag(1);
149  break;
150  }
151  // Set the CurrentStyle pointer to the picked style
152  this->SetCurrentStyle();
153 }
154 
155 //----------------------------------------------------------------------------
156 // this will do nothing if the CurrentStyle matchs
157 // JoystickOrTrackball and CameraOrActor
158 // It should! If the this->Interactor was changed (using SetInteractor()),
159 // and the currentstyle should not change.
161 {
162  // if the currentstyle does not match JoystickOrTrackball
163  // and CameraOrActor ivars, then call SetInteractor(0)
164  // on the Currentstyle to remove all of the observers.
165  // Then set the Currentstyle and call SetInteractor with
166  // this->Interactor so the callbacks are set for the
167  // currentstyle.
168  if (this->JoystickOrTrackball == VTKIS_JOYSTICK &&
169  this->CameraOrActor == VTKIS_CAMERA)
170  {
171  if(this->CurrentStyle != this->JoystickCamera)
172  {
173  if(this->CurrentStyle)
174  {
175  this->CurrentStyle->SetInteractor(0);
176  }
177  this->CurrentStyle = this->JoystickCamera;
178  }
179  }
180  else if (this->JoystickOrTrackball == VTKIS_JOYSTICK &&
181  this->CameraOrActor == VTKIS_ACTOR)
182  {
183  if(this->CurrentStyle != this->JoystickActor)
184  {
185  if(this->CurrentStyle)
186  {
187  this->CurrentStyle->SetInteractor(0);
188  }
189  this->CurrentStyle = this->JoystickActor;
190  }
191  }
192  else if (this->JoystickOrTrackball == VTKIS_TRACKBALL &&
193  this->CameraOrActor == VTKIS_CAMERA)
194  {
195  if(this->CurrentStyle != this->TrackballCamera)
196  {
197  if(this->CurrentStyle)
198  {
199  this->CurrentStyle->SetInteractor(0);
200  }
201  this->CurrentStyle = this->TrackballCamera;
202  }
203  }
204  else if (this->JoystickOrTrackball == VTKIS_TRACKBALL &&
205  this->CameraOrActor == VTKIS_ACTOR)
206  {
207  if(this->CurrentStyle != this->TrackballActor)
208  {
209  if(this->CurrentStyle)
210  {
211  this->CurrentStyle->SetInteractor(0);
212  }
213  this->CurrentStyle = this->TrackballActor;
214  }
215  }
216  if (this->CurrentStyle)
217  {
218  this->CurrentStyle->SetInteractor(this->Interactor);
219  this->CurrentStyle->SetTDxStyle(this->TDxStyle);
220  }
221 }
222 
223 //----------------------------------------------------------------------------
224 void axlInteractorStyleSwitch::SetInteractor(vtkRenderWindowInteractor *iren)
225 {
226  if(iren == this->Interactor)
227  {
228  return;
229  }
230  // if we already have an Interactor then stop observing it
231  if(this->Interactor)
232  {
233  this->Interactor->RemoveObserver(this->EventCallbackCommand);
234  }
235  this->Interactor = iren;
236  // add observers for each of the events handled in ProcessEvents
237  if(iren)
238  {
239  iren->AddObserver(vtkCommand::CharEvent,
240  this->EventCallbackCommand,
241  this->Priority);
242 
243  iren->AddObserver(vtkCommand::DeleteEvent,
244  this->EventCallbackCommand,
245  this->Priority);
246  }
247  this->SetCurrentStyle();
248 }
249 
250 //----------------------------------------------------------------------------
251 void axlInteractorStyleSwitch::PrintSelf(ostream& os, vtkIndent indent)
252 {
253  this->Superclass::PrintSelf(os,indent);
254  os << indent << "CurrentStyle " << this->CurrentStyle << "\n";
255  if (this->CurrentStyle)
256  {
257  vtkIndent next_indent = indent.GetNextIndent();
258  os << next_indent << this->CurrentStyle->GetClassName() << "\n";
259  this->CurrentStyle->PrintSelf(os, indent.GetNextIndent());
260  }
261 }
262 
263 //----------------------------------------------------------------------------
265 {
266  this->vtkInteractorStyle::SetDefaultRenderer(renderer);
267  this->JoystickActor->SetDefaultRenderer(renderer);
268  this->JoystickCamera->SetDefaultRenderer(renderer);
269  this->TrackballActor->SetDefaultRenderer(renderer);
270  this->TrackballCamera->SetDefaultRenderer(renderer);
271 }
272 
273 //----------------------------------------------------------------------------
275 {
276  this->vtkInteractorStyle::SetCurrentRenderer(renderer);
277  this->JoystickActor->SetCurrentRenderer(renderer);
278  this->JoystickCamera->SetCurrentRenderer(renderer);
279  this->TrackballActor->SetCurrentRenderer(renderer);
280  this->TrackballCamera->SetCurrentRenderer(renderer);
281 }
vtkInteractorStyleJoystickCamera * JoystickCamera
vtkInteractorStyleTrackballActor * TrackballActor
void SetAutoAdjustCameraClippingRange(int value) override
vtkInteractorStyleJoystickActor * JoystickActor
void SetInteractor(vtkRenderWindowInteractor *iren)
#define VTKIS_CAMERA
#define VTKIS_ACTOR
#define VTKIS_JOYSTICK
virtual void SetCurrentRenderer(vtkRenderer *) override
vtkInteractorStyleTrackballCamera * TrackballCamera
vtkInteractorStyle * CurrentStyle
axlInteractorStyleSwitch(QObject *parent=0)
#define VTKIS_TRACKBALL
vtkStandardNewMacro(axlInteractorStyleSwitch)
virtual void SetDefaultRenderer(vtkRenderer *) override
void PrintSelf(ostream &os, vtkIndent indent)