CustusX  16.12
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 
68  connect(viewManager(), &ViewManager::fps, this, &ViewService::fps);
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  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 {
166 }
167 
169 {
170  viewManager()->addDefaultLayout(layoutData);
171 }
172 
174 {
176 }
177 
179 {
180  return viewManager()->getLayoutRepository();
181 }
182 
184 {
185  return viewManager()->getCameraControl();
186 }
187 
189 {
191 }
192 
193 void ViewImplService::onSessionChanged()
194 {
195 }
196 void ViewImplService::onSessionCleared()
197 {
198  viewManager()->clear();
199 }
200 
201 //TODO: save/load clippers
202 void ViewImplService::onSessionLoad(QDomElement& node)
203 {
204  XMLNodeParser root(node);
205  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
206  if (!viewManagerNode.isNull())
207  viewManager()->parseXml(viewManagerNode);
208 
209  mClippers->parseXml(node);
210 }
211 void ViewImplService::onSessionSave(QDomElement& node)
212 {
213  XMLNodeAdder root(node);
214  QDomElement managerNode = root.descend("managers").node().toElement();
215  viewManager()->addXml(managerNode);
216  mClippers->addXml(node);
217 }
218 
219 void ViewImplService::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
220 {
221  viewManager()->setCameraStyle(style, groupIdx);
222 }
223 
224 } /* 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 void enableContextMenuForViews(bool enable=true)
virtual bool renderingIsEnabled() const
ViewManager * viewManager() 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()
static ViewManagerPtr create(VisServicesPtr backend)
virtual CameraControlPtr getCameraControl()
bool renderingIsEnabled() const
NavigationPtr getNavigation(int group=0)
void enableContextMenuForViews(bool enable=true)
ViewManagerPtr mBase
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