CustusX  15.8
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 
59 namespace cx
60 {
61 
62 
64 {
65  mBackend = backend;
66  mCameraStyle.reset(new CameraStyle(mBackend));
67 
68  mViewGroupData.reset(new ViewGroupData(backend));
69 }
70 
72 {
73 }
74 
78 {
79  mViews.push_back(wrapper->getView());
80  mViewWrappers.push_back(wrapper);
81 
82  // add state
83  wrapper->setViewGroup(mViewGroupData);
84  mCameraStyle->addView(wrapper->getView());
85 
86  View* view = wrapper->getView().get();
87  // connect signals
88 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
89  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
90  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
91 }
92 
94 {
95  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
96  {
97  ViewWrapperPtr wrapper = mViewWrappers[i];
98  View* view = wrapper->getView().get();
99 
100 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
101  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
102  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
103  }
104 
105  mViews.clear();
106  mViewWrappers.clear();
107  mCameraStyle->clearViews();
108 }
109 
111 {
112  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
113  {
114  if (mViewWrappers[i]->getView()->getUid() == viewUid)
115  return mViewWrappers[i];
116  }
117  return ViewWrapperPtr();
118 }
119 
121 {
122  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
123  {
124  mViewWrappers[i]->setOrientationMode(val);
125  }
126 }
127 
128 void ViewGroup::mouseClickInViewGroupSlot()
129 {
130  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
131  if (!images.empty())
132  {
133  if (!std::count(images.begin(), images.end(), mBackend->getPatientService()->getActiveImage()))
134  {
135  mBackend->getPatientService()->setActiveImage(images.front());
136  }
137  }
138 
139  View* view = static_cast<View*>(this->sender());
140  if (view && mActiveView)
141  mActiveView->set(view->getUid());
142 }
143 
144 std::vector<ViewPtr> ViewGroup::getViews() const
145 {
146  return mViews;
147 }
148 
150 {
151  mActiveView = val;
152 }
153 
154 
155 void ViewGroup::addXml(QDomNode& dataNode)
156 {
157  mViewGroupData->addXml(dataNode);
158 }
159 
161 {
162  mViewGroupData->clearData();
163 }
164 
165 void ViewGroup::parseXml(QDomNode dataNode)
166 {
167  mViewGroupData->parseXml(dataNode);
168 }
169 
171 {
172  for (unsigned j = 0; j < mViews.size(); ++j)
173  {
174  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
175  return true;
176  }
177  return false;
178 }
179 
180 } //cx
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:98
CameraStylePtr mCameraStyle
Definition: cxViewGroup.h:100
CoreServicesPtr mBackend
Definition: cxViewGroup.h:101
void clearPatientData()
std::vector< ViewPtr > mViews
Definition: cxViewGroup.h:96
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
Container for data shared between all members of a view group.
void removeViews()
Definition: cxViewGroup.cpp:93
bool contains3DView() const
static DataViewProperties createFull()
std::vector< ViewWrapperPtr > mViewWrappers
Definition: cxViewGroup.h:99
virtual void parseXml(QDomNode dataNode)
load internal state info from dataNode
ViewWrapperPtr getViewWrapperFromViewUid(QString viewUid)
std::vector< ViewPtr > getViews() const
void syncOrientationMode(SyncedValuePtr val)
virtual ~ViewGroup()
Definition: cxViewGroup.cpp:71
SyncedValuePtr mActiveView
Definition: cxViewGroup.h:102
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:63
void addView(ViewWrapperPtr wrapper)
Definition: cxViewGroup.cpp:77
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
void initializeActiveView(SyncedValuePtr val)