Salome HOME
Updated copyright comment
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
index d3610ed9fef32262a3f66350d923614efedf0179..1701d907e825839b032da7150a0318bfe4c9ca64 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -95,7 +95,8 @@ SVTK_InteractorStyle::SVTK_InteractorStyle():
   myRectBand(0),
   myPolygonBand(0),
   myPoligonState(Disable),
-  myIsAdvancedZoomingEnabled(false)
+  myIsAdvancedZoomingEnabled(false),
+  myInteractivePoint{0.0, 0.0, 0.0}
 {
   myPointPicker->Delete();
 
@@ -539,7 +540,7 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
           {
                Selection_Mode aSelectionMode = GetSelector()->SelectionMode();
                double* aCoords = NULL;
-               int aVtkId;
+               vtkIdType aVtkId;
                bool isTrueType = false;
                
                if( myCurrFocalPointType == SVTK::StartFocalPointSelection ||
@@ -553,7 +554,7 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
               aVtkId = myPointPicker->GetPointId();
               if ( aVtkId >= 0 )
               {
-                int anObjId = anActor->GetNodeObjId( aVtkId );
+                vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
                 aCoords = anActor->GetNodeCoord(anObjId);
                 isTrueType = true;
               }
@@ -569,7 +570,7 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
                                  0.0,
                                  GetCurrentRenderer() );
               aVtkId = aCellPicker->GetCellId();
-              int aCellId = anActor->GetElemObjId( aVtkId );
+              vtkIdType aCellId = anActor->GetElemObjId( aVtkId );
 
               if( aSelectionMode == EdgeSelection )
                isTrueType = anActor->GetObjDimension( aCellId ) == 1;
@@ -660,7 +661,11 @@ void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
     onFinishOperation();
+    int lastOperation = State;
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+    if (lastOperation == VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
+      InvokeEvent(SVTK::InteractiveSelectionFinished, nullptr);
+    }
   }
 }
 
@@ -685,7 +690,8 @@ void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
   }
   myOtherPoint = myPoint = QPoint(x, y);
-  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE &&
+      ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
     startOperation(ForcedState);
   }
   else {
@@ -743,7 +749,8 @@ void SVTK_InteractorStyle::OnRightButtonDown(int ctrl,
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
   }
   myOtherPoint = myPoint = QPoint(x, y);
-  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE && 
+      ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
     startOperation(ForcedState);
   }
   else {
@@ -917,6 +924,20 @@ void SVTK_InteractorStyle::startRotate()
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
 }
 
+/*!
+  Starts Interactive Selection operation
+*/
+void SVTK_InteractorStyle::startInteractiveSelection()
+{
+       if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
+       {
+               onFinishOperation();
+               startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+       }
+       ForcedState = VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION;
+}
+
+
 /*!
   Set rotation point selected by user
 */
@@ -1058,6 +1079,7 @@ void SVTK_InteractorStyle::startOperation(int operation)
   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
+  case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
     State = operation;
@@ -1142,6 +1164,11 @@ void SVTK_InteractorStyle::onStartOperation()
         drawRect();
       break;
     }
+    case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+    {
+      InteractiveSelection();
+      break;
+    }
     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
@@ -1336,6 +1363,8 @@ void SVTK_InteractorStyle::onOperation(QPoint mousePos)
         drawRect();
       break;
     }
+  case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+         this->InteractiveSelection();
   }
 }
 
@@ -1370,11 +1399,11 @@ void SVTK_InteractorStyle::onCursorMove(QPoint /*mousePos*/)
         {
           SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
           myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
-          int aVtkId = myPointPicker->GetPointId();
+          vtkIdType aVtkId = myPointPicker->GetPointId();
           if ( aVtkId >= 0 ) {
-            int anObjId = anActor->GetNodeObjId( aVtkId );
+            vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
 
-            TColStd_IndexedMapOfInteger aMapIndex;
+            SVTK_TIndexedMapOfVtkId aMapIndex;
             aMapIndex.Add( anObjId );
             myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
 
@@ -1492,6 +1521,23 @@ void SVTK_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
   this->RotateXY( incrX, -incrY );
 }
 
+void SVTK_InteractorStyle::InteractiveSelection() 
+{
+  if (vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera()) {
+    int posX, posY;
+    this->Interactor->GetEventPosition(posX, posY);
+    double viewFocus[3], z;
+    double* focalPointWorld = cam->GetFocalPoint();
+         this->ComputeWorldToDisplay(focalPointWorld[0], focalPointWorld[1],
+                 focalPointWorld[2], viewFocus);
+         z = viewFocus[2];
+
+         this->ComputeDisplayToWorld(double(posX), double(posY),
+               z, this->myInteractivePoint);
+         InvokeEvent(SVTK::InteractiveSelectionChanged, (void*)this->myInteractivePoint);
+  }
+}
+
 /*!
   Redefined in order to add an observer (callback) for custorm event (space mouse event)
 */
@@ -1538,6 +1584,8 @@ void SVTK_InteractorStyle::SetInteractor( vtkRenderWindowInteractor* theInteract
     theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
     theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
     theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
+         theInteractor->AddObserver( SVTK::StartInteractiveSelection, EventCallbackCommand, Priority);
+    theInteractor->AddObserver( SVTK::StopCurrentOperation, EventCallbackCommand, Priority);
   }
 }
 
@@ -1923,7 +1971,9 @@ void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
       case SVTK::StartFocalPointSelection:
         self->startFocalPointSelection();
         return;
-
+      case SVTK::StartInteractiveSelection:
+        self->startInteractiveSelection();
+        return;
       case SVTK::SetFocalPointSelected:
         if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
         {
@@ -1935,6 +1985,9 @@ void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
         self->myPrevFocalPointType = self->myCurrFocalPointType;
         self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
         return;
+      case SVTK::StopCurrentOperation:
+        self->onFinishOperation();
+        self->startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
       }
     }
   }