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

102 lines
2.7 KiB
C
Raw Normal View History

#ifndef MATCHINGNETWORK_H
#define MATCHINGNETWORK_H
2021-10-21 19:00:34 +08:00
#include "CustomWidgets/siunitedit.h"
#include "deembeddingoption.h"
#include "Tools/parameters.h"
#include "savable.h"
2021-11-28 02:11:45 +08:00
#include "touchstone.h"
2021-10-21 19:00:34 +08:00
#include <QWidget>
2021-11-28 02:11:45 +08:00
#include <QLabel>
2021-10-21 19:00:34 +08:00
#include <vector>
class MatchingComponent : public QFrame, public Savable
{
Q_OBJECT
public:
enum class Type {
SeriesR,
SeriesL,
SeriesC,
ParallelR,
ParallelL,
ParallelC,
2021-11-28 02:11:45 +08:00
DefinedThrough,
// Add new matching components here, do not explicitly assign values and keep the Last entry at the last position
Last,
};
MatchingComponent(Type type);
2021-11-28 02:11:45 +08:00
~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;
2021-11-28 02:11:45 +08:00
Touchstone *touchstone;
QLabel *touchstoneLabel;
private:
2021-11-28 02:11:45 +08:00
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;
};
class MatchingNetwork : public DeembeddingOption
{
public:
MatchingNetwork();
// DeembeddingOption interface
public:
void transformDatapoint(VNAData &p) override;
void edit() override;
Type getType() override {return Type::MatchingNetwork;}
nlohmann::json toJSON() override;
void fromJSON(nlohmann::json j) override;
private:
2021-11-28 02:11:45 +08:00
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(bool port1, int index, MatchingComponent *c);
void createDragComponent(MatchingComponent *c);
void updateInsertIndicator(int xcoord);
bool eventFilter(QObject *object, QEvent *event) override;
std::vector<MatchingComponent*> p1Network, p2Network;
QWidget *graph, *insertIndicator;
QPoint dragStartPosition;
MatchingComponent *dragComponent;
bool dropPending;
MatchingComponent *dropComponent;
class MatchingPoint {
public:
ABCDparam p1, p2;
};
std::map<double, MatchingPoint> matching;
bool addNetwork;
};
#endif // MATCHINGNETWORK_H