Merge branch 'master' into trace_math

This commit is contained in:
Jan Käberich 2020-11-28 13:56:30 +01:00
commit 163b23f28d
9 changed files with 135 additions and 31 deletions

View File

@ -621,6 +621,55 @@ std::vector<Trace *> Calibration::getErrorTermTraces()
return traces;
}
std::vector<Trace *> Calibration::getMeasurementTraces()
{
std::vector<Trace*> traces;
for(auto m : measurements) {
auto info = getMeasurementInfo(m.first);
if(info.points > 0) {
vector<QString> usedPrefixes;
switch(m.first) {
case Measurement::Port1Load:
case Measurement::Port1Open:
case Measurement::Port1Short:
usedPrefixes = {"S11"};
break;
case Measurement::Port2Load:
case Measurement::Port2Open:
case Measurement::Port2Short:
usedPrefixes = {"S22"};
break;
case Measurement::Through:
case Measurement::Line:
case Measurement::Isolation:
usedPrefixes = {"S11", "S12", "S21", "S22"};
break;
}
for(auto prefix : usedPrefixes) {
auto t = new Trace(prefix + " " + info.name);
t->setCalibration(true);
t->setReflection(prefix == "S11" || prefix == "S22");
for(auto p : m.second.datapoints) {
Trace::Data d;
d.frequency = p.frequency;
if(prefix == "S11") {
d.S = complex<double>(p.real_S11, p.imag_S11);
} else if(prefix == "S12") {
d.S = complex<double>(p.real_S12, p.imag_S12);
} else if(prefix == "S21") {
d.S = complex<double>(p.real_S21, p.imag_S21);
} else {
d.S = complex<double>(p.real_S22, p.imag_S22);
}
t->addData(d);
}
traces.push_back(t);
}
}
}
return traces;
}
bool Calibration::openFromFile(QString filename)
{
if(filename.isEmpty()) {

View File

@ -80,6 +80,7 @@ public:
}
std::vector<Trace*> getErrorTermTraces();
std::vector<Trace*> getMeasurementTraces();
bool openFromFile(QString filename = QString());
bool saveToFile(QString filename = QString());

View File

@ -32,7 +32,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -112,7 +112,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L0 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-12&lt;/span&gt;F]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L0 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-12&lt;/span&gt;H]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -122,7 +122,7 @@
<item row="4" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L1 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-24&lt;/span&gt;F/Hz]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L1 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-24&lt;/span&gt;H/Hz]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -132,7 +132,7 @@
<item row="5" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L2 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-33&lt;/span&gt;F/Hz&lt;span style=&quot; vertical-align:super;&quot;&gt;2&lt;/span&gt;]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L2 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-33&lt;/span&gt;H/Hz&lt;span style=&quot; vertical-align:super;&quot;&gt;2&lt;/span&gt;]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -142,7 +142,7 @@
<item row="6" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L3 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-42&lt;/span&gt;F/Hz&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt;]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;L3 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-42&lt;/span&gt;H/Hz&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt;]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -288,7 +288,7 @@
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>C0 [10&lt;sup&gt;-45&lt;/sup&gt;F/Hz&lt;sup&gt;3&lt;/sup&gt;]:</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;C3 [10&lt;span style=&quot; vertical-align:super;&quot;&gt;-45&lt;/span&gt;F/Hz&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt;]:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -845,17 +845,17 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SIUnitEdit</class>
<extends>QLineEdit</extends>
<header>CustomWidgets/siunitedit.h</header>
</customwidget>
<customwidget>
<class>TouchstoneImport</class>
<extends>QWidget</extends>
<header>CustomWidgets/touchstoneimport.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SIUnitEdit</class>
<extends>QLineEdit</extends>
<header>CustomWidgets/siunitedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>open_Z0</tabstop>
@ -933,10 +933,10 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="ThroughType"/>
<buttongroup name="TRL_Rtype"/>
<buttongroup name="LoadType"/>
<buttongroup name="ThroughType"/>
<buttongroup name="ShortType"/>
<buttongroup name="OpenType"/>
<buttongroup name="LoadType"/>
</buttongroups>
</ui>

View File

@ -0,0 +1,19 @@
<ui version="4.0" >
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -108,6 +108,8 @@ QVariant TraceModel::data(const QModelIndex &index, int role) const
} else {
return QIcon(":/icons/invisible.svg");
}
} else {
return QVariant();
}
break;
case ColIndexPlayPause:
@ -117,6 +119,8 @@ QVariant TraceModel::data(const QModelIndex &index, int role) const
} else {
return QIcon(":/icons/play.svg");
}
} else {
return QVariant();
}
break;
case ColIndexMath:

View File

