changeset 48:25befef48c35 wasm

integration mainline->wasm
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Apr 2017 11:01:48 +0200
parents 766d31dc5716 (diff) 28956ed68280 (current diff)
children 369fe11606fa
files Framework/Viewport/IViewport.h Framework/Viewport/WidgetViewport.cpp Framework/Viewport/WidgetViewport.h Framework/Widgets/EmptyWidget.cpp Framework/Widgets/EmptyWidget.h Framework/Widgets/IWidget.h Framework/Widgets/LayeredSceneWidget.cpp Framework/Widgets/LayeredSceneWidget.h Framework/Widgets/LayoutWidget.cpp Framework/Widgets/LayoutWidget.h Framework/Widgets/TestCairoWidget.cpp Framework/Widgets/TestCairoWidget.h Framework/Widgets/TestWorldSceneWidget.cpp Framework/Widgets/TestWorldSceneWidget.h Framework/Widgets/WidgetBase.cpp Framework/Widgets/WidgetBase.h Framework/Widgets/WorldSceneWidget.cpp Framework/Widgets/WorldSceneWidget.h
diffstat 18 files changed, 165 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Viewport/IViewport.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Viewport/IViewport.h	Thu Apr 27 11:01:48 2017 +0200
@@ -82,5 +82,9 @@
 
     virtual void KeyPressed(char key,
                             KeyboardModifiers modifiers) = 0;
+
+    virtual bool HasUpdateContent() = 0;
+
+    virtual void UpdateContent() = 0;
   };
 }
--- a/Framework/Viewport/WidgetViewport.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Viewport/WidgetViewport.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -166,18 +166,23 @@
     {
       return false;
     }
+    
+    Orthanc::ImageAccessor background = background_.GetAccessor();
 
-    if (backgroundChanged_)
+    if (backgroundChanged_ &&
+        !centralWidget_->Render(background))
     {
-      Orthanc::ImageAccessor accessor = background_.GetAccessor();
-      if (!centralWidget_->Render(accessor))
-      {
-        return false;
-      }
+      return false;
     }
 
-    Orthanc::ImageProcessing::Copy(surface, background_.GetAccessor());
+    if (background.GetWidth() != surface.GetWidth() ||
+        background.GetHeight() != surface.GetHeight())
+    {
+      return false;
+    }
 
+    Orthanc::ImageProcessing::Convert(surface, background);
+    
     if (mouseTracker_.get() != NULL)
     {
       mouseTracker_->Render(surface);
@@ -272,6 +277,14 @@
   {
     boost::mutex::scoped_lock lock(mutex_);
     isMouseOver_ = false;
+
+    if (started_ &&
+        mouseTracker_.get() != NULL)
+    {
+      mouseTracker_->MouseUp();
+      mouseTracker_.reset(NULL);
+    }
+
     observers_.NotifyChange(this);
   }
 
@@ -307,4 +320,30 @@
       centralWidget_->KeyPressed(key, modifiers);
     }
   }
+
+
+  bool WidgetViewport::HasUpdateContent()
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    if (centralWidget_.get() != NULL)
+    {
+      return centralWidget_->HasUpdateContent();
+    }
+    else
+    {
+      return false;
+    }
+  }
+   
+
+  void WidgetViewport::UpdateContent()
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    if (centralWidget_.get() != NULL)
+    {
+      centralWidget_->UpdateContent();
+    }
+  }
 }
--- a/Framework/Viewport/WidgetViewport.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Viewport/WidgetViewport.h	Thu Apr 27 11:01:48 2017 +0200
@@ -102,5 +102,9 @@
 
     virtual void KeyPressed(char key,
                             KeyboardModifiers modifiers);
+
+    virtual bool HasUpdateContent();
+
+    virtual void UpdateContent();
   };
 }
--- a/Framework/Widgets/EmptyWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/EmptyWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -31,4 +31,10 @@
     Orthanc::ImageProcessing::Set(surface, red_, green_, blue_, 255);
     return true;
   }
+
+  
+  void EmptyWidget::UpdateContent()
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+  }
 }
--- a/Framework/Widgets/EmptyWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/EmptyWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -102,5 +102,12 @@
                             KeyboardModifiers modifiers)
     {
     }
+
+    virtual bool HasUpdateContent() const
+    {
+      return false;
+    }
+
+    virtual void UpdateContent();
   };
 }
--- a/Framework/Widgets/IWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/IWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -73,5 +73,9 @@
 
     virtual void KeyPressed(char key,
                             KeyboardModifiers modifiers) = 0;
+
+    virtual bool HasUpdateContent() const = 0;
+
+    virtual void UpdateContent() = 0;
   };
 }
--- a/Framework/Widgets/LayeredSceneWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/LayeredSceneWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -357,7 +357,7 @@
   }
 
 
