LibreVNA/Software/PC_Application/Traces/tracexyplot.h

125 lines
3.3 KiB
C
Raw Normal View History

2020-10-27 22:07:14 +01:00
#ifndef TRACEXYPLOT_H
#define TRACEXYPLOT_H
#include "traceplot.h"
#include <set>
2020-10-27 22:07:14 +01:00
class TraceXYPlot : public TracePlot
{
2020-10-27 22:07:14 +01:00
friend class XYplotAxisDialog;
Q_OBJECT
public:
2020-10-27 22:07:14 +01:00
TraceXYPlot(TraceModel &model, QWidget *parent = nullptr);
enum class YAxisType {
Disabled,
2020-10-27 22:07:14 +01:00
// S parameter options
Magnitude,
Phase,
VSWR,
2021-10-11 15:22:08 +02:00
Real,
Imaginary,
// derived parameter options
SeriesR,
Capacitance,
Inductance,
QualityFactor,
2020-10-27 22:07:14 +01:00
// TDR options
ImpulseReal,
ImpulseMag,
Step,
Impedance,
Last,
};
2020-10-27 22:07:14 +01:00
static const std::set<YAxisType> YAxisTypes;
enum class XAxisType {
Frequency,
Time,
Distance,
2021-07-09 18:42:22 +02:00
Power,
Last,
2020-10-27 22:07:14 +01:00
};
2020-11-01 22:56:31 +01:00
enum class XAxisMode {
UseSpan,
FitTraces,
Manual,
Last,
2020-11-01 22:56:31 +01:00
};
void setYAxis(int axis, YAxisType type, bool log, bool autorange, double min, double max, double div);
2020-11-01 22:56:31 +01:00
void setXAxis(XAxisType type, XAxisMode mode, double min, double max, double div);
void enableTrace(Trace *t, bool enabled) override;
void updateSpan(double min, double max) override;
void replot() override;
2020-12-04 23:49:52 +01:00
virtual Type getType() override { return Type::XYPlot;};
virtual nlohmann::json toJSON() override;
virtual void fromJSON(nlohmann::json j) override;
2020-10-27 22:07:14 +01:00
bool isTDRtype(YAxisType type);
2020-11-01 22:56:31 +01:00
public slots:
void axisSetupDialog();
protected:
virtual bool configureForTrace(Trace *t) override;
2020-10-27 22:07:14 +01:00
virtual void updateContextMenu() override;
virtual bool dropSupported(Trace *t) override;
virtual void draw(QPainter &p) override;
private slots:
void updateAxisTicks();
private:
static constexpr int AxisLabelSize = 10;
static QString AxisTypeToName(YAxisType type);
static QString AxisTypeToName(XAxisType type);
static QString AxisModeToName(XAxisMode mode);
XAxisType XAxisTypeFromName(QString name);
YAxisType YAxisTypeFromName(QString name);
XAxisMode AxisModeFromName(QString name);
void enableTraceAxis(Trace *t, int axis, bool enabled);
bool supported(Trace *t) override;
bool supported(Trace *t, YAxisType type);
2020-11-26 17:45:55 +01:00
QPointF traceToCoordinate(Trace *t, unsigned int sample, YAxisType type);
2020-11-22 21:25:41 +01:00
QPoint plotValueToPixel(QPointF plotValue, int Yaxis);
QPointF pixelToPlotValue(QPoint pixel, int YAxis);
QPoint markerToPixel(Marker *m) override;
2021-05-14 20:34:23 +02:00
double nearestTracePoint(Trace *t, QPoint pixel, double *distance = nullptr) override;
virtual bool xCoordinateVisible(double x);
void traceDropped(Trace *t, QPoint position) override;
QString mouseText(QPoint pos) override;
static QString AxisUnit(YAxisType type);
static QString AxisUnit(XAxisType type);
std::set<Trace*> tracesAxis[2];
2020-11-01 22:56:31 +01:00
class YAxis {
public:
2020-11-01 22:56:31 +01:00
YAxisType type;
bool log; // not used yet
bool autorange;
double rangeMin;
double rangeMax;
double rangeDiv;
std::vector<double> ticks;
};
2020-11-01 22:56:31 +01:00
class XAxis {
public:
XAxisType type;
XAxisMode mode;
bool log; // not used yet
double rangeMin;
double rangeMax;
double rangeDiv;
std::vector<double> ticks;
2020-11-01 22:56:31 +01:00
};
YAxis YAxis[2];
XAxis XAxis;
int plotAreaLeft, plotAreaWidth, plotAreaBottom;
};
2020-10-27 22:07:14 +01:00
#endif // TRACEXYPLOT_H