CustusX  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRecordTrackingWidget.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 #include "cxRecordTrackingWidget.h"
33 
34 #include "cxRecordSessionWidget.h"
35 #include "cxRecordSession.h"
36 #include "cxToolRep3D.h"
37 #include "cxToolTracer.h"
38 #include "cxLogger.h"
39 #include "cxPatientModelService.h"
40 #include "cxViewService.h"
41 #include "cxStringProperty.h"
43 #include "cxTrackingService.h"
44 #include "cxProfile.h"
45 #include "cxHelperWidgets.h"
46 #include "cxRepContainer.h"
49 #include "cxAcquisitionService.h"
51 #include "cxBoolProperty.h"
52 
53 
54 namespace cx
55 {
56 
59  VisServicesPtr services,
60  QString category,
61  QWidget* parent) :
62  QWidget(parent),
63  mServices(services),
64  mOptions(options),
65  mAcquisitionService(acquisitionService)
66 {
67  QVBoxLayout* mVerticalLayout = new QVBoxLayout(this);
68 
69  mToolSelector = StringPropertySelectTool::New(services->tracking());
70 
71  mSelectRecordSession.reset(new SelectRecordSession(mOptions, acquisitionService, services));
72  connect(mSelectRecordSession->getSessionSelector().get(), &StringProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
73 
74  mMergeWithExistingSession = BoolProperty::initialize("mergerecording", "Merge",
75  "Merge new recording with selected recorded session",
76  false, QDomNode());
77  connect(mMergeWithExistingSession.get(), &BoolProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
78 
80  mRecordSessionWidget = new RecordSessionWidget(mAcquisitionService, this, context, category);
81 
82  mVerticalLayout->setMargin(0);
83 
84  mToolSelectorWidget = sscCreateDataWidget(this, mToolSelector);
85  mVerticalLayout->addWidget(mToolSelectorWidget);
86  mVerticalLayout->addWidget(mRecordSessionWidget);
87  mVerticalLayout->addWidget(sscCreateDataWidget(this, mMergeWithExistingSession));
88  mVerticalLayout->addWidget(new LabeledComboBoxWidget(this, mSelectRecordSession->getSessionSelector()));
89 
90  mObscuredListener.reset(new WidgetObscuredListener(this));
91  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
92 }
93 
95 {
96  mToolSelectorWidget->setVisible(on);
97 }
98 
100 {
101  return mSelectRecordSession->getSessionSelector();
102 }
103 
104 void RecordTrackingWidget::acquisitionStarted()
105 {
106  mRecordingTool = this->getSuitableRecordingTool();
107 
108  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
109  if (activeRep3D)
110  {
111  if (!mMergeWithExistingSession->getValue())
112  activeRep3D->getTracer()->clear();
113  activeRep3D->getTracer()->setColor(QColor("magenta"));
114  activeRep3D->getTracer()->start();
115  }
116 }
117 
118 void RecordTrackingWidget::acquisitionStopped()
119 {
120  QString newUid = mAcquisitionService->getLatestSession()->getUid();
121  mSelectRecordSession->getSessionSelector()->setValue(newUid);
122 
123  mServices->patient()->autoSave();
124 
125  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
126  if (activeRep3D)
127  {
128  activeRep3D->getTracer()->stop();
129  }
130  mRecordingTool.reset();
131 
132  emit acquisitionCompleted();
133 }
134 
135 void RecordTrackingWidget::acquisitionCancelled()
136 {
137  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
138  if (activeRep3D)
139  {
140  activeRep3D->getTracer()->stop();
141  activeRep3D->getTracer()->clear();
142  }
143  mRecordingTool.reset();
144 }
145 
146 void RecordTrackingWidget::onMergeChanged()
147 {
148  QString mergeSession = "";
149  if (mMergeWithExistingSession->getValue())
150  mergeSession = mSelectRecordSession->getSessionSelector()->getValue();
151 
152  mRecordSessionWidget->setCurrentSession(mergeSession);
153 }
154 
155 ToolRep3DPtr RecordTrackingWidget::getToolRepIn3DView()
156 {
157  return mServices->view()->get3DReps(0, 0)->findFirst<ToolRep3D>(mRecordingTool);
158 }
159 
160 void RecordTrackingWidget::obscuredSlot(bool obscured)
161 {
162  if (obscured)
163  mAcquisitionService->cancelRecord();
164 
165  if (!obscured)
166  {
167  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
168  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped, Qt::QueuedConnection);
169  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
170  connect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
171  connect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
172  }
173  else
174  {
175  disconnect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
176  disconnect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped);
177  disconnect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
178  disconnect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
179  disconnect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
180  }
181 
182  mSelectRecordSession->setVisible(!obscured);
183 }
184 
185 void RecordTrackingWidget::onToolChanged()
186 {
187  mSelectRecordSession->setTool(mToolSelector->getTool());
188 }
189 
190 
192 {
193  ToolPtr retval = mToolSelector->getTool();
194  if(!retval)
195  retval = mServices->tracking()->getActiveTool();
196  return retval;
197 }
198 
200 {
201  return mSelectRecordSession->getRecordedTrackerData_prMt();
202 }
203 
204 } //namespace cx
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
TimedTransformMap getRecordedTrackerData_prMt()
StringPropertyPtr getSessionSelector()
Composite widget for string selection.
void activeToolChanged(const QString &uId)
boost::shared_ptr< class StringProperty > StringPropertyPtr
cxLogicManager_EXPORT AcquisitionServicePtr acquisitionService()
void changed()
emit when the underlying data value is changed: The user interface will be updated.
RecordTrackingWidget(XmlOptionFile options, AcquisitionServicePtr acquisitionService, VisServicesPtr services, QString category, QWidget *parent)
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void setCurrentSession(QString uid)
set a session that the next recording adds to
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
void acquisitionCompleted()
aquisition complete, and widget internal state is updated accordingly
Helper class for xml files used to store ssc/cx data.
std::map< double, Transform3D > TimedTransformMap
boost::shared_ptr< class Tool > ToolPtr