CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxViewGroup.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 "cxViewGroup.h"
34 
35 #include <vector>
36 #include <QtWidgets>
37 
38 #include <vtkRenderWindow.h>
39 #include "cxView.h"
40 #include "cxSliceProxy.h"
41 #include "cxSlicerRepSW.h"
42 #include "cxToolRep2D.h"
43 #include "cxUtilHelpers.h"
44 #include "cxSlicePlanes3DRep.h"
45 
46 #include "cxTrackingService.h"
47 #include "cxViewWrapper2D.h"
48 #include "cxViewManager.h"
49 #include "cxCameraControl.h"
50 #include "cxData.h"
51 #include "cxViewWrapper.h"
52 #include "cxManualTool.h"
53 #include "cxVolumeHelpers.h"
54 #include "cxTypeConversions.h"
55 #include "cxCoreServices.h"
56 #include "cxCameraStyle.h"
57 #include "cxPatientModelService.h"
58 #include "cxImage.h"
59 #include "cxMesh.h"
60 #include "cxTrackedStream.h"
61 #include "cxActiveData.h"
62 
63 namespace cx
64 {
65 
66 
68 {
69  mBackend = backend;
70  mViewGroupData.reset(new ViewGroupData(backend, uid));
72 
73  connect(mViewGroupData.get(), &ViewGroupData::optionsChanged, this, &ViewGroup::optionChangedSlot);
74  this->optionChangedSlot();
75 }
76 
78 {
79 }
80 
81 void ViewGroup::optionChangedSlot()
82 {
83  mCameraStyle->setCameraStyle(mViewGroupData->getOptions().mCameraStyle);
84 }
85 
89 {
90  mViews.push_back(wrapper->getView());
91  mViewWrappers.push_back(wrapper);
92 
93  // add state
94  wrapper->setViewGroup(mViewGroupData);
95  mCameraStyle->addView(wrapper->getView());
96 
97  View* view = wrapper->getView().get();
98  // connect signals
99 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
100  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
101  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
102 }
103 
105 {
106  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
107  {
108  ViewWrapperPtr wrapper = mViewWrappers[i];
109  View* view = wrapper->getView().get();
110 
111 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
112  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
113  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
114  }
115 
116  mViews.clear();
117  mViewWrappers.clear();
118  mCameraStyle->clearViews();
119 }
120 
122 {
123  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
124  {
125  if (mViewWrappers[i]->getView()->getUid() == viewUid)
126  return mViewWrappers[i];
127  }
128  return ViewWrapperPtr();
129 }
130 
132 {
133  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
134  std::vector<MeshPtr> meshes = mViewGroupData->getMeshes(DataViewProperties::createFull());
135  std::vector<TrackedStreamPtr> trackedStreams = mViewGroupData->getTrackedStreams(DataViewProperties::createFull());
136  ActiveDataPtr activeData = mBackend->patient()->getActiveData();
137 
138  if(shouldUpdateActiveData(activeData->getActive<Mesh>(), meshes))
139  activeData->setActive(meshes.front()->getUid());
140  if(shouldUpdateActiveData(activeData->getActive<Image>(), images))
141  activeData->setActive(images.front()->getUid());
142  if(shouldUpdateActiveData(activeData->getActive<TrackedStream>(), trackedStreams))
143  activeData->setActive(trackedStreams.front()->getUid());
144 
145  View* view = static_cast<View*>(this->sender());
146  if (view && mActiveView)
147  mActiveView->set(view->getUid());
148 }
149 
150 template<class T>
151 bool ViewGroup::shouldUpdateActiveData(T activeData, std::vector<T> datas) const
152 {
153  bool activeDataExistsInGroup = std::find(datas.begin(), datas.end(), activeData) != datas.end();
154  return !activeDataExistsInGroup && !datas.empty();
155 }
156 
157 std::vector<ViewPtr> ViewGroup::getViews() const
158 {
159  return mViews;
160 }
161 
163 {
164  mActiveView = val;
165 }
166 
167 void ViewGroup::addXml(QDomNode& dataNode)
168 {
169  mViewGroupData->addXml(dataNode);
170 }
171 
173 {
174  mViewGroupData->clearData();
175 }
176 
177 void ViewGroup::parseXml(QDomNode dataNode)
178 {
179  mViewGroupData->parseXml(dataNode);
180 }
181 
183 {
184  for (unsigned j = 0; j < mViews.size(); ++j)
185  {
186  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
187  return true;
188  }
189  return false;
190 }
191 
192 } //cx
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:96
A mesh data set.
Definition: cxMesh.h:66
CameraStylePtr mCameraStyle
Definition: cxViewGroup.h:98
CoreServicesPtr mBackend
Definition: cxViewGroup.h:99
void clearPatientData()
std::vector< ViewPtr > mViews
Definition: cxViewGroup.h:94
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
Container for data shared between all members of a view group.
A data set for video streams (2D/3D).
void mouseClickInViewGroupSlot()
void removeViews()
A volumetric data set.
Definition: cxImage.h:66
bool contains3DView() const
static DataViewProperties createFull()
std::vector< ViewWrapperPtr > mViewWrappers
Definition: cxViewGroup.h:97
virtual void parseXml(QDomNode dataNode)
load internal state info from dataNode
ViewWrapperPtr getViewWrapperFromViewUid(QString viewUid)
virtual QString getUid()=0
Get a views unique id.
std::vector< ViewPtr > getViews() const
virtual ~ViewGroup()
Definition: cxViewGroup.cpp:77
SyncedValuePtr mActiveView
Definition: cxViewGroup.h:100
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:51
void addView(ViewWrapperPtr wrapper)
Definition: cxViewGroup.cpp:88
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
void initializeActiveView(SyncedValuePtr val)
ViewGroup(CoreServicesPtr backend, QString uid)
Definition: cxViewGroup.cpp:67