Fraxinus  17.12-rc4
An IGT application
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);
96 
97  emit activeLayoutChanged();
98  emit activeViewChanged();
100 }
101 
102 void ViewServiceProxy::onServiceRemoved(ViewService *service)
103 {
105  disconnect(service, &ViewService::fps, this, &ViewService::fps);
108  disconnect(service, &ViewService::pointSampled, this, &ViewService::pointSampled);
109  disconnect(service, &ViewService::renderFinished, this, &ViewService::renderFinished);
110 
111  mViewService = ViewService::getNullObject();
112 
113  emit activeLayoutChanged();
114  emit activeViewChanged();
116 }
117 
119 {
120  return mViewService->isNull();
121 }
122 
124 {
125  mViewService->aboutToStop();
126 }
127 
129 {
130  mViewService->autoShowData(data);
131 }
132 
134 {
135  mViewService->enableRender(val);
136 }
137 
139 {
140  return mViewService->renderingIsEnabled();
141 }
142 
143 QWidget* ViewServiceProxy::createLayoutWidget(QWidget* parent, int index)
144 {
145  return mViewService->createLayoutWidget(parent, index);
146 }
147 
149 {
150  return mViewService->getLayoutWidget(index);
151 }
152 
153 QString ViewServiceProxy::getActiveLayout(int widgetIndex) const
154 {
155  return mViewService->getActiveLayout(widgetIndex);
156 }
157 
158 void ViewServiceProxy::setActiveLayout(const QString& uid, int widgetIndex)
159 {
160  mViewService->setActiveLayout(uid, widgetIndex);
161 }
162 
164 {
165  return mViewService->getCropper();
166 }
167 
169 {
170  return mViewService->getRenderTimer();
171 }
172 
174 {
175  return mViewService->getNavigation();
176 }
177 
179 {
180  return mViewService->getLayoutRepository();
181 }
182 
184 {
185  return mViewService->getCameraControl();
186 }
187 
189 {
190  return mViewService->getInteractorStyleActionGroup();
191 }
192 
194 {
195  return mViewService->centerToImageCenterInActiveViewGroup();
196 }
197 
198 void ViewServiceProxy::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
199 {
200  mViewService->setCameraStyle(style, groupIdx);
201 }
202 
203 void ViewServiceProxy::zoomCamera3D(int viewGroup3DNumber, int zoomFactor)
204 {
205  mViewService->zoomCamera3D(viewGroup3DNumber, zoomFactor);
206 }
207 
209 {
210  mViewService->addDefaultLayout(layoutData);
211 }
212 
214 {
215  mViewService->enableContextMenuForViews(enable);
216 }
217 
219 {
220  return mViewService->getClippers();
221 }
222 
223 } //cx
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
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:71
virtual void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
virtual QWidget * createLayoutWidget(QWidget *parent, int index)
Get the specified layout widget, create if necessary.
boost::shared_ptr< class CameraControl > CameraControlPtr
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
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
virtual InteractiveCropperPtr getCropper()
virtual int getActiveGroupId() const
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class Clippers > ClippersPtr
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)
void renderFinished()
virtual void autoShowData(DataPtr data)
virtual ViewPtr get3DView(int group=0, int index=0)
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()
virtual NavigationPtr getNavigation(int group=0)
virtual bool renderingIsEnabled() const
virtual void zoomCamera3D(int viewGroup3DNumber, int zoomFactor)
static ViewServicePtr create(ctkPluginContext *pluginContext)
boost::shared_ptr< class Navigation > NavigationPtr
virtual void enableContextMenuForViews(bool enable=true)
virtual void setActiveLayout(const QString &uid, int widgetIndex)
Namespace for all CustusX production code.