changeset 329:b10dfdb96866 am-2

removing WorldSceneWidget::IWorldObserver
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Oct 2018 12:30:32 +0200
parents c80b5bddf86b
children 7a364e44fbb4
files Applications/Samples/SingleFrameEditorApplication.h Framework/Layers/OrthancFrameLayerSource.cpp Framework/Widgets/LayerWidget.cpp Framework/Widgets/WorldSceneWidget.cpp Framework/Widgets/WorldSceneWidget.h
diffstat 5 files changed, 15 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h	Wed Oct 17 10:26:33 2018 +0200
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Wed Oct 17 12:30:32 2018 +0200
@@ -72,9 +72,11 @@
                                                             IStatusBar* statusBar)
         {
           switch (application_.currentTool_) {
-          case Tools_Crop:
+          case Tools_Zoom:
+            printf("ZOOM\n");
+
+            case Tools_Crop:
           case Tools_Windowing:
-          case Tools_Zoom:
           case Tools_Pan:
             // TODO return the right mouse tracker
             return NULL;
@@ -97,7 +99,7 @@
             char buf[64];
             sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)",
                     p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
-            statusBar->SetMessage(buf);
+            //statusBar->SetMessage(buf);
           }
         }
 
@@ -149,8 +151,9 @@
         }
       };
 
-      void OnMainWidgetGeometryReady(const ILayerSource::GeometryReadyMessage& message)
+      void OnGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
       {
+        mainWidget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
         mainWidget_->SetDefaultView();
       }
       
@@ -208,7 +211,7 @@
         std::auto_ptr<OrthancFrameLayerSource> layer(new OrthancFrameLayerSource(broker_, *orthancApiClient_));
         source_ = layer.get();
         layer->LoadFrame(instance, frame);
-        layer->RegisterObserverCallback(new Callable<SingleFrameEditorApplication, ILayerSource::GeometryReadyMessage>(*this, &SingleFrameEditorApplication::OnMainWidgetGeometryReady));
+        mainWidget_->RegisterObserverCallback(new Callable<SingleFrameEditorApplication, LayerWidget::GeometryChangedMessage>(*this, &SingleFrameEditorApplication::OnGeometryChanged));
         mainWidget_->AddLayer(layer.release());
 
         mainWidget_->SetTransmitMouseOver(true);
--- a/Framework/Layers/OrthancFrameLayerSource.cpp	Wed Oct 17 10:26:33 2018 +0200
+++ b/Framework/Layers/OrthancFrameLayerSource.cpp	Wed Oct 17 12:30:32 2018 +0200
@@ -105,6 +105,7 @@
                                           const CoordinateSystem3D& viewportSlice)
   {
     size_t index;
+
     if (loader_.IsGeometryReady() &&
         loader_.LookupSlice(index, viewportSlice))
     {
@@ -122,17 +123,10 @@
   {
     size_t index;
 
-    if (loader_.IsGeometryReady())
+    if (loader_.IsGeometryReady() &&
+        loader_.LookupSlice(index, viewportSlice))
     {
-      if (loader_.LookupSlice(index, viewportSlice))
-      {
-        loader_.ScheduleLoadSliceImage(index, quality_);
-      }
-      else
-      {
-        Slice slice;
-        LayerSourceBase::NotifyLayerReady(NULL, slice.GetGeometry(), true);
-      }
+      loader_.ScheduleLoadSliceImage(index, quality_);
     }
   }
 }
--- a/Framework/Widgets/LayerWidget.cpp	Wed Oct 17 10:26:33 2018 +0200
+++ b/Framework/Widgets/LayerWidget.cpp	Wed Oct 17 12:30:32 2018 +0200
@@ -255,7 +255,7 @@
                                    ILayerSource& source) const
   {
     extent.Reset();
-    
+
     std::vector<Vector> points;
     if (source.GetExtent(points, slice_))
     {
--- a/Framework/Widgets/WorldSceneWidget.cpp	Wed Oct 17 10:26:33 2018 +0200
+++ b/Framework/Widgets/WorldSceneWidget.cpp	Wed Oct 17 12:30:32 2018 +0200
@@ -43,23 +43,6 @@
   }
 
 
-  struct WorldSceneWidget::SizeChangeFunctor
-  {
-    ViewportGeometry& view_;
-
-    SizeChangeFunctor(ViewportGeometry& view) :
-      view_(view)
-    {
-    }
-
-    void operator() (IWorldObserver& observer,
-                     const WorldSceneWidget& source)
-    {
-      observer.NotifySizeChange(source, view_);
-    }
-  };
-
-
   // this is an adapter between a IWorldSceneMouseTracker
   // that is tracking a mouse in scene coordinates/mm and
   // an IMouseTracker that is tracking a mouse
@@ -112,14 +95,14 @@
     that_.view_.GetPan(previousPanX_, previousPanY_);
   }
 
