comparison 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
comparison
equal deleted inserted replaced
298:f58bfb7bbcc9 299:3897f9f28cfa
202 mainLayout_(NULL), 202 mainLayout_(NULL),
203 currentInstanceIndex_(0), 203 currentInstanceIndex_(0),
204 wasmViewport1_(NULL), 204 wasmViewport1_(NULL),
205 wasmViewport2_(NULL) 205 wasmViewport2_(NULL)
206 { 206 {
207 DeclareIgnoredMessage(MessageType_Widget_ContentChanged); 207 // DeclareIgnoredMessage(MessageType_Widget_ContentChanged);
208 DeclareHandledMessage(MessageType_Widget_GeometryChanged);
209
210 DeclareHandledMessage(MessageType_OrthancApi_GetStudyIds_Ready);
211 DeclareHandledMessage(MessageType_OrthancApi_GetStudy_Ready);
212 DeclareHandledMessage(MessageType_OrthancApi_GetSeries_Ready);
213 } 208 }
214 209
215 virtual void Finalize() {} 210 virtual void Finalize() {}
216 virtual IWidget* GetCentralWidget() {return mainLayout_;} 211 virtual IWidget* GetCentralWidget() {return mainLayout_;}
217 212
247 thumbnailsLayout_->SetBackgroundCleared(true); 242 thumbnailsLayout_->SetBackgroundCleared(true);
248 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); 243 thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
249 thumbnailsLayout_->SetVertical(); 244 thumbnailsLayout_->SetVertical();
250 245
251 mainWidget_ = new LayerWidget(broker_, "main-viewport"); 246 mainWidget_ = new LayerWidget(broker_, "main-viewport");
252 mainWidget_->RegisterObserver(*this); 247 //mainWidget_->RegisterObserver(*this);
253 248
254 // hierarchy 249 // hierarchy
255 mainLayout_->AddWidget(thumbnailsLayout_); 250 mainLayout_->AddWidget(thumbnailsLayout_);
256 mainLayout_->AddWidget(mainWidget_); 251 mainLayout_->AddWidget(mainWidget_);
257 252
271 orthancApiClient_.reset(new OrthancApiClient(broker_, context_->GetWebService())); 266 orthancApiClient_.reset(new OrthancApiClient(broker_, context_->GetWebService()));
272 267
273 if (parameters.count("studyId") < 1) 268 if (parameters.count("studyId") < 1)
274 { 269 {
275 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; 270 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc";
276 orthancApiClient_->ScheduleGetStudyIds(*this); 271 orthancApiClient_->GetJsonAsync("/studies", new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyListReceived));
277 } 272 }
278 else 273 else
279 { 274 {
280 SelectStudy(parameters["studyId"].as<std::string>()); 275 SelectStudy(parameters["studyId"].as<std::string>());
281 } 276 }
282 } 277 }
283 278
284 void OnStudyListReceived(const Json::Value& response) 279 void OnStudyListReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message)
285 { 280 {
281 const Json::Value& response = message.response_;
282
286 if (response.isArray() && response.size() > 1) 283 if (response.isArray() && response.size() > 1)
287 { 284 {
288 SelectStudy(response[0].asString()); 285 SelectStudy(response[0].asString());
289 } 286 }
290 } 287 }
291 void OnStudyReceived(const Json::Value& response) 288 void OnStudyReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message)
292 { 289 {
290 const Json::Value& response = message.response_;
291
293 if (response.isObject() && response["Series"].isArray()) 292 if (response.isObject() && response["Series"].isArray())
294 { 293 {
295 for (size_t i=0; i < response["Series"].size(); i++) 294 for (size_t i=0; i < response["Series"].size(); i++)
296 { 295 {
297 orthancApiClient_->ScheduleGetSeries(*this, response["Series"][(int)i].asString()); 296 orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(), new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnSeriesReceived));
298 } 297 }
299 } 298 }
300 } 299 }
301 300
302 void OnSeriesReceived(const Json::Value& response) 301 void OnSeriesReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message)
303 { 302 {
303 const Json::Value& response = message.response_;
304
304 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) 305 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0)
305 { 306 {
306 // keep track of all instances IDs 307 // keep track of all instances IDs
307 const std::string& seriesId = response["ID"].asString(); 308 const std::string& seriesId = response["ID"].asString();
308 seriesTags_[seriesId] = response; 309 seriesTags_[seriesId] = response;
328 { 329 {
329 LOG(INFO) << "Loading thumbnail for series " << seriesId; 330 LOG(INFO) << "Loading thumbnail for series " << seriesId;
330 LayerWidget* thumbnailWidget = new LayerWidget(broker_, "thumbnail-series-" + seriesId); 331 LayerWidget* thumbnailWidget = new LayerWidget(broker_, "thumbnail-series-" + seriesId);
331 thumbnails_.push_back(thumbnailWidget); 332 thumbnails_.push_back(thumbnailWidget);
332 thumbnailsLayout_->AddWidget(thumbnailWidget); 333 thumbnailsLayout_->AddWidget(thumbnailWidget);
333 thumbnailWidget->RegisterObserver(*this); 334 thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, LayerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged));
334 thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0)); 335 thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0));
335 thumbnailWidget->SetInteractor(*thumbnailInteractor_); 336 thumbnailWidget->SetInteractor(*thumbnailInteractor_);
336 } 337 }
337 338
338 void SelectStudy(const std::string& studyId) 339 void SelectStudy(const std::string& studyId)
339 { 340 {
340 orthancApiClient_->ScheduleGetStudy(*this, studyId); 341 orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived));
341 } 342 }
342 343
343 virtual void HandleMessage(IObservable& from, const IMessage& message) { 344 void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
344 switch (message.GetType()) { 345 {
345 case MessageType_Widget_GeometryChanged: 346 message.origin_.SetDefaultView();
346 LOG(INFO) << "Widget geometry ready: " << dynamic_cast<LayerWidget&>(from).GetName();
347 dynamic_cast<LayerWidget&>(from).SetDefaultView();
348 break;
349 case MessageType_OrthancApi_GetStudyIds_Ready:
350 OnStudyListReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
351 break;
352 case MessageType_OrthancApi_GetSeries_Ready:
353 OnSeriesReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
354 break;
355 case MessageType_OrthancApi_GetStudy_Ready:
356 OnStudyReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
357 break;
358 default:
359 VLOG("unhandled message type" << message.GetType());
360 }
361 } 347 }
362 348
363 void SelectSeriesInMainViewport(const std::string& seriesId) 349 void SelectSeriesInMainViewport(const std::string& seriesId)
364 { 350 {
365 mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0)); 351 mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0));