NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxAcquisitionImplService.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 
34 #include "cxAcquisitionData.h"
35 #include "cxUSAcquisition.h"
39 #include "cxXMLNodeWrapper.h"
40 #include "cxVisServices.h"
41 
42 namespace cx
43 {
44 
46  mContext(context),
47  mUsReconstructService(new UsReconstructionServiceProxy(context))
48 {
49  mServices = VisServices::create(context);
50  mAcquisitionData.reset(new AcquisitionData(mServices, mUsReconstructService));
51  mAcquisition.reset(new Acquisition(mAcquisitionData));
52  mUsAcquisition.reset(new USAcquisition(mAcquisition));
53 
54  connect(mAcquisition.get(), &Acquisition::started, this, &AcquisitionService::started);
55  connect(mAcquisition.get(), &Acquisition::cancelled, this, &AcquisitionService::cancelled);
56  connect(mAcquisition.get(), &Acquisition::stateChanged, this, &AcquisitionService::stateChanged);
57  connect(mAcquisition.get(), &Acquisition::acquisitionStopped, this, &AcquisitionService::acquisitionStopped);
58  connect(mAcquisition.get(), &Acquisition::readinessChanged, this, &AcquisitionService::usReadinessChanged);
59 
61 
63  connect(mUsAcquisition.get(), &USAcquisition::saveDataCompleted, this, &AcquisitionService::saveDataCompleted);
64  connect(mUsAcquisition.get(), &USAcquisition::readinessChanged, this, &AcquisitionService::usReadinessChanged);
65 
66  connect(mServices->session().get(), &SessionStorageService::cleared, this, &AcquisitionImplService::duringClearPatientSlot);
67  connect(mServices->session().get(), &SessionStorageService::isLoading, this, &AcquisitionImplService::duringLoadPatientSlot);
68  connect(mServices->session().get(), &SessionStorageService::isSaving, this, &AcquisitionImplService::duringSavePatientSlot);
69 }
70 
72 {
73 }
74 
76 {
77  return false;
78 }
79 
80 void AcquisitionImplService::duringClearPatientSlot()
81 {
82  // clear data?
83  mAcquisitionData->clear();//TODO: Check if wee need this
84 }
85 
86 void AcquisitionImplService::duringSavePatientSlot(QDomElement& node)
87 {
88  XMLNodeAdder root(node);
89  QDomElement managerNode = root.descend("managers").node().toElement();
90  this->addXml(managerNode);
91 }
92 
93 void AcquisitionImplService::duringLoadPatientSlot(QDomElement& node)
94 {
95  XMLNodeParser root(node);
96  QDomElement stateManagerNode = root.descend("managers/stateManager").node().toElement();
97  if (!stateManagerNode.isNull())
98  this->parseXml(stateManagerNode);
99 }
100 
102 {
103  return mAcquisition->getLatestSession();
104 }
105 
106 std::vector<RecordSessionPtr> AcquisitionImplService::getSessions()
107 {
108  return mAcquisition->getPluginData()->getRecordSessions();
109 }
110 
112 {
113  return mUsAcquisition->isReady(context)
114  && mAcquisition->isReady(context);
115 }
116 
118 {
119  QString text;
120  text = mAcquisition->getInfoText(context) + "<br>" + mUsAcquisition->getInfoText(context);
121 
122  // remove redundant line breaks
123  QStringList list = text.split("<br>", QString::SkipEmptyParts);
124  text = list.join("<br>");
125 
126  //Make sure we have at least 2 lines to avoid "bouncing buttons"
127  if (list.size() < 2)
128  text.append("<br>");
129 
130  return text;
131 }
132 
134 {
135  return mAcquisition->getState();
136 }
137 
138 void AcquisitionImplService::startRecord(TYPES context, QString category, RecordSessionPtr session)
139 {
140  mAcquisition->startRecord(context, category, session);
141 }
142 
144 {
145  mAcquisition->stopRecord();
146 }
147 
149 {
150  mAcquisition->cancelRecord();
151 }
152 
154 {
155  mAcquisition->startPostProcessing();
156 }
157 
159 {
160  mAcquisition->stopPostProcessing();
161 }
162 
164 {
165  return mUsAcquisition->getNumberOfSavingThreads();
166 }
167 
168 void AcquisitionImplService::addXml(QDomNode &dataNode)
169 {
170  mAcquisitionData->addXml(dataNode);
171 }
172 
173 void AcquisitionImplService::parseXml(QDomNode &dataNode)
174 {
175  mAcquisitionData->parseXml(dataNode);
176 }
177 
178 } // cx
AcquisitionImplService(ctkPluginContext *context)
virtual bool isReady(TYPES context) const
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value...
void saveDataCompleted(QString mhdFilename)
emitted when data has been saved to file
void readinessChanged()
void saveDataCompleted(QString mhdFilename)
emitted when data has been saved to file
virtual int getNumberOfSavingThreads() const
static VisServicesPtr create(ctkPluginContext *context)
virtual QString getInfoText(TYPES context) const
virtual void startRecord(TYPES context, QString category, RecordSessionPtr session)
boost::shared_ptr< class RecordSession > RecordSessionPtr
void recordedSessionsChanged()
void cleared()
emitted when session is cleared, before isLoading is called
void acquisitionDataReady()
emitted when data is acquired and sent to the reconstruction module
virtual RecordSessionPtr getLatestSession()
void acquisitionStopped()
void acquisitionDataReady()
emitted when data is acquired and sent to the reconstruction module
void isSaving(QDomElement &root)
xml storage is available
Handles the us acquisition process.The USAcquisition object attaches itself to an input Acquisition o...
virtual std::vector< RecordSessionPtr > getSessions()