NorMIT-nav  16.5
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 "cxTypeConversions.h"
41 #include "cxImageAlgorithms.h"
42 #include "cxDataMetric.h"
43 #include "cxView.h"
44 #include "cxImage.h"
45 #include "cxViewManager.h"
46 #include "cxInteractiveClipper.h"
47 #include "cxVisServices.h"
48 #include "cxNavigation.h"
49 #include "cxActiveData.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->patient()->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->patient()->getData(uid);
80 
81  QAction* action = new QAction(qstring_cast(data->getName()), parent);
82 
83  action->setIcon(data->getIcon());
84 
85 // std::cout << "base " << mLastDataActionUid << " " << uid << std::endl;
86  if (uid.contains(mLastDataActionUid))
87  {
88  action->setText(" " + action->text());
89 // std::cout << "indenting " << action->text() << std::endl;
90  }
91  else
92  {
93  mLastDataActionUid = uid;
94  }
95 
96  action->setData(QVariant(qstring_cast(uid)));
97  action->setCheckable(true);
98  std::vector<DataPtr> allVisible = mGroupData->getData(mProperties);
99  action->setChecked(std::count(allVisible.begin(), allVisible.end(), data));
100  connect(action, SIGNAL(triggered()), this, SLOT(dataActionSlot()));
101  parent->addAction(action);
102 }
103 
104 void DataViewPropertiesInteractor::dataActionSlot()
105 {
106  QAction* theAction = static_cast<QAction*>(sender());
107  if(!theAction)
108  return;
109 
110  QString uid = theAction->data().toString();
111  DataPtr data = mServices->patient()->getData(uid);
112 
113  bool firstData = mGroupData->getData(DataViewProperties::createFull()).empty();
114 
115  DataViewProperties old = mGroupData->getProperties(uid);
116 
117  if (theAction->isChecked())
118  {
119  DataViewProperties props = old.addFlagsIn(mProperties);
120  mGroupData->setProperties(uid, props);
121 
122  if (data)
123  {
124  ActiveDataPtr activeData = mServices->patient()->getActiveData();
125  activeData->setActive(data);
126  }
127  }
128  else
129  {
130  DataViewProperties props = old.removeFlagsIn(mProperties);
131  mGroupData->setProperties(uid, props);
132  }
133 
134  if (firstData)
135  {
136  Navigation(mServices).centerToDataInViewGroup(mGroupData);
137  mGroupData->requestInitialize();
138  }
139 }
140 
144 
146  mServices(services)
147 {
148 }
149 
151 {
152  mGroupData = group;
153 
156 
157  std::vector<DataPtr> data = mGroupData->getData();
158  for (unsigned i = 0; i < data.size(); ++i)
159  this->dataViewPropertiesChangedSlot(data[i]->getUid());
160 
161 
163 
166 }
167 
168 void ViewWrapper::contextMenuSlot(const QPoint& point)
169 {
170  QMenu contextMenu;
171  mDataViewPropertiesInteractor->addDataActions(&contextMenu);
172  //append specific info from derived classes
173  this->appendToContextMenu(contextMenu);
174  contextMenu.exec(point);
175 }
176 
177 
179 {
180  connect(view.get(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuSlot(const QPoint &)));
181 }
182 
184 {
185  if (!mGroupData)
186  return QStringList();
187  std::vector<DataPtr> data = mGroupData->getData(properties);
188 
189  QStringList text;
190  for (unsigned i = 0; i < data.size(); ++i)
191  {
192  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data[i]);
193  if (metric) // dont show metrics here: too much spam - use separate list is necessary
194  continue;
195  QString line = data[i]->getName();
196 
197  ImagePtr image = boost::dynamic_pointer_cast<Image>(data[i]);
198  if (image)
199  {
200  if (image->getCropping())
201  line += " (cropped)";
202  if (!image->getAllClipPlanes().empty())
203  line += " (clipped)";
204  }
205 
206  text << line;
207  }
208  std::reverse(text.begin(), text.end());
209  return text;
210 }
211 
212 } //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:95
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
void addDataActions(QWidget *parent)
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
virtual void videoSourceChangedSlot(QString uid)
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
virtual QString getName() const
Definition: cxData.cpp:89
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)