NorMIT-nav  18.04-rc6
An IGT application
cxViewWrapper.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 
12 #include "cxViewWrapper.h"
13 
14 #include <QMenu>
15 #include "vtkCamera.h"
16 
17 #include "cxViewGroup.h" //for class Navigation
18 #include "cxTypeConversions.h"
19 #include "cxDataMetric.h"
20 #include "cxView.h"
21 #include "cxImage.h"
22 #include "cxInteractiveClipper.h"
23 #include "cxNavigation.h"
24 #include "cxActiveData.h"
25 #include "cxSettings.h"
26 #include "cxDisplayTextRep.h"
27 
28 namespace cx
29 {
30 
32  mServices(services),
33  mGroupData(groupData)
34 {
35  mProperties = DataViewProperties::createDefault();
36 }
37 
39 {
40  mProperties = properties;
41 }
42 
43 void DataViewPropertiesInteractor::addDataAction(QString uid, QWidget* parent)
44 {
45  DataPtr data = mServices->patient()->getData(uid);
46 
47  QAction* action = new QAction(qstring_cast(data->getName()), parent);
48 
49  action->setIcon(data->getIcon());
50 
51 // std::cout << "base " << mLastDataActionUid << " " << uid << std::endl;
52  if (uid.contains(mLastDataActionUid))
53  {
54  action->setText(" " + action->text());
55 // std::cout << "indenting " << action->text() << std::endl;
56  }
57  else
58  {
59  mLastDataActionUid = uid;
60  }
61 
62  action->setData(QVariant(qstring_cast(uid)));
63  action->setCheckable(true);
64  std::vector<DataPtr> allVisible = mGroupData->getData(mProperties);
65  action->setChecked(std::count(allVisible.begin(), allVisible.end(), data));
66  connect(action, SIGNAL(triggered()), this, SLOT(dataActionSlot()));
67  parent->addAction(action);
68 }
69 
70 void DataViewPropertiesInteractor::dataActionSlot()
71 {
72  QAction* theAction = static_cast<QAction*>(sender());
73  if(!theAction)
74  return;
75 
76  QString uid = theAction->data().toString();
77  DataPtr data = mServices->patient()->getData(uid);
78 
79  bool firstData = mGroupData->getData(DataViewProperties::createFull()).empty();
80 
81  DataViewProperties old = mGroupData->getProperties(uid);
82 
83  if (theAction->isChecked())
84  {
85  DataViewProperties props = old.addFlagsIn(mProperties);
86  mGroupData->setProperties(uid, props);
87 
88  if (data)
89  {
90  ActiveDataPtr activeData = mServices->patient()->getActiveData();
91  activeData->setActive(data);
92  }
93  }
94  else
95  {
96  DataViewProperties props = old.removeFlagsIn(mProperties);
97  mGroupData->setProperties(uid, props);
98  }
99 
100  if (firstData)
101  {
102  Navigation(mServices).centerToDataInViewGroup(mGroupData);
103  mGroupData->requestInitialize();
104  }
105 }
106 
110 
112  mServices(services)
113 {
114 }
115 
117 {
118  mGroupData = group;
119 
122 
123  std::vector<DataPtr> data = mGroupData->getData();
124  for (unsigned i = 0; i < data.size(); ++i)
125  this->dataViewPropertiesChangedSlot(data[i]->getUid());
126 
127 
129 
132 
133  connect(settings(), SIGNAL(valueChangedFor(QString)), this, SLOT(settingsChangedSlot(QString)));
134 }
135 
137 {
138  if (key.startsWith("View"))
139  {
140  this->updateView();
141  }
142 }
143 
144 void ViewWrapper::contextMenuSlot(const QPoint& point)
145 {
146  QMenu contextMenu;
147  mDataViewPropertiesInteractor->addDataActionsOfType<Data>(&contextMenu);
148  //append specific info from derived classes
149  this->appendToContextMenu(contextMenu);
150  contextMenu.exec(point);
151 }
152 
153 
155 {
156  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
157 }
158 
160 {
161  if (!mGroupData)
162  return QStringList();
163  std::vector<DataPtr> data = mGroupData->getData(properties);
164 
165  QStringList text;
166  for (unsigned i = 0; i < data.size(); ++i)
167  {
168  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
169  if (metric) // dont show metrics here: too much spam - use separate list is necessary
170  continue;
171  QString line = data[i]->getName();
172 
173  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
174  if (image)
175  {
176  if (image->getCropping())
177  line += " (cropped)";
178  if (!image->getAllClipPlanes().empty())
179  line += " (clipped)";
180  }
181 
182  text << line;
183  }
184  std::reverse(text.begin(), text.end());
185  return text;
186 }
187 
189 {
190  // view description
191  QString annotationText;
192  if (settings()->value("View/showOrientationAnnotation").value<bool>())
193  {
194  annotationText = QString("%1-%2")
195  .arg(this->getViewDescription())
196  .arg(mGroupData ? mGroupData->getUid() : "");
197  }
198  mPlaneTypeText->setText(0, annotationText);
199 
200  // data description
201  QString showDataText;
202  if (settings()->value("View/showDataText").value<bool>())
203  {
204  showDataText = this->getDataDescription();
205  }
206  mDataNameText->setText(0, showDataText);
207  mDataNameText->setFontSize(std::max(12, 22 - 2 * showDataText.size()));
208 }
209 
211 {
212  // plane type text rep
213  mPlaneTypeText = DisplayTextRep::New();
214  mPlaneTypeText->addText(QColor(Qt::green), "--", Vector3D(0.98, 0.02, 0.0));
215  this->getView()->addRep(mPlaneTypeText);
216 
217  //data name text rep
218  mDataNameText = DisplayTextRep::New();
219  mDataNameText->addText(QColor(Qt::green), "--", Vector3D(0.02, 0.02, 0.0));
220  this->getView()->addRep(mDataNameText);
221 }
222 
224 {
225  mSharedOpenGLContext = sharedOpenGLContext;
226 }
227 
228 } //namespace cx
QString qstring_cast(const T &val)
static DataViewProperties createSlice3D()
virtual QString getDataDescription()=0
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
static DataViewProperties createDefault()
virtual void appendToContextMenu(QMenu &contextMenu)=0
virtual void setSharedOpenGLContext(SharedOpenGLContextPtr sharedOpenGLContext)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
SharedOpenGLContextPtr mSharedOpenGLContext
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
DataViewPropertiesInteractorPtr mDataViewPropertiesInteractor
boost::shared_ptr< class View > ViewPtr
virtual void dataViewPropertiesChangedSlot(QString uid)=0
virtual void setViewGroup(ViewGroupDataPtr group)
boost::shared_ptr< class Data > DataPtr
void settingsChangedSlot(QString key)
virtual void videoSourceChangedSlot(QString uid)
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
virtual QString getName() const
Definition: cxData.cpp:69
ViewGroupDataPtr mGroupData
A volumetric data set.
Definition: cxImage.h:45
DataViewPropertiesInteractor(VisServicesPtr services, ViewGroupDataPtr groupData)
virtual ViewPtr getView()=0
void centerToDataInViewGroup(ViewGroupDataPtr group, DataViewProperties properties=DataViewProperties::createFull())
static DataViewProperties createFull()
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
void dataViewPropertiesChanged(QString uid)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual void addReps()
Superclass for all data objects.
Definition: cxData.h:88
VisServicesPtr mServices
QStringList getAllDataNames(DataViewProperties properties) const
void contextMenuSlot(const QPoint &point)
static DisplayTextRepPtr New(const QString &uid="")
DataViewProperties removeFlagsIn(DataViewProperties rhs) const
virtual void updateView()
DataViewPropertiesInteractorPtr mShow3DSlicesInteractor
DataViewProperties addFlagsIn(DataViewProperties rhs) const
void videoSourceChanged(QString uid)
void setDataViewProperties(DataViewProperties properties)
Base class for all Data Metrics.
Definition: cxDataMetric.h:43
virtual QString getViewDescription()=0
void connectContextMenu(ViewPtr view)
ViewWrapper(VisServicesPtr backend)
Namespace for all CustusX production code.