CustusX  15.8
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 
40 namespace cx
41 {
42 
44 {
45  mTrackingService = trackingService;
46  mDataManager = dataManager;
47 }
48 
50 {
51 }
52 
54 {
55  this->doDisconnect();
56  mSpace = space;
57  this->doConnect();
58  emit changed();
59 }
60 
61 void SpaceListenerImpl::reconnect()
62 {
63  this->doDisconnect();
64  this->doConnect();
65  emit changed();
66 }
67 
69 {
70  return mSpace;
71 }
72 
73 void SpaceListenerImpl::doConnect()
74 {
75  if (mSpace.mId == csDATA)
76  {
77  if (mSpace.mRefObject == "active")
78  {
79  connect(mDataManager.get(), &PatientModelService::activeImageChanged, this, &SpaceListenerImpl::reconnect);
80  }
81 
82  DataPtr data = mDataManager->getData(mSpace.mRefObject);
83  if (data)
84  {
85  connect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
86  connect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
87  }
88  }
89 
90  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
91  {
92  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
93  if (tool)
94  {
95  connect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
96  connect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
97 
98  if (mSpace.mRefObject == "active")
99  {
100 // connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
101  connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(reconnect()));
102  }
103  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
104  }
105  }
106 
107  if (mSpace.mId == csPATIENTREF)
108  {
109  connect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
110  }
111 }
112 
113 void SpaceListenerImpl::doDisconnect()
114 {
115  if (mSpace.mId == csDATA)
116  {
117  DataPtr data = mDataManager->getData(mSpace.mRefObject);
118  if (data)
119  {
120  disconnect(data.get(), SIGNAL(transformChanged()), this, SIGNAL(changed()));
121  disconnect(mDataManager.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
122  }
123  }
124 
125  if (mSpace.mId == csSENSOR || mSpace.mId == csTOOL || mSpace.mId == csTOOL_OFFSET)
126  {
127  ToolPtr tool = mTrackingService->getTool(mSpace.mRefObject);
128  if (tool)
129  {
130  disconnect(tool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SIGNAL(changed()));
131  disconnect(tool.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(changed()));
132 
133  if (mSpace.mRefObject == "active")
134  {
135  disconnect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
136  disconnect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(reconnect()));
137  }
138  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
139  }
140  }
141 
142  if (mSpace.mId == csPATIENTREF)
143  {
144  disconnect(mDataManager.get(), SIGNAL(rMprChanged()), this, SIGNAL(changed()));
145  }
146 }
147 
148 } // namespace cx
void activeImageChanged(const QString &uId)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class TrackingService > TrackingServicePtr
csSENSOR
a tools sensor space (s)
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)
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