diff --git a/src/AIS/AIS_InteractiveObject.cxx b/src/AIS/AIS_InteractiveObject.cxx index 79139abe4d..913cd619f3 100644 --- a/src/AIS/AIS_InteractiveObject.cxx +++ b/src/AIS/AIS_InteractiveObject.cxx @@ -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 : diff --git a/src/AIS/AIS_InteractiveObject.hxx b/src/AIS/AIS_InteractiveObject.hxx index e66043f966..8b4f9229f1 100644 --- a/src/AIS/AIS_InteractiveObject.hxx +++ b/src/AIS/AIS_InteractiveObject.hxx @@ -18,12 +18,14 @@ #define _AIS_InteractiveObject_HeaderFile #include +#include #include 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. diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 45e5ca4fa8..53d75ed000 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -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 : diff --git a/src/AIS/AIS_Manipulator.hxx b/src/AIS/AIS_Manipulator.hxx index b05e1dc57c..1b5c94fd9d 100644 --- a/src/AIS/AIS_Manipulator.hxx +++ b/src/AIS/AIS_Manipulator.hxx @@ -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 diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index 41580021fc..497216a768 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -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; } } diff --git a/src/AIS/AIS_ViewController.hxx b/src/AIS/AIS_ViewController.hxx index 11a6b6066d..bb5636b5ba 100644 --- a/src/AIS/AIS_ViewController.hxx +++ b/src/AIS/AIS_ViewController.hxx @@ -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