mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-21 06:13:41 +00:00
More intuitive handling of calibration measurements
- Allow saving of calibration only if a calibration is active (no more calibration files that "don't do anything" when they are opened) - Delete old measurements when loading a new calibration file - Update calibration when a measurement is updated (no need to disable and enable again) - Disable calibration when a required measurement is deleted
This commit is contained in:
parent
3f66bdda48
commit
0d6e844def
12 changed files with 149 additions and 88 deletions
|
|
@ -24,7 +24,7 @@ Calibration::Calibration()
|
|||
void Calibration::clearMeasurements()
|
||||
{
|
||||
for(auto m : measurements) {
|
||||
m.second.datapoints.clear();
|
||||
clearMeasurement(m.first);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,11 +42,19 @@ void Calibration::addMeasurement(Calibration::Measurement type, Protocol::Datapo
|
|||
|
||||
bool Calibration::calculationPossible(Calibration::Type type)
|
||||
{
|
||||
if(type == Type::None) {
|
||||
// always possible to reset to None
|
||||
return true;
|
||||
}
|
||||
return SanityCheckSamples(Measurements(type, false));
|
||||
}
|
||||
#include <QDebug>
|
||||
bool Calibration::constructErrorTerms(Calibration::Type type)
|
||||
{
|
||||
if(type == Type::None) {
|
||||
resetErrorTerms();
|
||||
return true;
|
||||
}
|
||||
if(!calculationPossible(type)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -602,6 +610,10 @@ bool Calibration::openFromFile(QString filename)
|
|||
}
|
||||
}
|
||||
|
||||
// reset all data before loading new calibration
|
||||
clearMeasurements();
|
||||
resetErrorTerms();
|
||||
|
||||
// attempt to load associated calibration kit first (needs to be available when performing calibration)
|
||||
auto calkit_file = filename;
|
||||
auto dotPos = calkit_file.lastIndexOf('.');
|
||||
|
|
@ -610,7 +622,7 @@ bool Calibration::openFromFile(QString filename)
|
|||
}
|
||||
calkit_file.append(".calkit");
|
||||
try {
|
||||
kit = Calkit::fromFile(calkit_file.toStdString());
|
||||
kit = Calkit::fromFile(calkit_file);
|
||||
} catch (runtime_error e) {
|
||||
QMessageBox::warning(nullptr, "Missing calibration kit", "The calibration kit file associated with the selected calibration could not be parsed. The calibration might not be accurate. (" + QString(e.what()) + ")");
|
||||
}
|
||||
|
|
@ -636,20 +648,17 @@ bool Calibration::saveToFile(QString filename)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// strip any potential file name extension and set default
|
||||
auto dotPos = filename.lastIndexOf('.');
|
||||
if(dotPos >= 0) {
|
||||
filename.truncate(dotPos);
|
||||
|
||||
if(filename.endsWith(".cal")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
auto calibration_file = filename;
|
||||
calibration_file.append(".cal");
|
||||
auto calibration_file = filename + ".cal";
|
||||
ofstream file;
|
||||
file.open(calibration_file.toStdString());
|
||||
file << *this;
|
||||
|
||||
auto calkit_file = filename;
|
||||
calkit_file.append(".calkit");
|
||||
kit.toFile(calkit_file.toStdString());
|
||||
auto calkit_file = filename + ".calkit";
|
||||
kit.toFile(calkit_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ CalibrationTraceDialog::CalibrationTraceDialog(Calibration *cal, Calibration::Ty
|
|||
ui->tableView->setColumnWidth(1, 350);
|
||||
ui->tableView->setColumnWidth(2, 320);
|
||||
ui->tableView->setColumnWidth(3, 160);
|
||||
UpdateApplyButton();
|
||||
UpdateCalibrationStatus();
|
||||
}
|
||||
|
||||
CalibrationTraceDialog::~CalibrationTraceDialog()
|
||||
|
|
@ -32,11 +32,19 @@ CalibrationTraceDialog::~CalibrationTraceDialog()
|
|||
void CalibrationTraceDialog::measurementComplete(Calibration::Measurement m)
|
||||
{
|
||||
model->measurementUpdated(m);
|
||||
UpdateApplyButton();
|
||||
UpdateCalibrationStatus();
|
||||
}
|
||||
|
||||
void CalibrationTraceDialog::UpdateApplyButton()
|
||||
void CalibrationTraceDialog::UpdateCalibrationStatus()
|
||||
{
|
||||
if(!cal->calculationPossible(cal->getType())) {
|
||||
// some trace for the current calibration was deleted
|
||||
cal->resetErrorTerms();
|
||||
emit calibrationInvalidated();
|
||||
} else {
|
||||
// update error terms as a measurement might have changed
|
||||
cal->constructErrorTerms(cal->getType());
|
||||
}
|
||||
ui->bApply->setEnabled(cal->calculationPossible(requestedType));
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +53,7 @@ void CalibrationTraceDialog::on_bDelete_clicked()
|
|||
auto measurement = measurements[ui->tableView->currentIndex().row()];
|
||||
cal->clearMeasurement(measurement);
|
||||
model->measurementUpdated(measurement);
|
||||
UpdateApplyButton();
|
||||
UpdateCalibrationStatus();
|
||||
}
|
||||
|
||||
void CalibrationTraceDialog::on_bMeasure_clicked()
|
||||
|
|
@ -59,17 +67,3 @@ void CalibrationTraceDialog::on_bApply_clicked()
|
|||
emit applyCalibration(requestedType);
|
||||
accept();
|
||||
}
|
||||
|
||||
void CalibrationTraceDialog::on_bOpen_clicked()
|
||||
{
|
||||
cal->openFromFile();
|
||||
UpdateApplyButton();
|
||||
if(cal->getType() != Calibration::Type::None) {
|
||||
emit applyCalibration(cal->getType());
|
||||
}
|
||||
}
|
||||
|
||||
void CalibrationTraceDialog::on_bSave_clicked()
|
||||
{
|
||||
cal->saveToFile();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,18 +22,15 @@ public slots:
|
|||
signals:
|
||||
void triggerMeasurement(Calibration::Measurement m);
|
||||
void applyCalibration(Calibration::Type type);
|
||||
void calibrationInvalidated();
|
||||
|
||||
private slots:
|
||||
void on_bDelete_clicked();
|
||||
void on_bMeasure_clicked();
|
||||
void on_bApply_clicked();
|
||||
|
||||
void on_bOpen_clicked();
|
||||
|
||||
void on_bSave_clicked();
|
||||
|
||||
private:
|
||||
void UpdateApplyButton();
|
||||
void UpdateCalibrationStatus();
|
||||
Ui::CalibrationTraceDialog *ui;
|
||||
Calibration *cal;
|
||||
Calibration::Type requestedType;
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1066</width>
|
||||
<height>396</height>
|
||||
<width>1079</width>
|
||||
<height>578</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Calibration Traces</string>
|
||||
<string>Calibration Measurements</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
|
|
@ -65,28 +65,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bOpen">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="document-open" resource="../icons.qrc">
|
||||
<normaloff>:/icons/open.png</normaloff>:/icons/open.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="document-save" resource="../icons.qrc">
|
||||
<normaloff>:/icons/save.png</normaloff>:/icons/save.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
|
|||
|
|
@ -26,9 +26,12 @@ Calkit::Calkit()
|
|||
|
||||
|
||||
#include <QDebug>
|
||||
void Calkit::toFile(std::string filename)
|
||||
{
|
||||
TransformPathsToRelative(QString::fromStdString(filename));
|
||||
void Calkit::toFile(QString filename)
|
||||
{
|
||||
if(!filename.endsWith(".calkit")) {
|
||||
filename.append(".calkit");
|
||||
}
|
||||
TransformPathsToRelative(filename);
|
||||
|
||||
json j;
|
||||
for(auto e : json_descr) {
|
||||
|
|
@ -39,7 +42,6 @@ void Calkit::toFile(std::string filename)
|
|||
}
|
||||
// json library does not now about QVariant, handle used cases
|
||||
auto val = e.var.value();
|
||||
qDebug() << val << endl;
|
||||
switch(static_cast<QMetaType::Type>(val.type())) {
|
||||
case QMetaType::Double: *json_entry = val.toDouble(); break;
|
||||
case QMetaType::Int: *json_entry = val.toInt(); break;
|
||||
|
|
@ -50,11 +52,11 @@ void Calkit::toFile(std::string filename)
|
|||
}
|
||||
}
|
||||
ofstream file;
|
||||
file.open(filename);
|
||||
file.open(filename.toStdString());
|
||||
file << setw(4) << j << endl;
|
||||
file.close();
|
||||
|
||||
TransformPathsToAbsolute(QString::fromStdString(filename));
|
||||
TransformPathsToAbsolute(filename);
|
||||
}
|
||||
|
||||
static QString readLine(ifstream &file) {
|
||||
|
|
@ -63,11 +65,11 @@ static QString readLine(ifstream &file) {
|
|||
return QString::fromStdString(line).simplified();
|
||||
}
|
||||
|
||||
Calkit Calkit::fromFile(std::string filename)
|
||||
Calkit Calkit::fromFile(QString filename)
|
||||
{
|
||||
auto c = Calkit();
|
||||
ifstream file;
|
||||
file.open(filename);
|
||||
file.open(filename.toStdString());
|
||||
if(!file.is_open()) {
|
||||
throw runtime_error("Unable to open file");
|
||||
}
|
||||
|
|
@ -101,9 +103,7 @@ Calkit Calkit::fromFile(std::string filename)
|
|||
case QMetaType::Bool: e.var.setValue((*json_entry).get<bool>()); break;
|
||||
case QMetaType::QString: {
|
||||
auto s = QString::fromStdString((*json_entry).get<string>());
|
||||
qDebug() << s;
|
||||
e.var.setValue(s);
|
||||
qDebug() << e.var.value();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -162,7 +162,7 @@ Calkit Calkit::fromFile(std::string filename)
|
|||
|
||||
auto msg = new QMessageBox();
|
||||
msg->setWindowTitle("Loading calkit file");
|
||||
msg->setText("The file \"" + QString::fromStdString(filename) + "\" is stored in a deprecated"
|
||||
msg->setText("The file \"" + filename + "\" is stored in a deprecated"
|
||||
" calibration kit format. Future versions of this application might not support"
|
||||
" it anymore. Please save the calibration kit to update to the new format");
|
||||
msg->setStandardButtons(QMessageBox::Ok);
|
||||
|
|
@ -170,7 +170,7 @@ Calkit Calkit::fromFile(std::string filename)
|
|||
}
|
||||
file.close();
|
||||
|
||||
c.TransformPathsToAbsolute(QString::fromStdString(filename));
|
||||
c.TransformPathsToAbsolute(filename);
|
||||
|
||||
// set default values for non-editable items (for now)
|
||||
c.TRL.Through.Z0 = 50.0;
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ public:
|
|||
std::complex<double> ThroughS11, ThroughS12, ThroughS21, ThroughS22;
|
||||
};
|
||||
|
||||
void toFile(std::string filename);
|
||||
static Calkit fromFile(std::string filename);
|
||||
void toFile(QString filename);
|
||||
static Calkit fromFile(QString filename);
|
||||
void edit();
|
||||
SOLT toSOLT(double frequency);
|
||||
TRL toTRL(double frequency);
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ CalkitDialog::CalkitDialog(Calkit &c, QWidget *parent) :
|
|||
connect(ui->buttonBox->button(QDialogButtonBox::Open), &QPushButton::clicked, [=](){
|
||||
auto filename = QFileDialog::getOpenFileName(this, "Open calibration kit coefficients", "", "Calibration kit files (*.calkit)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||
if(filename.length() > 0) {
|
||||
ownKit = Calkit::fromFile(filename.toStdString());
|
||||
ownKit = Calkit::fromFile(filename);
|
||||
updateEntries();
|
||||
}
|
||||
});
|
||||
|
|
@ -127,14 +127,8 @@ CalkitDialog::CalkitDialog(Calkit &c, QWidget *parent) :
|
|||
connect(ui->buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=](){
|
||||
auto filename = QFileDialog::getSaveFileName(this, "Save calibration kit coefficients", "", "Calibration kit files (*.calkit)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||
if(filename.length() > 0) {
|
||||
// strip any potential file name extension and set default
|
||||
auto dotPos = filename.lastIndexOf('.');
|
||||
if(dotPos >= 0) {
|
||||
filename.truncate(dotPos);
|
||||
}
|
||||
filename.append(".calkit");
|
||||
parseEntries();
|
||||
ownKit.toFile(filename.toStdString());
|
||||
ownKit.toFile(filename);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue