]> OCCT Git - occt-copy.git/commitdiff
0031656: Visualization - drag item to handle in AIS_ViewController
authornds <natalia.ermolaeva@opencascade.com>
Mon, 6 Jul 2020 16:32:55 +0000 (19:32 +0300)
committernds <natalia.ermolaeva@opencascade.com>
Mon, 6 Jul 2020 17:00:32 +0000 (20:00 +0300)
(cherry picked from commit e72fa9fc9d26715ca0cb4294d8d4b5ed7d2a6f76)

src/AIS/AIS_DragItem.hxx [new file with mode: 0644]
src/AIS/AIS_Manipulator.hxx
src/AIS/AIS_ViewController.cxx
src/AIS/FILES

diff --git a/src/AIS/AIS_DragItem.hxx b/src/AIS/AIS_DragItem.hxx
new file mode 100644 (file)
index 0000000..1cccb5d
--- /dev/null
@@ -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 <AIS_DragItem.hxx>
+
+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
index b05e1dc57c768be26296bd05cf9ef3b44e7e58d3..5608854e37ff84a508be0224665953ea500e7f1c 100644 (file)
@@ -17,6 +17,7 @@
 #define _AIS_Manipulator_HeaderFile
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_DragItem.hxx>
 #include <AIS_ManipulatorMode.hxx>
 #include <gp.hxx>
 #include <gp_Ax1.hxx>
@@ -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; }
 
index 17a5425e2d0bff3f096fb8548c692fb6ef4293ae..e95de04064faebd8fd86cf234d75f2c61b8bfb09 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <AIS_AnimationCamera.hxx>
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Manipulator.hxx>
+#include <AIS_DragItem.hxx>
 #include <AIS_Point.hxx>
 #include <AIS_RubberBand.hxx>
 #include <AIS_XRTrackedDevice.hxx>
@@ -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<AIS_DragItem*>(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<AIS_DragItem*>(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<AIS_DragItem*>(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<AIS_DragItem*>(myDragObject.get()))
+      {
+        aDragItem->StopTransform (false);
+      }
       theView->Invalidate();
       myDragObject.Nullify();
       return;
index 1f9b18b48f1553902a9696f087deec197e037678..1f4d9c71bfbc90d39d5689ba69671a0584bfb6de 100644 (file)
@@ -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