@ -462,6 +462,7 @@ void TraceXYPlot::updateAxisTicks()
};
auto createAutomaticTicks = [](vector<double>& ticks, double start, double stop, int minDivisions) -> double {
Q_ASSERT(stop > start);
ticks.clear();
double max_div_step = (stop - start) / minDivisions;
int zeros = floor(log10(max_div_step));
@ -561,13 +562,28 @@ void TraceXYPlot::updateAxisTicks()
}
}
}
// add 5% overrange
auto range = max - min;
min -= range * 0.05;
max += range * 0.05;
YAxis[i].rangeMin = min;
YAxis[i].rangeMax = max;
YAxis[i].rangeDiv = createAutomaticTicks(YAxis[i].ticks, min, max, 8);
if(max >= min) {
auto range = max - min;
if(range == 0.0) {
// this could happen if all values in a trace are identical (e.g. imported ideal touchstone files)
if(max == 0.0) {
// simply use +/-1 range
max = 1.0;
min = -1.0;
} else {
// +/-5% around value
max += abs(max * 0.05);
min -= abs(max * 0.05);
}
} else {
// add 5% of range at both ends
min -= range * 0.05;
max += range * 0.05;
}
YAxis[i].rangeMin = min;
YAxis[i].rangeMax = max;
YAxis[i].rangeDiv = createAutomaticTicks(YAxis[i].ticks, min, max, 8);
}
}
}
}

View File

@ -47,8 +47,6 @@ XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) :
ui->Y2divs->setUnit(unit);
});
connect(ui->XType, qOverload<int>(&QComboBox::currentIndexChanged), this, &XYplotAxisDialog::XAxisTypeChanged);
connect(ui->Y2auto, &QCheckBox::toggled, [this](bool checked) {
ui->Y2min->setEnabled(!checked);
ui->Y2max->setEnabled(!checked);
@ -67,6 +65,9 @@ XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) :
ui->Xmax->setPrefixes("pnum kMG");
ui->Xdivs->setPrefixes("pnum kMG");
XAxisTypeChanged((int) plot->XAxis.type);
connect(ui->XType, qOverload<int>(&QComboBox::currentIndexChanged), this, &XYplotAxisDialog::XAxisTypeChanged);
// Fill initial values
// assume same order in YAxisType enum as in ComboBox items
ui->Y1type->setCurrentIndex((int) plot->YAxis[0].type);

View File

@ -445,6 +445,9 @@
</item>
<item>
<widget class="QComboBox" name="Xautomode">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Use Span</string>

View File

@ -119,13 +119,6 @@ VNA::VNA(AppWindow *window)
StartCalibrationDialog();
});
auto calImport = calMenu->addAction("Import error terms as traces");
calImport->setEnabled(false);
connect(calImport, &QAction::triggered, [=](){
auto import = new TraceImportDialog(traceModel, cal.getErrorTermTraces());
import->show();
});
auto calEditKit = calMenu->addAction("Edit Calibration Kit");
connect(calEditKit, &QAction::triggered, [=](){
cal.getCalibrationKit().edit([=](){
@ -134,6 +127,22 @@ VNA::VNA(AppWindow *window)
}
});
});
calMenu->addSeparator();
auto calImportTerms = calMenu->addAction("Import error terms as traces");
calImportTerms->setEnabled(false);
connect(calImportTerms, &QAction::triggered, [=](){
auto import = new TraceImportDialog(traceModel, cal.getErrorTermTraces());
import->show();
});
auto calImportMeas = calMenu->addAction("Import measurements as traces");
calImportMeas->setEnabled(false);
connect(calImportMeas, &QAction::triggered, [=](){
auto import = new TraceImportDialog(traceModel, cal.getMeasurementTraces());
import->show();
});
portExtension.setCalkit(&cal.getCalibrationKit());
// Tools menu
@ -319,7 +328,8 @@ VNA::VNA(AppWindow *window)
cbEnableCal->setCheckState(Qt::CheckState::Unchecked);
cbType->blockSignals(false);
cbEnableCal->blockSignals(false);
calImport->setEnabled(false);
calImportTerms->setEnabled(false);
calImportMeas->setEnabled(false);
saveCal->setEnabled(false);
});
connect(calDisable, &QAction::triggered, this, &VNA::DisableCalibration);
@ -335,7 +345,8 @@ VNA::VNA(AppWindow *window)
cbEnableCal->setCheckState(Qt::CheckState::Checked);
cbType->blockSignals(false);
cbEnableCal->blockSignals(false);
calImport->setEnabled(true);
calImportTerms->setEnabled(true);
calImportMeas->setEnabled(true);
saveCal->setEnabled(true);
});