]> OCCT Git - occt-copy.git/commitdiff
0031656: Visualization - drag item to handle in AIS_ViewController
authornds <nds@opencascade.com>
Tue, 8 Sep 2020 19:59:02 +0000 (22:59 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 9 Sep 2020 16:48:49 +0000 (19:48 +0300)
ProcessDragging method in AIS_InteractiveObject. Empty by default. Should be implemented if drag is used for the object.

src/AIS/AIS_InteractiveObject.cxx
src/AIS/AIS_InteractiveObject.hxx
src/AIS/AIS_Manipulator.cxx
src/AIS/AIS_Manipulator.hxx
src/AIS/AIS_ViewController.cxx
src/AIS/AIS_ViewController.hxx

index 79139abe4d445e7c38cd0ad538efa37fc20f8fda..913cd619f3f35b5709f02bd07dc9d7ca0aced3be 100644 (file)
@@ -56,6 +56,20 @@ void AIS_InteractiveObject::Redisplay (const Standard_Boolean AllModes)
   myCTXPtr->Redisplay (this, Standard_False, AllModes);
 }
 
+//=======================================================================
+//function : ProcessDragging
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_InteractiveObject::ProcessDragging (const Handle(AIS_InteractiveContext)&,
+                                                         const Handle(V3d_View)&,
+                                                         const Handle(SelectMgr_EntityOwner)&,
+                                                         const Graphic3d_Vec2i&,
+                                                         const Graphic3d_Vec2i&,
+                                                         const AIS_DragAction)
+{
+  return Standard_False;
+}
+
 //=======================================================================
 //function : 
 //purpose  : 
index e66043f9664bd72bb6c3f15fcc54c5fecabdb252..8b4f9229f18863d94803761c7014227131f0b0ec 100644 (file)
 #define _AIS_InteractiveObject_HeaderFile
 
 #include <AIS_KindOfInteractive.hxx>
+#include <AIS_DragAction.hxx>
 #include <SelectMgr_SelectableObject.hxx>
 
 class AIS_InteractiveContext;
 class Graphic3d_MaterialAspect;
 class Prs3d_BasicAspect;
 class Bnd_Box;
+class V3d_View;
 
 //! Defines a class of objects with display and selection services.
 //! Entities which are visualized and selected are Interactive Objects.
@@ -103,6 +105,21 @@ public:
   //! This method removes the owner from the graphic entity.
   void ClearOwner() { myOwner.Nullify(); }
 
+  //! Drag object in the viewer.
+  //! @param theCtx      [in] interactive context
+  //! @param theView     [in] active View
+  //! @param theOwner    [in] the owner of detected entity
+  //! @param theDragFrom [in] drag start point
+  //! @param theDragTo   [in] drag end point
+  //! @param theAction   [in] drag action
+  //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start)
+  Standard_EXPORT virtual Standard_Boolean ProcessDragging (const Handle(AIS_InteractiveContext)& theCtx,
+                                                            const Handle(V3d_View)& theView,
+                                                            const Handle(SelectMgr_EntityOwner)& theOwner,
+                                                            const Graphic3d_Vec2i& theDragFrom,
+                                                            const Graphic3d_Vec2i& theDragTo,
+                                                            const AIS_DragAction theAction);
+
 public:
 
   //! Returns the context pointer to the interactive context.
index 45e5ca4fa8270fed6e8b972c37bde0619876268b..53d75ed00030e3b2a77e86504550eca93bbef375 100644 (file)
@@ -639,6 +639,44 @@ Standard_Boolean AIS_Manipulator::ObjectTransformation (const Standard_Integer t
   return Standard_False;
 }
 
+//=======================================================================
+//function : ProcessDragging
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_Manipulator::ProcessDragging (const Handle(AIS_InteractiveContext)&,
+                                                   const Handle(V3d_View)& theView,
+                                                   const Handle(SelectMgr_EntityOwner)&,
+                                                   const Graphic3d_Vec2i& theDragFrom,
+                                                   const Graphic3d_Vec2i& theDragTo,
+                                                   const AIS_DragAction theAction)
+{
+  switch (theAction)
+  {
+    case AIS_DragAction_Start:
+    {
+      if (HasActiveMode())
+      {
+        StartTransform (theDragFrom.x(), theDragFrom.y(), theView);
+        return Standard_True;
+      }
+      break;
+    }
+    case AIS_DragAction_Update:
+    {
+      Transform (theDragTo.x(), theDragTo.y(), theView);
+      return Standard_True;
+    }
+    case AIS_DragAction_Abort:
+    {
+      StopTransform (false);
+      return Standard_True;
+    }
+    case AIS_DragAction_Stop:
+      break;
+  }
+  return Standard_False;
+}
+
 //=======================================================================
 //function : StartTransform
 //purpose  : 
