summaryrefslogtreecommitdiff
path: root/gr-qtgui/lib/TimeDomainDisplayPlot.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc')
-rw-r--r--gr-qtgui/lib/TimeDomainDisplayPlot.cc141
1 files changed, 81 insertions, 60 deletions
diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc
index be25a6cde..f635a2b0c 100644
--- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc
+++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc
@@ -1,3 +1,25 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2009,2010,2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
#ifndef TIME_DOMAIN_DISPLAY_PLOT_C
#define TIME_DOMAIN_DISPLAY_PLOT_C
@@ -5,7 +27,8 @@
#include <qwt_scale_draw.h>
#include <qwt_legend.h>
-
+#include <QColor>
+#include <iostream>
class TimePrecisionClass
{
@@ -70,16 +93,14 @@ private:
std::string _unitType;
};
-TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent)
+TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent)
+ : QwtPlot(parent), _nplots(nplots)
{
- timespec_reset(&_lastReplot);
-
resize(parent->width(), parent->height());
_numPoints = 1024;
- _realDataPoints = new double[_numPoints];
- _imagDataPoints = new double[_numPoints];
_xAxisPoints = new double[_numPoints];
+ memset(_xAxisPoints, 0x0, _numPoints*sizeof(double));
_zoomer = new TimeDomainDisplayZoomer(canvas(), 0);
_zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection);
@@ -96,41 +117,40 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent)
canvas()->setPalette(palette);
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
- set_xaxis(0, _numPoints);
+ setXaxis(0, _numPoints);
setAxisTitle(QwtPlot::xBottom, "Time (sec)");
setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
- set_yaxis(-2.0, 2.0);
- setAxisTitle(QwtPlot::yLeft, "Normalized Voltage");
+ setYaxis(-2.0, 2.0);
+ setAxisTitle(QwtPlot::yLeft, "Amplitude");
+ QList<QColor> colors;
+ colors << QColor(Qt::blue) << QColor(Qt::red) << QColor(Qt::green)
+ << QColor(Qt::black) << QColor(Qt::cyan) << QColor(Qt::magenta)
+ << QColor(Qt::yellow) << QColor(Qt::gray) << QColor(Qt::darkRed)
+ << QColor(Qt::darkGreen) << QColor(Qt::darkBlue) << QColor(Qt::darkGray);
+
+ int ncolors = colors.size();
+
+ // Setup dataPoints and plot vectors
// Automatically deleted when parent is deleted
- _real_plot_curve = new QwtPlotCurve("Real Data");
- _real_plot_curve->attach(this);
- _real_plot_curve->setPen(QPen(Qt::blue));
- _real_plot_curve->setRawData(_xAxisPoints, _realDataPoints, _numPoints);
-
- _imag_plot_curve = new QwtPlotCurve("Imaginary Data");
- _imag_plot_curve->attach(this);
- _imag_plot_curve->setPen(QPen(Qt::magenta));
- _imag_plot_curve->setRawData(_xAxisPoints, _imagDataPoints, _numPoints);
- // _imag_plot_curve->setVisible(false);
-
- memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
- memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
- memset(_xAxisPoints, 0x0, _numPoints*sizeof(double));
+ for(int i = 0; i < _nplots; i++) {
+ _dataPoints.push_back(new double[_numPoints]);
+ memset(_dataPoints[i], 0x0, _numPoints*sizeof(double));
+
+ _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i)));
+ _plot_curve[i]->attach(this);
+ _plot_curve[i]->setPen(QPen(colors[i]));
+ _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints);
+ }
_sampleRate = 1;
_resetXAxisPoints();
-#if QT_VERSION < 0x040000
- _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
- Qt::RightButton, Qt::ControlModifier);
-#else
_zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
- Qt::RightButton, Qt::ControlModifier);
-#endif
+ Qt::RightButton, Qt::ControlModifier);
_zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
- Qt::RightButton);
+ Qt::RightButton);
_panner = new QwtPlotPanner(canvas());
_panner->setAxisEnabled(QwtPlot::yRight, false);
@@ -164,29 +184,40 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent)
this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
}
-TimeDomainDisplayPlot::~TimeDomainDisplayPlot(){
- delete[] _realDataPoints;
- delete[] _imagDataPoints;
+TimeDomainDisplayPlot::~TimeDomainDisplayPlot()
+{
+ for(int i = 0; i < _nplots; i++)
+ delete [] _dataPoints[i];
delete[] _xAxisPoints;
- // _fft_plot_curves deleted when parent deleted
// _zoomer and _panner deleted when parent deleted
}
void
-TimeDomainDisplayPlot::set_yaxis(double min, double max)
+TimeDomainDisplayPlot::setYaxis(double min, double max)
{
setAxisScale(QwtPlot::yLeft, min, max);
_zoomer->setZoomBase();
}
void
-TimeDomainDisplayPlot::set_xaxis(double min, double max)
+TimeDomainDisplayPlot::setXaxis(double min, double max)
{
setAxisScale(QwtPlot::xBottom, min, max);
_zoomer->setZoomBase();
}
+void
+TimeDomainDisplayPlot::setTitle(int which, QString title)
+{
+ _plot_curve[which]->setTitle(title);
+}
+
+void
+TimeDomainDisplayPlot::setColor(int which, QString color)
+{
+ _plot_curve[which]->setPen(QPen(color));
+}
void TimeDomainDisplayPlot::replot()
{
@@ -196,47 +227,37 @@ void TimeDomainDisplayPlot::replot()
void
TimeDomainDisplayPlot::resizeSlot( QSize *s )
{
- resize(s->width(), s->height());
+ // -10 is to spare some room for the legend and x-axis label
+ resize(s->width()-10, s->height()-10);
}
-void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints,
- const double* imagDataPoints,
+void TimeDomainDisplayPlot::PlotNewData(const std::vector<double*> dataPoints,
const int64_t numDataPoints,
const double timeInterval)
{
- if((numDataPoints > 0) &&
- (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) {
-
+ if((numDataPoints > 0)) {
if(numDataPoints != _numPoints){
_numPoints = numDataPoints;
- delete[] _realDataPoints;
- delete[] _imagDataPoints;
delete[] _xAxisPoints;
- _realDataPoints = new double[_numPoints];
- _imagDataPoints = new double[_numPoints];
_xAxisPoints = new double[_numPoints];
-
- _real_plot_curve->setRawData(_xAxisPoints, _realDataPoints, _numPoints);
- _imag_plot_curve->setRawData(_xAxisPoints, _imagDataPoints, _numPoints);
-
- set_xaxis(0, numDataPoints);
+ for(int i = 0; i < _nplots; i++) {
+ delete[] _dataPoints[i];
+ _dataPoints[i] = new double[_numPoints];
+ _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints);
+ }
+
+ setXaxis(0, numDataPoints);
_resetXAxisPoints();
}
- memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
- memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
-
- _lastReplot = get_highres_clock();
+ for(int i = 0; i < _nplots; i++) {
+ memcpy(_dataPoints[i], dataPoints[i], numDataPoints*sizeof(double));
+ }
}
}
-void TimeDomainDisplayPlot::SetImaginaryDataVisible(const bool visibleFlag)
-{
- _imag_plot_curve->setVisible(visibleFlag);
-}
-
void TimeDomainDisplayPlot::_resetXAxisPoints()
{
double delt = 1.0/_sampleRate;