From b3b3fa7718a80e89b7d37717199e91a7566ae2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Thu, 1 May 2025 14:53:48 +0200 Subject: [PATCH] improve domain handling for math traces --- .../LibreVNA-GUI/Traces/trace.cpp | 23 +++++++++- .../LibreVNA-GUI/Traces/trace.h | 1 + .../LibreVNA-GUI/Traces/traceeditdialog.cpp | 43 ++++++++++++++----- .../LibreVNA-GUI/Traces/traceeditdialog.h | 1 + 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp index ee017db..99d2d46 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp @@ -465,7 +465,21 @@ void Trace::updateMathTracePoints() double startX = std::numeric_limits::lowest(); double stopX = std::numeric_limits::max(); double stepSize = std::numeric_limits::max(); + auto domain = DataType::Invalid; for(auto t : mathSourceTraces) { + if(domain == DataType::Invalid) { + domain = t.first->outputType(); + } else { + if(domain != t.first->outputType()) { + // not all traces have the same domain, clear output and do not calculate + data.resize(0); + mathUpdateBegin = 0; + mathUpdateEnd = 0; + dataType = DataType::Invalid; + emit outputTypeChanged(dataType); + return; + } + } if(t.first->minX() > startX) { startX = t.first->minX(); } @@ -480,7 +494,14 @@ void Trace::updateMathTracePoints() stepSize = traceStepSize; } } - unsigned int samples = round((stopX - startX) / stepSize + 1); + if(domain != this->domain) { + this->domain = domain; + emit typeChanged(this); + } + unsigned int samples = 0; + if(stopX > startX) { + samples = round((stopX - startX) / stepSize + 1); + } // qDebug() << "Updated trace points, now"<setText(""); variableItem->setFlags(variableItem->flags() & ~(Qt::ItemIsEnabled | Qt::ItemIsEditable)); } - // available trace selections may have changed, disable/enable other rows - for(unsigned int i=0;igetTraces().size();i++) { - auto traceItem = ui->mathTraceTable->item(i, 0); - auto flags = traceItem->flags(); - if(t.canAddAsMathSource(t.getModel()->trace(i))) { - traceItem->setFlags(flags | Qt::ItemIsEnabled); - } else { - traceItem->setFlags(flags & ~Qt::ItemIsEnabled); - } - } + updateMathFormulaSelectableRows(); } else { // changed the variable name text t.addMathSource(trace, item->text()); @@ -216,6 +207,8 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(updateMathFormulaStatus()); }); } + updateMathFormulaSelectableRows(); + updateMathFormulaStatus(); switch(t.getSource()) { case Trace::Source::Live: ui->bLive->click(); break; @@ -384,6 +377,21 @@ void TraceEditDialog::okClicked() bool TraceEditDialog::updateMathFormulaStatus() { + // check output domains first (there could be a problem if a trace changed its output domain + // after the math trace was created) + auto domain = TraceMath::DataType::Invalid; + for(auto t : trace.mathSourceTraces) { + if(domain == TraceMath::DataType::Invalid) { + domain = t.first->outputType(); + } else { + if(domain != t.first->outputType()) { + // not all traces have the same domain + ui->lMathFormulaStatus->setText("Different output domains of selected source traces"); + ui->lMathFormulaStatus->setStyleSheet("QLabel { color : red; }"); + return false; + } + } + } auto error = trace.getMathFormulaError(); if(error.isEmpty()) { // all good @@ -397,6 +405,21 @@ bool TraceEditDialog::updateMathFormulaStatus() } } +void TraceEditDialog::updateMathFormulaSelectableRows() +{ + // available trace selections may have changed, disable/enable other rows + for(unsigned int i=0;igetTraces().size();i++) { + auto traceItem = ui->mathTraceTable->item(i, 0); + auto flags = traceItem->flags(); + if(trace.canAddAsMathSource(trace.getModel()->trace(i)) || traceItem->checkState()) { + // Item can always be deselected but only selected if it is compatible + traceItem->setFlags(flags | Qt::ItemIsEnabled); + } else { + traceItem->setFlags(flags & ~Qt::ItemIsEnabled); + } + } +} + MathModel::MathModel(Trace &t, QObject *parent) : QAbstractTableModel(parent), t(t) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h index f00d237..6a6f511 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h @@ -50,6 +50,7 @@ private slots: private: bool updateMathFormulaStatus(); + void updateMathFormulaSelectableRows(); Ui::TraceEditDialog *ui; Trace &trace; bool VNAtrace;