Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
42 namespace cx
43 {
44 
46 {
47  mTrackingService = trackingService;
48  mDataManager = dataManager;
49 }
50 
52 {
53 }
54 
56 {
57  this->doDisconnect();
58  mSpace = space;
59  this->doConnect();
60  emit changed();
61 }
62 
63 void SpaceListenerImpl::reconnect()
64 {
65  this->doDisconnect();
66  this->doConnect();
67  emit changed();
68 }
69 
71 {
72  return mSpace;
73 }
74 
75 void SpaceListenerImpl::doConnect()
76 {
77  if (mSpace.mId == csDATA)
78  {
79  ActiveDataPtr activeData = mDataManager->getActiveData();
80  if (mSpace.mRefObject == "active")
81  connect(activeData.get(), &ActiveData::activeDataChanged, this, &SpaceListenerImpl::reconnect);
82 
83  DataPtr data = mDataManager->getData(mSpace.mRefObject);
84  // NOTE: metrics have no own space, and thus are ignored if connected to.
85  // this breaks a loop if e.g. a dist depends on a pt and the dist becomes active.
86  if (data && !data->getSpace().isEmpty())
87  {
88  connect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
89  connect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
90  }
91  }
92 
93  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
94  {
95  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
96  if (tool)
97  {
98  connect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
99  connect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
100 
101  if (mSpace.mRefObject == "active")
102  {
103 // connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
104  connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(reconnect()));
105  }
106  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
107  }
108  }
109 
110  if (mSpace.mId == csPATIENTREF)
111  {
112  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
113  }
114 }
115 
116 void SpaceListenerImpl::doDisconnect()
117 {
118  if (mSpace.mId == csDATA)
119  {
120  ActiveDataPtr activeData = mDataManager->getActiveData();
121  if (mSpace.mRefObject == "active")
122  disconnect(activeData.get(), &ActiveData::activeDataChanged, this, &SpaceListenerImpl::reconnect);
123 
124  DataPtr data = mDataManager->getData(mSpace.mRefObject);
125  if (data)
126  {
127  disconnect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
128  disconnect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
129  }
130  }
131 
132  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
133  {
134  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
135  if (tool)
136  {
137  disconnect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
138  disconnect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
139 
140  if (mSpace.mRefObject == "active")
141  {
142  disconnect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
143  disconnect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(reconnect()));
144  }
145  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
146  }
147  }
148 
149  if (mSpace.mId == csPATIENTREF)
150  {
151  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
152  }
153 }
154 
155 } // 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
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
cxLogicManager_EXPORT TrackingServicePtr trackingService()
csTOOL
a tools rspace (t)
CoordinateSystem getSpace() const
boost::shared_ptr< class Tool > ToolPtr