Fraxinus  17.12-rc4
An IGT application
cxDataTreeNode.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 "cxDataTreeNode.h"
33 #include "cxPatientModelService.h"
34 #include "cxDefinitions.h"
35 #include "cxData.h"
36 #include "cxTreeRepository.h"
37 #include "cxLogger.h"
38 #include "cxDataMetric.h"
39 #include "cxActiveData.h"
40 #include "cxViewService.h"
41 #include "cxViewGroupData.h"
42 #include "cxVisServices.h"
43 #include <QFont>
44 #include <QLabel>
45 #include "cxMesh.h"
46 #include "cxMeshInfoWidget.h"
48 #include "cxImage.h"
50 #include "cxDataMetric.h"
51 #include "cxMetricUtilities.h"
52 #include "cxNullDeleter.h"
53 
54 namespace cx
55 {
56 
57 
59  TreeNodeImpl(repo), mData(data)
60 {
61  // too expensive: this happens for every position change in some cases (metrics),
62  // while nothing is changed in the gui.
63 // connect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
64 }
65 
67 {
68 // disconnect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
69 }
70 
71 QString DataTreeNode::getUid() const
72 {
73  return mData->getUid();
74 }
75 
76 QString DataTreeNode::getName() const
77 {
78  return mData->getName();
79 }
80 
81 QString DataTreeNode::getType() const
82 {
83  return "data";
84 }
85 
87 {
88  QStringList visible = this->repo()->getVisibleNodeTypes();
89 
90  bool hasData = visible.contains(this->getType());
91  if (!hasData)
92  return false;
93 
94  if (boost::dynamic_pointer_cast<Mesh>(mData) && !visible.contains("model"))
95  return false;
96  if (boost::dynamic_pointer_cast<Image>(mData) && !visible.contains("image"))
97  return false;
98  if (boost::dynamic_pointer_cast<DataMetric>(mData) && !visible.contains("metric"))
99  return false;
100 
101  return true;
102 }
103 
105 {
106  if (this->repo()->getMode()=="flat")
107  return this->repo()->getNodeForGroup("data");
108 
109  if (mData->getParentSpace().isEmpty())
110  return this->repo()->getNode(CoordinateSystem(csREF).toString());
111  TreeNodePtr parent = this->repo()->getNode(mData->getParentSpace());
112  if (!parent)
113  parent = this->repo()->getNode(CoordinateSystem(csDATA, mData->getParentSpace()).toString());
114  return parent;
115 }
116 
118 {
119  this->getServices()->patient()->getActiveData()->setActive(mData);
120 }
121 
123 {
124  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
125  if (metric)
126  return this->addBackgroundColorToIcon(mData->getIcon(), metric->getColor());
127  return mData->getIcon();
128 }
129 
130 QVariant DataTreeNode::getColor() const
131 {
132  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
133  if (metric)
134  return metric->getColor();
135  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mData);
136  if (mesh)
137  return mesh->getColor();
138  return QVariant();
139 // return QColor("black");
140 }
141 
142 QVariant DataTreeNode::getFont() const
143 {
144  if (this->getServices()->patient()->getActiveData()->getActive()==mData)
145  {
146  QFont font;
147  font.setBold(true);
148  return font;
149  }
150  return QVariant();
151 }
152 
154 {
155  return (this->repo()->getMode()!="flat");
156 }
157 
159 {
160  this->getServices()->patient()->removeData(mData->getUid());
161 }
162 
163 QVariant DataTreeNode::getViewGroupVisibility(int index) const
164 {
165  DataViewProperties props = this->getServices()->view()->getGroup(index)->getProperties(mData->getUid());
166  if (props.empty())
167  return Qt::CheckState(0);
168  if ((props.hasVolume3D() || props.hasSlice3D()) && props.hasSlice2D())
169  return Qt::CheckState(2);
170  return Qt::CheckState(1);
171 // return true;
172 }
173 
174 void DataTreeNode::setViewGroupVisibility(int index, bool value)
175 {
176  if (value)
177  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties::createDefault());
178  else
179  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties());
180 }
181 
182 boost::shared_ptr<QWidget> DataTreeNode::createPropertiesWidget() const
183 {
184  WidgetTypeRepositoryPtr wrepo = this->repo()->getWidgetTypeRepository();
185 
186  if (boost::dynamic_pointer_cast<Mesh>(mData))
187  {
188  boost::shared_ptr<AllMeshPropertiesWidget> widget = wrepo->find<AllMeshPropertiesWidget>();
189  if (!widget)
190  {
191  StringPropertySelectMeshPtr meshSelector = StringPropertySelectMesh::New(this->getServices()->patient());
192  widget.reset( new AllMeshPropertiesWidget(meshSelector,
193  this->getServices(),
194  NULL));
195  wrepo->add(widget);
196  }
197  widget->getSelector()->setValue(mData->getUid());
198  return widget;
199  }
200  if (boost::dynamic_pointer_cast<Image>(mData))
201  {
202  boost::shared_ptr<ImagePropertiesWidget> widget = wrepo->find<ImagePropertiesWidget>();
203  if (!widget)
204  {
205  widget.reset (new ImagePropertiesWidget(this->getServices(), NULL));
206  wrepo->add(widget);
207  }
208  return widget;
209  }
210  if(boost::dynamic_pointer_cast<DataMetric>(mData))
211  {
212  boost::shared_ptr<QWidget> widget = wrepo->findMetricWidget(mData);
213  if(!widget)
214  {
215  MetricUtilities utilities(this->getServices());
216  widget.reset(utilities.createMetricWidget(mData));
217  wrepo->add(widget);
218  }
219  return widget;
220 
221  }
222  return boost::shared_ptr<QWidget>(new QLabel(QString("Data widget %1 ").arg(mData->getName())));
223 }
224 
225 
226 } // namespace cx
boost::shared_ptr< TreeNode > TreeNodePtr
virtual QVariant getFont() const
A mesh data set.
Definition: cxMesh.h:66
virtual QVariant getColor() const
VisServicesPtr getServices() const
static DataViewProperties createDefault()
virtual QString getName() const
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:755
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:94
virtual QString getUid() const
virtual bool isDefaultExpanded() const
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
virtual QString getType() const
TreeRepositoryPtr repo()
csDATA
a datas space (d)
boost::shared_ptr< class Data > DataPtr
DataTreeNode(TreeRepositoryWeakPtr repo, DataPtr data)
virtual void setViewGroupVisibility(int index, bool value)
boost::shared_ptr< class WidgetTypeRepository > WidgetTypeRepositoryPtr
QIcon addBackgroundColorToIcon(QIcon input, QColor color) const
Identification of a Coordinate system.
QColor getColor()
virtual ~DataTreeNode()
QWidget * createMetricWidget(DataPtr data)
Widget for displaying and manipulating various Image properties.
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
virtual TreeNodePtr getParent() const
virtual QVariant getViewGroupVisibility(int index) const
virtual bool isVisibleNode() const
virtual QIcon getIcon() const
boost::shared_ptr< class Mesh > MeshPtr
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
virtual void activate()
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
virtual void remove()
QColor getColor()
Get the color of the mesh (Values are range 0 - 255)
Definition: cxMesh.cpp:210
Namespace for all CustusX production code.