CustusX  15.3.4-beta
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 "cxThresholdPreview.h"
40 #include "cxCoreServices.h"
42 #include "cxXMLNodeWrapper.h"
43 #include "cxLogger.h"
44 
45 namespace cx
46 {
47 
49  mContext(context )
50 {
51  CoreServicesPtr backend = CoreServices::create(context);
52  mSession = SessionStorageServiceProxy::create(mContext);
53  mBase = ViewManager::create(backend);
54 
55  if(!viewManager())
56  std::cout << "VisualizationImplService got no viewManager" << std::endl;
57 // connect(viewManager(), SIGNAL(activeViewChanged()), this, SIGNAL(activeViewChanged()));
58 // connect(viewManager(), &ViewManager::renderingEnabledChanged, this, &VisualizationService::renderingEnabledChanged);
59 
60  connect(mSession.get(), &SessionStorageService::sessionChanged, this, &VisualizationImplService::onSessionChanged);
61  connect(mSession.get(), &SessionStorageService::cleared, this, &VisualizationImplService::onSessionCleared);
62  connect(mSession.get(), &SessionStorageService::isLoading, this, &VisualizationImplService::onSessionLoad);
63  connect(mSession.get(), &SessionStorageService::isSaving, this, &VisualizationImplService::onSessionSave);
64 
66  connect(viewManager(), &ViewManager::fps, this, &VisualizationService::fps);
69 }
70 
72 {
73 }
74 
76 {
77  return viewManager()->get3DView(group, index);
78 }
79 
81 {
82  return viewManager()->getActiveViewGroup();
83 }
85 {
86  return viewManager()->getViewGroup(groupIdx);
87 }
88 
90 {
91  return false;
92 }
93 
95 {
96  CX_LOG_DEBUG() << "About to destruct the visualizationservice and viewmanager, making sure timers are stopped.";
97  viewManager()->enableRender(false);
98 }
99 
101 {
102  viewManager()->autoShowData(data);
103 }
104 
106 {
107  viewManager()->enableRender(val);
108 }
109 
111 {
112  return viewManager()->renderingIsEnabled();
113 }
114 
115 QWidget* VisualizationImplService::getLayoutWidget(QWidget* parent, int index)
116 {
117  return viewManager()->getLayoutWidget(parent, index);
118 }
119 
120 QString VisualizationImplService::getActiveLayout(int widgetIndex) const
121 {
122  return viewManager()->getActiveLayout(widgetIndex);
123 }
124 
125 void VisualizationImplService::setActiveLayout(const QString& uid, int widgetIndex)
126 {
127  viewManager()->setActiveLayout(uid, widgetIndex);
128 }
129 
131 {
132  return viewManager()->getClipper();
133 }
134 
136 {
137  return viewManager()->getCropper();
138 }
139 
141 {
142  return viewManager()->getRenderTimer();
143 }
144 
146 {
147  return viewManager()->getNavigation();
148 }
149 
151 {
152  return viewManager()->getLayoutRepository();
153 }
154 
156 {
157  return viewManager()->getCameraControl();
158 }
159 
161 {
162  return viewManager()->createInteractorStyleActionGroup();
163 }
164 
165 void VisualizationImplService::setPreview(ImagePtr image, const std::vector<double>& threshold)
166 {
167  if (threshold.size()==1)
168  RepManager::getInstance()->getThresholdPreview()->setPreview(image, threshold[0]);
169  if (threshold.size()==2)
170  RepManager::getInstance()->getThresholdPreview()->setPreview(image, Eigen::Vector2d(threshold[0], threshold[1]));
171 }
172 
174 {
175  RepManager::getInstance()->getThresholdPreview()->removePreview();
176 }
177 
178 void VisualizationImplService::onSessionChanged()
179 {
180 }
181 void VisualizationImplService::onSessionCleared()
182 {
183  viewManager()->clear();
184 }
185 void VisualizationImplService::onSessionLoad(QDomElement& node)
186 {
187  XMLNodeParser root(node);
188  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
189  if (!viewManagerNode.isNull())
190  viewManager()->parseXml(viewManagerNode);
191 }
192 void VisualizationImplService::onSessionSave(QDomElement& node)
193 {
194  XMLNodeAdder root(node);
195  QDomElement managerNode = root.descend("managers").node().toElement();
196  viewManager()->addXml(managerNode);
197 }
198 
199 
200 } /* namespace cx */
virtual int getActiveGroup() const
static VisualizationServiceOldPtr create(CoreServicesPtr backend)
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
static RepManager * getInstance()
get the only instance of this class
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
virtual CyclicActionLoggerPtr getRenderTimer()
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
virtual void setPreview(ImagePtr image, const std::vector< double > &threshold)
void fps(int number)
Emits number of frames per second.
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.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
CameraControlPtr getCameraControl()
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()
static CoreServicesPtr create(ctkPluginContext *context)
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:57
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()
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
bool renderingIsEnabled() const
virtual ViewGroupDataPtr getViewGroup(int groupIdx) const
void activeLayoutChanged()
emitted when the active layout changes
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
ThresholdPreviewPtr getThresholdPreview()
Get the ThresholdPreview object.