Salome HOME
#26454 [EDF] (2021) SMESH: interactive mesh modification occ/26454
authorrnv <rnv@opencascade.com>
Fri, 4 Feb 2022 22:51:47 +0000 (01:51 +0300)
committervsr <vsr@opencascade.com>
Wed, 9 Feb 2022 14:57:17 +0000 (17:57 +0300)
src/SVTK/SVTK_Event.h
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index eae9b9a84c851c8e2dabf1256baf71d758ddf1a2..c45537018b35e659097b49f4c63e57ed85d4eccd 100644 (file)
@@ -71,9 +71,14 @@ namespace SVTK
     SetFocalPointSelected,
     StartFocalPointSelection,
     FocalPointChanged,
-    
-    OperationFinished, // rnv: invoked then SpinXY, RotateXY, DollyXY or PanXY operation is finished.
+
+         StartInteractiveSelection,
+         InteractiveSelectionChanged,
+    InteractiveSelectionFinished,
         
+    OperationFinished, // rnv: invoked when SpinXY, RotateXY, DollyXY or PanXY operation is finished.
+
+    StopCurrentOperation,
     LastEvent
   };
 }
index 92c2b81993152f5675d8c640ed9b1ec79107ffa9..c476e6c3868b8daf596121946411b2bd8c5372c1 100644 (file)
@@ -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();
 
@@ -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();
   }
 }
 
@@ -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);
       }
     }
   }
index bab2397500394f1ccb353bca6291b8ece245d1dd..81cfd6d4cc1146427fcb5bf183e1ce801e401b5c 100644 (file)
@@ -145,6 +145,7 @@ class QtxRectRubberBand;
 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
+#define VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION 9
 
 enum PolygonState { Disable, Start, InProcess, Finished, Closed, NotValid };
 
@@ -281,6 +282,9 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
   void
   IncrementalRotate( const int incrX, const int incrY );
 
+  void
+  InteractiveSelection();
+
   // Main process event method (reimplemented from #vtkInteractorStyle)
   static 
   void
@@ -303,6 +307,7 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
 
   void startPointSelection();
   void startFocalPointSelection();
+  void startInteractiveSelection();
 
  protected:
   void loadCursors();
@@ -369,6 +374,7 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
   vtkSmartPointer<vtkPointPicker> myPointPicker;
   
   double                          myBBCenter[3];
+  double                          myInteractivePoint[3];
   bool                            myBBFirstCheck;
 
   QtxRectRubberBand*              myRectBand; //!< selection rectangle rubber band
index 1c3d88ae70a85f4ddc387ed4d19f9eb01415846c..3719aca14c75995fb4d865adba9da6a3a8970802 100644 (file)
@@ -1045,6 +1045,21 @@ void SVTK_ViewWindow::activateSetFocalPointGravity()
   myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
 }
 
+/*!
+  Activate interactive selection
+*/
+void SVTK_ViewWindow::activateInteractiveSelection()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartInteractiveSelection, 0);
+}
+
+/*
+  Deactivate current active operation
+*/
+void SVTK_ViewWindow::deactivateCurrectOperation() {
+  myEventDispatcher->InvokeEvent(SVTK::StopCurrentOperation, 0);
+}
+
 /*!
   Set the selected point as a focal point
 */
index 49cac7f51db663f0912ada75ef8d32b0c5c731da..b9282869841a53eb5a25828d65770411fa691796 100644 (file)
@@ -328,6 +328,8 @@ public slots:
   void activateSetFocalPointGravity();
   void activateSetFocalPointSelected();
   void activateStartFocalPointSelection();
+  void activateInteractiveSelection();
+  void deactivateCurrectOperation();
 
   void onViewParameters(bool theIsActivate);