Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
polarplotwidget.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 POLARPLOTWIDGET_H
19#define POLARPLOTWIDGET_H
20
21#include "./QCustomPlot/qcustomplot.h"
22#include <QCheckBox>
23#include <QComboBox>
24#include <QDoubleSpinBox>
25#include <QGridLayout>
26#include <QLabel>
27#include <QMap>
28#include <QPen>
29#include <QWidget>
30#include <complex>
31#include <limits>
32
33class PolarPlotWidget : public QWidget {
34 Q_OBJECT
35
36public:
37 struct Trace {
38 QList<std::complex<double>>
39 values; // Complex values (for polar representation)
40 QList<double> frequencies; // Corresponding frequencies for each point
41 QPen pen; // Line style for this trace
42 int displayMode; // 0: Magnitude/Phase, 1: Real/Imaginary
43 };
44
45 struct Marker {
46 QString id;
47 double frequency;
48 QPen pen;
49 };
50
51 struct AxisSettings {
52 double freqMax;
53 double freqMin;
54 QString freqUnit;
55
56 double radius_min;
57 double radius_max;
58 double radius_div;
59
60 QString marker_format;
61 };
62
63 void setSettings(const AxisSettings& settings);
64 PolarPlotWidget::AxisSettings getSettings() const;
65
66 explicit PolarPlotWidget(QWidget* parent = nullptr);
68
69 // Trace management functions
70 void addTrace(const QString& name, const Trace& trace);
71 void removeTrace(const QString& name);
72 void clearTraces();
73 QPen getTracePen(const QString& traceName) const;
74 void setTracePen(const QString& traceName, const QPen& pen);
75 QMap<QString, QPen> getTracesInfo() const;
76
77 // Axis value access functions
78 double getRmax();
79 double getRmin();
80 double getRdiv();
81 int getDisplayMode() const;
82
83 // Marker management functions
84 bool addMarker(const QString& markerId, double frequency,
85 const QPen& pen = QPen(Qt::red, 2));
86 bool removeMarker(const QString& markerId);
87 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
88 void clearMarkers();
89
90 QMap<QString, double> getMarkers() const;
91
92 // Access to underlying plot
93 QCustomPlot* customPlot() const { return plot; }
94
95private slots:
96 void updateRAxis();
97 void updateAngleAxis();
98 void toggleDisplayMode();
99
100 void onFMinChanged(double value);
101 void onFMaxChanged(double value);
102 void onFUnitChanged();
103
104private slots: // Slot to update axis settings widget based on the user zoom
105 void checkAxisRanges();
106 void checkAxisRanges(QMouseEvent* event);
107 void onRadialRangeChanged(const QCPRange& newRange);
108
109private:
110 QCustomPlot* plot;
111 QCPPolarAxisAngular* angularAxis;
112 QCPPolarAxisRadial* radialAxis;
113
114 QDoubleSpinBox* rAxisMin;
115 QDoubleSpinBox* rAxisMax;
116 QDoubleSpinBox* rAxisDiv;
117 QComboBox* displayModeCombo;
118
119 QDoubleSpinBox* fMinSpinBox;
120 QDoubleSpinBox* fMaxSpinBox;
121 QComboBox* fUnitComboBox;
122 double fMin;
123 double fMax;
124 QStringList frequencyUnits;
125
126 QMap<QString, Trace> traces;
127 QMap<QString, Marker> markers;
128 QMap<QString, QList<QCPPolarGraph*>>
129 traceGraphs; // Each trace can have multiple graphs for phase wrapping
130
131 // Marker items for drawing
132 QList<QCPItemEllipse*> markerItems;
133 QList<QCPItemText*> markerLabels;
134
135 void updateFrequencyRange();
136 QGridLayout* setupAxisSettings();
137 void updatePlot();
138 void clearGraphicsItems();
139 void drawCustomMarkers();
140 double getFrequencyMultiplier() const;
141
142 // Helper to find a complex value at a specific frequency using interpolation
143 std::complex<double> getComplexValueAtFrequency(const Trace& trace,
144 double frequency);
145
146 // Convert between display modes (magnitude/phase <-> real/imaginary)
147 std::complex<double> convertToDisplayFormat(const std::complex<double>& value,
148 int mode);
149};
150
151#endif // POLARPLOTWIDGET_H
Definition polarplotwidget.h:33
Definition polarplotwidget.h:51
Definition polarplotwidget.h:45
Definition polarplotwidget.h:37