Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
52 namespace cx
53 {
54 
55 
57  TreeNodeImpl(repo), mData(data)
58 {
59  connect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
60 }
61 
63 {
64  disconnect(mData.get(), &Data::transformChanged, this, &TreeNode::changed);
65 }
66 
67 QString DataTreeNode::getUid() const
68 {
69  return mData->getUid();
70 }
71 
72 QString DataTreeNode::getName() const
73 {
74  return mData->getName();
75 }
76 
77 QString DataTreeNode::getType() const
78 {
79  return "data";
80 }
81 
83 {
84  QStringList visible = this->repo()->getVisibleNodeTypes();
85 
86  bool hasData = visible.contains(this->getType());
87  if (!hasData)
88  return false;
89 
90  if (boost::dynamic_pointer_cast<Mesh>(mData) && !visible.contains("model"))
91  return false;
92  if (boost::dynamic_pointer_cast<Image>(mData) && !visible.contains("image"))
93  return false;
94  if (boost::dynamic_pointer_cast<DataMetric>(mData) && !visible.contains("metric"))
95  return false;
96 
97  return true;
98 }
99 
101 {
102  if (this->repo()->getMode()=="flat")
103  return this->repo()->getNodeForGroup("data");
104 
105  if (mData->getParentSpace().isEmpty())
106  return this->repo()->getNode(CoordinateSystem(csREF).toString());
107  TreeNodePtr parent = this->repo()->getNode(mData->getParentSpace());
108  if (!parent)
109  parent = this->repo()->getNode(CoordinateSystem(csDATA, mData->getParentSpace()).toString());
110  return parent;
111 }
112 
114 {
115  this->getServices()->patient()->getActiveData()->setActive(mData);
116 }
117 
119 {
120  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
121  if (metric)
122  return this->addBackgroundColorToIcon(mData->getIcon(), metric->getColor());
123  return mData->getIcon();
124 }
125 
126 QVariant DataTreeNode::getColor() const
127 {
128  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mData);
129  if (metric)
130  return metric->getColor();
131  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mData);
132  if (mesh)
133  return mesh->getColor();
134  return QVariant();
135 // return QColor("black");
136 }
137 
138 QVariant DataTreeNode::getFont() const
139 {
140  if (this->getServices()->patient()->getActiveData()->getActive()==mData)
141  {
142  QFont font;
143  font.setBold(true);
144  return font;
145  }
146  return QVariant();
147 }
148 
150 {
151  return (this->repo()->getMode()!="flat");
152 }
153 
155 {
156  this->getServices()->patient()->removeData(mData->getUid());
157 }
158 
159 QVariant DataTreeNode::getViewGroupVisibility(int index) const
160 {
161  DataViewProperties props = this->getServices()->view()->getGroup(index)->getProperties(mData->getUid());
162  if (props.empty())
163  return Qt::CheckState(0);
164  if ((props.hasVolume3D() || props.hasSlice3D()) && props.hasSlice2D())
165  return Qt::CheckState(2);
166  return Qt::CheckState(1);
167 // return true;
168 }
169 
170 void DataTreeNode::setViewGroupVisibility(int index, bool value)
171 {
172  if (value)
173  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties::createDefault());
174  else
175  this->getServices()->view()->getGroup(index)->setProperties(mData->getUid(), DataViewProperties());
176 }
177 
179 {
180  WidgetTypeRepositoryPtr wrepo = this->repo()->getWidgetTypeRepository();
181 
182  if (boost::dynamic_pointer_cast<Mesh>(mData))
183  {
184  MeshInfoWidget* widget = wrepo->find<MeshInfoWidget>();
185  if (!widget)
186  {
187  StringPropertySelectMeshPtr meshSelector = StringPropertySelectMesh::New(this->getServices()->patient());
188  widget = new MeshInfoWidget(meshSelector,
189  this->getServices()->patient(),
190  this->getServices()->view(),
191  NULL);
192  wrepo->add(widget);
193  }
194  widget->getSelector()->setValue(mData->getUid());
195  return widget;
196  }
197  if (boost::dynamic_pointer_cast<Image>(mData))
198  {
199  ImagePropertiesWidget* widget = wrepo->find<ImagePropertiesWidget>();
200  if (!widget)
201  {
202  widget = new ImagePropertiesWidget(this->getServices(), NULL);
203  wrepo->add(widget);
204  }
205  return widget;
206  }
207  return new QLabel(QString("Data widget %1 ").arg(mData->getName()));
208 }
209 
210 
211 } // namespace cx
boost::shared_ptr< TreeNode > TreeNodePtr
void changed()
virtual QVariant getFont() const
A mesh data set.
Definition: cxMesh.h:61
virtual QVariant getColor() const
VisServicesPtr getServices() const
static DataViewProperties createDefault()
virtual QString getName() const
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:95
virtual QString getUid() const
virtual bool isDefaultExpanded() const
bool hasSlice3D() const
void transformChanged()
emitted when transform is changed
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
QWidget * createPropertiesWidget() const
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
Widget for displaying and manipulating various Image properties.
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
virtual TreeNodePtr getParent() const
SelectDataStringPropertyBasePtr getSelector()
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:243
bool hasSlice2D() const