Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "cxAcquisitionData.h"
14 #include "cxUSAcquisition.h"
18 #include "cxXMLNodeWrapper.h"
19 #include "cxVisServices.h"
20 #include "cxTrackingService.h"
21 
22 namespace cx
23 {
24 
26  mContext(context),
27  mUsReconstructService(new UsReconstructionServiceProxy(context))
28 {
29  mServices = VisServices::create(context);
30  mAcquisitionData.reset(new AcquisitionData(mServices, mUsReconstructService));
31  mAcquisition.reset(new Acquisition(mAcquisitionData));
32  mUsAcquisition.reset(new USAcquisition(mAcquisition));
33 
34  connect(mAcquisition.get(), &Acquisition::started, this, &AcquisitionService::started);
35  connect(mAcquisition.get(), &Acquisition::cancelled, this, &AcquisitionService::cancelled);
36  connect(mAcquisition.get(), &Acquisition::stateChanged, this, &AcquisitionService::stateChanged);
37  connect(mAcquisition.get(), &Acquisition::acquisitionStopped, this, &AcquisitionService::acquisitionStopped);
38  connect(mAcquisition.get(), &Acquisition::readinessChanged, this, &AcquisitionService::usReadinessChanged);
39 
41 
43  connect(mUsAcquisition.get(), &USAcquisition::saveDataCompleted, this, &AcquisitionService::saveDataCompleted);
44  connect(mUsAcquisition.get(), &USAcquisition::readinessChanged, this, &AcquisitionService::usReadinessChanged);
45 
46  connect(mServices->session().get(), &SessionStorageService::cleared, this, &AcquisitionImplService::duringClearPatientSlot);
47  connect(mServices->session().get(), &SessionStorageService::isLoading, this, &AcquisitionImplService::duringLoadPatientSlot);
48  connect(mServices->session().get(), &SessionStorageService::isSaving, this, &AcquisitionImplService::duringSavePatientSlot);
49 }
50 
52 {
53 }
54 
56 {
57  return false;
58 }
59 
60 void AcquisitionImplService::duringClearPatientSlot()
61 {
62  // clear data?
63  mAcquisitionData->clear();//TODO: Check if wee need this
64 }
65 
66 void AcquisitionImplService::duringSavePatientSlot(QDomElement& node)
67 {
68  XMLNodeAdder root(node);
69  QDomElement managerNode = root.descend("managers").node().toElement();
70  this->addXml(managerNode);
71 }
72 
73 void AcquisitionImplService::duringLoadPatientSlot(QDomElement& node)
74 {
75  XMLNodeParser root(node);
76  QDomElement stateManagerNode = root.descend("managers/stateManager").node().toElement();
77  if (!stateManagerNode.isNull())
78  this->parseXml(stateManagerNode);
79 }
80 
82 {
83  return mAcquisition->getLatestSession();
84 }
85 
86 std::vector<RecordSessionPtr> AcquisitionImplService::getSessions()
87 {
88  return mAcquisition->getPluginData()->getRecordSessions();
89 }
90 
92 {
93  return mUsAcquisition->isReady(context)
94  && mAcquisition->isReady(context);
95 }
96 
98 {
99  QString text;
100  text = mAcquisition->getInfoText(context) + "<br>" + mUsAcquisition->getInfoText(context);
101 
102  // remove redundant line breaks
103  QStringList list = text.split("<br>", QString::SkipEmptyParts);
104  text = list.join("<br>");
105 
106  //Make sure we have at least 2 lines to avoid "bouncing buttons"
107  if (list.size() < 2)
108  text.append("<br>");
109 
110  return text;
111 }
112 
114 {
115  return mAcquisition->getState();
116 }
117 
118 void AcquisitionImplService::startRecord(TYPES context, QString category, RecordSessionPtr session)
119 {
120  mServices->tracking()->resetTimeSynchronization();
121  mAcquisition->startRecord(context, category, session);
122 }
123 
125 {
126  mAcquisition->stopRecord();
127 }
128 
130 {
131  mAcquisition->cancelRecord();
132 }
133 
135 {
136  mAcquisition->startPostProcessing();
137 }
138 
140 {
141  mAcquisition->stopPostProcessing();
142 }
143 
145 {
146  return mUsAcquisition->getNumberOfSavingThreads();
147 }
148 
149 void AcquisitionImplService::addXml(QDomNode &dataNode)
150 {
151  mAcquisitionData->addXml(dataNode);
152 }
153 
154 void AcquisitionImplService::parseXml(QDomNode &dataNode)
155 {
156  mAcquisitionData->parseXml(dataNode);
157 }
158 
159 } // 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
XMLNodeAdder descend(QString path)
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()
XMLNodeParser descend(QString path)
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()
Namespace for all CustusX production code.