changeset 503:77e0eb83ff63 am-touch-events

layers are now Observable and emitting LayerEdited messages
author amazy
date Tue, 26 Feb 2019 12:58:03 +0100
parents 3ae7563b4fe1
children 801d2697a1b1 7a16fb9a4ba5
files Framework/Radiography/RadiographyAlphaLayer.cpp Framework/Radiography/RadiographyAlphaLayer.h Framework/Radiography/RadiographyDicomLayer.cpp Framework/Radiography/RadiographyDicomLayer.h Framework/Radiography/RadiographyLayer.cpp Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyMaskLayer.cpp Framework/Radiography/RadiographyMaskLayer.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyTextLayer.h Framework/StoneEnumerations.h
diffstat 12 files changed, 142 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyAlphaLayer.cpp	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyAlphaLayer.cpp	Tue Feb 26 12:58:03 2019 +0100
@@ -45,6 +45,8 @@
 
     SetSize(image->GetWidth(), image->GetHeight());
     alpha_ = raii;
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
   void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer,
@@ -84,7 +86,7 @@
     if (useWindowing_)
     {
       float center, width;
-      if (scene_.GetWindowing(center, width))
+      if (GetScene().GetWindowing(center, width))
       {
         value = center + width / 2.0f;  // set it to the maximum pixel value of the image
       }
--- a/Framework/Radiography/RadiographyAlphaLayer.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyAlphaLayer.h	Tue Feb 26 12:58:03 2019 +0100
@@ -33,14 +33,13 @@
   class RadiographyAlphaLayer : public RadiographyLayer
   {
   private:
-    const RadiographyScene&                scene_;
     std::auto_ptr<Orthanc::ImageAccessor>  alpha_;      // Grayscale8
     bool                                   useWindowing_;
     float                                  foreground_;
 
   public:
-    RadiographyAlphaLayer(const RadiographyScene& scene) :
-      scene_(scene),
+    RadiographyAlphaLayer(MessageBroker& broker, const RadiographyScene& scene) :
+      RadiographyLayer(broker, scene),
       useWindowing_(true),
       foreground_(0)
     {
--- a/Framework/Radiography/RadiographyDicomLayer.cpp	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyDicomLayer.cpp	Tue Feb 26 12:58:03 2019 +0100
@@ -102,6 +102,8 @@
 
     source_ = raii;
     ApplyConverter();
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
   void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer,
--- a/Framework/Radiography/RadiographyDicomLayer.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyDicomLayer.h	Tue Feb 26 12:58:03 2019 +0100
@@ -41,6 +41,11 @@
     void ApplyConverter();
 
   public:
+    RadiographyDicomLayer(MessageBroker& broker, const RadiographyScene& scene)
+      : RadiographyLayer(broker, scene)
+    {
+    }
+
     void SetInstance(const std::string& instanceId, unsigned int frame)
     {
       instanceId_ = instanceId;
--- a/Framework/Radiography/RadiographyLayer.cpp	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyLayer.cpp	Tue Feb 26 12:58:03 2019 +0100
@@ -117,12 +117,14 @@
   }
 
 
-  RadiographyLayer::RadiographyLayer() :
+  RadiographyLayer::RadiographyLayer(MessageBroker& broker, const RadiographyScene& scene) :
+    IObservable(broker),
     index_(0),
     hasSize_(false),
     width_(0),
     height_(0),
-    prefferedPhotometricDisplayMode_(PhotometricDisplayMode_Default)
+    prefferedPhotometricDisplayMode_(PhotometricDisplayMode_Default),
+    scene_(scene)
   {
     UpdateTransform();
   }
@@ -133,6 +135,13 @@
     UpdateTransform();
   }
 
+  void RadiographyLayer::SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode  prefferedPhotometricDisplayMode)
+  {
+    prefferedPhotometricDisplayMode_ = prefferedPhotometricDisplayMode;
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
+  }
+
   void RadiographyLayer::SetCrop(unsigned int x,
                                  unsigned int y,
                                  unsigned int width,
@@ -151,6 +160,8 @@
 
     geometry_.SetCrop(x, y, width, height);
     UpdateTransform();
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
   void RadiographyLayer::SetGeometry(const Geometry& geometry)
@@ -161,6 +172,8 @@
     {
       UpdateTransform();
     }
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
 
@@ -187,6 +200,8 @@
   {
     geometry_.SetAngle(angle);
     UpdateTransform();
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
 
@@ -205,6 +220,7 @@
     height_ = height;
 
     UpdateTransform();
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
 
@@ -282,6 +298,7 @@
   {
     geometry_.SetPan(x, y);
     UpdateTransform();
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
 
@@ -290,6 +307,7 @@
   {
     geometry_.SetPixelSpacing(x, y);
     UpdateTransform();
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
 
--- a/Framework/Radiography/RadiographyLayer.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyLayer.h	Tue Feb 26 12:58:03 2019 +0100
@@ -24,9 +24,13 @@
 #include "../Toolbox/AffineTransform2D.h"
 #include "../Toolbox/Extent2D.h"
 #include "../Viewport/CairoContext.h"
+#include "../Messages/IMessage.h"
+#include "../Messages/IObservable.h"
 
 namespace OrthancStone
 {
+  class RadiographyScene;
+
   struct ControlPoint
   {
     double x;
@@ -46,11 +50,24 @@
     {}
   };
 
-  class RadiographyLayer : public boost::noncopyable
+  class RadiographyLayer : public IObservable
   {
     friend class RadiographyScene;
 
   public:
+    class LayerEditedMessage :
+        public OriginMessage<MessageType_RadiographyLayer_Edited, RadiographyLayer>
+    {
+    private:
+
+    public:
+      LayerEditedMessage(const RadiographyLayer& origin) :
+        OriginMessage(origin)
+      {
+      }
+    };
+
+
     class Geometry
     {
       bool               hasCrop_;
@@ -160,7 +177,7 @@
     AffineTransform2D  transformInverse_;
     Geometry           geometry_;
     PhotometricDisplayMode  prefferedPhotometricDisplayMode_;
-
+    const RadiographyScene&   scene_;
 
   protected:
     virtual const AffineTransform2D& GetTransform() const
@@ -173,10 +190,7 @@
       return transformInverse_;
     }
 
-    void SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode  prefferedPhotometricDisplayMode)
-    {
-      prefferedPhotometricDisplayMode_ = prefferedPhotometricDisplayMode;
-    }
+    void SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode  prefferedPhotometricDisplayMode);
 
   private:
     void UpdateTransform();
@@ -197,7 +211,7 @@
                      double zoom);
 
   public:
-    RadiographyLayer();
+    RadiographyLayer(MessageBroker& broker, const RadiographyScene& scene);
 
     virtual ~RadiographyLayer()
     {
@@ -208,6 +222,11 @@
       return index_;
     }
 
+    const RadiographyScene& GetScene() const
+    {
+      return scene_;
+    }
+
     const Geometry& GetGeometry() const
     {
       return geometry_;
--- a/Framework/Radiography/RadiographyMaskLayer.cpp	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyMaskLayer.cpp	Tue Feb 26 12:58:03 2019 +0100
@@ -62,12 +62,16 @@
     else
       corners_.push_back(corner);
     invalidated_ = true;
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
   void RadiographyMaskLayer::SetCorners(const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners)
   {
     corners_ = corners;
     invalidated_ = true;
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
   void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer,
--- a/Framework/Radiography/RadiographyMaskLayer.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyMaskLayer.h	Tue Feb 26 12:58:03 2019 +0100
@@ -40,9 +40,9 @@
 
     mutable std::auto_ptr<Orthanc::ImageAccessor>  mask_;
   public:
-    RadiographyMaskLayer(const RadiographyScene& scene, const RadiographyDicomLayer& dicomLayer,
+    RadiographyMaskLayer(MessageBroker& broker, const RadiographyScene& scene, const RadiographyDicomLayer& dicomLayer,
                          float foreground) :
-      RadiographyLayer(),
+      RadiographyLayer(broker, scene),
       dicomLayer_(dicomLayer),
       invalidated_(true),
       foreground_(foreground)
--- a/Framework/Radiography/RadiographyScene.cpp	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Tue Feb 26 12:58:03 2019 +0100
@@ -142,10 +142,15 @@
 
     EmitMessage(GeometryChangedMessage(*this, *layer));
     EmitMessage(ContentChangedMessage(*this, *layer));
+    layer->RegisterObserverCallback(new Callable<RadiographyScene, RadiographyLayer::LayerEditedMessage>(*this, &RadiographyScene::OnLayerEdited));
 
     return *layer;
   }
 
+  void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message)
+  {
+    EmitMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin()));
+  }
 
   RadiographyScene::RadiographyScene(MessageBroker& broker) :
     IObserver(broker),
@@ -247,6 +252,8 @@
     hasWindowing_ = true;
     windowingCenter_ = center;
     windowingWidth_ = width;
+
+    EmitMessage(RadiographyScene::WindowingChangedMessage(*this));
   }
 
 
@@ -254,7 +261,7 @@
                                                const std::string& utf8,
                                                RadiographyLayer::Geometry* geometry)
   {
-    std::auto_ptr<RadiographyTextLayer>  alpha(new RadiographyTextLayer(*this));
+    std::auto_ptr<RadiographyTextLayer>  alpha(new RadiographyTextLayer(IObservable::GetBroker(), *this));
     alpha->LoadText(font, utf8);
     if (geometry != NULL)
     {
@@ -298,7 +305,7 @@
                                                float foreground,
                                                RadiographyLayer::Geometry* geometry)
   {
-    std::auto_ptr<RadiographyMaskLayer>  mask(new RadiographyMaskLayer(*this, dicomLayer, foreground));
+    std::auto_ptr<RadiographyMaskLayer>  mask(new RadiographyMaskLayer(IObservable::GetBroker(), *this, dicomLayer, foreground));
     mask->SetCorners(corners);
     if (geometry != NULL)
     {
@@ -311,7 +318,7 @@
 
   RadiographyLayer& RadiographyScene::LoadAlphaBitmap(Orthanc::ImageAccessor* bitmap, RadiographyLayer::Geometry *geometry)
   {
-    std::auto_ptr<RadiographyAlphaLayer>  alpha(new RadiographyAlphaLayer(*this));
+    std::auto_ptr<RadiographyAlphaLayer>  alpha(new RadiographyAlphaLayer(IObservable::GetBroker(), *this));
     alpha->SetAlpha(bitmap);
     if (geometry != NULL)
     {
@@ -327,7 +334,7 @@
                                                      bool httpCompression,
                                                      RadiographyLayer::Geometry* geometry)
   {
-    RadiographyDicomLayer& layer = dynamic_cast<RadiographyDicomLayer&>(RegisterLayer(new RadiographyDicomLayer));
+    RadiographyDicomLayer& layer = dynamic_cast<RadiographyDicomLayer&>(RegisterLayer(new RadiographyDicomLayer(IObservable::GetBroker(), *this)));
     layer.SetInstance(instance, frame);
 
     if (geometry != NULL)
@@ -371,7 +378,7 @@
 
   RadiographyLayer& RadiographyScene::LoadDicomWebFrame(IWebService& web)
   {
-    RadiographyLayer& layer = RegisterLayer(new RadiographyDicomLayer);
+    RadiographyLayer& layer = RegisterLayer(new RadiographyDicomLayer(IObservable::GetBroker(), *this));
 
 
     return layer;
--- a/Framework/Radiography/RadiographyScene.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.h	Tue Feb 26 12:58:03 2019 +0100
@@ -37,7 +37,7 @@
   {
   public:
     class GeometryChangedMessage :
-        public OriginMessage<MessageType_Scene_GeometryChanged, RadiographyScene>
+        public OriginMessage<MessageType_RadiographyScene_GeometryChanged, RadiographyScene>
     {
     private:
       RadiographyLayer&        layer_;
@@ -57,7 +57,7 @@
     };
 
     class ContentChangedMessage :
-        public OriginMessage<MessageType_Scene_ContentChanged, RadiographyScene>
+        public OriginMessage<MessageType_RadiographyScene_ContentChanged, RadiographyScene>
     {
     private:
       RadiographyLayer&        layer_;
@@ -76,6 +76,37 @@
       }
     };
 
+    class LayerEditedMessage :
+        public OriginMessage<MessageType_RadiographyScene_LayerEdited, RadiographyScene>
+    {
+    private:
+      const RadiographyLayer&        layer_;
+
+    public:
+      LayerEditedMessage(const RadiographyScene& origin,
+                         const RadiographyLayer& layer) :
+        OriginMessage(origin),
+        layer_(layer)
+      {
+      }
+
+      const RadiographyLayer& GetLayer() const
+      {
+        return layer_;
+      }
+
+    };
+
+    class WindowingChangedMessage :
+        public OriginMessage<MessageType_RadiographyScene_WindowingChanged, RadiographyScene>
+    {
+
+    public:
+      WindowingChangedMessage(const RadiographyScene& origin) :
+        OriginMessage(origin)
+      {
+      }
+    };
 
     class LayerAccessor : public boost::noncopyable
     {
@@ -130,6 +161,7 @@
 
     void OnDicomWebReceived(const IWebService::HttpRequestSuccessMessage& message);
 
+    void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message);
   public:
     RadiographyScene(MessageBroker& broker);
     
@@ -198,6 +230,30 @@
       return NULL;
     }
 
+    template <typename TypeLayer>
+    const TypeLayer* GetLayer(size_t index = 0) const
+    {
+      std::vector<size_t> layerIndexes;
+      GetLayersIndexes(layerIndexes);
+
+      size_t count = 0;
+
+      for (size_t i = 0; i < layerIndexes.size(); ++i)
+      {
+        const TypeLayer* typedLayer = dynamic_cast<const TypeLayer*>(layers_.at(layerIndexes[i]));
+        if (typedLayer != NULL)
+        {
+          if (count == index)
+          {
+            return typedLayer;
+          }
+          count++;
+        }
+      }
+
+      return NULL;
+    }
+
     void GetLayersIndexes(std::vector<size_t>& output) const;
 
     Extent2D GetSceneExtent() const;
--- a/Framework/Radiography/RadiographyTextLayer.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/Radiography/RadiographyTextLayer.h	Tue Feb 26 12:58:03 2019 +0100
@@ -34,8 +34,8 @@
     std::string                fontName_;
 
   public:
-    RadiographyTextLayer(const RadiographyScene& scene) :
-      RadiographyAlphaLayer(scene)
+    RadiographyTextLayer(MessageBroker& broker, const RadiographyScene& scene) :
+      RadiographyAlphaLayer(broker, scene)
     {
     }
 
--- a/Framework/StoneEnumerations.h	Mon Feb 25 17:57:37 2019 +0100
+++ b/Framework/StoneEnumerations.h	Tue Feb 26 12:58:03 2019 +0100
@@ -157,8 +157,12 @@
     MessageType_OrthancApi_GenericHttpError_Ready,
     MessageType_OrthancApi_GenericEmptyResponse_Ready,
 
-    MessageType_Scene_GeometryChanged,
-    MessageType_Scene_ContentChanged,
+    MessageType_RadiographyScene_GeometryChanged,
+    MessageType_RadiographyScene_ContentChanged,
+    MessageType_RadiographyScene_LayerEdited,
+    MessageType_RadiographyScene_WindowingChanged,
+
+    MessageType_RadiographyLayer_Edited,
 
     MessageType_ViewportChanged,