CustusX  15.8
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 
44 namespace cx
45 {
46 
48  mContext(context )
49 {
50  VisServicesPtr services = VisServices::create(context);
51  mSession = SessionStorageServiceProxy::create(mContext);
52  mBase = ViewManager::create(services);
53 
54  if(!viewManager())
55  std::cout << "VisualizationImplService got no viewManager" << std::endl;
56 // connect(viewManager(), SIGNAL(activeViewChanged()), this, SIGNAL(activeViewChanged()));
57 // connect(viewManager(), &ViewManager::renderingEnabledChanged, this, &VisualizationService::renderingEnabledChanged);
58 
59  connect(mSession.get(), &SessionStorageService::sessionChanged, this, &VisualizationImplService::onSessionChanged);
60  connect(mSession.get(), &SessionStorageService::cleared, this, &VisualizationImplService::onSessionCleared);
61  connect(mSession.get(), &SessionStorageService::isLoading, this, &VisualizationImplService::onSessionLoad);
62  connect(mSession.get(), &SessionStorageService::isSaving, this, &VisualizationImplService::onSessionSave);
63 
65  connect(viewManager(), &ViewManager::fps, this, &VisualizationService::fps);
68 }
69 
71 {
72 }
73 
75 {
76  return viewManager()->get3DView(group, index);
77 }
78 
80 {
81  return viewManager()->getActiveViewGroup();
82 }
84 {
85  return viewManager()->getViewGroup(groupIdx);
86 }
87 
89 {
90  return false;
91 }
92 
94 {
95  CX_LOG_DEBUG() << "About to destruct the visualizationservice and viewmanager, making sure timers are stopped.";
96  viewManager()->enableRender(false);
97 }
98 
100 {
101  viewManager()->autoShowData(data);
102 }
103 
105 {
106  viewManager()->enableRender(val);
107 }
108 
110 {
111  return viewManager()->renderingIsEnabled();
112 }
113 
114 QWidget* VisualizationImplService::getLayoutWidget(QWidget* parent, int index)
115 {
116  return viewManager()->getLayoutWidget(parent, index);
117 }
118 
119 QString VisualizationImplService::getActiveLayout(int widgetIndex) const
120 {
121  return viewManager()->getActiveLayout(widgetIndex);
122 }
123 
124 void VisualizationImplService::setActiveLayout(const QString& uid, int widgetIndex)
125 {
126  viewManager()->setActiveLayout(uid, widgetIndex);
127 }
128 
130 {
131  return viewManager()->getClipper();
132 }
133 
135 {
136  return viewManager()->getCropper();
137 }
138 
140 {
141  return viewManager()->getRenderTimer();
142 }
143 
145 {
146  return viewManager()->getNavigation();
147 }
148 
150 {
151  return viewManager()->getLayoutRepository();
152 }
153 
155 {
156  return viewManager()->getCameraControl();
157 }
158 
160 {
161  return viewManager()->createInteractorStyleActionGroup();
162 }
163 
164 void VisualizationImplService::onSessionChanged()
165 {
166 }
167 void VisualizationImplService::onSessionCleared()
168 {
169  viewManager()->clear();
170 }
171 void VisualizationImplService::onSessionLoad(QDomElement& node)
172 {
173  XMLNodeParser root(node);
174  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
175  if (!viewManagerNode.isNull())
176  viewManager()->parseXml(viewManagerNode);
177 }
178 void VisualizationImplService::onSessionSave(QDomElement& node)
179 {
180  XMLNodeAdder root(node);
181  QDomElement managerNode = root.descend("managers").node().toElement();
182  viewManager()->addXml(managerNode);
183 }
184 
185 
186 } /* namespace cx */
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
virtual InteractiveCropperPtr getCropper()
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 CyclicActionLoggerPtr getRenderTimer()
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
void fps(int number)
Emits number of frames per second.
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
NavigationPtr getNavigation()
LayoutRepositoryPtr getLayoutRepository()
virtual bool renderingIsEnabled() const
virtual void autoShowData(DataPtr data)
void activeLayoutChanged()
emitted when the active layout changes
virtual void enableRender(bool val)
QActionGroup * createInteractorStyleActionGroup()
void fps(int number)
Emits number of frames per second.
static VisServicesPtr create(ctkPluginContext *context)
CameraControlPtr getCameraControl()
static VisualizationServiceOldPtr create(VisServicesPtr backend)
static SessionStorageServicePtr create(ctkPluginContext *pluginContext)
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
boost::shared_ptr< class View > ViewPtr
void autoShowData(DataPtr data)
boost::shared_ptr< class Navigation > NavigationPtr
Definition: cxViewGroup.h:54
virtual ViewGroupDataPtr getGroup(int groupIdx) const
VisualizationImplService(ctkPluginContext *context)
virtual void setActiveLayout(const QString &uid, int widgetIndex)
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
virtual QWidget * getLayoutWidget(QWidget *parent, int index)
virtual InteractiveClipperPtr getClipper()
void addXml(QDomNode &parentNode)
boost::shared_ptr< class Data > DataPtr
void parseXml(QDomNode viewmanagerNode)
QWidget * getLayoutWidget(QWidget *parent, int index)
virtual ViewPtr get3DView(int group=0, int index=0)
InteractiveClipperPtr getClipper()
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
virtual QActionGroup * createInteractorStyleActionGroup()
virtual NavigationPtr getNavigation()
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
InteractiveCropperPtr getCropper()
void setActiveLayout(const QString &uid, int widgetIndex=0)
change the layout
void cleared()
emitted when session is cleared, before isLoading is called
virtual int getActiveViewGroup() const
virtual QString getActiveLayout(int widgetIndex) const
boost::shared_ptr< class CameraControl > CameraControlPtr
Definition: cxMainWindow.h:58
void activeViewChanged()
emitted when the active view changes
void enableRender(bool val)
CyclicActionLoggerPtr getRenderTimer()
#define CX_LOG_DEBUG
Definition: cxLogger.h:109
virtual LayoutRepositoryPtr getLayoutRepository()
bool renderingIsEnabled() const
virtual ViewGroupDataPtr getViewGroup(int groupIdx) const
void activeLayoutChanged()
emitted when the active layout changes
virtual int getActiveGroupId() const
void isSaving(QDomElement &root)
xml storage is available
virtual CameraControlPtr getCameraControl()
ViewPtr get3DView(int group=0, int index=0)
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
QString getActiveLayout(int widgetIndex=0) const
returns the active layout