+  
   void WorldSceneWidget::PanMouseTracker::MouseMove(int x, int y)
   {
     that_.view_.SetPan(previousPanX_ + x - downX_,
                        previousPanY_ + y - downY_);
-
-    that_.observers_.Apply(that_, &IWorldObserver::NotifyViewChange, that_.view_);
   }
 
+  
   WorldSceneWidget::ZoomMouseTracker::ZoomMouseTracker(WorldSceneWidget&  that,
                                                        int x,
                                                        int y) :
@@ -174,8 +157,6 @@
     that_.view_.MapSceneToDisplay(tx, ty, centerX_, centerY_);
     that_.view_.SetPan(panX + static_cast<double>(downX_ - tx),
                        panY + static_cast<double>(downY_ - ty));
-
-    that_.observers_.Apply(that_, &IWorldObserver::NotifyViewChange, that_.view_);
   }
 
 
@@ -209,20 +190,7 @@
                                  unsigned int height)
   {
     CairoWidget::SetSize(width, height);
-
     view_.SetDisplaySize(width, height);
-
-    if (observers_.IsEmpty())
-    {
-      // Without a size observer, reset to the default view
-      // view_.SetDefaultView();
-    }
-    else
-    {
-      // With a size observer, let it decide which view to use
-      SizeChangeFunctor functor(view_);
-      observers_.Notify(*this, functor);
-    }
   }
 
 
@@ -238,8 +206,6 @@
     view_.SetDefaultView();
 
     NotifyContentChanged();
-
-    observers_.Apply(*this, &IWorldObserver::NotifyViewChange, view_);
   }
 
 
@@ -248,8 +214,6 @@
     view_ = view;
 
     NotifyContentChanged();
-
-    observers_.Apply(*this, &IWorldObserver::NotifyViewChange, view_);
   }
 
 
--- a/Framework/Widgets/WorldSceneWidget.h	Wed Oct 17 10:26:33 2018 +0200
+++ b/Framework/Widgets/WorldSceneWidget.h	Wed Oct 17 12:30:32 2018 +0200
@@ -32,20 +32,6 @@
   class WorldSceneWidget : public CairoWidget
   {
   public:
-    class IWorldObserver : public boost::noncopyable
-    {
-    public:
-      virtual ~IWorldObserver()
-      {
-      }
-
-      virtual void NotifySizeChange(const WorldSceneWidget& source,
-                                    ViewportGeometry& view) = 0;  // Can be tuned by the observer
-
-      virtual void NotifyViewChange(const WorldSceneWidget& source,
-                                    const ViewportGeometry& view) = 0;
-    };
-
     class PanMouseTracker : public IMouseTracker
     {
     private:
@@ -90,10 +76,7 @@
 
     class SceneMouseTracker;
 
-    typedef ObserversRegistry<WorldSceneWidget, IWorldObserver>  Observers;
-
     ViewportGeometry       view_;
-    Observers              observers_;
     IWorldSceneInteractor* interactor_;
 
   public:
@@ -118,16 +101,6 @@
     {
     }
 
-    void Register(IWorldObserver& observer)
-    {
-      observers_.Register(observer);
-    }
-
-    void Unregister(IWorldObserver& observer)
-    {
-      observers_.Unregister(observer);
-    }
-
     virtual void SetSize(unsigned int width,
                          unsigned int height);