diff --git a/Software/PC_Application/Calibration/calibration.cpp b/Software/PC_Application/Calibration/calibration.cpp index 310f850..4263a52 100644 --- a/Software/PC_Application/Calibration/calibration.cpp +++ b/Software/PC_Application/Calibration/calibration.cpp @@ -709,6 +709,7 @@ bool Calibration::openFromFile(QString filename) qWarning() << "Calibration file parsing failed: " << e.what(); return false; } + this->currentCalFile = filename; // if all ok, remember this return true; } @@ -716,7 +717,8 @@ bool Calibration::openFromFile(QString filename) bool Calibration::saveToFile(QString filename) { 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()) { // aborted selection return false; @@ -734,10 +736,51 @@ bool Calibration::saveToFile(QString filename) auto calkit_file = filename + ".calkit"; qDebug() << "Saving associated calibration kit to file" << calkit_file; kit.toFile(calkit_file); + this->currentCalFile = calibration_file; // if all ok, remember this 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) { for(auto m : c.measurements) { diff --git a/Software/PC_Application/Calibration/calibration.h b/Software/PC_Application/Calibration/calibration.h index 47b496d..0ae16c4 100644 --- a/Software/PC_Application/Calibration/calibration.h +++ b/Software/PC_Application/Calibration/calibration.h @@ -137,6 +137,15 @@ private: std::vector points; Calkit kit; + QString descriptiveCalName(); + +private: + QString currentCalFile; +public: + QString getCurrentCalibrationFile(); + double getMinFreq(); + double getMaxFreq(); + int getNumPoints(); }; #endif // CALIBRATION_H diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp index 1ecd786..258e371 100644 --- a/Software/PC_Application/VNA/vna.cpp +++ b/Software/PC_Application/VNA/vna.cpp @@ -287,7 +287,10 @@ VNA::VNA(AppWindow *window) // Calibration toolbar (and populate calibration menu) 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; tb_cal->addWidget(cbEnableCal); auto cbType = new QComboBox(); @@ -326,6 +329,8 @@ VNA::VNA(AppWindow *window) cbEnableCal->blockSignals(true); calDisable->setChecked(true); 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); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(false); @@ -343,6 +348,8 @@ VNA::VNA(AppWindow *window) } } 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); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(true); @@ -407,6 +414,58 @@ VNA::VNA(AppWindow *window) 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 = "" + lo + "";} + if (settings.f_stop > cal.getMaxFreq() ) { hi = "" + hi + "";} + txt = + "limits: " + lo + " - " + hi + + "
" + + "points: " + QString::number(cal.getNumPoints()) + + "
" + "file: " + cal.getCurrentCalibrationFile(); + break; + } + case Calibration::InterpolationType::NoCalibration: + txt = "none"; + break; + } + return txt; +} + void VNA::deactivate() { StoreSweepSettings(); @@ -427,7 +486,12 @@ void VNA::initializeDevice() if(cal.openFromFile(filename)) { ApplyCalibration(cal.getType()); 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); } else { diff --git a/Software/PC_Application/VNA/vna.h b/Software/PC_Application/VNA/vna.h index f9db043..c30de43 100644 --- a/Software/PC_Application/VNA/vna.h +++ b/Software/PC_Application/VNA/vna.h @@ -70,6 +70,9 @@ private: bool calMeasuring; bool calWaitFirst; QProgressDialog calDialog; + QString getCalStyle(); + QString getCalToolTip(); + QMenu *defaultCalMenu; QAction *assignDefaultCal, *removeDefaultCal; diff --git a/Software/PC_Application/preferences.cpp b/Software/PC_Application/preferences.cpp index 6ca99dd..d1bc3b0 100644 --- a/Software/PC_Application/preferences.cpp +++ b/Software/PC_Application/preferences.cpp @@ -163,6 +163,11 @@ void PreferencesDialog::setInitialGUIState() ui->GeneralGraphBackground->setColor(p->General.graphColors.background); ui->GeneralGraphAxis->setColor(p->General.graphColors.axis); 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()