From: Soeren Apel Date: Mon, 31 Jul 2017 20:31:54 +0000 (+0200) Subject: Implement graphical display of A2L thresholds X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4433246b9ef4247ff469ae7307606a6d872c573f;p=pulseview.git Implement graphical display of A2L thresholds --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 8ad8e068..76966f4c 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index ca8291de..11277f7a 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -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); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 6ec4a8e9..895dda54 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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"; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 7bbff59f..201c5e20 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index 93078073..c40c93b0 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -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 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; diff --git a/pv/views/trace/analogsignal.hpp b/pv/views/trace/analogsignal.hpp index 7dc1e0d9..37b0c1a3 100644 --- a/pv/views/trace/analogsignal.hpp +++ b/pv/views/trace/analogsignal.hpp @@ -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,