-  void LayeredSceneWidget::UpdateStep()
+  void LayeredSceneWidget::UpdateContent()
   {
     size_t layer = 0;
     bool isLast = true;
--- a/Framework/Widgets/LayeredSceneWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/LayeredSceneWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -60,13 +60,6 @@
     Observers                     observers_;
 
   protected:
-    virtual bool HasUpdateThread() const
-    {
-      return true;
-    }
-
-    virtual void UpdateStep();
-
     virtual bool RenderScene(CairoContext& context,
                              const ViewportGeometry& view);
 
@@ -120,5 +113,12 @@
     {
       observers_.Unregister(observer);
     }
+
+    virtual bool HasUpdateContent() const
+    {
+      return true;
+    }
+
+    virtual void UpdateContent();
   };
 }
--- a/Framework/Widgets/LayoutWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/LayoutWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -252,12 +252,6 @@
   }
 
 
-  void LayoutWidget::UpdateStep()
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-  }
-
-
   LayoutWidget::LayoutWidget() :
     isHorizontal_(true),
     started_(false),
--- a/Framework/Widgets/LayoutWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/LayoutWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -48,15 +48,6 @@
 
     void ComputeChildrenExtents();
 
-  protected:
-    virtual bool HasUpdateThread() const 
-    {
-      return false;
-    }
-
-    virtual void UpdateStep();
-
-
   public:
     LayoutWidget();
 
--- a/Framework/Widgets/TestCairoWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/TestCairoWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -21,8 +21,6 @@
 
 #include "TestCairoWidget.h"
 
-#include "../../Resources/Orthanc/Core/SystemToolbox.h"
-
 #include <stdio.h>
 
 
@@ -30,7 +28,7 @@
 {
   namespace Samples
   {
-    void TestCairoWidget::UpdateStep() 
+    void TestCairoWidget::UpdateContent() 
     {
       value_ -= 0.01f;
       if (value_ < 0)
@@ -39,8 +37,6 @@
       }
 
       NotifyChange();
-
-      Orthanc::SystemToolbox::USleep(25000);
     }
 
 
--- a/Framework/Widgets/TestCairoWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/TestCairoWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -35,13 +35,6 @@
       float         value_;
       bool          animate_;
 
-      virtual bool HasUpdateThread() const
-      {
-        return animate_;
-      }
-
-      virtual void UpdateStep();
-
     protected:
       virtual bool RenderCairo(CairoContext& context);
 
@@ -67,6 +60,13 @@
     
       virtual void KeyPressed(char key,
                               KeyboardModifiers modifiers);
+
+      virtual bool HasUpdateContent() const
+      {
+        return animate_;
+      }
+      
+      virtual void UpdateContent();
     };
   }
 }
--- a/Framework/Widgets/TestWorldSceneWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/TestWorldSceneWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -94,7 +94,7 @@
 
 
     bool TestWorldSceneWidget::RenderScene(CairoContext& context,
-                                           const ViewportGeometry& view)
+                                           const ViewportGeometry& view) 
     {
       cairo_t* cr = context.GetObject();
 
@@ -102,7 +102,8 @@
       cairo_set_source_rgb(cr, 0, 0, 0);
       cairo_paint(cr);
 
-      cairo_set_source_rgb(cr, 0, 1, 0);
+      float color = static_cast<float>(count_ % 16) / 15.0f;
+      cairo_set_source_rgb(cr, 0, 1.0f - color, color);
       cairo_rectangle(cr, -10, -.5, 20, 1);
       cairo_fill(cr);
 
@@ -110,8 +111,10 @@
     }
 
 
-    TestWorldSceneWidget::TestWorldSceneWidget() :
-      interactor_(new Interactor)
+    TestWorldSceneWidget::TestWorldSceneWidget(bool animate) :
+      interactor_(new Interactor),
+      animate_(animate),
+      count_(0)
     {
       SetInteractor(*interactor_);
     }
@@ -127,5 +130,19 @@
       y1 = -.5;
       y2 = .5;
     }
+
+
+    void TestWorldSceneWidget::UpdateContent()
+    {
+      if (animate_)
+      {
+        count_++;
+        NotifyChange();
+      }
+      else
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+      }
+    }
   }
 }
--- a/Framework/Widgets/TestWorldSceneWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/TestWorldSceneWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -33,23 +33,27 @@
       class Interactor;
 
       std::auto_ptr<Interactor>   interactor_;
+      bool                        animate_;
+      unsigned int                count_;
 
     protected:
-      virtual SliceGeometry GetSlice()
-      {
-        return SliceGeometry();
-      }
-
       virtual bool RenderScene(CairoContext& context,
                                const ViewportGeometry& view);
 
     public:
-      TestWorldSceneWidget();
+      TestWorldSceneWidget(bool animate);
 
       virtual void GetSceneExtent(double& x1,
                                   double& y1,
                                   double& x2,
                                   double& y2);
+
+      virtual bool HasUpdateContent() const
+      {
+        return animate_;
+      }
+
+      virtual void UpdateContent();
     };
   }
 }
