NorMIT-nav  2023.01.05-dev+develop.0da12
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
cx::WidgetTypeRepositoryPtr
boost::shared_ptr< class WidgetTypeRepository > WidgetTypeRepositoryPtr
Definition: cxTreeRepository.h:35
cx::StringPropertySelectMesh::New
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
Definition: cxSelectDataStringProperty.h:131
cxLogger.h
cxDataTreeNode.h
cx::TreeNodeImpl
Definition: cxTreeNodeImpl.h:26
cx::DataTreeNode::getType
virtual QString getType() const
Definition: cxDataTreeNode.cpp:60
cxTreeRepository.h
cxActiveData.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DataTreeNode::getIcon
virtual QIcon getIcon() const
Definition: cxDataTreeNode.cpp:101
cxImage.h
cxDataMetric.h
cx::DataMetricPtr
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
cxImagePropertiesWidget.h
cx::DataTreeNode::getName
virtual QString getName() const
Definition: cxDataTreeNode.cpp:55
cxDefinitions.h
cx::DataTreeNode::isDefaultExpanded
virtual bool isDefaultExpanded() const
Definition: cxDataTreeNode.cpp:132
csDATA
csDATA
a datas space (d)
Definition: cxDefinitions.h:91
cx::DataTreeNode::getUid
virtual QString getUid() const
Definition: cxDataTreeNode.cpp:50
cx::DataTreeNode::getColor
virtual QVariant getColor() const
Definition: cxDataTreeNode.cpp:109
cx::DataTreeNode::DataTreeNode
DataTreeNode(TreeRepositoryWeakPtr repo, DataPtr data)
Definition: cxDataTreeNode.cpp:37
cx::DataTreeNode::createPropertiesWidget
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const
Definition: cxDataTreeNode.cpp:161
cxViewGroupData.h
cx::DataTreeNode::getViewGroupVisibility
virtual QVariant getViewGroupVisibility(int index) const
Definition: cxDataTreeNode.cpp:142
cx::DataTreeNode::isVisibleNode
virtual bool isVisibleNode() const
Definition: cxDataTreeNode.cpp:65
cx::StringPropertySelectMeshPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Definition: cxRecordSessionSelector.h:26
cx::DataViewProperties::empty
bool empty() const
Definition: cxViewGroupData.cpp:220
cx::AllMeshPropertiesWidget
Definition: cxMeshInfoWidget.h:38
cxData.h
cxMeshInfoWidget.h
cx::DataViewProperties::hasSlice3D
bool hasSlice3D() const
Definition: cxViewGroupData.h:97
cx::DataTreeNode::setViewGroupVisibility
virtual void setViewGroupVisibility(int index, bool value)
Definition: cxDataTreeNode.cpp:153
cx::MeshPtr
boost::shared_ptr< class Mesh > MeshPtr
Definition: cxForwardDeclarations.h:48
cx::DataTreeNode::~DataTreeNode
virtual ~DataTreeNode()
Definition: cxDataTreeNode.cpp:45
cxNullDeleter.h
csREF
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
cxViewService.h
cx::DataViewProperties::hasSlice2D
bool hasSlice2D() const
Definition: cxViewGroupData.h:98
cx::DataTreeNode::getParent
virtual TreeNodePtr getParent() const
Definition: cxDataTreeNode.cpp:83
cx::MetricUtilities
Definition: cxMetricUtilities.h:28
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::DataViewProperties
Definition: cxViewGroupData.h:79
cx::MetricUtilities::createMetricWidget
QWidget * createMetricWidget(DataPtr data)
Definition: cxMetricUtilities.cpp:103
cxPatientModelService.h
cx::DataViewProperties::createDefault
static DataViewProperties createDefault()
Definition: cxViewGroupData.cpp:150
cx::TreeNodePtr
boost::shared_ptr< TreeNode > TreeNodePtr
Definition: cxDataTreeNode.h:22
cx::TreeNodeImpl::getServices
VisServicesPtr getServices() const
Definition: cxTreeNodeImpl.cpp:97
cx::TreeNodeImpl::addBackgroundColorToIcon
QIcon addBackgroundColorToIcon(QIcon input, QColor color) const
Definition: cxTreeNodeImpl.cpp:112
cx::TreeNodeImpl::repo
TreeRepositoryPtr repo()
Definition: cxTreeNodeImpl.cpp:102
cx::CoordinateSystem::toString
QString toString() const
Definition: cxCoordinateSystemHelpers.cpp:19
cx::DataTreeNode::remove
virtual void remove()
Definition: cxDataTreeNode.cpp:137
cx::ImagePropertiesWidget
Widget for displaying and manipulating various Image properties.
Definition: cxImagePropertiesWidget.h:33
cx::DataTreeNode::activate
virtual void activate()
Definition: cxDataTreeNode.cpp:96
cxSelectDataStringProperty.h
cx::DataViewProperties::hasVolume3D
bool hasVolume3D() const
Definition: cxViewGroupData.h:96
cxMesh.h
cxMetricUtilities.h
cx::TreeRepositoryWeakPtr
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cxVisServices.h
cx::DataTreeNode::getFont
virtual QVariant getFont() const
Definition: cxDataTreeNode.cpp:121