CustusX  22.04-rc5
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) 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 #include "cxDataTreeNode.h"
12 #include "cxPatientModelService.h"
13 #include "cxDefinitions.h"
14 #include "cxData.h"
15 #include "cxTreeRepository.h"
16 #include "cxLogger.h"
17 #include "cxDataMetric.h"
18 #include "cxActiveData.h"
19 #include "cxViewService.h"
20 #include "cxViewGroupData.h"
21 #include "cxVisServices.h"
22 #include <QFont>
23 #include <QLabel>
24 #include "cxMesh.h"
25 #include "cxMeshInfoWidget.h"
27 #include "cxImage.h"
29 #include "cxDataMetric.h"
30 #include "cxMetricUtilities.h"
31 #include "cxNullDeleter.h"
32 
33 namespace cx
34 {
35 
36 
38  TreeNodeImpl(repo), mData(data)
39 {
40  // too expensive: this happens for every position change in some cases (metrics),
41  // while nothing is changed in the gui.
42 // connect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
43 }
44 
46 {
47 // disconnect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
48 }
49 
50 QString DataTreeNode::getUid() const
51 {
52  return mData->getUid();
53 }
54 
55 QString DataTreeNode::getName() const
56 {
57  return mData->getName();
58 }
59 
60 QString DataTreeNode::getType() const
61 {
62  return "data";
63 }
64 
66 {
67  QStringList visible = this->repo()->getVisibleNodeTypes();
68 
69  bool hasData = visible.contains(this->getType());
70  if (!hasData)
71  return false;
72 
73  if (boost::dynamic_pointer_cast<Mesh>(mData) && !visible.contains("model"))
74  return false;
75  if (boost::dynamic_pointer_cast<Image>(mData) && !visible.contains("image"))
76  return false;
77  if (boost::dynamic_pointer_cast<DataMetric>(mData) && !visible.contains("metric"))
78  return false;
79 
80  return true;
81 }
82 
84 {
85  if (this->repo()->getMode()=="flat")
86  return this->repo()->getNodeForGroup("data");
87 
88  if (mData->getParentSpace().isEmpty())
89  return this->repo()->getNode(CoordinateSystem(csREF).toString());
90  TreeNodePtr parent = this->repo()->getNode(mData->getParentSpace());
91  if (!parent)
92  parent = this->repo()->getNode(CoordinateSystem(csDATA, mData->getParentSpace()).toString());
93  return parent;
94 }
95 
97 {
98  this->getServices()->patient()->getActiveData()->setActive(mData);
99 }
100 
102 {
103  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
104  if (metric)
105  return this->addBackgroundColorToIcon(mData->getIcon(), metric->getColor());
106  return mData->getIcon();
107 }
108 
109 QVariant DataTreeNode::getColor() const
110 {
111  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
112  if (metric)
113  return metric->getColor();
114  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mData);
115  if (mesh)
116  return mesh->getColor();
117  return QVariant();
118 // return QColor("black");
119 }
120 
121 QVariant DataTreeNode::getFont() const
122 {
123  if (this->getServices()->patient()->getActiveData()->getActive()==mData)
124  {
125  QFont font;
126  font.setBold(true);
127  return font;
128  }
129  return QVariant();
130 }
131 
133 {
134  return (this->repo()->getMode()!="flat");
135 }
136 
138 {
139  this->getServices()->patient()->removeData(mData->getUid());
140 }
141 
142 QVariant DataTreeNode::getViewGroupVisibility(int index) const
143 {
144  DataViewProperties props = this->getServices()->view()->getGroup(index)->getProperties(mData->getUid());
145  if (props.empty())
146  return Qt::CheckState(0);
147  if ((props.hasVolume3D() || props.hasSlice3D()) && props.hasSlice2D())
148  return Qt::CheckState(2);
149  return Qt::CheckState(1);
150 // return true;
151 }
152 
153 void DataTreeNode::setViewGroupVisibility(int index, bool value)
154 {
155  if (value)
156  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties::createDefault());
157  else
158  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties());
159 }
160 
161 boost::shared_ptr<QWidget> DataTreeNode::createPropertiesWidget() const
162 {
163  WidgetTypeRepositoryPtr wrepo = this->repo()->getWidgetTypeRepository();
164 
165  if (boost::dynamic_pointer_cast<Mesh>(mData))
166  {
167  boost::shared_ptr<AllMeshPropertiesWidget> widget = wrepo->find<AllMeshPropertiesWidget>();
168  if (!widget)
169  {
170  StringPropertySelectMeshPtr meshSelector = StringPropertySelectMesh::New(this->getServices()->patient());
171  widget.reset( new AllMeshPropertiesWidget(meshSelector,
172  this->getServices(),
173  NULL));
174  wrepo->add(widget);
175  }
176  widget->getSelector()->setValue(mData->getUid());
177  return widget;
178  }
179  if (boost::dynamic_pointer_cast<Image>(mData))
180  {
181  boost::shared_ptr<ImagePropertiesWidget> widget = wrepo->find<ImagePropertiesWidget>();
182  if (!widget)
183  {
184  widget.reset (new ImagePropertiesWidget(this->getServices(), NULL));
185  wrepo->add(widget);
186  }
187  return widget;
188  }
189  if(boost::dynamic_pointer_cast<DataMetric>(mData))
190  {
191  boost::shared_ptr<QWidget> widget = wrepo->findMetricWidget(mData);
192  if(!widget)
193  {
194  MetricUtilities utilities(this->getServices());
195  widget.reset(utilities.createMetricWidget(mData));
196  wrepo->add(widget);
197  }
198  return widget;
199 
200  }
201  return boost::shared_ptr<QWidget>(new QLabel(QString("Data widget %1 ").arg(mData->getName())));
202 }
203 
204 
205 } // namespace cx
boost::shared_ptr< TreeNode > TreeNodePtr
virtual QVariant getFont() const
A mesh data set.
Definition: cxMesh.h:45
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:73
virtual QString getUid() const
virtual bool isDefaultExpanded() const
bool hasSlice3D() const
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
virtual QString getType() const
TreeRepositoryPtr repo()
csDATA
a datas space (d)
Definition: cxDefinitions.h:90
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()
bool hasVolume3D() const
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:43
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:190
bool hasSlice2D() const
Namespace for all CustusX production code.