From befadabc2f18b483c71250adfd7dbf42f66b16f0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> 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 0000000000..9c98cec5b0 --- /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 <TimeDomainDisplayPlot.h> + +#include <qwt_scale_draw.h> +#include <qwt_legend.h> + + +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 v1.2.3 From b0f876b55549db96920c2b3bfee32de6748096af Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Wed, 6 Apr 2011 00:07:00 -0400 Subject: gr-qtgui: cleaning up unnecessary plotting calls. --- gr-qtgui/apps/pyqt_example_c.py | 5 ----- gr-qtgui/lib/ConstellationDisplayPlot.cc | 4 ---- gr-qtgui/lib/FrequencyDisplayPlot.cc | 2 -- gr-qtgui/lib/TimeDomainDisplayPlot.cc | 4 ---- gr-qtgui/lib/spectrumdisplayform.cc | 8 +++----- 5 files changed, 3 insertions(+), 20 deletions(-) (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc') diff --git a/gr-qtgui/apps/pyqt_example_c.py b/gr-qtgui/apps/pyqt_example_c.py index 6625857a56..e1fb8a6beb 100755 --- a/gr-qtgui/apps/pyqt_example_c.py +++ b/gr-qtgui/apps/pyqt_example_c.py @@ -5,11 +5,6 @@ from gnuradio import qtgui from PyQt4 import QtGui, QtCore import sys, sip -import os -print os.getpid() -raw_input() - - class dialog_box(QtGui.QWidget): def __init__(self, display, control): QtGui.QWidget.__init__(self, None) diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index 9ad5bdd3c4..71933cece7 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -74,8 +74,6 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) memset(_realDataPoints, 0x0, _numPoints*sizeof(double)); memset(_imagDataPoints, 0x0, _numPoints*sizeof(double)); - replot(); - _zoomer = new ConstellationDisplayZoomer(canvas()); #if QT_VERSION < 0x040000 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, @@ -178,8 +176,6 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); - replot(); - _lastReplot = get_highres_clock(); } } diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index d150e2e4ce..45e2e6c168 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -367,8 +367,6 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat SetUpperIntensityLevel(_peakAmplitude); - replot(); - _lastReplot = get_highres_clock(); } } diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 9c98cec5b0..da28d03044 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(); } } diff --git a/gr-qtgui/lib/spectrumdisplayform.cc b/gr-qtgui/lib/spectrumdisplayform.cc index d85637a671..d4fc037810 100644 --- a/gr-qtgui/lib/spectrumdisplayform.cc +++ b/gr-qtgui/lib/spectrumdisplayform.cc @@ -59,6 +59,9 @@ SpectrumDisplayForm::SpectrumDisplayForm(bool useOpenGL, QWidget* parent) ToggleTabTime(false); ToggleTabConstellation(false); + _historyEntry = 0; + _historyEntryCount = 0; + // Create a timer to update plots at the specified rate displayTimer = new QTimer(this); connect(displayTimer, SIGNAL(timeout()), this, SLOT(UpdateGuiTimer())); @@ -74,11 +77,6 @@ SpectrumDisplayForm::~SpectrumDisplayForm() delete[] _realFFTDataPoints; delete[] _averagedValues; - //delete _frequencyDisplayPlot; - //delete _waterfallDisplayPlot; - //delete _timeDomainDisplayPlot; - //delete _constellationDisplayPlot; - for(unsigned int count = 0; count < _historyVector->size(); count++){ delete[] _historyVector->operator[](count); } -- cgit v1.2.3