14 #include <QPushButton>
15 #include <QDoubleSpinBox>
16 #include <QVBoxLayout>
17 #include <QHBoxLayout>
27 BaseWidget(parent,
"sound_speed_converter_widget",
"Sound Speed Converter"),
28 mScannerSoundSpeed(1540.0),
29 mApplyButton(new QPushButton(
"Apply compensation")),
30 mResetButton(new QPushButton(
"Reset")),
31 mSoundSpeedSpinBox(new QDoubleSpinBox()),
32 mWaterDegreeSpinBox(new QDoubleSpinBox()),
33 mTrackingService(trackingService)
35 QVBoxLayout* vLayout =
new QVBoxLayout(
this);
36 this->setToolTip(
"Correct the sound speed received from the US scanner");
39 connect(mResetButton, SIGNAL(clicked()),
this, SLOT(resetSlot()));
41 mWaterDegreeSpinBox->setRange(0.0, 50.0);
42 connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterDegreeChangedSlot()));
43 mSoundSpeedSpinBox->setRange(1000.0, 2000.0);
44 connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterSoundSpeedChangedSlot()));
46 QHBoxLayout* speedLayout =
new QHBoxLayout();
47 speedLayout->addWidget(
new QLabel(
"Water sound speed: "));
48 speedLayout->addWidget(mSoundSpeedSpinBox);
49 speedLayout->addWidget(
new QLabel(
"m/s, or "));
50 speedLayout->addWidget(mWaterDegreeSpinBox);
51 speedLayout->addWidget(
new QLabel(
"C"+QString::fromUtf8(
"\302\260")+
""));
53 QHBoxLayout* buttonLayout =
new QHBoxLayout();
54 buttonLayout->addWidget(mApplyButton);
55 buttonLayout->addWidget(mResetButton);
57 vLayout->addLayout(speedLayout);
58 vLayout->addLayout(buttonLayout);
61 this->updateButtons();
73 reportWarning(
"Don't know which probe to set the sound speed compensation for...");
77 double factor = this->getSoundSpeedCompensationFactor();
78 mProbe->setSoundSpeedCompensationFactor(factor);
81 void SoundSpeedConverterWidget::setToolSlot(
const QString& uid)
83 ToolPtr tool = mTrackingService->getTool(uid);
89 this->setProbe(probe);
92 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
94 return mToSoundSpeed/mScannerSoundSpeed;
97 double SoundSpeedConverterWidget::getWaterSoundSpeed()
99 double waterDegree = mWaterDegreeSpinBox->value();
100 double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
105 void SoundSpeedConverterWidget::setProbe(
ProbePtr probe)
108 this->updateButtons();
111 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
113 mToSoundSpeed = mSoundSpeedSpinBox->value();
115 QFont font = mWaterDegreeSpinBox->font();
116 font.setStrikeOut(
true);
117 mWaterDegreeSpinBox->setFont(font);
120 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
122 mToSoundSpeed = this->getWaterSoundSpeed();
124 if(mToSoundSpeed != mSoundSpeedSpinBox->value())
125 mSoundSpeedSpinBox->setValue(mToSoundSpeed);
127 QFont font = mWaterDegreeSpinBox->font();
128 font.setStrikeOut(
false);
129 mWaterDegreeSpinBox->setFont(font);
132 void SoundSpeedConverterWidget::resetSlot()
134 this->setSoundSpeed(mScannerSoundSpeed);
141 void SoundSpeedConverterWidget::setSoundSpeed(
double soundspeed)
143 mSoundSpeedSpinBox->setValue(soundspeed);
146 void SoundSpeedConverterWidget::setWaterDegree(
double degree)
148 mWaterDegreeSpinBox->setValue(degree);
151 void SoundSpeedConverterWidget::updateButtons()
153 mApplyButton->setEnabled(mProbe ?
true :
false);
154 mResetButton->setEnabled(
true);