changeset 2378:29020ee1e020 refactoring

linking MeasureTool to its ViewportController
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Oct 2026 16:09:48 +0200
parents 94d62ecd8d50
children badae7b22831
files Applications/Samples/Common/SimpleViewerCore.cpp OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp OrthancStone/Sources/Scene2DViewport/MeasureCommands.h OrthancStone/Sources/Scene2DViewport/MeasureTool.cpp OrthancStone/Sources/Scene2DViewport/MeasureTool.h OrthancStone/Sources/Scene2DViewport/ViewportController.cpp
diffstat 10 files changed, 92 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/Common/SimpleViewerCore.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/Applications/Samples/Common/SimpleViewerCore.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -159,7 +159,7 @@
       viewportLock->GetController().SetUndoStack(boost::make_shared<UndoStack>());
     }
 
-#if TEST_MEASURE_TOOLS == 1
+#if 0 && TEST_MEASURE_TOOLS == 1    // TODO Refactoring - Reenable this
     {
       boost::shared_ptr<LineMeasureTool> tool = OrthancStone::LineMeasureTool::Create(viewport);
       tool->Enable();
@@ -267,7 +267,7 @@
         {
           if (core_->annotations_->GetActiveTool() == AnnotationsSceneLayer::Tool_Remove)
           {
-            boost::shared_ptr<MeasureCommand> command(new DeleteMeasureCommand(viewportLock->GetController(), tools[0]));
+            boost::shared_ptr<MeasureCommand> command(new DeleteMeasureCommand(tools[0]));
             viewportLock->GetController().PushCommand(command);
             return NULL;
           }
--- a/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -76,12 +76,12 @@
         std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock());
         if (isCreation)
         {
-          boost::shared_ptr<MeasureCommand> command(new CreateMeasureCommand(lock->GetController(), tool_));
+          boost::shared_ptr<MeasureCommand> command(new CreateMeasureCommand(tool_));
           lock->GetController().PushCommand(command);
         }
         else
         {
-          boost::shared_ptr<EditMeasureCommand> command(new EditMeasureCommand(lock->GetController(), tool_));
+          boost::shared_ptr<EditMeasureCommand> command(new EditMeasureCommand(tool_));
           editCommand_ = command;
         }
       }
@@ -182,9 +182,9 @@
 
   // the params in the LayerHolder ctor specify the number of polyline and text
   // layers
-  AngleMeasureTool::AngleMeasureTool(
-    boost::weak_ptr<IViewport> viewport)
-    : MeasureTool(viewport)
+  AngleMeasureTool::AngleMeasureTool(boost::weak_ptr<IViewport> viewport,
+                                     const boost::shared_ptr<ViewportController>& controller) :
+    MeasureTool(viewport, controller)
 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1
     , layerHolder_(boost::shared_ptr<LayerHolder>(new LayerHolder(1, 5)))
 #else
@@ -194,9 +194,10 @@
   {
   }
 
-  boost::shared_ptr<AngleMeasureTool> AngleMeasureTool::Create(boost::weak_ptr<IViewport> viewport)
+  boost::shared_ptr<AngleMeasureTool> AngleMeasureTool::Create(boost::weak_ptr<IViewport> viewport,
+                                                               const boost::shared_ptr<ViewportController>& controller)
   {
-    boost::shared_ptr<AngleMeasureTool> obj(new AngleMeasureTool(viewport));
+    boost::shared_ptr<AngleMeasureTool> obj(new AngleMeasureTool(viewport, controller));
     obj->MeasureTool::PostConstructor();
     obj->RefreshScene();
     return obj;
@@ -412,7 +413,7 @@
                 chain.push_back(side2End_);
                 chain.push_back(center_);
                 if ((angleHighlightArea_ == AngleHighlightArea_Side1) ||
-                  (angleHighlightArea_ == AngleHighlightArea_Side2))
+                    (angleHighlightArea_ == AngleHighlightArea_Side2))
                 {
                   polylineLayer->AddChain(chain, false, highlightColor);
                 }
