Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
LoadSpecificationWidget.h
1/*
2 * Copyright (C) 2019-2025 Andrés Martínez Mera - andresmmera@protonmail.com
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef LOADSPECIFICATIONWIDGET_H
19#define LOADSPECIFICATIONWIDGET_H
20
21#include <QButtonGroup>
22#include <QCheckBox>
23#include <QComboBox>
24#include <QDoubleSpinBox>
25#include <QFileDialog>
26#include <QFileInfo>
27#include <QGridLayout>
28#include <QGroupBox>
29#include <QHBoxLayout>
30#include <QLabel>
31#include <QMessageBox>
32#include <QMouseEvent>
33#include <QPushButton>
34#include <QRadioButton>
35#include <QTextStream>
36#include <QVBoxLayout>
37#include <QWidget>
38#include <cmath>
39#include <complex>
40
41#include "../../Misc/general.h"
42
43class LoadSpecificationWidget : public QGroupBox {
44 Q_OBJECT
45
46public:
47 explicit LoadSpecificationWidget(QWidget* parent = nullptr);
49
50 // Getters
51 std::array<std::complex<double>, 4> getSParameters() const;
52 std::complex<double> getLoadImpedance_At_Fmatch() const;
53 QList<std::complex<double>> getZLdata();
54 QList<double> getFrequency();
55 std::pair<std::complex<double>, std::complex<double>>
56 getTwoPortMatchingImpedances() const;
57 std::complex<double> getReflectionCoefficient() const;
58 QString getSparFilePath();
59 bool isTwoPortMode() const { return m_twoPortMode; }
60
61 // S-parameter getters (for two-port mode)
62 std::complex<double> getS11() const;
63 std::complex<double> getS12() const;
64 std::complex<double> getS21() const;
65 std::complex<double> getS22() const;
66
67 // Setters
68 void setLoadImpedance(const std::complex<double>& impedance);
69 void setReflectionCoefficient(const std::complex<double>& gamma);
70 void setTwoPortMode(bool enabled);
71 void setReferenceImpedance(double Z0) {
72 m_Z0 = Z0;
73 updateReflectionCoefficient();
74 }
75 void setCollapsed(bool collapsed);
76 void setFmatch(double freq) { f_match = freq; }
77 bool isCollapsed() const { return m_isCollapsed; }
78
79 // Reference impedance of the source and the load port. Required for the
80 // 2-port matching. This data is provided by the main widget
81 double Z0_Port1, Z0_Port2;
82
83protected:
84 void mousePressEvent(QMouseEvent* event) override;
85
86private slots:
87 void onImpedanceChanged();
88 void onReflectionCoefficientChanged();
89 void onFormatChanged();
90 void onInputMethodChanged();
91 void onBrowseFile();
92 void onSParameterChanged();
93 void onToggleCollapse();
94
95private:
96 void setupUI();
97 void setupOnePortUI();
98 void setupTwoPortUI();
99 void updateReflectionCoefficient();
100 void updateImpedance();
101 void updateSParameterDisplays();
102 void updateImpedanceFormat();
103 void updateReflectionFormat();
104 void updateSParameterFormat();
105
106 double f_match;
107
108 QMap<QString, QList<double>> loadData; // It could be either 1-port or 2-port
109 QString spar_file_path; // Path to the S-parameter file (this is required for
110 // simulation)
111
112 // UI Components - One Port
113 QGridLayout* m_mainLayout;
114 QWidget* m_contentWidget;
115 QPushButton* m_toggleButton;
116
117 // Input method selection
118 QRadioButton* m_manualInputRadio;
119 QRadioButton* m_fileInputRadio;
120 QButtonGroup* m_inputMethodGroup;
121 QPushButton* m_browseButton;
122 QLabel* m_fileLabel;
123
124 // Format selection
125 QLabel* m_formatLabel;
126 QComboBox* m_formatCombo;
127
128 // Manual input widgets - Impedance
129 QLabel* m_impedanceLabel;
130 QDoubleSpinBox* m_impedanceReal;
131 QLabel* m_impedanceSeparator;
132 QDoubleSpinBox* m_impedanceImag;
133 QLabel* m_impedanceUnit;
134
135 // Manual input widgets - Reflection coefficient
136 QLabel* m_reflectionLabel;
137 QDoubleSpinBox* m_reflectionReal;
138 QLabel* m_reflectionSeparator;
139 QDoubleSpinBox* m_reflectionImag;
140
141 // Two-port widgets
142 QWidget* m_twoPortWidget;
143 QGridLayout* m_twoPortLayout;
144
145 // S-parameter widgets
146 QLabel* m_s11Label;
147 QDoubleSpinBox* m_s11Real;
148 QLabel* m_s11Separator;
149 QDoubleSpinBox* m_s11Imag;
150
151 QLabel* m_s12Label;
152 QDoubleSpinBox* m_s12Real;
153 QLabel* m_s12Separator;
154 QDoubleSpinBox* m_s12Imag;
155
156 QLabel* m_s21Label;
157 QDoubleSpinBox* m_s21Real;
158 QLabel* m_s21Separator;
159 QDoubleSpinBox* m_s21Imag;
160
161 QLabel* m_s22Label;
162 QDoubleSpinBox* m_s22Real;
163 QLabel* m_s22Separator;
164 QDoubleSpinBox* m_s22Imag;
165
166 // Internal state
167 bool m_twoPortMode;
168 bool m_updatingValues;
169 bool m_isCollapsed;
170 double m_Z0; // Reference impedance
171 QString m_currentFile;
172
173signals:
174 void impedanceChanged();
175 void reflectionCoefficientChanged();
176 void sParametersChanged();
177 void collapsedStateChanged(bool collapsed);
178};
179
180#endif // LOADSPECIFICATIONWIDGET_H
Definition LoadSpecificationWidget.h:43