CustusX  22.04-rc5
An IGT application
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) 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 #include "cxRecordTrackingWidget.h"
12 
13 #include "cxRecordSessionWidget.h"
14 #include "cxRecordSession.h"
15 #include "cxToolRep3D.h"
16 #include "cxToolTracer.h"
17 #include "cxLogger.h"
18 #include "cxPatientModelService.h"
19 #include "cxViewService.h"
20 #include "cxStringProperty.h"
22 #include "cxTrackingService.h"
23 #include "cxProfile.h"
24 #include "cxHelperWidgets.h"
25 #include "cxRepContainer.h"
28 #include "cxAcquisitionService.h"
30 #include "cxBoolProperty.h"
31 
32 
33 namespace cx
34 {
35 
37  AcquisitionServicePtr acquisitionService,
38  VisServicesPtr services,
39  QString category,
40  QWidget* parent) :
41  QWidget(parent),
42  mServices(services),
43  mOptions(options),
44  mAcquisitionService(acquisitionService)
45 {
46  QVBoxLayout* mVerticalLayout = new QVBoxLayout(this);
47 
48  mToolSelector = StringPropertySelectTool::New(services->tracking());
49 
50  mSelectRecordSession.reset(new SelectRecordSession(mOptions, acquisitionService, services));
51  connect(mSelectRecordSession->getSessionSelector().get(), &StringProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
52 
53  mMergeWithExistingSession = BoolProperty::initialize("mergerecording", "Merge",
54  "Merge new recording with selected recorded session",
55  false, QDomNode());
56  connect(mMergeWithExistingSession.get(), &BoolProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
57 
59  mRecordSessionWidget = new RecordSessionWidget(mAcquisitionService, this, context, category);
60 
61  mVerticalLayout->setMargin(0);
62 
63  mToolSelectorWidget = sscCreateDataWidget(this, mToolSelector);
64  mMergeWithExistingSessionWidget = sscCreateDataWidget(this, mMergeWithExistingSession);
65  mVerticalLayout->addWidget(mToolSelectorWidget);
66  mVerticalLayout->addWidget(mRecordSessionWidget);
67  mVerticalLayout->addWidget(mMergeWithExistingSessionWidget);
68  mVerticalLayout->addWidget(new LabeledComboBoxWidget(this, mSelectRecordSession->getSessionSelector()));
69 
70  mObscuredListener.reset(new WidgetObscuredListener(this));
71  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
72 }
73 
75 {
76  mToolSelectorWidget->setVisible(on);
77 }
78 
80 {
81  return mSelectRecordSession->getSessionSelector();
82 }
83 
84 void RecordTrackingWidget::acquisitionStarted()
85 {
86  mRecordingTool = this->getSuitableRecordingTool();
87 
88  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
89  if (activeRep3D)
90  {
91  if (!mMergeWithExistingSession->getValue())
92  activeRep3D->getTracer()->clear();
93  activeRep3D->getTracer()->setColor(QColor("magenta"));
94  activeRep3D->getTracer()->start();
95  }
96 }
97 
98 void RecordTrackingWidget::acquisitionStopped()
99 {
100  QString newUid = mAcquisitionService->getLatestSession()->getUid();
101  mSelectRecordSession->getSessionSelector()->setValue(newUid);
102 
103  mServices->patient()->autoSave();
104 
105  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
106  if (activeRep3D)
107  {
108  activeRep3D->getTracer()->stop();
109  }
110  mRecordingTool.reset();
111 
112  emit acquisitionCompleted();
113 }
114 
115 void RecordTrackingWidget::acquisitionCancelled()
116 {
117  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
118  if (activeRep3D)
119  {
120  activeRep3D->getTracer()->stop();
121  activeRep3D->getTracer()->clear();
122  }
123  mRecordingTool.reset();
124 }
125 
126 void RecordTrackingWidget::onMergeChanged()
127 {
128  QString mergeSession = "";
129  if (mMergeWithExistingSession->getValue())
130  mergeSession = mSelectRecordSession->getSessionSelector()->getValue();
131 
132  mRecordSessionWidget->setCurrentSession(mergeSession);
133 }
134 
135 ToolRep3DPtr RecordTrackingWidget::getToolRepIn3DView()
136 {
137  return mServices->view()->get3DReps(0, 0)->findFirst<ToolRep3D>(mRecordingTool);
138 }
139 
140 void RecordTrackingWidget::obscuredSlot(bool obscured)
141 {
142  if (obscured)
143  mAcquisitionService->cancelRecord();
144 
145  if (!obscured)
146  {
147  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
148  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped, Qt::QueuedConnection);
149  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
150  connect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
151  connect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
152  }
153  else
154  {
155  disconnect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
156  disconnect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped);
157  disconnect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
158  disconnect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
159  disconnect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
160  }
161 
162  mSelectRecordSession->setVisible(!obscured);
163 }
164 
165 void RecordTrackingWidget::onToolChanged()
166 {
167  mSelectRecordSession->setTool(mToolSelector->getTool());
168 }
169 
170 
172 {
173  ToolPtr retval = mToolSelector->getTool();
174  if(!retval)
175  retval = mServices->tracking()->getActiveTool();
176  return retval;
177 }
178 
180 {
181  return mSelectRecordSession->getRecordedTrackerData_prMt();
182 }
183 
185 {
186  if(!mMergeWithExistingSessionWidget->isHidden())
187  mMergeWithExistingSessionWidget->hide();
188 }
189 
190 } //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:40
TimedTransformMap getRecordedTrackerData_prMt()
StringPropertyPtr getSessionSelector()
Composite widget for string selection.
Display a Tool in 3D.
Definition: cxToolRep3D.h:51
void activeToolChanged(const QString &uId)
boost::shared_ptr< class StringProperty > StringPropertyPtr
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
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr