CustusX  15.8
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 "cxVisServices.h"
49 #include "cxNavigation.h"
50 
51 namespace cx
52 {
53 
55  mServices(services),
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(mServices->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 = mServices->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 = mServices->getPatientService()->getData(uid);
117  ImagePtr image = mServices->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  mServices->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(mServices).centerToDataInActiveViewGroup(); // reset center for convenience
140  mGroupData->requestInitialize();
141  }
142 }
143 
147 
149  mServices(services)
150 {
151 }
152 
154 {
155  mGroupData = group;
156 
159 
160  std::vector<DataPtr> data = mGroupData->getData();
161  for (unsigned i = 0; i < data.size(); ++i)
162  this->dataViewPropertiesChangedSlot(data[i]->getUid());
163 
164 
166 
169 }
170 
171 void ViewWrapper::contextMenuSlot(const QPoint& point)
172 {
173  QMenu contextMenu;
174  mDataViewPropertiesInteractor->addDataActions(&contextMenu);
175  //append specific info from derived classes
176  this->appendToContextMenu(contextMenu);
177  contextMenu.exec(point);
178 }
179 
180 
182 {
183  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
184 }
185 
187 {
188  if (!mGroupData)
189  return QStringList();
190  std::vector<DataPtr> data = mGroupData->getData(properties);
191 
192  QStringList text;
193  for (unsigned i = 0; i < data.size(); ++i)
194  {
195  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
196  if (metric) // dont show metrics here: too much spam - use separate list is necessary
197  continue;
198  QString line = data[i]->getName();
199 
200  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
201  if (image)
202  {
203  if (image->getCropping())
204  line += " (cropped)";
205  if (!image->getAllClipPlanes().empty())
206  line += " (clipped)";
207  }
208 
209  text << line;
210  }
211  std::reverse(text.begin(), text.end());
212  return text;
213 }
214 
215 } //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< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:93
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
void addDataActions(QWidget *parent)
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
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:66
DataViewPropertiesInteractor(VisServicesPtr services, ViewGroupDataPtr groupData)
static DataViewProperties createFull()
void dataViewPropertiesChanged(QString uid)
VisServicesPtr mServices
QStringList getAllDataNames(DataViewProperties properties) const
void contextMenuSlot(const QPoint &point)
DataViewPropertiesInteractorPtr mShow3DSlicesInteractor
void videoSourceChanged(QString uid)
void setDataViewProperties(DataViewProperties properties)
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
void connectContextMenu(ViewPtr view)
ViewWrapper(VisServicesPtr backend)