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