Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 "cxUSAcqusitionWidget.h"
34 
35 #include <QtWidgets>
36 
37 #include <QVBoxLayout>
38 #include "boost/bind.hpp"
39 #include "cxTrackingService.h"
41 #include "cxDoubleWidgets.h"
42 #include "cxTypeConversions.h"
44 #include "cxRecordSessionWidget.h"
45 #include "cxSettings.h"
47 #include "cxDisplayTimerWidget.h"
48 #include "cxTimedAlgorithm.h"
50 #include "cxStringProperty.h"
52 #include "cxHelperWidgets.h"
53 #include "cxVisServices.h"
54 #include "cxLogger.h"
55 
56 #include "cxToolProperty.h"
58 #include "cxProbeConfigWidget.h"
59 
60 
61 namespace cx
62 {
63 
65  BaseWidget(parent, "org_custusx_acquisition_widgets_acquisition", "US Acquisition"),
66  mUsReconstructionService(usReconstructionService),
67  mAcquisitionService(acquisitionService),
68  mLayout(new QVBoxLayout(this))
69 {
70  this->setToolTip("Record and reconstruct US data");
71 
72  QString desc = settings()->value("Ultrasound/acquisitionName").toString();
74  mRecordSessionWidget = new RecordSessionWidget(mAcquisitionService, this, context, desc);
75  mLayout->addWidget(mRecordSessionWidget);
76 
77  mServices = services;
78  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructAboutToStart, this, &USAcqusitionWidget::reconstructAboutToStartSlot);
79  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructStarted, this, &USAcqusitionWidget::reconstructStartedSlot);
80  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructFinished, this, &USAcqusitionWidget::reconstructFinishedSlot);
81 
82  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &USAcqusitionWidget::acquisitionStateChangedSlot);
83  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &USAcqusitionWidget::recordStarted);
84  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &USAcqusitionWidget::recordStopped, Qt::DirectConnection);
85  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &USAcqusitionWidget::recordCancelled);
86 
87  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionDataReady, this, &USAcqusitionWidget::acquisitionDataReadySlot);
88  connect(mAcquisitionService.get(), &AcquisitionService::saveDataCompleted, mUsReconstructionService.get(), &UsReconstructionService::newDataOnDisk);
89 
90  QHBoxLayout* timerLayout = new QHBoxLayout;
91  mLayout->addLayout(timerLayout);
92  mDisplayTimerWidget = new DisplayTimerWidget(this);
93  mDisplayTimerWidget ->setFontSize(10);
94  timerLayout->addStretch();
95  timerLayout->addWidget(mDisplayTimerWidget);
96  timerLayout->addStretch();
97 
98  QGridLayout* editsLayout = new QGridLayout;
99  editsLayout->setColumnStretch(0,0);
100  editsLayout->setColumnStretch(1,1);
101  mLayout->addLayout(editsLayout);
102 
103  new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->tracking()), editsLayout, 0);
104  sscCreateDataWidget(this, mUsReconstructionService->getParam("Preset"), editsLayout, 1);
105 
106  QAction* optionsAction = this->createAction(this,
107  QIcon(":/icons/open_icon_library/system-run-5.png"),
108  "Details", "Toggle Details",
109  SLOT(toggleDetailsSlot()),
110  NULL);
111 
112  QToolButton* optionsButton = new QToolButton();
113  optionsButton->setDefaultAction(optionsAction);
114  editsLayout->addWidget(optionsButton, 0, 2);
115 
116  mOptionsWidget = this->createOptionsWidget();
117  mOptionsWidget->setVisible(settings()->value("acquisition/UsAcqShowDetails").toBool());
118 
119  mTimedAlgorithmProgressBar = new cx::TimedAlgorithmProgressBar;
120  mLayout->addWidget(mOptionsWidget);
121 
122  mLayout->addStretch();
123  mLayout->addWidget(mTimedAlgorithmProgressBar);
124 }
125 
127 {
128 }
129 
130 void USAcqusitionWidget::toggleDetailsSlot()
131 {
132  mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
133  settings()->setValue("acquisition/UsAcqShowDetails", mOptionsWidget->isVisible());
134 }
135 
136 QWidget* USAcqusitionWidget::createOptionsWidget()
137 {
138  QWidget* retval = new QWidget(this);
139  QGridLayout* layout = new QGridLayout(retval);
140  layout->setMargin(0);
141 
142  SoundSpeedConverterWidget* soundSpeedWidget = new SoundSpeedConverterWidget(mServices->tracking(), this);
143 
144  ProbeConfigWidget* probeWidget = new ProbeConfigWidget(mServices, this);
145  probeWidget->getActiveProbeConfigWidget()->setVisible(false);
146 
147  SpinBoxGroupWidget* temporalCalibrationWidget = new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->tracking()));
148 
149  int line = 0;
150  layout->addWidget(this->createHorizontalLine(), line++, 0, 1, 1);
151  layout->addWidget(this->wrapGroupBox(probeWidget, "Probe", "Probe Definition"), line++, 0);
152  layout->addWidget(this->wrapGroupBox(soundSpeedWidget, "Sound Speed", "Sound Speed"), line++, 0);
153  layout->addWidget(temporalCalibrationWidget, line++, 0);
154 
155  return retval;
156 }
157 
158 QWidget* USAcqusitionWidget::wrapGroupBox(QWidget* input, QString name, QString tip)
159 {
160  QGroupBox* retval = new QGroupBox(name);
161  retval->setToolTip(tip);
162  QVBoxLayout* layout = new QVBoxLayout(retval);
163  layout->addWidget(input);
164  layout->addStretch();
165  layout->setMargin(layout->margin()/2);
166  return retval;
167 }
168 
169 QWidget* USAcqusitionWidget::wrapVerticalStretch(QWidget* input)
170 {
171  QWidget* retval = new QWidget(this);
172  QVBoxLayout* layout = new QVBoxLayout(retval);
173  layout->addWidget(input);
174  layout->addStretch();
175  layout->setMargin(0);
176  layout->setSpacing(0);
177  return retval;
178 }
179 
180 void USAcqusitionWidget::acquisitionDataReadySlot()
181 {
182  if (settings()->value("Automation/autoReconstruct").toBool())
183  {
184  mUsReconstructionService->startReconstruction();
185  }
186 }
187 
188 void USAcqusitionWidget::acquisitionStateChangedSlot()
189 {
190  AcquisitionService::STATE state = mAcquisitionService->getState();
191 
192  switch (state)
193  {
195  break;
197  break;
199  break;
200  }
201 }
202 
203 void USAcqusitionWidget::recordStarted()
204 {
205  mDisplayTimerWidget->start();
206 }
207 void USAcqusitionWidget::recordStopped()
208 {
209  mDisplayTimerWidget->stop();
210 }
211 void USAcqusitionWidget::recordCancelled()
212 {
213  mDisplayTimerWidget->stop();
214 }
215 
216 void USAcqusitionWidget::reconstructAboutToStartSlot()
217 {
218  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
219  mTimedAlgorithmProgressBar->attach(threads);
220 }
221 
222 void USAcqusitionWidget::reconstructStartedSlot()
223 {
224  mAcquisitionService->startPostProcessing();
225 }
226 
227 void USAcqusitionWidget::reconstructFinishedSlot()
228 {
229  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
230  mTimedAlgorithmProgressBar->detach(threads);
231  mAcquisitionService->stopPostProcessing();
232 }
233 
234 }//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:62
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:87
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:149
void detach(TimedAlgorithmPtr algorithm)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void attach(TimedAlgorithmPtr algorithm)
cxLogicManager_EXPORT AcquisitionServicePtr acquisitionService()
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
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.