Mercurial > hg > orthanc-stone
annotate Applications/BasicApplicationContext.cpp @ 61:ca644004d2ee wasm
MAJOR - removal of Start/Stop and observers in IWidget
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 May 2017 17:55:13 +0200 |
parents | d20e25cfcf3a |
children | a4497c6449df |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "BasicApplicationContext.h" | |
23 | |
51 | 24 #include "../../Framework/Toolbox/OrthancSeriesLoader.h" |
25 #include "../../Framework/Volumes/VolumeImageSimplePolicy.h" | |
26 #include "../../Framework/Volumes/VolumeImageProgressivePolicy.h" | |
0 | 27 |
28 namespace OrthancStone | |
29 { | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
30 void BasicApplicationContext::UpdateThread(BasicApplicationContext* that) |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
31 { |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
32 while (!that->stopped_) |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
33 { |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
34 { |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
35 printf("GOSH\n"); fflush(stdout); |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
36 ViewportLocker locker(*that); |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
37 locker.GetViewport().UpdateContent(); |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
38 } |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
39 |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
40 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelay_)); |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
41 } |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
42 } |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
43 |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
44 |
57 | 45 BasicApplicationContext::BasicApplicationContext(OrthancWebService& orthanc) : |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
46 orthanc_(orthanc), |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
47 stopped_(true), |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
48 updateDelay_(100) // By default, 100ms between each refresh of the content |
0 | 49 { |
50 } | |
51 | |
52 | |
53 BasicApplicationContext::~BasicApplicationContext() | |
54 { | |
55 for (Interactors::iterator it = interactors_.begin(); it != interactors_.end(); ++it) | |
56 { | |
57 assert(*it != NULL); | |
58 delete *it; | |
59 } | |
60 | |
61 for (Volumes::iterator it = volumes_.begin(); it != volumes_.end(); ++it) | |
62 { | |
63 assert(*it != NULL); | |
64 delete *it; | |
65 } | |
66 | |
67 for (StructureSets::iterator it = structureSets_.begin(); it != structureSets_.end(); ++it) | |
68 { | |
69 assert(*it != NULL); | |
70 delete *it; | |
71 } | |
72 } | |
73 | |
74 | |
75 IWidget& BasicApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership | |
76 { | |
77 viewport_.SetCentralWidget(widget); | |
78 return *widget; | |
79 } | |
80 | |
81 | |
82 VolumeImage& BasicApplicationContext::AddSeriesVolume(const std::string& series, | |
83 bool isProgressiveDownload, | |
84 size_t downloadThreadCount) | |
85 { | |
57 | 86 std::auto_ptr<VolumeImage> volume |
87 (new VolumeImage(new OrthancSeriesLoader(GetWebService().GetConnection(), series))); | |
0 | 88 |
89 if (isProgressiveDownload) | |
90 { | |
91 volume->SetDownloadPolicy(new VolumeImageProgressivePolicy); | |
92 } | |
93 else | |
94 { | |
95 volume->SetDownloadPolicy(new VolumeImageSimplePolicy); | |
96 } | |
97 | |
98 volume->SetThreadCount(downloadThreadCount); | |
99 | |
100 VolumeImage& result = *volume; | |
101 volumes_.push_back(volume.release()); | |
102 | |
103 return result; | |
104 } | |
105 | |
106 | |
107 DicomStructureSet& BasicApplicationContext::AddStructureSet(const std::string& instance) | |
108 { | |
57 | 109 std::auto_ptr<DicomStructureSet> structureSet |
110 (new DicomStructureSet(GetWebService().GetConnection(), instance)); | |
0 | 111 |
112 DicomStructureSet& result = *structureSet; | |
113 structureSets_.push_back(structureSet.release()); | |
114 | |
115 return result; | |
116 } | |
117 | |
118 | |
119 IWorldSceneInteractor& BasicApplicationContext::AddInteractor(IWorldSceneInteractor* interactor) | |
120 { | |
121 if (interactor == NULL) | |
122 { | |
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
124 } | |
125 | |
126 interactors_.push_back(interactor); | |
127 | |
128 return *interactor; | |
129 } | |
130 | |
131 | |
132 void BasicApplicationContext::Start() | |
133 { | |
134 for (Volumes::iterator it = volumes_.begin(); it != volumes_.end(); ++it) | |
135 { | |
136 assert(*it != NULL); | |
137 (*it)->Start(); | |
138 } | |
139 | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
140 if (viewport_.HasUpdateContent()) |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
141 { |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
142 stopped_ = false; |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
143 updateThread_ = boost::thread(UpdateThread, this); |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
144 } |
0 | 145 } |
146 | |
147 | |
148 void BasicApplicationContext::Stop() | |
149 { | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
150 stopped_ = true; |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
151 |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
152 if (updateThread_.joinable()) |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
153 { |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
154 updateThread_.join(); |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
155 } |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
51
diff
changeset
|
156 |
0 | 157 for (Volumes::iterator it = volumes_.begin(); it != volumes_.end(); ++it) |
158 { | |
159 assert(*it != NULL); | |
160 (*it)->Stop(); | |
161 } | |
162 } | |
163 } |