1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
30 #include "SVTK_InteractorStyle.h"
32 #include "VTKViewer_Utilities.h"
33 #include "SVTK_GenericRenderWindowInteractor.h"
35 #include "SVTK_Selection.h"
36 #include "SVTK_Event.h"
37 #include "SVTK_Selector.h"
38 #include "SVTK_Functor.h"
40 #include "VTKViewer_Algorithm.h"
41 #include "SVTK_Functor.h"
43 #include "SALOME_Actor.h"
45 #include <vtkObjectFactory.h>
47 #include <vtkCommand.h>
48 #include <vtkCamera.h>
49 #include <vtkRenderer.h>
50 #include <vtkPicker.h>
51 #include <vtkRenderWindow.h>
52 #include <vtkRenderWindowInteractor.h>
53 #include <vtkCallbackCommand.h>
54 #include <vtkRendererCollection.h>
56 #include <qapplication.h>
58 //VRV: porting on Qt 3.0.5
59 #if QT_VERSION >= 0x030005
62 //VRV: porting on Qt 3.0.5
71 GetEventPosition(vtkRenderWindowInteractor* theInteractor,
75 theInteractor->GetEventPosition(theX,theY);
76 theY = theInteractor->GetSize()[1] - theY - 1;
79 //==================================================================
80 // function : GetFirstSALOMEActor
82 //==================================================================
86 operator()(SALOME_Actor* theActor)
88 return theActor->hasIO();
94 GetFirstSALOMEActor(vtkPicker *thePicker)
96 return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
101 vtkStandardNewMacro(SVTK_InteractorStyle);
107 ::SVTK_InteractorStyle():
108 mySelectionEvent(new SVTK_SelectionEvent()),
109 myPicker(vtkPicker::New()),
110 myLastHighlitedActor(NULL),
111 myLastPreHighlitedActor(NULL),
112 myControllerIncrement(SVTK_ControllerIncrement::New()),
113 myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New())
117 this->MotionFactor = 10.0;
118 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
119 this->RadianToDegree = 180.0 / vtkMath::Pi();
120 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
124 // set custom event handling function (to handle 3d space mouse events)
125 EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
127 // set default values of properties. user may edit them in preferences.
128 mySMDecreaseSpeedBtn = 1;
129 mySMIncreaseSpeedBtn = 2;
130 mySMDominantCombinedSwitchBtn = 9;
132 myControllerIncrement->Delete();
133 myControllerOnKeyDown->Delete();
140 ::~SVTK_InteractorStyle()
145 \return widget for rendering
151 return myInteractor->GetRenderWidget();
161 return myInteractor->GetSelector();
165 Generate special SVTK_SelectionEvent
169 ::GetSelectionEvent()
171 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
173 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
174 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
176 mySelectionEvent->myLastX = mySelectionEvent->myX;
177 mySelectionEvent->myLastY = mySelectionEvent->myY;
179 GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
181 return mySelectionEvent.get();
185 Generate special SVTK_SelectionEvent with flipped Y coordinate
189 ::GetSelectionEventFlipY()
191 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
193 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
194 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
196 mySelectionEvent->myLastX = mySelectionEvent->myX;
197 mySelectionEvent->myLastY = mySelectionEvent->myY;
199 this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
201 return mySelectionEvent.get();
206 ::RotateXY(int dx, int dy)
208 if(GetCurrentRenderer() == NULL)
211 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
212 double aDeltaElevation = -20.0 / size[1];
213 double aDeltaAzimuth = -20.0 / size[0];
215 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
216 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
218 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
221 cam->OrthogonalizeViewUp();
223 GetCurrentRenderer()->ResetCameraClippingRange();
230 ::PanXY(int x, int y, int oldX, int oldY)
232 TranslateView(x, y, oldX, oldY);
239 ::DollyXY(int dx, int dy)
241 if (GetCurrentRenderer() == NULL)
244 double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
245 double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
247 double zoomFactor = pow((double)1.1, dxf + dyf);
249 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
250 if (aCam->GetParallelProjection())
251 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
253 aCam->Dolly(zoomFactor);
254 GetCurrentRenderer()->ResetCameraClippingRange();
262 ::SpinXY(int x, int y, int oldX, int oldY)
266 if (GetCurrentRenderer() == NULL)
269 double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
270 (double)(x - GetCurrentRenderer()->GetCenter()[0]));
271 double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
272 (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
274 newAngle *= this->RadianToDegree;
275 oldAngle *= this->RadianToDegree;
277 cam = GetCurrentRenderer()->GetActiveCamera();
278 cam->Roll(newAngle - oldAngle);
279 cam->OrthogonalizeViewUp();
292 this->FindPokedRenderer(0,0);
293 this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
297 To handle mouse move event
304 GetEventPosition( this->Interactor, x, y );
305 this->OnMouseMove( this->Interactor->GetControlKey(),
306 this->Interactor->GetShiftKey(),
311 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
318 GetEventPosition( this->Interactor, x, y );
319 this->OnLeftButtonDown( this->Interactor->GetControlKey(),
320 this->Interactor->GetShiftKey(),
325 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
332 GetEventPosition( this->Interactor, x, y );
333 this->OnLeftButtonUp( this->Interactor->GetControlKey(),
334 this->Interactor->GetShiftKey(),
339 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
343 ::OnMiddleButtonDown()
346 GetEventPosition( this->Interactor, x, y );
347 this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
348 this->Interactor->GetShiftKey(),
353 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
360 GetEventPosition( this->Interactor, x, y );
361 this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
362 this->Interactor->GetShiftKey(),
367 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
371 ::OnRightButtonDown()
374 GetEventPosition( this->Interactor, x, y );
375 this->OnRightButtonDown( this->Interactor->GetControlKey(),
376 this->Interactor->GetShiftKey(),
381 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
388 GetEventPosition( this->Interactor, x, y );
389 this->OnRightButtonUp( this->Interactor->GetControlKey(),
390 this->Interactor->GetShiftKey(),
395 To handle mouse move event
399 ::OnMouseMove(int vtkNotUsed(ctrl),
403 myShiftState = shift;
404 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
405 onOperation(QPoint(x, y));
406 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
407 onCursorMove(QPoint(x, y));
411 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
415 ::OnLeftButtonDown(int ctrl, int shift,
418 this->FindPokedRenderer(x, y);
419 if(GetCurrentRenderer() == NULL)
422 myShiftState = shift;
423 // finishing current viewer operation
424 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
426 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
428 myOtherPoint = myPoint = QPoint(x, y);
429 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
430 startOperation(ForcedState);
433 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
435 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
441 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
445 ::OnLeftButtonUp(int vtkNotUsed(ctrl),
450 myShiftState = shift;
451 // finishing current viewer operation
452 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
454 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
459 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
463 ::OnMiddleButtonDown(int ctrl,
467 this->FindPokedRenderer(x, y);
468 if(GetCurrentRenderer() == NULL)
471 myShiftState = shift;
472 // finishing current viewer operation
473 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
475 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
477 myOtherPoint = myPoint = QPoint(x, y);
478 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
479 startOperation(ForcedState);
483 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
489 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
493 ::OnMiddleButtonUp(int vtkNotUsed(ctrl),
498 myShiftState = shift;
499 // finishing current viewer operation
500 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
502 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
508 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
512 ::OnRightButtonDown(int ctrl,
516 this->FindPokedRenderer(x, y);
517 if(GetCurrentRenderer() == NULL)
520 myShiftState = shift;
521 // finishing current viewer operation
522 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
524 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
526 myOtherPoint = myPoint = QPoint(x, y);
527 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
528 startOperation(ForcedState);
532 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
537 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
541 ::OnRightButtonUp(int vtkNotUsed(ctrl),
546 myShiftState = shift;
547 // finishing current viewer operation
548 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
550 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
555 const char* imageZoomCursor[] = {
560 "................................",
561 "................................",
562 ".#######........................",
563 "..aaaaaaa.......................",
564 "................................",
565 ".............#####..............",
566 "...........##.aaaa##............",
567 "..........#.aa.....a#...........",
568 ".........#.a.........#..........",
569 ".........#a..........#a.........",
570 "........#.a...........#.........",
571 "........#a............#a........",
572 "........#a............#a........",
573 "........#a............#a........",
574 "........#a............#a........",
575 ".........#...........#.a........",
576 ".........#a..........#a.........",
577 ".........##.........#.a.........",
578 "........#####.....##.a..........",
579 ".......###aaa#####.aa...........",
580 "......###aa...aaaaa.......#.....",
581 ".....###aa................#a....",
582 "....###aa.................#a....",
583 "...###aa...............#######..",
584 "....#aa.................aa#aaaa.",
585 ".....a....................#a....",
586 "..........................#a....",
587 "...........................a....",
588 "................................",
589 "................................",
590 "................................",
591 "................................"};
593 const char* imageRotateCursor[] = {
598 "................................",
599 "................................",
600 "................................",
601 "................................",
602 "........#.......................",
603 ".......#.a......................",
604 "......#######...................",
605 ".......#aaaaa#####..............",
606 "........#..##.a#aa##........##..",
607 ".........a#.aa..#..a#.....##.aa.",
608 ".........#.a.....#...#..##.aa...",
609 ".........#a.......#..###.aa.....",
610 "........#.a.......#a..#aa.......",
611 "........#a.........#..#a........",
612 "........#a.........#a.#a........",
613 "........#a.........#a.#a........",
614 "........#a.........#a.#a........",
615 ".........#.........#a#.a........",
616 "........##a........#a#a.........",
617 "......##.a#.......#.#.a.........",
618 "....##.aa..##.....##.a..........",
619 "..##.aa.....a#####.aa...........",
620 "...aa.........aaa#a.............",
621 "................#.a.............",
622 "...............#.a..............",
623 "..............#.a...............",
624 "...............a................",
625 "................................",
626 "................................",
627 "................................",
628 "................................",
629 "................................"};
633 loads cursors for viewer operations - zoom, pan, etc...
639 myDefCursor = QCursor(Qt::ArrowCursor);
640 myHandCursor = QCursor(Qt::PointingHandCursor);
641 myPanCursor = QCursor(Qt::SizeAllCursor);
642 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
643 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
644 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
645 myGlobalPanCursor = QCursor(Qt::CrossCursor);
646 myCursorState = false;
651 Starts Zoom operation (e.g. through menu command)
657 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
660 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
662 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
663 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
668 Starts Pan operation (e.g. through menu command)
674 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
677 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
679 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
680 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
684 Starts Rotate operation (e.g. through menu command)
690 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
693 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
695 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
696 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
701 Starts Spin operation (e.g. through menu command)
707 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
710 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
712 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
713 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
719 Starts Fit Area operation (e.g. through menu command)
725 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
728 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
730 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
731 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
736 Starts Global Panning operation (e.g. through menu command)
742 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
745 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
747 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
748 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
750 // store current zoom scale
751 myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
753 GetCurrentRenderer()->ResetCamera();
760 Fits viewer contents to rect
764 ::fitRect(const int left,
769 if (GetCurrentRenderer() == NULL)
773 int x = (left + right)/2;
774 int y = (top + bottom)/2;
775 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
776 int oldX = aSize[0]/2;
777 int oldY = aSize[1]/2;
778 TranslateView(oldX, oldY, x, y);
781 double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
782 double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
783 double zoomFactor = (dxf + dyf)/2 ;
785 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
786 if(aCam->GetParallelProjection())
787 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
789 aCam->Dolly(zoomFactor);
790 GetCurrentRenderer()->ResetCameraClippingRange();
798 Starts viewer operation (!internal usage!)
802 ::startOperation(int operation)
806 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
807 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
808 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
809 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
810 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
811 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
812 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
813 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
814 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
816 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
817 setCursor(operation);
820 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
822 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
823 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
830 Sets proper cursor for window when viewer operation is activated
834 ::setCursor(const int operation)
836 if (!GetRenderWidget()) return;
839 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
840 GetRenderWidget()->setCursor(myZoomCursor);
841 myCursorState = true;
843 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
844 GetRenderWidget()->setCursor(myPanCursor);
845 myCursorState = true;
847 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
848 GetRenderWidget()->setCursor(myRotateCursor);
849 myCursorState = true;
851 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
852 GetRenderWidget()->setCursor(mySpinCursor);
853 myCursorState = true;
855 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
856 GetRenderWidget()->setCursor(myGlobalPanCursor);
857 myCursorState = true;
859 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
860 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
861 GetRenderWidget()->setCursor(myHandCursor);
862 myCursorState = true;
864 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
866 GetRenderWidget()->setCursor(myDefCursor);
867 myCursorState = false;
874 Called when viewer operation started (!put necessary initialization here!)
880 if (!GetRenderWidget())
883 vtkRenderWindowInteractor *aRWI = this->Interactor;
884 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
885 aRenWin->SetDesiredUpdateRate(aRWI->GetDesiredUpdateRate());
888 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
889 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
891 QPainter p(GetRenderWidget());
892 p.setPen(Qt::lightGray);
893 p.setRasterOp(Qt::XorROP);
894 p.drawRect(QRect(myPoint, myOtherPoint));
897 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
898 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
899 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
900 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
901 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
908 Called when viewer operation finished (!put necessary post-processing here!)
912 ::onFinishOperation()
914 if (!GetRenderWidget())
917 vtkRenderWindowInteractor *aRWI = this->Interactor;
918 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
919 aRenWin->SetDesiredUpdateRate(aRWI->GetStillUpdateRate());
921 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
924 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
925 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
927 QPainter aPainter(GetRenderWidget());
928 aPainter.setPen(Qt::lightGray);
929 aPainter.setRasterOp(Qt::XorROP);
930 QRect aRect(myPoint, myOtherPoint);
931 aPainter.drawRect(aRect);
932 aRect = aRect.normalize();
934 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
935 // making fit rect opeation
937 Interactor->GetSize(w, h);
938 int x1 = aRect.left();
939 int y1 = h - aRect.top() - 1;
940 int x2 = aRect.right();
941 int y2 = h - aRect.bottom() - 1;
942 fitRect(x1, y1, x2, y2);
945 if (myPoint == myOtherPoint) {
946 // process point selection
947 this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
948 Interactor->StartPickCallback();
950 myPicker->Pick(aSelectionEvent->myX,
951 aSelectionEvent->myY,
953 GetCurrentRenderer());
955 SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
956 aSelectionEvent->myIsRectangle = false;
959 GetSelector()->ClearIObjects();
962 anActor->Highlight( this, aSelectionEvent, true );
964 if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
965 myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
967 myLastHighlitedActor = anActor;
970 //processing rectangle selection
971 Interactor->StartPickCallback();
972 GetSelector()->StartPickCallback();
973 aSelectionEvent->myIsRectangle = true;
976 GetSelector()->ClearIObjects();
978 vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors();
979 aListActors->InitTraversal();
980 while(vtkActor* aActor = aListActors->GetNextActor()){
981 if(aActor->GetVisibility()){
982 if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){
983 if(aSActor->hasIO()){
984 aSActor->Highlight( this, aSelectionEvent, true );
990 Interactor->EndPickCallback();
991 GetSelector()->EndPickCallback();
995 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
996 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
997 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
998 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1000 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1003 Interactor->GetSize(w, h);
1005 y = h - myPoint.y() - 1;
1016 Called during viewer operation when user moves mouse (!put necessary processing here!)
1019 SVTK_InteractorStyle
1020 ::onOperation(QPoint mousePos)
1022 if (!GetRenderWidget())
1026 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1028 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1032 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1034 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1038 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1040 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1044 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1046 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1050 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1054 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1057 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1059 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1061 QPainter p(GetRenderWidget());
1062 p.setPen(Qt::lightGray);
1063 p.setRasterOp(Qt::XorROP);
1064 p.drawRect(QRect(myPoint, myOtherPoint));
1065 myOtherPoint = mousePos;
1066 p.drawRect(QRect(myPoint, myOtherPoint));
1073 Called when user moves mouse inside viewer window and there is no active viewer operation
1074 (!put necessary processing here!)
1077 SVTK_InteractorStyle
1078 ::onCursorMove(QPoint mousePos)
1080 // processing highlighting
1081 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1082 this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1084 bool anIsChanged = false;
1086 myPicker->Pick(aSelectionEvent->myX,
1087 aSelectionEvent->myY,
1089 GetCurrentRenderer());
1091 SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
1093 anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
1096 if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
1097 anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );
1099 myLastPreHighlitedActor = anActor;
1106 Called on finsh GlobalPan operation
1109 SVTK_InteractorStyle
1110 ::Place(const int theX, const int theY)
1112 if (GetCurrentRenderer() == NULL)
1116 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1117 int centerX = aSize[0]/2;
1118 int centerY = aSize[1]/2;
1120 TranslateView(centerX, centerY, theX, theY);
1122 // restore zoom scale
1123 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1124 cam->SetParallelScale(myScale);
1125 GetCurrentRenderer()->ResetCameraClippingRange();
1133 Translates view from Point to Point
1136 SVTK_InteractorStyle
1137 ::TranslateView(int toX, int toY, int fromX, int fromY)
1139 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1140 double viewFocus[4], focalDepth, viewPoint[3];
1141 vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
1142 cam->GetFocalPoint(viewFocus);
1144 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1145 viewFocus[2], viewFocus);
1146 focalDepth = viewFocus[2];
1148 this->ComputeDisplayToWorld(double(toX), double(toY),
1149 focalDepth, newPickPoint);
1150 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1151 focalDepth, oldPickPoint);
1153 // camera motion is reversed
1154 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1155 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1156 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1158 cam->GetFocalPoint(viewFocus);
1159 cam->GetPosition(viewPoint);
1160 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1161 motionVector[1] + viewFocus[1],
1162 motionVector[2] + viewFocus[2]);
1163 cam->SetPosition(motionVector[0] + viewPoint[0],
1164 motionVector[1] + viewPoint[1],
1165 motionVector[2] + viewPoint[2]);
1169 SVTK_InteractorStyle
1170 ::IncrementalPan( const int incrX, const int incrY )
1172 this->PanXY( incrX, incrY, 0, 0 );
1176 SVTK_InteractorStyle
1177 ::IncrementalZoom( const int incr )
1179 this->DollyXY( incr, incr );
1183 SVTK_InteractorStyle
1184 ::IncrementalRotate( const int incrX, const int incrY )
1186 this->RotateXY( incrX, -incrY );
1190 Redefined in order to add an observer (callback) for custorm event (space mouse event)
1193 SVTK_InteractorStyle
1194 ::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1196 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1197 Superclass::SetInteractor( theInteractor );
1199 myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1202 // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1203 theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1204 theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1205 theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1206 theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1207 theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1208 theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1209 theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1210 theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1211 theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1212 theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1213 theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1214 theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1215 theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1216 theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1217 theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1219 theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1220 theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1221 theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1223 theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1224 theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1225 theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1226 theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1227 theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1232 To implement cached rendering
1235 SVTK_InteractorStyle
1238 //vtkInteractorStyle::OnTimer();
1239 this->Interactor->Render();
1243 To invoke #vtkRenderWindowInteractor::CreateTimer
1246 SVTK_InteractorStyle
1249 this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1253 SVTK_InteractorStyle
1254 ::onSpaceMouseMove( double* data )
1256 // general things, do SetCurrentRenderer() within FindPokedRenderer()
1258 GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1259 FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1261 IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in
1262 IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1263 IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis
1264 IncrementalRotate( (int)data[3], 0 ); // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1268 SVTK_InteractorStyle
1269 ::onSpaceMouseButton( int button )
1271 if( mySMDecreaseSpeedBtn == button ) {
1272 ControllerIncrement()->Decrease();
1274 if( mySMIncreaseSpeedBtn == button ) {
1275 ControllerIncrement()->Increase();
1277 if( mySMDominantCombinedSwitchBtn == button )
1278 DominantCombinedSwitch();
1282 SVTK_InteractorStyle
1283 ::DominantCombinedSwitch()
1285 printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1289 Main process event method (reimplemented from #vtkInteractorStyle)
1292 SVTK_InteractorStyle
1293 ::ProcessEvents( vtkObject* object,
1294 unsigned long event,
1299 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1300 SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1301 int aSpeedIncrement=self->ControllerIncrement()->Current();
1304 case SVTK::SpaceMouseMoveEvent :
1305 self->onSpaceMouseMove( (double*)callData );
1307 case SVTK::SpaceMouseButtonEvent :
1308 self->onSpaceMouseButton( *((int*)callData) );
1310 case SVTK::PanLeftEvent:
1311 self->IncrementalPan(-aSpeedIncrement, 0);
1313 case SVTK::PanRightEvent:
1314 self->IncrementalPan(aSpeedIncrement, 0);
1316 case SVTK::PanUpEvent:
1317 self->IncrementalPan(0, aSpeedIncrement);
1319 case SVTK::PanDownEvent:
1320 self->IncrementalPan(0, -aSpeedIncrement);
1322 case SVTK::ZoomInEvent:
1323 self->IncrementalZoom(aSpeedIncrement);
1325 case SVTK::ZoomOutEvent:
1326 self->IncrementalZoom(-aSpeedIncrement);
1328 case SVTK::RotateLeftEvent:
1329 self->IncrementalRotate(-aSpeedIncrement, 0);
1331 case SVTK::RotateRightEvent:
1332 self->IncrementalRotate(aSpeedIncrement, 0);
1334 case SVTK::RotateUpEvent:
1335 self->IncrementalRotate(0, -aSpeedIncrement);
1337 case SVTK::RotateDownEvent:
1338 self->IncrementalRotate(0, aSpeedIncrement);
1340 case SVTK::PlusSpeedIncrementEvent:
1341 self->ControllerIncrement()->Increase();
1343 case SVTK::MinusSpeedIncrementEvent:
1344 self->ControllerIncrement()->Decrease();
1346 case SVTK::SetSpeedIncrementEvent:
1347 self->ControllerIncrement()->SetStartValue(*((int*)callData));
1350 case SVTK::SetSMDecreaseSpeedEvent:
1351 self->mySMDecreaseSpeedBtn = *((int*)callData);
1353 case SVTK::SetSMIncreaseSpeedEvent:
1354 self->mySMIncreaseSpeedBtn = *((int*)callData);
1356 case SVTK::SetSMDominantCombinedSwitchEvent:
1357 self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1360 case SVTK::StartZoom:
1363 case SVTK::StartPan:
1366 case SVTK::StartRotate:
1367 self->startRotate();
1369 case SVTK::StartGlobalPan:
1370 self->startGlobalPan();
1372 case SVTK::StartFitArea:
1373 self->startFitArea();
1379 Superclass::ProcessEvents( object, event, clientData, callData );
1383 To handle keyboard event (reimplemented from #vtkInteractorStyle)
1385 void SVTK_InteractorStyle::OnChar()
1390 Redefined vtkInteractorStyle::OnKeyDown
1392 void SVTK_InteractorStyle::OnKeyDown()
1394 bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1395 if (bInvokeSuperclass){
1396 Superclass::OnKeyDown();
1401 Provide instructions for Picking
1403 void SVTK_InteractorStyle::ActionPicking()
1406 Interactor->GetEventPosition( x, y );
1407 FindPokedRenderer( x, y );
1409 myOtherPoint = myPoint = QPoint(x, y);
1411 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1412 onFinishOperation();
1413 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1417 To set current increment controller
1419 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1421 myControllerOnKeyDown=theController;
1425 To get current OnKeyDown controller
1427 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1429 return myControllerOnKeyDown.GetPointer();
1433 To get current increment controller
1435 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1437 myControllerIncrement=theController;
1441 To get current increment controller
1443 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
1445 return myControllerIncrement.GetPointer();
1448 vtkStandardNewMacro(SVTK_ControllerIncrement);
1449 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
1453 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
1456 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
1458 myIncrement=theValue;
1460 int SVTK_ControllerIncrement::Current()const
1464 int SVTK_ControllerIncrement::Increase()
1469 int SVTK_ControllerIncrement::Decrease()
1477 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
1482 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
1489 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
1493 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)