diff --git a/Software/PC_Application/LibreVNA-GUI/Calibration/manualcalibrationdialog.ui b/Software/PC_Application/LibreVNA-GUI/Calibration/manualcalibrationdialog.ui
index 8eaf18f..644eb66 100644
--- a/Software/PC_Application/LibreVNA-GUI/Calibration/manualcalibrationdialog.ui
+++ b/Software/PC_Application/LibreVNA-GUI/Calibration/manualcalibrationdialog.ui
@@ -7,11 +7,11 @@
0
0
597
- 200
+ 331
- Dialog
+ Manual Calibration
true
diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.cpp
index 5dbf75d..572d6ff 100644
--- a/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.cpp
+++ b/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.cpp
@@ -2,21 +2,27 @@
#include
#include
+#include
+#include
+#include
+#include
using namespace std;
-SparamTraceSelector::SparamTraceSelector(const TraceModel &model, std::vector used_ports, bool empty_allowed)
+SparamTraceSelector::SparamTraceSelector(const TraceModel &model, std::vector used_ports, bool empty_allowed, unsigned int editablePorts)
: model(model),
empty_allowed(empty_allowed),
- used_ports(used_ports)
+ used_ports(used_ports),
+ editablePorts(editablePorts)
{
createGUI();
setInitialChoices();
}
-SparamTraceSelector::SparamTraceSelector(const TraceModel &model, std::set used_ports, bool empty_allowed)
+SparamTraceSelector::SparamTraceSelector(const TraceModel &model, std::set used_ports, bool empty_allowed, unsigned int editablePorts)
: model(model),
- empty_allowed(empty_allowed)
+ empty_allowed(empty_allowed),
+ editablePorts(editablePorts)
{
// create vector from set
std::copy(used_ports.begin(), used_ports.end(), std::back_inserter(this->used_ports));
@@ -113,7 +119,9 @@ void SparamTraceSelector::traceSelectionChanged(QComboBox *cb)
for(int j=0;jcount();j++) {
auto candidate = b->itemText(j);
// check if correct parameter
- QString expectedSparam = QString::number(i/used_ports.size()+1)+QString::number(i%used_ports.size()+1);
+ int port1 = used_ports[i/used_ports.size()];
+ int port2 = used_ports[i%used_ports.size()];
+ QString expectedSparam = QString::number(port1)+QString::number(port2);
if(!candidate.endsWith(expectedSparam)) {
// wrong S parameter, skip
continue;
@@ -131,7 +139,9 @@ void SparamTraceSelector::traceSelectionChanged(QComboBox *cb)
}
} else if(cb->currentIndex() == 0 && points > 0) {
- emit selectionValid(false);
+ if(!empty_allowed) {
+ emit selectionValid(false);
+ }
// Check if all trace selections are set for none
for(auto c : boxes) {
if(!c->isVisible()) {
@@ -150,8 +160,8 @@ void SparamTraceSelector::traceSelectionChanged(QComboBox *cb)
setInitialChoices();
}
if(empty_allowed) {
- // always valid
- emit selectionValid(true);
+ // always valid as soon as at least one trace is selected
+ emit selectionValid(points > 0);
} else {
// actually need to check
valid = true;
@@ -172,8 +182,44 @@ void SparamTraceSelector::traceSelectionChanged(QComboBox *cb)
void SparamTraceSelector::createGUI()
{
// Create comboboxes
- auto layout = new QFormLayout;
- setLayout(layout);
+ qDeleteAll(findChildren(QString(), Qt::FindDirectChildrenOnly));
+ delete layout();
+ boxes.clear();
+
+ auto scroll = new QScrollArea(this);
+ scroll->installEventFilter(this);
+ scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ auto w = new QWidget();
+
+ auto boxlayout = new QVBoxLayout();
+ setLayout(boxlayout);
+ boxlayout->setContentsMargins(0,0,0,0);
+ boxlayout->addWidget(scroll);
+
+ auto formlayout = new QFormLayout;
+ w->setLayout(formlayout);
+
+ for(unsigned int i=1;i<=editablePorts;i++) {
+ auto label = new QLabel("Include Port "+QString::number(i)+":");
+ auto cb = new QCheckBox();
+ if(std::find(used_ports.begin(), used_ports.end(), i) != used_ports.end()) {
+ cb->setChecked(true);
+ }
+ connect(cb, &QCheckBox::toggled, [=](bool checked){
+ if(checked) {
+ // add this port to the vector at the correct position
+ used_ports.insert(upper_bound(used_ports.begin(), used_ports.end(), i), i);
+ } else {
+ // remove port from the vector
+ used_ports.erase(std::remove(used_ports.begin(), used_ports.end(), i), used_ports.end());
+ }
+ QTimer::singleShot(0, [=](){
+ createGUI();
+ setInitialChoices();
+ });
+ });
+ formlayout->addRow(label, cb);
+ }
for(unsigned int i=0;iaddRow(label, box);
+ formlayout->addRow(label, box);
}
}
+
+ scroll->setWidget(w);
+ w->show();
+ eventFilter(scroll, new QEvent(QEvent::Resize));
+}
+
+bool SparamTraceSelector::eventFilter(QObject *watched, QEvent *event)
+{
+ // Make sure that the widget in the scroll area always expands to the scroll area size horizontally (only vertical scrolling)
+ if(event->type() == QEvent::Resize) {
+ auto scroll = (QScrollArea*) watched;
+ auto w = scroll->widget();
+ auto width = scroll->width();
+ if(scroll->verticalScrollBar()->isVisible()) {
+ width -= scroll->verticalScrollBar()->width();
+ }
+ w->setFixedWidth(width);
+ }
+ return false;
}
diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.h b/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.h
index f04b403..dd6a559 100644
--- a/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.h
+++ b/Software/PC_Application/LibreVNA-GUI/Traces/sparamtraceselector.h
@@ -13,8 +13,8 @@ class SparamTraceSelector : public QWidget
Q_OBJECT
public:
- SparamTraceSelector(const TraceModel &model, std::vector used_ports, bool empty_allowed = false);
- SparamTraceSelector(const TraceModel &model, std::set used_ports, bool empty_allowed = false);
+ SparamTraceSelector(const TraceModel &model, std::vector used_ports, bool empty_allowed = false, unsigned int editablePorts = 0);
+ SparamTraceSelector(const TraceModel &model, std::set used_ports, bool empty_allowed = false, unsigned int editablePorts = 0);
bool isValid();
@@ -29,11 +29,14 @@ private:
void traceSelectionChanged(QComboBox *cb);
void createGUI();
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
const TraceModel &model;
std::vector boxes;
bool empty_allowed;
std::vector used_ports;
+ unsigned int editablePorts;
unsigned int points;
double minFreq, maxFreq;
bool valid;
diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp
index e9fdcae..0de47df 100644
--- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp
+++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp
@@ -979,6 +979,7 @@ std::vector Trace::assembleDatapoints(std::mapsetupUi(this);
- auto traceSelector = new SparamTraceSelector(model, deemb->getAffectedPorts());
+ auto traceSelector = new SparamTraceSelector(model, deemb->getAffectedPorts(), true, 8);
ui->verticalLayout->insertWidget(1, traceSelector, 1.0);
ui->buttonBox->setEnabled(false);
connect(traceSelector, &SparamTraceSelector::selectionValid, ui->buttonBox, &QDialogButtonBox::setEnabled);
diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/manualdeembeddingdialog.ui b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/manualdeembeddingdialog.ui
index 8f342e4..02f6014 100644
--- a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/manualdeembeddingdialog.ui
+++ b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/manualdeembeddingdialog.ui
@@ -6,12 +6,12 @@
0
0
- 508
- 168
+ 522
+ 371
- Dialog
+ Manual De-embedding
true
diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetwork.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetwork.cpp
index cbc0b0a..3026fd1 100644
--- a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetwork.cpp
+++ b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetwork.cpp
@@ -51,25 +51,33 @@ void MatchingNetwork::transformDatapoint(VirtualDevice::VNAMeasurement &p)
// at this point the map contains the matching network effect
auto m = matching[p.frequency];
VirtualDevice::VNAMeasurement uncorrected = p;
- // correct reflection measurement (in case no two-port measurement is complete
- QString name = "S"+QString::number(port)+QString::number(port);
- if(uncorrected.measurements.count(name) > 0) {
- auto S = Sparam(uncorrected.measurements[name], 0.0, 0.0, 1.0);
- auto corrected = Sparam(m.p * ABCDparam(S, p.Z0), p.Z0);
- p.measurements[name] = corrected.m11;
- }
- // handle the rest of the measurements
- for(unsigned int i=1;i<=VirtualDevice::getInfo(VirtualDevice::getConnected()).ports;i++) {
- for(unsigned int j=i+1;j<=VirtualDevice::getInfo(VirtualDevice::getConnected()).ports;j++) {
+ // handle the measurements
+ for(auto &meas : p.measurements) {
+ QString name = meas.first;
+ unsigned int i = name.mid(1,1).toUInt();
+ unsigned int j = name.mid(2,1).toUInt();
+ if(i == j) {
+ // reflection measurement
if(i == port) {
- auto S = uncorrected.toSparam(i, j);
+ // the port of the matching network itself
+ auto S = Sparam(uncorrected.measurements[name], 1.0, 1.0, 0.0);
auto corrected = Sparam(m.p * ABCDparam(S, p.Z0), p.Z0);
- p.fromSparam(corrected, i, j);
- } else if(j == port) {
- auto S = uncorrected.toSparam(i, j);
- auto corrected = Sparam(ABCDparam(S, p.Z0) * m.p, p.Z0);
- p.fromSparam(corrected, i, j);
+ p.measurements[name] = corrected.m11;
+ } else {
+ // another reflection measurement
+ try {
+ auto S = uncorrected.toSparam(i, port);
+ auto corrected = Sparam(ABCDparam(S, p.Z0) * m.p, p.Z0);
+ p.fromSparam(corrected, i, port);
+ } catch (...) {
+ // missing measurements, nothing can be done
+ }
}
+ } else {
+ // through measurement
+ // Already handled by reflection measurement (toSparam uses S12/S21 as well)
+ // and if the corresponding reflection measurement is not available, we can't
+ // do anything anyway
}
}
}
@@ -230,9 +238,11 @@ void MatchingNetwork::addComponentAtPosition(int pos, MatchingComponent *c)
void MatchingNetwork::addComponent(int index, MatchingComponent *c)
{
network.insert(network.begin() + index, c);
+ matching.clear();
// remove from list when the component deletes itself
connect(c, &MatchingComponent::deleted, [=](){
network.erase(remove(network.begin(), network.end(), c), network.end());
+ matching.clear();
});
}
diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetworkdialog.ui b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetworkdialog.ui
index 5b9a10a..ee9eb7e 100644
--- a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetworkdialog.ui
+++ b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetworkdialog.ui
@@ -6,8 +6,8 @@
0
0
- 913
- 633
+ 902
+ 492
@@ -79,7 +79,7 @@
0
0
- 891
+ 880
168