]> sigrok.org Git - pulseview.git/commitdiff
Implement graphical display of A2L thresholds
authorSoeren Apel <redacted>
Mon, 31 Jul 2017 20:31:54 +0000 (22:31 +0200)
committerUwe Hermann <redacted>
Tue, 1 Aug 2017 12:42:20 +0000 (14:42 +0200)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/analogsignal.cpp
pv/views/trace/analogsignal.hpp

index 8ad8e068e933061ccbe2e0202194cb84fe2d0095..76966f4c93fdc4678bf50453ee96106ac78c22a9 100644 (file)
@@ -171,6 +171,10 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
                SLOT(on_view_showAnalogMinorGrid_changed(int)));
        trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), cb);
 
+       cb = create_checkbox(GlobalSettings::Key_View_ShowConversionThresholds,
+               SLOT(on_view_showConversionThresholds_changed(int)));
+       trace_view_layout->addRow(tr("Show conversion thresholds in analog traces"), cb);
+
        QSpinBox *default_div_height_sb = new QSpinBox();
        default_div_height_sb->setRange(20, 1000);
        default_div_height_sb->setSuffix(tr(" pixels"));
@@ -437,6 +441,12 @@ void Settings::on_view_showAnalogMinorGrid_changed(int state)
        settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
 }
 
+void Settings::on_view_showConversionThresholds_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_ShowConversionThresholds, state ? true : false);
+}
+
 void Settings::on_view_defaultDivHeight_changed(int value)
 {
        GlobalSettings settings;
index ca8291def8c7b2f496088b335d15f4025942e691..11277f7ae9563ac653d3378a421873214f5dfa8e 100644 (file)
@@ -56,6 +56,7 @@ private Q_SLOTS:
        void on_view_stickyScrolling_changed(int state);
        void on_view_showSamplingPoints_changed(int state);
        void on_view_showAnalogMinorGrid_changed(int state);
+       void on_view_showConversionThresholds_changed(int state);
        void on_view_defaultDivHeight_changed(int value);
        void on_view_defaultLogicHeight_changed(int value);
        void on_dec_initialStateConfigurable_changed(int state);
index 6ec4a8e95635677b20d3afa2abf66755f41ef15b..895dda54317e3aa4ec21653456d10f9adcef11a5 100644 (file)
@@ -36,6 +36,7 @@ const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
 const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling";
 const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints";
 const QString GlobalSettings::Key_View_ShowAnalogMinorGrid = "View_ShowAnalogMinorGrid";
+const QString GlobalSettings::Key_View_ShowConversionThresholds = "View_ShowConversionThresholds";
 const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight";
 const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
index 7bbff59fa9068d4b2f4650b5ea35b4521ddb1e0f..201c5e20a9fc23f95b72f0d2f0cf2b546f9cee0c 100644 (file)
@@ -46,6 +46,7 @@ public:
        static const QString Key_View_StickyScrolling;
        static const QString Key_View_ShowSamplingPoints;
        static const QString Key_View_ShowAnalogMinorGrid;
+       static const QString Key_View_ShowConversionThresholds;
        static const QString Key_View_DefaultDivHeight;
        static const QString Key_View_DefaultLogicHeight;
        static const QString Key_Dec_InitialStateConfigurable;
index 930780731e1a550acf23c25602e11d59c334dc72..c40c93b028a341d2e8c2329313d16acde193c925 100644 (file)
@@ -75,6 +75,8 @@ const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
 
 const QColor AnalogSignal::SamplingPointColour(0x77, 0x77, 0x77);
 
+const QColor AnalogSignal::ThresholdColor = QColor(0, 0, 0, 30 * 256 / 100);
+
 const int64_t AnalogSignal::TracePaintBlockSize = 1024 * 1024;  // 4 MiB (due to float)
 const float AnalogSignal::EnvelopeThreshold = 64.0f;
 
@@ -242,11 +244,15 @@ void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                                pixels_offset, samples_per_pixel);
        }
 
-       if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth)) {
-               const SignalBase::ConversionType conv_type = base_->get_conversion_type();
+       const SignalBase::ConversionType conv_type = base_->get_conversion_type();
+
+       if (((conv_type == SignalBase::A2LConversionByThreshold) ||
+               (conv_type == SignalBase::A2LConversionBySchmittTrigger))) {
+
+               if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth))
+                       paint_conversion_thresholds(p, pp);
 
-               if (((conv_type == SignalBase::A2LConversionByThreshold) ||
-                       (conv_type == SignalBase::A2LConversionBySchmittTrigger)))
+               if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth))
                        paint_logic_mid(p, pp);
        }
 }
@@ -434,6 +440,44 @@ void AnalogSignal::paint_envelope(QPainter &p,
        delete[] e.samples;
 }
 
+void AnalogSignal::paint_conversion_thresholds(QPainter &p,
+       ViewItemPaintParams &pp)
+{
+       if (!base_->enabled() || !base_->logic_data())
+               return;
+
+       // TODO Register a change handler instead of querying this with every repaint
+       GlobalSettings settings;
+       const bool show_conversion_thresholds =
+               settings.value(GlobalSettings::Key_View_ShowConversionThresholds).toBool();
+
+       if (!show_conversion_thresholds)
+               return;
+
+       const vector<double> thresholds = base_->get_conversion_thresholds();
+       const int y = get_visual_y();
+
+       p.setRenderHint(QPainter::Antialiasing, false);
+
+       p.setPen(ThresholdColor);
+
+       if (thresholds.size() == 2) {
+               // Draw as hatched block because two thresholds denote lower/upper level
+               const double thr_y0 = y - thresholds[0] * scale_;
+               const double thr_y1 = y - thresholds[1] * scale_;
+               p.fillRect(QRect(pp.left(), thr_y0, pp.right(), thr_y1 - thr_y0),
+                       QBrush(ThresholdColor, Qt::BDiagPattern));
+       } else {
+               // Draw as individual lines
+               for (const double thr : thresholds) {
+                       const double thr_y = y - thr * scale_;
+                       p.drawLine(QPointF(pp.left(), thr_y), QPointF(pp.right(), thr_y));
+               }
+       }
+
+       p.setRenderHint(QPainter::Antialiasing, true);
+}
+
 void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        QLineF *line;
index 7dc1e0d9de9917135c7e1dbb60747e1fbdfca11f..37b0c1a3ccdae7db9d89db07f2871abf8056473f 100644 (file)
@@ -50,6 +50,7 @@ private:
        static const QColor SignalColours[4];
        static const QColor GridMajorColor, GridMinorColor;
        static const QColor SamplingPointColour;
+       static const QColor ThresholdColor;
 
        static const int64_t TracePaintBlockSize;
        static const float EnvelopeThreshold;
@@ -131,6 +132,8 @@ private:
                int y, int left, const int64_t start, const int64_t end,
                const double pixels_offset, const double samples_per_pixel);
 
+       void paint_conversion_thresholds(QPainter &p, ViewItemPaintParams &pp);
+
        void paint_logic_mid(QPainter &p, ViewItemPaintParams &pp);
 
        void paint_logic_caps(QPainter &p, QLineF *const lines,