changeset 246:5470b15f7cf2 am

first usage of boost::signals2
author am@osimis.io
date Tue, 26 Jun 2018 13:55:17 +0200
parents e802578e1554
children 3d523c9a8f0d
files Applications/Samples/SimpleViewerApplication.h Framework/Layers/LayerSourceBase.cpp Framework/Layers/LayerSourceBase.h Platforms/Generic/CMakeLists.txt Platforms/Generic/OracleWebService.h Platforms/Generic/WebServiceGetCommand.cpp Platforms/Generic/WebServiceGetCommand.h Platforms/Wasm/build-wasm.sh Resources/CMake/OrthancStoneConfiguration.cmake
diffstat 9 files changed, 45 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewerApplication.h	Wed Jun 20 15:59:52 2018 +0200
+++ b/Applications/Samples/SimpleViewerApplication.h	Tue Jun 26 13:55:17 2018 +0200
@@ -109,6 +109,10 @@
             case 's':
               widget.SetDefaultView();
               break;
+            case 'n':
+              application_.NextImage(widget);
+              //widget.SetDefaultView();
+              break;
 
             default:
               break;
@@ -182,7 +186,12 @@
 
         mainLayout_->SetDefaultView();
       }
-      
+
+      void OnGeometryReady(const ILayerSource& source)
+      {
+        mainLayout_->SetDefaultView();
+      }
+
       virtual void NotifyGeometryError(const ILayerSource& source)
       {
       }
@@ -292,7 +301,8 @@
         // sources
         source_ = new OrthancFrameLayerSource(context_->GetWebService());
         source_->LoadFrame(instances_[currentInstanceIndex_], 0);
-        source_->Register(*this);
+//        source_->Register(*this);
+        source_->SignalGeometryReady.connect(boost::bind(&SimpleViewerApplication::OnGeometryReady, this, _1));
 
         mainViewport_->AddLayer(source_);
 
@@ -316,6 +326,19 @@
         AttachWidgetToWasmViewport("canvas2", mainViewport_);
       }
 #endif
+      void NextImage(WorldSceneWidget& widget) {
+        assert(context_);
+
+        currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size();
+
+        std::auto_ptr<OrthancFrameLayerSource> layer
+            (new OrthancFrameLayerSource(context_->GetWebService()));
+        layer->LoadFrame(instances_[currentInstanceIndex_], 0);
+
+        mainViewport_->ReplaceLayer(0, layer.release());
+        //  source_->LoadFrame("45b7e6bc-168e8ed1-063dc08d-cffd6431-133a276a", 0);
+      }
+
     };
   }
 }
--- a/Framework/Layers/LayerSourceBase.cpp	Wed Jun 20 15:59:52 2018 +0200
+++ b/Framework/Layers/LayerSourceBase.cpp	Tue Jun 26 13:55:17 2018 +0200
@@ -54,6 +54,10 @@
 
   void LayerSourceBase::NotifyGeometryReady()
   {
+    //new observers
+    SignalGeometryReady(*this);
+
+    //old observers
     observers_.Apply(*this, &IObserver::NotifyGeometryReady);
   }
     
--- a/Framework/Layers/LayerSourceBase.h	Wed Jun 20 15:59:52 2018 +0200
+++ b/Framework/Layers/LayerSourceBase.h	Tue Jun 26 13:55:17 2018 +0200
@@ -23,6 +23,7 @@
 
 #include "ILayerSource.h"
 #include "../Toolbox/ObserversRegistry.h"
+#include <boost/signals2.hpp>
 
 namespace OrthancStone
 {
@@ -48,5 +49,6 @@
 
   public:
     virtual void Register(IObserver& observer);
+    boost::signals2::signal<void (const ILayerSource& source)> SignalGeometryReady;
   };
 }
--- a/Platforms/Generic/CMakeLists.txt	Wed Jun 20 15:59:52 2018 +0200
+++ b/Platforms/Generic/CMakeLists.txt	Tue Jun 26 13:55:17 2018 +0200
@@ -71,7 +71,7 @@
 BuildSample(OrthancStoneSimpleViewer SimpleViewerApplication.h 8)
 
 
-#####################################################################
+####################################################################
 ## Build the unit tests
 #####################################################################
 
--- a/Platforms/Generic/OracleWebService.h	Wed Jun 20 15:59:52 2018 +0200
+++ b/Platforms/Generic/OracleWebService.h	Tue Jun 26 13:55:17 2018 +0200
@@ -46,6 +46,7 @@
                                     const std::string& uri,
                                     Orthanc::IDynamicObject* payload)
     {
+
       oracle_.Submit(new WebServiceGetCommand(callback, parameters_, uri, payload));
     }
 
--- a/Platforms/Generic/WebServiceGetCommand.cpp	Wed Jun 20 15:59:52 2018 +0200
+++ b/Platforms/Generic/WebServiceGetCommand.cpp	Tue Jun 26 13:55:17 2018 +0200
@@ -34,6 +34,7 @@
     uri_(uri),
     payload_(payload)
   {
+    //SignalSuccess.connect(boost::bind(&IWebService::ICallback::NotifySuccess, callback, _1, _2, _3, _4));
   }
 
 
@@ -50,7 +51,8 @@
   {
     if (success_)
     {
-      callback_.NotifySuccess(uri_, answer_.c_str(), answer_.size(), payload_.release());
+      SignalSuccess(uri_, answer_.c_str(), answer_.size(), payload_.release());
+      //callback_.NotifySuccess(uri_, answer_.c_str(), answer_.size(), payload_.release());
     }
     else
     {
--- a/Platforms/Generic/WebServiceGetCommand.h	Wed Jun 20 15:59:52 2018 +0200
+++ b/Platforms/Generic/WebServiceGetCommand.h	Tue Jun 26 13:55:17 2018 +0200
@@ -28,6 +28,7 @@
 #include <Core/WebServiceParameters.h>
 
 #include <memory>
+#include <boost/signals2.hpp>
 
 namespace OrthancStone
 {
@@ -50,5 +51,11 @@
     virtual void Execute();
 
     virtual void Commit();
+
+    boost::signals2::signal<void (const std::string& uri,
+                                  const void* answer,
+                                  size_t answerSize,
+                                  Orthanc::IDynamicObject* payload)> SignalSuccess;
+
   };
 }
--- a/Platforms/Wasm/build-wasm.sh	Wed Jun 20 15:59:52 2018 +0200
+++ b/Platforms/Wasm/build-wasm.sh	Tue Jun 26 13:55:17 2018 +0200
@@ -7,7 +7,7 @@
 cd $wasmRootDir/build
 
 source ~/Downloads/emsdk/emsdk_env.sh
-cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake .. -DCMAKE_BUILD_TYPE=Release -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc -DALLOW_DOWNLOADS=ON -DSTATIC_BUILD=OFF
+cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc -DALLOW_DOWNLOADS=ON ..
 make -j 5
 
 echo "-- building the web application -- "
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Jun 20 15:59:52 2018 +0200
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Tue Jun 26 13:55:17 2018 +0200
@@ -145,6 +145,7 @@
     ${ORTHANC_STONE_ROOT}/Platforms/Generic/WebServiceGetCommand.cpp
     ${ORTHANC_STONE_ROOT}/Platforms/Generic/WebServicePostCommand.cpp
     ${ORTHANC_STONE_ROOT}/Platforms/Generic/Oracle.cpp
+    ${ORTHANC_STONE_ROOT}/Platforms/Generic/OracleWebService.h
     )
 
   list(APPEND APPLICATIONS_SOURCES