1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 myIsLeftButtonDown( false ),
41 myIsRightButtonDown( false )
45 //----------------------------------------------------------------------------
46 SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle()
50 //----------------------------------------------------------------------------
51 void SVTK_KeyFreeInteractorStyle::OnMouseMove(int ctrl,
55 // OnLeftButtonDown + OnMouseMove = Rotate
56 if ( myIsLeftButtonDown ) {
57 OnLeftButtonDown( ctrl, shift, x, y );
58 myIsLeftButtonDown = false;
60 // OnRightButtonDown + OnMouseMove = Zoom
61 if ( myIsRightButtonDown ) {
62 OnRightButtonDown( ctrl, shift, x, y );
63 myIsRightButtonDown = false;
65 SVTK_InteractorStyle::OnMouseMove( ctrl, shift, x, y );
68 //----------------------------------------------------------------------------
69 void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift,
73 SVTK_InteractorStyle::OnLeftButtonDown( !ctrl, shift, x, y );
77 if( !myIsLeftButtonDown ) {
78 myIsLeftButtonDown = true;
82 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
83 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
86 this->FindPokedRenderer(x, y);
87 if (this->CurrentRenderer == NULL) {
91 // finishing current viewer operation
92 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
94 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
96 myOtherPoint = myPoint = QPoint(x, y);
97 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
98 startOperation(ForcedState);
101 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
106 //----------------------------------------------------------------------------
107 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
112 SVTK_InteractorStyle::OnMiddleButtonDown( !ctrl, shift, x, y );
116 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
117 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
120 this->FindPokedRenderer(x, y);
121 if (this->CurrentRenderer == NULL) {
124 myShiftState = shift;
125 // finishing current viewer operation
126 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
128 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
130 myOtherPoint = myPoint = QPoint(x, y);
131 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
132 startOperation(ForcedState);
135 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
138 //----------------------------------------------------------------------------
139 void SVTK_KeyFreeInteractorStyle::OnRightButtonDown( int ctrl,
144 SVTK_InteractorStyle::OnRightButtonDown( !ctrl, shift, x, y );
148 if( !myIsRightButtonDown ) {
149 myIsRightButtonDown = true;
153 if( this->HasObserver( vtkCommand::RightButtonPressEvent ) ) {
154 this->InvokeEvent( vtkCommand::RightButtonPressEvent, NULL );
157 this->FindPokedRenderer( x, y );
158 if( this->CurrentRenderer == NULL ) {
161 myShiftState = shift;
162 // finishing current viewer operation
163 if ( State != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
165 startOperation( VTK_INTERACTOR_STYLE_CAMERA_NONE );
167 myOtherPoint = myPoint = QPoint(x, y);
168 if ( ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
169 startOperation(ForcedState);
172 startOperation( VTK_INTERACTOR_STYLE_CAMERA_ZOOM );
175 //----------------------------------------------------------------------------
176 void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
178 // OnLeftButtonDown + OnLeftButtonUp = Select
179 if ( myIsLeftButtonDown ) {
180 SVTK_InteractorStyle::OnLeftButtonDown( ctrl, shift, x, y );
181 myIsLeftButtonDown = false;
183 SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
186 //----------------------------------------------------------------------------
187 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
189 SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
192 //----------------------------------------------------------------------------
193 void SVTK_KeyFreeInteractorStyle::OnRightButtonUp(int ctrl, int shift, int x, int y)
195 // OnRightButtonDown + OnRightButtonUp = Open context menu
196 if( myIsRightButtonDown ) {
197 myIsRightButtonDown = false;
198 SVTK_InteractorStyle::OnRightButtonDown( ctrl, shift, x, y );
200 SVTK_InteractorStyle::OnRightButtonUp( ctrl, shift, x, y );
203 //----------------------------------------------------------------------------
204 void SVTK_KeyFreeInteractorStyle::OnChar()
206 char key = GetInteractor()->GetKeyCode();
211 EventCallbackCommand->AbortFlagOn();
214 SVTK_InteractorStyle::OnChar();