Mercurial > hg > orthanc-stone
diff Applications/Samples/SimpleViewerApplication.h @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | 8c8da145fefa |
children | b4abaeb783b1 |
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewerApplication.h Mon Sep 10 12:22:26 2018 +0200 +++ b/Applications/Samples/SimpleViewerApplication.h Fri Sep 14 16:44:01 2018 +0200 @@ -204,12 +204,7 @@ wasmViewport1_(NULL), wasmViewport2_(NULL) { - DeclareIgnoredMessage(MessageType_Widget_ContentChanged); - DeclareHandledMessage(MessageType_Widget_GeometryChanged); - - DeclareHandledMessage(MessageType_OrthancApi_GetStudyIds_Ready); - DeclareHandledMessage(MessageType_OrthancApi_GetStudy_Ready); - DeclareHandledMessage(MessageType_OrthancApi_GetSeries_Ready); +// DeclareIgnoredMessage(MessageType_Widget_ContentChanged); } virtual void Finalize() {} @@ -249,7 +244,7 @@ thumbnailsLayout_->SetVertical(); mainWidget_ = new LayerWidget(broker_, "main-viewport"); - mainWidget_->RegisterObserver(*this); + //mainWidget_->RegisterObserver(*this); // hierarchy mainLayout_->AddWidget(thumbnailsLayout_); @@ -273,7 +268,7 @@ if (parameters.count("studyId") < 1) { LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; - orthancApiClient_->ScheduleGetStudyIds(*this); + orthancApiClient_->GetJsonAsync("/studies", new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyListReceived)); } else { @@ -281,26 +276,32 @@ } } - void OnStudyListReceived(const Json::Value& response) + void OnStudyListReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) { + const Json::Value& response = message.response_; + if (response.isArray() && response.size() > 1) { SelectStudy(response[0].asString()); } } - void OnStudyReceived(const Json::Value& response) + void OnStudyReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) { + const Json::Value& response = message.response_; + if (response.isObject() && response["Series"].isArray()) { for (size_t i=0; i < response["Series"].size(); i++) { - orthancApiClient_->ScheduleGetSeries(*this, response["Series"][(int)i].asString()); + orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(), new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnSeriesReceived)); } } } - void OnSeriesReceived(const Json::Value& response) + void OnSeriesReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) { + const Json::Value& response = message.response_; + if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) { // keep track of all instances IDs @@ -330,34 +331,19 @@ LayerWidget* thumbnailWidget = new LayerWidget(broker_, "thumbnail-series-" + seriesId); thumbnails_.push_back(thumbnailWidget); thumbnailsLayout_->AddWidget(thumbnailWidget); - thumbnailWidget->RegisterObserver(*this); + thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, LayerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged)); thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0)); thumbnailWidget->SetInteractor(*thumbnailInteractor_); } void SelectStudy(const std::string& studyId) { - orthancApiClient_->ScheduleGetStudy(*this, studyId); + orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived)); } - virtual void HandleMessage(IObservable& from, const IMessage& message) { - switch (message.GetType()) { - case MessageType_Widget_GeometryChanged: - LOG(INFO) << "Widget geometry ready: " << dynamic_cast<LayerWidget&>(from).GetName(); - dynamic_cast<LayerWidget&>(from).SetDefaultView(); - break; - case MessageType_OrthancApi_GetStudyIds_Ready: - OnStudyListReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_); - break; - case MessageType_OrthancApi_GetSeries_Ready: - OnSeriesReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_); - break; - case MessageType_OrthancApi_GetStudy_Ready: - OnStudyReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_); - break; - default: - VLOG("unhandled message type" << message.GetType()); - } + void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message) + { + message.origin_.SetDefaultView(); } void SelectSeriesInMainViewport(const std::string& seriesId)