Merge pull request #16 from nbgsmk/master

Calibration widget handling
This commit is contained in:
jankae 2020-12-07 17:34:09 +01:00 committed by GitHub
commit 87d3cd3e6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 2 deletions

View File

@ -709,6 +709,7 @@ bool Calibration::openFromFile(QString filename)
qWarning() << "Calibration file parsing failed: " << e.what(); qWarning() << "Calibration file parsing failed: " << e.what();
return false; return false;
} }
this->currentCalFile = filename; // if all ok, remember this
return true; return true;
} }
@ -716,7 +717,8 @@ bool Calibration::openFromFile(QString filename)
bool Calibration::saveToFile(QString filename) bool Calibration::saveToFile(QString filename)
{ {
if(filename.isEmpty()) { if(filename.isEmpty()) {
filename = QFileDialog::getSaveFileName(nullptr, "Save calibration data", "", "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog); QString fn = descriptiveCalName();
filename = QFileDialog::getSaveFileName(nullptr, "Save calibration data", fn, "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog);
if(filename.isEmpty()) { if(filename.isEmpty()) {
// aborted selection // aborted selection
return false; return false;
@ -734,10 +736,51 @@ bool Calibration::saveToFile(QString filename)
auto calkit_file = filename + ".calkit"; auto calkit_file = filename + ".calkit";
qDebug() << "Saving associated calibration kit to file" << calkit_file; qDebug() << "Saving associated calibration kit to file" << calkit_file;
kit.toFile(calkit_file); kit.toFile(calkit_file);
this->currentCalFile = calibration_file; // if all ok, remember this
return true; return true;
} }
/**
* @brief Calibration::hzToString
* @param freqHz - input frequency in Hz
* @return descriptive name ie. "SOLT 40M-700M 1000pt"
*/
QString Calibration::descriptiveCalName(){
int precision = 3;
QString lo = Unit::ToString(this->minFreq, "", " kMG", precision); // seems to work, but what are 2nd and 3rd parameters???
QString hi = Unit::ToString(this->maxFreq, "", " kMG", precision);
// due to rounding up 123.66M and 123.99M -> we get lo="124M" and hi="124M"
// so let's add some precision
if (lo == hi) {
// Only in case of 123.66M and 123.69M we would need 5 digits, but that kind of narrow cal. is very unlikely.
precision = 4;
lo = Unit::ToString(this->minFreq, "", " kMG", precision);
hi = Unit::ToString(this->maxFreq, "", " kMG", precision);
}
QString tmp =
Calibration::TypeToString(this->getType())
+ " "
+ lo + "-" + hi
+ " "
+ QString::number(this->points.size()) + "pt";
return tmp;
}
double Calibration::getMinFreq(){
return this->minFreq;
}
double Calibration::getMaxFreq(){
return this->maxFreq;
}
int Calibration::getNumPoints(){
return this->points.size();
}
QString Calibration::getCurrentCalibrationFile(){
return this->currentCalFile;
}
ostream& operator<<(ostream &os, const Calibration &c) ostream& operator<<(ostream &os, const Calibration &c)
{ {
for(auto m : c.measurements) { for(auto m : c.measurements) {

View File

@ -137,6 +137,15 @@ private:
std::vector<Point> points; std::vector<Point> points;
Calkit kit; Calkit kit;
QString descriptiveCalName();
private:
QString currentCalFile;
public:
QString getCurrentCalibrationFile();
double getMinFreq();
double getMaxFreq();
int getNumPoints();
}; };
#endif // CALIBRATION_H #endif // CALIBRATION_H

View File

@ -287,7 +287,10 @@ VNA::VNA(AppWindow *window)
// Calibration toolbar (and populate calibration menu) // Calibration toolbar (and populate calibration menu)
auto tb_cal = new QToolBar("Calibration"); auto tb_cal = new QToolBar("Calibration");
tb_cal->addWidget(new QLabel("Calibration:")); QLabel *cbEnableCal_label = new QLabel("Calibration:");
cbEnableCal_label->setStyleSheet(getCalStyle()); // on app start
cbEnableCal_label->setToolTip(getCalToolTip()); // no cal. file loaded
tb_cal->addWidget(cbEnableCal_label);
auto cbEnableCal = new QCheckBox; auto cbEnableCal = new QCheckBox;
tb_cal->addWidget(cbEnableCal); tb_cal->addWidget(cbEnableCal);
auto cbType = new QComboBox(); auto cbType = new QComboBox();
@ -326,6 +329,8 @@ VNA::VNA(AppWindow *window)
cbEnableCal->blockSignals(true); cbEnableCal->blockSignals(true);
calDisable->setChecked(true); calDisable->setChecked(true);
cbEnableCal->setCheckState(Qt::CheckState::Unchecked); cbEnableCal->setCheckState(Qt::CheckState::Unchecked);
cbEnableCal_label->setStyleSheet(getCalStyle()); // visually indicate loss of calibration
cbEnableCal_label->setToolTip(getCalToolTip()); // cal. file unknown at this moment
cbType->blockSignals(false); cbType->blockSignals(false);
cbEnableCal->blockSignals(false); cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(false); calImportTerms->setEnabled(false);
@ -343,6 +348,8 @@ VNA::VNA(AppWindow *window)
} }
} }
cbEnableCal->setCheckState(Qt::CheckState::Checked); cbEnableCal->setCheckState(Qt::CheckState::Checked);
cbEnableCal_label->setStyleSheet(getCalStyle()); // restore default look of widget
cbEnableCal_label->setToolTip(getCalToolTip()); // on hover, show name of active cal. file
cbType->blockSignals(false); cbType->blockSignals(false);
cbEnableCal->blockSignals(false); cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(true); calImportTerms->setEnabled(true);
@ -407,6 +414,58 @@ VNA::VNA(AppWindow *window)
finalize(central); finalize(central);
} }
QString VNA::getCalStyle()
{
Calibration::InterpolationType interpol = cal.getInterpolation(settings);
QString style = "";
switch (interpol)
{
case Calibration::InterpolationType::Unchanged:
case Calibration::InterpolationType::Exact:
case Calibration::InterpolationType::Interpolate:
style = "";
break;
case Calibration::InterpolationType::Extrapolate:
style = "background-color: yellow";
break;
case Calibration::InterpolationType::NoCalibration:
style = "background-color: red";
break;
}
return style;
}
QString VNA::getCalToolTip()
{
Calibration::InterpolationType interpol = cal.getInterpolation(settings);
QString txt = "";
switch (interpol)
{
case Calibration::InterpolationType::Unchanged:
case Calibration::InterpolationType::Exact:
case Calibration::InterpolationType::Interpolate:
case Calibration::InterpolationType::Extrapolate:
{
QString lo = Unit::ToString(cal.getMinFreq(), "", " kMG", 5);
QString hi = Unit::ToString(cal.getMaxFreq(), "", " kMG", 5);
if (settings.f_start < cal.getMinFreq() ) { lo = "<font color=\"red\">" + lo + "</font>";}
if (settings.f_stop > cal.getMaxFreq() ) { hi = "<font color=\"red\">" + hi + "</font>";}
txt =
"limits: " + lo + " - " + hi
+ "<br>"
+ "points: " + QString::number(cal.getNumPoints())
+ "<br>"
"file: " + cal.getCurrentCalibrationFile();
break;
}
case Calibration::InterpolationType::NoCalibration:
txt = "none";
break;
}
return txt;
}
void VNA::deactivate() void VNA::deactivate()
{ {
StoreSweepSettings(); StoreSweepSettings();
@ -427,7 +486,12 @@ void VNA::initializeDevice()
if(cal.openFromFile(filename)) { if(cal.openFromFile(filename)) {
ApplyCalibration(cal.getType()); ApplyCalibration(cal.getType());
portExtension.setCalkit(&cal.getCalibrationKit()); portExtension.setCalkit(&cal.getCalibrationKit());
qDebug() << "Calibration successful from " << filename;
} else {
qDebug() << "Calibration not successfull from: " << filename;
} }
} else {
qDebug() << "Calibration file not found: " << filename;
} }
removeDefaultCal->setEnabled(true); removeDefaultCal->setEnabled(true);
} else { } else {

View File

@ -70,6 +70,9 @@ private:
bool calMeasuring; bool calMeasuring;
bool calWaitFirst; bool calWaitFirst;
QProgressDialog calDialog; QProgressDialog calDialog;
QString getCalStyle();
QString getCalToolTip();
QMenu *defaultCalMenu; QMenu *defaultCalMenu;
QAction *assignDefaultCal, *removeDefaultCal; QAction *assignDefaultCal, *removeDefaultCal;

View File

@ -163,6 +163,11 @@ void PreferencesDialog::setInitialGUIState()
ui->GeneralGraphBackground->setColor(p->General.graphColors.background); ui->GeneralGraphBackground->setColor(p->General.graphColors.background);
ui->GeneralGraphAxis->setColor(p->General.graphColors.axis); ui->GeneralGraphAxis->setColor(p->General.graphColors.axis);
ui->GeneralGraphDivisions->setColor(p->General.graphColors.divisions); ui->GeneralGraphDivisions->setColor(p->General.graphColors.divisions);
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(0);
if (item != nullptr) {
ui->treeWidget->setCurrentItem(item); // visually select first item
}
} }
void Preferences::load() void Preferences::load()