NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxViewGroup.h"
13 
14 #include <vector>
15 #include <QtWidgets>
16 
17 #include <vtkRenderWindow.h>
18 #include "cxView.h"
19 #include "cxSliceProxy.h"
20 #include "cxSlicerRepSW.h"
21 #include "cxToolRep2D.h"
22 #include "cxUtilHelpers.h"
23 #include "cxSlicePlanes3DRep.h"
24 
25 #include "cxTrackingService.h"
26 #include "cxViewWrapper2D.h"
27 #include "cxCameraControl.h"
28 #include "cxData.h"
29 #include "cxViewWrapper.h"
30 #include "cxManualTool.h"
31 #include "cxVolumeHelpers.h"
32 #include "cxTypeConversions.h"
33 #include "cxCoreServices.h"
34 #include "cxCameraStyle.h"
35 #include "cxPatientModelService.h"
36 #include "cxImage.h"
37 #include "cxMesh.h"
38 #include "cxTrackedStream.h"
39 #include "cxActiveData.h"
40 #include "cxLogger.h"
41 
42 namespace cx
43 {
44 
45 
47 {
48  mBackend = backend;
49  mViewGroupData.reset(new ViewGroupData(backend, uid));
51 
52  connect(mViewGroupData.get(), &ViewGroupData::optionsChanged, this, &ViewGroup::optionChangedSlot);
53  this->optionChangedSlot();
54 }
55 
57 {
58 }
59 
60 void ViewGroup::optionChangedSlot()
61 {
62  mCameraStyle->setCameraStyle(mViewGroupData->getOptions().mCameraStyle);
63 }
64 
67 void ViewGroup::addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
68 {
69  wrapper->setSharedOpenGLContext(sharedOpenGLContext);
70  mViews.push_back(wrapper->getView());
71  mViewWrappers.push_back(wrapper);
72 
73  // add state
74  wrapper->setViewGroup(mViewGroupData);
75  mCameraStyle->addView(wrapper->getView());
76 
77  View* view = wrapper->getView().get();
78  // connect signals
79 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
80  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
81  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
82 }
83 
85 {
86  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
87  {
88  ViewWrapperPtr wrapper = mViewWrappers[i];
89  View* view = wrapper->getView().get();
90 
91 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
92  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
93  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
94  }
95 
96  mViews.clear();
97  mViewWrappers.clear();
98  mCameraStyle->clearViews();
99 }
100 
102 {
103  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
104  {
105  if (mViewWrappers[i]->getView()->getUid() == viewUid)
106  return mViewWrappers[i];
107  }
108  return ViewWrapperPtr();
109 }
110 
112 {
113  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
114  std::vector<MeshPtr> meshes = mViewGroupData->getMeshes(DataViewProperties::createFull());
115  std::vector<TrackedStreamPtr> trackedStreams = mViewGroupData->getTrackedStreams(DataViewProperties::createFull());
116  ActiveDataPtr activeData = mBackend->patient()->getActiveData();
117 
118  if(shouldUpdateActiveData(activeData->getActive<Mesh>(), meshes))
119  activeData->setActive(meshes.front()->getUid());
120  if(shouldUpdateActiveData(activeData->getActive<Image>(), images))
121  activeData->setActive(images.front()->getUid());
122  if(shouldUpdateActiveData(activeData->getActive<TrackedStream>(), trackedStreams))
123  activeData->setActive(trackedStreams.front()->getUid());
124 
125  View* view = static_cast<View*>(this->sender());
126  if (view && mActiveView)
127  mActiveView->set(view->getUid());
128 }
129 
130 template<class T>
131 bool ViewGroup::shouldUpdateActiveData(T activeData, std::vector<T> datas) const
132 {
133  bool activeDataExistsInGroup = std::find(datas.begin(), datas.end(), activeData) != datas.end();
134  return !activeDataExistsInGroup && !datas.empty();
135 }
136 
137 std::vector<ViewPtr> ViewGroup::getViews() const
138 {
139  return mViews;
140 }
141 
143 {
144  mActiveView = val;
145 }
146 
147 void ViewGroup::addXml(QDomNode& dataNode)
148 {
149  mViewGroupData->addXml(dataNode);
150 }
151 
153 {
154  mViewGroupData->clearData();
155 }
156 
157 void ViewGroup::parseXml(QDomNode dataNode)
158 {
159  mViewGroupData->parseXml(dataNode);
160 }
161 
163 {
164  for (unsigned j = 0; j < mViews.size(); ++j)
165  {
166  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
167  return true;
168  }
169  return false;
170 }
171 
172 } //cx
cxSlicePlanes3DRep.h
cxVolumeHelpers.h
cxLogger.h
cxActiveData.h
cx::ViewGroup::getViews
std::vector< ViewPtr > getViews() const
Definition: cxViewGroup.cpp:137
cx::View::getUid
virtual QString getUid()=0
Get a views unique id.
cx::ViewGroup::parseXml
virtual void parseXml(QDomNode dataNode)
load internal state info from dataNode
Definition: cxViewGroup.cpp:157
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxImage.h
cx::View::VIEW_3D
@ VIEW_3D
Definition: cxView.h:54
cx::ViewGroup::initializeActiveView
void initializeActiveView(SyncedValuePtr val)
Definition: cxViewGroup.cpp:142
cxToolRep2D.h
cxUtilHelpers.h
cx::ViewGroup::addXml
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
Definition: cxViewGroup.cpp:147
cx::ViewGroup::contains3DView
bool contains3DView() const
Definition: cxViewGroup.cpp:162
cx::ViewGroupData::optionsChanged
void optionsChanged()
cx::ViewGroup::ViewGroup
ViewGroup(CoreServicesPtr backend, QString uid)
Definition: cxViewGroup.cpp:46
cxViewWrapper.h
cxManualTool.h
cxViewGroup.h
cxData.h
cx::ViewGroup::mBackend
CoreServicesPtr mBackend
Definition: cxViewGroup.h:78
cxCameraControl.h
cx::ViewGroup::removeViews
void removeViews()
Definition: cxViewGroup.cpp:84
cx::CameraStyle
Definition: cxCameraStyle.h:55
cx::CoreServicesPtr
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:37
cxTypeConversions.h
cxCameraStyle.h
cxView.h
cx::ViewGroup::mViewWrappers
std::vector< ViewWrapperPtr > mViewWrappers
Definition: cxViewGroup.h:76
cxPatientModelService.h
cx::ViewGroup::mCameraStyle
CameraStylePtr mCameraStyle
Definition: cxViewGroup.h:77
cx::DataViewProperties::createFull
static DataViewProperties createFull()
Definition: cxViewGroupData.cpp:158
cxViewWrapper2D.h
cx::ViewWrapperPtr
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
Definition: cxForwardDeclarations.h:173
cx::ViewGroup::mActiveView
SyncedValuePtr mActiveView
Definition: cxViewGroup.h:79
cx::ViewGroup::clearPatientData
void clearPatientData()
Definition: cxViewGroup.cpp:152
cx::ViewGroup::mViewGroupData
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:75
cx::Mesh
A mesh data set.
Definition: cxMesh.h:45
cxCoreServices.h
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cx::SyncedValuePtr
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:30
cxSlicerRepSW.h
cx::ViewGroup::mouseClickInViewGroupSlot
void mouseClickInViewGroupSlot()
Definition: cxViewGroup.cpp:111
cx::View
Definition: cxView.h:48
cx::ViewGroup::mViews
std::vector< ViewPtr > mViews
Definition: cxViewGroup.h:73
cx::ActiveDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
cxSliceProxy.h
cx::TrackedStream
A data set for video streams (2D/3D).
Definition: cxTrackedStream.h:29
cx::ViewGroup::addView
void addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
Definition: cxViewGroup.cpp:67
cx::ViewGroupData
Container for data shared between all members of a view group.
Definition: cxViewGroupData.h:108
cxMesh.h
cxTrackingService.h
cx::ViewGroup::~ViewGroup
virtual ~ViewGroup()
Definition: cxViewGroup.cpp:56
cx::ViewGroup::getViewWrapperFromViewUid
ViewWrapperPtr getViewWrapperFromViewUid(QString viewUid)
Definition: cxViewGroup.cpp:101
cxTrackedStream.h
cx::SharedOpenGLContextPtr
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
Definition: cxForwardDeclarations.h:166