Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
smithchartwidget.h
Go to the documentation of this file.
1
7
8#ifndef SMITHCHARTWIDGET_H
9#define SMITHCHARTWIDGET_H
10
12#include <QCheckBox>
13#include <QComboBox>
14#include <QLabel>
15#include <QMap>
16#include <QMouseEvent>
17#include <QPainter>
18#include <QPen>
19#include <QSet>
20#include <QVBoxLayout>
21#include <QWidget>
22#include <complex>
23
26
27
32class SmithChartWidget : public QWidget {
33 Q_OBJECT
34
35public:
38 struct Trace {
39 QList<std::complex<double>> impedances;
40 QList<double> frequencies;
41 QPen pen;
42 double Z0;
43 };
44
45
49 struct Marker {
50 QString id;
51 double frequency;
52 QPen pen;
53 };
54
57 struct AxisSettings {
58 QString Z0;
59 double freqMax;
60 double freqMin;
61 QString freqUnit;
62
63 bool y_chart;
64 bool z_chart;
65 };
66
70
73 void setSettings(const AxisSettings& settings);
74
77 SmithChartWidget(QWidget* parent = nullptr);
78
80 ~SmithChartWidget() override {}
81
87 void addTrace(const QString& name, const Trace& trace);
88
91 void removeTrace(const QString&);
92
94 void clearTraces() {
95 traces.clear(); // Remove all traces
96 update(); // Trigger a repaint to reflect the changes
97 }
98
102 z0 = z;
103 update(); // Redraw the chart with the new Z0
104 }
105
108 double characteristicImpedance() const { return z0; }
109
113 QPen getTracePen(const QString& traceName) const;
114
118 void setTracePen(const QString& traceName, const QPen& pen);
119
122 QMap<QString, QPen> getTracesInfo() const;
123
130 bool addMarker(const QString& markerId, double frequency,
131 const QPen& pen = QPen(Qt::red, 2));
132
135 bool removeMarker(const QString& markerId);
136
141 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
142
145 markers.clear();
146 update();
147 }
148
151 QMap<QString, double> getMarkers() const;
152
153signals:
156 void impedanceSelected(const std::complex<double>& impedance);
157
158protected:
160 void paintEvent(QPaintEvent* event) override;
161
163 void mousePressEvent(QMouseEvent* event) override;
164
165private:
168 void drawSmithChartGrid(QPainter* painter);
169
175 void drawReactanceArc(QPainter* painter, const QPointF& center, double radius,
176 double reactance);
177
183 void drawSusceptanceArc(QPainter* painter, const QPointF& center,
184 double radius, double susceptance);
185
188 void plotImpedanceData(QPainter* painter);
189
192 void drawMarkers(QPainter* painter);
193
197 QPointF smithChartToWidget(const std::complex<double>& reflectionCoefficient);
198
202 std::complex<double> widgetToSmithChart(const QPointF& widgetPoint);
203
209 std::complex<double>
210 interpolateImpedance(const QList<double>& frequencies,
211 const QList<std::complex<double>>& impedances,
212 double targetFreq);
213
220 void calculateArcPoints(const QRectF& arcRect, double startAngle,
221 double sweepAngle, QPointF& startPoint,
222 QPointF& endPoint);
223
224private:
225
226 QMap<QString, Trace> traces;
227 QMap<QString, Marker> markers;
228
229
230 double z0;
231 QPointF lastMousePos;
232 double scaleFactor;
233 double panX;
234 double panY;
235
236private slots:
238 void onZ0Changed(int index);
239
242 void onShowAdmittanceChartChanged(int state) {
243 m_showAdmittanceChart = (state == Qt::Checked);
244 update(); // Trigger a repaint
245 }
246
249 void onShowConstantCurvesChanged(int state) {
250 m_showConstantCurves = (state == Qt::Checked);
251 update(); // Trigger a repaint
252 }
253
254private:
255 QComboBox* m_Z0ComboBox;
256 QCheckBox* m_ShowAdmittanceChartCheckBox;
257 QCheckBox*
258 m_ShowConstantCurvesCheckBox;
259 bool m_showConstantCurves;
260 bool m_showAdmittanceChart;
261 QVBoxLayout* m_layout;
262
263private:
264 // Frequency range controls
265 CustomDoubleSpinBox* m_minFreqSpinBox;
266 CustomDoubleSpinBox* m_maxFreqSpinBox;
267 QComboBox* m_freqUnitComboBox;
268 double m_minFreq;
269 double m_maxFreq;
270
271private slots:
274 void onMinFreqChanged(double value);
275
278 void onMaxFreqChanged(double value);
279
282 void onFreqUnitChanged(int index);
283
286 double getFrequencyMultiplier() const;
287
289 void updateFrequencyRange();
290};
291
292#endif // SMITHCHARTWIDGET_H
Custom QDoubleSpinBox. It includes a context menu (right-click) for setting the minimum,...
A QDoubleSpinBox subclass that provides a context menu for configuring range and step.
Definition CustomDoubleSpinBox.h:28
Main application class for S-parameter viewer (and its RF circuit synthesis tools)
Definition qucs-s-spar-viewer.h:168
Smith chart visualization and interaction widget. Provides impedance/admittance Smith chart drawing,...
Definition smithchartwidget.h:32
~SmithChartWidget() override
Class destructor.
Definition smithchartwidget.h:80
void setSettings(const AxisSettings &settings)
Set the current axis settings.
Definition smithchartwidget.cpp:1065
void clearTraces()
Remove all traces from the plot.
Definition smithchartwidget.h:94
SmithChartWidget::AxisSettings getSettings() const
Returns the current axis settings.
Definition smithchartwidget.cpp:1052
void removeTrace(const QString &)
Remove a trace from the plot.
Definition smithchartwidget.cpp:820
QMap< QString, QPen > getTracesInfo() const
Returns a map with trace names and their QPens.
Definition smithchartwidget.cpp:810
void setCharacteristicImpedance(double z)
Set the characteristic impedance of the diagram.
Definition smithchartwidget.h:101
bool updateMarkerFrequency(const QString &markerId, double newFrequency)
Update the frequency of an existing marker.
Definition smithchartwidget.cpp:1021
void setTracePen(const QString &traceName, const QPen &pen)
Sets the pen for an existing trace (given its name)
Definition smithchartwidget.cpp:803
double characteristicImpedance() const
Get the characteristic impedance of the diagram.
Definition smithchartwidget.h:108
void addTrace(const QString &name, const Trace &trace)
Add or update a trace on the plot.
Definition smithchartwidget.cpp:189
void mousePressEvent(QMouseEvent *event) override
Handles mouse clicks to pick impedances and emit impedanceSelected().
Definition smithchartwidget.cpp:238
bool addMarker(const QString &markerId, double frequency, const QPen &pen=QPen(Qt::red, 2))
Adds a marker at a given frequency.
Definition smithchartwidget.cpp:827
void clearMarkers()
Remove all markers from the plot.
Definition smithchartwidget.h:144
QPen getTracePen(const QString &traceName) const
Get the diagram QPen style of a trace (by name)
Definition smithchartwidget.cpp:795
void impedanceSelected(const std::complex< double > &impedance)
Emitted when a point on the chart is clicked.
bool removeMarker(const QString &markerId)
Remove a trace from the plot, given its name.
Definition smithchartwidget.cpp:864
void paintEvent(QPaintEvent *event) override
Reimplements paintEvent to draw the Smith chart and overlays.
Definition smithchartwidget.cpp:213
QMap< QString, double > getMarkers() const
Get all markers and their frequencies.
Definition smithchartwidget.cpp:874
Settings for plot axes and display options.
Definition smithchartwidget.h:57
bool y_chart
Show admittance chart.
Definition smithchartwidget.h:63
bool z_chart
Show impedance chart.
Definition smithchartwidget.h:64
QString freqUnit
Frequency units.
Definition smithchartwidget.h:61
double freqMax
Maximum frequency to shown on the diagram [Hz].
Definition smithchartwidget.h:59
QString Z0
Diagram reference impedance [Ohm].
Definition smithchartwidget.h:58
double freqMin
Minimum frequency to shown on the diagram [Hz].
Definition smithchartwidget.h:60
Data structure for the frequency marker Defines a marker at a specific frequency with its appearance.
Definition smithchartwidget.h:49
double frequency
Marker frequency [Hz].
Definition smithchartwidget.h:51
QPen pen
Marker pen style.
Definition smithchartwidget.h:52
QString id
Unique marker identifier.
Definition smithchartwidget.h:50
Data structure representing a trace on the plot.
Definition smithchartwidget.h:38
QPen pen
Pen used to draw the trace.
Definition smithchartwidget.h:41
QList< std::complex< double > > impedances
Impedance samples for the trace [Ohm].
Definition smithchartwidget.h:39
QList< double > frequencies
Frequencies for each impedance sample [Hz].
Definition smithchartwidget.h:40
double Z0
Characteristic impedance of the trace data [Ohm].
Definition smithchartwidget.h:42