00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __SVTK_InteractorStyle_h
00030 #define __SVTK_InteractorStyle_h
00031
00032 #include "SVTK.h"
00033
00034 #include "SVTK_SelectionEvent.h"
00035
00036 #include <boost/shared_ptr.hpp>
00037
00038 #include <vtkInteractorStyle.h>
00039 #include <vtkSmartPointer.h>
00040
00041 #include <QCursor>
00042
00043 #include <map>
00044
00045 #include <vtkObject.h>
00046
00047 #ifdef WIN32
00048 #pragma warning ( disable:4251 )
00049 #endif
00050
00051
00053
00057 class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{
00058 public:
00059 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
00060 static SVTK_ControllerIncrement* New();
00061
00063 void SetStartValue(const int );
00064
00066 int Current()const;
00067
00069 virtual int Increase();
00070
00072 virtual int Decrease();
00073 protected:
00074 SVTK_ControllerIncrement();
00075 virtual ~SVTK_ControllerIncrement();
00076 protected:
00077 int myIncrement;
00078 private:
00079 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);
00080 void operator=(const SVTK_ControllerIncrement&);
00081 };
00082
00083
00085
00089 class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{
00090 public:
00091 vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement);
00092 static SVTK_GeomControllerIncrement* New();
00093
00095 virtual int Increase();
00096
00098 virtual int Decrease();
00099 protected:
00100 SVTK_GeomControllerIncrement();
00101 virtual ~SVTK_GeomControllerIncrement();
00102 private:
00103 SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);
00104 void operator=(const SVTK_GeomControllerIncrement&);
00105 };
00106
00108
00112 class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
00113 public:
00114 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
00115 static SVTK_ControllerOnKeyDown* New();
00116
00118 virtual bool OnKeyDown(vtkInteractorStyle* );
00119
00120 protected:
00121 SVTK_ControllerOnKeyDown();
00122 virtual ~SVTK_ControllerOnKeyDown();
00123
00124 private:
00125 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);
00126 void operator=(const SVTK_ControllerOnKeyDown&);
00127 };
00128
00129 class vtkPointPicker;
00130 class vtkTDxInteractorStyle;
00131
00132 class SALOME_Actor;
00133
00134 class SVTK_Selector;
00135 class SVTK_GenericRenderWindowInteractor;
00136 class SVTK_Actor;
00137
00138 class QRubberBand;
00139
00140 #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0
00141 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1
00142 #define VTK_INTERACTOR_STYLE_CAMERA_PAN 2
00143 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM 3
00144 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN 4
00145 #define VTK_INTERACTOR_STYLE_CAMERA_FIT 5
00146 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6
00147 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
00148 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
00149
00151
00155 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
00156 {
00157 public:
00158 static SVTK_InteractorStyle *New();
00159 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
00160
00161 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
00162
00163 void SetTDxStyle(vtkTDxInteractorStyle*){}
00164
00166 virtual SVTK_SelectionEvent* GetSelectionEvent();
00167
00169 virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
00170
00172 virtual void SetInteractor( vtkRenderWindowInteractor* );
00173
00175 virtual void Render();
00176
00178 virtual void OnTimer();
00179
00181 virtual void OnConfigure();
00182
00184 virtual void OnMouseMove();
00185
00187 virtual void OnLeftButtonDown();
00188
00190 virtual void OnLeftButtonUp();
00191
00193 virtual void OnMiddleButtonDown();
00194
00196 virtual void OnMiddleButtonUp();
00197
00199 virtual void OnRightButtonDown();
00200
00202 virtual void OnRightButtonUp();
00203
00205 virtual void OnMouseWheelForward();
00206
00208 virtual void OnMouseWheelBackward();
00209
00211 virtual void OnChar();
00212
00214 void SetControllerIncrement(SVTK_ControllerIncrement*);
00215
00217 void SetIncrementSpeed(const int, const int = 0);
00218
00220 SVTK_ControllerIncrement* ControllerIncrement();
00221
00223 virtual void OnKeyDown();
00224
00226 void ActionPicking();
00227
00229 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
00230
00232 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
00233
00234 SVTK_Selector* GetSelector();
00235
00236 int CurrentState() const { return State; }
00237
00238 void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
00239 bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
00240
00241 protected:
00242 SVTK_InteractorStyle();
00243 ~SVTK_InteractorStyle();
00244
00245 QWidget*
00246 GetRenderWidget();
00247
00248
00249 virtual void OnMouseMove (int ctrl, int shift, int x, int y);
00250 virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
00251 virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y);
00252 virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
00253 virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y);
00254 virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
00255 virtual void OnRightButtonUp (int ctrl, int shift, int x, int y);
00256
00257 void RotateXY(int dx, int dy);
00258 void PanXY(int x, int y, int oldX, int oldY);
00259 void DollyXY(int dx, int dy);
00260 void SpinXY(int dx, int dy, int oldX, int oldY);
00261 void fitRect(const int left, const int top, const int right, const int bottom);
00262 void Place(const int theX, const int theY);
00263 void TranslateView(int toX, int toY, int fromX, int fromY);
00264
00265 void
00266 IncrementalPan( const int incrX, const int incrY );
00267
00268 void
00269 IncrementalZoom( const int incr );
00270
00271 void
00272 IncrementalRotate( const int incrX, const int incrY );
00273
00274
00275 static
00276 void
00277 ProcessEvents(vtkObject* object,
00278 unsigned long event,
00279 void* clientData,
00280 void* callData );
00281
00282 float MotionFactor;
00283 float RadianToDegree;
00284 double myScale;
00285
00286 protected:
00287 void startZoom();
00288 void startPan();
00289 void startGlobalPan();
00290 void startRotate();
00291 void startFitArea();
00292 void startSpin();
00293
00294 void startPointSelection();
00295 void startFocalPointSelection();
00296
00297 protected:
00298 void loadCursors();
00299 void startOperation(int operation);
00300 void onStartOperation();
00301 virtual void onFinishOperation();
00302 void onOperation(QPoint mousePos);
00303 void onCursorMove(QPoint mousePos);
00304 void setCursor(const int operation);
00305
00306 void onSpaceMouseMove( double* data );
00307 virtual void onSpaceMouseButton( int button );
00308
00309 void DominantCombinedSwitch();
00310
00311 void drawRect();
00312 void endDrawRect();
00313
00314 protected:
00315 QCursor myDefCursor;
00316 QCursor myPanCursor;
00317 QCursor myZoomCursor;
00318 QCursor myRotateCursor;
00319 QCursor mySpinCursor;
00320 QCursor myHandCursor;
00321 QCursor myGlobalPanCursor;
00322 QPoint myPoint;
00323 QPoint myOtherPoint;
00324 bool myCursorState;
00325 bool myShiftState;
00326 int ForcedState;
00327
00328 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
00329 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
00330
00332 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
00333
00335 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
00336
00337
00338 int mySMDecreaseSpeedBtn;
00339 int mySMIncreaseSpeedBtn;
00340 int mySMDominantCombinedSwitchBtn;
00341
00342 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
00343
00344 PSelectionEvent mySelectionEvent;
00345
00346 unsigned long myCurrRotationPointType;
00347 unsigned long myPrevRotationPointType;
00348
00349 unsigned long myCurrFocalPointType;
00350 unsigned long myPrevFocalPointType;
00351
00352 double myRotationPointX;
00353 double myRotationPointY;
00354 double myRotationPointZ;
00355
00356 vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
00357 vtkSmartPointer<vtkPointPicker> myPointPicker;
00358
00359 vtkFloatingPointType myBBCenter[3];
00360 bool myBBFirstCheck;
00361
00362 QRubberBand* myRectBand;
00363
00364 bool myIsAdvancedZoomingEnabled;
00365 };
00366
00367 #ifdef WIN32
00368 #pragma warning ( default:4251 )
00369 #endif
00370
00371 #endif