--- a/Framework/Widgets/WidgetBase.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/WidgetBase.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -80,15 +80,6 @@
   }
 
 
-  void WidgetBase::WorkerThread(WidgetBase* that)
-  {
-    while (that->started_)
-    {
-      that->UpdateStep();
-    }
-  }
-
-
   WidgetBase::WidgetBase() :
     statusBar_(NULL),
     started_(false),
@@ -121,12 +112,22 @@
 
   void WidgetBase::Register(IChangeObserver& observer)
   {
+    if (started_)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+
     observers_.Register(observer);
   }
 
 
   void WidgetBase::Unregister(IChangeObserver& observer)
   {
+    if (started_)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+
     observers_.Unregister(observer);
   }
 
@@ -135,39 +136,35 @@
   {
     if (started_)
     {
-      LOG(ERROR) << "Cannot Start() twice";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
-
-    started_ = true;
-
-    if (HasUpdateThread())
+    else
     {
-      thread_ = boost::thread(WorkerThread, this);
+      started_ = true;
     }
   }
 
+  
+  void WidgetBase::Stop()
+  {
+    if (started_)
+    {
+      started_ = false;
+    }
+    else
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+  }
 
-  void WidgetBase::Stop()
+  
+  bool WidgetBase::Render(Orthanc::ImageAccessor& surface)
   {
     if (!started_)
     {
-      LOG(ERROR) << "Cannot Stop() if Start() has not been invoked";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
-
-    started_ = false;
-
-    if (HasUpdateThread() &&
-        thread_.joinable())
-    {
-      thread_.join();
-    }
-  }
-
-
-  bool WidgetBase::Render(Orthanc::ImageAccessor& surface)
-  {
+    
 #if 0
     ClearBackgroundOrthanc(surface);
 #else
@@ -176,4 +173,10 @@
 
     return true;
   }
+
+  
+  void WidgetBase::UpdateContent()
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+  }
 }
--- a/Framework/Widgets/WidgetBase.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/WidgetBase.h	Thu Apr 27 11:01:48 2017 +0200
@@ -26,8 +26,6 @@
 #include "../Viewport/CairoContext.h"
 #include "../Toolbox/ObserversRegistry.h"
 
-#include <boost/thread.hpp>
-
 namespace OrthancStone
 {
   class WidgetBase : public IWidget
@@ -36,7 +34,6 @@
     IStatusBar*                  statusBar_;
     ObserversRegistry<IWidget>   observers_;
     bool                         started_;
-    boost::thread                thread_;
     bool                         backgroundCleared_;
     uint8_t                      backgroundColor_[3];
 
@@ -51,25 +48,19 @@
 
     void UpdateStatusBar(const std::string& message);
 
-    static void WorkerThread(WidgetBase* that);
-
     IStatusBar* GetStatusBar() const
     {
       return statusBar_;
     }
 
-    virtual bool HasUpdateThread() const = 0;
-
-    virtual void UpdateStep() = 0;
-
-  public:
-    WidgetBase();
-
     bool IsStarted() const
     {
       return started_;
     }
 
+  public:
+    WidgetBase();
+
     void SetBackgroundCleared(bool clear)
     {
       backgroundCleared_ = clear;
@@ -107,5 +98,12 @@
     virtual void Stop();
 
     virtual bool Render(Orthanc::ImageAccessor& surface);
+
+    virtual bool HasUpdateContent() const
+    {
+      return false;
+    }
+
+    virtual void UpdateContent();
   };
 }
--- a/Framework/Widgets/WorldSceneWidget.cpp	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/WorldSceneWidget.cpp	Thu Apr 27 11:01:48 2017 +0200
@@ -236,12 +236,6 @@
   };
 
 
-  void WorldSceneWidget::UpdateStep()
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-  }
-
-
   bool WorldSceneWidget::RenderCairo(CairoContext& context)
   {
     ViewportGeometry view;
--- a/Framework/Widgets/WorldSceneWidget.h	Thu Apr 27 11:00:15 2017 +0200
+++ b/Framework/Widgets/WorldSceneWidget.h	Thu Apr 27 11:01:48 2017 +0200
@@ -66,13 +66,6 @@
     virtual bool RenderScene(CairoContext& context,
                              const ViewportGeometry& view) = 0;
 
-    virtual bool HasUpdateThread() const
-    {
-      return false;
-    }
-
-    virtual void UpdateStep();
-
     virtual bool RenderCairo(CairoContext& context);
 
     virtual void RenderMouseOverCairo(CairoContext& context,
@@ -100,7 +93,10 @@
       observers_.Unregister(observer);
     }
 
-    virtual SliceGeometry GetSlice() = 0;
+    virtual SliceGeometry GetSlice()
+    {
+      return SliceGeometry();
+    }
 
     virtual void GetSceneExtent(double& x1,
                                 double& y1,