NorMIT-nav  16.5
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 }
73 
75 {
76 }
77 
78 ViewPtr ViewImplService::get3DView(int group, int index)
79 {
80  return viewManager()->get3DView(group, index);
81 }
82 
84 {
85  return viewManager()->getActiveViewGroup();
86 }
88 {
89  return viewManager()->getViewGroup(groupIdx);
90 }
91 
92 void ViewImplService::setRegistrationMode(REGISTRATION_STATUS mode)
93 {
94  this->getGroup(0)->setRegistrationMode(mode);
95 }
96 
98 {
99  return false;
100 }
101 
103 {
104  CX_LOG_DEBUG() << "About to destruct the visualizationservice and viewmanager, making sure timers are stopped.";
105  viewManager()->enableRender(false);
106 }
107 
109 {
110  viewManager()->autoShowData(data);
111 }
112 
114 {
115  viewManager()->enableRender(val);
116 }
117 
119 {
120  return viewManager()->renderingIsEnabled();
121 }
122 
123 QWidget* ViewImplService::createLayoutWidget(QWidget* parent, int index)
124 {
125  return viewManager()->createLayoutWidget(parent, index);
126 }
127 
129 {
130  return viewManager()->getLayoutWidget(index);
131 }
132 
133 QString ViewImplService::getActiveLayout(int widgetIndex) const
134 {
135  return viewManager()->getActiveLayout(widgetIndex);
136 }
137 
138 void ViewImplService::setActiveLayout(const QString& uid, int widgetIndex)
139 {
140  viewManager()->setActiveLayout(uid, widgetIndex);
141 }
142 
144 {
145  return this->mClippers;
146 }
147 
149 {
150  return viewManager()->getCropper();
151 }
152 
154 {
155  return viewManager()->getRenderTimer();
156 }
157 
159 {
160  return viewManager()->getNavigation();
161 }
162 
164 {
165  viewManager()->centerToImageCenterInViewGroup(this->getActiveGroupId());
166 }
167 
169 {
170  viewManager()->addDefaultLayout(layoutData);
171 }
172 
174 {
175  return viewManager()->getLayoutRepository();
176 }
177 
179 {
180  return viewManager()->getCameraControl();
181 }
182 
184 {
185  return viewManager()->getInteractorStyleActionGroup();
186 }
187 
188 void ViewImplService::onSessionChanged()
189 {
190 }
191 void ViewImplService::onSessionCleared()
192 {
193  viewManager()->clear();
194 }
195 
196 //TODO: save/load clippers
197 void ViewImplService::onSessionLoad(QDomElement& node)
198 {
199  XMLNodeParser root(node);
200  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
201  if (!viewManagerNode.isNull())
202  viewManager()->parseXml(viewManagerNode);
203 
204  mClippers->parseXml(node);
205 }
206 void ViewImplService::onSessionSave(QDomElement& node)
207 {
208  XMLNodeAdder root(node);
209  QDomElement managerNode = root.descend("managers").node().toElement();
210  viewManager()->addXml(managerNode);
211  mClippers->addXml(node);
212 }
213 
214 void ViewImplService::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
215 {
216  viewManager()->setCameraStyle(style, groupIdx);
217 }
218 
219 } /* 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()
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()
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