CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxViewServiceProxy.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 "cxViewServiceProxy.h"
34 
35 #include <boost/bind.hpp>
36 #include <ctkPluginContext.h>
37 #include "cxNullDeleter.h"
38 
39 #include <QDomNode>
40 
41 namespace cx
42 {
43 
44 ViewServicePtr ViewServiceProxy::create(ctkPluginContext *pluginContext)
45 {
46  return ViewServicePtr(new ViewServiceProxy(pluginContext));
47 }
48 
49 ViewServiceProxy::ViewServiceProxy(ctkPluginContext *pluginContext) :
50  mPluginContext(pluginContext),
51  mViewService(ViewService::getNullObject())
52 {
53  this->initServiceListener();
54 }
55 
56 ViewPtr ViewServiceProxy::get3DView(int group, int index)
57 {
58  return mViewService->get3DView(group, index);
59 }
60 
62 {
63  return mViewService->getActiveGroupId();
64 }
65 
67 {
68  return mViewService->getGroup(groupIdx);
69 }
70 
71 void ViewServiceProxy::setRegistrationMode(REGISTRATION_STATUS mode)
72 {
73  mViewService->setRegistrationMode(mode);
74 }
75 
76 void ViewServiceProxy::initServiceListener()
77 {
78  mServiceListener.reset(new ServiceTrackerListener<ViewService>(
79  mPluginContext,
80  boost::bind(&ViewServiceProxy::onServiceAdded, this, _1),
81  boost::function<void (ViewService*)>(),
82  boost::bind(&ViewServiceProxy::onServiceRemoved, this, _1)
83  ));
84  mServiceListener->open();
85 }
86 void ViewServiceProxy::onServiceAdded(ViewService* service)
87 {
88  mViewService.reset(service, null_deleter());
89 
91  connect(service, &ViewService::fps, this, &ViewService::fps);
94  connect(service, &ViewService::pointSampled, this, &ViewService::pointSampled);
95 
96  emit activeLayoutChanged();
97  emit activeViewChanged();
99 }
100 
101 void ViewServiceProxy::onServiceRemoved(ViewService *service)
102 {
104  disconnect(service, &ViewService::fps, this, &ViewService::fps);
107  disconnect(service, &ViewService::pointSampled, this, &ViewService::pointSampled);
108 
109  mViewService = ViewService::getNullObject();
110 
111  emit activeLayoutChanged();
112  emit activeViewChanged();
114 }
115 
117 {
118  return mViewService->isNull();
119 }
120 
122 {
123  mViewService->aboutToStop();
124 }
125 
127 {
128  mViewService->autoShowData(data);
129 }
130 
132 {
133  mViewService->enableRender(val);
134 }
135 
137 {
138  return mViewService->renderingIsEnabled();
139 }
140 
141 QWidget* ViewServiceProxy::createLayoutWidget(QWidget* parent, int index)
142 {
143  return mViewService->createLayoutWidget(parent, index);
144 }
145 
147 {
148  return mViewService->getLayoutWidget(index);
149 }
150 
151 QString ViewServiceProxy::getActiveLayout(int widgetIndex) const
152 {
153  return mViewService->getActiveLayout(widgetIndex);
154 }
155 
156 void ViewServiceProxy::setActiveLayout(const QString& uid, int widgetIndex)
157 {
158  mViewService->setActiveLayout(uid, widgetIndex);
159 }
160 
162 {
163  return mViewService->getCropper();
164 }
165 
167 {
168  return mViewService->getRenderTimer();
169 }
170 
172 {
173  return mViewService->getNavigation();
174 }
175 
177 {
178  return mViewService->getLayoutRepository();
179 }
180 
182 {
183  return mViewService->getCameraControl();
184 }
185 
187 {
188  return mViewService->getInteractorStyleActionGroup();
189 }
190 
192 {
193  return mViewService->centerToImageCenterInActiveViewGroup();
194 }
195 
196 void ViewServiceProxy::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
197 {
198  mViewService->setCameraStyle(style, groupIdx);
199 }
200 
202 {
203  mViewService->addDefaultLayout(layoutData);
204 }
205 
207 {
208  return mViewService->getClippers();
209 }
210 
211 } //cx
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
virtual QWidget * getLayoutWidget(int index)
Get the specified layout widget, NULL if not created.
Visualization services.
Definition: cxViewService.h:70
virtual void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
virtual QWidget * createLayoutWidget(QWidget *parent, int index)
Get the specified layout widget, create if necessary.
virtual void setRegistrationMode(REGISTRATION_STATUS mode)
virtual CameraControlPtr getCameraControl()
ViewServiceProxy(ctkPluginContext *pluginContext)
virtual LayoutRepositoryPtr getLayoutRepository()
void fps(int number)
Emits number of frames per second.
virtual ViewGroupDataPtr getGroup(int groupIdx) const
virtual CyclicActionLoggerPtr getRenderTimer()
boost::shared_ptr< class ViewService > ViewServicePtr
virtual InteractiveCropperPtr getCropper()
virtual int getActiveGroupId() const
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class Navigation > NavigationPtr
Definition: cxViewGroup.h:54
virtual void centerToImageCenterInActiveViewGroup()
virtual ClippersPtr getClippers()
void pointSampled(Vector3D p_r)
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
boost::shared_ptr< class Data > DataPtr
virtual QString getActiveLayout(int widgetIndex=0) const
virtual void enableRender(bool val)
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
virtual void autoShowData(DataPtr data)
virtual ViewPtr get3DView(int group=0, int index=0)
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
void activeViewChanged()
emitted when the active view changes
virtual void addDefaultLayout(LayoutData layoutData)
static ViewServicePtr getNullObject()
void activeLayoutChanged()
emitted when the active layout changes
Helper class for listening to services being added, modified and removed.
virtual QActionGroup * getInteractorStyleActionGroup()
boost::shared_ptr< class CameraControl > CameraControlPtr
Definition: cxMainWindow.h:58
virtual NavigationPtr getNavigation()
virtual bool renderingIsEnabled() const
static ViewServicePtr create(ctkPluginContext *pluginContext)
boost::shared_ptr< class Clippers > ClippersPtr
virtual void setActiveLayout(const QString &uid, int widgetIndex)