@@ -500,49 +501,49 @@
           if (enableInfoDisplay)
           {
             TrackerSample_SetInfoDisplayMessage("center_.GetX()",
-              boost::lexical_cast<std::string>(center_.GetX()));
+                                                boost::lexical_cast<std::string>(center_.GetX()));
 
             TrackerSample_SetInfoDisplayMessage("center_.GetY()",
-              boost::lexical_cast<std::string>(center_.GetY()));
+                                                boost::lexical_cast<std::string>(center_.GetY()));
 
             TrackerSample_SetInfoDisplayMessage("side1End_.GetX()",
-              boost::lexical_cast<std::string>(side1End_.GetX()));
+                                                boost::lexical_cast<std::string>(side1End_.GetX()));
 
             TrackerSample_SetInfoDisplayMessage("side1End_.GetY()",
-              boost::lexical_cast<std::string>(side1End_.GetY()));
+                                                boost::lexical_cast<std::string>(side1End_.GetY()));
 
             TrackerSample_SetInfoDisplayMessage("side2End_.GetX()",
-              boost::lexical_cast<std::string>(side2End_.GetX()));
+                                                boost::lexical_cast<std::string>(side2End_.GetX()));
 
             TrackerSample_SetInfoDisplayMessage("side2End_.GetY()",
-              boost::lexical_cast<std::string>(side2End_.GetY()));
+                                                boost::lexical_cast<std::string>(side2End_.GetY()));
 
             TrackerSample_SetInfoDisplayMessage("p1cAngle (deg)",
-              boost::lexical_cast<std::string>(RadiansToDegrees(p1cAngle)));
+                                                boost::lexical_cast<std::string>(RadiansToDegrees(p1cAngle)));
 
             TrackerSample_SetInfoDisplayMessage("delta (deg)",
-              boost::lexical_cast<std::string>(RadiansToDegrees(delta)));
+                                                boost::lexical_cast<std::string>(RadiansToDegrees(delta)));
 
             TrackerSample_SetInfoDisplayMessage("theta (deg)",
-              boost::lexical_cast<std::string>(RadiansToDegrees(theta)));
+                                                boost::lexical_cast<std::string>(RadiansToDegrees(theta)));
 
             TrackerSample_SetInfoDisplayMessage("p2cAngle (deg)",
-              boost::lexical_cast<std::string>(RadiansToDegrees(p2cAngle)));
+                                                boost::lexical_cast<std::string>(RadiansToDegrees(p2cAngle)));
 
             TrackerSample_SetInfoDisplayMessage("ox (scene)",
-              boost::lexical_cast<std::string>(ox));
+                                                boost::lexical_cast<std::string>(ox));
 
             TrackerSample_SetInfoDisplayMessage("offsetY (scene)",
-              boost::lexical_cast<std::string>(oy));
+                                                boost::lexical_cast<std::string>(oy));
 
             TrackerSample_SetInfoDisplayMessage("pointX",
-              boost::lexical_cast<std::string>(pointX));
+                                                boost::lexical_cast<std::string>(pointX));
 
             TrackerSample_SetInfoDisplayMessage("pointY",
-              boost::lexical_cast<std::string>(pointY));
+                                                boost::lexical_cast<std::string>(pointY));
 
             TrackerSample_SetInfoDisplayMessage("angleDeg",
-              boost::lexical_cast<std::string>(angleDeg));
+                                                boost::lexical_cast<std::string>(angleDeg));
           }
 #endif
         }
--- a/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h	Fri Oct 09 16:09:48 2026 +0200
@@ -72,7 +72,8 @@
     };
 
   public:
-    static boost::shared_ptr<AngleMeasureTool> Create(boost::weak_ptr<IViewport> viewport);
+    static boost::shared_ptr<AngleMeasureTool> Create(boost::weak_ptr<IViewport> viewport,
+                                                      const boost::shared_ptr<ViewportController>& controller);
 
     ~AngleMeasureTool();
 
@@ -108,7 +109,8 @@
   private:
     class Tracker;
 
-    explicit AngleMeasureTool(boost::weak_ptr<IViewport> viewport);
+    explicit AngleMeasureTool(boost::weak_ptr<IViewport> viewport,
+                              const boost::shared_ptr<ViewportController>& controller);
 
     virtual void        RefreshScene() ORTHANC_OVERRIDE;
     void                RemoveFromScene();
--- a/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -42,19 +42,16 @@
     ScenePoint2D                               originalClickPosition_;
     LineMeasureTool::LineHighlightArea         modifiedZone_;
     bool                                       alive_;
-    boost::weak_ptr<IViewport>&                viewport_;  // TODO Refactoring
     boost::shared_ptr<EditMeasureCommand>      editCommand_;
 
   public:
     Tracker(const boost::shared_ptr<LineMeasureTool>& tool,
             bool isCreation,
             const Scene2D& scene,
-            const PointerEvent& e,
-            boost::weak_ptr<IViewport>& viewport) :
+            const PointerEvent& e) :
       tool_(tool),
       originalClickPosition_(e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform())),
