From 5ad44c780ca5fac78128ce13c4375418cced406b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Fri, 16 Dec 2022 22:29:21 +0100 Subject: [PATCH] Rename: non-uniformity -> flatness, also show lines --- .../LibreVNA-GUI/Traces/Marker/marker.cpp | 67 +++++++++++++------ .../LibreVNA-GUI/Traces/Marker/marker.h | 16 ++++- .../LibreVNA-GUI/Traces/traceplot.cpp | 2 +- .../LibreVNA-GUI/Traces/tracexyplot.cpp | 18 +++++ .../PC_Application/LibreVNA-GUI/Util/util.h | 2 +- .../LibreVNA-GUI/preferences.cpp | 4 +- .../PC_Application/LibreVNA-GUI/preferences.h | 4 +- .../LibreVNA-GUI/preferencesdialog.ui | 24 +++---- 8 files changed, 95 insertions(+), 42 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.cpp index 60d854d..2164ff0 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.cpp @@ -136,7 +136,7 @@ QString Marker::formatToString(Marker::Format f) case Format::CenterBandwidth: return "Center + Bandwidth"; case Format::InsertionLoss: return "Insertion loss"; case Format::P1dB: return "P1dB"; - case Format::NonUniformity: return "Non-uniformity"; + case Format::Flatness: return "Flatness"; case Format::maxDeltaNeg: return "Max. Delta Negative"; case Format::maxDeltaPos: return "Max. Delta Positive"; case Format::Last: return ""; @@ -265,8 +265,8 @@ std::vector Marker::applicableFormats() ret.push_back(Format::AvgTone); ret.push_back(Format::AvgModulationProduct); break; - case Type::NonUniformity: - ret.push_back(Format::NonUniformity); + case Type::Flatness: + ret.push_back(Format::Flatness); ret.push_back(Format::maxDeltaNeg); ret.push_back(Format::maxDeltaPos); break; @@ -371,8 +371,8 @@ std::vector Marker::defaultActiveFormats() if(pref.Marker.defaultBehavior.showP1dB) { ret.push_back(Format::P1dB); } - if(pref.Marker.defaultBehavior.showNonUniformity) { - ret.push_back(Format::NonUniformity); + if(pref.Marker.defaultBehavior.showFlatness) { + ret.push_back(Format::Flatness); } if(pref.Marker.defaultBehavior.showMaxDeltaNeg) { ret.push_back(Format::maxDeltaNeg); @@ -567,8 +567,8 @@ QString Marker::readableData(Format f) return "Input P1dB:"+Unit::ToString(position, "dBm", " ", 4); } break; - case Format::NonUniformity: - return "Non-uniformity:"+Unit::ToString(maxDeltaNeg+maxDeltaPos, "dB", " ", 4); + case Format::Flatness: + return "Flatness:"+Unit::ToString(maxDeltaNeg+maxDeltaPos, "dB", " ", 4); break; case Format::maxDeltaNeg: return "max. Δ-:"+Unit::ToString(maxDeltaNeg, "dB", " ", 4); @@ -652,7 +652,7 @@ QString Marker::readableSettings() return "none"; case Type::PhaseNoise: return Unit::ToString(offset, "Hz", " kM", 4); - case Type::NonUniformity: + case Type::Flatness: return "None"; default: break; @@ -1016,7 +1016,7 @@ std::set Marker::getSupportedTypes() supported.insert(Type::Minimum); supported.insert(Type::Delta); supported.insert(Type::PeakTable); - supported.insert(Type::NonUniformity); + supported.insert(Type::Flatness); if(!parentTrace->isReflection()) { supported.insert(Type::Lowpass); supported.insert(Type::Highpass); @@ -1202,7 +1202,7 @@ void Marker::setType(Marker::Type t) case Type::PhaseNoise: required_helpers = {{"o", "Offset", Type::Manual}}; break; - case Type::NonUniformity: + case Type::Flatness: required_helpers = {{"l", "Lower Limit", Type::Manual}, {"u", "Upper Limit", Type::Manual}}; break; default: @@ -1216,7 +1216,7 @@ void Marker::setType(Marker::Type t) helper->setType(h.type); helperMarkers.push_back(helper); } - if(type == Type::NonUniformity) { + if(type == Type::Flatness) { // need to update when any of the helper markers is moved for(auto h : helperMarkers) { connect(h, &Marker::positionChanged, [=](){ @@ -1764,6 +1764,7 @@ void Marker::update() // empty trace, nothing to do return; } + lines.clear(); auto xmin = restrictPosition ? minPosition : numeric_limits::lowest(); auto xmax = restrictPosition ? maxPosition : numeric_limits::max(); switch(type) { @@ -1922,28 +1923,47 @@ void Marker::update() setPosition(p1db); } break; - case Type::NonUniformity: { - auto dbLower = Util::SparamTodB(helperMarkers[0]->getData()); - auto dbUpper = Util::SparamTodB(helperMarkers[1]->getData()); + case Type::Flatness: { + auto lower = helperMarkers[0]->getData(); + auto upper = helperMarkers[1]->getData(); auto posLower = helperMarkers[0]->getPosition(); auto posUpper = helperMarkers[1]->getPosition(); + // three additional lines: + // 0: line between lower and upper markers + // 1: positive peak deviation + // 2: negative peak deviation + lines.resize(3); + lines[0].p1.x = posLower; + lines[0].p1.y = lower; + lines[0].p2.x = posUpper; + lines[0].p2.y = upper; if(posLower > posUpper) { swap(posLower, posUpper); - swap(dbLower, dbUpper); + swap(lower, upper); } auto startIndex = parentTrace->index(posLower); auto stopIndex = parentTrace->index(posUpper); maxDeltaNeg = std::numeric_limits::lowest(); maxDeltaPos = std::numeric_limits::lowest(); for(int i=startIndex;i<=stopIndex;i++) { - auto dbTrace = Util::SparamTodB(parentTrace->sample(i).y); - auto dbStraightLine = Util::Scale((double) i, (double) startIndex, (double) stopIndex, dbLower, dbUpper); + auto sample = parentTrace->sample(i); + auto dbTrace = Util::SparamTodB(sample.y); + auto dbStraightLine = Util::Scale((double) i, (double) startIndex, (double) stopIndex, Util::SparamTodB(lower), Util::SparamTodB(upper)); + auto straightLine = Util::dBToMagnitude(dbStraightLine); auto delta = dbTrace - dbStraightLine; if(delta > maxDeltaPos) { maxDeltaPos = delta; + lines[1].p1.x = sample.x; + lines[1].p1.y = sample.y; + lines[1].p2.x = sample.x; + lines[1].p2.y = straightLine; } if(-delta > maxDeltaNeg) { maxDeltaNeg = -delta; + lines[2].p1.x = sample.x; + lines[2].p1.y = sample.y; + lines[2].p2.x = sample.x; + lines[2].p2.y = straightLine; } } } @@ -1972,8 +1992,8 @@ std::complex Marker::getData() const bool Marker::isMovable() { if(parent) { - if(parent->type == Type::NonUniformity) { - // non-uniformity is the exception, it has movable helper markers + if(parent->type == Type::Flatness) { + // flatness is the exception, it has movable helper markers return true; } // helper traces are never movable by the user @@ -1994,8 +2014,8 @@ bool Marker::isMovable() bool Marker::isEditable() { if(parent) { - if(parent->type == Type::NonUniformity) { - // non-uniformity is the exception, it has movable helper markers + if(parent->type == Type::Flatness) { + // flatness is the exception, it has movable helper markers return true; } // helper traces are never movable by the user @@ -2027,3 +2047,8 @@ Trace::DataType Marker::getDomain() return Trace::DataType::Invalid; } +std::vector Marker::getLines() +{ + return lines; +} + diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.h b/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.h index 203c319..4e1cbba 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/Marker/marker.h @@ -47,7 +47,7 @@ public: AvgModulationProduct, // average level of modulation products // compression parameters P1dB, // power level at 1dB compression - NonUniformity, + Flatness, maxDeltaPos, maxDeltaNeg, // keep last at end @@ -74,6 +74,12 @@ public: bool isEditable(); Trace::DataType getDomain(); + class Line { + public: + TraceMath::Data p1, p2; + }; + std::vector getLines(); + QPixmap& getSymbol(); unsigned long getCreationTimestamp() const; @@ -96,7 +102,7 @@ public: TOI, PhaseNoise, P1dB, - NonUniformity, + Flatness, // keep last at end Last, }; @@ -176,7 +182,7 @@ private: case Type::TOI: return "TOI/IP3"; case Type::PhaseNoise: return "Phase noise"; case Type::P1dB: return "1dB compression"; - case Type::NonUniformity: return "Non-uniformity"; + case Type::Flatness: return "Flatness"; default: return QString(); } } @@ -212,6 +218,10 @@ private: Marker *delta; std::vector helperMarkers; Marker *parent; + + // additional lines the marker wants to show on the graphs (the graphs are responsible for drawing the lines) + std::vector lines; + // settings for the different marker types double cutoffAmplitude; double peakThreshold; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp index ac89e3f..231db7a 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp @@ -448,7 +448,7 @@ Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable) closestDistance = distance; if(m->getParent()) { closestMarker = m->getParent(); - if(closestMarker->getType() == Marker::Type::NonUniformity) { + if(closestMarker->getType() == Marker::Type::Flatness) { closestMarker = m; } } else { diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index 54da364..5190e88 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -607,6 +607,24 @@ void TraceXYPlot::draw(QPainter &p) markerPoint = traceToCoordinate(t, t->index(xPosition), yAxis[i]); } auto point = plotValueToPixel(markerPoint, i); + + for(auto line : m->getLines()) { + QPointF pF1 = QPointF(numeric_limits::quiet_NaN(), numeric_limits::quiet_NaN()); + pF1.setX(xAxis.sampleToCoordinate(line.p1)); + pF1.setY(yAxis[0].sampleToCoordinate(line.p1)); + QPointF pF2 = QPointF(numeric_limits::quiet_NaN(), numeric_limits::quiet_NaN()); + pF2.setX(xAxis.sampleToCoordinate(line.p2)); + pF2.setY(yAxis[0].sampleToCoordinate(line.p2)); + auto p1 = plotValueToPixel(pF1, i); + auto p2 = plotValueToPixel(pF2, i); + if(!plotRect.contains(p1) && !plotRect.contains(p2)) { + // completely out of frame + continue; + } + // draw line + p.drawLine(p1, p2); + } + if(!plotRect.contains(point)) { // out of screen continue; diff --git a/Software/PC_Application/LibreVNA-GUI/Util/util.h b/Software/PC_Application/LibreVNA-GUI/Util/util.h index 14de768..cec5015 100644 --- a/Software/PC_Application/LibreVNA-GUI/Util/util.h +++ b/Software/PC_Application/LibreVNA-GUI/Util/util.h @@ -11,7 +11,7 @@ namespace Util { template T Scale(T value, T from_low, T from_high, T to_low, T to_high, bool log_from = false, bool log_to = false) { - double normalized; + T normalized; if(log_from) { normalized = log10(value / from_low) / log10(from_high / from_low); } else { diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.cpp b/Software/PC_Application/LibreVNA-GUI/preferences.cpp index 7b8ecf5..90fc33e 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.cpp +++ b/Software/PC_Application/LibreVNA-GUI/preferences.cpp @@ -380,7 +380,7 @@ void PreferencesDialog::setInitialGUIState() ui->MarkerShowAvgTone->setChecked(p->Marker.defaultBehavior.showAvgTone); ui->MarkerShowAvgMod->setChecked(p->Marker.defaultBehavior.showAvgModulation); ui->MarkerShowP1dB->setChecked(p->Marker.defaultBehavior.showP1dB); - ui->MarkerShowNonUniformity->setChecked(p->Marker.defaultBehavior.showNonUniformity); + ui->MarkerShowFlatness->setChecked(p->Marker.defaultBehavior.showFlatness); ui->MarkerShowMaxDeltaNeg->setChecked(p->Marker.defaultBehavior.showMaxDeltaNeg); ui->MarkerShowMaxDeltaPos->setChecked(p->Marker.defaultBehavior.showMaxDeltaPos); ui->MarkerInterpolate->setCurrentIndex(p->Marker.interpolatePoints ? 1 : 0); @@ -488,7 +488,7 @@ void PreferencesDialog::updateFromGUI() p->Marker.defaultBehavior.showAvgTone = ui->MarkerShowAvgTone->isChecked(); p->Marker.defaultBehavior.showAvgModulation = ui->MarkerShowAvgMod->isChecked(); p->Marker.defaultBehavior.showP1dB = ui->MarkerShowP1dB->isChecked(); - p->Marker.defaultBehavior.showNonUniformity = ui->MarkerShowNonUniformity->isChecked(); + p->Marker.defaultBehavior.showFlatness = ui->MarkerShowFlatness->isChecked(); p->Marker.defaultBehavior.showMaxDeltaNeg = ui->MarkerShowMaxDeltaNeg->isChecked(); p->Marker.defaultBehavior.showMaxDeltaPos = ui->MarkerShowMaxDeltaPos->isChecked(); p->Marker.interpolatePoints = ui->MarkerInterpolate->currentIndex() == 1; diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.h b/Software/PC_Application/LibreVNA-GUI/preferences.h index 411b490..34cb523 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.h +++ b/Software/PC_Application/LibreVNA-GUI/preferences.h @@ -150,7 +150,7 @@ public: struct { bool showDataOnGraphs; bool showdB, showdBm, showdBuV, showdBAngle, showRealImag, showImpedance, showVSWR, showResistance, showCapacitance, showInductance, showQualityFactor; - bool showNoise, showPhasenoise, showCenterBandwidth, showCutoff, showInsertionLoss, showTOI, showAvgTone, showAvgModulation, showP1dB, showNonUniformity, showMaxDeltaNeg, showMaxDeltaPos; + bool showNoise, showPhasenoise, showCenterBandwidth, showCutoff, showInsertionLoss, showTOI, showAvgTone, showAvgModulation, showP1dB, showFlatness, showMaxDeltaNeg, showMaxDeltaPos; } defaultBehavior; bool interpolatePoints; MarkerSortOrder sortOrder; @@ -264,7 +264,7 @@ private: {&Marker.defaultBehavior.showAvgTone, "Marker.defaultBehavior.showAvgTone", true}, {&Marker.defaultBehavior.showAvgModulation, "Marker.defaultBehavior.showAvgModulation", true}, {&Marker.defaultBehavior.showP1dB, "Marker.defaultBehavior.showP1dB", true}, - {&Marker.defaultBehavior.showNonUniformity, "Marker.defaultBehavior.showNonUniformity", true}, + {&Marker.defaultBehavior.showFlatness, "Marker.defaultBehavior.showNonUniformity", true}, {&Marker.defaultBehavior.showMaxDeltaNeg, "Marker.defaultBehavior.showMaxDeltaNeg", true}, {&Marker.defaultBehavior.showMaxDeltaPos, "Marker.defaultBehavior.showMaxDeltaPos", true}, {&Marker.interpolatePoints, "Marker.interpolatePoints", false}, diff --git a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui index 6ea3bc0..c7e8581 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui @@ -107,8 +107,8 @@ 0 0 - 749 - 920 + 530 + 937 @@ -712,8 +712,8 @@ 0 0 - 749 - 846 + 565 + 863 @@ -1033,8 +1033,8 @@ 0 0 - 749 - 952 + 553 + 969 @@ -1641,9 +1641,9 @@ - + - Non-uniformity + Flatness @@ -1885,8 +1885,8 @@ 0 0 - 763 - 561 + 126 + 90 @@ -1956,8 +1956,8 @@ 0 0 - 763 - 561 + 263 + 241