LibreVNA/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/matchingnetwork.h

115 lines
3.0 KiB
C
Raw Normal View History

2022-10-01 23:10:44 +08:00
#ifndef MATCHINGNETWORK_H
#define MATCHINGNETWORK_H
#include "CustomWidgets/siunitedit.h"
#include "deembeddingoption.h"
#include "Tools/parameters.h"
#include "savable.h"
#include "touchstone.h"
#include <QWidget>
#include <QLabel>
#include <vector>
class MatchingComponent : public QFrame, public Savable, public SCPINode
2022-10-01 23:10:44 +08:00
{
Q_OBJECT
public:
enum class Type {
SeriesR,
SeriesL,
SeriesC,
ParallelR,
ParallelL,
ParallelC,
DefinedThrough,
DefinedShunt,
2022-10-01 23:10:44 +08:00
// Add new matching components here, do not explicitly assign values and keep the Last entry at the last position
Last,
};
MatchingComponent(Type type);
~MatchingComponent();
ABCDparam parameters(double freq);
void setValue(double v);
static MatchingComponent* createFromName(QString name);
QString getName();
nlohmann::json toJSON() override;
void fromJSON(nlohmann::json j) override;
signals:
void valueChanged();
void deleted(MatchingComponent* m);
protected:
SIUnitEdit *eValue;
Touchstone *touchstone;
QLabel *touchstoneLabel;
private:
void mouseDoubleClickEvent(QMouseEvent *e) override;
void updateTouchstoneLabel();
static QString typeToName(Type type);
Type type;
void keyPressEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
QString oldStylesheet;
double value;
2022-10-01 23:10:44 +08:00
};
class MatchingNetwork : public DeembeddingOption
{
public:
MatchingNetwork();
~MatchingNetwork();
2022-10-01 23:10:44 +08:00
// DeembeddingOption interface
public:
2022-10-14 06:27:22 +08:00
std::set<unsigned int> getAffectedPorts() override;
2023-01-16 07:25:29 +08:00
void transformDatapoint(DeviceDriver::VNAMeasurement &p) override;
2022-10-01 23:10:44 +08:00
void edit() override;
Type getType() override {return Type::MatchingNetwork;}
nlohmann::json toJSON() override;
void fromJSON(nlohmann::json j) override;
void clearNetwork();
2022-10-01 23:10:44 +08:00
private:
static constexpr int imageHeight = 151;
static constexpr int componentWidth = 151;
static constexpr int DUTWidth = 151;
static constexpr int portWidth = 76;
MatchingComponent *componentAtPosition(int pos);
unsigned int findInsertPosition(int xcoord);
void addComponentAtPosition(int pos, MatchingComponent *c);
void addComponent(int index, MatchingComponent *c);
void removeComponent(int index);
void removeComponent(MatchingComponent *c);
2022-10-01 23:10:44 +08:00
void createDragComponent(MatchingComponent *c);
void updateInsertIndicator(int xcoord);
bool eventFilter(QObject *object, QEvent *event) override;
void updateSCPINames();
2022-10-01 23:10:44 +08:00
std::vector<MatchingComponent*> network;
2022-10-14 06:27:22 +08:00
unsigned int port;
2022-10-01 23:10:44 +08:00
QWidget *graph, *insertIndicator;
QPoint dragStartPosition;
MatchingComponent *dragComponent;
bool dropPending;
MatchingComponent *dropComponent;
class MatchingPoint {
public:
ABCDparam forward;
ABCDparam reverse;
2022-10-01 23:10:44 +08:00
};
std::map<double, MatchingPoint> matching;
bool addNetwork;
};
#endif // MATCHINGNETWORK_H