changeset 1272:a989c7d46b9a

options to avoid multiple LayerEditedMessage
author Alain Mazy <alain@mazy.be>
date Mon, 03 Feb 2020 14:56:56 +0100
parents 69177b10e2b9
children 398ea4259e65
files Framework/Radiography/RadiographyDicomLayer.cpp Framework/Radiography/RadiographyDicomLayer.h Framework/Radiography/RadiographyLayer.cpp Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h
diffstat 6 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyDicomLayer.cpp	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyDicomLayer.cpp	Mon Feb 03 14:56:56 2020 +0100
@@ -112,7 +112,7 @@
     BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
-  void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY)   // Takes ownership
+  void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY, bool emitLayerEditedEvent)   // Takes ownership
   {
     std::auto_ptr<Orthanc::ImageAccessor> raii(image);
 
@@ -121,14 +121,17 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
 
-    SetSize(image->GetWidth(), image->GetHeight());
+    SetSize(image->GetWidth(), image->GetHeight(), false);
 
     source_ = raii;
     ApplyConverter();
 
     SetPixelSpacing(newPixelSpacingX, newPixelSpacingY, false);
 
-    BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
+    if (emitLayerEditedEvent)
+    {
+      BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
+    }
   }
 
 
--- a/Framework/Radiography/RadiographyDicomLayer.h	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyDicomLayer.h	Mon Feb 03 14:56:56 2020 +0100
@@ -80,7 +80,7 @@
 
     void SetSourceImage(Orthanc::ImageAccessor* image);   // Takes ownership
 
-    void SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY);   // Takes ownership
+    void SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY, bool emitLayerEditedEvent = true);   // Takes ownership
 
     const Orthanc::ImageAccessor* GetSourceImage() const {return source_.get();}  // currently need this access to serialize scene in plain old data to send to a WASM worker
 
--- a/Framework/Radiography/RadiographyLayer.cpp	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyLayer.cpp	Mon Feb 03 14:56:56 2020 +0100
@@ -223,14 +223,19 @@
   }
 
   void RadiographyLayer::SetSize(unsigned int width,
-                                 unsigned int height)
+                                 unsigned int height,
+                                 bool emitLayerEditedEvent)
   {
     hasSize_ = true;
     width_ = width;
     height_ = height;
 
     UpdateTransform();
-    BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
+
+    if (emitLayerEditedEvent)
+    {
+      BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
+    }
   }
 
 
--- a/Framework/Radiography/RadiographyLayer.h	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyLayer.h	Mon Feb 03 14:56:56 2020 +0100
@@ -298,7 +298,8 @@
     }
 
     void SetSize(unsigned int width,
-                 unsigned int height);
+                 unsigned int height,
+                 bool emitLayerEditedEvent = true);
 
     bool HasSize() const
     {
--- a/Framework/Radiography/RadiographyScene.cpp	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Mon Feb 03 14:56:56 2020 +0100
@@ -229,6 +229,8 @@
       
       LOG(INFO) << "Removing layer, there are now : " << layers_.size() << " layers";
 
+      _OnLayerRemoved();
+
       BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex));
     }
   }
--- a/Framework/Radiography/RadiographyScene.h	Tue Jan 21 16:52:37 2020 +0100
+++ b/Framework/Radiography/RadiographyScene.h	Mon Feb 03 14:56:56 2020 +0100
@@ -173,6 +173,7 @@
 
   protected:
     virtual void _RegisterLayer(RadiographyLayer* layer);
+    virtual void _OnLayerRemoved() {}
 
     void SetLayerIndex(RadiographyLayer* layer, size_t index)
     {