# HG changeset patch # User am@osimis.io # Date 1535377213 -7200 # Node ID 8f5d7495076d2843a54af8619f4cdefa43735093 # Parent 8a86695fcbc322637199b85dd339af943445edfa SimpleViewer sample working in SDL, Qt and WASM diff -r 8a86695fcbc3 -r 8f5d7495076d Applications/Samples/SimpleViewerApplication.h --- a/Applications/Samples/SimpleViewerApplication.h Mon Aug 27 14:58:37 2018 +0200 +++ b/Applications/Samples/SimpleViewerApplication.h Mon Aug 27 15:40:13 2018 +0200 @@ -59,7 +59,9 @@ { if (button == MouseButton_Left) { - statusBar->SetMessage("trying to drag the thumbnail from " + widget.GetName()); + statusBar->SetMessage("selected thumbnail " + widget.GetName()); + std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-")); + application_.SelectSeriesInMainViewport(seriesId); } return NULL; } @@ -156,9 +158,6 @@ case 's': widget.SetDefaultView(); break; - case 'n': - application_.NextImage(widget); - break; default: break; @@ -173,7 +172,7 @@ LayoutWidget* thumbnailsLayout_; LayerWidget* mainWidget_; std::vector thumbnails_; - std::vector instances_; + std::map> instancesIdsPerSeriesId_; unsigned int currentInstanceIndex_; OrthancStone::WidgetViewport* wasmViewport1_; @@ -292,7 +291,23 @@ { if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) { - LoadThumbnailForSeries(response["ID"].asString(), response["Instances"][0].asString()); + // keep track of all instances IDs + const std::string& seriesId = response["ID"].asString(); + instancesIdsPerSeriesId_[seriesId] = std::vector(); + for (size_t i = 0; i < response["Instances"].size(); i++) + { + const std::string& instanceId = response["Instances"][static_cast(i)].asString(); + instancesIdsPerSeriesId_[seriesId].push_back(instanceId); + } + + // load the first instance in the thumbnail + LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]); + + // if this is the first thumbnail loaded, load the first instance in the mainWidget + if (mainWidget_->GetLayerCount() == 0) + { + mainWidget_->AddLayer(smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0)); + } } } @@ -304,7 +319,7 @@ thumbnailsLayout_->AddWidget(thumbnailWidget); thumbnailWidget->RegisterObserver(*this); thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0)); - //thumbnailWidget->SetInteractor(*thumbnailInteractor_); + thumbnailWidget->SetInteractor(*thumbnailInteractor_); } void SelectStudy(const std::string& studyId) @@ -340,14 +355,9 @@ } #endif - void NextImage(WorldSceneWidget& widget) { - assert(context_); - statusBar_->SetMessage("displaying next image"); - - currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size(); - - mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0)); - + void SelectSeriesInMainViewport(const std::string& seriesId) + { + mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0)); } }; diff -r 8a86695fcbc3 -r 8f5d7495076d Applications/Sdl/BasicSdlApplication.cpp --- a/Applications/Sdl/BasicSdlApplication.cpp Mon Aug 27 14:58:37 2018 +0200 +++ b/Applications/Sdl/BasicSdlApplication.cpp Mon Aug 27 15:40:13 2018 +0200 @@ -61,7 +61,7 @@ !parameters.count("opengl")) { LOG(ERROR) << "Parameter \"width\", \"height\" or \"opengl\" is missing"; - return -1; + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } int w = parameters["width"].as(); @@ -69,15 +69,15 @@ if (w <= 0 || h <= 0) { LOG(ERROR) << "Parameters \"width\" and \"height\" must be positive"; - return -1; + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } width_ = static_cast(w); height_ = static_cast(h); LOG(WARNING) << "Initial display size: " << width_ << "x" << height_; - opengl_ = parameters["opengl"].as(); - if (opengl_) + enableOpenGl_ = parameters["opengl"].as(); + if (enableOpenGl_) { LOG(WARNING) << "OpenGL is enabled, disable it with option \"--opengl=off\" if the application crashes"; } diff -r 8a86695fcbc3 -r 8f5d7495076d Framework/SmartLoader.h --- a/Framework/SmartLoader.h Mon Aug 27 14:58:37 2018 +0200 +++ b/Framework/SmartLoader.h Mon Aug 27 15:40:13 2018 +0200 @@ -20,6 +20,7 @@ #pragma once +#include #include "Layers/ILayerSource.h" #include "Messages/IObservable.h" @@ -35,6 +36,7 @@ OrthancApiClient orthancApiClient_; int studyListRequest_; + public: SmartLoader(MessageBroker& broker, IWebService& webService); // TODO: add maxPreloadStorageSizeInBytes @@ -48,6 +50,8 @@ ILayerSource* GetFrame(const std::string& instanceId, unsigned int frame); + void GetFirstInstanceIdForSeries(std::string& output, const std::string& seriesId); + }; } diff -r 8a86695fcbc3 -r 8f5d7495076d Platforms/Generic/CMakeLists.txt --- a/Platforms/Generic/CMakeLists.txt Mon Aug 27 14:58:37 2018 +0200 +++ b/Platforms/Generic/CMakeLists.txt Mon Aug 27 15:40:13 2018 +0200 @@ -29,8 +29,8 @@ LIST(APPEND ORTHANC_BOOST_COMPONENTS program_options) -SET(ENABLE_SDL OFF) -SET(ENABLE_QT ON) +SET(ENABLE_SDL ON) +SET(ENABLE_QT OFF) SET(ORTHANC_SANDBOXED OFF) SET(ENABLE_CRYPTO_OPTIONS ON) SET(ENABLE_GOOGLE_TEST ON)