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 //----------------------------------------------------------------------------
102 vtkStandardNewMacro(SVTK_InteractorStyle);
103 //----------------------------------------------------------------------------
105 ::SVTK_InteractorStyle():
106 mySelectionEvent(new SVTK_SelectionEvent()),
107 myPicker(vtkPicker::New()),
108 myLastHighlitedActor(NULL),
109 myLastPreHighlitedActor(NULL),
110 myControllerIncrement(SVTK_ControllerIncrement::New()),
111 myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New())
115 this->MotionFactor = 10.0;
116 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
117 this->RadianToDegree = 180.0 / vtkMath::Pi();
118 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
122 // set custom event handling function (to handle 3d space mouse events)
123 EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
125 // set default values of properties. user may edit them in preferences.
126 mySMDecreaseSpeedBtn = 1;
127 mySMIncreaseSpeedBtn = 2;
128 mySMDominantCombinedSwitchBtn = 9;
130 myControllerIncrement->Delete();
131 myControllerOnKeyDown->Delete();
134 //----------------------------------------------------------------------------
136 ::~SVTK_InteractorStyle()
140 //----------------------------------------------------------------------------
145 return myInteractor->GetRenderWidget();
152 return myInteractor->GetSelector();
155 //----------------------------------------------------------------------------
158 ::GetSelectionEvent()
160 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
162 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
163 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
165 mySelectionEvent->myLastX = mySelectionEvent->myX;
166 mySelectionEvent->myLastY = mySelectionEvent->myY;
168 GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
170 return mySelectionEvent.get();
173 //----------------------------------------------------------------------------
176 ::GetSelectionEventFlipY()
178 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
180 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
181 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
183 mySelectionEvent->myLastX = mySelectionEvent->myX;
184 mySelectionEvent->myLastY = mySelectionEvent->myY;
186 this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
188 return mySelectionEvent.get();
191 //----------------------------------------------------------------------------
194 ::RotateXY(int dx, int dy)
196 if(GetCurrentRenderer() == NULL)
199 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
200 double aDeltaElevation = -20.0 / size[1];
201 double aDeltaAzimuth = -20.0 / size[0];
203 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
204 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
206 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
209 cam->OrthogonalizeViewUp();
211 GetCurrentRenderer()->ResetCameraClippingRange();
216 //----------------------------------------------------------------------------
219 ::PanXY(int x, int y, int oldX, int oldY)
221 TranslateView(x, y, oldX, oldY);
226 //----------------------------------------------------------------------------
229 ::DollyXY(int dx, int dy)
231 if (GetCurrentRenderer() == NULL)
234 double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
235 double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
237 double zoomFactor = pow((double)1.1, dxf + dyf);
239 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
240 if (aCam->GetParallelProjection())
241 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
243 aCam->Dolly(zoomFactor);
244 GetCurrentRenderer()->ResetCameraClippingRange();
250 //----------------------------------------------------------------------------
253 ::SpinXY(int x, int y, int oldX, int oldY)
257 if (GetCurrentRenderer() == NULL)
260 double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
261 (double)(x - GetCurrentRenderer()->GetCenter()[0]));
262 double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
263 (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
265 newAngle *= this->RadianToDegree;
266 oldAngle *= this->RadianToDegree;
268 cam = GetCurrentRenderer()->GetActiveCamera();
269 cam->Roll(newAngle - oldAngle);
270 cam->OrthogonalizeViewUp();
276 //----------------------------------------------------------------------------
281 this->FindPokedRenderer(0,0);
282 this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
286 //----------------------------------------------------------------------------
292 GetEventPosition( this->Interactor, x, y );
293 this->OnMouseMove( this->Interactor->GetControlKey(),
294 this->Interactor->GetShiftKey(),
299 //----------------------------------------------------------------------------
305 GetEventPosition( this->Interactor, x, y );
306 this->OnLeftButtonDown( this->Interactor->GetControlKey(),
307 this->Interactor->GetShiftKey(),
312 //----------------------------------------------------------------------------
318 GetEventPosition( this->Interactor, x, y );
319 this->OnLeftButtonUp( this->Interactor->GetControlKey(),
320 this->Interactor->GetShiftKey(),
325 //----------------------------------------------------------------------------
328 ::OnMiddleButtonDown()
331 GetEventPosition( this->Interactor, x, y );
332 this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
333 this->Interactor->GetShiftKey(),
338 //----------------------------------------------------------------------------
344 GetEventPosition( this->Interactor, x, y );
345 this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
346 this->Interactor->GetShiftKey(),
351 //----------------------------------------------------------------------------
354 ::OnRightButtonDown()
357 GetEventPosition( this->Interactor, x, y );
358 this->OnRightButtonDown( this->Interactor->GetControlKey(),
359 this->Interactor->GetShiftKey(),
363 //----------------------------------------------------------------------------
369 GetEventPosition( this->Interactor, x, y );
370 this->OnRightButtonUp( this->Interactor->GetControlKey(),
371 this->Interactor->GetShiftKey(),
376 //----------------------------------------------------------------------------
379 ::OnMouseMove(int vtkNotUsed(ctrl),
383 myShiftState = shift;
384 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
385 onOperation(QPoint(x, y));
386 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
387 onCursorMove(QPoint(x, y));
391 //----------------------------------------------------------------------------
394 ::OnLeftButtonDown(int ctrl, int shift,
397 this->FindPokedRenderer(x, y);
398 if(GetCurrentRenderer() == NULL)
401 myShiftState = shift;
402 // finishing current viewer operation
403 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
405 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
407 myOtherPoint = myPoint = QPoint(x, y);
408 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
409 startOperation(ForcedState);
412 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
414 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
420 //----------------------------------------------------------------------------
423 ::OnLeftButtonUp(int vtkNotUsed(ctrl),
428 myShiftState = shift;
429 // finishing current viewer operation
430 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
432 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
437 //----------------------------------------------------------------------------
440 ::OnMiddleButtonDown(int ctrl,
444 this->FindPokedRenderer(x, y);
445 if(GetCurrentRenderer() == NULL)
448 myShiftState = shift;
449 // finishing current viewer operation
450 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
452 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
454 myOtherPoint = myPoint = QPoint(x, y);
455 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
456 startOperation(ForcedState);
460 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
465 //----------------------------------------------------------------------------
468 ::OnMiddleButtonUp(int vtkNotUsed(ctrl),
473 myShiftState = shift;
474 // finishing current viewer operation
475 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
477 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
482 //----------------------------------------------------------------------------
485 ::OnRightButtonDown(int ctrl,
489 this->FindPokedRenderer(x, y);
490 if(GetCurrentRenderer() == NULL)
493 myShiftState = shift;
494 // finishing current viewer operation
495 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
497 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
499 myOtherPoint = myPoint = QPoint(x, y);
500 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
501 startOperation(ForcedState);
505 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
509 //----------------------------------------------------------------------------
512 ::OnRightButtonUp(int vtkNotUsed(ctrl),
517 myShiftState = shift;
518 // finishing current viewer operation
519 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
521 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
525 //----------------------------------------------------------------------------
527 const char* imageZoomCursor[] = {
532 "................................",
533 "................................",
534 ".#######........................",
535 "..aaaaaaa.......................",
536 "................................",
537 ".............#####..............",
538 "...........##.aaaa##............",
539 "..........#.aa.....a#...........",
540 ".........#.a.........#..........",
541 ".........#a..........#a.........",
542 "........#.a...........#.........",
543 "........#a............#a........",
544 "........#a............#a........",
545 "........#a............#a........",
546 "........#a............#a........",
547 ".........#...........#.a........",
548 ".........#a..........#a.........",
549 ".........##.........#.a.........",
550 "........#####.....##.a..........",
551 ".......###aaa#####.aa...........",
552 "......###aa...aaaaa.......#.....",
553 ".....###aa................#a....",
554 "....###aa.................#a....",
555 "...###aa...............#######..",
556 "....#aa.................aa#aaaa.",
557 ".....a....................#a....",
558 "..........................#a....",
559 "...........................a....",
560 "................................",
561 "................................",
562 "................................",
563 "................................"};
565 const char* imageRotateCursor[] = {
570 "................................",
571 "................................",
572 "................................",
573 "................................",
574 "........#.......................",
575 ".......#.a......................",
576 "......#######...................",
577 ".......#aaaaa#####..............",
578 "........#..##.a#aa##........##..",
579 ".........a#.aa..#..a#.....##.aa.",
580 ".........#.a.....#...#..##.aa...",
581 ".........#a.......#..###.aa.....",
582 "........#.a.......#a..#aa.......",
583 "........#a.........#..#a........",
584 "........#a.........#a.#a........",
585 "........#a.........#a.#a........",
586 "........#a.........#a.#a........",
587 ".........#.........#a#.a........",
588 "........##a........#a#a.........",
589 "......##.a#.......#.#.a.........",
590 "....##.aa..##.....##.a..........",
591 "..##.aa.....a#####.aa...........",
592 "...aa.........aaa#a.............",
593 "................#.a.............",
594 "...............#.a..............",
595 "..............#.a...............",
596 "...............a................",
597 "................................",
598 "................................",
599 "................................",
600 "................................",
601 "................................"};
604 //----------------------------------------------------------------------------
605 // loads cursors for viewer operations - zoom, pan, etc...
610 myDefCursor = QCursor(Qt::ArrowCursor);
611 myHandCursor = QCursor(Qt::PointingHandCursor);
612 myPanCursor = QCursor(Qt::SizeAllCursor);
613 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
614 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
615 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
616 myGlobalPanCursor = QCursor(Qt::CrossCursor);
617 myCursorState = false;
621 //----------------------------------------------------------------------------
622 // starts Zoom operation (e.g. through menu command)
627 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
630 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
632 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
633 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
637 //----------------------------------------------------------------------------
638 // starts Pan operation (e.g. through menu command)
643 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
646 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
648 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
649 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
652 //----------------------------------------------------------------------------
653 // starts Rotate operation (e.g. through menu command)
658 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
661 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
663 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
664 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
668 //----------------------------------------------------------------------------
669 // starts Spin 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_SPIN);
680 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
685 //----------------------------------------------------------------------------
686 // starts Fit Area operation (e.g. through menu command)
691 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
694 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
696 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
697 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
701 //----------------------------------------------------------------------------
702 // starts Global Panning 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_GLOBAL_PAN);
713 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
715 // store current zoom scale
716 myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
718 GetCurrentRenderer()->ResetCamera();
724 //----------------------------------------------------------------------------
725 // fits viewer contents to rect
728 ::fitRect(const int left,
733 if (GetCurrentRenderer() == NULL)
737 int x = (left + right)/2;
738 int y = (top + bottom)/2;
739 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
740 int oldX = aSize[0]/2;
741 int oldY = aSize[1]/2;
742 TranslateView(oldX, oldY, x, y);
745 double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
746 double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
747 double zoomFactor = (dxf + dyf)/2 ;
749 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
750 if(aCam->GetParallelProjection())
751 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
753 aCam->Dolly(zoomFactor);
754 GetCurrentRenderer()->ResetCameraClippingRange();
761 //----------------------------------------------------------------------------
762 // starts viewer operation (!internal usage!)
765 ::startOperation(int operation)
769 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
770 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
771 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
772 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
773 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
774 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
775 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
776 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
777 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
779 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
780 setCursor(operation);
783 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
785 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
786 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
792 //----------------------------------------------------------------------------
793 // sets proper cursor for window when viewer operation is activated
796 ::setCursor(const int operation)
798 if (!GetRenderWidget()) return;
801 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
802 GetRenderWidget()->setCursor(myZoomCursor);
803 myCursorState = true;
805 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
806 GetRenderWidget()->setCursor(myPanCursor);
807 myCursorState = true;
809 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
810 GetRenderWidget()->setCursor(myRotateCursor);
811 myCursorState = true;
813 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
814 GetRenderWidget()->setCursor(mySpinCursor);
815 myCursorState = true;
817 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
818 GetRenderWidget()->setCursor(myGlobalPanCursor);
819 myCursorState = true;
821 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
822 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
823 GetRenderWidget()->setCursor(myHandCursor);
824 myCursorState = true;
826 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
828 GetRenderWidget()->setCursor(myDefCursor);
829 myCursorState = false;
835 //----------------------------------------------------------------------------
836 // called when viewer operation started (!put necessary initialization here!)
841 if (!GetRenderWidget()) return;
842 // VSV: LOD actor activisation
843 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
845 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
846 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
848 QPainter p(GetRenderWidget());
849 p.setPen(Qt::lightGray);
850 p.setRasterOp(Qt::XorROP);
851 p.drawRect(QRect(myPoint, myOtherPoint));
854 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
855 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
856 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
857 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
858 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
864 //----------------------------------------------------------------------------
865 // called when viewer operation finished (!put necessary post-processing here!)
868 ::onFinishOperation()
870 if (!GetRenderWidget())
873 // VSV: LOD actor activisation
874 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
876 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
879 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
880 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
882 QPainter aPainter(GetRenderWidget());
883 aPainter.setPen(Qt::lightGray);
884 aPainter.setRasterOp(Qt::XorROP);
885 QRect aRect(myPoint, myOtherPoint);
886 aPainter.drawRect(aRect);
887 aRect = aRect.normalize();
889 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
890 // making fit rect opeation
892 Interactor->GetSize(w, h);
893 int x1 = aRect.left();
894 int y1 = h - aRect.top() - 1;
895 int x2 = aRect.right();
896 int y2 = h - aRect.bottom() - 1;
897 fitRect(x1, y1, x2, y2);
900 if (myPoint == myOtherPoint) {
901 // process point selection
902 this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
903 Interactor->StartPickCallback();
905 myPicker->Pick(aSelectionEvent->myX,
906 aSelectionEvent->myY,
908 GetCurrentRenderer());
910 SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
911 aSelectionEvent->myIsRectangle = false;
913 anActor->Highlight( this, aSelectionEvent, true );
915 if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
916 myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
918 GetSelector()->ClearIObjects();
920 myLastHighlitedActor = anActor;
923 //processing rectangle selection
924 Interactor->StartPickCallback();
925 GetSelector()->StartPickCallback();
926 aSelectionEvent->myIsRectangle = true;
929 GetSelector()->ClearIObjects();
931 vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors();
932 aListActors->InitTraversal();
933 while(vtkActor* aActor = aListActors->GetNextActor()){
934 if(aActor->GetVisibility()){
935 if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){
936 if(aSActor->hasIO()){
937 aSActor->Highlight( this, aSelectionEvent, true );
943 Interactor->EndPickCallback();
944 GetSelector()->EndPickCallback();
948 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
949 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
950 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
951 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
953 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
956 Interactor->GetSize(w, h);
958 y = h - myPoint.y() - 1;
968 // called during viewer operation when user moves mouse (!put necessary processing here!)
969 //----------------------------------------------------------------------------
972 ::onOperation(QPoint mousePos)
974 if (!GetRenderWidget())
978 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
980 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
984 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
986 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
990 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
992 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
996 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
998 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1002 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1006 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1009 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1011 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1013 QPainter p(GetRenderWidget());
1014 p.setPen(Qt::lightGray);
1015 p.setRasterOp(Qt::XorROP);
1016 p.drawRect(QRect(myPoint, myOtherPoint));
1017 myOtherPoint = mousePos;
1018 p.drawRect(QRect(myPoint, myOtherPoint));
1024 // called when user moves mouse inside viewer window and there is no active viewer operation
1025 // (!put necessary processing here!)
1026 //----------------------------------------------------------------------------
1028 SVTK_InteractorStyle
1029 ::onCursorMove(QPoint mousePos)
1031 // processing highlighting
1032 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1033 this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1035 bool anIsChanged = false;
1037 myPicker->Pick(aSelectionEvent->myX,
1038 aSelectionEvent->myY,
1040 GetCurrentRenderer());
1042 SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
1044 anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
1047 if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
1048 anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );
1050 myLastPreHighlitedActor = anActor;
1056 // called on finsh GlobalPan operation
1057 //----------------------------------------------------------------------------
1059 SVTK_InteractorStyle
1060 ::Place(const int theX, const int theY)
1062 if (GetCurrentRenderer() == NULL)
1066 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1067 int centerX = aSize[0]/2;
1068 int centerY = aSize[1]/2;
1070 TranslateView(centerX, centerY, theX, theY);
1072 // restore zoom scale
1073 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1074 cam->SetParallelScale(myScale);
1075 GetCurrentRenderer()->ResetCameraClippingRange();
1082 // Translates view from Point to Point
1083 //----------------------------------------------------------------------------
1085 SVTK_InteractorStyle
1086 ::TranslateView(int toX, int toY, int fromX, int fromY)
1088 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1089 double viewFocus[4], focalDepth, viewPoint[3];
1090 float newPickPoint[4], oldPickPoint[4], motionVector[3];
1091 cam->GetFocalPoint(viewFocus);
1093 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1094 viewFocus[2], viewFocus);
1095 focalDepth = viewFocus[2];
1097 this->ComputeDisplayToWorld(double(toX), double(toY),
1098 focalDepth, newPickPoint);
1099 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1100 focalDepth, oldPickPoint);
1102 // camera motion is reversed
1103 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1104 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1105 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1107 cam->GetFocalPoint(viewFocus);
1108 cam->GetPosition(viewPoint);
1109 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1110 motionVector[1] + viewFocus[1],
1111 motionVector[2] + viewFocus[2]);
1112 cam->SetPosition(motionVector[0] + viewPoint[0],
1113 motionVector[1] + viewPoint[1],
1114 motionVector[2] + viewPoint[2]);
1117 //----------------------------------------------------------------------------
1119 SVTK_InteractorStyle
1120 ::IncrementalPan( const int incrX, const int incrY )
1122 this->PanXY( incrX, incrY, 0, 0 );
1125 //----------------------------------------------------------------------------
1127 SVTK_InteractorStyle
1128 ::IncrementalZoom( const int incr )
1130 this->DollyXY( incr, incr );
1133 //----------------------------------------------------------------------------
1135 SVTK_InteractorStyle
1136 ::IncrementalRotate( const int incrX, const int incrY )
1138 this->RotateXY( incrX, -incrY );
1141 //----------------------------------------------------------------------------
1143 SVTK_InteractorStyle
1144 ::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1146 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1147 Superclass::SetInteractor( theInteractor );
1149 myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1152 // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1153 theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1154 theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1155 theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1156 theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1157 theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1158 theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1159 theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1160 theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1161 theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1162 theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1163 theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1164 theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1165 theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1166 theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1167 theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1169 theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1170 theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1171 theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1173 theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1174 theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1175 theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1176 theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1177 theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1182 //----------------------------------------------------------------------------
1184 SVTK_InteractorStyle
1187 //vtkInteractorStyle::OnTimer();
1188 this->Interactor->Render();
1191 //----------------------------------------------------------------------------
1193 SVTK_InteractorStyle
1196 this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1199 //----------------------------------------------------------------------------
1201 SVTK_InteractorStyle
1202 ::onSpaceMouseMove( double* data )
1204 // general things, do SetCurrentRenderer() within FindPokedRenderer()
1206 GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1207 FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1209 IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in
1210 IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1211 IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis
1212 IncrementalRotate( (int)data[3], 0 ); // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1215 //----------------------------------------------------------------------------
1217 SVTK_InteractorStyle
1218 ::onSpaceMouseButton( int button )
1220 if( mySMDecreaseSpeedBtn == button ) {
1221 ControllerIncrement()->Decrease();
1223 if( mySMIncreaseSpeedBtn == button ) {
1224 ControllerIncrement()->Increase();
1226 if( mySMDominantCombinedSwitchBtn == button )
1227 DominantCombinedSwitch();
1230 //----------------------------------------------------------------------------
1232 SVTK_InteractorStyle
1233 ::DominantCombinedSwitch()
1235 printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1238 //----------------------------------------------------------------------------
1240 SVTK_InteractorStyle
1241 ::ProcessEvents( vtkObject* object,
1242 unsigned long event,
1247 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1248 SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1249 int aSpeedIncrement=self->ControllerIncrement()->Current();
1252 case SVTK::SpaceMouseMoveEvent :
1253 self->onSpaceMouseMove( (double*)callData );
1255 case SVTK::SpaceMouseButtonEvent :
1256 self->onSpaceMouseButton( *((int*)callData) );
1258 case SVTK::PanLeftEvent:
1259 self->IncrementalPan(-aSpeedIncrement, 0);
1261 case SVTK::PanRightEvent:
1262 self->IncrementalPan(aSpeedIncrement, 0);
1264 case SVTK::PanUpEvent:
1265 self->IncrementalPan(0, aSpeedIncrement);
1267 case SVTK::PanDownEvent:
1268 self->IncrementalPan(0, -aSpeedIncrement);
1270 case SVTK::ZoomInEvent:
1271 self->IncrementalZoom(aSpeedIncrement);
1273 case SVTK::ZoomOutEvent:
1274 self->IncrementalZoom(-aSpeedIncrement);
1276 case SVTK::RotateLeftEvent:
1277 self->IncrementalRotate(-aSpeedIncrement, 0);
1279 case SVTK::RotateRightEvent:
1280 self->IncrementalRotate(aSpeedIncrement, 0);
1282 case SVTK::RotateUpEvent:
1283 self->IncrementalRotate(0, -aSpeedIncrement);
1285 case SVTK::RotateDownEvent:
1286 self->IncrementalRotate(0, aSpeedIncrement);
1288 case SVTK::PlusSpeedIncrementEvent:
1289 self->ControllerIncrement()->Increase();
1291 case SVTK::MinusSpeedIncrementEvent:
1292 self->ControllerIncrement()->Decrease();
1294 case SVTK::SetSpeedIncrementEvent:
1295 self->ControllerIncrement()->SetStartValue(*((int*)callData));
1298 case SVTK::SetSMDecreaseSpeedEvent:
1299 self->mySMDecreaseSpeedBtn = *((int*)callData);
1301 case SVTK::SetSMIncreaseSpeedEvent:
1302 self->mySMIncreaseSpeedBtn = *((int*)callData);
1304 case SVTK::SetSMDominantCombinedSwitchEvent:
1305 self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1308 case SVTK::StartZoom:
1311 case SVTK::StartPan:
1314 case SVTK::StartRotate:
1315 self->startRotate();
1317 case SVTK::StartGlobalPan:
1318 self->startGlobalPan();
1320 case SVTK::StartFitArea:
1321 self->startFitArea();
1327 Superclass::ProcessEvents( object, event, clientData, callData );
1329 //----------------------------------------------------------------------------
1330 void SVTK_InteractorStyle::OnChar()
1333 //----------------------------------------------------------------------------
1334 void SVTK_InteractorStyle::OnKeyDown()
1336 bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1337 if (bInvokeSuperclass){
1338 Superclass::OnKeyDown();
1341 //----------------------------------------------------------------------------
1342 void SVTK_InteractorStyle::ActionPicking()
1345 Interactor->GetEventPosition( x, y );
1346 FindPokedRenderer( x, y );
1348 myOtherPoint = myPoint = QPoint(x, y);
1350 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1351 onFinishOperation();
1352 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1354 //----------------------------------------------------------------------------
1355 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1357 myControllerOnKeyDown=theController;
1359 //----------------------------------------------------------------------------
1360 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1362 return myControllerOnKeyDown.GetPointer();
1364 //----------------------------------------------------------------------------
1365 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1367 myControllerIncrement=theController;
1369 //----------------------------------------------------------------------------
1370 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
1372 return myControllerIncrement.GetPointer();
1375 vtkStandardNewMacro(SVTK_ControllerIncrement);
1376 //----------------------------------------------------------------------------
1377 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
1381 //----------------------------------------------------------------------------
1382 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
1385 //----------------------------------------------------------------------------
1386 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
1388 myIncrement=theValue;
1390 //----------------------------------------------------------------------------
1391 int SVTK_ControllerIncrement::Current()const
1395 //----------------------------------------------------------------------------
1396 int SVTK_ControllerIncrement::Increase()
1401 //----------------------------------------------------------------------------
1402 int SVTK_ControllerIncrement::Decrease()
1410 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
1411 //----------------------------------------------------------------------------
1412 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
1415 //----------------------------------------------------------------------------
1416 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
1419 //----------------------------------------------------------------------------
1420 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)