CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxStateServiceImpl.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxStateServiceImpl.h"
34 
35 
36 
37 #include <iostream>
38 #include <QApplication>
39 #include <QByteArray>
40 #include <QDir>
41 #include "cxDefinitions.h"
42 #include "cxEnumConverter.h"
43 #include "cxXmlOptionItem.h"
44 
45 #include "cxSettings.h"
46 #include "cxDataLocations.h"
47 #include "cxWorkflowStateMachine.h"
48 #include "cxDataLocations.h"
49 #include "cxConfig.h"
50 #include "cxVLCRecorder.h"
51 #include "cxStateServiceBackend.h"
52 
53 #include "cxTrackingServiceProxy.h"
55 #include "cxSpaceProviderImpl.h"
56 #include "cxVideoServiceProxy.h"
57 #include "cxApplicationsParser.h"
58 #include "cxProfile.h"
59 #include "cxLogger.h"
60 
61 namespace cx
62 {
63 
64 
65 StateServiceImpl::StateServiceImpl(ctkPluginContext* context)
66 {
67  this->initialize(this->createBackend(context));
68 }
69 
70 StateServiceBackendPtr StateServiceImpl::createBackend(ctkPluginContext* context)
71 {
74  SpaceProviderPtr spacer(new SpaceProviderImpl(tracker, pasm));
76 
77  StateServiceBackendPtr backend;
78  backend.reset(new StateServiceBackend(tracker, video, spacer, pasm));
79  return backend;
80 }
81 
83 {
84 }
85 
87 {
88  return false;
89 }
90 
91 void StateServiceImpl::initialize(StateServiceBackendPtr backend)
92 {
93  mBackend = backend;
94  this->fillDefaultSettings();
95 
97 
98 // mApplicationStateMachine.reset(new ApplicationStateMachine(mBackend));
99 // mApplicationStateMachine->start();
100 
101  mWorkflowStateMachine.reset(new WorkflowStateMachine(mBackend));
102  mWorkflowStateMachine->start();
103 
104  connect(mWorkflowStateMachine.get(), &WorkflowStateMachine::activeStateChanged, this, &StateServiceImpl::workflowStateChanged);
106 
108 // connect(mApplicationStateMachine.get(), &ApplicationStateMachine::activeStateChanged, this, &StateServiceImpl::applicationStateChanged);
109 }
110 
111 //QActionGroup* StateServiceImpl::getApplicationActions()
112 //{
113 // mActionGroup = new QActionGroup(this);
114 
115 
116 // return mApplicationStateMachine->getActionGroup();
117 //}
118 
119 //QActionGroup* ApplicationStateMachine::getActionGroup()
120 //{
121 // QString active = this->getActiveUidState();
122 // mActionGroup->setExclusive(true);
123 // //TODO rebuild action list when we need dynamic lists. Must rethink memory management then.
124 // for (ApplicationStateMap::iterator iter = mStates.begin(); iter != mStates.end(); ++iter)
125 // {
126 // iter->second->createAction(mActionGroup);
127 // }
128 
129 // return mActionGroup;
130 //}
131 
132 //QAction* ApplicationState::createAction(QActionGroup* group)
133 //{
134 // if (mAction)
135 // return mAction;
136 
137 // mAction = new QAction(this->getName(), group);
138 // mAction->setCheckable(true);
139 // mAction->setChecked(mActive);
140 // mAction->setData(QVariant(this->getUid()));
141 
142 // connect(mAction, SIGNAL(triggered()), this, SLOT(setActionSlot()));
143 
144 // return mAction;
145 //}
146 
147 //QString PresetWidget::getNewPresetName(bool withoutSpaces = false)
148 //{
149 // QString retval;
150 
151 // // generate a name suggestion: identical if custom, appended by index if default.
152 // QString newName = PresetWidget::getCurrentPreset();
153 // if (!mPresets->getPresetList("").contains(newName))
154 // newName = "custom preset";
155 // if (mPresets->isDefaultPreset(newName))
156 // newName += "(2)";
157 
158 // bool ok;
159 // QString text = QInputDialog::getText(this, "Save Preset",
160 // "Custom Preset Name", QLineEdit::Normal, newName, &ok);
161 // if (!ok || text.isEmpty())
162 // text = newName;
163 
164 // retval = text;
165 // if(withoutSpaces)
166 // retval = retval.replace(" ", "-");
167 
168 // return retval;
169 //}
170 
172 {
173  return ProfileManager::getInstance()->activeProfile()->getUid();
174 // if (!mApplicationStateMachine)
175 // return "";
176 // return mApplicationStateMachine->getActiveStateName();
177 }
178 
180 {
182 // return mApplicationStateMachine->getAllApplicationNames();
183 }
184 
186 {
187  return QString("%1").arg(CustusX_VERSION_STRING);
188 }
189 
191 {
192  return mWorkflowStateMachine->getActionGroup();
193 }
194 
195 WorkflowStateMachinePtr StateServiceImpl::getWorkflow()
196 {
197  return mWorkflowStateMachine;
198 }
199 
201 {
202  mWorkflowStateMachine->setActiveState(uid);
203 }
204 
205 //ApplicationStateMachinePtr StateServiceImpl::getApplication()
206 //{
207 // return mApplicationStateMachine;
208 //}
209 
210 template<class T>
211 void StateServiceImpl::fillDefault(QString name, T value)
212 {
213  settings()->fillDefault(name, value);
214 }
215 
219 void StateServiceImpl::fillDefaultSettings()
220 {
221  this->fillDefault("Automation/autoStartTracking", true);
222  this->fillDefault("Automation/autoStartStreaming", true);
223  this->fillDefault("Automation/autoReconstruct", true);
224  this->fillDefault("Automation/autoSelectActiveTool", true);
225  this->fillDefault("Automation/autoSave", true);
226  this->fillDefault("Automation/autoLoadRecentPatient", true);
227  this->fillDefault("Automation/autoLoadRecentPatientWithinHours", 8);
228  this->fillDefault("Automation/autoShowNewData", false);
229 
230  this->fillDefault("TrackingPositionFilter/enabled", false);
231 
232  this->fillDefault("renderingInterval", 33);
233  this->fillDefault("backgroundColor", QColor("black"));
234  this->fillDefault("vlcPath", vlc()->getVLCPath());
235  this->fillDefault("globalPatientNumber", 1);
236  this->fillDefault("Ultrasound/acquisitionName", "US-Acq");
237  this->fillDefault("Ultrasound/8bitAcquisitionData", false);
238  this->fillDefault("Ultrasound/CompressAcquisition", true);
239  this->fillDefault("View3D/sphereRadius", 1.0);
240  this->fillDefault("View3D/labelSize", 2.5);
241  this->fillDefault("View3D/showOrientationAnnotation", true);
242  this->fillDefault("Navigation/anyplaneViewOffset", 0.25);
243  this->fillDefault("Navigation/followTooltip", true);
244  this->fillDefault("Navigation/followTooltipBoundary", 0.1);
245 
246 // QStringList grabber = this->getDefaultGrabberServer();
247 // if (grabber.size()>0)
248 // {
249 // this->fillDefault("IGTLink/localServer", grabber[0]);
250 // grabber.pop_front();
251 // if (grabber.size()>0)
252 // {
253 // this->fillDefault("IGTLink/arguments", grabber.join(" "));
254 // this->fillDefault("IGTLink/directLinkArgumentHistory", QStringList() << grabber.join(" "));
255 // }
256 // }
257 
258 // this->fillDefault("IGTLink/initScript", this->getDefaultGrabberInitScript());
259 
260  this->fillDefault("showSectorInRTView", true);
261  this->fillDefault("View3D/stereoType", stFRAME_SEQUENTIAL);
262  this->fillDefault("View3D/eyeAngle", 4.0);
263  this->fillDefault("View/showDataText", true);
264  this->fillDefault("View/showLabels", true);
265  this->fillDefault("View/showMetricNamesInCorner", false);
266  this->fillDefault("View3D/annotationModelSize", 0.2);
267  this->fillDefault("View3D/annotationModel", "woman.stl");
268  this->fillDefault("View3D/depthPeeling", false);
269  this->fillDefault("View3D/ImageRender3DVisualizer", "vtkGPUVolumeRayCastMapper");
270  this->fillDefault("View3D/maxRenderSize", 10 * pow(10.0,6));
271 
272  this->fillDefault("stillUpdateRate", 0.001);
273 
274 #ifdef __APPLE__
275  this->fillDefault("useGPU2DRendering", true);
276 #elif WIN32
277  this->fillDefault("useGPU2DRendering", false);
278 #else
279  this->fillDefault("useGPU2DRendering", true);
280 #endif
281 
282  this->fillDefault("optimizedViews", true);
283  this->fillDefault("smartRender", true);
284 
285  this->fillDefault("IGSTKDebugLogging", false);
286  this->fillDefault("giveManualToolPhysicalProperties", false);
287  this->fillDefault("renderSpeedLogging", false);
288 
289  this->fillDefault("applyTransferFunctionPresetsToAll", false);
290 
291  this->fillDefault("USsimulation/type", "Original data");
292  this->fillDefault("USsimulation/volume", "");
293  this->fillDefault("USsimulation/gain", 0.70);
294 }
295 
296 
298 {
299  ApplicationsParser parser;
300  return parser.getDesktop(mWorkflowStateMachine->getActiveUidState());
301 }
302 
304 {
305  ApplicationsParser parser;
306  parser.setDesktop(mWorkflowStateMachine->getActiveUidState(),
307  desktop);
308 }
309 
311 {
312  ApplicationsParser parser;
313  parser.resetDesktop(mWorkflowStateMachine->getActiveUidState());
314 }
315 
316 } //namespace cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
virtual QActionGroup * getWorkflowActions()
void activeProfileChanged()
boost::shared_ptr< class VideoService > VideoServicePtr
virtual void setWorkFlowState(QString uid)
ProfilePtr activeProfile()
Definition: cxProfile.cpp:267
virtual void saveDesktop(Desktop desktop)
void applicationStateChanged()
void setDesktop(QString workflowName, Desktop desktop)
boost::shared_ptr< class TrackingService > TrackingServicePtr
static void initialize()
Definition: cxProfile.cpp:158
virtual Desktop getActiveDesktop()
QStringList getProfiles()
Definition: cxProfile.cpp:238
static VideoServicePtr create(ctkPluginContext *pluginContext)
virtual QString getVersionName()
stFRAME_SEQUENTIAL
static TrackingServicePtr create(ctkPluginContext *pluginContext)
virtual QStringList getAllApplicationStateNames() const
void resetDesktop(QString workflowName)
static PatientModelServicePtr create(ctkPluginContext *pluginContext)
boost::shared_ptr< class StateServiceBackend > StateServiceBackendPtr
StateServiceImpl(ctkPluginContext *context)
void workflowStateAboutToChange()
static ProfileManager * getInstance()
returns the only instance of this class
Definition: cxProfile.cpp:149
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual QString getApplicationStateName() const
boost::shared_ptr< class WorkflowStateMachine > WorkflowStateMachinePtr
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void workflowStateChanged()
Data class for CustusX desktop.
State Machine for the Workflow Steps.
void fillDefault(QString name, T value)
Definition: cxSettings.h:85
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.
Desktop getDesktop(QString workflowName)