handle zero span data throughout the application

This commit is contained in:
Jan Käberich 2022-06-22 23:50:21 +02:00
parent 7151fffcdb
commit edec4d9ec5
12 changed files with 49 additions and 16 deletions

View File

@ -96,6 +96,7 @@ void CSVImport::evaluateFile()
ui->to->setUnit("Hz");
break;
case Trace::DataType::Time:
case Trace::DataType::TimeZeroSpan:
ui->from->setUnit("s");
ui->to->setUnit("s");
break;

View File

@ -50,6 +50,7 @@ void Math::Expression::edit()
case DataType::Frequency: ui->stackedWidget->setCurrentIndex(0); break;
case DataType::Time: ui->stackedWidget->setCurrentIndex(1); break;
case DataType::Power: ui->stackedWidget->setCurrentIndex(2); break;
case DataType::TimeZeroSpan: ui->stackedWidget->setCurrentIndex(3); break;
default: break;
}
@ -129,6 +130,9 @@ void Math::Expression::expressionChanged()
case DataType::Power:
parser->DefineVar("P", Variable(&P));
break;
case DataType::TimeZeroSpan:
parser->DefineVar("t", Variable(&t));
break;
default:
break;
}

View File

@ -44,7 +44,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x: the S parameter as a (complex) voltage vector. &lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;f: measurement frequency in Hz&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;w: angular measurement frequency (w = 2πf)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples:&lt;br/&gt;Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x * sqrt(10)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;abs(x) &amp;lt; 1 ? x : exp(i*arg(x))&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x: the S parameter as a (complex) voltage ratio vector. &lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;f: measurement frequency in Hz&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;w: angular measurement frequency (w = 2πf)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples:&lt;br/&gt;Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x * sqrt(10)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;abs(x) &amp;lt; 1 ? x : exp(i*arg(x))&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -66,7 +66,7 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x: the S parameter as a (complex) voltage vector. &lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;P: power of the stimulus signal in dBm&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples:&lt;br/&gt;Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x * sqrt(10)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;abs(x) &amp;lt; 1 ? x : exp(i*arg(x))&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x: the S parameter as a (complex) voltage ratio vector. &lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;P: power of the stimulus signal in dBm&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples:&lt;br/&gt;Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x * sqrt(10)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;abs(x) &amp;lt; 1 ? x : exp(i*arg(x))&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -75,6 +75,17 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;x: the S parameter as a (complex) voltage ratio vector. &lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;t: time in seconds&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>

View File

@ -146,6 +146,8 @@ QString TraceMath::dataTypeToString(TraceMath::DataType type)
return "Power";
case DataType::Time:
return "Time";
case DataType::TimeZeroSpan:
return "Time (Zero Span)";
default:
return "Invalid";
}

View File

@ -228,6 +228,8 @@ QString Trace::fillFromCSV(CSV &csv, unsigned int parameter)
domain = DataType::Time;
} else if(csv.getHeader(0).compare("power", Qt::CaseInsensitive) == 0) {
domain = DataType::Power;
} else if(csv.getHeader(0).compare("time (zero span)", Qt::CaseInsensitive) == 0) {
domain = DataType::TimeZeroSpan;
} else {
domain = DataType::Frequency;
}

View File

@ -26,7 +26,7 @@ TraceCSVExport::TraceCSVExport(TraceModel &traceModel, QWidget *parent) :
if(traces.size() == 0) {
ui->listColumns->clear();
} else if(ui->listColumns->count() == 0) {
// first trace has bee selected, fill column selection
// first trace has been selected, fill column selection
auto t = traces.front();
auto domain = t->outputType();
auto Xaxis = XAxis::Type::Last;
@ -34,6 +34,7 @@ TraceCSVExport::TraceCSVExport(TraceModel &traceModel, QWidget *parent) :
case Trace::DataType::Frequency: Xaxis = XAxis::Type::Frequency; break;
case Trace::DataType::Power: Xaxis = XAxis::Type::Power; break;
case Trace::DataType::Time: Xaxis = XAxis::Type::Time; break;
case Trace::DataType::TimeZeroSpan: Xaxis = XAxis::Type::TimeZeroSpan; break;
}
if(Xaxis == XAxis::Type::Last) {
// invalid axis selection

View File

@ -351,7 +351,10 @@ QVariant MathModel::data(const QModelIndex &index, int role) const
return "Frequency";
case TraceMath::DataType::Power:
return "Power";
case TraceMath::DataType::TimeZeroSpan:
return "Time (Zero Span)";
case TraceMath::DataType::Invalid:
default:
return "Invalid";
}
}

