Skip to content

Commit

Permalink
new setting: chose pass/fail for limit checking of NaN/inf values
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Nov 3, 2024
1 parent 64a7ddc commit 69b2fac
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
33 changes: 20 additions & 13 deletions Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@ void TraceXYPlot::draw(QPainter &p)
auto last = traceToCoordinate(t, j-1, yAxis[i]);
auto now = traceToCoordinate(t, j, yAxis[i]);

// checking limits
for(auto limit : constantLines) {
if(i == 0 && limit->getAxis() != XYPlotConstantLine::Axis::Primary) {
continue;
}
if(i == 1 && limit->getAxis() != XYPlotConstantLine::Axis::Secondary) {
continue;
}
if(!limit->pass(now)) {
limitPassing = false;
}
}

if(isnan(last.y()) || isnan(now.y()) || isinf(last.y()) || isinf(now.y())) {
continue;
}
Expand All @@ -595,19 +608,6 @@ void TraceXYPlot::draw(QPainter &p)
}
// draw line
p.drawLine(p1, p2);

// checking limits
for(auto limit : constantLines) {
if(i == 0 && limit->getAxis() != XYPlotConstantLine::Axis::Primary) {
continue;
}
if(i == 1 && limit->getAxis() != XYPlotConstantLine::Axis::Secondary) {
continue;
}
if(!limit->pass(now)) {
limitPassing = false;
}
}
}
if(i == 0 && nPoints > 0) {
// only draw markers on primary YAxis and if the trace has at least one point
Expand Down Expand Up @@ -1352,6 +1352,13 @@ bool XYPlotConstantLine::pass(QPointF testPoint)
// out of range, always passes
return true;
}

// check for inf/nan on Y value
if(isnan(testPoint.y()) || isinf(testPoint.y())) {
// can not actually evaluate the limits, use pass/fail from preferences for this case
return Preferences::getInstance().Graphs.limitNaNpasses;
}

auto p = lower_bound(points.begin(), points.end(), testPoint.x(), [](QPointF p, double x) -> bool {
return p.x() < x;
});
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ void PreferencesDialog::setInitialGUIState()
ui->GraphsColorTicksBackground->setColor(p->Graphs.Color.Ticks.Background.background);
ui->GraphsDomainChangeBehavior->setCurrentIndex((int) p->Graphs.domainChangeBehavior);
ui->GraphsLimitIndication->setCurrentIndex((int) p->Graphs.limitIndication);
ui->GraphsLimitNaNpasses->setCurrentIndex(p->Graphs.limitNaNpasses ? 1 : 0);
ui->GraphsLineWidth->setValue(p->Graphs.lineWidth);
ui->GraphsFontSizeAxis->setValue(p->Graphs.fontSizeAxis);
ui->GraphsFontSizeCursorOverlay->setValue(p->Graphs.fontSizeCursorOverlay);
Expand Down Expand Up @@ -388,6 +389,7 @@ void PreferencesDialog::updateFromGUI()
p->Graphs.Color.Ticks.divisions = ui->GraphsColorTicksDivisions->getColor();
p->Graphs.domainChangeBehavior = (GraphDomainChangeBehavior) ui->GraphsDomainChangeBehavior->currentIndex();
p->Graphs.limitIndication = (GraphLimitIndication) ui->GraphsLimitIndication->currentIndex();
p->Graphs.limitNaNpasses = ui->GraphsLimitNaNpasses->currentIndex() == 1;
p->Graphs.lineWidth = ui->GraphsLineWidth->value();
p->Graphs.fontSizeAxis = ui->GraphsFontSizeAxis->value();
p->Graphs.fontSizeCursorOverlay = ui->GraphsFontSizeCursorOverlay->value();
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Preferences : public Savable {
} Color;
GraphDomainChangeBehavior domainChangeBehavior;
GraphLimitIndication limitIndication;
bool limitNaNpasses;

double lineWidth;
int fontSizeAxis;
Expand Down Expand Up @@ -257,6 +258,7 @@ class Preferences : public Savable {
{&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)},
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
{&Graphs.limitIndication, "Graphs.limitIndication", GraphLimitIndication::PassFailText},
{&Graphs.limitNaNpasses, "Graphs.limitNaNpasses", false},
{&Graphs.lineWidth, "Graphs.lineWidth", 1.0},
{&Graphs.fontSizeAxis, "Graphs.fontSizeAxis", 10},
{&Graphs.fontSizeCursorOverlay, "Graphs.fontSizeCursorOverlay", 12},
Expand Down
37 changes: 29 additions & 8 deletions Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</size>
</property>
<property name="currentIndex">
<number>6</number>
<number>2</number>
</property>
<widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4">
Expand All @@ -111,7 +111,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-206</y>
<width>679</width>
<height>836</height>
</rect>
Expand Down Expand Up @@ -945,7 +945,7 @@
<x>0</x>
<y>-400</y>
<width>679</width>
<height>964</height>
<height>992</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
Expand Down Expand Up @@ -1378,7 +1378,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_17">
<widget class="QGroupBox" name="GraphsLimitGroup">
<property name="title">
<string>Limit checking</string>
</property>
Expand Down Expand Up @@ -1409,6 +1409,27 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_62">
<property name="text">
<string>NaN/Inf values:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="GraphsLimitNaNpasses">
<item>
<property name="text">
<string>Fail</string>
</property>
</item>
<item>
<property name="text">
<string>Pass</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1445,8 +1466,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>696</width>
<height>564</height>
<width>402</width>
<height>540</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -1791,8 +1812,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>696</width>
<height>564</height>
<width>138</width>
<height>112</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_12">
Expand Down

0 comments on commit 69b2fac

Please sign in to comment.