Salome HOME
refs #416: to store the open state of object browser items in the binary array
[modules/gui.git] / src / SVTK / SVTK_KeyFreeInteractorStyle.cxx
index 4bdb61401ee680b62fa268ae468b85399170a7b0..11b70dac085d778aa99a34be455f2b7e97fc7164 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -37,8 +37,8 @@ vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle);
 //----------------------------------------------------------------------------
 
 SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle():
-  myIsMidButtonDown( false ),
-  myIsLeftButtonDown( false )
+  myIsLeftButtonDown( false ),
+  myIsRightButtonDown( false )
 {
 }
 
@@ -47,11 +47,37 @@ SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle()
 {
 }
 
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnMouseMove(int ctrl,
+                                              int shift,
+                                              int x, int y)
+{
+  // OnLeftButtonDown + OnMouseMove = Rotate
+  if ( myIsLeftButtonDown ) {
+    OnLeftButtonDown( ctrl, shift, x, y );
+    myIsLeftButtonDown = false;
+  }
+  // OnRightButtonDown + OnMouseMove = Zoom
+  if ( myIsRightButtonDown ) {
+    OnRightButtonDown( ctrl, shift, x, y );
+    myIsRightButtonDown = false;
+  }
+  SVTK_InteractorStyle::OnMouseMove( ctrl, shift, x, y );
+}
+
 //----------------------------------------------------------------------------
 void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift, 
                                                    int x, int y) 
 {
-  myIsLeftButtonDown = true;
+  if ( ctrl ) {
+    SVTK_InteractorStyle::OnLeftButtonDown( !ctrl, shift, x, y );
+    return;
+  }
+
+  if( !myIsLeftButtonDown ) {
+    myIsLeftButtonDown = true;
+    return;
+  }
 
   if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
     this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
@@ -71,16 +97,9 @@ void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift,
   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
     startOperation(ForcedState);
   } 
-  else {
-    if (!(ctrl||shift)){
-      if (myIsMidButtonDown){
-        startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
-      }
-      else{
-        startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
-      }
-    }
-  }
+  else if ( !shift )
+    startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
+
   return;
 }
 
@@ -89,7 +108,10 @@ void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
                                                      int shift, 
                                                      int x, int y) 
 {
-  myIsMidButtonDown = true;
+  if ( ctrl ) {
+    SVTK_InteractorStyle::OnMiddleButtonDown( !ctrl, shift, x, y );
+    return;
+  }
 
   if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))  {
     this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
@@ -109,36 +131,73 @@ void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl,
   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
     startOperation(ForcedState);
   }
-  else {
-    if (!(ctrl||shift)){
-      if ( myIsLeftButtonDown ){
-        startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
-      }
-      else{
-        startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
-      }
-    }
+  else if ( !shift )
+    startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
+}
+
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnRightButtonDown( int ctrl,
+                                                     int shift,
+                                                     int x, int y )
+{
+  if ( ctrl ) {
+    SVTK_InteractorStyle::OnRightButtonDown( !ctrl, shift, x, y );
+    return;
   }
+
+  if( !myIsRightButtonDown ) {
+    myIsRightButtonDown = true;
+    return;
+  }
+
+  if( this->HasObserver( vtkCommand::RightButtonPressEvent ) ) {
+    this->InvokeEvent( vtkCommand::RightButtonPressEvent, NULL );
+    return;
+  }
+  this->FindPokedRenderer( x, y );
+  if( this->CurrentRenderer == NULL ) {
+    return;
+  }
+  myShiftState = shift;
+  // finishing current viewer operation
+  if ( State != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
+    onFinishOperation();
+    startOperation( VTK_INTERACTOR_STYLE_CAMERA_NONE );
+  }
+  myOtherPoint = myPoint = QPoint(x, y);
+  if ( ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE ) {
+    startOperation(ForcedState);
+  }
+  else if ( !shift )
+    startOperation( VTK_INTERACTOR_STYLE_CAMERA_ZOOM );
 }
 
 //----------------------------------------------------------------------------
 void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y)
 {
-  myIsLeftButtonDown = false;
+  // OnLeftButtonDown + OnLeftButtonUp = Select
+  if ( myIsLeftButtonDown ) {
+    SVTK_InteractorStyle::OnLeftButtonDown( ctrl, shift, x, y );
+    myIsLeftButtonDown = false;
+  }
   SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y );
-
-  if ( myIsMidButtonDown )
-    OnMiddleButtonDown( ctrl, shift, x, y );
 }
 
 //----------------------------------------------------------------------------
 void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y)
 {
-  myIsMidButtonDown = false;
   SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y );
+}
 
-  if ( myIsLeftButtonDown )
-    OnLeftButtonDown( ctrl, shift, x, y );
+//----------------------------------------------------------------------------
+void SVTK_KeyFreeInteractorStyle::OnRightButtonUp(int ctrl, int shift, int x, int y)
+{
+  // OnRightButtonDown + OnRightButtonUp = Open context menu
+  if( myIsRightButtonDown ) {
+    myIsRightButtonDown = false;
+    SVTK_InteractorStyle::OnRightButtonDown( ctrl, shift, x, y );
+  }
+  SVTK_InteractorStyle::OnRightButtonUp( ctrl, shift, x, y );
 }
 
 //----------------------------------------------------------------------------