Fraxinus  16.5.0-fx-rc8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxViewImplService.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 "cxViewImplService.h"
34 
35 #include <ctkPluginContext.h>
36 #include "cxViewManager.h"
37 #include "cxViewGroup.h"
38 #include "cxRepManager.h"
39 #include "cxVisServices.h"
41 #include "cxXMLNodeWrapper.h"
42 #include "cxLogger.h"
43 #include "cxViewGroupData.h"
44 #include "cxClippers.h"
45 
46 namespace cx
47 {
48 
49 ViewImplService::ViewImplService(ctkPluginContext *context) :
50  mContext(context )
51 {
52  VisServicesPtr services = VisServices::create(context);
53  mSession = SessionStorageServiceProxy::create(mContext);
54  mBase = ViewManager::create(services);
55  mClippers = ClippersPtr(new Clippers(services));
56 
57  if(!viewManager())
58  std::cout << "ViewImplService got no viewManager" << std::endl;
59 // connect(viewManager(), SIGNAL(activeViewChanged()), this, SIGNAL(activeViewChanged()));
60 // connect(viewManager(), &ViewManager::renderingEnabledChanged, this, &ViewService::renderingEnabledChanged);
61 
62  connect(mSession.get(), &SessionStorageService::sessionChanged, this, &ViewImplService::onSessionChanged);
63  connect(mSession.get(), &SessionStorageService::cleared, this, &ViewImplService::onSessionCleared);
64  connect(mSession.get(), &SessionStorageService::isLoading, this, &ViewImplService::onSessionLoad);
65  connect(mSession.get(), &SessionStorageService::isSaving, this, &ViewImplService::onSessionSave);
66 
67  connect(viewManager(), &ViewManager::activeViewChanged, this, &ViewService::activeViewChanged);
68  connect(viewManager(), &ViewManager::fps, this, &ViewService::fps);
71  connect(viewManager(), &ViewManager::pointSampled, this, &ViewService::pointSampled);
72  connect(viewManager(), &ViewManager::renderFinished, this, &ViewService::renderFinished);
73 }
74 
76 {
77 }
78 
79 ViewPtr ViewImplService::get3DView(int group, int index)
80 {
81  return viewManager()->get3DView(group, index);
82 }
83 
85 {
86  return viewManager()->getActiveViewGroup();
87 }
89 {
90  return viewManager()->getViewGroup(groupIdx);
91 }
92 
93 void ViewImplService::setRegistrationMode(REGISTRATION_STATUS mode)
94 {
95  this->getGroup(0)->setRegistrationMode(mode);
96 }
97 
99 {
100  return false;
101 }
102 
104 {
105  CX_LOG_DEBUG() << "About to destruct the visualizationservice and viewmanager, making sure timers are stopped.";
106  viewManager()->enableRender(false);
107 }
108 
110 {
111  viewManager()->autoShowData(data);
112 }
113 
115 {
116  viewManager()->enableRender(val);
117 }
118 
120 {
121  return viewManager()->renderingIsEnabled();
122 }
123 
124 QWidget* ViewImplService::createLayoutWidget(QWidget* parent, int index)
125 {
126  return viewManager()->createLayoutWidget(parent, index);
127 }
128 
130 {
131  return viewManager()->getLayoutWidget(index);
132 }
133 
134 QString ViewImplService::getActiveLayout(int widgetIndex) const
135 {
136  return viewManager()->getActiveLayout(widgetIndex);
137 }
138 
139 void ViewImplService::setActiveLayout(const QString& uid, int widgetIndex)
140 {
141  viewManager()->setActiveLayout(uid, widgetIndex);
142 }
143 
145 {
146  return this->mClippers;
147 }
148 
150 {
151  return viewManager()->getCropper();
152 }
153 
155 {
156  return viewManager()->getRenderTimer();
157 }
158 
160 {
161  return viewManager()->getNavigation();
162 }
163 
165 {
166  viewManager()->centerToImageCenterInViewGroup(this->getActiveGroupId());
167 }
168 
170 {
171  viewManager()->addDefaultLayout(layoutData);
172 }
173 
175 {
176  return viewManager()->getLayoutRepository();
177 }
178 
180 {
181  return viewManager()->getCameraControl();
182 }
183 
185 {
186  return viewManager()->getInteractorStyleActionGroup();
187 }
188 
189 void ViewImplService::onSessionChanged()
190 {
191 }
192 void ViewImplService::onSessionCleared()
193 {
194  viewManager()->clear();
195 }
196 
197 //TODO: save/load clippers
198 void ViewImplService::onSessionLoad(QDomElement& node)
199 {
200  XMLNodeParser root(node);
201  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
202  if (!viewManagerNode.isNull())
203  viewManager()->parseXml(viewManagerNode);
204 
205  mClippers->parseXml(node);
206 }
207 void ViewImplService::onSessionSave(QDomElement& node)
208 {
209  XMLNodeAdder root(node);
210  QDomElement managerNode = root.descend("managers").node().toElement();
211  viewManager()->addXml(managerNode);
212  mClippers->addXml(node);
213 }
214 
215 void ViewImplService::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
216 {
217  viewManager()->setCameraStyle(style, groupIdx);
218 }
219 
220 } /* namespace cx */
QActionGroup * getInteractorStyleActionGroup()
virtual QWidget * getLayoutWidget(int index)
Get the specified layout widget, NULL if not created.
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value...
void activeViewChanged()
emitted when the active view changes
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
virtual int getActiveGroupId() const
virtual ViewPtr get3DView(int group=0, int index=0)
void fps(int number)
Emits number of frames per second.
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
LayoutRepositoryPtr getLayoutRepository()
void renderFinished()
virtual InteractiveCropperPtr getCropper()
void fps(int number)
Emits number of frames per second.
virtual CyclicActionLoggerPtr getRenderTimer()
virtual ViewGroupDataPtr getGroup(int groupIdx) const
virtual bool renderingIsEnabled() const
virtual void setRegistrationMode(REGISTRATION_STATUS mode)
virtual QString getActiveLayout(int widgetIndex) const
static VisServicesPtr create(ctkPluginContext *context)
CameraControlPtr getCameraControl()
static SessionStorageServicePtr create(ctkPluginContext *pluginContext)
QWidget * getLayoutWidget(int index)
virtual void centerToImageCenterInActiveViewGroup()
virtual void addDefaultLayout(LayoutData layoutData)
boost::shared_ptr< class View > ViewPtr
void autoShowData(DataPtr data)
boost::shared_ptr< class Navigation > NavigationPtr
Definition: cxViewGroup.h:54
void pointSampled(Vector3D p_r)
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
virtual void autoShowData(DataPtr data)
virtual NavigationPtr getNavigation()
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
void addXml(QDomNode &parentNode)
boost::shared_ptr< class Data > DataPtr
void parseXml(QDomNode viewmanagerNode)
virtual LayoutRepositoryPtr getLayoutRepository()
void renderFinished()
virtual ClippersPtr getClippers()
void pointSampled(Vector3D p_r)
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
ViewImplService(ctkPluginContext *context)
virtual void aboutToStop()
QWidget * createLayoutWidget(QWidget *parent, int index)
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
InteractiveCropperPtr getCropper()
void activeViewChanged()
emitted when the active view changes
void setActiveLayout(const QString &uid, int widgetIndex=0)
change the layout
void cleared()
emitted when session is cleared, before isLoading is called
virtual QWidget * createLayoutWidget(QWidget *parent, int index)
Get the specified layout widget, create if necessary.
void activeLayoutChanged()
emitted when the active layout changes
Clipper container. Used by ClippersWidget.
Definition: cxClippers.h:50
virtual int getActiveViewGroup() const
boost::shared_ptr< class CameraControl > CameraControlPtr
Definition: cxMainWindow.h:58
void enableRender(bool val)
CyclicActionLoggerPtr getRenderTimer()
#define CX_LOG_DEBUG
Definition: cxLogger.h:110
static ViewManagerPtr create(VisServicesPtr backend)
virtual CameraControlPtr getCameraControl()
bool renderingIsEnabled() const
NavigationPtr getNavigation(int group=0)
virtual ViewGroupDataPtr getViewGroup(int groupIdx) const
boost::shared_ptr< class Clippers > ClippersPtr
void activeLayoutChanged()
emitted when the active layout changes
virtual void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
void isSaving(QDomElement &root)
xml storage is available
virtual void setActiveLayout(const QString &uid, int widgetIndex)
void centerToImageCenterInViewGroup(unsigned groupNr)
virtual void enableRender(bool val)
ViewPtr get3DView(int group=0, int index=0)
void addDefaultLayout(LayoutData layoutData)
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
virtual QActionGroup * getInteractorStyleActionGroup()
QString getActiveLayout(int widgetIndex=0) const
returns the active layout