NorMIT-nav  16.5
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  mCameraStyle.reset(new CameraStyle(mBackend));
71 
72  mViewGroupData.reset(new ViewGroupData(backend));
73 }
74 
76 {
77 }
78 
82 {
83  mViews.push_back(wrapper->getView());
84  mViewWrappers.push_back(wrapper);
85 
86  // add state
87  wrapper->setViewGroup(mViewGroupData);
88  mCameraStyle->addView(wrapper->getView());
89 
90  View* view = wrapper->getView().get();
91  // connect signals
92 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
93  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
94  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
95 }
96 
98 {
99  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
100  {
101  ViewWrapperPtr wrapper = mViewWrappers[i];
102  View* view = wrapper->getView().get();
103 
104 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
105  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
106  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
107  }
108 
109  mViews.clear();
110  mViewWrappers.clear();
111  mCameraStyle->clearViews();
112 }
113 
115 {
116  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
117  {
118  if (mViewWrappers[i]->getView()->getUid() == viewUid)
119  return mViewWrappers[i];
120  }
121  return ViewWrapperPtr();
122 }
123 
125 {
126  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
127  std::vector<MeshPtr> meshes = mViewGroupData->getMeshes(DataViewProperties::createFull());
128  std::vector<TrackedStreamPtr> trackedStreams = mViewGroupData->getTrackedStreams(DataViewProperties::createFull());
129  ActiveDataPtr activeData = mBackend->patient()->getActiveData();
130 
131  if(shouldUpdateActiveData(activeData->getActive<Mesh>(), meshes))
132  activeData->setActive(meshes.front()->getUid());
133  if(shouldUpdateActiveData(activeData->getActive<Image>(), images))
134  activeData->setActive(images.front()->getUid());
135  if(shouldUpdateActiveData(activeData->getActive<TrackedStream>(), trackedStreams))
136  activeData->setActive(trackedStreams.front()->getUid());
137 
138  View* view = static_cast<View*>(this->sender());
139  if (view && mActiveView)
140  mActiveView->set(view->getUid());
141 }
142 
143 template<class T>
144 bool ViewGroup::shouldUpdateActiveData(T activeData, std::vector<T> datas) const
145 {
146  bool activeDataExistsInGroup = std::find(datas.begin(), datas.end(), activeData) != datas.end();
147  return !activeDataExistsInGroup && !datas.empty();
148 }
149 
150 std::vector<ViewPtr> ViewGroup::getViews() const
151 {
152  return mViews;
153 }
154 
156 {
157  mActiveView = val;
158 }
159 
160 void ViewGroup::addXml(QDomNode& dataNode)
161 {
162  mViewGroupData->addXml(dataNode);
163 }
164 
166 {
167  mViewGroupData->clearData();
168 }
169 
170 void ViewGroup::parseXml(QDomNode dataNode)
171 {
172  mViewGroupData->parseXml(dataNode);
173 }
174 
176 {
177  for (unsigned j = 0; j < mViews.size(); ++j)
178  {
179  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
180  return true;
181  }
182  return false;
183 }
184 
185 } //cx
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:96
A mesh data set.
Definition: cxMesh.h:61
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()
Definition: cxViewGroup.cpp:97
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:75
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
ViewGroup(CoreServicesPtr backend)
Definition: cxViewGroup.cpp:67
void addView(ViewWrapperPtr wrapper)
Definition: cxViewGroup.cpp:81
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
void initializeActiveView(SyncedValuePtr val)