diff Samples/Common/CreateLineMeasureTracker.cpp @ 654:462a5074f914

Turned the scene into an observable to be able to dynamically react to scene to canvas transform changes --> now the handles and angle measure adornments are immune to zoom changes
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 13:51:00 +0200
parents 1e9ed656318e
children
line wrap: on
line diff
--- a/Samples/Common/CreateLineMeasureTracker.cpp	Tue May 14 13:49:12 2019 +0200
+++ b/Samples/Common/CreateLineMeasureTracker.cpp	Tue May 14 13:51:00 2019 +0200
@@ -26,45 +26,47 @@
 namespace OrthancStone
 {
   CreateLineMeasureTracker::CreateLineMeasureTracker(
+    MessageBroker&                  broker,
     Scene2D&                        scene,
     std::vector<TrackerCommandPtr>& undoStack,
     std::vector<MeasureToolPtr>&    measureTools,
     const PointerEvent&             e)
     : CreateMeasureTracker(scene, undoStack, measureTools)
-  {
+  {
     command_.reset(
       new CreateLineMeasureCommand(
+        broker,
         scene,
         measureTools,
-        e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform())));
-  }
-
+        e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform())));
+  }
+
   CreateLineMeasureTracker::~CreateLineMeasureTracker()
   {
 
   }
 
-  void CreateLineMeasureTracker::PointerMove(const PointerEvent& event)
-  {
-    if (!active_)
-    {
-      throw OrthancException(ErrorCode_InternalError,
-        "Internal error: wrong state in CreateLineMeasureTracker::"
-        "PointerMove: active_ == false");
-    }
-
-    ScenePoint2D scenePos = event.GetMainPosition().Apply(
-      scene_.GetCanvasToSceneTransform());
-
+  void CreateLineMeasureTracker::PointerMove(const PointerEvent& event)
+  {
+    if (!active_)
+    {
+      throw OrthancException(ErrorCode_InternalError,
+        "Internal error: wrong state in CreateLineMeasureTracker::"
+        "PointerMove: active_ == false");
+    }
+
+    ScenePoint2D scenePos = event.GetMainPosition().Apply(
+      scene_.GetCanvasToSceneTransform());
+
     //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << "     " <<
     //  "scenePos.GetY() = " << scenePos.GetY();
-
+
     CreateLineMeasureTracker* concreteThis =
       dynamic_cast<CreateLineMeasureTracker*>(this);
     assert(concreteThis != NULL);
-    GetCommand()->SetEnd(scenePos);
-  }
-
+    GetCommand()->SetEnd(scenePos);
+  }
+
   void CreateLineMeasureTracker::PointerUp(const PointerEvent& e)
   {
     // TODO: the current app does not prevent multiple PointerDown AND
@@ -72,7 +74,7 @@
     // Unless we augment the PointerEvent structure with the button index, 
     // we cannot really tell if this pointer up event matches the initial
     // pointer down event. Let's make it simple for now.
-    active_ = false;
+    active_ = false;
   }
 
   void CreateLineMeasureTracker::PointerDown(const PointerEvent& e)