CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRecordSession.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 #include "cxRecordSession.h"
33 
34 #include <QDomDocument>
35 #include <QDomElement>
36 #include "cxTypeConversions.h"
37 #include "cxLogger.h"
38 #include "cxTime.h"
39 #include "cxTool.h"
40 
41 namespace cx
42 {
43 RecordSession::RecordSession(QString uid, double startTime, double stopTime, QString description) :
44  mStartTime(startTime),
45  mStopTime(stopTime),
46  mDescription(description)
47 {
48  mUid = uid;
49  mDescription.append("_"+mUid+"");
50 }
51 
53 {}
54 
56 {
57  return mUid;
58 }
59 
61 {
62  return mDescription;
63 }
64 
66 {
67  return mStartTime;
68 }
69 
71 {
72  return mStopTime;
73 }
74 
75 void RecordSession::addXml(QDomNode& parentNode)
76 {
77  QDomDocument doc = parentNode.ownerDocument();
78 
79  parentNode.toElement().setAttribute("uid", mUid);
80 
81  QDomElement startNode = doc.createElement("start");
82  startNode.appendChild(doc.createTextNode(qstring_cast(mStartTime)));
83  parentNode.appendChild(startNode);
84 
85  QDomElement stopNode = doc.createElement("stop");
86  stopNode.appendChild(doc.createTextNode(qstring_cast(mStopTime)));
87  parentNode.appendChild(stopNode);
88 
89  QDomElement descriptionNode = doc.createElement("description");
90  descriptionNode.appendChild(doc.createTextNode(mDescription));
91  parentNode.appendChild(descriptionNode);
92 }
93 
94 void RecordSession::parseXml(QDomNode& parentNode)
95 {
96  if (parentNode.isNull())
97  {
98  reportWarning("RecordSession::parseXml() parentnode is null");
99  return;
100  }
101 
102  QDomElement base = parentNode.toElement();
103 
104  mUid = base.attribute("uid");
105  bool ok;
106  mStartTime = parentNode.namedItem("start").toElement().text().toDouble(&ok);
107  mStopTime = parentNode.namedItem("stop").toElement().text().toDouble(&ok);
108  mDescription = parentNode.namedItem("description").toElement().text();
109 }
110 
112 {
113  if(!tool)
114  reportError("RecordSession::getToolHistory_prMt(): Tool missing.");
115 
116  TimedTransformMap retval;
117 
118  if(tool && session)
119  retval = tool->getSessionHistory(session->getStartTime(), session->getStopTime());
120 
121  if(retval.empty() && session)
122  {
123  reportError("RecordSession::getToolHistory_prMt(): Could not find any tracking data from session "+session->getUid()+".");
124  }
125 
126  return retval;
127 }
128 
129 }//namespace cx
QString qstring_cast(const T &val)
void reportError(QString msg)
Definition: cxLogger.cpp:92
void addXml(QDomNode &dataNode)
static TimedTransformMap getToolHistory_prMt(ToolPtr tool, RecordSessionPtr session)
boost::shared_ptr< class RecordSession > RecordSessionPtr
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
RecordSession(QString uid, double startTime, double stopTime, QString description)
void parseXml(QDomNode &dataNode)
std::map< double, Transform3D > TimedTransformMap
boost::shared_ptr< class Tool > ToolPtr