Fixing displayed pen and x-axis to report the right units and scaling of frequencies.
authorTom Rondeau <trondeau@vt.edu>
Sat, 1 May 2010 21:36:07 +0000 (17:36 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sat, 1 May 2010 21:36:07 +0000 (17:36 -0400)
gr-qtgui/src/lib/WaterfallDisplayPlot.cc
gr-qtgui/src/lib/WaterfallDisplayPlot.h

index f6d0cc0ba77c5e67e3cad8b44cb68b37a3f5424d..b23612524fe2df3bce71417f91d11a4ac9e5038d 100644 (file)
@@ -66,8 +66,7 @@ public:
 
   QwtText label(double value) const
   {
-    return QString("%1").arg((value + GetCenterFrequency()) / ((GetFrequencyPrecision() == 0) ? 1.0 : 1000.0), 
-                            0, 'f', GetFrequencyPrecision());
+    return QString("%1").arg(value, 0, 'f', GetFrequencyPrecision());
   }
 
   virtual void initiateUpdate()
@@ -180,6 +179,11 @@ public:
     updateDisplay();
   }
 
+  void SetUnitType(const std::string &type)
+  {
+    _unitType = type;
+  }
+
 protected:
   virtual QwtText trackerText( const QwtDoublePoint& p ) const 
   {
@@ -193,10 +197,14 @@ protected:
                                  timeTm.tm_mday, timeTm.tm_hour, timeTm.tm_min,
                                  timeTm.tm_sec, lineTime.tv_nsec/1000000));
 
-    QwtText t(QString("%1 %2, %3").arg((p.x() + GetCenterFrequency()) / ((GetFrequencyPrecision() == 0) ? 1.0 : 1000.0), 0, 'f', GetFrequencyPrecision()).arg( (GetFrequencyPrecision() == 0) ? "Hz" : "kHz").arg(yLabel));
+    QwtText t(QString("%1 %2, %3").arg(p.x(), 0, 'f',
+                                      GetFrequencyPrecision()).arg(_unitType.c_str()).arg(yLabel));
 
     return t;
   }
+
+private:
+  std::string _unitType;
 };
 
 
@@ -310,27 +318,39 @@ WaterfallDisplayPlot::SetFrequencyRange(const double constStartFreq,
   double stopFreq = constStopFreq / units;
   double centerFreq = constCenterFreq / units;
 
-  if(stopFreq > startFreq) {
-    _startFrequency = 1000*startFreq;
-    _stopFrequency = 1000*stopFreq;
+  _useCenterFrequencyFlag = useCenterFrequencyFlag;
+
+  if(_useCenterFrequencyFlag){
+    startFreq = (startFreq + centerFreq);
+    stopFreq = (stopFreq + centerFreq);
+  }
+
+  bool reset = false;
+  if((startFreq != _startFrequency) || (stopFreq != _stopFrequency))
+    reset = true;
 
-    setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
+  if(stopFreq > startFreq) {
+    _startFrequency = startFreq;
+    _stopFrequency = stopFreq;
 
     if((axisScaleDraw(QwtPlot::xBottom) != NULL) && (_zoomer != NULL)){
-      WaterfallFreqDisplayScaleDraw* freqScale = ((WaterfallFreqDisplayScaleDraw*)axisScaleDraw(QwtPlot::xBottom));
-      freqScale->SetCenterFrequency(centerFreq);
-      ((WaterfallZoomer*)_zoomer)->SetCenterFrequency(centerFreq);
+      double display_units = ceil(log10(units)/2.0);
+      setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
+      setAxisScaleDraw(QwtPlot::xBottom, new WaterfallFreqDisplayScaleDraw(display_units));
 
-      freqScale->SetFrequencyPrecision( 2 );
-      ((WaterfallZoomer*)_zoomer)->SetFrequencyPrecision( 2 );
-      setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
-    }
+      if(reset) {
+       Reset();
+      }
 
-    Reset();
+      ((WaterfallZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
+      ((WaterfallZoomer*)_zoomer)->SetUnitType(strunits);
 
-    // Only replot if screen is visible
-    if(isVisible()){
-      replot();
+      // Load up the new base zoom settings
+      _zoomer->setZoomBase();
+      
+      // Zooms back to the base and clears any other zoom levels
+      _zoomer->zoom(0);
     }
   }
 }
index bb87fb09f4944fbcd7474db0b4b798eb9e10e89e..18e10aae94d6310bce17a3c41a519e2c096c8797 100644 (file)
@@ -69,6 +69,8 @@ private:
 
   timespec _lastReplot;
 
+  bool _useCenterFrequencyFlag;
+
   int64_t _numPoints;
 
   double _displayIntervalTime;