-      alive_(true),
-      viewport_(viewport)
+      alive_(true)
     {
       if (!tool)
       {
@@ -64,20 +61,15 @@
       modifiedZone_ = tool_->LineHitTest(scene, originalClickPosition_);
       originalMemento_.reset(dynamic_cast<LineMeasureTool::Memento*>(tool->CreateMemento()));
 
-      boost::shared_ptr<IViewport> sharedViewport = viewport.lock();
-      if (sharedViewport)
+      if (isCreation)
       {
-        std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock());
-        if (isCreation)
-        {
-          boost::shared_ptr<MeasureCommand> command(new CreateMeasureCommand(lock->GetController(), tool_));
-          lock->GetController().PushCommand(command);
-        }
-        else
-        {
-          boost::shared_ptr<EditMeasureCommand> command(new EditMeasureCommand(lock->GetController(), tool_));
-          editCommand_ = command;
-        }
+        boost::shared_ptr<MeasureCommand> command(new CreateMeasureCommand(tool_));
+        tool->GetController().PushCommand(command);
+      }
+      else
+      {
+        boost::shared_ptr<EditMeasureCommand> command(new EditMeasureCommand(tool_));
+        editCommand_ = command;
       }
     }
 
@@ -123,13 +115,8 @@
       if (alive_ && editCommand_)
       {
         editCommand_->SetMementoModified(tool_->CreateMemento());
-
-        boost::shared_ptr<IViewport> sharedViewport = viewport_.lock();
-        if (sharedViewport)
-        {
-          std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock());
-          lock->GetController().PushCommand(editCommand_);
-        }
+        tool_->GetController().PushCommand(editCommand_);
+        editCommand_.reset();
       }
 
       alive_ = false;
@@ -158,9 +145,9 @@
   };
 
 
-  LineMeasureTool::LineMeasureTool(
-    boost::weak_ptr<IViewport> viewport):
-    MeasureTool(viewport),
+  LineMeasureTool::LineMeasureTool(boost::weak_ptr<IViewport> viewport,
+                                   const boost::shared_ptr<ViewportController>& controller) :
+    MeasureTool(viewport, controller),
 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1
     layerHolder_(boost::shared_ptr<LayerHolder>(new LayerHolder(1, 5))),
 #else
@@ -172,9 +159,10 @@
 
   }
 
-  boost::shared_ptr<LineMeasureTool> LineMeasureTool::Create(boost::weak_ptr<IViewport> viewport)
+  boost::shared_ptr<LineMeasureTool> LineMeasureTool::Create(boost::weak_ptr<IViewport> viewport,
+                                                             const boost::shared_ptr<ViewportController>& controller)
   {
-    boost::shared_ptr<LineMeasureTool> obj(new LineMeasureTool(viewport));
+    boost::shared_ptr<LineMeasureTool> obj(new LineMeasureTool(viewport, controller));
     obj->MeasureTool::PostConstructor();
     obj->RefreshScene();
     return obj;
@@ -297,7 +285,7 @@
     }
     else
     {
-      return new Tracker(boost::dynamic_pointer_cast<LineMeasureTool>(shared_from_this()), isCreation, scene, e, viewport_);
+      return new Tracker(boost::dynamic_pointer_cast<LineMeasureTool>(shared_from_this()), isCreation, scene, e);
     }
   }
 
@@ -402,7 +390,7 @@
               scene, layerHolder_, buf, ScenePoint2D(midX, midY), 0);
 #else
             SetTextLayerProperties(
-                                   scene, layerHolder_, buf, ScenePoint2D(midX, midY), 0);
+              scene, layerHolder_, buf, ScenePoint2D(midX, midY), 0);
 #endif
             lock->Invalidate();
           }
--- a/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h	Fri Oct 09 16:09:48 2026 +0200
@@ -67,7 +67,8 @@
     };
 
   public:
-    static boost::shared_ptr<LineMeasureTool> Create(boost::weak_ptr<IViewport> viewport);
+    static boost::shared_ptr<LineMeasureTool> Create(boost::weak_ptr<IViewport> viewport,
+                                                     const boost::shared_ptr<ViewportController>& controller);
 
     ~LineMeasureTool();
 
@@ -102,7 +103,8 @@
   private:
     class Tracker;
 
