changeset 1215:9efa66d8d3f8 broker

removed ViewportBase, and removed dependency of ViewportController on IViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Dec 2019 20:12:15 +0100
parents 741201eab130
children 5147277850cf
files Framework/Scene2D/ICompositor.h Framework/Scene2DViewport/ViewportController.cpp Framework/Scene2DViewport/ViewportController.h Framework/Viewport/IViewport.h Framework/Viewport/SdlViewport.h Framework/Viewport/ViewportBase.cpp Framework/Viewport/ViewportBase.h Resources/CMake/OrthancStoneConfiguration.cmake
diffstat 8 files changed, 45 insertions(+), 138 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Scene2D/ICompositor.h	Wed Dec 04 19:12:08 2019 +0100
+++ b/Framework/Scene2D/ICompositor.h	Wed Dec 04 20:12:15 2019 +0100
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "Scene2D.h"
+#include "ScenePoint2D.h"
 
 #include <EmbeddedResources.h>
 
@@ -32,5 +33,18 @@
                          unsigned int fontSize,
                          Orthanc::Encoding codepage) = 0;
 #endif
+
+    // Get the center of the given pixel, in canvas coordinates
+    ScenePoint2D GetPixelCenterCoordinates(int x, int y) const
+    {
+      return ScenePoint2D(
+        static_cast<double>(x) + 0.5 - static_cast<double>(GetCanvasWidth()) / 2.0,
+        static_cast<double>(y) + 0.5 - static_cast<double>(GetCanvasHeight()) / 2.0);
+    }
+
+    void FitContent(Scene2D& scene) const
+    {
+      scene.FitContent(GetCanvasWidth(), GetCanvasHeight());
+    }
   };
 }
--- a/Framework/Scene2DViewport/ViewportController.cpp	Wed Dec 04 19:12:08 2019 +0100
+++ b/Framework/Scene2DViewport/ViewportController.cpp	Wed Dec 04 20:12:15 2019 +0100
@@ -34,8 +34,9 @@
 {
   IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(
     boost::shared_ptr<ViewportController> controller,
-    IViewport& viewport,
-    const PointerEvent& event)
+    const PointerEvent& event,
+    unsigned int viewportWidth,
+    unsigned int viewportHeight)
   {
     switch (event.GetMouseButton())
     {
@@ -47,10 +48,9 @@
       
       case MouseButton_Right:
       {
-        std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
-        if (lock->HasCompositor())
+        if (viewportWidth != 0)
         {
-          return new ZoomSceneTracker(controller, event, lock->GetCompositor().GetCanvasWidth());
+          return new ZoomSceneTracker(controller, event, viewportWidth);
         }
         else
         {
@@ -181,13 +181,10 @@
     BroadcastMessage(SceneTransformChanged(*this));
   }
 
-  void ViewportController::FitContent(IViewport& viewport)
+  void ViewportController::FitContent(unsigned int viewportWidth,
+                                      unsigned int viewportHeight)
   {
-    {
-      std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
-      lock->FitContent(scene_);
-    }
-
+    scene_.FitContent(viewportWidth, viewportHeight);
     canvasToSceneFactor_ = scene_.GetCanvasToSceneTransform().ComputeZoom();
     BroadcastMessage(SceneTransformChanged(*this));
   }
@@ -234,9 +231,10 @@
   }
 
 
-  void ViewportController::HandleMousePress(IViewport& viewport,
-                                            IViewportInteractor& interactor,
-                                            const PointerEvent& event)
+  void ViewportController::HandleMousePress(OrthancStone::IViewportInteractor& interactor,
+                                            const PointerEvent& event,
+                                            unsigned int viewportWidth,
+                                            unsigned int viewportHeight)
   {
     if (activeTracker_)
     {
@@ -261,7 +259,7 @@
       }
 
       // No measure tool, create new tracker from the interactor
-      activeTracker_.reset(interactor.CreateTracker(shared_from_this(), viewport, event));
+      activeTracker_.reset(interactor.CreateTracker(shared_from_this(), event, viewportWidth, viewportHeight));
     }
   }
 
--- a/Framework/Scene2DViewport/ViewportController.h	Wed Dec 04 19:12:08 2019 +0100
+++ b/Framework/Scene2DViewport/ViewportController.h	Wed Dec 04 20:12:15 2019 +0100
@@ -22,7 +22,8 @@
 
 #include "PredeclaredTypes.h"
 
-#include "../Viewport/IViewport.h"
+#include "../Messages/IObservable.h"
+#include "../Scene2D/Scene2D.h"
 #include "../Scene2DViewport/IFlexiblePointerTracker.h"
 
 #include <boost/enable_shared_from_this.hpp>
@@ -39,8 +40,9 @@
     }
 
     virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller,
-                                                   IViewport& viewport,
-                                                   const PointerEvent& event) = 0;
+                                                   const PointerEvent& event,
+                                                   unsigned int viewportWidth,
+                                                   unsigned int viewportHeight) = 0;
   };
 
 
@@ -49,8 +51,9 @@
   {
   public:
     virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller,
-                                                   IViewport& viewport,
-                                                   const PointerEvent& event) ORTHANC_OVERRIDE;
+                                                   const PointerEvent& event,
+                                                   unsigned int viewportWidth,
+                                                   unsigned int viewportHeight) ORTHANC_OVERRIDE;
   };
 
 
