comparison Applications/Samples/SimpleViewerApplicationSingleFile.h @ 377:8eb4fe74000f

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 Nov 2018 16:18:27 +0100
parents face7b7008de
children 20f149669c1f
comparison
equal deleted inserted replaced
376:70256a53ff21 377:8eb4fe74000f
42 namespace OrthancStone 42 namespace OrthancStone
43 { 43 {
44 namespace Samples 44 namespace Samples
45 { 45 {
46 class SimpleViewerApplication : 46 class SimpleViewerApplication :
47 public SampleSingleCanvasWithButtonsApplicationBase, 47 public SampleSingleCanvasWithButtonsApplicationBase,
48 public IObserver 48 public IObserver
49 { 49 {
50 private: 50 private:
51 class ThumbnailInteractor : public IWorldSceneInteractor 51 class ThumbnailInteractor : public IWorldSceneInteractor
52 { 52 {
53 private: 53 private:
167 KeyboardModifiers modifiers, 167 KeyboardModifiers modifiers,
168 IStatusBar* statusBar) 168 IStatusBar* statusBar)
169 { 169 {
170 switch (keyChar) 170 switch (keyChar)
171 { 171 {
172 case 's': 172 case 's':
173 widget.FitContent(); 173 widget.FitContent();
174 break; 174 break;
175 175
176 case 'l': 176 case 'l':
177 application_.currentTool_ = Tools_LineMeasure; 177 application_.currentTool_ = Tools_LineMeasure;
178 break; 178 break;
179 179
180 case 'c': 180 case 'c':
181 application_.currentTool_ = Tools_CircleMeasure; 181 application_.currentTool_ = Tools_CircleMeasure;
182 break; 182 break;
183 183
184 default: 184 default:
185 break; 185 break;
186 } 186 }
187 } 187 }
188 }; 188 };
189 189
190 190
194 SimpleViewerApplication& viewerApplication_; 194 SimpleViewerApplication& viewerApplication_;
195 195
196 public: 196 public:
197 SimpleViewerApplicationAdapter(MessageBroker& broker, SimpleViewerApplication& application) 197 SimpleViewerApplicationAdapter(MessageBroker& broker, SimpleViewerApplication& application)
198 : WasmPlatformApplicationAdapter(broker, application), 198 : WasmPlatformApplicationAdapter(broker, application),
199 viewerApplication_(application) 199 viewerApplication_(application)
200 { 200 {
201 201
202 } 202 }
203 203
204 virtual void HandleMessageFromWeb(std::string& output, const std::string& input) { 204 virtual void HandleMessageFromWeb(std::string& output, const std::string& input) {
262 262
263 virtual void DeclareStartupOptions(boost::program_options::options_description& options) 263 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
264 { 264 {
265 boost::program_options::options_description generic("Sample options"); 265 boost::program_options::options_description generic("Sample options");
266 generic.add_options() 266 generic.add_options()
267 ("studyId", boost::program_options::value<std::string>(), 267 ("studyId", boost::program_options::value<std::string>(),
268 "Orthanc ID of the study") 268 "Orthanc ID of the study")
269 ; 269 ;
270 270
271 options.add(generic); 271 options.add(generic);
272 } 272 }
273 273
274 virtual void Initialize(StoneApplicationContext* context, 274 virtual void Initialize(StoneApplicationContext* context,
317 317
318 318
319 if (parameters.count("studyId") < 1) 319 if (parameters.count("studyId") < 1)
320 { 320 {
321 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; 321 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc";
322 orthancApiClient_->GetJsonAsync("/studies", new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyListReceived)); 322 orthancApiClient_->GetJsonAsync("/studies",
323 new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>
324 (*this, &SimpleViewerApplication::OnStudyListReceived));
323 } 325 }
324 else 326 else
325 { 327 {
326 SelectStudy(parameters["studyId"].as<std::string>()); 328 SelectStudy(parameters["studyId"].as<std::string>());
327 } 329 }
328 } 330 }
329 331
330 void OnStudyListReceived(const OrthancApiClient::JsonResponseReadyMessage& message) 332 void OnStudyListReceived(const OrthancApiClient::JsonResponseReadyMessage& message)
331 { 333 {
332 const Json::Value& response = message.Response; 334 const Json::Value& response = message.GetJson();
333 335
334 if (response.isArray() && response.size() > 1) 336 if (response.isArray() && response.size() > 1)
335 { 337 {
336 SelectStudy(response[0].asString()); 338 SelectStudy(response[0].asString());
337 } 339 }
338 } 340 }
339 void OnStudyReceived(const OrthancApiClient::JsonResponseReadyMessage& message) 341 void OnStudyReceived(const OrthancApiClient::JsonResponseReadyMessage& message)
340 { 342 {
341 const Json::Value& response = message.Response; 343 const Json::Value& response = message.GetJson();
342 344
343 if (response.isObject() && response["Series"].isArray()) 345 if (response.isObject() && response["Series"].isArray())
344 { 346 {
345 for (size_t i=0; i < response["Series"].size(); i++) 347 for (size_t i=0; i < response["Series"].size(); i++)
346 { 348 {
347 orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(), new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnSeriesReceived)); 349 orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(),
350 new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>
351 (*this, &SimpleViewerApplication::OnSeriesReceived));
348 } 352 }
349 } 353 }
350 } 354 }
351 355
352 void OnSeriesReceived(const OrthancApiClient::JsonResponseReadyMessage& message) 356 void OnSeriesReceived(const OrthancApiClient::JsonResponseReadyMessage& message)
353 { 357 {
354 const Json::Value& response = message.Response; 358 const Json::Value& response = message.GetJson();
355 359
356 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) 360 if (response.isObject() &&
361 response["Instances"].isArray() &&
362 response["Instances"].size() > 0)
357 { 363 {
358 // keep track of all instances IDs 364 // keep track of all instances IDs
359 const std::string& seriesId = response["ID"].asString(); 365 const std::string& seriesId = response["ID"].asString();
360 seriesTags_[seriesId] = response; 366 seriesTags_[seriesId] = response;
361 instancesIdsPerSeriesId_[seriesId] = std::vector<std::string>(); 367 instancesIdsPerSeriesId_[seriesId] = std::vector<std::string>();
393 orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived)); 399 orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::JsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived));
394 } 400 }
395 401
396 void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message) 402 void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
397 { 403 {
398 message.origin_.FitContent(); 404 message.GetOrigin().FitContent();
399 } 405 }
400 406
401 void SelectSeriesInMainViewport(const std::string& seriesId) 407 void SelectSeriesInMainViewport(const std::string& seriesId)
402 { 408 {
403 LayerWidget& widget = *dynamic_cast<LayerWidget*>(mainWidget_); 409 LayerWidget& widget = *dynamic_cast<LayerWidget*>(mainWidget_);
415 virtual void OnTool2Clicked() { currentTool_ = Tools_CircleMeasure;} 421 virtual void OnTool2Clicked() { currentTool_ = Tools_CircleMeasure;}
416 422
417 virtual void GetButtonNames(std::string& pushButton1, 423 virtual void GetButtonNames(std::string& pushButton1,
418 std::string& pushButton2, 424 std::string& pushButton2,
419 std::string& tool1, 425 std::string& tool1,
420 std::string& tool2 426 std::string& tool2)
421 ) { 427 {
422 tool1 = "line"; 428 tool1 = "line";
423 tool2 = "circle"; 429 tool2 = "circle";
424 pushButton1 = "action1"; 430 pushButton1 = "action1";
425 pushButton2 = "action2"; 431 pushButton2 = "action2";
426 } 432 }
427 433
428 #if ORTHANC_ENABLE_WASM==1 434 #if ORTHANC_ENABLE_WASM==1
429 virtual void InitializeWasm() { 435 virtual void InitializeWasm()
430 436 {
431 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_); 437 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_);
432 AttachWidgetToWasmViewport("canvas2", mainWidget_); 438 AttachWidgetToWasmViewport("canvas2", mainWidget_);
433 } 439 }
434 #endif 440 #endif
435 441