1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
27 #include "SVTK_InteractorStyle.h"
29 #include "VTKViewer_Algorithm.h"
30 #include "VTKViewer_Utilities.h"
31 #include "SVTK_GenericRenderWindowInteractor.h"
33 #include "SVTK_Selection.h"
34 #include "SVTK_Event.h"
35 #include "SVTK_Selector.h"
36 #include "SVTK_Functor.h"
37 #include "SVTK_Actor.h"
39 #include "VTKViewer_Algorithm.h"
40 #include "SVTK_Functor.h"
42 #include "SUIT_Tools.h"
43 #include "SALOME_Actor.h"
45 #include <vtkObjectFactory.h>
47 #include <vtkCommand.h>
48 #include <vtkCamera.h>
49 #include <vtkRenderer.h>
50 #include <vtkPointPicker.h>
51 #include <vtkRenderWindow.h>
52 #include <vtkRenderWindowInteractor.h>
53 #include <vtkCallbackCommand.h>
54 #include <vtkRendererCollection.h>
55 #include <vtkDataSet.h>
56 #include <vtkPerspectiveTransform.h>
57 #include <vtkMatrix4x4.h>
61 #include <QRubberBand>
68 inline void GetEventPosition(vtkRenderWindowInteractor* theInteractor,
72 theInteractor->GetEventPosition(theX,theY);
73 theY = theInteractor->GetSize()[1] - theY - 1;
78 vtkStandardNewMacro(SVTK_InteractorStyle);
84 SVTK_InteractorStyle::SVTK_InteractorStyle():
85 mySelectionEvent(new SVTK_SelectionEvent()),
86 myPointPicker(vtkPointPicker::New()),
87 myLastHighlitedActor(NULL),
88 myLastPreHighlitedActor(NULL),
89 myControllerIncrement(SVTK_ControllerIncrement::New()),
90 myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
91 myHighlightSelectionPointActor(SVTK_Actor::New()),
93 myIsAdvancedZoomingEnabled(false)
95 myPointPicker->Delete();
97 myPointPicker->SetTolerance(0.025);
99 this->MotionFactor = 10.0;
100 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
101 this->RadianToDegree = 180.0 / vtkMath::Pi();
102 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
106 // set custom event handling function (to handle 3d space mouse events)
107 EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
109 // set default values of properties. user may edit them in preferences.
110 mySMDecreaseSpeedBtn = 1;
111 mySMIncreaseSpeedBtn = 2;
112 mySMDominantCombinedSwitchBtn = 9;
114 myControllerIncrement->Delete();
115 myControllerOnKeyDown->Delete();
117 myCurrRotationPointType = SVTK::SetRotateGravity;
118 myPrevRotationPointType = myCurrRotationPointType;
120 myCurrFocalPointType = SVTK::SetFocalPointSelected;
121 myPrevFocalPointType = myCurrFocalPointType;
123 myHighlightSelectionPointActor->Delete();
124 myHighlightSelectionPointActor->Initialize();
125 myHighlightSelectionPointActor->PickableOff();
126 myHighlightSelectionPointActor->SetVisibility( false );
128 myHighlightSelectionPointActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE+2);
129 myHighlightSelectionPointActor->GetProperty()->SetLineWidth(SALOME_LINE_WIDTH+2);
130 myHighlightSelectionPointActor->GetProperty()->SetRepresentationToPoints();
132 myBBFirstCheck = true;
138 SVTK_InteractorStyle::~SVTK_InteractorStyle()
144 \return widget for rendering
146 QWidget* SVTK_InteractorStyle::GetRenderWidget()
148 return myInteractor->GetRenderWidget();
154 SVTK_Selector* SVTK_InteractorStyle::GetSelector()
156 return myInteractor->GetSelector();
160 Generate special SVTK_SelectionEvent
162 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEvent()
164 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
166 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
167 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
169 mySelectionEvent->myLastX = mySelectionEvent->myX;
170 mySelectionEvent->myLastY = mySelectionEvent->myY;
172 GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
174 return mySelectionEvent.get();
178 Generate special SVTK_SelectionEvent with flipped Y coordinate
180 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEventFlipY()
182 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
184 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
185 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
187 mySelectionEvent->myLastX = mySelectionEvent->myX;
188 mySelectionEvent->myLastY = mySelectionEvent->myY;
190 this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
192 return mySelectionEvent.get();
195 void SVTK_InteractorStyle::RotateXY(int dx, int dy)
197 /* if(GetCurrentRenderer() == NULL)
200 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
201 double aDeltaElevation = -20.0 / size[1];
202 double aDeltaAzimuth = -20.0 / size[0];
204 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
205 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
207 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
210 cam->OrthogonalizeViewUp();
212 GetCurrentRenderer()->ResetCameraClippingRange();
216 if(GetCurrentRenderer() == NULL)
219 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
221 double viewFP[3], viewPos[3];
222 cam->GetFocalPoint(viewFP);
223 cam->GetPosition(viewPos);
225 if ( myCurrRotationPointType == SVTK::SetRotateGravity )
227 vtkFloatingPointType aCenter[3];
228 if ( ComputeBBCenter(GetCurrentRenderer(),aCenter) )
230 myRotationPointX = aCenter[0];
231 myRotationPointY = aCenter[1];
232 myRotationPointZ = aCenter[2];
236 // Calculate corresponding transformation
237 vtkPerspectiveTransform* aTransform = vtkPerspectiveTransform::New();
238 aTransform->Identity();
239 aTransform->Translate(+myRotationPointX, +myRotationPointY, +myRotationPointZ);
241 // Azimuth transformation
242 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
243 double aDeltaAzimuth = -20.0 / size[0];
245 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
246 aTransform->RotateWXYZ(rxf, cam->GetViewUp());
248 // Elevation transformation
249 double aDeltaElevation = -20.0 / size[1];
251 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
252 vtkMatrix4x4* aMatrix = cam->GetViewTransformMatrix();
253 const double anAxis[3] = {-aMatrix->GetElement(0,0), // mkr : 27.11.2006 : PAL14011 - Strange behaviour in rotation in VTK Viewer.
254 -aMatrix->GetElement(0,1),
255 -aMatrix->GetElement(0,2)};
257 aTransform->RotateWXYZ(ryf, anAxis);
259 aTransform->Translate(-myRotationPointX, -myRotationPointY, -myRotationPointZ);
261 // To apply the transformation
262 cam->SetPosition(aTransform->TransformPoint(viewPos));
263 cam->SetFocalPoint(aTransform->TransformPoint(viewFP));
264 aTransform->Delete();
266 cam->OrthogonalizeViewUp();
268 GetCurrentRenderer()->ResetCameraClippingRange();
271 this->InvokeEvent(SVTK::OperationFinished,NULL);
274 void SVTK_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
276 TranslateView(x, y, oldX, oldY);
278 this->InvokeEvent(SVTK::OperationFinished,NULL);
281 void SVTK_InteractorStyle::DollyXY(int dx, int dy)
283 if (GetCurrentRenderer() == NULL)
286 double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
287 double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
289 double zoomFactor = pow((double)1.1, dxf + dyf);
291 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
292 if (aCam->GetParallelProjection()) {
293 int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
294 if( IsAdvancedZoomingEnabled() ) { // zoom relatively to the cursor
295 int* aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
300 x1 = myOtherPoint.x();
301 y1 = h - myOtherPoint.y();
302 TranslateView( x0, y0, x1, y1 );
304 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
305 if( IsAdvancedZoomingEnabled() )
306 TranslateView( x1, y1, x0, y0 );
309 aCam->Dolly(zoomFactor); // Move camera in/out along projection direction
310 GetCurrentRenderer()->ResetCameraClippingRange();
314 this->InvokeEvent(SVTK::OperationFinished,NULL);
317 void SVTK_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
321 if (GetCurrentRenderer() == NULL)
324 double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
325 (double)(x - GetCurrentRenderer()->GetCenter()[0]));
326 double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
327 (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
329 newAngle *= this->RadianToDegree;
330 oldAngle *= this->RadianToDegree;
332 cam = GetCurrentRenderer()->GetActiveCamera();
333 cam->Roll(newAngle - oldAngle);
334 cam->OrthogonalizeViewUp();
337 this->InvokeEvent(SVTK::OperationFinished,NULL);
344 void SVTK_InteractorStyle::OnConfigure()
346 this->FindPokedRenderer(0,0);
347 this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
351 To handle mouse move event
353 void SVTK_InteractorStyle::OnMouseMove()
356 GetEventPosition( this->Interactor, x, y );
357 this->OnMouseMove( this->Interactor->GetControlKey(),
358 this->Interactor->GetShiftKey(),
363 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
365 void SVTK_InteractorStyle::OnLeftButtonDown()
368 GetEventPosition( this->Interactor, x, y );
369 this->OnLeftButtonDown( this->Interactor->GetControlKey(),
370 this->Interactor->GetShiftKey(),
375 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
377 void SVTK_InteractorStyle::OnLeftButtonUp()
380 GetEventPosition( this->Interactor, x, y );
381 this->OnLeftButtonUp( this->Interactor->GetControlKey(),
382 this->Interactor->GetShiftKey(),
387 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
389 void SVTK_InteractorStyle::OnMiddleButtonDown()
392 GetEventPosition( this->Interactor, x, y );
393 this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
394 this->Interactor->GetShiftKey(),
399 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
401 void SVTK_InteractorStyle::OnMiddleButtonUp()
404 GetEventPosition( this->Interactor, x, y );
405 this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
406 this->Interactor->GetShiftKey(),
411 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
413 void SVTK_InteractorStyle::OnRightButtonDown()
416 GetEventPosition( this->Interactor, x, y );
417 this->OnRightButtonDown( this->Interactor->GetControlKey(),
418 this->Interactor->GetShiftKey(),
423 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
425 void SVTK_InteractorStyle::OnRightButtonUp()
428 GetEventPosition( this->Interactor, x, y );
429 this->OnRightButtonUp( this->Interactor->GetControlKey(),
430 this->Interactor->GetShiftKey(),
435 To handle mouse wheel forward event (reimplemented from #vtkInteractorStyle)
437 void SVTK_InteractorStyle::OnMouseWheelForward()
440 GetEventPosition( this->Interactor, x, y );
441 myOtherPoint = QPoint(x, y);
445 To handle mouse wheel backward event (reimplemented from #vtkInteractorStyle)
447 void SVTK_InteractorStyle::OnMouseWheelBackward()
450 GetEventPosition( this->Interactor, x, y );
451 myOtherPoint = QPoint(x, y);
455 To handle mouse move event
457 void SVTK_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
461 myShiftState = shift;
462 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
463 onOperation(QPoint(x, y));
464 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
465 onCursorMove(QPoint(x, y));
469 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
471 void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
474 this->FindPokedRenderer(x, y);
475 if(GetCurrentRenderer() == NULL)
478 myShiftState = shift;
479 // finishing current viewer operation
480 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
482 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
484 myOtherPoint = myPoint = QPoint(x, y);
485 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
486 startOperation(ForcedState);
489 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
490 else if ( myCurrRotationPointType == SVTK::StartPointSelection ||
491 myCurrFocalPointType == SVTK::StartFocalPointSelection )
493 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
495 bool isPicked = false;
496 vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
498 if( anActorCollection )
500 anActorCollection->InitTraversal();
501 while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
503 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
505 SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
506 myPointPicker->Pick( aSelectionEvent->myX,
507 aSelectionEvent->myY,
509 GetCurrentRenderer() );
510 int aVtkId = myPointPicker->GetPointId();
513 int anObjId = anActor->GetNodeObjId( aVtkId );
514 vtkFloatingPointType* aCoords = anActor->GetNodeCoord(anObjId);
516 if (myCurrRotationPointType == SVTK::StartPointSelection) {
517 myCurrRotationPointType = SVTK::SetRotateSelected;
519 // invoke event for update coordinates in SVTK_SetRotationPointDlg
520 InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
522 else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
523 myCurrFocalPointType = SVTK::SetFocalPointSelected;
525 // invoke event for update coordinates in SVTK_ViewParameterDlg
526 InvokeEvent(SVTK::FocalPointChanged,(void*)aCoords);
538 if (myCurrRotationPointType == SVTK::StartPointSelection) {
539 // invoke event with no data (for SVTK_SetRotationPointDlg)
540 InvokeEvent(SVTK::RotationPointChanged,0);
541 myCurrRotationPointType = myPrevRotationPointType;
543 else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
544 // invoke event with no data (for SVTK_ViewParameterDlg)
545 InvokeEvent(SVTK::FocalPointChanged,0);
546 myCurrFocalPointType = myPrevFocalPointType;
550 myHighlightSelectionPointActor->SetVisibility( false );
551 if(GetCurrentRenderer() != NULL)
552 GetCurrentRenderer()->RemoveActor( myHighlightSelectionPointActor.GetPointer() );
554 GetRenderWidget()->setCursor(myDefCursor);
557 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
564 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
566 void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
571 myShiftState = shift;
572 // finishing current viewer operation
573 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
575 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
580 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
582 void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
586 this->FindPokedRenderer(x, y);
587 if(GetCurrentRenderer() == NULL)
590 myShiftState = shift;
591 // finishing current viewer operation
592 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
594 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
596 myOtherPoint = myPoint = QPoint(x, y);
597 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
598 startOperation(ForcedState);
602 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
608 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
610 void SVTK_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
615 myShiftState = shift;
616 // finishing current viewer operation
617 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
619 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
625 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
627 void SVTK_InteractorStyle::OnRightButtonDown(int ctrl,
631 this->FindPokedRenderer(x, y);
632 if(GetCurrentRenderer() == NULL)
635 myShiftState = shift;
636 // finishing current viewer operation
637 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
639 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
641 myOtherPoint = myPoint = QPoint(x, y);
642 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
643 startOperation(ForcedState);
647 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
652 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
654 void SVTK_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
659 myShiftState = shift;
660 // finishing current viewer operation
661 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
663 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
668 const char* imageZoomCursor[] = {
673 "................................",
674 "................................",
675 ".#######........................",
676 "..aaaaaaa.......................",
677 "................................",
678 ".............#####..............",
679 "...........##.aaaa##............",
680 "..........#.aa.....a#...........",
681 ".........#.a.........#..........",
682 ".........#a..........#a.........",
683 "........#.a...........#.........",
684 "........#a............#a........",
685 "........#a............#a........",
686 "........#a............#a........",
687 "........#a............#a........",
688 ".........#...........#.a........",
689 ".........#a..........#a.........",
690 ".........##.........#.a.........",
691 "........#####.....##.a..........",
692 ".......###aaa#####.aa...........",
693 "......###aa...aaaaa.......#.....",
694 ".....###aa................#a....",
695 "....###aa.................#a....",
696 "...###aa...............#######..",
697 "....#aa.................aa#aaaa.",
698 ".....a....................#a....",
699 "..........................#a....",
700 "...........................a....",
701 "................................",
702 "................................",
703 "................................",
704 "................................"};
706 const char* imageRotateCursor[] = {
711 "................................",
712 "................................",
713 "................................",
714 "................................",
715 "........#.......................",
716 ".......#.a......................",
717 "......#######...................",
718 ".......#aaaaa#####..............",
719 "........#..##.a#aa##........##..",
720 ".........a#.aa..#..a#.....##.aa.",
721 ".........#.a.....#...#..##.aa...",
722 ".........#a.......#..###.aa.....",
723 "........#.a.......#a..#aa.......",
724 "........#a.........#..#a........",
725 "........#a.........#a.#a........",
726 "........#a.........#a.#a........",
727 "........#a.........#a.#a........",
728 ".........#.........#a#.a........",
729 "........##a........#a#a.........",
730 "......##.a#.......#.#.a.........",
731 "....##.aa..##.....##.a..........",
732 "..##.aa.....a#####.aa...........",
733 "...aa.........aaa#a.............",
734 "................#.a.............",
735 "...............#.a..............",
736 "..............#.a...............",
737 "...............a................",
738 "................................",
739 "................................",
740 "................................",
741 "................................",
742 "................................"};
746 loads cursors for viewer operations - zoom, pan, etc...
748 void SVTK_InteractorStyle::loadCursors()
750 myDefCursor = QCursor(Qt::ArrowCursor);
751 myHandCursor = QCursor(Qt::PointingHandCursor);
752 myPanCursor = QCursor(Qt::SizeAllCursor);
753 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
754 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
755 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
756 myGlobalPanCursor = QCursor(Qt::CrossCursor);
757 myCursorState = false;
762 Starts Zoom operation (e.g. through menu command)
764 void SVTK_InteractorStyle::startZoom()
766 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
769 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
771 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
772 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
777 Starts Pan operation (e.g. through menu command)
779 void SVTK_InteractorStyle::startPan()
781 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
784 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
786 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
787 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
791 Starts Rotate operation (e.g. through menu command)
793 void SVTK_InteractorStyle::startRotate()
795 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
798 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
800 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
801 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
805 Set rotation point selected by user
807 void SVTK_InteractorStyle::startPointSelection()
809 myCurrRotationPointType = SVTK::StartPointSelection;
811 if(GetCurrentRenderer() != NULL) {
812 GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
813 vtkFloatingPointType aColor[3];
814 GetCurrentRenderer()->GetBackground( aColor );
815 myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
820 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
824 Set focal point selected by user
826 void SVTK_InteractorStyle::startFocalPointSelection()
828 myCurrFocalPointType = SVTK::StartFocalPointSelection;
830 if(GetCurrentRenderer() != NULL) {
831 GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
832 vtkFloatingPointType aColor[3];
833 GetCurrentRenderer()->GetBackground( aColor );
834 myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
839 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
843 Starts Spin operation (e.g. through menu command)
845 void SVTK_InteractorStyle::startSpin()
847 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
850 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
852 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
853 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
859 Starts Fit Area operation (e.g. through menu command)
861 void SVTK_InteractorStyle::startFitArea()
863 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
866 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
868 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
869 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
874 Starts Global Panning operation (e.g. through menu command)
876 void SVTK_InteractorStyle::startGlobalPan()
878 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
881 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
883 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
884 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
886 // store current zoom scale
887 myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
889 GetCurrentRenderer()->ResetCamera();
896 Fits viewer contents to rect
898 void SVTK_InteractorStyle::fitRect(const int left,
903 if (GetCurrentRenderer() == NULL)
907 int x = (left + right)/2;
908 int y = (top + bottom)/2;
909 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
910 int oldX = aSize[0]/2;
911 int oldY = aSize[1]/2;
912 TranslateView(oldX, oldY, x, y);
915 double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
916 double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
917 double zoomFactor = (dxf + dyf)/2 ;
919 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
920 if(aCam->GetParallelProjection())
921 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
923 aCam->Dolly(zoomFactor);
924 GetCurrentRenderer()->ResetCameraClippingRange();
932 Starts viewer operation (!internal usage!)
934 void SVTK_InteractorStyle::startOperation(int operation)
938 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
939 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
940 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
941 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
942 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
943 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
944 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
945 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
946 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
948 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
949 setCursor(operation);
952 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
954 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
955 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
962 Sets proper cursor for window when viewer operation is activated
964 void SVTK_InteractorStyle::setCursor(const int operation)
966 if (!GetRenderWidget()) return;
969 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
970 GetRenderWidget()->setCursor(myZoomCursor);
971 myCursorState = true;
973 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
974 GetRenderWidget()->setCursor(myPanCursor);
975 myCursorState = true;
977 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
978 GetRenderWidget()->setCursor(myRotateCursor);
979 myCursorState = true;
981 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
982 GetRenderWidget()->setCursor(mySpinCursor);
983 myCursorState = true;
985 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
986 GetRenderWidget()->setCursor(myGlobalPanCursor);
987 myCursorState = true;
989 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
990 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
991 GetRenderWidget()->setCursor(myHandCursor);
992 myCursorState = true;
994 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
996 if ( myCurrRotationPointType == SVTK::StartPointSelection ||
997 myCurrFocalPointType == SVTK::StartFocalPointSelection )
998 GetRenderWidget()->setCursor(myHandCursor);
1000 GetRenderWidget()->setCursor(myDefCursor);
1001 myCursorState = false;
1008 Called when viewer operation started (!put necessary initialization here!)
1010 void SVTK_InteractorStyle::onStartOperation()
1012 if (!GetRenderWidget())
1015 vtkRenderWindowInteractor *aRWI = this->Interactor;
1016 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
1017 aRenWin->SetDesiredUpdateRate(aRWI->GetDesiredUpdateRate());
1020 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1021 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1026 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1027 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1028 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1029 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1030 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1037 Called when viewer operation finished (!put necessary post-processing here!)
1039 void SVTK_InteractorStyle::onFinishOperation()
1041 if (!GetRenderWidget())
1044 vtkRenderWindowInteractor *aRWI = this->Interactor;
1045 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
1046 aRenWin->SetDesiredUpdateRate(aRWI->GetStillUpdateRate());
1048 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1051 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1052 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1055 QRect aRect(myPoint, myOtherPoint);
1056 aRect = aRect.normalized();
1058 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
1059 // making fit rect opeation
1061 Interactor->GetSize(w, h);
1062 int x1 = aRect.left();
1063 int y1 = h - aRect.top() - 1;
1064 int x2 = aRect.right();
1065 int y2 = h - aRect.bottom() - 1;
1066 fitRect(x1, y1, x2, y2);
1069 if (myPoint == myOtherPoint)
1071 // process point selection
1072 this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
1073 Interactor->StartPickCallback();
1075 SALOME_Actor* aHighlightedActor = NULL;
1076 vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1078 aSelectionEvent->myIsRectangle = false;
1081 GetSelector()->ClearIObjects();
1083 if( anActorCollection )
1085 anActorCollection->InitTraversal();
1086 while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1088 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1090 if( anActor->Highlight( this, aSelectionEvent, true ) )
1092 aHighlightedActor = anActor;
1099 if( !aHighlightedActor )
1101 if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
1102 myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
1104 myLastHighlitedActor = aHighlightedActor;
1108 //processing rectangle selection
1109 Interactor->StartPickCallback();
1110 GetSelector()->StartPickCallback();
1111 aSelectionEvent->myIsRectangle = true;
1114 GetSelector()->ClearIObjects();
1116 VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
1117 vtkActorCollection* aListActors = aCopy.GetActors();
1118 aListActors->InitTraversal();
1119 while(vtkActor* aActor = aListActors->GetNextActor())
1121 if(aActor->GetVisibility())
1123 if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
1125 if(aSActor->hasIO())
1126 aSActor->Highlight( this, aSelectionEvent, true );
1131 Interactor->EndPickCallback();
1132 GetSelector()->EndPickCallback();
1136 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1137 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1138 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1139 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1141 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1144 Interactor->GetSize(w, h);
1146 y = h - myPoint.y() - 1;
1157 Called during viewer operation when user moves mouse (!put necessary processing here!)
1159 void SVTK_InteractorStyle::onOperation(QPoint mousePos)
1161 if (!GetRenderWidget())
1165 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1167 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1171 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1173 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1177 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1179 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1183 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1185 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1189 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1193 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1196 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1198 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1200 myOtherPoint = mousePos;
1208 Called when user moves mouse inside viewer window and there is no active viewer operation
1209 (!put necessary processing here!)
1211 void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
1213 // processing highlighting
1214 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1215 this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1217 bool anIsChanged = false;
1219 SALOME_Actor* aPreHighlightedActor = NULL;
1220 vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1222 if ( myCurrRotationPointType == SVTK::StartPointSelection ||
1223 myCurrFocalPointType == SVTK::StartFocalPointSelection )
1225 myHighlightSelectionPointActor->SetVisibility( false );
1227 if( anActorCollection )
1229 anActorCollection->InitTraversal();
1230 while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1232 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1234 SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
1235 myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
1236 int aVtkId = myPointPicker->GetPointId();
1237 if ( aVtkId >= 0 ) {
1238 int anObjId = anActor->GetNodeObjId( aVtkId );
1240 TColStd_IndexedMapOfInteger aMapIndex;
1241 aMapIndex.Add( anObjId );
1242 myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
1244 myHighlightSelectionPointActor->SetVisibility( true );
1253 if( anActorCollection )
1255 anActorCollection->InitTraversal();
1256 while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1258 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1260 anIsChanged = anActor->PreHighlight( this, aSelectionEvent, true );
1261 if( anActor->isPreselected() )
1263 aPreHighlightedActor = anActor;
1270 if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != aPreHighlightedActor)
1271 anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );
1275 myLastPreHighlitedActor = aPreHighlightedActor;
1282 Called on finsh GlobalPan operation
1284 void SVTK_InteractorStyle::Place(const int theX, const int theY)
1286 if (GetCurrentRenderer() == NULL)
1290 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1291 int centerX = aSize[0]/2;
1292 int centerY = aSize[1]/2;
1294 TranslateView(centerX, centerY, theX, theY);
1296 // restore zoom scale
1297 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1298 cam->SetParallelScale(myScale);
1299 GetCurrentRenderer()->ResetCameraClippingRange();
1307 Translates view from Point to Point
1309 void SVTK_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1311 if (GetCurrentRenderer() == NULL)
1314 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1315 double viewFocus[4], focalDepth, viewPoint[3];
1316 vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
1317 cam->GetFocalPoint(viewFocus);
1319 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1320 viewFocus[2], viewFocus);
1321 focalDepth = viewFocus[2];
1323 this->ComputeDisplayToWorld(double(toX), double(toY),
1324 focalDepth, newPickPoint);
1325 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1326 focalDepth, oldPickPoint);
1328 // camera motion is reversed
1329 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1330 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1331 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1333 cam->GetFocalPoint(viewFocus);
1334 cam->GetPosition(viewPoint);
1335 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1336 motionVector[1] + viewFocus[1],
1337 motionVector[2] + viewFocus[2]);
1338 cam->SetPosition(motionVector[0] + viewPoint[0],
1339 motionVector[1] + viewPoint[1],
1340 motionVector[2] + viewPoint[2]);
1343 void SVTK_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1345 this->PanXY( incrX, incrY, 0, 0 );
1348 void SVTK_InteractorStyle::IncrementalZoom( const int incr )
1350 this->DollyXY( incr, incr );
1353 void SVTK_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1355 this->RotateXY( incrX, -incrY );
1359 Redefined in order to add an observer (callback) for custorm event (space mouse event)
1361 void SVTK_InteractorStyle::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1363 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1364 Superclass::SetInteractor( theInteractor );
1366 myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1369 // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1370 theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1371 theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1372 theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1373 theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1374 theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1375 theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1376 theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1377 theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1378 theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1379 theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1380 theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1381 theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1382 theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1383 theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1384 theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1386 theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1387 theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1388 theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1390 theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1391 theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1392 theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1393 theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1394 theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1396 theInteractor->AddObserver( SVTK::SetRotateGravity, EventCallbackCommand, Priority );
1397 theInteractor->AddObserver( SVTK::StartPointSelection, EventCallbackCommand, Priority );
1399 theInteractor->AddObserver( SVTK::ChangeRotationPoint, EventCallbackCommand, Priority );
1401 theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
1402 theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
1403 theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
1408 To implement cached rendering
1410 void SVTK_InteractorStyle::OnTimer()
1412 //vtkInteractorStyle::OnTimer();
1413 this->Interactor->Render();
1414 // check if bounding box was changed
1415 if ( GetCurrentRenderer() )
1417 vtkFloatingPointType aCurrBBCenter[3];
1418 if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
1420 if ( !myBBFirstCheck )
1422 if ( fabs(aCurrBBCenter[0]-myBBCenter[0]) > 1e-38 ||
1423 fabs(aCurrBBCenter[1]-myBBCenter[1]) > 1e-38 ||
1424 fabs(aCurrBBCenter[2]-myBBCenter[2]) > 1e-38 ) {
1425 // bounding box was changed => send SVTK::RotationPointChanged event
1426 // invoke event for update coordinates in SVTK_SetRotationPointDlg
1427 InvokeEvent(SVTK::BBCenterChanged,(void*)aCurrBBCenter);
1428 for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1433 for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1434 myBBFirstCheck = false;
1441 To invoke #vtkRenderWindowInteractor::CreateTimer
1443 void SVTK_InteractorStyle::Render()
1445 this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1448 void SVTK_InteractorStyle::onSpaceMouseMove( double* data )
1450 // general things, do SetCurrentRenderer() within FindPokedRenderer()
1452 GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1453 FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1455 IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in
1456 IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1457 IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis
1458 IncrementalRotate( (int)data[3], 0 ); // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1461 void SVTK_InteractorStyle::onSpaceMouseButton( int button )
1463 if( mySMDecreaseSpeedBtn == button ) {
1464 ControllerIncrement()->Decrease();
1466 if( mySMIncreaseSpeedBtn == button ) {
1467 ControllerIncrement()->Increase();
1469 if( mySMDominantCombinedSwitchBtn == button )
1470 DominantCombinedSwitch();
1473 void SVTK_InteractorStyle::DominantCombinedSwitch()
1475 printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1479 Draws rectangle by starting and current points
1481 void SVTK_InteractorStyle::drawRect()
1483 if ( !myRectBand ) {
1484 myRectBand = new QRubberBand( QRubberBand::Rectangle, GetRenderWidget() );
1486 palette.setColor(myRectBand->foregroundRole(), Qt::white);
1487 myRectBand->setPalette(palette);
1491 QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
1492 myRectBand->setGeometry( aRect );
1493 myRectBand->setVisible( aRect.isValid() );
1497 \brief Delete rubber band on the end on the dragging operation.
1499 void SVTK_InteractorStyle::endDrawRect()
1501 if ( myRectBand ) myRectBand->hide();
1508 Main process event method (reimplemented from #vtkInteractorStyle)
1510 void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
1511 unsigned long event,
1516 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1517 SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1518 int aSpeedIncrement=self->ControllerIncrement()->Current();
1519 vtkFloatingPointType aCenter[3];
1520 vtkFloatingPointType* aSelectedPoint;
1523 case SVTK::SpaceMouseMoveEvent :
1524 self->onSpaceMouseMove( (double*)callData );
1526 case SVTK::SpaceMouseButtonEvent :
1527 self->onSpaceMouseButton( *((int*)callData) );
1529 case SVTK::PanLeftEvent:
1530 self->IncrementalPan(-aSpeedIncrement, 0);
1532 case SVTK::PanRightEvent:
1533 self->IncrementalPan(aSpeedIncrement, 0);
1535 case SVTK::PanUpEvent:
1536 self->IncrementalPan(0, aSpeedIncrement);
1538 case SVTK::PanDownEvent:
1539 self->IncrementalPan(0, -aSpeedIncrement);
1541 case SVTK::ZoomInEvent:
1542 self->IncrementalZoom(aSpeedIncrement);
1544 case SVTK::ZoomOutEvent:
1545 self->IncrementalZoom(-aSpeedIncrement);
1547 case SVTK::RotateLeftEvent:
1548 self->IncrementalRotate(-aSpeedIncrement, 0);
1550 case SVTK::RotateRightEvent:
1551 self->IncrementalRotate(aSpeedIncrement, 0);
1553 case SVTK::RotateUpEvent:
1554 self->IncrementalRotate(0, -aSpeedIncrement);
1556 case SVTK::RotateDownEvent:
1557 self->IncrementalRotate(0, aSpeedIncrement);
1559 case SVTK::PlusSpeedIncrementEvent:
1560 self->ControllerIncrement()->Increase();
1562 case SVTK::MinusSpeedIncrementEvent:
1563 self->ControllerIncrement()->Decrease();
1565 case SVTK::SetSpeedIncrementEvent:
1566 self->ControllerIncrement()->SetStartValue(*((int*)callData));
1569 case SVTK::SetSMDecreaseSpeedEvent:
1570 self->mySMDecreaseSpeedBtn = *((int*)callData);
1572 case SVTK::SetSMIncreaseSpeedEvent:
1573 self->mySMIncreaseSpeedBtn = *((int*)callData);
1575 case SVTK::SetSMDominantCombinedSwitchEvent:
1576 self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1579 case SVTK::StartZoom:
1582 case SVTK::StartPan:
1585 case SVTK::StartRotate:
1586 self->startRotate();
1588 case SVTK::StartGlobalPan:
1589 self->startGlobalPan();
1591 case SVTK::StartFitArea:
1592 self->startFitArea();
1595 case SVTK::SetRotateGravity:
1596 if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1598 self->myHighlightSelectionPointActor->SetVisibility( false );
1599 if( self->GetCurrentRenderer() != NULL )
1600 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1601 self->GetRenderWidget()->setCursor(self->myDefCursor);
1603 self->myPrevRotationPointType = self->myCurrRotationPointType;
1604 self->myCurrRotationPointType = SVTK::SetRotateGravity;
1605 if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) )
1606 // invoke event for update coordinates in SVTK_SetRotationPointDlg
1607 self->InvokeEvent(SVTK::BBCenterChanged,(void*)aCenter);
1609 case SVTK::StartPointSelection:
1610 self->startPointSelection();
1613 case SVTK::ChangeRotationPoint:
1614 if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1616 self->myHighlightSelectionPointActor->SetVisibility( false );
1617 if( self->GetCurrentRenderer() != NULL )
1618 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1619 self->GetRenderWidget()->setCursor(self->myDefCursor);
1621 self->myPrevRotationPointType = self->myCurrRotationPointType;
1622 self->myCurrRotationPointType = SVTK::SetRotateSelected;
1623 aSelectedPoint = (vtkFloatingPointType*)callData;
1624 self->myRotationPointX = aSelectedPoint[0];
1625 self->myRotationPointY = aSelectedPoint[1];
1626 self->myRotationPointZ = aSelectedPoint[2];
1629 case SVTK::SetFocalPointGravity:
1630 if ( self->myCurrFocalPointType == SVTK::StartPointSelection )
1632 self->myHighlightSelectionPointActor->SetVisibility( false );
1633 if( self->GetCurrentRenderer() != NULL )
1634 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1635 self->GetRenderWidget()->setCursor(self->myDefCursor);
1637 self->myCurrFocalPointType = SVTK::SetFocalPointGravity;
1638 if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) {
1639 // invoke event for update coordinates in SVTK_ViewParameterDlg
1640 self->InvokeEvent(SVTK::FocalPointChanged,(void*)aCenter);
1643 case SVTK::StartFocalPointSelection:
1644 self->startFocalPointSelection();
1647 case SVTK::SetFocalPointSelected:
1648 if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
1650 self->myHighlightSelectionPointActor->SetVisibility( false );
1651 if( self->GetCurrentRenderer() != NULL )
1652 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1653 self->GetRenderWidget()->setCursor(self->myDefCursor);
1655 self->myPrevFocalPointType = self->myCurrFocalPointType;
1656 self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
1662 Superclass::ProcessEvents( object, event, clientData, callData );
1666 To handle keyboard event (reimplemented from #vtkInteractorStyle)
1668 void SVTK_InteractorStyle::OnChar()
1670 char key = GetInteractor()->GetKeyCode();
1672 case '+': ControllerIncrement()->Increase(); break;
1673 case '-': ControllerIncrement()->Decrease(); break;
1678 Redefined vtkInteractorStyle::OnKeyDown
1680 void SVTK_InteractorStyle::OnKeyDown()
1682 bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1683 if (bInvokeSuperclass){
1684 Superclass::OnKeyDown();
1689 Provide instructions for Picking
1691 void SVTK_InteractorStyle::ActionPicking()
1694 Interactor->GetEventPosition( x, y );
1695 FindPokedRenderer( x, y );
1697 myOtherPoint = myPoint = QPoint(x, y);
1699 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1700 onFinishOperation();
1701 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1705 To set current increment controller
1707 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1709 myControllerOnKeyDown=theController;
1713 To get current OnKeyDown controller
1715 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1717 return myControllerOnKeyDown.GetPointer();
1721 To set current increment controller
1723 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1725 myControllerIncrement=theController;
1729 To modify current increment controller
1731 void SVTK_InteractorStyle::SetIncrementSpeed(const int theValue, const int theMode)
1733 SVTK_ControllerIncrement* c = 0;
1735 case 0: c = SVTK_ControllerIncrement::New(); break;
1736 case 1: c = SVTK_GeomControllerIncrement::New(); break;
1738 c->SetStartValue(theValue);
1740 SetControllerIncrement(c);
1745 To get current increment controller
1747 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
1749 return myControllerIncrement.GetPointer();
1752 vtkStandardNewMacro(SVTK_ControllerIncrement);
1753 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
1757 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
1760 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
1762 myIncrement=theValue;
1764 int SVTK_ControllerIncrement::Current()const
1768 int SVTK_ControllerIncrement::Increase()
1773 int SVTK_ControllerIncrement::Decrease()
1781 vtkStandardNewMacro(SVTK_GeomControllerIncrement);
1782 SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
1785 SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement()
1788 int SVTK_GeomControllerIncrement::Increase()
1793 int SVTK_GeomControllerIncrement::Decrease()
1802 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
1807 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
1814 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
1818 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)