Fraxinus  18.10
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxTrackingServiceProxy.h"
13 
14 #include <boost/bind.hpp>
15 #include <ctkPluginContext.h>
16 #include "cxNullDeleter.h"
17 
18 
19 namespace cx
20 {
21 
22 TrackingServicePtr TrackingServiceProxy::create(ctkPluginContext *pluginContext)
23 {
24  return TrackingServicePtr(new TrackingServiceProxy(pluginContext));
25 }
26 
27 TrackingServiceProxy::TrackingServiceProxy(ctkPluginContext *pluginContext) :
28  mPluginContext(pluginContext),
29  mTrackingService(TrackingService::getNullObject())
30 {
31  this->initServiceListener();
32 }
33 
34 void TrackingServiceProxy::initServiceListener()
35 {
36  mServiceListener.reset(new ServiceTrackerListener<TrackingService>(
37  mPluginContext,
38  boost::bind(&TrackingServiceProxy::onServiceAdded, this, _1),
39  boost::function<void (TrackingService*)>(),
40  boost::bind(&TrackingServiceProxy::onServiceRemoved, this, _1)
41  ));
42  mServiceListener->open();
43 }
44 void TrackingServiceProxy::onServiceAdded(TrackingService* service)
45 {
46  mTrackingService.reset(service, null_deleter());
47 
48  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
49  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
50 
51  emit stateChanged();
52  emit activeToolChanged(mTrackingService->getActiveTool()->getUid());
53 }
54 
55 void TrackingServiceProxy::onServiceRemoved(TrackingService *service)
56 {
57  disconnect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
58  disconnect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
59 
60  mTrackingService = TrackingService::getNullObject();
61 
62  emit stateChanged();
63  emit activeToolChanged("");
64 }
65 
67 {
68  return mTrackingService->isNull();
69 }
70 
72 {
73  return mTrackingService->getState();
74 }
75 
77 {
78  mTrackingService->setState(val);
79 }
80 
82 {
83  return mTrackingService->getTool(uid);
84 }
85 
87 {
88  return mTrackingService->getActiveTool();
89 }
90 
91 void TrackingServiceProxy::setActiveTool(const QString& uid)
92 {
93  mTrackingService->setActiveTool(uid);
94 }
95 
97 {
98  return mTrackingService->getFirstProbe();
99 }
100 
102 {
103  return mTrackingService->getReferenceTool();
104 }
105 
107 {
108  return mTrackingService->getManualTool();
109 }
110 
112 {
113  return mTrackingService->getTools();
114 }
115 
117 {
118  return mTrackingService->isPlaybackMode();
119 }
120 
122 {
123  mTrackingService->setPlaybackMode(controller);
124 }
125 
127 {
128  return mTrackingService->getSessionHistory(startTime, stopTime);
129 }
130 
132 {
133  mTrackingService->runDummyTool(tool);
134 }
135 
137 {
138  return mTrackingService->getConfiguration();
139 }
140 
141 
143 {
144  mTrackingService->installTrackingSystem(system);
145 }
146 
148 {
149  mTrackingService->unInstallTrackingSystem(system);
150 }
151 
152 std::vector<TrackingSystemServicePtr> TrackingServiceProxy::getTrackingSystems()
153 {
154  return mTrackingService->getTrackingSystems();
155 }
156 
157 
158 
159 } //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
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
boost::shared_ptr< class TrackingSystemService > TrackingSystemServicePtr