CustusX  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMetricReferenceArgumentList.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 "cxData.h"
35 #include "cxPointMetric.h"
36 #include <QDomNode>
37 #include "cxTypeConversions.h"
38 
39 namespace cx
40 {
41 
43  QObject(NULL)
44 {
45  mArgument.resize(descriptions.size());
46  mDescriptions = descriptions;
47  this->setValidArgumentTypes(QStringList() << "pointMetric");
48 }
49 
51 {
52  mValidTypes = types;
53 }
54 
56 {
57  if (mArgument[index] == p)
58  return;
59 
60  if (mArgument[index])
61  {
62  disconnect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
63  disconnect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
64  }
65 
66  mArgument[index] = p;
67 
68  if (mArgument[index])
69  {
70  connect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
71  connect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
72  }
73 
74  emit argumentsChanged();
75 }
76 
78 {
79  return mArgument[index];
80 }
81 
83 {
84  if (!p)
85  return false;
86  return mValidTypes.contains(p->getType());
87 }
88 
90 {
91  return (unsigned)mArgument.size();
92 }
93 
95 {
96  return mDescriptions[index];
97 }
98 
99 std::vector<Vector3D> MetricReferenceArgumentList::getRefCoords() const
100 {
101  std::vector<Vector3D> p(this->getCount());
102  for (unsigned i = 0; i < p.size(); ++i)
103  {
104  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mArgument[i]);
105  if (!metric)
106  return std::vector<Vector3D>();
107  p[i] = metric->getRefCoord();
108  }
109  return p;
110 }
111 
112 void MetricReferenceArgumentList::addXml(QDomNode& dataNode)
113 {
114  for (unsigned i = 0; i < mArgument.size(); ++i)
115  {
116  if (mArgument[i])
117  dataNode.toElement().setAttribute(QString("p%1").arg(i), mArgument[i]->getUid());
118  }
119 }
120 
121 void MetricReferenceArgumentList::parseXml(QDomNode& dataNode, const std::map<QString, DataPtr>& data)
122 {
123  for (unsigned i = 0; i < mArgument.size(); ++i)
124  {
125  QString uid = dataNode.toElement().attribute(QString("p%1").arg(i), "");
126  if (!data.count(uid))
127  continue;
128  this->set(i, data.find(uid)->second);
129  }
130 }
131 
132 } // namespace cx
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:95
virtual void parseXml(QDomNode &dataNode, const std::map< QString, DataPtr > &data)
virtual void addXml(QDomNode &dataNode)
boost::shared_ptr< class Data > DataPtr
std::vector< Vector3D > getRefCoords() const
MetricReferenceArgumentList(QStringList descriptions)
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
virtual Vector3D getRefCoord() const =0