View File

@ -47,11 +47,11 @@ protected:
void initializeTraceInfo();
std::vector<Trace*> activeTraces();
// changes the graph settings to make it possible to display a specific trace. The trace is not aded yet
virtual bool configureForTrace(Trace *t) { Q_UNUSED(t) return false; }; // default implementation fails for all traces
virtual bool configureForTrace(Trace *t) { Q_UNUSED(t) return false; } // default implementation fails for all traces
void contextMenuEvent(QContextMenuEvent *event) override;
void paintEvent(QPaintEvent *event) override;
virtual void updateContextMenu(){};
virtual void replot(){update();};
virtual void updateContextMenu(){}
virtual void replot(){update();}
virtual void draw(QPainter& p) = 0;
virtual bool supported(Trace *t) = 0;
std::map<Trace*, bool> traces;
@ -79,7 +79,7 @@ protected:
void dropEvent(QDropEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
virtual void traceDropped(Trace *t, QPoint position);
virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();};
virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();}
protected slots:
void newTraceAvailable(Trace *t);

View File

@ -49,6 +49,9 @@ void TraceWaterfall::enableTrace(Trace *t, bool enabled)
trace = t;
connect(t, &Trace::dataChanged, this, &TraceWaterfall::traceDataChanged);
} else {
if(trace) {
disconnect(trace, &Trace::dataChanged, this, &TraceWaterfall::traceDataChanged);
}
trace = nullptr;
}
@ -130,14 +133,18 @@ bool TraceWaterfall::configureForTrace(Trace *t)
xAxis.set(XAxis::Type::Frequency, false, true, 0, 1, 0.1);
yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0);
break;
case Trace::DataType::Time:
xAxis.set(XAxis::Type::Time, false, true, 0, 1, 0.1);
yAxis.set(YAxis::Type::ImpulseMag, false, true, 0, 1, 1.0);
break;
// case Trace::DataType::Time:
// xAxis.set(XAxis::Type::Time, false, true, 0, 1, 0.1);
// yAxis.set(YAxis::Type::ImpulseMag, false, true, 0, 1, 1.0);
// break;
case Trace::DataType::Power:
xAxis.set(XAxis::Type::Power, false, true, 0, 1, 0.1);
yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0);
break;
// case Trace::DataType::TimeZeroSpan:
// xAxis.set(XAxis::Type::Power, false, true, 0, 1, 0.1);
// yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0);
// break;
case Trace::DataType::Invalid:
// unable to add
return false;
@ -156,6 +163,8 @@ bool TraceWaterfall::domainMatch(Trace *t)
return t->outputType() == Trace::DataType::Time;
case XAxis::Type::Power:
return t->outputType() == Trace::DataType::Power;
case XAxis::Type::TimeZeroSpan:
return t->outputType() == Trace::DataType::TimeZeroSpan;
case XAxis::Type::Last:
return false;
}

View File

@ -12,12 +12,12 @@ class TraceWaterfall : public TracePlot
friend class WaterfallAxisDialog;
Q_OBJECT
public:
TraceWaterfall(TraceModel &model, QWidget *parent = 0);;
TraceWaterfall(TraceModel &model, QWidget *parent = 0);
virtual void enableTrace(Trace *t, bool enabled) override;
void replot() override;
virtual Type getType() override { return Type::Waterfall;};
virtual Type getType() override { return Type::Waterfall;}
void fromJSON(nlohmann::json j) override;
nlohmann::json toJSON() override;
@ -33,7 +33,7 @@ protected:
bool domainMatch(Trace *t);
virtual bool supported(Trace *t) override;
virtual QPoint markerToPixel(Marker *m) override { Q_UNUSED(m) return QPoint(0,0);};
virtual QPoint markerToPixel(Marker *m) override { Q_UNUSED(m) return QPoint(0,0);}
virtual double nearestTracePoint(Trace *t, QPoint pixel, double *distance = nullptr) override;
virtual QString mouseText(QPoint pos) override;

View File

@ -74,7 +74,7 @@ public:
void updateSpan(double min, double max) override;
void replot() override;
virtual Type getType() override { return Type::XYPlot;};
virtual Type getType() override { return Type::XYPlot;}
virtual nlohmann::json toJSON() override;
virtual void fromJSON(nlohmann::json j) override;

View File

@ -4,7 +4,7 @@
namespace Protocol {
static constexpr uint16_t Version = 10;
static constexpr uint16_t Version = 11;
#pragma pack(push, 1)