-    explicit LineMeasureTool(boost::weak_ptr<IViewport> viewport);
+    explicit LineMeasureTool(boost::weak_ptr<IViewport> viewport,
+                             const boost::shared_ptr<ViewportController>& controller);
 
     virtual void        RefreshScene() ORTHANC_OVERRIDE;
     void                RemoveFromScene();
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -26,9 +26,7 @@
 
 namespace OrthancStone
 {
-  MeasureCommand::MeasureCommand(ViewportController& controller,
-                                 const boost::shared_ptr<MeasureTool>& tool) :
-    controller_(controller),
+  MeasureCommand::MeasureCommand(const boost::shared_ptr<MeasureTool>& tool) :
     measureTool_(tool)
   {
     if (!tool)
@@ -43,22 +41,21 @@
   {
     // simply disable the measure tool upon undo
     GetMeasureTool()->Disable();
-    GetController().RemoveMeasureTool(GetMeasureTool());
+    GetMeasureTool()->GetController().RemoveMeasureTool(GetMeasureTool());
   }
 
 
   void CreateMeasureCommand::Redo()
   {
     GetMeasureTool()->Enable();
-    GetController().AddMeasureTool(GetMeasureTool());
+    GetMeasureTool()->GetController().AddMeasureTool(GetMeasureTool());
   }
 
 
 
 
-  EditMeasureCommand::EditMeasureCommand(ViewportController& controller,
-                                         const boost::shared_ptr<MeasureTool>& tool) :
-    MeasureCommand(controller, tool),
+  EditMeasureCommand::EditMeasureCommand(const boost::shared_ptr<MeasureTool>& tool) :
+    MeasureCommand(tool),
     mementoModified_(tool->CreateMemento()),
     mementoOriginal_(tool->CreateMemento())
   {
@@ -97,19 +94,18 @@
 
 
 
-  DeleteMeasureCommand::DeleteMeasureCommand(ViewportController& controller,
-                                             const boost::shared_ptr<MeasureTool>& tool) :
-    MeasureCommand(controller, tool)
+  DeleteMeasureCommand::DeleteMeasureCommand(const boost::shared_ptr<MeasureTool>& tool) :
+    MeasureCommand(tool)
   {
     GetMeasureTool()->Disable();
-    GetController().RemoveMeasureTool(GetMeasureTool());  // TODO Refactoring - Should probably be moved into ViewportController
+    GetMeasureTool()->GetController().RemoveMeasureTool(GetMeasureTool());  // TODO Refactoring - Should probably be moved into ViewportController
   }
 
 
   void DeleteMeasureCommand::Undo()
   {
     GetMeasureTool()->Enable();
-    GetController().AddMeasureTool(GetMeasureTool());
+    GetMeasureTool()->GetController().AddMeasureTool(GetMeasureTool());
   }
 
 
@@ -117,6 +113,6 @@
   {
     // simply disable the measure tool upon undo
     GetMeasureTool()->Disable();
-    GetController().RemoveMeasureTool(GetMeasureTool());
+    GetMeasureTool()->GetController().RemoveMeasureTool(GetMeasureTool());
   }
 }
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h	Fri Oct 09 16:09:48 2026 +0200
@@ -34,23 +34,16 @@
   class MeasureCommand : public UndoStack::ICommand
   {
   private:
-    ViewportController&             controller_;   // TODO Refactoring - Should be a boost::shared_ptr
     boost::shared_ptr<MeasureTool>  measureTool_;
 
   protected:
-    ViewportController& GetController() const
-    {
-      return controller_;
-    }
-
     const boost::shared_ptr<MeasureTool>& GetMeasureTool() const
     {
       return measureTool_;
     }
 
   public:
-    explicit MeasureCommand(ViewportController& controller,
-                            const boost::shared_ptr<MeasureTool>& measureTool);
+    explicit MeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool);
 
     virtual ~MeasureCommand()
     {
@@ -65,9 +58,8 @@
   class CreateMeasureCommand : public MeasureCommand
   {
   public:
-    CreateMeasureCommand(ViewportController& controller,
-                         const boost::shared_ptr<MeasureTool>& measureTool) :
-      MeasureCommand(controller, measureTool)
+    CreateMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool) :
+      MeasureCommand(measureTool)
     {
     }
 
@@ -87,8 +79,7 @@
     std::unique_ptr<MeasureTool::IMemento> mementoOriginal_;
 
   public:
-    EditMeasureCommand(ViewportController& controller,
-                       const boost::shared_ptr<MeasureTool>& measureTool);
+    EditMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool);
 
     virtual void Undo() ORTHANC_OVERRIDE;
 
@@ -103,8 +94,7 @@
   class DeleteMeasureCommand : public MeasureCommand
   {
   public:
-    DeleteMeasureCommand(ViewportController& controller,
-                         const boost::shared_ptr<MeasureTool>& measureTool);
+    DeleteMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool);
 
     virtual void Undo() ORTHANC_OVERRIDE;
     
--- a/OrthancStone/Sources/Scene2DViewport/MeasureTool.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/MeasureTool.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -77,22 +77,21 @@
     return HANDLE_SIDE_LENGTH_CANVAS_COORD * scene.GetCanvasToSceneTransform().ComputeZoom();
   }
 
-  MeasureTool::MeasureTool(boost::weak_ptr<IViewport> viewport) :
+  MeasureTool::MeasureTool(boost::weak_ptr<IViewport> viewport,
+                           const boost::shared_ptr<ViewportController>& controller) :
     enabled_(true),
+    controller_(controller),
     viewport_(viewport)
   {
+    if (!controller)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
+    }
   }
 
   void MeasureTool::PostConstructor()
   {
-    std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
-
-    if (lock.get() != NULL)
-    {
-      Register<ViewportController::SceneTransformChanged>(
-        lock->GetController(), 
-        &MeasureTool::OnSceneTransformChanged);
-    }
+    Register<ViewportController::SceneTransformChanged>(*controller_, &MeasureTool::OnSceneTransformChanged);
   }
 
   bool MeasureTool::IsSceneAlive() const
