CustusX  15.3.4-beta
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 "cxPatientModelService.h"
39 #include "cxViewGroup.h" //for class Navigation
40 #include "cxMesh.h"
41 #include "cxTypeConversions.h"
42 #include "cxImageAlgorithms.h"
43 #include "cxDataMetric.h"
44 #include "cxView.h"
45 #include "cxImage.h"
46 #include "cxViewManager.h"
47 #include "cxInteractiveClipper.h"
48 #include "cxCoreServices.h"
49 #include "cxNavigation.h"
50 
51 namespace cx
52 {
53 
55  mBackend(backend),
56  mGroupData(groupData)
57 {
58  mProperties = DataViewProperties::createDefault();
59 }
60 
62 {
63  //add actions to the actiongroups and the contextmenu
64  std::vector<DataPtr> sorted = sortOnGroupsAndAcquisitionTime(mBackend->getPatientService()->getData());
65  mLastDataActionUid = "________________________";
66  for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
67  {
68  this->addDataAction((*iter)->getUid(), parent);
69  }
70 }
71 
73 {
74  mProperties = properties;
75 }
76 
77 void DataViewPropertiesInteractor::addDataAction(QString uid, QWidget* parent)
78 {
79  DataPtr data = mBackend->getPatientService()->getData(uid);
80 
81  QAction* action = new QAction(qstring_cast(data->getName()), parent);
82 
83  if (boost::dynamic_pointer_cast<Image>(data))
84  action->setIcon(QIcon(":/icons/volume.png"));
85  else if (boost::dynamic_pointer_cast<Mesh>(data))
86  action->setIcon(QIcon(":/icons/surface.png"));
87  else if (boost::dynamic_pointer_cast<DataMetric>(data))
88  action->setIcon(QIcon(":/icons/metric.png"));
89 
90 // std::cout << "base " << mLastDataActionUid << " " << uid << std::endl;
91  if (uid.contains(mLastDataActionUid))
92  {
93  action->setText(" " + action->text());
94 // std::cout << "indenting " << action->text() << std::endl;
95  }
96  else
97  {
98  mLastDataActionUid = uid;
99  }
100 
101  action->setData(QVariant(qstring_cast(uid)));
102  action->setCheckable(true);
103  std::vector<DataPtr> allVisible = mGroupData->getData(mProperties);
104  action->setChecked(std::count(allVisible.begin(), allVisible.end(), data));
105  connect(action, SIGNAL(triggered()), this, SLOT(dataActionSlot()));
106  parent->addAction(action);
107 }
108 
109 void DataViewPropertiesInteractor::dataActionSlot()
110 {
111  QAction* theAction = static_cast<QAction*>(sender());
112  if(!theAction)
113  return;
114 
115  QString uid = theAction->data().toString();
116  DataPtr data = mBackend->getPatientService()->getData(uid);
117  ImagePtr image = mBackend->getPatientService()->getData<Image>(data->getUid());
118 
119  bool firstData = mGroupData->getData(DataViewProperties::createFull()).empty();
120 
121  DataViewProperties old = mGroupData->getProperties(uid);
122 
123  if (theAction->isChecked())
124  {
125  DataViewProperties props = old.addFlagsIn(mProperties);
126  mGroupData->setProperties(uid, props);
127 
128  if (image)
129  mBackend->getPatientService()->setActiveImage(image);
130  }
131  else
132  {
133  DataViewProperties props = old.removeFlagsIn(mProperties);
134  mGroupData->setProperties(uid, props);
135  }
136 
137  if (firstData)
138  {
139  Navigation(mBackend).centerToGlobalDataCenter(); // reset center for convenience
140  mGroupData->requestInitialize();
141  }
142 }
143 
147 
149  mBackend(backend)
150 {
151 }
152 
154 {
155  mGroupData = group;
156 
157  connect(mGroupData.get(), SIGNAL(dataViewPropertiesChanged(QString)), SLOT(dataViewPropertiesChangedSlot(QString)));
158 // connect(mGroupData.get(), SIGNAL(dataAdded(QString)), SLOT(dataAddedSlot(QString)));
159 // connect(mGroupData.get(), SIGNAL(dataRemoved(QString)), SLOT(dataRemovedSlot(QString)));
160  connect(mGroupData.get(), SIGNAL(videoSourceChanged(QString)), SLOT(videoSourceChangedSlot(QString)));
161 
162  std::vector<DataPtr> data = mGroupData->getData();
163  for (unsigned i = 0; i < data.size(); ++i)
164  this->dataViewPropertiesChangedSlot(data[i]->getUid());
165 
167 
170 }
171 
173 {
174 }
175 
176 void ViewWrapper::contextMenuSlot(const QPoint& point)
177 {
178  QMenu contextMenu;
179  mDataViewPropertiesInteractor->addDataActions(&contextMenu);
180  //append specific info from derived classes
181  this->appendToContextMenu(contextMenu);
182  contextMenu.exec(point);
183 }
184 
185 
187 {
188  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
189 }
190 
192 {
193  if (!mGroupData)
194  return QStringList();
195  std::vector<DataPtr> data = mGroupData->getData(properties);
196 
197  QStringList text;
198  for (unsigned i = 0; i < data.size(); ++i)
199  {
200  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
201  if (metric) // dont show metrics here: too much spam - use separate list is necessary
202  continue;
203  QString line = data[i]->getName();
204 
205  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
206  if (image)
207  {
208  if (image->getCropping())
209  line += " (cropped)";
210  if (!image->getAllClipPlanes().empty())
211  line += " (clipped)";
212  }
213 
214  text << line;
215  }
216  std::reverse(text.begin(), text.end());
217  return text;
218 }
219 
220 } //namespace cx
QString qstring_cast(const T &val)
static DataViewProperties createSlice3D()
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
static DataViewProperties createDefault()
virtual void appendToContextMenu(QMenu &contextMenu)=0
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:93
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
void addDataActions(QWidget *parent)
CoreServicesPtr mBackend
DataViewPropertiesInteractorPtr mDataViewPropertiesInteractor
boost::shared_ptr< class View > ViewPtr
virtual void setViewGroup(ViewGroupDataPtr group)
boost::shared_ptr< class Data > DataPtr
virtual void videoSourceChangedSlot(QString uid)
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
virtual QString getName() const
Definition: cxData.cpp:83
ViewGroupDataPtr mGroupData
A volumetric data set.
Definition: cxImage.h:64
static DataViewProperties createFull()
virtual void dataViewPropertiesChangedSlot(QString uid)
QStringList getAllDataNames(DataViewProperties properties) const
void contextMenuSlot(const QPoint &point)
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
DataViewPropertiesInteractorPtr mShow3DSlicesInteractor
DataViewPropertiesInteractor(CoreServicesPtr backend, ViewGroupDataPtr groupData)
void setDataViewProperties(DataViewProperties properties)
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
void connectContextMenu(ViewPtr view)
ViewWrapper(CoreServicesPtr backend)