1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME VTKViewer : build VTK viewer into Salome desktop
21 // File : SVTK_KeyFreeInteractorStyle.cxx
22 // Author : Christophe ATTANASIO
24 #include "SVTK_KeyFreeInteractorStyle.h"
25 #include "SVTK_Selector.h"
27 #include <vtkObjectFactory.h>
28 #include <vtkRenderWindowInteractor.h>
29 #include <vtkCallbackCommand.h>
30 #include <vtkCommand.h>
31 #include <vtkRenderer.h>
32 #include <vtkCamera.h>
35 //----------------------------------------------------------------------------
36 vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle);
37 //----------------------------------------------------------------------------
39 SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle():
40 myIsMidButtonDown( false ),
41 myIsLeftButtonDown( false )
45 //----------------------------------------------------------------------------
46 SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle()
50 //----------------------------------------------------------------------------
51 void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift,
54 myIsLeftButtonDown = true;
56 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
57 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
60 this->FindPokedRenderer(x, y);
61 if (this->CurrentRenderer == NULL) {
65 // finishing current viewer operation
66 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
68 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
70 myOtherPoint = myPoint = QPoint(x, y);
71 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
72 startOperation(ForcedState);
76 if (myIsMidButtonDown){
77 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
80 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
87 //----------------------------------------------------------------------------
88 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
92 myIsMidButtonDown = true;
94 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
95 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
98 this->FindPokedRenderer(x, y);
99 if (this->CurrentRenderer == NULL) {
102 myShiftState = shift;
103 // finishing current viewer operation
104 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
106 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
108 myOtherPoint = myPoint = QPoint(x, y);
109 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
110 startOperation(ForcedState);
114 if ( myIsLeftButtonDown ){
115 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
118 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
124 //----------------------------------------------------------------------------
125 void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
127 myIsLeftButtonDown = false;
128 SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
130 if ( myIsMidButtonDown )
131 OnMiddleButtonDown( ctrl, shift, x, y );
134 //----------------------------------------------------------------------------
135 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
137 myIsMidButtonDown = false;
138 SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
140 if ( myIsLeftButtonDown )
141 OnLeftButtonDown( ctrl, shift, x, y );
144 //----------------------------------------------------------------------------
145 void SVTK_KeyFreeInteractorStyle::OnChar()
147 char key = GetInteractor()->GetKeyCode();
152 EventCallbackCommand->AbortFlagOn();
155 SVTK_InteractorStyle::OnChar();