Back to index

salome-gui  6.5.0
SVTK_KeyFreeInteractorStyle.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00021 //  File   : SVTK_KeyFreeInteractorStyle.cxx
00022 //  Author : Christophe ATTANASIO
00023 
00024 #include "SVTK_KeyFreeInteractorStyle.h"
00025 #include "SVTK_Selector.h"
00026 
00027 #include <vtkObjectFactory.h>
00028 #include <vtkRenderWindowInteractor.h>
00029 #include <vtkCallbackCommand.h>
00030 #include <vtkCommand.h>
00031 #include <vtkRenderer.h>
00032 #include <vtkCamera.h>
00033 
00034 
00035 //----------------------------------------------------------------------------
00036 vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle);
00037 //----------------------------------------------------------------------------
00038 
00039 SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle():
00040   myIsMidButtonDown( false ),
00041   myIsLeftButtonDown( false )
00042 {
00043 }
00044 
00045 //----------------------------------------------------------------------------
00046 SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle() 
00047 {
00048 }
00049 
00050 //----------------------------------------------------------------------------
00051 void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift, 
00052                                                    int x, int y) 
00053 {
00054   myIsLeftButtonDown = true;
00055 
00056   if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
00057     this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
00058     return;
00059   }
00060   this->FindPokedRenderer(x, y);
00061   if (this->CurrentRenderer == NULL) {
00062     return;
00063   }
00064   myShiftState = shift;
00065   // finishing current viewer operation
00066   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00067     onFinishOperation();
00068     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00069   }
00070   myOtherPoint = myPoint = QPoint(x, y);
00071   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00072     startOperation(ForcedState);
00073   } 
00074   else {
00075     if (!(ctrl||shift)){
00076       if (myIsMidButtonDown){
00077         startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
00078       }
00079       else{
00080         startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
00081       }
00082     }
00083   }
00084   return;
00085 }
00086 
00087 //----------------------------------------------------------------------------
00088 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
00089                                                      int shift, 
00090                                                      int x, int y) 
00091 {
00092   myIsMidButtonDown = true;
00093 
00094   if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))  {
00095     this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
00096     return;
00097   }
00098   this->FindPokedRenderer(x, y);
00099   if (this->CurrentRenderer == NULL)    {
00100     return;
00101   }
00102   myShiftState = shift;
00103   // finishing current viewer operation
00104   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00105     onFinishOperation();
00106     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00107   }
00108   myOtherPoint = myPoint = QPoint(x, y);
00109   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00110     startOperation(ForcedState);
00111   }
00112   else {
00113     if (!(ctrl||shift)){
00114       if ( myIsLeftButtonDown ){
00115         startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
00116       }
00117       else{
00118         startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
00119       }
00120     }
00121   }
00122 }
00123 
00124 //----------------------------------------------------------------------------
00125 void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
00126 {
00127   myIsLeftButtonDown = false;
00128   SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
00129 
00130   if ( myIsMidButtonDown )
00131     OnMiddleButtonDown( ctrl, shift, x, y );
00132 }
00133 
00134 //----------------------------------------------------------------------------
00135 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
00136 {
00137   myIsMidButtonDown = false;
00138   SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
00139 
00140   if ( myIsLeftButtonDown )
00141     OnLeftButtonDown( ctrl, shift, x, y );
00142 }
00143 
00144 //----------------------------------------------------------------------------
00145 void SVTK_KeyFreeInteractorStyle::OnChar()
00146 {
00147   char key = GetInteractor()->GetKeyCode();
00148   switch (key) {
00149   case 's':
00150   case 'S':
00151     ActionPicking();
00152     EventCallbackCommand->AbortFlagOn();
00153     return;
00154   }
00155   SVTK_InteractorStyle::OnChar();
00156 }