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
23 // File : SVTK_KeyFreeInteractorStyle.cxx
24 // Author : Christophe ATTANASIO
28 #include "SVTK_KeyFreeInteractorStyle.h"
29 #include "SVTK_Selector.h"
31 #include <vtkObjectFactory.h>
32 #include <vtkRenderWindowInteractor.h>
33 #include <vtkCallbackCommand.h>
34 #include <vtkCommand.h>
35 #include <vtkRenderer.h>
36 #include <vtkCamera.h>
39 //----------------------------------------------------------------------------
40 vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle);
41 //----------------------------------------------------------------------------
43 SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle():
44 myIsMidButtonDown( false ),
45 myIsLeftButtonDown( false )
49 //----------------------------------------------------------------------------
50 SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle()
54 //----------------------------------------------------------------------------
55 void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift,
58 myIsLeftButtonDown = true;
60 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
61 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
64 this->FindPokedRenderer(x, y);
65 if (this->CurrentRenderer == NULL) {
69 // finishing current viewer operation
70 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
72 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
74 myOtherPoint = myPoint = QPoint(x, y);
75 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
76 startOperation(ForcedState);
80 if (myIsMidButtonDown){
81 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
84 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
91 //----------------------------------------------------------------------------
92 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
96 myIsMidButtonDown = true;
98 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
99 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
102 this->FindPokedRenderer(x, y);
103 if (this->CurrentRenderer == NULL) {
106 myShiftState = shift;
107 // finishing current viewer operation
108 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
110 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
112 myOtherPoint = myPoint = QPoint(x, y);
113 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
114 startOperation(ForcedState);
118 if ( myIsLeftButtonDown ){
119 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
122 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
128 //----------------------------------------------------------------------------
129 void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
131 myIsLeftButtonDown = false;
132 SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
134 if ( myIsMidButtonDown )
135 OnMiddleButtonDown( ctrl, shift, x, y );
138 //----------------------------------------------------------------------------
139 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
141 myIsMidButtonDown = false;
142 SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
144 if ( myIsLeftButtonDown )
145 OnLeftButtonDown( ctrl, shift, x, y );
148 //----------------------------------------------------------------------------
149 void SVTK_KeyFreeInteractorStyle::OnChar()
151 char key = GetInteractor()->GetKeyCode();
156 EventCallbackCommand->AbortFlagOn();
159 SVTK_InteractorStyle::OnChar();