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
46 _realDataPoints = new double[_numPoints];
47 _imagDataPoints = new double[_numPoints];
49 // Disable polygon clipping
50 QwtPainter::setDeviceClipping(false);
52 // We don't need the cache here
53 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
54 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
57 palette.setColor(canvas()->backgroundRole(), QColor("white"));
58 canvas()->setPalette(palette);
60 setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
61 //setAxisScale(QwtPlot::xBottom, -1.0, 1.0);
63 setAxisTitle(QwtPlot::xBottom, "In-phase");
65 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
66 //setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
68 setAxisTitle(QwtPlot::yLeft, "Quadrature");
70 // Automatically deleted when parent is deleted
71 _plot_curve = new QwtPlotCurve("Constellation Points");
72 _plot_curve->attach(this);
73 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
74 _plot_curve->setStyle(QwtPlotCurve::Dots);
75 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
77 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
78 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
82 _zoomer = new ConstellationDisplayZoomer(canvas());
83 #if QT_VERSION < 0x040000
84 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
85 Qt::RightButton, Qt::ControlModifier);
87 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
88 Qt::RightButton, Qt::ControlModifier);
90 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
93 _panner = new QwtPlotPanner(canvas());
94 _panner->setAxisEnabled(QwtPlot::yRight, false);
95 _panner->setMouseButton(Qt::MidButton);
97 // Avoid jumping when labels with more/less digits
98 // appear/disappear when scrolling vertically
100 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
101 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
102 sd->setMinimumExtent( fm.width("100.00") );
104 const QColor c(Qt::darkRed);
105 _zoomer->setRubberBandPen(c);
106 _zoomer->setTrackerPen(c);
108 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ),
109 this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
112 ConstellationDisplayPlot::~ConstellationDisplayPlot()
114 delete[] _realDataPoints;
115 delete[] _imagDataPoints;
117 // _fft_plot_curves deleted when parent deleted
118 // _zoomer and _panner deleted when parent deleted
122 ConstellationDisplayPlot::set_pen_size(int size)
124 if(size > 0 && size < 30){
126 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
132 ConstellationDisplayPlot::set_xaxis(double min, double max)
134 setAxisScale(QwtPlot::xBottom, min, max);
138 ConstellationDisplayPlot::set_yaxis(double min, double max)
140 setAxisScale(QwtPlot::yLeft, min, max);
144 ConstellationDisplayPlot::set_axis(double xmin, double xmax,
145 double ymin, double ymax)
147 set_xaxis(xmin, xmax);
148 set_yaxis(ymin, ymax);
151 void ConstellationDisplayPlot::replot(){
153 const timespec startTime = get_highres_clock();
157 double differenceTime = (diff_timespec(get_highres_clock(), startTime));
159 differenceTime *= 99.0;
160 // Require at least a 10% duty cycle
161 if(differenceTime > (1.0/10.0)){
162 _displayIntervalTime = differenceTime;
167 ConstellationDisplayPlot::resizeSlot( QSize *s )
169 resize(s->width(), s->height());
172 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
173 const double* imagDataPoints,
174 const int64_t numDataPoints)
176 if(numDataPoints > 0){
178 if(numDataPoints != _numPoints){
179 _numPoints = numDataPoints;
181 delete[] _realDataPoints;
182 delete[] _imagDataPoints;
183 _realDataPoints = new double[_numPoints];
184 _imagDataPoints = new double[_numPoints];
186 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
188 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
189 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
193 // Allow at least a 50% duty cycle
194 if(diff_timespec(get_highres_clock(), _lastReplot) > _displayIntervalTime){
195 // Only replot the screen if it is visible
199 _lastReplot = get_highres_clock();
204 ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
206 plotItem->setVisible(!on);
209 #endif /* CONSTELLATION_DISPLAY_PLOT_C */