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