Fraxinus  16.5.0-fx-rc8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTrackingServiceProxy.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 "cxTrackingServiceProxy.h"
34 
35 #include <boost/bind.hpp>
36 #include <ctkPluginContext.h>
37 #include "cxNullDeleter.h"
38 
39 
40 namespace cx
41 {
42 
43 TrackingServicePtr TrackingServiceProxy::create(ctkPluginContext *pluginContext)
44 {
45  return TrackingServicePtr(new TrackingServiceProxy(pluginContext));
46 }
47 
48 TrackingServiceProxy::TrackingServiceProxy(ctkPluginContext *pluginContext) :
49  mPluginContext(pluginContext),
50  mTrackingService(TrackingService::getNullObject())
51 {
52  this->initServiceListener();
53 }
54 
55 void TrackingServiceProxy::initServiceListener()
56 {
57  mServiceListener.reset(new ServiceTrackerListener<TrackingService>(
58  mPluginContext,
59  boost::bind(&TrackingServiceProxy::onServiceAdded, this, _1),
60  boost::function<void (TrackingService*)>(),
61  boost::bind(&TrackingServiceProxy::onServiceRemoved, this, _1)
62  ));
63  mServiceListener->open();
64 }
65 void TrackingServiceProxy::onServiceAdded(TrackingService* service)
66 {
67  mTrackingService.reset(service, null_deleter());
68 
69  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
70  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
71 
72  emit stateChanged();
73  emit activeToolChanged(mTrackingService->getActiveTool()->getUid());
74 }
75 
76 void TrackingServiceProxy::onServiceRemoved(TrackingService *service)
77 {
78  disconnect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
79  disconnect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
80 
81  mTrackingService = TrackingService::getNullObject();
82 
83  emit stateChanged();
84  emit activeToolChanged("");
85 }
86 
88 {
89  return mTrackingService->isNull();
90 }
91 
93 {
94  return mTrackingService->getState();
95 }
96 
98 {
99  mTrackingService->setState(val);
100 }
101 
103 {
104  return mTrackingService->getTool(uid);
105 }
106 
108 {
109  return mTrackingService->getActiveTool();
110 }
111 
112 void TrackingServiceProxy::setActiveTool(const QString& uid)
113 {
114  mTrackingService->setActiveTool(uid);
115 }
116 
118 {
119  return mTrackingService->getFirstProbe();
120 }
121 
123 {
124  return mTrackingService->getReferenceTool();
125 }
126 
128 {
129  return mTrackingService->getManualTool();
130 }
131 
133 {
134  return mTrackingService->getTools();
135 }
136 
138 {
139  return mTrackingService->isPlaybackMode();
140 }
141 
143 {
144  mTrackingService->setPlaybackMode(controller);
145 }
146 
148 {
149  return mTrackingService->getSessionHistory(startTime, stopTime);
150 }
151 
153 {
154  mTrackingService->runDummyTool(tool);
155 }
156 
158 {
159  return mTrackingService->getConfiguration();
160 }
161 
162 
164 {
165  mTrackingService->installTrackingSystem(system);
166 }
167 
169 {
170  mTrackingService->unInstallTrackingSystem(system);
171 }
172 
173 std::vector<TrackingSystemServicePtr> TrackingServiceProxy::getTrackingSystems()
174 {
175  return mTrackingService->getTrackingSystems();
176 }
177 
178 
179 
180 } //cx
virtual void installTrackingSystem(TrackingSystemServicePtr system)
virtual ToolPtr getActiveTool()
get the tool that has higest priority when tracking
virtual TrackerConfigurationPtr getConfiguration()
std::map< ToolPtr, TimedTransformMap > SessionToolHistoryMap
boost::shared_ptr< class TrackingService > TrackingServicePtr
virtual void setActiveTool(const QString &uid)
set a tool to be the active tool
virtual bool isPlaybackMode() const
virtual void setState(const Tool::State val)
static TrackingServicePtr getNullObject()
static TrackingServicePtr create(ctkPluginContext *pluginContext)
virtual ToolPtr getReferenceTool() const
tool used as patient reference
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
virtual void unInstallTrackingSystem(TrackingSystemServicePtr system)
boost::shared_ptr< class DummyTool > DummyToolPtr
boost::shared_ptr< class TrackerConfiguration > TrackerConfigurationPtr
void activeToolChanged(const QString &uId)
TrackingServiceProxy(ctkPluginContext *pluginContext)
virtual SessionToolHistoryMap getSessionHistory(double startTime, double stopTime)
virtual ToolPtr getFirstProbe()
get the active probe or any if none active
Service providing tools and tracking systems.
Helper class for listening to services being added, modified and removed.
std::map< QString, ToolPtr > ToolMap
virtual ToolPtr getTool(const QString &uid)
get a tool
virtual ToolPtr getManualTool()
a mouse-controllable virtual tool that is available even when not tracking.
virtual void runDummyTool(DummyToolPtr tool)
virtual ToolMap getTools()
get configured and initialized tools
virtual void setPlaybackMode(PlaybackTimePtr controller)
virtual std::vector< TrackingSystemServicePtr > getTrackingSystems()
virtual Tool::State getState() const
boost::shared_ptr< class Tool > ToolPtr
boost::shared_ptr< class TrackingSystemService > TrackingSystemServicePtr