CustusX  15.8
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  RecordBaseWidget(acquisitionService, parent, settings()->value("Ultrasound/acquisitionName").toString()),
66  mUsReconstructionService(usReconstructionService)
67 {
68  this->setObjectName("org_custusx_acquisition_widgets_acquisition");
69  this->setWindowTitle("US Acquisition");
70  this->setToolTip("Record and reconstruct US data");
71 
72  mServices = services;
73  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructAboutToStart, this, &USAcqusitionWidget::reconstructAboutToStartSlot);
74  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructStarted, this, &USAcqusitionWidget::reconstructStartedSlot);
75  connect(mUsReconstructionService.get(), &UsReconstructionService::reconstructFinished, this, &USAcqusitionWidget::reconstructFinishedSlot);
76 
77  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &USAcqusitionWidget::acquisitionStateChangedSlot);
78  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &USAcqusitionWidget::recordStarted);
79  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &USAcqusitionWidget::recordStopped, Qt::DirectConnection);
80  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &USAcqusitionWidget::recordCancelled);
81 
82  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionDataReady, this, &USAcqusitionWidget::acquisitionDataReadySlot);
84 
86 
87  QHBoxLayout* timerLayout = new QHBoxLayout;
88  mLayout->addLayout(timerLayout);
89  mDisplayTimerWidget = new DisplayTimerWidget(this);
90  mDisplayTimerWidget ->setFontSize(10);
91  timerLayout->addStretch();
92  timerLayout->addWidget(mDisplayTimerWidget);
93  timerLayout->addStretch();
94 
95  QGridLayout* editsLayout = new QGridLayout;
96  editsLayout->setColumnStretch(0,0);
97  editsLayout->setColumnStretch(1,1);
98  RecordBaseWidget::mLayout->addLayout(editsLayout);
99 
100  new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->getToolManager()), editsLayout, 0);
101  sscCreateDataWidget(this, mUsReconstructionService->getParam("Preset"), editsLayout, 1);
102 
103  QAction* optionsAction = this->createAction(this,
104  QIcon(":/icons/open_icon_library/system-run-5.png"),
105  "Details", "Show Details",
106  SLOT(toggleDetailsSlot()),
107  NULL);
108 
109  QToolButton* optionsButton = new QToolButton();
110  optionsButton->setDefaultAction(optionsAction);
111  editsLayout->addWidget(optionsButton, 0, 2);
112 
113  mOptionsWidget = this->createOptionsWidget();
114  mOptionsWidget->setVisible(settings()->value("acquisition/UsAcqShowDetails").toBool());
115 
116  mTimedAlgorithmProgressBar = new cx::TimedAlgorithmProgressBar;
117  mLayout->addWidget(mOptionsWidget);
118 
119  mLayout->addStretch();
120  mLayout->addWidget(mTimedAlgorithmProgressBar);
121 }
122 
124 {
125 }
126 
127 void USAcqusitionWidget::toggleDetailsSlot()
128 {
129  mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
130  settings()->setValue("acquisition/UsAcqShowDetails", mOptionsWidget->isVisible());
131 }
132 
133 QWidget* USAcqusitionWidget::createOptionsWidget()
134 {
135  QWidget* retval = new QWidget(this);
136  QGridLayout* layout = new QGridLayout(retval);
137  layout->setMargin(0);
138 
139  SoundSpeedConverterWidget* soundSpeedWidget = new SoundSpeedConverterWidget(mServices->getToolManager(), this);
140 
141  ProbeConfigWidget* probeWidget = new ProbeConfigWidget(mServices, this);
142  probeWidget->getActiveProbeConfigWidget()->setVisible(false);
143 
144  SpinBoxGroupWidget* temporalCalibrationWidget = new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->getToolManager()));
145 
146  int line = 0;
147  layout->addWidget(this->createHorizontalLine(), line++, 0, 1, 1);
148  layout->addWidget(this->wrapGroupBox(probeWidget, "Probe", "Probe Definition"), line++, 0);
149  layout->addWidget(this->wrapGroupBox(soundSpeedWidget, "Sound Speed", "Sound Speed"), line++, 0);
150  layout->addWidget(temporalCalibrationWidget, line++, 0);
151 
152  return retval;
153 }
154 
155 QWidget* USAcqusitionWidget::wrapGroupBox(QWidget* input, QString name, QString tip)
156 {
157  QGroupBox* retval = new QGroupBox(name);
158  retval->setToolTip(tip);
159  QVBoxLayout* layout = new QVBoxLayout(retval);
160  layout->addWidget(input);
161  layout->addStretch();
162  layout->setMargin(layout->margin()/2);
163  return retval;
164 }
165 
166 QWidget* USAcqusitionWidget::wrapVerticalStretch(QWidget* input)
167 {
168  QWidget* retval = new QWidget(this);
169  QVBoxLayout* layout = new QVBoxLayout(retval);
170  layout->addWidget(input);
171  layout->addStretch();
172  layout->setMargin(0);
173  layout->setSpacing(0);
174  return retval;
175 }
176 
177 void USAcqusitionWidget::acquisitionDataReadySlot()
178 {
179  if (settings()->value("Automation/autoReconstruct").toBool())
180  {
181  mUsReconstructionService->startReconstruction();
182  }
183 }
184 
185 void USAcqusitionWidget::acquisitionStateChangedSlot()
186 {
188 
189  switch (state)
190  {
192  break;
194  break;
196  break;
197  }
198 }
199 
200 void USAcqusitionWidget::recordStarted()
201 {
202  mDisplayTimerWidget->start();
203 }
204 void USAcqusitionWidget::recordStopped()
205 {
206  mDisplayTimerWidget->stop();
207 }
208 void USAcqusitionWidget::recordCancelled()
209 {
210  mDisplayTimerWidget->stop();
211 }
212 
213 void USAcqusitionWidget::reconstructAboutToStartSlot()
214 {
215  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
216  mTimedAlgorithmProgressBar->attach(threads);
217 }
218 
219 void USAcqusitionWidget::reconstructStartedSlot()
220 {
221  mAcquisitionService->startPostProcessing();
222 }
223 
224 void USAcqusitionWidget::reconstructFinishedSlot()
225 {
226  std::set<cx::TimedAlgorithmPtr> threads = mUsReconstructionService->getThreadedReconstruction();
227  mTimedAlgorithmProgressBar->detach(threads);
228  mAcquisitionService->stopPostProcessing();
229 }
230 
231 }//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)
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: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)
AcquisitionServicePtr mAcquisitionService
cxLogicManager_EXPORT AcquisitionServicePtr acquisitionService()
void setDescriptionVisibility(bool value)
RecordSessionWidget * mRecordSessionWidget
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.