CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxAcquisitionData.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 "cxAcquisitionData.h"
34 
35 //#include "cxAcquisitionManager.h"
36 #include <vector>
37 #include <QDomNode>
38 #include <QDateTime>
39 #include <QStringList>
40 #include "cxTime.h"
41 #include "cxLogger.h"
42 #include "cxTrackingService.h"
43 #include "cxSettings.h"
45 #include "cxReporter.h"
46 
47 namespace cx
48 {
50 {}
51 
53  mServices(services),
54  mReconstructer(reconstructer)
55 {
56 
57 }
58 
60 {
61 }
62 
64 {
65  mRecordSessions.clear();
67 }
68 
70 {
71  mRecordSessions.push_back(session);
73 }
74 
76 {
77  std::vector<RecordSessionPtr>::iterator it = mRecordSessions.begin();
78  while (it != mRecordSessions.end())
79  {
80  std::vector<RecordSessionPtr>::iterator current = it;
81  ++it;
82  if((*current)->getUid() == session->getUid())
83  mRecordSessions.erase(current);
84  }
86 }
87 
88 std::vector<RecordSessionPtr> AcquisitionData::getRecordSessions()
89 {
90  return mRecordSessions;
91 }
92 
94 {
95  RecordSessionPtr retval;
96  std::vector<RecordSessionPtr>::iterator it = mRecordSessions.begin();
97  for(; it != mRecordSessions.end(); ++it)
98  {
99  if((*it)->getUid() == uid)
100  retval = (*it);
101  }
102  return retval;
103 }
104 
105 void AcquisitionData::addXml(QDomNode& parentNode)
106 {
107  QDomDocument doc = parentNode.ownerDocument();
108  QDomElement base = doc.createElement("stateManager");
109  parentNode.appendChild(base);
110 
111  QDomElement sessionsNode = doc.createElement("recordSessions");
112  std::vector<RecordSessionPtr>::iterator it = mRecordSessions.begin();
113  for(; it != mRecordSessions.end(); ++it)
114  {
115  QDomElement sessionNode = doc.createElement("recordSession");
116  (*it)->addXml(sessionNode);
117  sessionsNode.appendChild(sessionNode);
118  }
119  base.appendChild(sessionsNode);
120 }
121 
122 void AcquisitionData::parseXml(QDomNode& dataNode)
123 {
124  QDomNode recordsessionsNode = dataNode.namedItem("recordSessions");
125  QDomElement recodesessionNode = recordsessionsNode.firstChildElement("recordSession");
126  for (; !recodesessionNode.isNull(); recodesessionNode = recodesessionNode.nextSiblingElement("recordSession"))
127  {
128  RecordSessionPtr session(new RecordSession("", 0,0,""));
129  session->parseXml(recodesessionNode);
130  this->addRecordSession(session);
131  }
132 }
133 
138 {
139  QString retval;
140  int max = 0;
141  std::vector<RecordSessionPtr> recordsessions = this->getRecordSessions();
142  std::vector<RecordSessionPtr>::iterator iter;
143  for (iter = recordsessions.begin(); iter != recordsessions.end(); ++iter)
144  {
145  QString index = (*iter)->getUid().split("_").front();
146  max = std::max(max, index.toInt());
147  }
148 
149  // retval = qstring_cast(max + 1);
150  retval = QString("%1").arg(max + 1, 2, 10, QChar('0'));
151  retval += "_" + QDateTime::currentDateTime().toString(timestampSecondsFormat());
152  return retval;
153 }
154 
155 
159 
160 Acquisition::Acquisition(AcquisitionDataPtr pluginData, QObject* parent) :
161  QObject(parent), mPluginData(pluginData), mCurrentState(AcquisitionService::sNOT_RUNNING)
162 {
163 }
164 
166 {
167 }
168 
170 {
172  this->stopRecord();
173  else
174  this->startRecord();
175 }
176 
178 {
180  {
181  report("Already recording a session, stop before trying to start a new record session.");
182  return;
183  }
184 
185  double startTime = getMilliSecondsSinceEpoch();
186  mLatestSession.reset(new cx::RecordSession(mPluginData->getNewUid(), startTime, startTime, settings()->value("Ultrasound/acquisitionName").toString()));
187  reporter()->playStartSound();
188  this->setState(AcquisitionService::sRUNNING);
189 }
190 
192 {
194  {
195  return;
196  }
197 
198  mLatestSession->setStopTime(getMilliSecondsSinceEpoch());
199  mPluginData->addRecordSession(mLatestSession);
200 // trackingService()->savePositionHistory(); //asks all the tools to save their transforms and timestamps
201  reporter()->playStopSound();
202  this->setState(AcquisitionService::sNOT_RUNNING);
203 }
204 
206 {
208  {
209  return;
210  }
211  reporter()->playCancelSound();
212  mLatestSession.reset();
213  this->setState(AcquisitionService::sNOT_RUNNING);
214 }
215 
217 {
218  this->setState(AcquisitionService::sPOST_PROCESSING);
219 }
220 
222 {
223  this->setState(AcquisitionService::sNOT_RUNNING);
224 }
225 
226 void Acquisition::setState(AcquisitionService::STATE newState)
227 {
228  AcquisitionService::STATE lastState = mCurrentState;
229  mCurrentState = newState;
230 
231  // emit some helper signals
233  emit started();
234  else if (lastState==AcquisitionService::sRUNNING && newState!=AcquisitionService::sRUNNING && mLatestSession)
235  emit acquisitionStopped();
236  else if (lastState==AcquisitionService::sRUNNING && newState!=AcquisitionService::sRUNNING && !mLatestSession)
237  emit cancelled();
238 
239  emit stateChanged();
240 }
241 
242 
243 }
Acqusition services abstract interface.
boost::shared_ptr< class UsReconstructionService > UsReconstructionServicePtr
ReporterPtr reporter()
Definition: cxReporter.cpp:59
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
std::vector< RecordSessionPtr > getRecordSessions()
void removeRecordSession(RecordSessionPtr session)
double getMilliSecondsSinceEpoch()
Definition: cxTime.cpp:65
void addXml(QDomNode &dataNode)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
QString timestampSecondsFormat()
Definition: cxTime.cpp:39
boost::shared_ptr< class AcquisitionData > AcquisitionDataPtr
boost::shared_ptr< class RecordSession > RecordSessionPtr
AcquisitionService::STATE getState() const
void recordedSessionsChanged()
void addRecordSession(RecordSessionPtr session)
void parseXml(QDomNode &dataNode)
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void report(QString msg)
Definition: cxLogger.cpp:90
RecordSessionPtr getRecordSession(QString uid)
Acquisition(AcquisitionDataPtr pluginData, QObject *parent=0)
void acquisitionStopped()