changeset 1214:741201eab130 broker

removing pointer to viewport from ViewportController
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Dec 2019 19:12:08 +0100
parents 86a8266b8888
children 9efa66d8d3f8
files Framework/Scene2DViewport/ViewportController.cpp Framework/Scene2DViewport/ViewportController.h
diffstat 2 files changed, 18 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Scene2DViewport/ViewportController.cpp	Wed Dec 04 17:54:10 2019 +0100
+++ b/Framework/Scene2DViewport/ViewportController.cpp	Wed Dec 04 19:12:08 2019 +0100
@@ -32,8 +32,10 @@
 
 namespace OrthancStone
 {
-  IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(boost::shared_ptr<ViewportController> controller,
-                                                                    const PointerEvent& event)
+  IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(
+    boost::shared_ptr<ViewportController> controller,
+    IViewport& viewport,
+    const PointerEvent& event)
   {
     switch (event.GetMouseButton())
     {
@@ -45,7 +47,7 @@
       
       case MouseButton_Right:
       {
-        std::auto_ptr<IViewport::ILock> lock(controller->GetViewport().Lock());
+        std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
         if (lock->HasCompositor())
         {
           return new ZoomSceneTracker(controller, event, lock->GetCompositor().GetCanvasWidth());
@@ -62,16 +64,10 @@
   }
 
 
-  ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW,
-                                         boost::shared_ptr<IViewport> viewport)
+  ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW)
     : undoStackW_(undoStackW)
-    , viewport_(viewport)
     , canvasToSceneFactor_(1)
   {
-    if (viewport.get() == NULL)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
-    }
   }
  
   ViewportController::~ViewportController()
@@ -185,10 +181,10 @@
     BroadcastMessage(SceneTransformChanged(*this));
   }
 
-  void ViewportController::FitContent()
+  void ViewportController::FitContent(IViewport& viewport)
   {
     {
-      std::auto_ptr<IViewport::ILock> lock(viewport_->Lock());
+      std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
       lock->FitContent(scene_);
     }
 
@@ -238,7 +234,8 @@
   }
 
 
-  void ViewportController::HandleMousePress(IViewportInteractor& interactor,
+  void ViewportController::HandleMousePress(IViewport& viewport,
+                                            IViewportInteractor& interactor,
                                             const PointerEvent& event)
   {
     if (activeTracker_)
@@ -264,7 +261,7 @@
       }
 
       // No measure tool, create new tracker from the interactor
-      activeTracker_.reset(interactor.CreateTracker(shared_from_this(), event));
+      activeTracker_.reset(interactor.CreateTracker(shared_from_this(), viewport, event));
     }
   }
 
--- a/Framework/Scene2DViewport/ViewportController.h	Wed Dec 04 17:54:10 2019 +0100
+++ b/Framework/Scene2DViewport/ViewportController.h	Wed Dec 04 19:12:08 2019 +0100
@@ -39,6 +39,7 @@
     }
 
     virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller,
+                                                   IViewport& viewport,
                                                    const PointerEvent& event) = 0;
   };
 
@@ -48,6 +49,7 @@
   {
   public:
     virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller,
+                                                   IViewport& viewport,
                                                    const PointerEvent& event) ORTHANC_OVERRIDE;
   };
 
@@ -104,8 +106,7 @@
     ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \
                                         SceneTransformChanged, ViewportController);
 
-    ViewportController(boost::weak_ptr<UndoStack> undoStackW,
-                       boost::shared_ptr<IViewport> viewport);
+    ViewportController(boost::weak_ptr<UndoStack> undoStackW);
 
     ~ViewportController();
 
@@ -138,7 +139,7 @@
     void SetSceneToCanvasTransform(const AffineTransform2D& transform);
 
     /** Forwarded to the underlying scene, and broadcasted to the observers */
-    void FitContent();
+    void FitContent(IViewport& viewport);
 
     /** Adds a new measure tool */
     void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool);
@@ -188,14 +189,10 @@
     /** forwarded to the UndoStack */
     bool CanRedo() const;
 
-    IViewport& GetViewport() const
-    {
-      return *viewport_;
-    }
-
 
     // Must be expressed in canvas coordinates
-    void HandleMousePress(IViewportInteractor& interactor,
+    void HandleMousePress(IViewport& viewport,
+                          IViewportInteractor& interactor,
                           const PointerEvent& event);
 
     // Must be expressed in canvas coordinates
@@ -218,9 +215,8 @@
     double GetCanvasToSceneFactor() const;
 
     boost::weak_ptr<UndoStack>                    undoStackW_;  // Global stack, possibly shared by all viewports
-    boost::shared_ptr<IViewport>                  viewport_;
     std::vector<boost::shared_ptr<MeasureTool> >  measureTools_;
-    boost::shared_ptr<IFlexiblePointerTracker>    activeTracker_;  // TODO - Can't this be a "std::auto_ptr"?
+    boost::shared_ptr<IFlexiblePointerTracker>    activeTracker_;  // TODO - Couldn't this be a "std::auto_ptr"?
 
     Scene2D   scene_;