Mercurial > hg > orthanc-stone
annotate 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 |
rev | line source |
---|---|
235 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
249 | 16 * |
235 | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "SampleApplicationBase.h" | |
25 | |
26 #include "../../Framework/Layers/OrthancFrameLayerSource.h" | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
27 #include "../../Framework/Layers/CircleMeasureTracker.h" |
281 | 28 #include "../../Framework/Layers/LineMeasureTracker.h" |
235 | 29 #include "../../Framework/Widgets/LayerWidget.h" |
30 #include "../../Framework/Widgets/LayoutWidget.h" | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
31 #include "../../Framework/Messages/IObserver.h" |
258 | 32 #include "../../Framework/SmartLoader.h" |
235 | 33 |
287 | 34 #if ORTHANC_ENABLE_WASM==1 |
35 #include "../../Platforms/Wasm/IStoneApplicationToWebApplicationAdapter.h" | |
36 #include "../../Platforms/Wasm/Defaults.h" | |
37 #endif | |
235 | 38 #include <Core/Logging.h> |
39 | |
40 namespace OrthancStone | |
41 { | |
42 namespace Samples | |
43 { | |
44 class SimpleViewerApplication : | |
249 | 45 public SampleApplicationBase, |
287 | 46 #if ORTHANC_ENABLE_WASM==1 |
47 public IStoneApplicationToWebApplicationAdapter, | |
48 #endif | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
49 public IObserver |
235 | 50 { |
51 private: | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
52 class ThumbnailInteractor : public IWorldSceneInteractor |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
53 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
54 private: |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
55 SimpleViewerApplication& application_; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
56 public: |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
57 ThumbnailInteractor(SimpleViewerApplication& application) : |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
58 application_(application) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
59 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
60 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
61 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
62 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
63 const ViewportGeometry& view, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
64 MouseButton button, |
281 | 65 KeyboardModifiers modifiers, |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
66 double x, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
67 double y, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
68 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
69 { |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
70 if (button == MouseButton_Left) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
71 { |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
72 statusBar->SetMessage("selected thumbnail " + widget.GetName()); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
73 std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-")); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
74 application_.SelectSeriesInMainViewport(seriesId); |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
75 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
76 return NULL; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
77 } |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
78 virtual void MouseOver(CairoContext& context, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
79 WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
80 const ViewportGeometry& view, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
81 double x, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
82 double y, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
83 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
84 {} |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
85 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
86 virtual void MouseWheel(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
87 MouseWheelDirection direction, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
88 KeyboardModifiers modifiers, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
89 IStatusBar* statusBar) |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
90 {} |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
91 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
92 virtual void KeyPressed(WorldSceneWidget& widget, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
93 char key, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
94 KeyboardModifiers modifiers, |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
95 IStatusBar* statusBar) |
281 | 96 {} |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
97 |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
98 }; |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
99 |
281 | 100 class MainWidgetInteractor : public IWorldSceneInteractor |
235 | 101 { |
102 private: | |
103 SimpleViewerApplication& application_; | |
104 | |
105 public: | |
281 | 106 MainWidgetInteractor(SimpleViewerApplication& application) : |
235 | 107 application_(application) |
108 { | |
109 } | |
110 | |
111 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
112 const ViewportGeometry& view, | |
113 MouseButton button, | |
281 | 114 KeyboardModifiers modifiers, |
235 | 115 double x, |
116 double y, | |
117 IStatusBar* statusBar) | |
118 { | |
281 | 119 if (button == MouseButton_Left) |
120 { | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
121 if (application_.currentTool_ == Tools_LineMeasure) |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
122 { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
123 return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10); |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
124 } |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
125 else if (application_.currentTool_ == Tools_CircleMeasure) |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
126 { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
127 return new CircleMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10); |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
128 } |
281 | 129 } |
235 | 130 return NULL; |
131 } | |
132 | |
133 virtual void MouseOver(CairoContext& context, | |
134 WorldSceneWidget& widget, | |
135 const ViewportGeometry& view, | |
136 double x, | |
137 double y, | |
138 IStatusBar* statusBar) | |
139 { | |
140 if (statusBar != NULL) | |
141 { | |
142 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); | |
143 | |
144 char buf[64]; | |
249 | 145 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", |
235 | 146 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); |
147 statusBar->SetMessage(buf); | |
148 } | |
149 } | |
150 | |
151 virtual void MouseWheel(WorldSceneWidget& widget, | |
152 MouseWheelDirection direction, | |
153 KeyboardModifiers modifiers, | |
154 IStatusBar* statusBar) | |
155 { | |
156 } | |
157 | |
158 virtual void KeyPressed(WorldSceneWidget& widget, | |
159 char key, | |
160 KeyboardModifiers modifiers, | |
161 IStatusBar* statusBar) | |
162 { | |
163 switch (key) | |
164 { | |
249 | 165 case 's': |
166 widget.SetDefaultView(); | |
167 break; | |
235 | 168 |
249 | 169 default: |
170 break; | |
235 | 171 } |
172 } | |
173 }; | |
174 | |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
175 enum Tools { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
176 Tools_LineMeasure, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
177 Tools_CircleMeasure |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
178 }; |
235 | 179 |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
180 Tools currentTool_; |
281 | 181 std::unique_ptr<MainWidgetInteractor> mainWidgetInteractor_; |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
182 std::unique_ptr<ThumbnailInteractor> thumbnailInteractor_; |
235 | 183 LayoutWidget* mainLayout_; |
184 LayoutWidget* thumbnailsLayout_; | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
185 LayerWidget* mainWidget_; |
235 | 186 std::vector<LayerWidget*> thumbnails_; |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
187 std::map<std::string, std::vector<std::string>> instancesIdsPerSeriesId_; |
287 | 188 std::map<std::string, Json::Value> seriesTags_; |
270 | 189 |
235 | 190 unsigned int currentInstanceIndex_; |
270 | 191 OrthancStone::WidgetViewport* wasmViewport1_; |
192 OrthancStone::WidgetViewport* wasmViewport2_; | |
235 | 193 |
254 | 194 IStatusBar* statusBar_; |
258 | 195 std::unique_ptr<SmartLoader> smartLoader_; |
270 | 196 std::unique_ptr<OrthancApiClient> orthancApiClient_; |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
197 |
235 | 198 public: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
199 SimpleViewerApplication(MessageBroker& broker) : |
258 | 200 IObserver(broker), |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
201 currentTool_(Tools_LineMeasure), |
235 | 202 mainLayout_(NULL), |
203 currentInstanceIndex_(0), | |
242 | 204 wasmViewport1_(NULL), |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
205 wasmViewport2_(NULL) |
235 | 206 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
207 // DeclareIgnoredMessage(MessageType_Widget_ContentChanged); |
235 | 208 } |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
249
diff
changeset
|
209 |
237
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
210 virtual void Finalize() {} |
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
211 virtual IWidget* GetCentralWidget() {return mainLayout_;} |
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
212 |
235 | 213 virtual void DeclareStartupOptions(boost::program_options::options_description& options) |
214 { | |
215 boost::program_options::options_description generic("Sample options"); | |
216 generic.add_options() | |
270 | 217 ("studyId", boost::program_options::value<std::string>(), |
218 "Orthanc ID of the study") | |
249 | 219 ; |
235 | 220 |
249 | 221 options.add(generic); |
235 | 222 } |
223 | |
288 | 224 virtual void Initialize(StoneApplicationContext* context, |
242 | 225 IStatusBar& statusBar, |
235 | 226 const boost::program_options::variables_map& parameters) |
227 { | |
228 using namespace OrthancStone; | |
229 | |
242 | 230 context_ = context; |
254 | 231 statusBar_ = &statusBar; |
270 | 232 |
233 {// initialize viewports and layout | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
234 mainLayout_ = new LayoutWidget("main-layout"); |
270 | 235 mainLayout_->SetPadding(10); |
236 mainLayout_->SetBackgroundCleared(true); | |
237 mainLayout_->SetBackgroundColor(0, 0, 0); | |
238 mainLayout_->SetHorizontal(); | |
239 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
240 thumbnailsLayout_ = new LayoutWidget("thumbnail-layout"); |
270 | 241 thumbnailsLayout_->SetPadding(10); |
242 thumbnailsLayout_->SetBackgroundCleared(true); | |
243 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); | |
244 thumbnailsLayout_->SetVertical(); | |
245 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
246 mainWidget_ = new LayerWidget(broker_, "main-viewport"); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
247 //mainWidget_->RegisterObserver(*this); |
270 | 248 |
249 // hierarchy | |
250 mainLayout_->AddWidget(thumbnailsLayout_); | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
251 mainLayout_->AddWidget(mainWidget_); |
270 | 252 |
253 // sources | |
254 smartLoader_.reset(new SmartLoader(broker_, context_->GetWebService())); | |
255 smartLoader_->SetImageQuality(SliceImageQuality_FullPam); | |
256 | |
257 mainLayout_->SetTransmitMouseOver(true); | |
281 | 258 mainWidgetInteractor_.reset(new MainWidgetInteractor(*this)); |
259 mainWidget_->SetInteractor(*mainWidgetInteractor_); | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
271
diff
changeset
|
260 thumbnailInteractor_.reset(new ThumbnailInteractor(*this)); |
270 | 261 } |
262 | |
235 | 263 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout"); |
254 | 264 statusBar.SetMessage("Use the key \"n\" to go to next image in the main viewport"); |
235 | 265 |
270 | 266 orthancApiClient_.reset(new OrthancApiClient(broker_, context_->GetWebService())); |
267 | |
268 if (parameters.count("studyId") < 1) | |
235 | 269 { |
270 | 270 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc"; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
271 orthancApiClient_->GetJsonAsync("/studies", new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyListReceived)); |
235 | 272 } |
270 | 273 else |
235 | 274 { |
270 | 275 SelectStudy(parameters["studyId"].as<std::string>()); |
235 | 276 } |
270 | 277 } |
235 | 278 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
279 void OnStudyListReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) |
270 | 280 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
281 const Json::Value& response = message.response_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
282 |
270 | 283 if (response.isArray() && response.size() > 1) |
284 { | |
285 SelectStudy(response[0].asString()); | |
286 } | |
287 } | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
288 void OnStudyReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) |
270 | 289 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
290 const Json::Value& response = message.response_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
291 |
270 | 292 if (response.isObject() && response["Series"].isArray()) |
293 { | |
294 for (size_t i=0; i < response["Series"].size(); i++) | |
295 { | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
296 orthancApiClient_->GetJsonAsync("/series/" + response["Series"][(int)i].asString(), new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnSeriesReceived)); |
270 | 297 } |
298 } | |
299 } | |
235 | 300 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
301 void OnSeriesReceived(const OrthancApiClient::NewGetJsonResponseReadyMessage& message) |
270 | 302 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
303 const Json::Value& response = message.response_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
304 |
270 | 305 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0) |
306 { | |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
307 // keep track of all instances IDs |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
308 const std::string& seriesId = response["ID"].asString(); |
287 | 309 seriesTags_[seriesId] = response; |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
310 instancesIdsPerSeriesId_[seriesId] = std::vector<std::string>(); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
311 for (size_t i = 0; i < response["Instances"].size(); i++) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
312 { |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
313 const std::string& instanceId = response["Instances"][static_cast<int>(i)].asString(); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
314 instancesIdsPerSeriesId_[seriesId].push_back(instanceId); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
315 } |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
316 |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
317 // load the first instance in the thumbnail |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
318 LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]); |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
319 |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
320 // if this is the first thumbnail loaded, load the first instance in the mainWidget |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
321 if (mainWidget_->GetLayerCount() == 0) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
322 { |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
323 mainWidget_->AddLayer(smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0)); |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
324 } |
270 | 325 } |
326 } | |
327 | |
328 void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId) | |
329 { | |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
330 LOG(INFO) << "Loading thumbnail for series " << seriesId; |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
331 LayerWidget* thumbnailWidget = new LayerWidget(broker_, "thumbnail-series-" + seriesId); |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
332 thumbnails_.push_back(thumbnailWidget); |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
270
diff
changeset
|
333 thumbnailsLayout_->AddWidget(thumbnailWidget); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
334 thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, LayerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged)); |
270 | 335 thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0)); |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
336 thumbnailWidget->SetInteractor(*thumbnailInteractor_); |
270 | 337 } |
235 | 338 |
270 | 339 void SelectStudy(const std::string& studyId) |
340 { | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
341 orthancApiClient_->GetJsonAsync("/studies/" + studyId, new Callable<SimpleViewerApplication, OrthancApiClient::NewGetJsonResponseReadyMessage>(*this, &SimpleViewerApplication::OnStudyReceived)); |
270 | 342 } |
343 | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
344 void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
345 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
346 message.origin_.SetDefaultView(); |
242 | 347 } |
237
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
235
diff
changeset
|
348 |
279
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
349 void SelectSeriesInMainViewport(const std::string& seriesId) |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
350 { |
8f5d7495076d
SimpleViewer sample working in SDL, Qt and WASM
am@osimis.io
parents:
274
diff
changeset
|
351 mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0)); |
287 | 352 #if ORTHANC_ENABLE_WASM==1 |
353 NotifyStatusUpdateFromCppToWeb("series-description=" + seriesTags_[seriesId]["MainDicomTags"]["SeriesDescription"].asString()); | |
354 #endif | |
249 | 355 } |
285
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
356 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
357 virtual void OnPushButton1Clicked() {} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
358 virtual void OnPushButton2Clicked() {} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
359 virtual void OnTool1Clicked() { currentTool_ = Tools_LineMeasure;} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
360 virtual void OnTool2Clicked() { currentTool_ = Tools_CircleMeasure;} |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
361 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
362 virtual void GetButtonNames(std::string& pushButton1, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
363 std::string& pushButton2, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
364 std::string& tool1, |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
365 std::string& tool2 |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
366 ) { |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
367 tool1 = "line"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
368 tool2 = "circle"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
369 pushButton1 = "action1"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
370 pushButton2 = "action2"; |
3c190e2bb3af
refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
281
diff
changeset
|
371 } |
287 | 372 |
373 #if ORTHANC_ENABLE_WASM==1 | |
374 virtual void HandleMessageFromWeb(std::string& output, const std::string& input) { | |
375 if (input == "select-tool:line-measure") | |
376 { | |
377 currentTool_ = Tools_LineMeasure; | |
378 NotifyStatusUpdateFromCppToWeb("currentTool=line-measure"); | |
379 } | |
380 else if (input == "select-tool:circle-measure") | |
381 { | |
382 currentTool_ = Tools_CircleMeasure; | |
383 NotifyStatusUpdateFromCppToWeb("currentTool=circle-measure"); | |
384 } | |
385 | |
386 output = "ok"; | |
387 } | |
388 | |
389 virtual void NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage) { | |
390 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str()); | |
391 } | |
392 | |
393 virtual void InitializeWasm() { | |
394 | |
395 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_); | |
396 AttachWidgetToWasmViewport("canvas2", mainWidget_); | |
397 } | |
398 #endif | |
235 | 399 }; |
249 | 400 |
401 | |
235 | 402 } |
403 } |