CustusX  15.8
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("backgroundColor", QColor(30,60,70)); // a dark, grey-blue hue
159  this->fillDefault("vlcPath", vlc()->getVLCPath());
160  this->fillDefault("globalPatientNumber", 1);
161  this->fillDefault("Ultrasound/acquisitionName", "US-Acq");
162  this->fillDefault("Ultrasound/8bitAcquisitionData", false);
163  this->fillDefault("Ultrasound/CompressAcquisition", true);
164  this->fillDefault("View3D/sphereRadius", 1.0);
165  this->fillDefault("View3D/labelSize", 2.5);
166  this->fillDefault("View3D/showOrientationAnnotation", true);
167  this->fillDefault("Navigation/anyplaneViewOffset", 0.25);
168  this->fillDefault("Navigation/followTooltip", true);
169  this->fillDefault("Navigation/followTooltipBoundary", 0.1);
170 
171  this->fillDefault("showSectorInRTView", true);
172  this->fillDefault("View3D/stereoType", stFRAME_SEQUENTIAL);
173  this->fillDefault("View3D/eyeAngle", 4.0);
174  this->fillDefault("View/showDataText", true);
175  this->fillDefault("View/showLabels", true);
176  this->fillDefault("View/showMetricNamesInCorner", false);
177  this->fillDefault("View3D/annotationModelSize", 0.2);
178  this->fillDefault("View3D/annotationModel", "woman.stl");
179  this->fillDefault("View3D/depthPeeling", false);
180  this->fillDefault("View3D/ImageRender3DVisualizer", "vtkGPUVolumeRayCastMapper");
181  this->fillDefault("View3D/maxRenderSize", 10 * pow(10.0,6));
182 
183  this->fillDefault("stillUpdateRate", 0.001);
184 
185 #ifdef __APPLE__
186  this->fillDefault("useGPU2DRendering", true);
187 #elif WIN32
188  this->fillDefault("useGPU2DRendering", false);
189 #else
190  this->fillDefault("useGPU2DRendering", true);
191 #endif
192 
193  this->fillDefault("optimizedViews", true);
194  this->fillDefault("smartRender", true);
195 
196  this->fillDefault("IGSTKDebugLogging", false);
197  this->fillDefault("giveManualToolPhysicalProperties", false);
198  this->fillDefault("renderSpeedLogging", false);
199 
200  this->fillDefault("applyTransferFunctionPresetsToAll", false);
201 
202  this->fillDefault("USsimulation/type", "Original data");
203  this->fillDefault("USsimulation/volume", "");
204  this->fillDefault("USsimulation/gain", 0.70);
205 }
206 
207 
209 {
210  ApplicationsParser parser;
211  return parser.getDesktop(mWorkflowStateMachine->getActiveUidState());
212 }
213 
215 {
216  ApplicationsParser parser;
217  parser.setDesktop(mWorkflowStateMachine->getActiveUidState(),
218  desktop);
219 }
220 
222 {
223  ApplicationsParser parser;
224  parser.resetDesktop(mWorkflowStateMachine->getActiveUidState());
225 }
226 
227 } //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:294
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:185
virtual Desktop getActiveDesktop()
QStringList getProfiles()
Definition: cxProfile.cpp:265
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:176
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:81
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.
Desktop getDesktop(QString workflowName)