@@ -105,9 +104,9 @@
     return (lock != NULL);
   }
 
-  void MeasureTool::OnSceneTransformChanged(
-    const ViewportController::SceneTransformChanged& message)
+  void MeasureTool::OnSceneTransformChanged(const ViewportController::SceneTransformChanged& message)
   {
+    // TODO Refactoring - This is not called
     RefreshScene();
   }
 }
--- a/OrthancStone/Sources/Scene2DViewport/MeasureTool.h	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/MeasureTool.h	Fri Oct 09 16:09:48 2026 +0200
@@ -46,11 +46,13 @@
     };
 
   private:
-    bool     enabled_;
+    bool                                   enabled_;
+    boost::shared_ptr<ViewportController>  controller_;
 
 
   protected:
-    explicit MeasureTool(boost::weak_ptr<IViewport> viewport);
+    explicit MeasureTool(boost::weak_ptr<IViewport> viewport,  // TODO Refactoring - Remove
+                         const boost::shared_ptr<ViewportController>& controller);
 
     void PostConstructor();
 
@@ -60,7 +62,7 @@
        before accessing the scene.
     */
     bool IsSceneAlive() const;
-    
+
     /**
        This is the meat of the tool: this method must [create (if needed) and]
        update the layers and their data according to the measure tool kind and
@@ -78,7 +80,7 @@
        Protected to allow sub-classes to use this weak pointer in factory methods
        (pass them to created objects)
     */
-    boost::weak_ptr<IViewport> viewport_;
+    boost::weak_ptr<IViewport> viewport_;   // TODO Refactoring - Remove
 
     /**
     This will return a scoped lock to the viewport. 
@@ -163,8 +165,10 @@
        A description of the measuring tool, useful in debug logs
     */
     virtual std::string GetDescription() = 0;
+
+    ViewportController& GetController() const
+    {
+      return *controller_;
+    }
   };
 }
-
-//extern void TrackerSample_SetInfoDisplayMessage(
-//  std::string key, std::string value);
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Fri Oct 09 15:15:07 2026 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Fri Oct 09 16:09:48 2026 +0200
@@ -165,7 +165,7 @@
   {
     const ScenePoint2D p = event.GetMainPosition().Apply(scene_->GetCanvasToSceneTransform());
 
-    boost::shared_ptr<LineMeasureTool> tool = LineMeasureTool::Create(viewport_);
+    boost::shared_ptr<LineMeasureTool> tool = LineMeasureTool::Create(viewport_, shared_from_this());
     tool->Enable();
     tool->Set(p, p);
 
@@ -179,7 +179,7 @@
   {
     const ScenePoint2D p = event.GetMainPosition().Apply(scene_->GetCanvasToSceneTransform());
 
-    boost::shared_ptr<AngleMeasureTool> tool = AngleMeasureTool::Create(viewport_);
+    boost::shared_ptr<AngleMeasureTool> tool = AngleMeasureTool::Create(viewport_, shared_from_this());
     tool->Enable();
     tool->SetCenter(p);
     tool->SetSide1End(p);