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
24 // File : VVTK_InteractorStyle.cxx
25 // Author : Christophe ATTANASIO
30 #include "VVTK_InteractorStyle.h"
31 #include "VISU_GaussPtsSettings.h"
32 #include "SVTK_Selector.h"
33 #include "VISU_Event.h"
35 #include <vtkObjectFactory.h>
36 #include <vtkRenderWindowInteractor.h>
37 #include <vtkCallbackCommand.h>
38 #include <vtkCommand.h>
39 #include <vtkRenderer.h>
40 #include <vtkCamera.h>
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VVTK_InteractorStyle);
45 //----------------------------------------------------------------------------
48 ::VVTK_InteractorStyle():
49 myIsMidButtonDown( false ),
50 myIsLeftButtonDown( false ),
51 mySMDecreaseMagnificationBtn(10),
52 mySMIncreaseMagnificationBtn(11)
56 //----------------------------------------------------------------------------
58 ::~VVTK_InteractorStyle()
62 //----------------------------------------------------------------------------
65 ::OnLeftButtonDown(int ctrl, int shift,
68 myIsLeftButtonDown = true;
70 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
71 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
74 this->FindPokedRenderer(x, y);
75 if (this->CurrentRenderer == NULL) {
79 // finishing current viewer operation
80 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
82 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
84 myOtherPoint = myPoint = QPoint(x, y);
85 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
86 startOperation(ForcedState);
90 if (myIsMidButtonDown){
91 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
94 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
101 //----------------------------------------------------------------------------
104 ::OnMiddleButtonDown(int ctrl,
108 myIsMidButtonDown = true;
110 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
111 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
114 this->FindPokedRenderer(x, y);
115 if (this->CurrentRenderer == NULL) {
118 myShiftState = shift;
119 // finishing current viewer operation
120 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
122 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
124 myOtherPoint = myPoint = QPoint(x, y);
125 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
126 startOperation(ForcedState);
130 if ( myIsLeftButtonDown ){
131 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
134 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
140 //----------------------------------------------------------------------------
143 ::OnLeftButtonUp(int ctrl, int shift, int x, int y)
145 myIsLeftButtonDown = false;
146 SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
148 if ( myIsMidButtonDown )
149 OnMiddleButtonDown( ctrl, shift, x, y );
152 //----------------------------------------------------------------------------
155 ::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
157 myIsMidButtonDown = false;
158 SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
160 if ( myIsLeftButtonDown )
161 OnLeftButtonDown( ctrl, shift, x, y );
163 //----------------------------------------------------------------------------
164 void VVTK_InteractorStyle::onFinishOperation()
166 Superclass::onFinishOperation();
170 //----------------------------------------------------------------------------
173 ::SetInteractor( vtkRenderWindowInteractor* theInteractor )
175 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
176 Superclass::SetInteractor( theInteractor );
179 theInteractor->AddObserver( VISU::SetSMDecreaseMagnificationEvent, EventCallbackCommand, Priority );
180 theInteractor->AddObserver( VISU::SetSMIncreaseMagnificationEvent, EventCallbackCommand, Priority );
185 //----------------------------------------------------------------------------
188 ::ProcessEvents( vtkObject* object,
194 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
195 VVTK_InteractorStyle* self = dynamic_cast<VVTK_InteractorStyle*>( anObject );
198 case VISU::SetSMDecreaseMagnificationEvent:
199 self->mySMDecreaseMagnificationBtn = *((int*)callData);
201 case VISU::SetSMIncreaseMagnificationEvent:
202 self->mySMIncreaseMagnificationBtn = *((int*)callData);
208 Superclass::ProcessEvents( object, event, clientData, callData );
212 //----------------------------------------------------------------------------
215 ::onSpaceMouseButton( int button )
217 if( mySMDecreaseMagnificationBtn == button )
218 DecreaseGaussPointMagnification();
219 if( mySMIncreaseMagnificationBtn == button )
220 IncreaseGaussPointMagnification();
222 Superclass::onSpaceMouseButton( button );
225 //----------------------------------------------------------------------------
228 ::DecreaseGaussPointMagnification()
230 Interactor->InvokeEvent(VISU::SetSMDecreaseMagnificationEvent,NULL);
233 //----------------------------------------------------------------------------
236 ::IncreaseGaussPointMagnification()
238 Interactor->InvokeEvent(VISU::SetSMIncreaseMagnificationEvent,NULL);
240 //============================================================================
244 vtkStandardNewMacro(VVTK_ControllerIncrement);
245 //----------------------------------------------------------------------------
246 VVTK_ControllerIncrement::VVTK_ControllerIncrement()
250 //----------------------------------------------------------------------------
251 VVTK_ControllerIncrement::~VVTK_ControllerIncrement()
254 //----------------------------------------------------------------------------
255 int VVTK_ControllerIncrement::Increase()
260 //----------------------------------------------------------------------------
261 int VVTK_ControllerIncrement::Decrease()
270 vtkStandardNewMacro(VVTK_ControllerOnKeyDown);
271 //----------------------------------------------------------------------------
272 VVTK_ControllerOnKeyDown::VVTK_ControllerOnKeyDown()
275 //----------------------------------------------------------------------------
276 VVTK_ControllerOnKeyDown::~VVTK_ControllerOnKeyDown()
279 //----------------------------------------------------------------------------
280 bool VVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
282 SVTK_InteractorStyle *pIS=dynamic_cast<SVTK_InteractorStyle *>(theIS);
284 if(pIS->GetSelector()->SelectionMode()==GaussPointSelection){
285 char key = pIS->GetInteractor()->GetKeyCode();
288 pIS->ActionPicking();
293 return Superclass::OnKeyDown(theIS);