changeset 1131:4663f158c748

RadiographyWidget is now notified when a layer is removed from the scene
author Alain Mazy <alain@mazy.be>
date Wed, 06 Nov 2019 10:46:46 +0100
parents 6bc766eab0de
children 58799b7317fa
files Framework/Deprecated/Viewport/WidgetViewport.cpp Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyWidget.cpp Framework/Radiography/RadiographyWidget.h
diffstat 5 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Deprecated/Viewport/WidgetViewport.cpp	Mon Nov 04 22:16:33 2019 +0100
+++ b/Framework/Deprecated/Viewport/WidgetViewport.cpp	Wed Nov 06 10:46:46 2019 +0100
@@ -116,7 +116,7 @@
     {
       return false;
     }
-
+    
     if (background.GetWidth() != surface.GetWidth() ||
         background.GetHeight() != surface.GetHeight())
     {
--- a/Framework/Radiography/RadiographyScene.cpp	Mon Nov 04 22:16:33 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Wed Nov 06 10:46:46 2019 +0100
@@ -224,6 +224,8 @@
       countLayers_--;
       
       LOG(INFO) << "Removing layer, there are now : " << countLayers_ << " layers";
+
+      BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex));
     }
   }
 
--- a/Framework/Radiography/RadiographyScene.h	Mon Nov 04 22:16:33 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.h	Wed Nov 06 10:46:46 2019 +0100
@@ -100,6 +100,27 @@
       }
     };
 
+    class LayerRemovedMessage : public OriginMessage<RadiographyScene>
+    {
+      ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
+
+    private:
+      size_t&        layerIndex_;
+
+    public:
+      LayerRemovedMessage(const RadiographyScene& origin,
+                          size_t& layerIndex) :
+        OriginMessage(origin),
+        layerIndex_(layerIndex)
+      {
+      }
+
+      size_t& GetLayerIndex() const
+      {
+        return layerIndex_;
+      }
+    };
+
 
     ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, WindowingChangedMessage, RadiographyScene);
 
--- a/Framework/Radiography/RadiographyWidget.cpp	Mon Nov 04 22:16:33 2019 +0100
+++ b/Framework/Radiography/RadiographyWidget.cpp	Wed Nov 06 10:46:46 2019 +0100
@@ -201,6 +201,11 @@
     selectedLayer_ = layer;
   }
 
+  void RadiographyWidget::ClearSelectedLayer()
+  {
+    hasSelection_ = false;
+  }
+
   bool RadiographyWidget::SelectMaskLayer(size_t index)
   {
     std::vector<size_t> layerIndexes;
@@ -251,6 +256,14 @@
     NotifyContentChanged();
   }
 
+  void RadiographyWidget::OnLayerRemoved(const RadiographyScene::LayerRemovedMessage& message)
+  {
+    size_t removedLayerIndex = message.GetLayerIndex();
+    if (hasSelection_ && selectedLayer_ == removedLayerIndex)
+    {
+      ClearSelectedLayer();
+    }
+  }
   
   void RadiographyWidget::SetInvert(bool invert)
   {
@@ -262,7 +275,7 @@
   }
 
   
-  void RadiographyWidget::SwitchInvert()
+    void RadiographyWidget::SwitchInvert()
   {
     invert_ = !invert_;
     NotifyContentChanged();
@@ -295,6 +308,10 @@
           new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage>
           (*this, &RadiographyWidget::OnContentChanged));
 
+    scene_->RegisterObserverCallback(
+          new Callable<RadiographyWidget, RadiographyScene::LayerRemovedMessage>
+          (*this, &RadiographyWidget::OnLayerRemoved));
+
     NotifyContentChanged();
 
     // force redraw
--- a/Framework/Radiography/RadiographyWidget.h	Mon Nov 04 22:16:33 2019 +0100
+++ b/Framework/Radiography/RadiographyWidget.h	Wed Nov 06 10:46:46 2019 +0100
@@ -78,6 +78,8 @@
 
     void Select(size_t layer);
 
+    void ClearSelectedLayer();
+
     bool SelectMaskLayer(size_t index = 0);
 
     bool LookupSelectedLayer(size_t& layer);
@@ -86,6 +88,8 @@
 
     void OnContentChanged(const RadiographyScene::ContentChangedMessage& message);
 
+    void OnLayerRemoved(const RadiographyScene::LayerRemovedMessage& message);
+
     void SetInvert(bool invert);
 
     void SwitchInvert();