CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "cxViewManager.h"
44 #include "cxInteractiveClipper.h"
45 #include "cxNavigation.h"
46 #include "cxActiveData.h"
47 #include "cxSettings.h"
48 #include "cxDisplayTextRep.h"
49 
50 namespace cx
51 {
52 
54  mServices(services),
55  mGroupData(groupData)
56 {
57  mProperties = DataViewProperties::createDefault();
58 }
59 
61 {
62  mProperties = properties;
63 }
64 
65 void DataViewPropertiesInteractor::addDataAction(QString uid, QWidget* parent)
66 {
67  DataPtr data = mServices->patient()->getData(uid);
68 
69  QAction* action = new QAction(qstring_cast(data->getName()), parent);
70 
71  action->setIcon(data->getIcon());
72 
73 // std::cout << "base " << mLastDataActionUid << " " << uid << std::endl;
74  if (uid.contains(mLastDataActionUid))
75  {
76  action->setText(" " + action->text());
77 // std::cout << "indenting " << action->text() << std::endl;
78  }
79  else
80  {
81  mLastDataActionUid = uid;
82  }
83 
84  action->setData(QVariant(qstring_cast(uid)));
85  action->setCheckable(true);
86  std::vector<DataPtr> allVisible = mGroupData->getData(mProperties);
87  action->setChecked(std::count(allVisible.begin(), allVisible.end(), data));
88  connect(action, SIGNAL(triggered()), this, SLOT(dataActionSlot()));
89  parent->addAction(action);
90 }
91 
92 void DataViewPropertiesInteractor::dataActionSlot()
93 {
94  QAction* theAction = static_cast<QAction*>(sender());
95  if(!theAction)
96  return;
97 
98  QString uid = theAction->data().toString();
99  DataPtr data = mServices->patient()->getData(uid);
100 
101  bool firstData = mGroupData->getData(DataViewProperties::createFull()).empty();
102 
103  DataViewProperties old = mGroupData->getProperties(uid);
104 
105  if (theAction->isChecked())
106  {
107  DataViewProperties props = old.addFlagsIn(mProperties);
108  mGroupData->setProperties(uid, props);
109 
110  if (data)
111  {
112  ActiveDataPtr activeData = mServices->patient()->getActiveData();
113  activeData->setActive(data);
114  }
115  }
116  else
117  {
118  DataViewProperties props = old.removeFlagsIn(mProperties);
119  mGroupData->setProperties(uid, props);
120  }
121 
122  if (firstData)
123  {
124  Navigation(mServices).centerToDataInViewGroup(mGroupData);
125  mGroupData->requestInitialize();
126  }
127 }
128 
132 
134  mServices(services)
135 {
136 }
137 
139 {
140  mGroupData = group;
141 
144 
145  std::vector<DataPtr> data = mGroupData->getData();
146  for (unsigned i = 0; i < data.size(); ++i)
147  this->dataViewPropertiesChangedSlot(data[i]->getUid());
148 
149 
151 
154 
155  connect(settings(), SIGNAL(valueChangedFor(QString)), this, SLOT(settingsChangedSlot(QString)));
156 }
157 
159 {
160  if (key.startsWith("View"))
161  {
162  this->updateView();
163  }
164 }
165 
166 void ViewWrapper::contextMenuSlot(const QPoint& point)
167 {
168  QMenu contextMenu;
169  mDataViewPropertiesInteractor->addDataActionsOfType<Data>(&contextMenu);
170  //append specific info from derived classes
171  this->appendToContextMenu(contextMenu);
172  contextMenu.exec(point);
173 }
174 
175 
177 {
178  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
179 }
180 
182 {
183  if (!mGroupData)
184  return QStringList();
185  std::vector<DataPtr> data = mGroupData->getData(properties);
186 
187  QStringList text;
188  for (unsigned i = 0; i < data.size(); ++i)
189  {
190  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
191  if (metric) // dont show metrics here: too much spam - use separate list is necessary
192  continue;
193  QString line = data[i]->getName();
194 
195  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
196  if (image)
197  {
198  if (image->getCropping())
199  line += " (cropped)";
200  if (!image->getAllClipPlanes().empty())
201  line += " (clipped)";
202  }
203 
204  text << line;
205  }
206  std::reverse(text.begin(), text.end());
207  return text;
208 }
209 
211 {
212  // view description
213  QString annotationText;
214  if (settings()->value("View/showOrientationAnnotation").value<bool>())
215  {
216  annotationText = QString("%1-%2")
217  .arg(this->getViewDescription())
218  .arg(mGroupData ? mGroupData->getUid() : "");
219  }
220  mPlaneTypeText->setText(0, annotationText);
221 
222  // data description
223  QString showDataText;
224  if (settings()->value("View/showDataText").value<bool>())
225  {
226  showDataText = this->getDataDescription();
227  }
228  mDataNameText->setText(0, showDataText);
229  mDataNameText->setFontSize(std::max(12, 22 - 2 * showDataText.size()));
230 }
231 
233 {
234  // plane type text rep
235  mPlaneTypeText = DisplayTextRep::New();
236  mPlaneTypeText->addText(QColor(Qt::green), "--", Vector3D(0.98, 0.02, 0.0));
237  this->getView()->addRep(mPlaneTypeText);
238 
239  //data name text rep
240  mDataNameText = DisplayTextRep::New();
241  mDataNameText->addText(QColor(Qt::green), "--", Vector3D(0.02, 0.02, 0.0));
242  this->getView()->addRep(mDataNameText);
243 }
244 
245 } //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
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:96
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
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)
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
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="")
virtual void updateView()
DataViewPropertiesInteractorPtr mShow3DSlicesInteractor
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)