diff Framework/Widgets/LayerWidget.cpp @ 219:26e3bfe30e66 am

ReplaceLayer()
author am@osimis.io
date Fri, 08 Jun 2018 14:41:45 +0200
parents 5412adf19980
children 3d523c9a8f0d 192e6e349e69
line wrap: on
line diff
--- a/Framework/Widgets/LayerWidget.cpp	Thu Jun 07 17:03:47 2018 +0200
+++ b/Framework/Widgets/LayerWidget.cpp	Fri Jun 08 14:41:45 2018 +0200
@@ -395,7 +395,29 @@
     return index;
   }
 
-  
+  void LayerWidget::ReplaceLayer(size_t index, ILayerSource* layer)  // Takes ownership
+  {
+    if (layer == NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
+    }
+
+    if (index >= layers_.size())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+
+    delete layers_[index];
+    layers_[index] = layer;
+    layersIndex_[layer] = index;
+
+    ResetPendingScene();
+    layer->Register(*this);
+
+    InvalidateLayer(index);
+  }
+
+
   const RenderStyle& LayerWidget::GetLayerStyle(size_t layer) const
   {
     if (layer >= layers_.size())