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):QwtPlot(parent){
36 timespec_reset(&_lastReplot);
38 resize(parent->width(), parent->height());
40 _displayIntervalTime = (1.0/10.0); // 1/10 of a second between updates
43 _realDataPoints = new double[_numPoints];
44 _imagDataPoints = new double[_numPoints];
46 // Disable polygon clipping
47 QwtPainter::setDeviceClipping(false);
49 // We don't need the cache here
50 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
51 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
54 palette.setColor(canvas()->backgroundRole(), QColor("white"));
55 canvas()->setPalette(palette);
57 setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
58 setAxisScale(QwtPlot::xBottom, -1.0, 1.0);
59 setAxisTitle(QwtPlot::xBottom, "In-phase");
61 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
62 setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
63 setAxisTitle(QwtPlot::yLeft, "Quadrature");
65 // Automatically deleted when parent is deleted
66 _plot_curve = new QwtPlotCurve("Constellation Points");
67 _plot_curve->attach(this);
68 _plot_curve->setPen(QPen(Qt::blue, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
69 _plot_curve->setStyle(QwtPlotCurve::Dots);
70 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
72 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
73 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
77 _zoomer = new ConstellationDisplayZoomer(canvas());
78 #if QT_VERSION < 0x040000
79 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
80 Qt::RightButton, Qt::ControlModifier);
82 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
83 Qt::RightButton, Qt::ControlModifier);
85 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
88 _panner = new QwtPlotPanner(canvas());
89 _panner->setAxisEnabled(QwtPlot::yRight, false);
90 _panner->setMouseButton(Qt::MidButton);
92 // Avoid jumping when labels with more/less digits
93 // appear/disappear when scrolling vertically
95 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
96 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
97 sd->setMinimumExtent( fm.width("100.00") );
99 const QColor c(Qt::darkRed);
100 _zoomer->setRubberBandPen(c);
101 _zoomer->setTrackerPen(c);
103 QwtLegend* legendDisplay = new QwtLegend(this);
104 legendDisplay->setItemMode(QwtLegend::CheckableItem);
105 insertLegend(legendDisplay);
107 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ), this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
110 ConstellationDisplayPlot::~ConstellationDisplayPlot(){
111 delete[] _realDataPoints;
112 delete[] _imagDataPoints;
114 // _fft_plot_curves deleted when parent deleted
115 // _zoomer and _panner deleted when parent deleted
120 void ConstellationDisplayPlot::replot(){
122 const timespec startTime = get_highres_clock();
126 double differenceTime = (diff_timespec(get_highres_clock(), startTime));
128 differenceTime *= 99.0;
129 // Require at least a 10% duty cycle
130 if(differenceTime > (1.0/10.0)){
131 _displayIntervalTime = differenceTime;
135 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, const double* imagDataPoints, const int64_t numDataPoints){
136 if(numDataPoints > 0){
138 if(numDataPoints != _numPoints){
139 _numPoints = numDataPoints;
141 delete[] _realDataPoints;
142 delete[] _imagDataPoints;
143 _realDataPoints = new double[_numPoints];
144 _imagDataPoints = new double[_numPoints];
146 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
148 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
149 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
153 // Allow at least a 50% duty cycle
154 if(diff_timespec(get_highres_clock(), _lastReplot) > _displayIntervalTime){
155 // Only replot the screen if it is visible
159 _lastReplot = get_highres_clock();
163 void ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on){
164 plotItem->setVisible(!on);
167 #endif /* CONSTELLATION_DISPLAY_PLOT_C */