Fraxinus  2023.01.05-dev+develop.0da12
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 #include "cxTrackingService.h"
28 
29 namespace cx
30 {
31 
33  mServices(services),
34  mGroupData(groupData)
35 {
36  mProperties = DataViewProperties::createDefault();
37 }
38 
40 {
41  mProperties = properties;
42 }
43 
44 void DataViewPropertiesInteractor::addDataAction(QString uid, QWidget* parent)
45 {
46  DataPtr data = mServices->patient()->getData(uid);
47 
48  QAction* action = new QAction(qstring_cast(data->getName()), parent);
49 
50  action->setIcon(data->getIcon());
51 
52 // std::cout << "base " << mLastDataActionUid << " " << uid << std::endl;
53  if (uid.contains(mLastDataActionUid))
54  {
55  action->setText(" " + action->text());
56 // std::cout << "indenting " << action->text() << std::endl;
57  }
58  else
59  {
60  mLastDataActionUid = uid;
61  }
62 
63  action->setData(QVariant(qstring_cast(uid)));
64  action->setCheckable(true);
65  std::vector<DataPtr> allVisible = mGroupData->getData(mProperties);
66  action->setChecked(std::count(allVisible.begin(), allVisible.end(), data));
67  connect(action, SIGNAL(triggered()), this, SLOT(dataActionSlot()));
68  parent->addAction(action);
69 }
70 
71 void DataViewPropertiesInteractor::dataActionSlot()
72 {
73  QAction* theAction = static_cast<QAction*>(sender());
74  if(!theAction)
75  return;
76 
77  QString uid = theAction->data().toString();
78  DataPtr data = mServices->patient()->getData(uid);
79 
80  bool firstData = mGroupData->getData(DataViewProperties::createFull()).empty();
81 
82  DataViewProperties old = mGroupData->getProperties(uid);
83 
84  if (theAction->isChecked())
85  {
86  DataViewProperties props = old.addFlagsIn(mProperties);
87  mGroupData->setProperties(uid, props);
88 
89  if (data)
90  {
91  ActiveDataPtr activeData = mServices->patient()->getActiveData();
92  activeData->setActive(data);
93  }
94  }
95  else
96  {
97  DataViewProperties props = old.removeFlagsIn(mProperties);
98  mGroupData->setProperties(uid, props);
99  }
100 
101  if (firstData)
102  {
103  Navigation(mServices).centerToDataInViewGroup(mGroupData);
104  mGroupData->requestInitialize();
105  }
106 }
107 
111 
113  mServices(services)
114 {
115 }
116 
118 {
119  mGroupData = group;
120 
124 
125  std::vector<DataPtr> data = mGroupData->getData();
126  for (unsigned i = 0; i < data.size(); ++i)
127  this->dataViewPropertiesChangedSlot(data[i]->getUid());
128 
129 
131 
134 
135  connect(settings(), SIGNAL(valueChangedFor(QString)), this, SLOT(settingsChangedSlot(QString)));
136 }
137 
139 {
140  if (key.startsWith("View"))
141  {
142  this->updateView();
143  }
144 }
145 
146 void ViewWrapper::contextMenuSlot(const QPoint& point)
147 {
148  QMenu contextMenu;
149  contextMenu.setToolTipsVisible(true);
150  mDataViewPropertiesInteractor->addDataActionsOfType<Data>(&contextMenu);
151  //append specific info from derived classes
152  this->appendToContextMenu(contextMenu);
153  contextMenu.exec(point);
154 }
155 
156 
158 {
159  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
160 }
161 
163 {
164  if (!mGroupData)
165  return QStringList();
166  std::vector<DataPtr> data = mGroupData->getData(properties);
167 
168  QStringList text;
169  for (unsigned i = 0; i < data.size(); ++i)
170  {
171  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
172  if (metric) // dont show metrics here: too much spam - use separate list is necessary
173  continue;
174  QString line = data[i]->getName();
175 
176  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
177  if (image)
178  {
179  if (image->getCropping())
180  line += " (cropped)";
181  if (!image->getAllClipPlanes().empty())
182  line += " (clipped)";
183  }
184 
185  text << line;
186  }
187  std::reverse(text.begin(), text.end());
188  return text;
189 }
190 
192 {
193  // view description
194  QString annotationText;
195  if (settings()->value("View/showOrientationAnnotation").value<bool>())
196  {
197  annotationText = QString("%1-%2")
198  .arg(this->getViewDescription())
199  .arg(mGroupData ? mGroupData->getUid() : "");
200  }
201  mPlaneTypeText->setText(0, annotationText);
202 
203  // data description
204  QString showDataText;
205  if (settings()->value("View/showDataText").value<bool>())
206  {
207  showDataText = this->getDataDescription();
208  }
209  mDataNameText->setText(0, showDataText);
210  mDataNameText->setFontSize(std::max(12, 22 - 2 * showDataText.size()));
211 }
212 
214 {
215  // plane type text rep
216  mPlaneTypeText = DisplayTextRep::New();
217  mPlaneTypeText->addText(QColor(Qt::green), "--", Vector3D(0.98, 0.02, 0.0));
218  this->getView()->addRep(mPlaneTypeText);
219 
220  //data name text rep
221  mDataNameText = DisplayTextRep::New();
222  mDataNameText->addText(QColor(Qt::green), "--", Vector3D(0.02, 0.02, 0.0));
223  this->getView()->addRep(mDataNameText);
224 }
225 
227 {
228  mSharedOpenGLContext = sharedOpenGLContext;
229 }
230 
232 {
233  ToolPtr activeTool = mServices->tracking()->getActiveTool();
234  ToolPtr controllingTool;
235  if (mGroupData)
236  controllingTool = mGroupData->getControllingTool();
237 
238  if(!controllingTool)
239  controllingTool = activeTool;
240 
241  return controllingTool;
242 }
243 
244 } //namespace cx
QString qstring_cast(const T &val)
static DataViewProperties createSlice3D()
virtual QString getDataDescription()=0
ToolPtr getControllingTool()
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
void controllingToolChanged()
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:89
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)
virtual void activeToolChangedSlot()
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr