1 #ifndef CONSTELLATION_DISPLAY_PLOT_C
2 #define CONSTELLATION_DISPLAY_PLOT_C
4 #include <ConstellationDisplayPlot.h>
6 #include <qwt_scale_draw.h>
7 #include <qwt_legend.h>
10 class ConstellationDisplayZoomer: public QwtPlotZoomer
13 ConstellationDisplayZoomer(QwtPlotCanvas* canvas):QwtPlotZoomer(canvas)
15 setTrackerMode(QwtPicker::AlwaysOn);
18 virtual ~ConstellationDisplayZoomer(){
22 virtual void updateTrackerText(){
27 virtual QwtText trackerText( const QwtDoublePoint& p ) const
29 QwtText t(QString("Sample %1, %2 V").arg(p.x(), 0, 'f', 0).arg(p.y(), 0, 'f', 4));
35 ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent)
38 timespec_reset(&_lastReplot);
40 resize(parent->width(), parent->height());
42 _displayIntervalTime = (1.0/10.0); // 1/10 of a second between updates
45 _realDataPoints = new double[_numPoints];
46 _imagDataPoints = new double[_numPoints];
48 // Disable polygon clipping
49 QwtPainter::setDeviceClipping(false);
51 // We don't need the cache here
52 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
53 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
56 palette.setColor(canvas()->backgroundRole(), QColor("white"));
57 canvas()->setPalette(palette);
59 setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
60 //setAxisScale(QwtPlot::xBottom, -1.0, 1.0);
62 setAxisTitle(QwtPlot::xBottom, "In-phase");
64 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
65 //setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
67 setAxisTitle(QwtPlot::yLeft, "Quadrature");
69 // Automatically deleted when parent is deleted
70 _plot_curve = new QwtPlotCurve("Constellation Points");
71 _plot_curve->attach(this);
72 _plot_curve->setPen(QPen(Qt::blue, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
73 _plot_curve->setStyle(QwtPlotCurve::Dots);
74 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
76 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
77 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
81 _zoomer = new ConstellationDisplayZoomer(canvas());
82 #if QT_VERSION < 0x040000
83 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
84 Qt::RightButton, Qt::ControlModifier);
86 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
87 Qt::RightButton, Qt::ControlModifier);
89 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
92 _panner = new QwtPlotPanner(canvas());
93 _panner->setAxisEnabled(QwtPlot::yRight, false);
94 _panner->setMouseButton(Qt::MidButton);
96 // Avoid jumping when labels with more/less digits
97 // appear/disappear when scrolling vertically
99 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
100 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
101 sd->setMinimumExtent( fm.width("100.00") );
103 const QColor c(Qt::darkRed);
104 _zoomer->setRubberBandPen(c);
105 _zoomer->setTrackerPen(c);
107 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ),
108 this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
111 ConstellationDisplayPlot::~ConstellationDisplayPlot()
113 delete[] _realDataPoints;
114 delete[] _imagDataPoints;
116 // _fft_plot_curves deleted when parent deleted
117 // _zoomer and _panner deleted when parent deleted
121 ConstellationDisplayPlot::set_xaxis(double min, double max)
123 setAxisScale(QwtPlot::xBottom, min, max);
127 ConstellationDisplayPlot::set_yaxis(double min, double max)
129 setAxisScale(QwtPlot::yLeft, min, max);
133 ConstellationDisplayPlot::set_axis(double xmin, double xmax,
134 double ymin, double ymax)
136 set_xaxis(xmin, xmax);
137 set_yaxis(ymin, ymax);
140 void ConstellationDisplayPlot::replot(){
142 const timespec startTime = get_highres_clock();
146 double differenceTime = (diff_timespec(get_highres_clock(), startTime));
148 differenceTime *= 99.0;
149 // Require at least a 10% duty cycle
150 if(differenceTime > (1.0/10.0)){
151 _displayIntervalTime = differenceTime;
156 ConstellationDisplayPlot::resizeSlot( QSize *s )
158 resize(s->width(), s->height());
161 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
162 const double* imagDataPoints,
163 const int64_t numDataPoints)
165 if(numDataPoints > 0){
167 if(numDataPoints != _numPoints){
168 _numPoints = numDataPoints;
170 delete[] _realDataPoints;
171 delete[] _imagDataPoints;
172 _realDataPoints = new double[_numPoints];
173 _imagDataPoints = new double[_numPoints];
175 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
177 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
178 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
182 // Allow at least a 50% duty cycle
183 if(diff_timespec(get_highres_clock(), _lastReplot) > _displayIntervalTime){
184 // Only replot the screen if it is visible
188 _lastReplot = get_highres_clock();
193 ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
195 plotItem->setVisible(!on);
198 #endif /* CONSTELLATION_DISPLAY_PLOT_C */