@@ -139,7 +142,8 @@
     void SetSceneToCanvasTransform(const AffineTransform2D& transform);
 
     /** Forwarded to the underlying scene, and broadcasted to the observers */
-    void FitContent(IViewport& viewport);
+    void FitContent(unsigned int viewportWidth,
+                    unsigned int viewportHeight);
 
     /** Adds a new measure tool */
     void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool);
@@ -191,9 +195,10 @@
 
 
     // Must be expressed in canvas coordinates
-    void HandleMousePress(IViewport& viewport,
-                          IViewportInteractor& interactor,
-                          const PointerEvent& event);
+    void HandleMousePress(IViewportInteractor& interactor,
+                          const PointerEvent& event,
+                          unsigned int viewportWidth,
+                          unsigned int viewportHeight);
 
     // Must be expressed in canvas coordinates
     void HandleMouseMove(const PointerEvent& event);
--- a/Framework/Viewport/IViewport.h	Wed Dec 04 19:12:08 2019 +0100
+++ b/Framework/Viewport/IViewport.h	Wed Dec 04 20:12:15 2019 +0100
@@ -47,14 +47,9 @@
       {
       }
 
-      // Get the center of the given pixel, in canvas coordinates
-      virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) = 0;
-
       virtual bool HasCompositor() const = 0;
 
       virtual ICompositor& GetCompositor() = 0;
-
-      virtual void FitContent(Scene2D& scene) = 0;
     };   
     
     virtual ~IViewport()
--- a/Framework/Viewport/SdlViewport.h	Wed Dec 04 19:12:08 2019 +0100
+++ b/Framework/Viewport/SdlViewport.h	Wed Dec 04 20:12:15 2019 +0100
@@ -39,13 +39,13 @@
 #include "../OpenGL/SdlOpenGLContext.h"
 #include "../Scene2D/OpenGLCompositor.h"
 #include "../Scene2D/CairoCompositor.h"
-#include "ViewportBase.h"
+#include "IViewport.h"
 
 #include <SDL_events.h>
 
 namespace OrthancStone
 {
-  class SdlViewport : public ViewportBase
+  class SdlViewport : public IViewport
   {
   private:
     uint32_t  refreshEvent_;
@@ -75,7 +75,7 @@
     SdlOpenGLContext                 context_;
     std::auto_ptr<OpenGLCompositor>  compositor_;
 
-    class SdlLock : public LockBase
+    class SdlLock : public ILock
     {
     private:
       SdlOpenGLViewport&         that_;
@@ -83,7 +83,6 @@
       
     public:
       SdlLock(SdlOpenGLViewport& viewport) :
-        LockBase(viewport),
         that_(viewport),
         lock_(viewport.mutex_)
       {
@@ -131,7 +130,7 @@
   class SdlCairoViewport : public SdlViewport
   {
   private:
-    class SdlLock : public LockBase
+    class SdlLock : public ILock
     {
     private:
       SdlCairoViewport&          that_;
@@ -139,7 +138,6 @@
       
     public:
       SdlLock(SdlCairoViewport& viewport) :
-        LockBase(viewport),
         that_(viewport),
         lock_(viewport.mutex_)
       {
--- a/Framework/Viewport/ViewportBase.cpp	Wed Dec 04 19:12:08 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2019 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#include "ViewportBase.h"
-
-#include <Core/OrthancException.h>
-
-#include <boost/make_shared.hpp>
-
-namespace OrthancStone
-{
-  ScenePoint2D ViewportBase::LockBase::GetPixelCenterCoordinates(int x, int y)
-  {
-    if (HasCompositor())
-    {
-      ICompositor& compositor = GetCompositor();
-      return ScenePoint2D(
-        static_cast<double>(x) + 0.5 - static_cast<double>(compositor.GetCanvasWidth()) / 2.0,
-        static_cast<double>(y) + 0.5 - static_cast<double>(compositor.GetCanvasHeight()) / 2.0);
-    }
-    else
-    {
-      return ScenePoint2D(0, 0);
-    }
-  }
-
-
-  void ViewportBase::LockBase::FitContent(Scene2D& scene)
-  {
-    if (HasCompositor())
-    {
-      ICompositor& compositor = GetCompositor();
-      scene.FitContent(compositor.GetCanvasWidth(), compositor.GetCanvasHeight());
-    }
-  }
-}
--- a/Framework/Viewport/ViewportBase.h	Wed Dec 04 19:12:08 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2019 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#pragma once
-
-#include "IViewport.h"
-
-#include <boost/shared_ptr.hpp>
-
-namespace OrthancStone
-{
-  class ViewportBase : public IViewport
-  {
-  protected:
-    class LockBase : public ILock
-    {
-    private:
-      ViewportBase& that_;
-
-    public:
-      LockBase(ViewportBase& that) :
-        that_(that)
-      {
-      }
-
-      virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) ORTHANC_OVERRIDE;
-
-      virtual void FitContent(Scene2D& scene) ORTHANC_OVERRIDE;
-    };
-  };
-}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Dec 04 19:12:08 2019 +0100
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Dec 04 20:12:15 2019 +0100
@@ -594,8 +594,6 @@
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/UndoRedoStack.h
   
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/IViewport.h
-  ${ORTHANC_STONE_ROOT}/Framework/Viewport/ViewportBase.h
-  ${ORTHANC_STONE_ROOT}/Framework/Viewport/ViewportBase.cpp
   
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/IVolumeSlicer.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/IVolumeSlicer.h