Fraxinus  2023.01.05-dev+develop.0da12
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  mTrackingService->clearActiveTool();
99 }
100 
102 {
103  return mTrackingService->getFirstProbe();
104 }
105 
107 {
108  return mTrackingService->getReferenceTool();
109 }
110 
112 {
113  return mTrackingService->getManualTool();
114 }
115 
117 {
118  return mTrackingService->getTools();
119 }
120 
122 {
123  return mTrackingService->isPlaybackMode();
124 }
125 
127 {
128  mTrackingService->setPlaybackMode(controller);
129 }
130 
132 {
133  return mTrackingService->getSessionHistory(startTime, stopTime);
134 }
135 
137 {
138  mTrackingService->runDummyTool(tool);
139 }
140 
141 std::vector<TrackerConfigurationPtr> TrackingServiceProxy::getConfigurations()
142 {
143  return mTrackingService->getConfigurations();
144 }
145 
146 /*TrackerConfigurationPtr TrackingServiceProxy::getConfiguration(QString trackingSystemImplementation)
147 {
148  return mTrackingService->getConfiguration(trackingSystemImplementation);
149 }*/
150 
152 {
153  return mTrackingService->getConfiguration();
154 }
155 
156 void TrackingServiceProxy::setCurrentTrackingSystemImplementation(QString trackingSystemImplementation)
157 {
158  mTrackingService->setCurrentTrackingSystemImplementation(trackingSystemImplementation);
159 }
160 
162 {
163  return mTrackingService->getCurrentTrackingSystemImplementation();
164 }
165 
167 {
168  mTrackingService->installTrackingSystem(system);
169 }
170 
172 {
173  mTrackingService->unInstallTrackingSystem(system);
174 }
175 
176 std::vector<TrackingSystemServicePtr> TrackingServiceProxy::getTrackingSystems()
177 {
178  return mTrackingService->getTrackingSystems();
179 }
180 
182 {
183  return mTrackingService->resetTimeSynchronization();
184 }
185 
186 } //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 setCurrentTrackingSystemImplementation(QString trackingSystemImplementation)
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 std::vector< TrackerConfigurationPtr > getConfigurations()
virtual QString getCurrentTrackingSystemImplementation()
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 void clearActiveTool()
Deselect active tool.
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 resetTimeSynchronization()
Reset time synchronization. Used for resetting time synchronization of incoming timestamps in OpenIGT...
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