CustusX  15.4.0-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 #include <iostream>
36 #include <QApplication>
37 #include <QByteArray>
38 #include <QDir>
39 #include "cxDefinitions.h"
40 #include "cxEnumConverter.h"
41 #include "cxXmlOptionItem.h"
42 
43 #include "cxSettings.h"
44 #include "cxDataLocations.h"
45 #include "cxWorkflowStateMachine.h"
46 #include "cxDataLocations.h"
47 #include "cxConfig.h"
48 #include "cxVLCRecorder.h"
49 #include "cxStateServiceBackend.h"
50 
51 #include "cxTrackingServiceProxy.h"
53 #include "cxSpaceProviderImpl.h"
54 #include "cxVideoServiceProxy.h"
55 #include "cxApplicationsParser.h"
56 #include "cxProfile.h"
57 #include "cxLogger.h"
58 
59 namespace cx
60 {
61 
62 StateServiceImpl::StateServiceImpl(ctkPluginContext* context)
63 {
64  this->initialize(this->createBackend(context));
65 }
66 
67 StateServiceBackendPtr StateServiceImpl::createBackend(ctkPluginContext* context)
68 {
71  SpaceProviderPtr spacer(new SpaceProviderImpl(tracker, pasm));
73 
74  StateServiceBackendPtr backend;
75  backend.reset(new StateServiceBackend(tracker, video, spacer, pasm));
76  return backend;
77 }
78 
80 {
81 }
82 
84 {
85  return false;
86 }
87 
88 void StateServiceImpl::initialize(StateServiceBackendPtr backend)
89 {
90  mBackend = backend;
91  this->fillDefaultSettings();
92 
94 
95  mWorkflowStateMachine.reset(new WorkflowStateMachine(mBackend));
96  mWorkflowStateMachine->start();
97 
98  connect(mWorkflowStateMachine.get(), &WorkflowStateMachine::activeStateChanged, this, &StateServiceImpl::workflowStateChanged);
100 
102 }
103 
105 {
106  return ProfileManager::getInstance()->activeProfile()->getUid();
107 }
108 
110 {
112 }
113 
115 {
116  return QString("%1").arg(CustusX_VERSION_STRING);
117 }
118 
120 {
121  return mWorkflowStateMachine->getActionGroup();
122 }
123 
124 WorkflowStateMachinePtr StateServiceImpl::getWorkflow()
125 {
126  return mWorkflowStateMachine;
127 }
128 
130 {
131  mWorkflowStateMachine->setActiveState(uid);
132 }
133 
134 template<class T>
135 void StateServiceImpl::fillDefault(QString name, T value)
136 {
137  settings()->fillDefault(name, value);
138 }
139 
143 void StateServiceImpl::fillDefaultSettings()
144 {
145  this->fillDefault("Automation/autoStartTracking", true);
146  this->fillDefault("Automation/autoStartStreaming", true);
147  this->fillDefault("Automation/autoReconstruct", true);
148  this->fillDefault("Automation/autoSelectActiveTool", true);
149  this->fillDefault("Automation/autoSave", true);
150  this->fillDefault("Automation/autoLoadRecentPatient", true);
151  this->fillDefault("Automation/autoLoadRecentPatientWithinHours", 8);
152  this->fillDefault("Automation/autoShowNewData", false);
153 
154  this->fillDefault("TrackingPositionFilter/enabled", false);
155 
156  this->fillDefault("renderingInterval", 33);
157  this->fillDefault("backgroundColor", QColor("black"));
158  this->fillDefault("vlcPath", vlc()->getVLCPath());
159  this->fillDefault("globalPatientNumber", 1);
160  this->fillDefault("Ultrasound/acquisitionName", "US-Acq");
161  this->fillDefault("Ultrasound/8bitAcquisitionData", false);
162  this->fillDefault("Ultrasound/CompressAcquisition", true);
163  this->fillDefault("View3D/sphereRadius", 1.0);
164  this->fillDefault("View3D/labelSize", 2.5);
165  this->fillDefault("View3D/showOrientationAnnotation", true);
166  this->fillDefault("Navigation/anyplaneViewOffset", 0.25);
167  this->fillDefault("Navigation/followTooltip", true);
168  this->fillDefault("Navigation/followTooltipBoundary", 0.1);
169 
170  this->fillDefault("showSectorInRTView", true);
171  this->fillDefault("View3D/stereoType", stFRAME_SEQUENTIAL);
172  this->fillDefault("View3D/eyeAngle", 4.0);
173  this->fillDefault("View/showDataText", true);
174  this->fillDefault("View/showLabels", true);
175  this->fillDefault("View/showMetricNamesInCorner", false);
176  this->fillDefault("View3D/annotationModelSize", 0.2);
177  this->fillDefault("View3D/annotationModel", "woman.stl");
178  this->fillDefault("View3D/depthPeeling", false);
179  this->fillDefault("View3D/ImageRender3DVisualizer", "vtkGPUVolumeRayCastMapper");
180  this->fillDefault("View3D/maxRenderSize", 10 * pow(10.0,6));
181 
182  this->fillDefault("stillUpdateRate", 0.001);
183 
184 #ifdef __APPLE__
185  this->fillDefault("useGPU2DRendering", true);
186 #elif WIN32
187  this->fillDefault("useGPU2DRendering", false);
188 #else
189  this->fillDefault("useGPU2DRendering", true);
190 #endif
191 
192  this->fillDefault("optimizedViews", true);
193  this->fillDefault("smartRender", true);
194 
195  this->fillDefault("IGSTKDebugLogging", false);
196  this->fillDefault("giveManualToolPhysicalProperties", false);
197  this->fillDefault("renderSpeedLogging", false);
198 
199  this->fillDefault("applyTransferFunctionPresetsToAll", false);
200 
201  this->fillDefault("USsimulation/type", "Original data");
202  this->fillDefault("USsimulation/volume", "");
203  this->fillDefault("USsimulation/gain", 0.70);
204 }
205 
206 
208 {
209  ApplicationsParser parser;
210  return parser.getDesktop(mWorkflowStateMachine->getActiveUidState());
211 }
212 
214 {
215  ApplicationsParser parser;
216  parser.setDesktop(mWorkflowStateMachine->getActiveUidState(),
217  desktop);
218 }
219 
221 {
222  ApplicationsParser parser;
223  parser.resetDesktop(mWorkflowStateMachine->getActiveUidState());
224 }
225 
226 } //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)