changeset 96:f8bce1bebe01 wasm

removal of the NotifyLayerError callback
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 May 2017 10:30:57 +0200
parents f47349f4815c
children d18dcc963930
files Applications/Samples/SingleFrameApplication.h Framework/Layers/ILayerSource.h Framework/Layers/LayerSourceBase.cpp Framework/Layers/LayerSourceBase.h Framework/Layers/OrthancFrameLayerSource.cpp Framework/Widgets/LayerWidget.cpp Framework/Widgets/LayerWidget.h
diffstat 7 files changed, 36 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameApplication.h	Tue May 30 10:12:54 2017 +0200
+++ b/Applications/Samples/SingleFrameApplication.h	Tue May 30 10:30:57 2017 +0200
@@ -123,12 +123,8 @@
  
       virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer,
                                     const ILayerSource& source,
-                                    const Slice& slice)
-      {
-      }
-
-      virtual void NotifyLayerError(const ILayerSource& source,
-                                    const SliceGeometry& slice)
+                                    const Slice& slice,
+                                    bool isError)
       {
       }
 
--- a/Framework/Layers/ILayerSource.h	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Layers/ILayerSource.h	Tue May 30 10:30:57 2017 +0200
@@ -51,15 +51,12 @@
       virtual void NotifySliceChange(const ILayerSource& source,
                                      const Slice& slice) = 0;
  
-      // The layer must be deleted by the observer. "layer" will never
-      // be "NULL", otherwise "NotifyLayerError()" would have been
-      // called.
+      // The layer must be deleted by the observer that releases the
+      // std::auto_ptr
       virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer,
                                     const ILayerSource& source,
-                                    const Slice& slice) = 0;
-
-      virtual void NotifyLayerError(const ILayerSource& source,
-                                    const SliceGeometry& slice) = 0;
+                                    const Slice& slice,
+                                    bool isError) = 0;
     };
     
     virtual ~ILayerSource()
--- a/Framework/Layers/LayerSourceBase.cpp	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Layers/LayerSourceBase.cpp	Tue May 30 10:30:57 2017 +0200
@@ -32,23 +32,22 @@
     private:
       std::auto_ptr<ILayerRenderer>  layer_;
       const Slice&                   slice_;
+      bool                           isError_;
       
     public:
       LayerReadyFunctor(ILayerRenderer* layer,
-                        const Slice& slice) :
+                        const Slice& slice,
+                        bool isError) :
         layer_(layer),
-        slice_(slice)
+        slice_(slice),
+        isError_(isError)
       {
-        if (layer == NULL)
-        {
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
-        }
       }
 
       void operator() (ILayerSource::IObserver& observer,
                        const ILayerSource& source)
       {
-        observer.NotifyLayerReady(layer_, source, slice_);
+        observer.NotifyLayerReady(layer_, source, slice_, isError_);
       }
     };
   }
@@ -74,17 +73,13 @@
   }
 
   void LayerSourceBase::NotifyLayerReady(ILayerRenderer* layer,
-                                         const Slice& slice)
+                                         const Slice& slice,
+                                         bool isError)
   {
-    LayerReadyFunctor functor(layer, slice);
+    LayerReadyFunctor functor(layer, slice, isError);
     observers_.Notify(*this, functor);
   }
 
-  void LayerSourceBase::NotifyLayerError(const SliceGeometry& slice)
-  {
-    observers_.Apply(*this, &IObserver::NotifyLayerError, slice);
-  }
-
   void LayerSourceBase::Register(IObserver& observer)
   {
     observers_.Register(observer);
--- a/Framework/Layers/LayerSourceBase.h	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Layers/LayerSourceBase.h	Tue May 30 10:30:57 2017 +0200
@@ -43,9 +43,8 @@
     void NotifySliceChange(const Slice& slice);
 
     void NotifyLayerReady(ILayerRenderer* layer,
-                          const Slice& slice);
-    
-    void NotifyLayerError(const SliceGeometry& slice);
+                          const Slice& slice,
+                          bool isError);
 
   public:
     virtual void Register(IObserver& observer);
--- a/Framework/Layers/OrthancFrameLayerSource.cpp	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Layers/OrthancFrameLayerSource.cpp	Tue May 30 10:30:57 2017 +0200
@@ -55,7 +55,7 @@
                                                       SliceImageQuality quality)
   {
     bool isFull = (quality == SliceImageQuality_Full);
-    LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(image, slice, isFull), slice);
+    LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(image, slice, isFull), slice, false);
   }
 
   void OrthancFrameLayerSource::NotifySliceImageError(const OrthancSlicesLoader& loader,
@@ -63,7 +63,7 @@
                                                       const Slice& slice,
                                                       SliceImageQuality quality)
   {
-    LayerSourceBase::NotifyLayerError(slice.GetGeometry());
+    LayerSourceBase::NotifyLayerReady(NULL, slice, true);
   }
 
   OrthancFrameLayerSource::OrthancFrameLayerSource(IWebService& orthanc,
@@ -130,7 +130,8 @@
       }
       else
       {
-        LayerSourceBase::NotifyLayerError(viewportSlice);
+        Slice slice;
+        LayerSourceBase::NotifyLayerReady(NULL, slice, true);
       }
     }
   }
--- a/Framework/Widgets/LayerWidget.cpp	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Widgets/LayerWidget.cpp	Tue May 30 10:30:57 2017 +0200
@@ -481,36 +481,24 @@
   
   void LayerWidget::NotifyLayerReady(std::auto_ptr<ILayerRenderer>& renderer,
                                      const ILayerSource& source,
-                                     const Slice& slice)
+                                     const Slice& slice,
+                                     bool isError)
   {
     size_t index;
-    if (LookupLayer(index, source) &&
+    if (renderer.get() != NULL &&
+        LookupLayer(index, source) &&
         slice.ContainsPlane(slice_))  // Whether the slice comes from an older request
     {
-      LOG(INFO) << "Renderer ready for layer " << index;
+      if (isError)
+      {
+        LOG(ERROR) << "Using error renderer on layer " << index;
+      }
+      else
+      {
+        LOG(INFO) << "Renderer ready for layer " << index;
+      }
+      
       UpdateLayer(index, renderer.release(), slice);
     }
   }
-
-  
-  void LayerWidget::NotifyLayerError(const ILayerSource& source,
-                                     const SliceGeometry& slice)
-  {
-    size_t index;
-
-    Slice expected(slice_, THIN_SLICE_THICKNESS);
-
-    if (LookupLayer(index, source) &&
-        expected.ContainsPlane(slice))  // Whether the slice comes from an older request
-    {
-      LOG(INFO) << "Unable to load a slice from layer " << index;
-
-      double x1, y1, x2, y2;
-      if (GetAndFixExtent(x1, y1, x2, y2, *layers_[index]))
-      {
-        printf("**%d** %f %f %f %f\n", index, x1, y1, x2, y2);
-        UpdateLayer(index, new MissingLayerRenderer(x1, y1, x2, y2), Slice(slice, THIN_SLICE_THICKNESS));
-      }
-    }
-  }    
 }
--- a/Framework/Widgets/LayerWidget.h	Tue May 30 10:12:54 2017 +0200
+++ b/Framework/Widgets/LayerWidget.h	Tue May 30 10:30:57 2017 +0200
@@ -66,10 +66,8 @@
 
     virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& renderer,
                                   const ILayerSource& source,
-                                  const Slice& slice);
-
-    virtual void NotifyLayerError(const ILayerSource& source,
-                                  const SliceGeometry& slice);
+                                  const Slice& slice,
+                                  bool isError);
 
         
   protected: