Fraxinus  18.10
An IGT application
cxUSAcqusitionWidget.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 
12 #include "cxUSAcqusitionWidget.h"
13 
14 #include <QtWidgets>
15 
16 #include <QVBoxLayout>
17 #include "boost/bind.hpp"
18 #include "cxTrackingService.h"
20 #include "cxDoubleWidgets.h"
21 #include "cxTypeConversions.h"
23 #include "cxRecordSessionWidget.h"
24 #include "cxSettings.h"
26 #include "cxDisplayTimerWidget.h"
27 #include "cxTimedAlgorithm.h"
29 #include "cxStringProperty.h"
31 #include "cxHelperWidgets.h"
32 #include "cxVisServices.h"
33 #include "cxLogger.h"
34 
35 #include "cxToolProperty.h"
37 #include "cxProbeConfigWidget.h"
38 
39 
40 namespace cx
41 {
42 
43 USAcqusitionWidget::USAcqusitionWidget(AcquisitionServicePtr acquisitionService, VisServicesPtr services, UsReconstructionServicePtr usReconstructionService, QWidget* parent) :
44  BaseWidget(parent, "org_custusx_acquisition_widgets_acquisition", "US Acquisition"),
45  mUsReconstructionService(usReconstructionService),
46  mAcquisitionService(acquisitionService),
47  mLayout(new QVBoxLayout(this))
48 {
49  this->setToolTip("Record and reconstruct US data");
50 
51  QString desc = settings()->value("Ultrasound/acquisitionName").toString();
53  mRecordSessionWidget = new RecordSessionWidget(mAcquisitionService, this, context, desc);
54  mLayout->addWidget(mRecordSessionWidget);
55 
56  mServices = services;
57  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructAboutToStart, this, &USAcqusitionWidget::reconstructAboutToStartSlot);
58  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructStarted, this, &USAcqusitionWidget::reconstructStartedSlot);
59  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructFinished, this, &USAcqusitionWidget::reconstructFinishedSlot);
60 
61  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &USAcqusitionWidget::acquisitionStateChangedSlot);
62  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &USAcqusitionWidget::recordStarted);
63  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &USAcqusitionWidget::recordStopped, Qt::DirectConnection);
64  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &USAcqusitionWidget::recordCancelled);
65 
66  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionDataReady, this, &USAcqusitionWidget::acquisitionDataReadySlot);
67  connect(mAcquisitionService.get(), &AcquisitionService::saveDataCompleted, mUsReconstructionService.get(), &UsReconstructionService::newDataOnDisk);
68 
69  QHBoxLayout* timerLayout = new QHBoxLayout;
70  mLayout->addLayout(timerLayout);
71  mDisplayTimerWidget = new DisplayTimerWidget(this);
72  mDisplayTimerWidget ->setFontSize(10);
73  timerLayout->addStretch();
74  timerLayout->addWidget(mDisplayTimerWidget);
75  timerLayout->addStretch();
76 
77  QGridLayout* editsLayout = new QGridLayout;
78  editsLayout->setColumnStretch(0,0);
79  editsLayout->setColumnStretch(1,1);
80  mLayout->addLayout(editsLayout);
81 
82  new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->tracking()), editsLayout, 0);
83  sscCreateDataWidget(this, mUsReconstructionService->getParam("Preset"), editsLayout, 1);
84 
85  QAction* optionsAction = this->createAction(this,
86  QIcon(":/icons/open_icon_library/system-run-5.png"),
87  "Details", "Toggle Details",
88  SLOT(toggleDetailsSlot()),
89  NULL);
90 
91  QToolButton* optionsButton = new QToolButton();
92  optionsButton->setDefaultAction(optionsAction);
93  editsLayout->addWidget(optionsButton, 0, 2);
94 
95  mOptionsWidget = this->createOptionsWidget();
96  mOptionsWidget->setVisible(settings()->value("acquisition/UsAcqShowDetails").toBool());
97 
98  mTimedAlgorithmProgressBar = new cx::TimedAlgorithmProgressBar;
99  mLayout->addWidget(mOptionsWidget);
100 
101  mLayout->addStretch();
102  mLayout->addWidget(mTimedAlgorithmProgressBar);
103 }
104 
106 {
107 }
108 
109 void USAcqusitionWidget::toggleDetailsSlot()
110 {
111  mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
112  settings()->setValue("acquisition/UsAcqShowDetails", mOptionsWidget->isVisible());
113 }
114 
115 QWidget* USAcqusitionWidget::createOptionsWidget()
116 {
117  QWidget* retval = new QWidget(this);
118  QGridLayout* layout = new QGridLayout(retval);
119  layout->setMargin(0);
120 
121  SoundSpeedConverterWidget* soundSpeedWidget = new SoundSpeedConverterWidget(mServices->tracking(), this);
122 
123  ProbeConfigWidget* probeWidget = new ProbeConfigWidget(mServices, this);
124  probeWidget->getActiveProbeConfigWidget()->setVisible(false);
125 
126  SpinBoxGroupWidget* temporalCalibrationWidget = new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->tracking()));
127 
128  int line = 0;
129  layout->addWidget(this->createHorizontalLine(), line++, 0, 1, 1);
130  layout->addWidget(this->wrapGroupBox(probeWidget, "Probe", "Probe Definition"), line++, 0);
131  layout->addWidget(this->wrapGroupBox(soundSpeedWidget, "Sound Speed", "Sound Speed"), line++, 0);
132  layout->addWidget(temporalCalibrationWidget, line++, 0);
133 
134  return retval;
135 }
136 
137 QWidget* USAcqusitionWidget::wrapGroupBox(QWidget* input, QString name, QString tip)
138 {
139  QGroupBox* retval = new QGroupBox(name);
140  retval->setToolTip(tip);
141  QVBoxLayout* layout = new QVBoxLayout(retval);
142  layout->addWidget(input);
143  layout->addStretch();
144  layout->setMargin(layout->margin()/2);
145  return retval;
146 }
147 
148 QWidget* USAcqusitionWidget::wrapVerticalStretch(QWidget* input)
149 {
150  QWidget* retval = new QWidget(this);
151  QVBoxLayout* layout = new QVBoxLayout(retval);
152  layout->addWidget(input);
153  layout->addStretch();
154  layout->setMargin(0);
155  layout->setSpacing(0);
156  return retval;
157 }
158 
159 void USAcqusitionWidget::acquisitionDataReadySlot()
160 {
161  if (settings()->value("Automation/autoReconstruct").toBool())
162  {
163  mUsReconstructionService->startReconstruction();
164  }
165 }
166 
167 void USAcqusitionWidget::acquisitionStateChangedSlot()
168 {
169  AcquisitionService::STATE state = mAcquisitionService->getState();
170 
171  switch (state)
172  {
174  break;
176  break;
178  break;
179  }
180 }
181 
182 void USAcqusitionWidget::recordStarted()
183 {
184  mDisplayTimerWidget->start();
185 }
186 void USAcqusitionWidget::recordStopped()
187 {
188  mDisplayTimerWidget->stop();
189 }
190 void USAcqusitionWidget::recordCancelled()
191 {
192  mDisplayTimerWidget->stop();
193 }
194 
195 void USAcqusitionWidget::reconstructAboutToStartSlot()
196 {
197  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
198  mTimedAlgorithmProgressBar->attach(threads);
199 }
200 
201 void USAcqusitionWidget::reconstructStartedSlot()
202 {
203  mAcquisitionService->startPostProcessing();
204 }
205 
206 void USAcqusitionWidget::reconstructFinishedSlot()
207 {
208  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
209  mTimedAlgorithmProgressBar->detach(threads);
210  mAcquisitionService->stopPostProcessing();
211 }
212 
213 }//namespace cx
boost::shared_ptr< class UsReconstructionService > UsReconstructionServicePtr
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
void setFontSize(int fontSize)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
void saveDataCompleted(QString mhdFilename)
emitted when data has been saved to file
static DoublePropertyBasePtr New(TrackingServicePtr trackingService)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
Widget that displays/edits a probe configuration.
static StringPropertyActiveProbeConfigurationPtr New(TrackingServicePtr trackingService)
Composite widget for string selection.
Show progress for a TimedBaseAlgorithm.
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:129
void detach(TimedAlgorithmPtr algorithm)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
void attach(TimedAlgorithmPtr algorithm)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
Composite widget for scalar data manipulation.
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
virtual void newDataOnDisk(QString mhdFilename)=0
void acquisitionDataReady()
emitted when data is acquired and sent to the reconstruction module
USAcqusitionWidget(AcquisitionServicePtr acquisitionService, VisServicesPtr services, UsReconstructionServicePtr usReconstructionService, QWidget *parent)
A second counter widget.
Namespace for all CustusX production code.