WIP: calibration measurement GUI widgets
This commit is contained in:
parent
6e38aaddb8
commit
5c1180e443
@ -3,6 +3,9 @@
|
|||||||
#include "calibration2.h"
|
#include "calibration2.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -13,23 +16,33 @@ CalibrationMeasurement::Base::Base(Calibration2 *cal)
|
|||||||
timestamp = QDateTime();
|
timestamp = QDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CalStandard::Virtual *> CalibrationMeasurement::Base::supportedStandards()
|
||||||
|
{
|
||||||
|
vector<CalStandard::Virtual*> ret;
|
||||||
|
for(auto s : cal->getKit().getStandards()) {
|
||||||
|
if(supportedStandardTypes().count(s->getType())) {
|
||||||
|
ret.push_back(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool CalibrationMeasurement::Base::setFirstSupportedStandard()
|
bool CalibrationMeasurement::Base::setFirstSupportedStandard()
|
||||||
{
|
{
|
||||||
// assign first valid standard
|
// assign first valid standard
|
||||||
for(auto s : cal->getKit().getStandards()) {
|
auto supported = supportedStandards();
|
||||||
if(supportedStandards().count(s->getType())) {
|
if(supported.size() > 0) {
|
||||||
setStandard(s);
|
setStandard(supported[0]);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CalibrationMeasurement::Base::setStandard(CalStandard::Virtual *standard)
|
bool CalibrationMeasurement::Base::setStandard(CalStandard::Virtual *standard)
|
||||||
{
|
{
|
||||||
if(standard) {
|
if(standard) {
|
||||||
if(supportedStandards().count(standard->getType())) {
|
if(supportedStandardTypes().count(standard->getType())) {
|
||||||
// can use this standard
|
// can use this standard
|
||||||
this->standard = standard;
|
this->standard = standard;
|
||||||
|
emit standardChanged(standard);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// can't use this standard, leave unchanged
|
// can't use this standard, leave unchanged
|
||||||
@ -38,6 +51,7 @@ bool CalibrationMeasurement::Base::setStandard(CalStandard::Virtual *standard)
|
|||||||
} else {
|
} else {
|
||||||
// nullptr passed, remove currently used standard
|
// nullptr passed, remove currently used standard
|
||||||
this->standard = nullptr;
|
this->standard = nullptr;
|
||||||
|
emit standardChanged(nullptr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,6 +100,30 @@ CalibrationMeasurement::Base::Type CalibrationMeasurement::Base::TypeFromString(
|
|||||||
return Type::Last;
|
return Type::Last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *CalibrationMeasurement::Base::createStandardWidget()
|
||||||
|
{
|
||||||
|
auto cbStandard = new QComboBox();
|
||||||
|
for(auto s : supportedStandards()) {
|
||||||
|
cbStandard->addItem(s->getDescription(), qVariantFromValue((void*) s));
|
||||||
|
if(standard == s) {
|
||||||
|
cbStandard->setCurrentText(s->getDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(cbStandard, qOverload<int>(&QComboBox::currentIndexChanged), [=](){
|
||||||
|
auto s = (CalStandard::Virtual*) cbStandard->itemData(cbStandard->currentIndex(), Qt::UserRole).value<void*>();
|
||||||
|
setStandard(s);
|
||||||
|
});
|
||||||
|
connect(this, &CalibrationMeasurement::Base::standardChanged, [=](){
|
||||||
|
for(int i=0;i<cbStandard->count();i++) {
|
||||||
|
if((CalStandard::Virtual*) cbStandard->itemData(i, Qt::UserRole).value<void*>() == standard) {
|
||||||
|
cbStandard->setCurrentIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cbStandard;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json CalibrationMeasurement::Base::toJSON()
|
nlohmann::json CalibrationMeasurement::Base::toJSON()
|
||||||
{
|
{
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
@ -171,6 +209,37 @@ void CalibrationMeasurement::OnePort::addPoint(const VirtualDevice::VNAMeasureme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *CalibrationMeasurement::OnePort::createSettingsWidget()
|
||||||
|
{
|
||||||
|
auto label = new QLabel("Port:");
|
||||||
|
auto cbPort = new QComboBox();
|
||||||
|
auto dev = VirtualDevice::getConnected();
|
||||||
|
if(dev) {
|
||||||
|
for(int i=1;i<=dev->getInfo().ports;i++) {
|
||||||
|
cbPort->addItem(QString::number(i));
|
||||||
|
if(port == i) {
|
||||||
|
cbPort->setCurrentText(QString::number(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connect(cbPort, qOverload<int>(&QComboBox::currentIndexChanged), [=](){
|
||||||
|
setPort(cbPort->currentText().toInt());
|
||||||
|
});
|
||||||
|
connect(this, &OnePort::portChanged, [=](){
|
||||||
|
auto string = QString::number(port);
|
||||||
|
if(cbPort->findText(string) < 0) {
|
||||||
|
// setting does not exist yet, create (should not happen)
|
||||||
|
cbPort->addItem(string);
|
||||||
|
}
|
||||||
|
cbPort->setCurrentText(string);
|
||||||
|
});
|
||||||
|
auto ret = new QWidget();
|
||||||
|
ret->setLayout(new QHBoxLayout);
|
||||||
|
ret->layout()->addWidget(label);
|
||||||
|
ret->layout()->addWidget(cbPort);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json CalibrationMeasurement::OnePort::toJSON()
|
nlohmann::json CalibrationMeasurement::OnePort::toJSON()
|
||||||
{
|
{
|
||||||
auto j = Base::toJSON();
|
auto j = Base::toJSON();
|
||||||
@ -229,6 +298,14 @@ int CalibrationMeasurement::OnePort::getPort() const
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CalibrationMeasurement::OnePort::setPort(int p)
|
||||||
|
{
|
||||||
|
if(port != p) {
|
||||||
|
port = p;
|
||||||
|
emit portChanged(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double CalibrationMeasurement::TwoPort::minFreq()
|
double CalibrationMeasurement::TwoPort::minFreq()
|
||||||
{
|
{
|
||||||
if(points.size() > 0) {
|
if(points.size() > 0) {
|
||||||
@ -262,6 +339,56 @@ void CalibrationMeasurement::TwoPort::addPoint(const VirtualDevice::VNAMeasureme
|
|||||||
timestamp = QDateTime::currentDateTimeUtc();
|
timestamp = QDateTime::currentDateTimeUtc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *CalibrationMeasurement::TwoPort::createSettingsWidget()
|
||||||
|
{
|
||||||
|
auto label1 = new QLabel("From port ");
|
||||||
|
auto cbPort1 = new QComboBox();
|
||||||
|
auto label2 = new QLabel(" to port ");
|
||||||
|
auto cbPort2 = new QComboBox();
|
||||||
|
auto dev = VirtualDevice::getConnected();
|
||||||
|
if(dev) {
|
||||||
|
for(int i=1;i<=dev->getInfo().ports;i++) {
|
||||||
|
cbPort1->addItem(QString::number(i));
|
||||||
|
cbPort2->addItem(QString::number(i));
|
||||||
|
if(port1 == i) {
|
||||||
|
cbPort1->setCurrentText(QString::number(i));
|
||||||
|
}
|
||||||
|
if(port2 == i) {
|
||||||
|
cbPort2->setCurrentText(QString::number(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connect(cbPort1, qOverload<int>(&QComboBox::currentIndexChanged), [=](){
|
||||||
|
setPort1(cbPort1->currentText().toInt());
|
||||||
|
});
|
||||||
|
connect(cbPort2, qOverload<int>(&QComboBox::currentIndexChanged), [=](){
|
||||||
|
setPort2(cbPort2->currentText().toInt());
|
||||||
|
});
|
||||||
|
connect(this, &TwoPort::port1Changed, [=](){
|
||||||
|
auto string = QString::number(port1);
|
||||||
|
if(cbPort1->findText(string) < 0) {
|
||||||
|
// setting does not exist yet, create (should not happen)
|
||||||
|
cbPort1->addItem(string);
|
||||||
|
}
|
||||||
|
cbPort1->setCurrentText(string);
|
||||||
|
});
|
||||||
|
connect(this, &TwoPort::port2Changed, [=](){
|
||||||
|
auto string = QString::number(port2);
|
||||||
|
if(cbPort2->findText(string) < 0) {
|
||||||
|
// setting does not exist yet, create (should not happen)
|
||||||
|
cbPort2->addItem(string);
|
||||||
|
}
|
||||||
|
cbPort2->setCurrentText(string);
|
||||||
|
});
|
||||||
|
auto ret = new QWidget();
|
||||||
|
ret->setLayout(new QHBoxLayout);
|
||||||
|
ret->layout()->addWidget(label1);
|
||||||
|
ret->layout()->addWidget(cbPort1);
|
||||||
|
ret->layout()->addWidget(label2);
|
||||||
|
ret->layout()->addWidget(cbPort2);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json CalibrationMeasurement::TwoPort::toJSON()
|
nlohmann::json CalibrationMeasurement::TwoPort::toJSON()
|
||||||
{
|
{
|
||||||
auto j = Base::toJSON();
|
auto j = Base::toJSON();
|
||||||
@ -325,6 +452,22 @@ int CalibrationMeasurement::TwoPort::getPort2() const
|
|||||||
return port2;
|
return port2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CalibrationMeasurement::TwoPort::setPort1(int p)
|
||||||
|
{
|
||||||
|
if(port1 = p) {
|
||||||
|
port1 = p;
|
||||||
|
emit port1Changed(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CalibrationMeasurement::TwoPort::setPort2(int p)
|
||||||
|
{
|
||||||
|
if(port1 = p) {
|
||||||
|
port1 = p;
|
||||||
|
emit port1Changed(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CalibrationMeasurement::TwoPort::getPort1() const
|
int CalibrationMeasurement::TwoPort::getPort1() const
|
||||||
{
|
{
|
||||||
return port1;
|
return port1;
|
||||||
|
@ -5,13 +5,15 @@
|
|||||||
#include "Device/virtualdevice.h"
|
#include "Device/virtualdevice.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class Calibration2;
|
class Calibration2;
|
||||||
|
|
||||||
namespace CalibrationMeasurement {
|
namespace CalibrationMeasurement {
|
||||||
|
|
||||||
class Base : public Savable
|
class Base : public QObject, public Savable
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Base(Calibration2 *cal);
|
Base(Calibration2 *cal);
|
||||||
|
|
||||||
@ -23,6 +25,7 @@ public:
|
|||||||
Last,
|
Last,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<CalStandard::Virtual*> supportedStandards();
|
||||||
bool setFirstSupportedStandard();
|
bool setFirstSupportedStandard();
|
||||||
bool setStandard(CalStandard::Virtual *standard);
|
bool setStandard(CalStandard::Virtual *standard);
|
||||||
|
|
||||||
@ -35,15 +38,22 @@ public:
|
|||||||
static std::vector<Type> availableTypes();
|
static std::vector<Type> availableTypes();
|
||||||
static QString TypeToString(Type type);
|
static QString TypeToString(Type type);
|
||||||
static Type TypeFromString(QString s);
|
static Type TypeFromString(QString s);
|
||||||
virtual std::set<CalStandard::Virtual::Type> supportedStandards() = 0;
|
virtual std::set<CalStandard::Virtual::Type> supportedStandardTypes() = 0;
|
||||||
virtual Type getType() = 0;
|
virtual Type getType() = 0;
|
||||||
|
|
||||||
virtual void clearPoints() = 0;
|
virtual void clearPoints() = 0;
|
||||||
virtual void addPoint(const VirtualDevice::VNAMeasurement &m) = 0;
|
virtual void addPoint(const VirtualDevice::VNAMeasurement &m) = 0;
|
||||||
|
|
||||||
|
virtual QWidget* createStandardWidget();
|
||||||
|
virtual QWidget* createSettingsWidget() = 0;
|
||||||
|
|
||||||
virtual nlohmann::json toJSON() override;
|
virtual nlohmann::json toJSON() override;
|
||||||
virtual void fromJSON(nlohmann::json j) override;
|
virtual void fromJSON(nlohmann::json j) override;
|
||||||
|
|
||||||
static bool canMeasureSimultaneously(std::vector<Base*> measurements);
|
static bool canMeasureSimultaneously(std::vector<Base*> measurements);
|
||||||
|
protected:
|
||||||
|
signals:
|
||||||
|
void standardChanged(CalStandard::Virtual* newStandard);
|
||||||
protected:
|
protected:
|
||||||
CalStandard::Virtual *standard;
|
CalStandard::Virtual *standard;
|
||||||
QDateTime timestamp;
|
QDateTime timestamp;
|
||||||
@ -52,6 +62,7 @@ protected:
|
|||||||
|
|
||||||
class OnePort : public Base
|
class OnePort : public Base
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
OnePort(Calibration2 *cal) :
|
OnePort(Calibration2 *cal) :
|
||||||
Base(cal),
|
Base(cal),
|
||||||
@ -64,6 +75,8 @@ public:
|
|||||||
virtual void clearPoints();
|
virtual void clearPoints();
|
||||||
virtual void addPoint(const VirtualDevice::VNAMeasurement &m);
|
virtual void addPoint(const VirtualDevice::VNAMeasurement &m);
|
||||||
|
|
||||||
|
virtual QWidget* createSettingsWidget() override;
|
||||||
|
|
||||||
virtual nlohmann::json toJSON() override;
|
virtual nlohmann::json toJSON() override;
|
||||||
virtual void fromJSON(nlohmann::json j) override;
|
virtual void fromJSON(nlohmann::json j) override;
|
||||||
|
|
||||||
@ -72,6 +85,11 @@ public:
|
|||||||
|
|
||||||
int getPort() const;
|
int getPort() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
int setPort(int p);
|
||||||
|
protected:
|
||||||
|
signals:
|
||||||
|
void portChanged(int p);
|
||||||
protected:
|
protected:
|
||||||
int port;
|
int port;
|
||||||
class Point {
|
class Point {
|
||||||
@ -84,34 +102,38 @@ protected:
|
|||||||
|
|
||||||
class Open : public OnePort
|
class Open : public OnePort
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Open(Calibration2 *cal) :
|
Open(Calibration2 *cal) :
|
||||||
OnePort(cal){setFirstSupportedStandard();}
|
OnePort(cal){setFirstSupportedStandard();}
|
||||||
|
|
||||||
virtual std::set<CalStandard::Virtual::Type> supportedStandards() override {return {CalStandard::Virtual::Type::Open};}
|
virtual std::set<CalStandard::Virtual::Type> supportedStandardTypes() override {return {CalStandard::Virtual::Type::Open};}
|
||||||
virtual Type getType() override {return Type::Open;}
|
virtual Type getType() override {return Type::Open;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Short : public OnePort
|
class Short : public OnePort
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Short(Calibration2 *cal) :
|
Short(Calibration2 *cal) :
|
||||||
OnePort(cal){setFirstSupportedStandard();}
|
OnePort(cal){setFirstSupportedStandard();}
|
||||||
virtual std::set<CalStandard::Virtual::Type> supportedStandards() override {return {CalStandard::Virtual::Type::Short};}
|
virtual std::set<CalStandard::Virtual::Type> supportedStandardTypes() override {return {CalStandard::Virtual::Type::Short};}
|
||||||
virtual Type getType() override {return Type::Short;}
|
virtual Type getType() override {return Type::Short;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Load : public OnePort
|
class Load : public OnePort
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Load(Calibration2 *cal) :
|
Load(Calibration2 *cal) :
|
||||||
OnePort(cal){setFirstSupportedStandard();}
|
OnePort(cal){setFirstSupportedStandard();}
|
||||||
virtual std::set<CalStandard::Virtual::Type> supportedStandards() override {return {CalStandard::Virtual::Type::Load};}
|
virtual std::set<CalStandard::Virtual::Type> supportedStandardTypes() override {return {CalStandard::Virtual::Type::Load};}
|
||||||
virtual Type getType() override {return Type::Load;}
|
virtual Type getType() override {return Type::Load;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class TwoPort : public Base
|
class TwoPort : public Base
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TwoPort(Calibration2 *cal) :
|
TwoPort(Calibration2 *cal) :
|
||||||
Base(cal),
|
Base(cal),
|
||||||
@ -125,6 +147,8 @@ public:
|
|||||||
virtual void clearPoints();
|
virtual void clearPoints();
|
||||||
virtual void addPoint(const VirtualDevice::VNAMeasurement &m);
|
virtual void addPoint(const VirtualDevice::VNAMeasurement &m);
|
||||||
|
|
||||||
|
virtual QWidget* createSettingsWidget() override;
|
||||||
|
|
||||||
virtual nlohmann::json toJSON() override;
|
virtual nlohmann::json toJSON() override;
|
||||||
virtual void fromJSON(nlohmann::json j) override;
|
virtual void fromJSON(nlohmann::json j) override;
|
||||||
|
|
||||||
@ -134,6 +158,13 @@ public:
|
|||||||
int getPort1() const;
|
int getPort1() const;
|
||||||
int getPort2() const;
|
int getPort2() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
int setPort1(int p);
|
||||||
|
int setPort2(int p);
|
||||||
|
protected:
|
||||||
|
signals:
|
||||||
|
void port1Changed(int p);
|
||||||
|
void port2Changed(int p);
|
||||||
protected:
|
protected:
|
||||||
int port1, port2;
|
int port1, port2;
|
||||||
class Point {
|
class Point {
|
||||||
@ -146,10 +177,11 @@ protected:
|
|||||||
|
|
||||||
class Through : public TwoPort
|
class Through : public TwoPort
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Through(Calibration2 *cal) :
|
Through(Calibration2 *cal) :
|
||||||
TwoPort(cal){setFirstSupportedStandard();}
|
TwoPort(cal){setFirstSupportedStandard();}
|
||||||
virtual std::set<CalStandard::Virtual::Type> supportedStandards() override {return {CalStandard::Virtual::Type::Through};}
|
virtual std::set<CalStandard::Virtual::Type> supportedStandardTypes() override {return {CalStandard::Virtual::Type::Through};}
|
||||||
virtual Type getType() override {return Type::Through;}
|
virtual Type getType() override {return Type::Through;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user