From: nds Date: Mon, 6 Jul 2020 16:32:55 +0000 (+0300) Subject: 0031656: Visualization - drag item to handle in AIS_ViewController X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=b131328786f4cf9442d52062799da497009a65bf;p=occt-copy.git 0031656: Visualization - drag item to handle in AIS_ViewController (cherry picked from commit e72fa9fc9d26715ca0cb4294d8d4b5ed7d2a6f76) --- diff --git a/src/AIS/AIS_DragItem.hxx b/src/AIS/AIS_DragItem.hxx new file mode 100644 index 0000000000..1cccb5d505 --- /dev/null +++ b/src/AIS/AIS_DragItem.hxx @@ -0,0 +1,70 @@ +// Created on: 2020-07-05 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _AIS_DragItem_HeaderFile +#define _AIS_DragItem_HeaderFile + +#include + +class V3d_View; + +//! Interface to provide drag processing. +//! To use this interface, inherit AIS_InteractiveObject from it. After, implement functionality to +//! happen by drag action. +//! To perform transformation of an object use next code in your event processing chain: +//! @code +//! // catch mouse button down event +//! if (aDraggedObject->HasActiveMode()) +//! { +//! aDraggedObject->StartTransform (anXPix, anYPix, aV3dView); +//! } +//! ... +//! // or track mouse move event +//! if (aDraggedObject->HasActiveMode()) +//! { +//! aDraggedObject->Transform (anXPix, anYPix, aV3dView); +//! aV3dView->Redraw(); +//! } +//! ... +//! // or catch mouse button up event (apply) or escape event (cancel) +//! aDraggedObject->StopTransform(/*Standard_Boolean toApply*/); +//! @endcode +class AIS_DragItem +{ +public: + //! Constructs a drag item. + Standard_EXPORT AIS_DragItem() {} + +public: + //! @return true if this drag item participates in dragging + virtual Standard_Boolean HasActiveMode() const = 0; + + //! Init start (reference) transformation. + //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform + virtual void StartTransform (const Standard_Integer theX, + const Standard_Integer theY, + const Handle(V3d_View)& theView) = 0; + + //! Reset start (reference) transformation. + //! @param theToApply [in] option to apply or to cancel the started transformation. + virtual void StopTransform (const Standard_Boolean theToApply = Standard_True) = 0; + + //! Apply transformation made from mouse moving from start position + virtual gp_Trsf Transform (const Standard_Integer theX, + const Standard_Integer theY, + const Handle(V3d_View)& theView) = 0; +}; + +#endif // _AIS_DragItem_HeaderFile diff --git a/src/AIS/AIS_Manipulator.hxx b/src/AIS/AIS_Manipulator.hxx index b05e1dc57c..5608854e37 100644 --- a/src/AIS/AIS_Manipulator.hxx +++ b/src/AIS/AIS_Manipulator.hxx @@ -17,6 +17,7 @@ #define _AIS_Manipulator_HeaderFile #include +#include #include #include #include @@ -97,7 +98,7 @@ DEFINE_STANDARD_HANDLE (AIS_Manipulator, AIS_InteractiveObject) //! On construction an instance of AIS_Manipulator object is bound to Graphic3d_ZLayerId_Topmost layer, //! so make sure to call for your AIS_InteractiveContext the method MainSelector()->SetPickClosest (Standard_False) //! otherwise you may notice issues with activation of modes. -class AIS_Manipulator : public AIS_InteractiveObject +class AIS_Manipulator : public AIS_InteractiveObject, public AIS_DragItem { public: @@ -168,7 +169,9 @@ public: //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform //! and is used only for custom transform set. If Transform(const Standard_Integer, const Standard_Integer) is used, //! initial data is set automatically, and it is reset on DeactivateCurrentMode call if it is not reset yet. - Standard_EXPORT void StartTransform (const Standard_Integer theX, const Standard_Integer theY, const Handle(V3d_View)& theView); + Standard_EXPORT void StartTransform (const Standard_Integer theX, + const Standard_Integer theY, + const Handle(V3d_View)& theView) Standard_OVERRIDE; //! Apply to the owning objects the input transformation. //! @remark The transformation is set using SetLocalTransformation for owning objects. @@ -183,13 +186,13 @@ public: //! @param theToApply [in] option to apply or to cancel the started transformation. //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform //! and is used only for custom transform set. - Standard_EXPORT void StopTransform (const Standard_Boolean theToApply = Standard_True); + Standard_EXPORT void StopTransform (const Standard_Boolean theToApply = Standard_True) Standard_OVERRIDE; //! Apply transformation made from mouse moving from start position //! (save on the first Tranform() call and reset on DeactivateCurrentMode() call.) //! to the in/out mouse position (theX, theY) Standard_EXPORT gp_Trsf Transform (const Standard_Integer theX, const Standard_Integer theY, - const Handle(V3d_View)& theView); + const Handle(V3d_View)& theView) Standard_OVERRIDE; //! Computes transformation of parent object according to the active mode and input motion vector. //! You can use this method to get object transformation according to current mode or use own algorithm @@ -220,7 +223,7 @@ public: Standard_Boolean IsAttached() const { return HasOwner(); } //! @return true if some part of manipulator is selected (transformation mode is active, and owning object can be transformed). - Standard_Boolean HasActiveMode() const { return IsAttached() && myCurrentMode != AIS_MM_None; } + Standard_Boolean HasActiveMode() const Standard_OVERRIDE { return IsAttached() && myCurrentMode != AIS_MM_None; } Standard_Boolean HasActiveTransformation() { return myHasStartedTransformation; } diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index 17a5425e2d..e95de04064 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include @@ -2617,12 +2617,12 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)& } Handle(AIS_InteractiveObject) aPrs = theCtx->DetectedInteractive(); - if (Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (aPrs)) + if (AIS_DragItem* aDragItem = dynamic_cast(aPrs.get())) { - if (aManip->HasActiveMode()) + if (aDragItem->HasActiveMode()) { - myDragObject = aManip; - aManip->StartTransform (myGL.Dragging.PointStart.x(), myGL.Dragging.PointStart.y(), theView); + myDragObject = aPrs; + aDragItem->StartTransform (myGL.Dragging.PointStart.x(), myGL.Dragging.PointStart.y(), theView); } } return; @@ -2638,9 +2638,9 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)& { theCtx->SetSelectedState (aGlobOwner, true); } - if (Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (myDragObject)) + if (AIS_DragItem* aDragItem = dynamic_cast(myDragObject.get())) { - aManip->Transform (myGL.Dragging.PointTo.x(), myGL.Dragging.PointTo.y(), theView); + aDragItem->Transform (myGL.Dragging.PointTo.x(), myGL.Dragging.PointTo.y(), theView); } theView->Invalidate(); return; @@ -2655,9 +2655,9 @@ 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)) + if (AIS_DragItem* aDragItem = dynamic_cast(myDragObject.get())) { - aManip->StopTransform (false); + aDragItem->StopTransform (false); } Standard_FALLTHROUGH } @@ -2673,6 +2673,10 @@ void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)& theCtx->SetSelectedState (aGlobOwner, false); } + if (AIS_DragItem* aDragItem = dynamic_cast(myDragObject.get())) + { + aDragItem->StopTransform (false); + } theView->Invalidate(); myDragObject.Nullify(); return; diff --git a/src/AIS/FILES b/src/AIS/FILES index 1f9b18b48f..1f4d9c71bf 100644 --- a/src/AIS/FILES +++ b/src/AIS/FILES @@ -38,6 +38,7 @@ AIS_DataMapOfSelStat.hxx AIS_DisplayMode.hxx AIS_DisplayStatus.hxx AIS_DragAction.hxx +AIS_DragItem.hxx AIS_ExclusionFilter.cxx AIS_ExclusionFilter.hxx AIS_ExclusionFilter.lxx