Fraxinus  18.10
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  mVerticalLayout->addWidget(mToolSelectorWidget);
65  mVerticalLayout->addWidget(mRecordSessionWidget);
66  mVerticalLayout->addWidget(sscCreateDataWidget(this, mMergeWithExistingSession));
67  mVerticalLayout->addWidget(new LabeledComboBoxWidget(this, mSelectRecordSession->getSessionSelector()));
68 
69  mObscuredListener.reset(new WidgetObscuredListener(this));
70  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
71 }
72 
74 {
75  mToolSelectorWidget->setVisible(on);
76 }
77 
79 {
80  return mSelectRecordSession->getSessionSelector();
81 }
82 
83 void RecordTrackingWidget::acquisitionStarted()
84 {
85  mRecordingTool = this->getSuitableRecordingTool();
86 
87  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
88  if (activeRep3D)
89  {
90  if (!mMergeWithExistingSession->getValue())
91  activeRep3D->getTracer()->clear();
92  activeRep3D->getTracer()->setColor(QColor("magenta"));
93  activeRep3D->getTracer()->start();
94  }
95 }
96 
97 void RecordTrackingWidget::acquisitionStopped()
98 {
99  QString newUid = mAcquisitionService->getLatestSession()->getUid();
100  mSelectRecordSession->getSessionSelector()->setValue(newUid);
101 
102  mServices->patient()->autoSave();
103 
104  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
105  if (activeRep3D)
106  {
107  activeRep3D->getTracer()->stop();
108  }
109  mRecordingTool.reset();
110 
111  emit acquisitionCompleted();
112 }
113 
114 void RecordTrackingWidget::acquisitionCancelled()
115 {
116  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
117  if (activeRep3D)
118  {
119  activeRep3D->getTracer()->stop();
120  activeRep3D->getTracer()->clear();
121  }
122  mRecordingTool.reset();
123 }
124 
125 void RecordTrackingWidget::onMergeChanged()
126 {
127  QString mergeSession = "";
128  if (mMergeWithExistingSession->getValue())
129  mergeSession = mSelectRecordSession->getSessionSelector()->getValue();
130 
131  mRecordSessionWidget->setCurrentSession(mergeSession);
132 }
133 
134 ToolRep3DPtr RecordTrackingWidget::getToolRepIn3DView()
135 {
136  return mServices->view()->get3DReps(0, 0)->findFirst<ToolRep3D>(mRecordingTool);
137 }
138 
139 void RecordTrackingWidget::obscuredSlot(bool obscured)
140 {
141  if (obscured)
142  mAcquisitionService->cancelRecord();
143 
144  if (!obscured)
145  {
146  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
147  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped, Qt::QueuedConnection);
148  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
149  connect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
150  connect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
151  }
152  else
153  {
154  disconnect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
155  disconnect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped);
156  disconnect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
157  disconnect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
158  disconnect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
159  }
160 
161  mSelectRecordSession->setVisible(!obscured);
162 }
163 
164 void RecordTrackingWidget::onToolChanged()
165 {
166  mSelectRecordSession->setTool(mToolSelector->getTool());
167 }
168 
169 
171 {
172  ToolPtr retval = mToolSelector->getTool();
173  if(!retval)
174  retval = mServices->tracking()->getActiveTool();
175  return retval;
176 }
177 
179 {
180  return mSelectRecordSession->getRecordedTrackerData_prMt();
181 }
182 
183 } //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