index b05e1dc57c768be26296bd05cf9ef3b44e7e58d3..1b5c94fd9d129bfa9d2bded9e321e45968076461 100644 (file)
@@ -163,6 +163,20 @@ public:
   }
 
 public:
+  //! Drag object in the viewer.
+  //! @param theCtx      [in] interactive context
+  //! @param theView     [in] active View
+  //! @param theOwner    [in] the owner of detected entity
+  //! @param theDragFrom [in] drag start point
+  //! @param theDragTo   [in] drag end point
+  //! @param theAction   [in] drag action
+  //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start)
+  Standard_EXPORT virtual Standard_Boolean ProcessDragging (const Handle(AIS_InteractiveContext)& theCtx,
+                                                            const Handle(V3d_View)& theView,
+                                                            const Handle(SelectMgr_EntityOwner)& theOwner,
+                                                            const Graphic3d_Vec2i& theDragFrom,
+                                                            const Graphic3d_Vec2i& theDragTo,
+                                                            const AIS_DragAction theAction) Standard_OVERRIDE;
 
   //! Init start (reference) transformation.
   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
index 41580021fc9b3a4a472e7d2cf867f657fcac8961..497216a768e53c366c6d568aee7810a671380811 100644 (file)
@@ -15,7 +15,6 @@
 
 #include <AIS_AnimationCamera.hxx>
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Manipulator.hxx>
 #include <AIS_Point.hxx>
 #include <AIS_RubberBand.hxx>
 #include <AIS_XRTrackedDevice.hxx>
@@ -2611,19 +2610,20 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)&
     case AIS_DragAction_Start:
     {
       myDragObject.Nullify();
+      myDragOwner.Nullify();
       if (!theCtx->HasDetected())
       {
         return;
       }
 
-      Handle(AIS_InteractiveObject) aPrs = theCtx->DetectedInteractive();
-      if (Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (aPrs))
+      const Handle(SelectMgr_EntityOwner)& aDetectedOwner = theCtx->DetectedOwner();
+      Handle(AIS_InteractiveObject) aDetectedPrs = Handle(AIS_InteractiveObject)::DownCast (aDetectedOwner->Selectable());
+
+      if (aDetectedPrs->ProcessDragging (theCtx, theView, aDetectedOwner, myGL.Dragging.PointStart,
+                                         myGL.Dragging.PointTo, theAction))
       {
-        if (aManip->HasActiveMode())
-        {
-          myDragObject = aManip;
-          aManip->StartTransform (myGL.Dragging.PointStart.x(), myGL.Dragging.PointStart.y(), theView);
-        }
+        myDragObject = aDetectedPrs;
+        myDragOwner = aDetectedOwner;
       }
       return;
     }
@@ -2638,10 +2638,9 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)&
       {
         theCtx->SetSelectedState (aGlobOwner, true);
       }
-      if (Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (myDragObject))
-      {
-        aManip->Transform (myGL.Dragging.PointTo.x(), myGL.Dragging.PointTo.y(), theView);
-      }
+
+      myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart,
+                                     myGL.Dragging.PointTo, theAction);
       theView->Invalidate();
       return;
     }
@@ -2655,10 +2654,8 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)&
       myGL.Dragging.PointTo = myGL.Dragging.PointStart;
       OnObjectDragged (theCtx, theView, AIS_DragAction_Update);
 
-      if (Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (myDragObject))
-      {
-        aManip->StopTransform (false);
-      }
+      myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart,
+                                     myGL.Dragging.PointTo, theAction);
       Standard_FALLTHROUGH
     }
     case AIS_DragAction_Stop:
@@ -2673,8 +2670,11 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)&
         theCtx->SetSelectedState (aGlobOwner, false);
       }
 
+      myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart,
+                                     myGL.Dragging.PointTo, theAction);
       theView->Invalidate();
       myDragObject.Nullify();
+      myDragOwner.Nullify();
       return;
     }
   }
index 11a6b6066d92216f3632e49e728521642a56e4d7..bb5636b5bae91923262cee940d2ed8ed2536ff04 100644 (file)
@@ -40,6 +40,7 @@ class AIS_Point;
 class AIS_RubberBand;
 class AIS_XRTrackedDevice;
 class Graphic3d_Camera;
+class SelectMgr_EntityOwner;
 class V3d_View;
 class WNT_HIDSpaceMouse;
 
@@ -737,6 +738,7 @@ protected:
 
   Handle(AIS_AnimationCamera) myViewAnimation;    //!< view animation
   Handle(AIS_RubberBand) myRubberBand;            //!< Rubber-band presentation
+  Handle(SelectMgr_EntityOwner) myDragOwner;      //!< detected owner of currently dragged object
   Handle(AIS_InteractiveObject) myDragObject;     //!< currently dragged object
   Graphic3d_Vec2i     myPrevMoveTo;               //!< previous position of MoveTo event in 3D viewer
   Standard_Boolean    myHasHlrOnBeforeRotation;   //!< flag for restoring Computed mode after rotation