From befadabc2f18b483c71250adfd7dbf42f66b16f0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 27 Mar 2011 12:55:16 -0400 Subject: gr-qtgui: restructuring qtgui directory to new layout. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 276 ++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 gr-qtgui/lib/TimeDomainDisplayPlot.cc (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc new file mode 100644 index 000000000..9c98cec5b --- /dev/null +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -0,0 +1,276 @@ +#ifndef TIME_DOMAIN_DISPLAY_PLOT_C +#define TIME_DOMAIN_DISPLAY_PLOT_C + +#include + +#include +#include + + +class TimePrecisionClass +{ +public: + TimePrecisionClass(const int timePrecision) + { + _timePrecision = timePrecision; + } + + virtual ~TimePrecisionClass() + { + } + + virtual unsigned int GetTimePrecision() const + { + return _timePrecision; + } + + virtual void SetTimePrecision(const unsigned int newPrecision) + { + _timePrecision = newPrecision; + } +protected: + unsigned int _timePrecision; +}; + + +class TimeDomainDisplayZoomer: public QwtPlotZoomer, public TimePrecisionClass +{ +public: + TimeDomainDisplayZoomer(QwtPlotCanvas* canvas, const unsigned int timePrecision) + : QwtPlotZoomer(canvas),TimePrecisionClass(timePrecision) + { + setTrackerMode(QwtPicker::AlwaysOn); + } + + virtual ~TimeDomainDisplayZoomer(){ + + } + + virtual void updateTrackerText(){ + updateDisplay(); + } + + void SetUnitType(const std::string &type) + { + _unitType = type; + } + +protected: + using QwtPlotZoomer::trackerText; + virtual QwtText trackerText( const QwtDoublePoint& p ) const + { + QwtText t(QString("%1 %2, %3 V").arg(p.x(), 0, 'f', GetTimePrecision()). + arg(_unitType.c_str()). + arg(p.y(), 0, 'f', 4)); + + return t; + } + +private: + std::string _unitType; +}; + +TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) +{ + timespec_reset(&_lastReplot); + + resize(parent->width(), parent->height()); + + _numPoints = 1024; + _realDataPoints = new double[_numPoints]; + _imagDataPoints = new double[_numPoints]; + _xAxisPoints = new double[_numPoints]; + + _zoomer = new TimeDomainDisplayZoomer(canvas(), 0); + + // Disable polygon clipping + QwtPainter::setDeviceClipping(false); + + // We don't need the cache here + canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); + canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); + + QPalette palette; + palette.setColor(canvas()->backgroundRole(), QColor("white")); + canvas()->setPalette(palette); + + setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine); + set_xaxis(0, _numPoints); + setAxisTitle(QwtPlot::xBottom, "Time (sec)"); + + setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); + set_yaxis(-2.0, 2.0); + setAxisTitle(QwtPlot::yLeft, "Normalized Voltage"); + + // 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)); + + _sampleRate = 1; + _resetXAxisPoints(); + + replot(); + +#if QT_VERSION < 0x040000 + _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, + Qt::RightButton, Qt::ControlModifier); +#else + _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, + Qt::RightButton, Qt::ControlModifier); +#endif + _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, + Qt::RightButton); + + _panner = new QwtPlotPanner(canvas()); + _panner->setAxisEnabled(QwtPlot::yRight, false); + _panner->setMouseButton(Qt::MidButton); + + // Avoid jumping when labels with more/less digits + // appear/disappear when scrolling vertically + + const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font()); + QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); + sd->setMinimumExtent( fm.width("100.00") ); + + const QColor c(Qt::darkRed); + _zoomer->setRubberBandPen(c); + _zoomer->setTrackerPen(c); + + QwtLegend* legendDisplay = new QwtLegend(this); + legendDisplay->setItemMode(QwtLegend::CheckableItem); + insertLegend(legendDisplay); + + connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ), + this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) )); +} + +TimeDomainDisplayPlot::~TimeDomainDisplayPlot(){ + delete[] _realDataPoints; + delete[] _imagDataPoints; + delete[] _xAxisPoints; + + // _fft_plot_curves deleted when parent deleted + // _zoomer and _panner deleted when parent deleted +} + +void +TimeDomainDisplayPlot::set_yaxis(double min, double max) +{ + setAxisScale(QwtPlot::yLeft, min, max); + _zoomer->setZoomBase(); +} + +void +TimeDomainDisplayPlot::set_xaxis(double min, double max) +{ + setAxisScale(QwtPlot::xBottom, min, max); + _zoomer->setZoomBase(); +} + + +void TimeDomainDisplayPlot::replot() +{ + QwtPlot::replot(); +} + +void +TimeDomainDisplayPlot::resizeSlot( QSize *s ) +{ + resize(s->width(), s->height()); +} + +void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, + const double* imagDataPoints, + const int64_t numDataPoints, + const double timeInterval) +{ + if((numDataPoints > 0) && + (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + + 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); + + _resetXAxisPoints(); + } + + memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); + memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); + + replot(); + + _lastReplot = get_highres_clock(); + } +} + +void TimeDomainDisplayPlot::SetImaginaryDataVisible(const bool visibleFlag) +{ + _imag_plot_curve->setVisible(visibleFlag); +} + +void TimeDomainDisplayPlot::_resetXAxisPoints() +{ + double delt = 1.0/_sampleRate; + for(long loc = 0; loc < _numPoints; loc++){ + _xAxisPoints[loc] = loc*delt; + } + setAxisScale(QwtPlot::xBottom, 0, _numPoints*delt); + + // Set up zoomer base for maximum unzoom x-axis + // and reset to maximum unzoom level + QwtDoubleRect zbase = _zoomer->zoomBase(); + zbase.setLeft(0); + zbase.setRight(_numPoints*delt); + _zoomer->zoom(zbase); + _zoomer->setZoomBase(zbase); + _zoomer->zoom(0); +} + +void TimeDomainDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on) +{ + plotItem->setVisible(!on); +} + +void +TimeDomainDisplayPlot::SetSampleRate(double sr, double units, + const std::string &strunits) +{ + double newsr = sr/units; + if(newsr != _sampleRate) { + _sampleRate = sr/units; + _resetXAxisPoints(); + + // While we could change the displayed sigfigs based on the unit being + // displayed, I think it looks better by just setting it to 4 regardless. + //double display_units = ceil(log10(units)/2.0); + double display_units = 4; + setAxisTitle(QwtPlot::xBottom, QString("Time (%1)").arg(strunits.c_str())); + ((TimeDomainDisplayZoomer*)_zoomer)->SetTimePrecision(display_units); + ((TimeDomainDisplayZoomer*)_zoomer)->SetUnitType(strunits); + } +} + +#endif /* TIME_DOMAIN_DISPLAY_PLOT_C */ -- cgit From b0f876b55549db96920c2b3bfee32de6748096af Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 6 Apr 2011 00:07:00 -0400 Subject: gr-qtgui: cleaning up unnecessary plotting calls. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 9c98cec5b..da28d0304 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -121,8 +121,6 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) _sampleRate = 1; _resetXAxisPoints(); - replot(); - #if QT_VERSION < 0x040000 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); @@ -220,8 +218,6 @@ void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); - replot(); - _lastReplot = get_highres_clock(); } } -- cgit From 41ad09b4f22228dd555ea73f2078cb9ff056b979 Mon Sep 17 00:00:00 2001 From: Mike Cornelius Date: Mon, 11 Apr 2011 00:48:29 -0400 Subject: gr-qtgui: adding double-click point selector to main gui widgets. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index da28d0304..be25a6cde 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -82,6 +82,7 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) _xAxisPoints = new double[_numPoints]; _zoomer = new TimeDomainDisplayZoomer(canvas(), 0); + _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); // Disable polygon clipping QwtPainter::setDeviceClipping(false); @@ -135,6 +136,15 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) _panner->setAxisEnabled(QwtPlot::yRight, false); _panner->setMouseButton(Qt::MidButton); + // emit the position of clicks on widget + _picker = new QwtDblClickPlotPicker(canvas()); + connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), + this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); + + // Configure magnify on mouse wheel + _magnifier = new QwtPlotMagnifier(canvas()); + _magnifier->setAxisEnabled(QwtPlot::xBottom, false); + // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically @@ -269,4 +279,12 @@ TimeDomainDisplayPlot::SetSampleRate(double sr, double units, } } +void +TimeDomainDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) +{ + QPointF point = p; + //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); + emit plotPointSelected(point); +} + #endif /* TIME_DOMAIN_DISPLAY_PLOT_C */ -- cgit From 7ba2647977f9b302969208fa8548d1ca8dcddd4b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 18 Apr 2011 23:07:31 -0400 Subject: gr-qtgui: adding copyright dates to qtgui files. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index be25a6cde..86aa8533e 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 -- cgit From 8b7b6e297e0d929aac2a604229a675d7fa46c3b1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 23 Apr 2011 10:59:36 -0400 Subject: gr-qtgui: no need to check the version here since we require >4.4 --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 86aa8533e..9e7b796e8 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -144,13 +144,8 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) _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 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); @@ -186,12 +181,12 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) )); } -TimeDomainDisplayPlot::~TimeDomainDisplayPlot(){ +TimeDomainDisplayPlot::~TimeDomainDisplayPlot() +{ delete[] _realDataPoints; delete[] _imagDataPoints; delete[] _xAxisPoints; - // _fft_plot_curves deleted when parent deleted // _zoomer and _panner deleted when parent deleted } -- cgit From 01f44f64c916b4aa38bc81662d2c8b82c4cc0b57 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 23 Apr 2011 14:30:32 -0400 Subject: gr-qtgui: moving towards allowing time plot to have multiple connections. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 66 ++++++++++++++++------------------- 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 9e7b796e8..c9973fbc2 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -27,7 +27,7 @@ #include #include - +#include class TimePrecisionClass { @@ -92,16 +92,16 @@ 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); @@ -125,21 +125,20 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) set_yaxis(-2.0, 2.0); setAxisTitle(QwtPlot::yLeft, "Normalized Voltage"); + // 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); + if(i == 0) + _plot_curve[i]->setPen(QPen(Qt::blue)); + else + _plot_curve[i]->setPen(QPen(Qt::red)); + _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); + } _sampleRate = 1; _resetXAxisPoints(); @@ -183,8 +182,8 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) TimeDomainDisplayPlot::~TimeDomainDisplayPlot() { - delete[] _realDataPoints; - delete[] _imagDataPoints; + for(int i = 0; i < _nplots; i++) + delete [] _dataPoints[i]; delete[] _xAxisPoints; // _zoomer and _panner deleted when parent deleted @@ -216,8 +215,8 @@ TimeDomainDisplayPlot::resizeSlot( QSize *s ) resize(s->width(), s->height()); } -void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, - const double* imagDataPoints, +void TimeDomainDisplayPlot::PlotNewData(const int which, + const double* dataPoints, const int64_t numDataPoints, const double timeInterval) { @@ -227,33 +226,28 @@ void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, if(numDataPoints != _numPoints){ _numPoints = numDataPoints; - delete[] _realDataPoints; - delete[] _imagDataPoints; + delete[] _dataPoints[which]; + _dataPoints[which] = new double[_numPoints]; + 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); + _plot_curve[which]->setRawData(_xAxisPoints, _dataPoints[which], _numPoints); set_xaxis(0, numDataPoints); _resetXAxisPoints(); } - memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); - memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); + std::cout << "DisplayPlot: " << which << std::endl; + memcpy(_dataPoints[which], dataPoints, numDataPoints*sizeof(double)); + std::cout << "after" << std::endl; - _lastReplot = get_highres_clock(); + if(which == _nplots-1) + _lastReplot = get_highres_clock(); } } -void TimeDomainDisplayPlot::SetImaginaryDataVisible(const bool visibleFlag) -{ - _imag_plot_curve->setVisible(visibleFlag); -} - void TimeDomainDisplayPlot::_resetXAxisPoints() { double delt = 1.0/_sampleRate; -- cgit From 0877adb2e194c9dfad2484519b2979e2bed93958 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 23 Apr 2011 15:11:17 -0400 Subject: gr-qtgui: Passing vectors of data to update plot for stability; also moving responsibility of keeping track of plot updates out to qtgui_sink instead of inside plot qidget. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index c9973fbc2..e3c773e4c 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -95,8 +95,6 @@ private: TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) : QwtPlot(parent), _nplots(nplots) { - timespec_reset(&_lastReplot); - resize(parent->width(), parent->height()); _numPoints = 1024; @@ -215,36 +213,30 @@ TimeDomainDisplayPlot::resizeSlot( QSize *s ) resize(s->width(), s->height()); } -void TimeDomainDisplayPlot::PlotNewData(const int which, - const double* dataPoints, +void TimeDomainDisplayPlot::PlotNewData(const std::vector 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[] _dataPoints[which]; - _dataPoints[which] = new double[_numPoints]; - delete[] _xAxisPoints; _xAxisPoints = new double[_numPoints]; - - _plot_curve[which]->setRawData(_xAxisPoints, _dataPoints[which], _numPoints); + for(int i = 0; i < _nplots; i++) { + delete[] _dataPoints[i]; + _dataPoints[i] = new double[_numPoints]; + _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); + } + set_xaxis(0, numDataPoints); - _resetXAxisPoints(); } - std::cout << "DisplayPlot: " << which << std::endl; - memcpy(_dataPoints[which], dataPoints, numDataPoints*sizeof(double)); - std::cout << "after" << std::endl; - - if(which == _nplots-1) - _lastReplot = get_highres_clock(); + for(int i = 0; i < _nplots; i++) { + memcpy(_dataPoints[i], dataPoints[i], numDataPoints*sizeof(double)); + } } } -- cgit From 350611ddd9295ba8af6ea5913630ec0670208b43 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 23 Apr 2011 23:56:52 -0400 Subject: gr-qtgui: multiple connections working, each with their own color. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index e3c773e4c..70b11dd0e 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -27,6 +27,7 @@ #include #include +#include #include class TimePrecisionClass @@ -122,7 +123,16 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); set_yaxis(-2.0, 2.0); setAxisTitle(QwtPlot::yLeft, "Normalized Voltage"); - + + //QColor clr(Qt::blue); + QList 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 for(int i = 0; i < _nplots; i++) { @@ -131,10 +141,7 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); _plot_curve[i]->attach(this); - if(i == 0) - _plot_curve[i]->setPen(QPen(Qt::blue)); - else - _plot_curve[i]->setPen(QPen(Qt::red)); + _plot_curve[i]->setPen(QPen(colors[i])); _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); } -- cgit From e251c885f19281ef918987e09c2aac1af6a952c2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 24 Apr 2011 00:31:39 -0400 Subject: gr-qtgui: provide function and slot for setting the labels of a time curve. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 70b11dd0e..28cca3aaa 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -208,6 +208,11 @@ TimeDomainDisplayPlot::set_xaxis(double min, double max) _zoomer->setZoomBase(); } +void +TimeDomainDisplayPlot::set_title(int which, QString title) +{ + _plot_curve[which]->setTitle(title); +} void TimeDomainDisplayPlot::replot() { -- cgit From 43a3a7296412dc52216e7f63856a86945f4ba438 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 24 Apr 2011 01:30:08 -0400 Subject: gr-qtgui: clean up --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 28cca3aaa..ee13a7dce 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -117,14 +117,13 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* 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"); - - //QColor clr(Qt::blue); + setYaxis(-2.0, 2.0); + setAxisTitle(QwtPlot::yLeft, "Amplitude"); + QList colors; colors << QColor(Qt::blue) << QColor(Qt::red) << QColor(Qt::green) << QColor(Qt::black) << QColor(Qt::cyan) << QColor(Qt::magenta) @@ -149,9 +148,9 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) _resetXAxisPoints(); _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, - Qt::RightButton, Qt::ControlModifier); + Qt::RightButton, Qt::ControlModifier); _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, - Qt::RightButton); + Qt::RightButton); _panner = new QwtPlotPanner(canvas()); _panner->setAxisEnabled(QwtPlot::yRight, false); @@ -195,21 +194,21 @@ TimeDomainDisplayPlot::~TimeDomainDisplayPlot() } 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::set_title(int which, QString title) +TimeDomainDisplayPlot::setTitle(int which, QString title) { _plot_curve[which]->setTitle(title); } @@ -242,7 +241,7 @@ void TimeDomainDisplayPlot::PlotNewData(const std::vector dataPoints, _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); } - set_xaxis(0, numDataPoints); + setXaxis(0, numDataPoints); _resetXAxisPoints(); } -- cgit From 11de76b9214a59930ac8d8c031880b5bd293973d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 24 Apr 2011 01:47:05 -0400 Subject: gr-qtgui: adding function and slot to set a time display curve's color. --- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index ee13a7dce..f635a2b0c 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -213,6 +213,12 @@ 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() { QwtPlot::replot(); @@ -221,7 +227,8 @@ 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 std::vector dataPoints, -- cgit