Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
smithchartwidget.h
1/*
2 * Copyright (C) 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 SMITHCHARTWIDGET_H
19#define SMITHCHARTWIDGET_H
20
21#include <QCheckBox>
22#include <QComboBox>
23#include <QDoubleSpinBox>
24#include <QLabel>
25#include <QMap>
26#include <QMouseEvent>
27#include <QPainter>
28#include <QPen>
29#include <QSet>
30#include <QVBoxLayout>
31#include <QWidget>
32#include <complex>
33
34class Qucs_S_SPAR_Viewer; // Forward declaration
35
36class SmithChartWidget : public QWidget {
37 Q_OBJECT
38
39public:
40 struct Trace {
41 QList<std::complex<double>> impedances;
42 QList<double> frequencies;
43 QPen pen;
44 double Z0;
45 };
46
47 struct Marker {
48 QString id;
49 double frequency;
50 QPen pen;
51 };
52
53 struct AxisSettings {
54 QString Z0;
55
56 double freqMax;
57 double freqMin;
58 QString freqUnit;
59
60 bool y_chart;
61 bool z_chart;
62 };
63
64 SmithChartWidget::AxisSettings getSettings() const;
65 void setSettings(const AxisSettings& settings);
66
67 SmithChartWidget(QWidget* parent = nullptr);
68 ~SmithChartWidget() override;
69
70 void addTrace(const QString& name, const Trace& trace);
71 void removeTrace(const QString&);
72 void clearTraces();
73 void setCharacteristicImpedance(double z0);
74 double characteristicImpedance() const { return z0; }
75 QPen getTracePen(const QString& traceName) const;
76 void setTracePen(const QString& traceName, const QPen& pen);
77 QMap<QString, QPen> getTracesInfo() const;
78
79 bool addMarker(const QString& markerId, double frequency,
80 const QPen& pen = QPen(Qt::red, 2));
81 bool removeMarker(const QString& markerId);
82 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
83
84 void clearMarkers();
85 QMap<QString, double> getMarkers() const;
86
87signals:
88 void impedanceSelected(const std::complex<double>& impedance);
89
90protected:
91 void paintEvent(QPaintEvent* event) override;
92 void mousePressEvent(QMouseEvent* event) override;
93
94private:
95 void drawSmithChartGrid(QPainter* painter);
96 void drawReactanceArc(QPainter* painter, const QPointF& center, double radius,
97 double reactance);
98 void drawSusceptanceArc(QPainter* painter, const QPointF& center,
99 double radius, double susceptance);
100 void plotImpedanceData(QPainter* painter);
101
102 void drawMarkers(QPainter* painter);
103 QPointF smithChartToWidget(const std::complex<double>& reflectionCoefficient);
104 std::complex<double> widgetToSmithChart(const QPointF& widgetPoint);
105 std::complex<double>
106 interpolateImpedance(const QList<double>& frequencies,
107 const QList<std::complex<double>>& impedances,
108 double targetFreq);
109
110 void calculateArcPoints(const QRectF& arcRect, double startAngle,
111 double sweepAngle, QPointF& startPoint,
112 QPointF& endPoint);
113
114private:
115 QMap<QString, Trace> traces; // Changed from QList to QMap
116 QMap<QString, Marker> markers; // Store markers by ID instead of frequency
117 double z0; // Characteristic impedance
118 QPointF lastMousePos;
119
120 // Add a scale factor for zoom functionality
121 double scaleFactor;
122 double panX;
123 double panY;
124
125private slots:
126 void onZ0Changed(int index);
127 void onShowAdmittanceChartChanged(int);
128 void onShowConstantCurvesChanged(int);
129
130private:
131 QComboBox* m_Z0ComboBox;
132 QCheckBox* m_ShowAdmittanceChartCheckBox; // Checkbox for admittance chart
133 QCheckBox*
134 m_ShowConstantCurvesCheckBox; // Checkbox for reactance/resistance curves
135 bool m_showConstantCurves; // Flag for curve display
136 bool m_showAdmittanceChart; // Flag for admittance chart display
137 QVBoxLayout* m_layout;
138
139private:
140 // Frequency range controls
141 QDoubleSpinBox* m_minFreqSpinBox;
142 QDoubleSpinBox* m_maxFreqSpinBox;
143 QComboBox* m_freqUnitComboBox;
144 double m_minFreq; // Minimum frequency in Hz
145 double m_maxFreq; // Maximum frequency in Hz
146
147 // Add to private slots: section in smithchartwidget.h
148private slots:
149 void onMinFreqChanged(double value);
150 void onMaxFreqChanged(double value);
151 void onFreqUnitChanged(int index);
152 double getFrequencyMultiplier() const;
153 void updateFrequencyRange();
154};
155
156#endif // SMITHCHARTWIDGET_H
Definition qucs-s-spar-viewer.h:148
Definition smithchartwidget.h:36
Definition smithchartwidget.h:53
Definition smithchartwidget.h:47
Definition smithchartwidget.h:40