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 : VVTK_InteractorStyle.cxx
24 // Author : Christophe ATTANASIO
28 #include "VVTK_InteractorStyle.h"
29 #include "VISU_GaussPtsSettings.h"
30 #include "SVTK_Selector.h"
31 #include "VISU_Event.h"
33 #include <vtkObjectFactory.h>
34 #include <vtkRenderWindowInteractor.h>
35 #include <vtkCallbackCommand.h>
36 #include <vtkCommand.h>
37 #include <vtkRenderer.h>
38 #include <vtkCamera.h>
41 //----------------------------------------------------------------------------
42 vtkStandardNewMacro(VVTK_InteractorStyle);
43 //----------------------------------------------------------------------------
46 ::VVTK_InteractorStyle():
47 myIsMidButtonDown( false ),
48 myIsLeftButtonDown( false ),
49 mySMDecreaseMagnificationBtn(10),
50 mySMIncreaseMagnificationBtn(11)
54 //----------------------------------------------------------------------------
56 ::~VVTK_InteractorStyle()
60 //----------------------------------------------------------------------------
63 ::OnLeftButtonDown(int ctrl, int shift,
66 myIsLeftButtonDown = true;
68 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
69 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
72 this->FindPokedRenderer(x, y);
73 if (this->CurrentRenderer == NULL) {
77 // finishing current viewer operation
78 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
80 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
82 myOtherPoint = myPoint = QPoint(x, y);
83 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
84 startOperation(ForcedState);
88 if (myIsMidButtonDown){
89 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
92 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
99 //----------------------------------------------------------------------------
102 ::OnMiddleButtonDown(int ctrl,
106 myIsMidButtonDown = true;
108 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) {
109 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
112 this->FindPokedRenderer(x, y);
113 if (this->CurrentRenderer == NULL) {
116 myShiftState = shift;
117 // finishing current viewer operation
118 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
120 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
122 myOtherPoint = myPoint = QPoint(x, y);
123 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
124 startOperation(ForcedState);
128 if ( myIsLeftButtonDown ){
129 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
132 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
138 //----------------------------------------------------------------------------
141 ::OnLeftButtonUp(int ctrl, int shift, int x, int y)
143 myIsLeftButtonDown = false;
144 SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
146 if ( myIsMidButtonDown )
147 OnMiddleButtonDown( ctrl, shift, x, y );
150 //----------------------------------------------------------------------------
153 ::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
155 myIsMidButtonDown = false;
156 SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
158 if ( myIsLeftButtonDown )
159 OnLeftButtonDown( ctrl, shift, x, y );
161 //----------------------------------------------------------------------------
162 void VVTK_InteractorStyle::onFinishOperation()
164 Superclass::onFinishOperation();
168 //----------------------------------------------------------------------------
171 ::SetInteractor( vtkRenderWindowInteractor* theInteractor )
173 // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
174 Superclass::SetInteractor( theInteractor );
177 theInteractor->AddObserver( VISU::SetSMDecreaseMagnificationEvent, EventCallbackCommand, Priority );
178 theInteractor->AddObserver( VISU::SetSMIncreaseMagnificationEvent, EventCallbackCommand, Priority );
183 //----------------------------------------------------------------------------
186 ::ProcessEvents( vtkObject* object,
192 vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
193 VVTK_InteractorStyle* self = dynamic_cast<VVTK_InteractorStyle*>( anObject );
196 case VISU::SetSMDecreaseMagnificationEvent:
197 self->mySMDecreaseMagnificationBtn = *((int*)callData);
199 case VISU::SetSMIncreaseMagnificationEvent:
200 self->mySMIncreaseMagnificationBtn = *((int*)callData);
206 Superclass::ProcessEvents( object, event, clientData, callData );
210 //----------------------------------------------------------------------------
213 ::onSpaceMouseButton( int button )
215 if( mySMDecreaseMagnificationBtn == button )
216 DecreaseGaussPointMagnification();
217 if( mySMIncreaseMagnificationBtn == button )
218 IncreaseGaussPointMagnification();
220 Superclass::onSpaceMouseButton( button );
223 //----------------------------------------------------------------------------
226 ::DecreaseGaussPointMagnification()
228 Interactor->InvokeEvent(VISU::SetSMDecreaseMagnificationEvent,NULL);
231 //----------------------------------------------------------------------------
234 ::IncreaseGaussPointMagnification()
236 Interactor->InvokeEvent(VISU::SetSMIncreaseMagnificationEvent,NULL);
238 //============================================================================
242 vtkStandardNewMacro(VVTK_ControllerIncrement);
243 //----------------------------------------------------------------------------
244 VVTK_ControllerIncrement::VVTK_ControllerIncrement()
248 //----------------------------------------------------------------------------
249 VVTK_ControllerIncrement::~VVTK_ControllerIncrement()
252 //----------------------------------------------------------------------------
253 int VVTK_ControllerIncrement::Increase()
258 //----------------------------------------------------------------------------
259 int VVTK_ControllerIncrement::Decrease()
268 vtkStandardNewMacro(VVTK_ControllerOnKeyDown);
269 //----------------------------------------------------------------------------
270 VVTK_ControllerOnKeyDown::VVTK_ControllerOnKeyDown()
273 //----------------------------------------------------------------------------
274 VVTK_ControllerOnKeyDown::~VVTK_ControllerOnKeyDown()
277 //----------------------------------------------------------------------------
278 bool VVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
280 SVTK_InteractorStyle *pIS=dynamic_cast<SVTK_InteractorStyle *>(theIS);
282 if(pIS->GetSelector()->SelectionMode()==GaussPointSelection){
283 char key = pIS->GetInteractor()->GetKeyCode();
286 pIS->ActionPicking();
291 return Superclass::OnKeyDown(theIS);