1 // Copyright (C) 2007-2008 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
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
28 #include "SVTK_InteractorStyle.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>
70 inline void GetEventPosition(vtkRenderWindowInteractor* theInteractor,
74 theInteractor->GetEventPosition(theX,theY);
75 theY = theInteractor->GetSize()[1] - theY - 1;
80 vtkStandardNewMacro(SVTK_InteractorStyle);
86 SVTK_InteractorStyle::SVTK_InteractorStyle():
87 mySelectionEvent(new SVTK_SelectionEvent()),
88 myPointPicker(vtkPointPicker::New()),
89 myLastHighlitedActor(NULL),
90 myLastPreHighlitedActor(NULL),
91 myControllerIncrement(SVTK_ControllerIncrement::New()),
92 myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
93 myHighlightSelectionPointActor(SVTK_Actor::New()),
96 myPointPicker->Delete();
98 myPointPicker->SetTolerance(0.025);
100 this->MotionFactor = 10.0;
101 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
102 this->RadianToDegree = 180.0 / vtkMath::Pi();
103 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
107 // set custom event handling function (to handle 3d space mouse events)
108 EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
110 // set default values of properties. user may edit them in preferences.
111 mySMDecreaseSpeedBtn = 1;
112 mySMIncreaseSpeedBtn = 2;
113 mySMDominantCombinedSwitchBtn = 9;
115 myControllerIncrement->Delete();
116 myControllerOnKeyDown->Delete();
118 myCurrRotationPointType = SVTK::SetRotateGravity;
119 myPrevRotationPointType = myCurrRotationPointType;
121 myCurrFocalPointType = SVTK::SetFocalPointSelected;
122 myPrevFocalPointType = myCurrFocalPointType;
124 myHighlightSelectionPointActor->Delete();
125 myHighlightSelectionPointActor->Initialize();
126 myHighlightSelectionPointActor->PickableOff();
127 myHighlightSelectionPointActor->SetVisibility( false );
129 myHighlightSelectionPointActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE+2);
130 myHighlightSelectionPointActor->GetProperty()->SetLineWidth(SALOME_LINE_WIDTH+2);
131 myHighlightSelectionPointActor->GetProperty()->SetRepresentationToPoints();
133 myBBFirstCheck = true;
139 SVTK_InteractorStyle::~SVTK_InteractorStyle()
145 \return widget for rendering
147 QWidget* SVTK_InteractorStyle::GetRenderWidget()
149 return myInteractor->GetRenderWidget();
155 SVTK_Selector* SVTK_InteractorStyle::GetSelector()
157 return myInteractor->GetSelector();
161 Generate special SVTK_SelectionEvent
163 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEvent()
165 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
167 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
168 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
170 mySelectionEvent->myLastX = mySelectionEvent->myX;
171 mySelectionEvent->myLastY = mySelectionEvent->myY;
173 GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
175 return mySelectionEvent.get();
179 Generate special SVTK_SelectionEvent with flipped Y coordinate
181 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEventFlipY()
183 mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
185 mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
186 mySelectionEvent->myIsShift = Interactor->GetShiftKey();
188 mySelectionEvent->myLastX = mySelectionEvent->myX;
189 mySelectionEvent->myLastY = mySelectionEvent->myY;
191 this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
193 return mySelectionEvent.get();
196 void SVTK_InteractorStyle::RotateXY(int dx, int dy)
198 /* if(GetCurrentRenderer() == NULL)
201 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
202 double aDeltaElevation = -20.0 / size[1];
203 double aDeltaAzimuth = -20.0 / size[0];
205 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
206 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
208 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
211 cam->OrthogonalizeViewUp();
213 GetCurrentRenderer()->ResetCameraClippingRange();
217 if(GetCurrentRenderer() == NULL)
220 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
222 double viewFP[3], viewPos[3];
223 cam->GetFocalPoint(viewFP);
224 cam->GetPosition(viewPos);
226 if ( myCurrRotationPointType == SVTK::SetRotateGravity )
228 vtkFloatingPointType aCenter[3];
229 if ( ComputeBBCenter(GetCurrentRenderer(),aCenter) )
231 myRotationPointX = aCenter[0];
232 myRotationPointY = aCenter[1];
233 myRotationPointZ = aCenter[2];
237 // Calculate corresponding transformation
238 vtkPerspectiveTransform* aTransform = vtkPerspectiveTransform::New();
239 aTransform->Identity();
240 aTransform->Translate(+myRotationPointX, +myRotationPointY, +myRotationPointZ);
242 // Azimuth transformation
243 int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
244 double aDeltaAzimuth = -20.0 / size[0];
246 double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
247 aTransform->RotateWXYZ(rxf, cam->GetViewUp());
249 // Elevation transformation
250 double aDeltaElevation = -20.0 / size[1];
252 double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
253 vtkMatrix4x4* aMatrix = cam->GetViewTransformMatrix();
254 const double anAxis[3] = {-aMatrix->GetElement(0,0), // mkr : 27.11.2006 : PAL14011 - Strange behaviour in rotation in VTK Viewer.
255 -aMatrix->GetElement(0,1),
256 -aMatrix->GetElement(0,2)};
258 aTransform->RotateWXYZ(ryf, anAxis);
260 aTransform->Translate(-myRotationPointX, -myRotationPointY, -myRotationPointZ);
262 // To apply the transformation
263 cam->SetPosition(aTransform->TransformPoint(viewPos));
264 cam->SetFocalPoint(aTransform->TransformPoint(viewFP));
266 cam->OrthogonalizeViewUp();
268 GetCurrentRenderer()->ResetCameraClippingRange();
273 void SVTK_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
275 TranslateView(x, y, oldX, oldY);
279 void SVTK_InteractorStyle::DollyXY(int dx, int dy)
281 if (GetCurrentRenderer() == NULL)
284 double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
285 double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
287 double zoomFactor = pow((double)1.1, dxf + dyf);
289 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
290 if (aCam->GetParallelProjection())
291 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
293 aCam->Dolly(zoomFactor); // Move camera in/out along projection direction
294 GetCurrentRenderer()->ResetCameraClippingRange();
300 void SVTK_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
304 if (GetCurrentRenderer() == NULL)
307 double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
308 (double)(x - GetCurrentRenderer()->GetCenter()[0]));
309 double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
310 (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
312 newAngle *= this->RadianToDegree;
313 oldAngle *= this->RadianToDegree;
315 cam = GetCurrentRenderer()->GetActiveCamera();
316 cam->Roll(newAngle - oldAngle);
317 cam->OrthogonalizeViewUp();
326 void SVTK_InteractorStyle::OnConfigure()
328 this->FindPokedRenderer(0,0);
329 this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
333 To handle mouse move event
335 void SVTK_InteractorStyle::OnMouseMove()
338 GetEventPosition( this->Interactor, x, y );
339 this->OnMouseMove( this->Interactor->GetControlKey(),
340 this->Interactor->GetShiftKey(),
345 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
347 void SVTK_InteractorStyle::OnLeftButtonDown()
350 GetEventPosition( this->Interactor, x, y );
351 this->OnLeftButtonDown( this->Interactor->GetControlKey(),
352 this->Interactor->GetShiftKey(),
357 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
359 void SVTK_InteractorStyle::OnLeftButtonUp()
362 GetEventPosition( this->Interactor, x, y );
363 this->OnLeftButtonUp( this->Interactor->GetControlKey(),
364 this->Interactor->GetShiftKey(),
369 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
371 void SVTK_InteractorStyle::OnMiddleButtonDown()
374 GetEventPosition( this->Interactor, x, y );
375 this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
376 this->Interactor->GetShiftKey(),
381 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
383 void SVTK_InteractorStyle::OnMiddleButtonUp()
386 GetEventPosition( this->Interactor, x, y );
387 this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
388 this->Interactor->GetShiftKey(),
393 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
395 void SVTK_InteractorStyle::OnRightButtonDown()
398 GetEventPosition( this->Interactor, x, y );
399 this->OnRightButtonDown( this->Interactor->GetControlKey(),
400 this->Interactor->GetShiftKey(),
405 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
407 void SVTK_InteractorStyle::OnRightButtonUp()
410 GetEventPosition( this->Interactor, x, y );
411 this->OnRightButtonUp( this->Interactor->GetControlKey(),
412 this->Interactor->GetShiftKey(),
417 To handle mouse move event
419 void SVTK_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
423 myShiftState = shift;
424 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
425 onOperation(QPoint(x, y));
426 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
427 onCursorMove(QPoint(x, y));
431 To handle left mouse button down event (reimplemented from vtkInteractorStyle)
433 void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
436 this->FindPokedRenderer(x, y);
437 if(GetCurrentRenderer() == NULL)
440 myShiftState = shift;
441 // finishing current viewer operation
442 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
444 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
446 myOtherPoint = myPoint = QPoint(x, y);
447 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
448 startOperation(ForcedState);
451 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
452 else if ( myCurrRotationPointType == SVTK::StartPointSelection ||
453 myCurrFocalPointType == SVTK::StartFocalPointSelection )
455 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
457 SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
461 myPointPicker->Pick( aSelectionEvent->myX,
462 aSelectionEvent->myY,
464 GetCurrentRenderer() );
465 int aVtkId = myPointPicker->GetPointId();
468 int anObjId = anActor->GetNodeObjId( aVtkId );
469 vtkFloatingPointType* aCoords = anActor->GetNodeCoord(anObjId);
471 if (myCurrRotationPointType == SVTK::StartPointSelection) {
472 myCurrRotationPointType = SVTK::SetRotateSelected;
474 // invoke event for update coordinates in SVTK_SetRotationPointDlg
475 InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
477 else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
478 myCurrFocalPointType = SVTK::SetFocalPointSelected;
480 // invoke event for update coordinates in SVTK_ViewParameterDlg
481 InvokeEvent(SVTK::FocalPointChanged,(void*)aCoords);
486 if (myCurrRotationPointType == SVTK::StartPointSelection) {
487 // invoke event with no data (for SVTK_SetRotationPointDlg)
488 InvokeEvent(SVTK::RotationPointChanged,0);
489 myCurrRotationPointType = myPrevRotationPointType;
491 else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
492 // invoke event with no data (for SVTK_ViewParameterDlg)
493 InvokeEvent(SVTK::FocalPointChanged,0);
494 myCurrFocalPointType = myPrevFocalPointType;
500 if (myCurrRotationPointType == SVTK::StartPointSelection) {
501 // invoke event with no data (for SVTK_SetRotationPointDlg)
502 InvokeEvent(SVTK::RotationPointChanged,0);
503 myCurrRotationPointType = myPrevRotationPointType;
505 else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
506 // invoke event with no data (for SVTK_ViewParameterDlg)
507 InvokeEvent(SVTK::FocalPointChanged,0);
508 myCurrFocalPointType = myPrevFocalPointType;
512 myHighlightSelectionPointActor->SetVisibility( false );
513 if(GetCurrentRenderer() != NULL)
514 GetCurrentRenderer()->RemoveActor( myHighlightSelectionPointActor.GetPointer() );
516 GetRenderWidget()->setCursor(myDefCursor);
519 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
526 To handle left mouse button up event (reimplemented from vtkInteractorStyle)
528 void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
533 myShiftState = shift;
534 // finishing current viewer operation
535 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
537 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
542 To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
544 void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
548 this->FindPokedRenderer(x, y);
549 if(GetCurrentRenderer() == NULL)
552 myShiftState = shift;
553 // finishing current viewer operation
554 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
556 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
558 myOtherPoint = myPoint = QPoint(x, y);
559 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
560 startOperation(ForcedState);
564 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
570 To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
572 void SVTK_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
577 myShiftState = shift;
578 // finishing current viewer operation
579 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
581 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
587 To handle right mouse button down event (reimplemented from vtkInteractorStyle)
589 void SVTK_InteractorStyle::OnRightButtonDown(int ctrl,
593 this->FindPokedRenderer(x, y);
594 if(GetCurrentRenderer() == NULL)
597 myShiftState = shift;
598 // finishing current viewer operation
599 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
601 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
603 myOtherPoint = myPoint = QPoint(x, y);
604 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
605 startOperation(ForcedState);
609 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
614 To handle right mouse button up event (reimplemented from vtkInteractorStyle)
616 void SVTK_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
621 myShiftState = shift;
622 // finishing current viewer operation
623 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
625 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
630 const char* imageZoomCursor[] = {
635 "................................",
636 "................................",
637 ".#######........................",
638 "..aaaaaaa.......................",
639 "................................",
640 ".............#####..............",
641 "...........##.aaaa##............",
642 "..........#.aa.....a#...........",
643 ".........#.a.........#..........",
644 ".........#a..........#a.........",
645 "........#.a...........#.........",
646 "........#a............#a........",
647 "........#a............#a........",
648 "........#a............#a........",
649 "........#a............#a........",
650 ".........#...........#.a........",
651 ".........#a..........#a.........",
652 ".........##.........#.a.........",
653 "........#####.....##.a..........",
654 ".......###aaa#####.aa...........",
655 "......###aa...aaaaa.......#.....",
656 ".....###aa................#a....",
657 "....###aa.................#a....",
658 "...###aa...............#######..",
659 "....#aa.................aa#aaaa.",
660 ".....a....................#a....",
661 "..........................#a....",
662 "...........................a....",
663 "................................",
664 "................................",
665 "................................",
666 "................................"};
668 const char* imageRotateCursor[] = {
673 "................................",
674 "................................",
675 "................................",
676 "................................",
677 "........#.......................",
678 ".......#.a......................",
679 "......#######...................",
680 ".......#aaaaa#####..............",
681 "........#..##.a#aa##........##..",
682 ".........a#.aa..#..a#.....##.aa.",
683 ".........#.a.....#...#..##.aa...",
684 ".........#a.......#..###.aa.....",
685 "........#.a.......#a..#aa.......",
686 "........#a.........#..#a........",
687 "........#a.........#a.#a........",
688 "........#a.........#a.#a........",
689 "........#a.........#a.#a........",
690 ".........#.........#a#.a........",
691 "........##a........#a#a.........",
692 "......##.a#.......#.#.a.........",
693 "....##.aa..##.....##.a..........",
694 "..##.aa.....a#####.aa...........",
695 "...aa.........aaa#a.............",
696 "................#.a.............",
697 "...............#.a..............",
698 "..............#.a...............",
699 "...............a................",
700 "................................",
701 "................................",
702 "................................",
703 "................................",
704 "................................"};
708 loads cursors for viewer operations - zoom, pan, etc...
710 void SVTK_InteractorStyle::loadCursors()
712 myDefCursor = QCursor(Qt::ArrowCursor);
713 myHandCursor = QCursor(Qt::PointingHandCursor);
714 myPanCursor = QCursor(Qt::SizeAllCursor);
715 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
716 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
717 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
718 myGlobalPanCursor = QCursor(Qt::CrossCursor);
719 myCursorState = false;
724 Starts Zoom operation (e.g. through menu command)
726 void SVTK_InteractorStyle::startZoom()
728 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
731 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
733 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
734 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
739 Starts Pan operation (e.g. through menu command)
741 void SVTK_InteractorStyle::startPan()
743 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
746 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
748 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
749 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
753 Starts Rotate operation (e.g. through menu command)
755 void SVTK_InteractorStyle::startRotate()
757 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
760 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
762 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
763 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
767 Set rotation point selected by user
769 void SVTK_InteractorStyle::startPointSelection()
771 myCurrRotationPointType = SVTK::StartPointSelection;
773 if(GetCurrentRenderer() != NULL) {
774 GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
775 vtkFloatingPointType aColor[3];
776 GetCurrentRenderer()->GetBackground( aColor );
777 myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
782 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
786 Set focal point selected by user
788 void SVTK_InteractorStyle::startFocalPointSelection()
790 myCurrFocalPointType = SVTK::StartFocalPointSelection;
792 if(GetCurrentRenderer() != NULL) {
793 GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
794 vtkFloatingPointType aColor[3];
795 GetCurrentRenderer()->GetBackground( aColor );
796 myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
801 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
805 Starts Spin operation (e.g. through menu command)
807 void SVTK_InteractorStyle::startSpin()
809 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
812 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
814 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
815 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
821 Starts Fit Area operation (e.g. through menu command)
823 void SVTK_InteractorStyle::startFitArea()
825 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
828 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
830 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
831 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
836 Starts Global Panning operation (e.g. through menu command)
838 void SVTK_InteractorStyle::startGlobalPan()
840 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
843 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
845 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
846 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
848 // store current zoom scale
849 myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
851 GetCurrentRenderer()->ResetCamera();
858 Fits viewer contents to rect
860 void SVTK_InteractorStyle::fitRect(const int left,
865 if (GetCurrentRenderer() == NULL)
869 int x = (left + right)/2;
870 int y = (top + bottom)/2;
871 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
872 int oldX = aSize[0]/2;
873 int oldY = aSize[1]/2;
874 TranslateView(oldX, oldY, x, y);
877 double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
878 double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
879 double zoomFactor = (dxf + dyf)/2 ;
881 vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
882 if(aCam->GetParallelProjection())
883 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
885 aCam->Dolly(zoomFactor);
886 GetCurrentRenderer()->ResetCameraClippingRange();
894 Starts viewer operation (!internal usage!)
896 void SVTK_InteractorStyle::startOperation(int operation)
900 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
901 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
902 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
903 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
904 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
905 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
906 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
907 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
908 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
910 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
911 setCursor(operation);
914 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
916 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
917 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
924 Sets proper cursor for window when viewer operation is activated
926 void SVTK_InteractorStyle::setCursor(const int operation)
928 if (!GetRenderWidget()) return;
931 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
932 GetRenderWidget()->setCursor(myZoomCursor);
933 myCursorState = true;
935 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
936 GetRenderWidget()->setCursor(myPanCursor);
937 myCursorState = true;
939 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
940 GetRenderWidget()->setCursor(myRotateCursor);
941 myCursorState = true;
943 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
944 GetRenderWidget()->setCursor(mySpinCursor);
945 myCursorState = true;
947 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
948 GetRenderWidget()->setCursor(myGlobalPanCursor);
949 myCursorState = true;
951 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
952 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
953 GetRenderWidget()->setCursor(myHandCursor);
954 myCursorState = true;
956 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
958 if ( myCurrRotationPointType == SVTK::StartPointSelection ||
959 myCurrFocalPointType == SVTK::StartFocalPointSelection )
960 GetRenderWidget()->setCursor(myHandCursor);
962 GetRenderWidget()->setCursor(myDefCursor);
963 myCursorState = false;
970 Called when viewer operation started (!put necessary initialization here!)
972 void SVTK_InteractorStyle::onStartOperation()
974 if (!GetRenderWidget())
977 vtkRenderWindowInteractor *aRWI = this->Interactor;
978 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
979 aRenWin->SetDesiredUpdateRate(aRWI->GetDesiredUpdateRate());
982 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
983 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
988 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
989 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
990 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
991 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
992 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
999 Called when viewer operation finished (!put necessary post-processing here!)
1001 void SVTK_InteractorStyle::onFinishOperation()
1003 if (!GetRenderWidget())
1006 vtkRenderWindowInteractor *aRWI = this->Interactor;
1007 vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
1008 aRenWin->SetDesiredUpdateRate(aRWI->GetStillUpdateRate());
1010 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1013 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1014 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1017 QRect aRect(myPoint, myOtherPoint);
1018 aRect = aRect.normalized();
1020 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
1021 // making fit rect opeation
1023 Interactor->GetSize(w, h);
1024 int x1 = aRect.left();
1025 int y1 = h - aRect.top() - 1;
1026 int x2 = aRect.right();
1027 int y2 = h - aRect.bottom() - 1;
1028 fitRect(x1, y1, x2, y2);
1031 if (myPoint == myOtherPoint)
1033 // process point selection
1034 this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
1035 Interactor->StartPickCallback();
1037 SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1039 aSelectionEvent->myIsRectangle = false;
1042 GetSelector()->ClearIObjects();
1046 anActor->Highlight( this, aSelectionEvent, true );
1050 if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
1051 myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
1053 myLastHighlitedActor = anActor;
1057 //processing rectangle selection
1058 Interactor->StartPickCallback();
1059 GetSelector()->StartPickCallback();
1060 aSelectionEvent->myIsRectangle = true;
1063 GetSelector()->ClearIObjects();
1065 vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors();
1066 aListActors->InitTraversal();
1067 while(vtkActor* aActor = aListActors->GetNextActor())
1069 if(aActor->GetVisibility())
1071 if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
1073 if(aSActor->hasIO())
1074 aSActor->Highlight( this, aSelectionEvent, true );
1079 Interactor->EndPickCallback();
1080 GetSelector()->EndPickCallback();
1084 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1085 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1086 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1087 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1089 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1092 Interactor->GetSize(w, h);
1094 y = h - myPoint.y() - 1;
1105 Called during viewer operation when user moves mouse (!put necessary processing here!)
1107 void SVTK_InteractorStyle::onOperation(QPoint mousePos)
1109 if (!GetRenderWidget())
1113 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1115 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1119 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1121 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1125 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1127 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1131 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1133 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1137 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1141 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1144 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1146 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1148 myOtherPoint = mousePos;
1156 Called when user moves mouse inside viewer window and there is no active viewer operation
1157 (!put necessary processing here!)
1159 void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
1161 // processing highlighting
1162 SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1163 this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1165 bool anIsChanged = false;
1167 SALOME_Actor *anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1169 if ( myCurrRotationPointType == SVTK::StartPointSelection ||
1170 myCurrFocalPointType == SVTK::StartFocalPointSelection )
1172 myHighlightSelectionPointActor->SetVisibility( false );
1176 myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
1177 int aVtkId = myPointPicker->GetPointId();
1178 if ( aVtkId >= 0 ) {
1179 int anObjId = anActor->GetNodeObjId( aVtkId );
1181 TColStd_IndexedMapOfInteger aMapIndex;
1182 aMapIndex.Add( anObjId );
1183 myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
1185 myHighlightSelectionPointActor->SetVisibility( true );
1192 anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
1195 if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
1196 anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );
1200 myLastPreHighlitedActor = anActor;
1207 Called on finsh GlobalPan operation
1209 void SVTK_InteractorStyle::Place(const int theX, const int theY)
1211 if (GetCurrentRenderer() == NULL)
1215 int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1216 int centerX = aSize[0]/2;
1217 int centerY = aSize[1]/2;
1219 TranslateView(centerX, centerY, theX, theY);
1221 // restore zoom scale
1222 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1223 cam->SetParallelScale(myScale);
1224 GetCurrentRenderer()->ResetCameraClippingRange();
1232 Translates view from Point to Point
1234 void SVTK_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1236 vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1237 double viewFocus[4], focalDepth, viewPoint[3];
1238 vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
1239 cam->GetFocalPoint(viewFocus);
1241 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1242 viewFocus[2], viewFocus);
1243 focalDepth = viewFocus[2];
1245 this->ComputeDisplayToWorld(double(toX), double(toY),
1246 focalDepth, newPickPoint);
1247 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1248 focalDepth, oldPickPoint);
1250 // camera motion is reversed
1251 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1252 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1253 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1255 cam->GetFocalPoint(viewFocus);
1256 cam->GetPosition(viewPoint);
1257 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1258 motionVector[1] + viewFocus[1],
1259 motionVector[2] + viewFocus[2]);
1260 cam->SetPosition(motionVector[0] + viewPoint[0],
1261 motionVector[1] + viewPoint[1],
1262 motionVector[2] + viewPoint[2]);
1265 void SVTK_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1267 this->PanXY( incrX, incrY, 0, 0 );
1270 void SVTK_InteractorStyle::IncrementalZoom( const int incr )
1272 this->DollyXY( incr, incr );
1275 void SVTK_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1277 this->RotateXY( incrX, -incrY );
1281 Redefined in order to add an observer (callback) for custorm event (space mouse event)
1283 void SVTK_InteractorStyle::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1285 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1286 Superclass::SetInteractor( theInteractor );
1288 myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1291 // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1292 theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1293 theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1294 theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1295 theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1296 theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1297 theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1298 theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1299 theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1300 theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1301 theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1302 theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1303 theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1304 theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1305 theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1306 theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1308 theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1309 theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1310 theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1312 theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1313 theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1314 theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1315 theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1316 theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1318 theInteractor->AddObserver( SVTK::SetRotateGravity, EventCallbackCommand, Priority );
1319 theInteractor->AddObserver( SVTK::StartPointSelection, EventCallbackCommand, Priority );
1321 theInteractor->AddObserver( SVTK::ChangeRotationPoint, EventCallbackCommand, Priority );
1323 theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
1324 theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
1325 theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
1330 To implement cached rendering
1332 void SVTK_InteractorStyle::OnTimer()
1334 //vtkInteractorStyle::OnTimer();
1335 this->Interactor->Render();
1336 // check if bounding box was changed
1337 if ( GetCurrentRenderer() )
1339 vtkFloatingPointType aCurrBBCenter[3];
1340 if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
1342 if ( !myBBFirstCheck )
1344 if ( fabs(aCurrBBCenter[0]-myBBCenter[0]) > 1e-38 ||
1345 fabs(aCurrBBCenter[1]-myBBCenter[1]) > 1e-38 ||
1346 fabs(aCurrBBCenter[2]-myBBCenter[2]) > 1e-38 ) {
1347 // bounding box was changed => send SVTK::RotationPointChanged event
1348 // invoke event for update coordinates in SVTK_SetRotationPointDlg
1349 InvokeEvent(SVTK::BBCenterChanged,(void*)aCurrBBCenter);
1350 for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1355 for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1356 myBBFirstCheck = false;
1363 To invoke #vtkRenderWindowInteractor::CreateTimer
1365 void SVTK_InteractorStyle::Render()
1367 this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1370 void SVTK_InteractorStyle::onSpaceMouseMove( double* data )
1372 // general things, do SetCurrentRenderer() within FindPokedRenderer()
1374 GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1375 FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1377 IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in
1378 IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1379 IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis
1380 IncrementalRotate( (int)data[3], 0 ); // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1383 void SVTK_InteractorStyle::onSpaceMouseButton( int button )
1385 if( mySMDecreaseSpeedBtn == button ) {
1386 ControllerIncrement()->Decrease();
1388 if( mySMIncreaseSpeedBtn == button ) {
1389 ControllerIncrement()->Increase();
1391 if( mySMDominantCombinedSwitchBtn == button )
1392 DominantCombinedSwitch();
1395 void SVTK_InteractorStyle::DominantCombinedSwitch()
1397 printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1401 Draws rectangle by starting and current points
1403 void SVTK_InteractorStyle::drawRect()
1405 if ( !myRectBand ) {
1406 myRectBand = new QRubberBand( QRubberBand::Rectangle, GetRenderWidget() );
1408 palette.setColor(myRectBand->foregroundRole(), Qt::white);
1409 myRectBand->setPalette(palette);
1413 QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
1414 myRectBand->setGeometry( aRect );
1415 myRectBand->setVisible( aRect.isValid() );
1419 \brief Delete rubber band on the end on the dragging operation.
1421 void SVTK_InteractorStyle::endDrawRect()
1423 if ( myRectBand ) myRectBand->hide();
1430 Main process event method (reimplemented from #vtkInteractorStyle)
1432 void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
1433 unsigned long event,
1438 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1439 SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1440 int aSpeedIncrement=self->ControllerIncrement()->Current();
1441 vtkFloatingPointType aCenter[3];
1442 vtkFloatingPointType* aSelectedPoint;
1445 case SVTK::SpaceMouseMoveEvent :
1446 self->onSpaceMouseMove( (double*)callData );
1448 case SVTK::SpaceMouseButtonEvent :
1449 self->onSpaceMouseButton( *((int*)callData) );
1451 case SVTK::PanLeftEvent:
1452 self->IncrementalPan(-aSpeedIncrement, 0);
1454 case SVTK::PanRightEvent:
1455 self->IncrementalPan(aSpeedIncrement, 0);
1457 case SVTK::PanUpEvent:
1458 self->IncrementalPan(0, aSpeedIncrement);
1460 case SVTK::PanDownEvent:
1461 self->IncrementalPan(0, -aSpeedIncrement);
1463 case SVTK::ZoomInEvent:
1464 self->IncrementalZoom(aSpeedIncrement);
1466 case SVTK::ZoomOutEvent:
1467 self->IncrementalZoom(-aSpeedIncrement);
1469 case SVTK::RotateLeftEvent:
1470 self->IncrementalRotate(-aSpeedIncrement, 0);
1472 case SVTK::RotateRightEvent:
1473 self->IncrementalRotate(aSpeedIncrement, 0);
1475 case SVTK::RotateUpEvent:
1476 self->IncrementalRotate(0, -aSpeedIncrement);
1478 case SVTK::RotateDownEvent:
1479 self->IncrementalRotate(0, aSpeedIncrement);
1481 case SVTK::PlusSpeedIncrementEvent:
1482 self->ControllerIncrement()->Increase();
1484 case SVTK::MinusSpeedIncrementEvent:
1485 self->ControllerIncrement()->Decrease();
1487 case SVTK::SetSpeedIncrementEvent:
1488 self->ControllerIncrement()->SetStartValue(*((int*)callData));
1491 case SVTK::SetSMDecreaseSpeedEvent:
1492 self->mySMDecreaseSpeedBtn = *((int*)callData);
1494 case SVTK::SetSMIncreaseSpeedEvent:
1495 self->mySMIncreaseSpeedBtn = *((int*)callData);
1497 case SVTK::SetSMDominantCombinedSwitchEvent:
1498 self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1501 case SVTK::StartZoom:
1504 case SVTK::StartPan:
1507 case SVTK::StartRotate:
1508 self->startRotate();
1510 case SVTK::StartGlobalPan:
1511 self->startGlobalPan();
1513 case SVTK::StartFitArea:
1514 self->startFitArea();
1517 case SVTK::SetRotateGravity:
1518 if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1520 self->myHighlightSelectionPointActor->SetVisibility( false );
1521 if( self->GetCurrentRenderer() != NULL )
1522 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1523 self->GetRenderWidget()->setCursor(self->myDefCursor);
1525 self->myPrevRotationPointType = self->myCurrRotationPointType;
1526 self->myCurrRotationPointType = SVTK::SetRotateGravity;
1527 if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) )
1528 // invoke event for update coordinates in SVTK_SetRotationPointDlg
1529 self->InvokeEvent(SVTK::BBCenterChanged,(void*)aCenter);
1531 case SVTK::StartPointSelection:
1532 self->startPointSelection();
1535 case SVTK::ChangeRotationPoint:
1536 if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1538 self->myHighlightSelectionPointActor->SetVisibility( false );
1539 if( self->GetCurrentRenderer() != NULL )
1540 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1541 self->GetRenderWidget()->setCursor(self->myDefCursor);
1543 self->myPrevRotationPointType = self->myCurrRotationPointType;
1544 self->myCurrRotationPointType = SVTK::SetRotateSelected;
1545 aSelectedPoint = (vtkFloatingPointType*)callData;
1546 self->myRotationPointX = aSelectedPoint[0];
1547 self->myRotationPointY = aSelectedPoint[1];
1548 self->myRotationPointZ = aSelectedPoint[2];
1551 case SVTK::SetFocalPointGravity:
1552 if ( self->myCurrFocalPointType == SVTK::StartPointSelection )
1554 self->myHighlightSelectionPointActor->SetVisibility( false );
1555 if( self->GetCurrentRenderer() != NULL )
1556 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1557 self->GetRenderWidget()->setCursor(self->myDefCursor);
1559 self->myCurrFocalPointType = SVTK::SetFocalPointGravity;
1560 if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) {
1561 // invoke event for update coordinates in SVTK_ViewParameterDlg
1562 self->InvokeEvent(SVTK::FocalPointChanged,(void*)aCenter);
1565 case SVTK::StartFocalPointSelection:
1566 self->startFocalPointSelection();
1569 case SVTK::SetFocalPointSelected:
1570 if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
1572 self->myHighlightSelectionPointActor->SetVisibility( false );
1573 if( self->GetCurrentRenderer() != NULL )
1574 self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1575 self->GetRenderWidget()->setCursor(self->myDefCursor);
1577 self->myPrevFocalPointType = self->myCurrFocalPointType;
1578 self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
1584 Superclass::ProcessEvents( object, event, clientData, callData );
1588 To handle keyboard event (reimplemented from #vtkInteractorStyle)
1590 void SVTK_InteractorStyle::OnChar()
1592 char key = GetInteractor()->GetKeyCode();
1594 case '+': ControllerIncrement()->Increase(); break;
1595 case '-': ControllerIncrement()->Decrease(); break;
1600 Redefined vtkInteractorStyle::OnKeyDown
1602 void SVTK_InteractorStyle::OnKeyDown()
1604 bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1605 if (bInvokeSuperclass){
1606 Superclass::OnKeyDown();
1611 Provide instructions for Picking
1613 void SVTK_InteractorStyle::ActionPicking()
1616 Interactor->GetEventPosition( x, y );
1617 FindPokedRenderer( x, y );
1619 myOtherPoint = myPoint = QPoint(x, y);
1621 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1622 onFinishOperation();
1623 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1627 To set current increment controller
1629 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1631 myControllerOnKeyDown=theController;
1635 To get current OnKeyDown controller
1637 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1639 return myControllerOnKeyDown.GetPointer();
1643 To set current increment controller
1645 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1647 myControllerIncrement=theController;
1651 To modify current increment controller
1653 void SVTK_InteractorStyle::SetIncrementSpeed(const int theValue, const int theMode)
1655 SVTK_ControllerIncrement* c = 0;
1657 case 0: c = SVTK_ControllerIncrement::New(); break;
1658 case 1: c = SVTK_GeomControllerIncrement::New(); break;
1660 c->SetStartValue(theValue);
1662 SetControllerIncrement(c);
1667 To get current increment controller
1669 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
1671 return myControllerIncrement.GetPointer();
1674 vtkStandardNewMacro(SVTK_ControllerIncrement);
1675 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
1679 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
1682 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
1684 myIncrement=theValue;
1686 int SVTK_ControllerIncrement::Current()const
1690 int SVTK_ControllerIncrement::Increase()
1695 int SVTK_ControllerIncrement::Decrease()
1703 vtkStandardNewMacro(SVTK_GeomControllerIncrement);
1704 SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
1707 SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement()
1710 int SVTK_GeomControllerIncrement::Increase()
1715 int SVTK_GeomControllerIncrement::Decrease()
1724 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
1729 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
1736 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
1740 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)