Fraxinus  17.12
An IGT application
cxSpaceListenerImpl.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 "cxSpaceListenerImpl.h"
34 
35 #include "cxPatientModelService.h"
36 #include "cxTrackingService.h"
37 #include "cxData.h"
38 #include "cxTool.h"
39 #include "cxActiveData.h"
40 #include "cxLogger.h"
41 #include "cxActiveToolProxy.h"
42 
43 namespace cx
44 {
45 
47 {
48  mTrackingService = trackingService;
49  mDataManager = dataManager;
50 }
51 
53 {
54 }
55 
57 {
58  this->doDisconnect();
59  mSpace = space;
60  this->doConnect();
61  emit changed();
62 }
63 
64 void SpaceListenerImpl::reconnect()
65 {
66  this->doDisconnect();
67  this->doConnect();
68  emit changed();
69 }
70 
72 {
73  return mSpace;
74 }
75 
76 void SpaceListenerImpl::doConnect()
77 {
78  if (mSpace.mId == csDATA)
79  {
80  ActiveDataPtr activeData = mDataManager->getActiveData();
81  if (mSpace.mRefObject == "active")
82  connect(activeData.get(), &ActiveData::activeDataChanged, this, &SpaceListenerImpl::reconnect);
83 
84  DataPtr data = mDataManager->getData(mSpace.mRefObject);
85  // NOTE: metrics have no own space, and thus are ignored if connected to.
86  // this breaks a loop if e.g. a dist depends on a pt and the dist becomes active.
87  if (data && !data->getSpace().isEmpty())
88  {
89  connect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
90  connect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
91  }
92  }
93 
94  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
95  {
96  if (mSpace.mRefObject == "active")
97  {
98  mActiveTool = ActiveToolProxy::New(mTrackingService);
99  connect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
100  connect(mActiveTool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
101  }
102  else
103  {
104  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
105  if (tool)
106  {
107  connect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
108  connect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
109  }
110  }
111  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
112  }
113 
114  if (mSpace.mId == csPATIENTREF)
115  {
116  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
117  }
118 }
119 
120 void SpaceListenerImpl::doDisconnect()
121 {
122  if (mSpace.mId == csDATA)
123  {
124  ActiveDataPtr activeData = mDataManager->getActiveData();
125  if (mSpace.mRefObject == "active")
126  disconnect(activeData.get(), &ActiveData::activeDataChanged, this, &SpaceListenerImpl::reconnect);
127 
128  DataPtr data = mDataManager->getData(mSpace.mRefObject);
129  if (data)
130  {
131  disconnect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
132  disconnect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
133  }
134  }
135 
136  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
137  {
138  if (mActiveTool)
139  {
140  disconnect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
141  disconnect(mActiveTool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
142  mActiveTool.reset();
143  }
144  else
145  {
146  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
147  if (tool)
148  {
149  disconnect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
150  disconnect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
151  }
152  }
153  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
154  }
155 
156  if (mSpace.mId == csPATIENTREF)
157  {
158  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
159  }
160 }
161 
162 } // namespace cx
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class TrackingService > TrackingServicePtr
csSENSOR
a tools sensor space (s)
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
csDATA
a datas space (d)
SpaceListenerImpl(TrackingServicePtr trackingService, PatientModelServicePtr dataManager)
COORDINATE_SYSTEM mId
the type of coordinate system
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
csPATIENTREF
the patient/tool reference space (pr)
boost::shared_ptr< class Data > DataPtr
void setSpace(CoordinateSystem space)
void activeDataChanged(const QString &uId)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Identification of a Coordinate system.
csTOOL_OFFSET
the tool space t with a virtual offset added along the z axis. (to)
QString mRefObject
for tool, sensor and data we need a object uid to define the coordinate system
csTOOL
a tools rspace (t)
CoordinateSystem getSpace() const
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr