X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Flogicsignal.cpp;h=c23f09226cd9bfaa2cbaf3d362eca7065ad69088;hp=af992c6bac175391ffd7a3941f59c1a1ae036266;hb=fcc00c4d9d3c4e00a3e15bff666e0ceedfa9d0ea;hpb=3eb29afdb641606c2e2e059289d8cc103d027a25 diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index af992c6b..c23f0922 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -33,11 +34,12 @@ #include #include +#include #include -#include +#include #include -#include +#include using std::deque; using std::max; @@ -49,7 +51,6 @@ using std::vector; using sigrok::Channel; using sigrok::ConfigKey; -using sigrok::Device; using sigrok::Error; using sigrok::Trigger; using sigrok::TriggerStage; @@ -59,9 +60,6 @@ using sigrok::TriggerMatchType; namespace pv { namespace view { -const int LogicSignal::SignalHeight = 30; -const int LogicSignal::SignalMargin = 10; - const float LogicSignal::Oversampling = 2.0f; const QColor LogicSignal::EdgeColour(0x80, 0x80, 0x80); @@ -99,18 +97,19 @@ QCache LogicSignal::pixmap_cache_; LogicSignal::LogicSignal( pv::Session &session, - shared_ptr device, + shared_ptr device, shared_ptr channel, shared_ptr data) : Signal(session, channel), + signal_height_(QFontMetrics(QApplication::font()).height() * 2), device_(device), data_(data), - trigger_none_(NULL), - trigger_rising_(NULL), - trigger_high_(NULL), - trigger_falling_(NULL), - trigger_low_(NULL), - trigger_change_(NULL) + trigger_none_(nullptr), + trigger_rising_(nullptr), + trigger_high_(nullptr), + trigger_falling_(nullptr), + trigger_low_(nullptr), + trigger_change_(nullptr) { shared_ptr trigger; @@ -140,21 +139,38 @@ shared_ptr LogicSignal::logic_data() const return data_; } +void LogicSignal::set_logic_data(std::shared_ptr data) +{ + data_ = data; +} + std::pair LogicSignal::v_extents() const { - return make_pair(-SignalHeight - SignalMargin, SignalMargin); + const int signal_margin = + QFontMetrics(QApplication::font()).height() / 2; + return make_pair(-signal_height_ - signal_margin, signal_margin); } -void LogicSignal::paint_back(QPainter &p, const RowItemPaintParams &pp) +int LogicSignal::scale_handle_offset() const { - if (channel_->enabled()) - paint_axis(p, get_visual_y(), pp.left(), pp.right()); + return -signal_height_; } -void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) +void LogicSignal::scale_handle_dragged(int offset) { - using pv::view::View; + const int font_height = QFontMetrics(QApplication::font()).height(); + const int units = (-offset / font_height); + signal_height_ = ((units < 1) ? 1 : units) * font_height; +} +void LogicSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp) +{ + if (channel_->enabled()) + paint_axis(p, pp, get_visual_y()); +} + +void LogicSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) +{ QLineF *line; vector< pair > edges; @@ -165,44 +181,39 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const int y = get_visual_y(); - const View *const view = owner_->view(); - assert(view); - - const double scale = view->scale(); - assert(scale > 0); - - const double offset = view->offset(); - if (!channel_->enabled()) return; - const float high_offset = y - SignalHeight + 0.5f; + const float high_offset = y - signal_height_ + 0.5f; const float low_offset = y + 0.5f; - const deque< shared_ptr > &snapshots = - data_->get_snapshots(); - if (snapshots.empty()) + const deque< shared_ptr > &segments = + data_->logic_segments(); + if (segments.empty()) return; - const shared_ptr &snapshot = - snapshots.front(); + const shared_ptr &segment = + segments.front(); - double samplerate = data_->samplerate(); + double samplerate = segment->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) samplerate = 1.0; - const double pixels_offset = offset / scale; - const double start_time = data_->get_start_time(); - const int64_t last_sample = snapshot->get_sample_count() - 1; - const double samples_per_pixel = samplerate * scale; - const double start = samplerate * (offset - start_time); - const double end = start + samples_per_pixel * pp.width(); + const double pixels_offset = pp.pixels_offset(); + const pv::util::Timestamp& start_time = segment->start_time(); + const int64_t last_sample = segment->get_sample_count() - 1; + const double samples_per_pixel = samplerate * pp.scale(); + const pv::util::Timestamp start = samplerate * (pp.offset() - start_time); + const pv::util::Timestamp end = start + samples_per_pixel * pp.width(); + + const int64_t start_sample = min(max(floor(start).convert_to(), + (int64_t)0), last_sample); + const uint64_t end_sample = min(max(ceil(end).convert_to(), + (int64_t)0), last_sample); - snapshot->get_subsampled_edges(edges, - min(max((int64_t)floor(start), (int64_t)0), last_sample), - min(max((int64_t)ceil(end), (int64_t)0), last_sample), + segment->get_subsampled_edges(edges, start_sample, end_sample, samples_per_pixel / Oversampling, channel_->index()); assert(edges.size() >= 2); @@ -235,7 +246,7 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) delete[] cap_lines; } -void LogicSignal::paint_fore(QPainter &p, const RowItemPaintParams &pp) +void LogicSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp) { // Draw the trigger marker if (!trigger_match_) @@ -256,15 +267,15 @@ void LogicSignal::paint_fore(QPainter &p, const RowItemPaintParams &pp) if (!pixmap) continue; - const int pad = TriggerMarkerPadding; + const float pad = TriggerMarkerPadding - 0.5f; const QSize size = pixmap->size(); const QPoint point( pp.right() - size.width() - pad * 2, - y - (SignalHeight + size.height()) / 2); + y - (signal_height_ + size.height()) / 2); - p.setPen(QPen(Qt::NoPen)); + p.setPen(QPen(TriggerMarkerBackgroundColour.darker())); p.setBrush(TriggerMarkerBackgroundColour); - p.drawRoundedRect(QRect(point, size).adjusted( + p.drawRoundedRect(QRectF(point, size).adjusted( -pad, -pad, pad, pad), pad, pad); p.drawPixmap(point, *pixmap); @@ -326,14 +337,23 @@ void LogicSignal::init_trigger_actions(QWidget *parent) const vector LogicSignal::get_trigger_types() const { - try { - const Glib::VariantContainerBase gvar = - device_->config_list(ConfigKey::TRIGGER_MATCH); - return Glib::VariantBase::cast_dynamic< - Glib::Variant>>(gvar).get(); - } catch (Error e) { - return vector(); + const auto sr_dev = device_->device(); + const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); + const auto iter = keys.find(ConfigKey::TRIGGER_MATCH); + if (iter != keys.end() && + (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { + try { + const Glib::VariantContainerBase gvar = + sr_dev->config_list(ConfigKey::TRIGGER_MATCH); + return Glib::VariantBase::cast_dynamic< + Glib::Variant>>(gvar).get(); + } catch (Error e) { + // Failed to enumerate triggers + (void)e; + } } + + return vector(); } QAction* LogicSignal::action_from_trigger_type(const TriggerMatchType *type) @@ -386,21 +406,23 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) { Signal::populate_popup_form(parent, form); - trigger_bar_ = new QToolBar(parent); - init_trigger_actions(trigger_bar_); - trigger_bar_->addAction(trigger_none_); - trigger_none_->setChecked(!trigger_match_); - const vector trig_types = get_trigger_types(); - for (auto type_id : trig_types) { - const TriggerMatchType *const type = - TriggerMatchType::get(type_id); - QAction *const action = action_from_trigger_type(type); - trigger_bar_->addAction(action); - action->setChecked(trigger_match_ == type); - } - form->addRow(tr("Trigger"), trigger_bar_); + if (!trig_types.empty()) { + trigger_bar_ = new QToolBar(parent); + init_trigger_actions(trigger_bar_); + trigger_bar_->addAction(trigger_none_); + trigger_none_->setChecked(!trigger_match_); + + for (auto type_id : trig_types) { + const TriggerMatchType *const type = + TriggerMatchType::get(type_id); + QAction *const action = action_from_trigger_type(type); + trigger_bar_->addAction(action); + action->setChecked(trigger_match_ == type); + } + form->addRow(tr("Trigger"), trigger_bar_); + } } void LogicSignal::modify_trigger() @@ -411,7 +433,7 @@ void LogicSignal::modify_trigger() if (trigger) { for (auto stage : trigger->stages()) { const auto &matches = stage->matches(); - if (std::none_of(begin(matches), end(matches), + if (std::none_of(matches.begin(), matches.end(), [&](shared_ptr match) { return match->channel() != channel_; })) continue; @@ -425,14 +447,21 @@ void LogicSignal::modify_trigger() } } - if (trigger_match_) - new_trigger->add_stage()->add_match(channel_, trigger_match_); + if (trigger_match_) { + // Until we can let the user decide how to group trigger matches + // into stages, put all of the matches into a single stage -- + // most devices only support a single trigger stage. + if (new_trigger->stages().empty()) + new_trigger->add_stage(); + + new_trigger->stages().back()->add_match(channel_, trigger_match_); + } session_.session()->set_trigger( new_trigger->stages().empty() ? nullptr : new_trigger); if (owner_) - owner_->appearance_changed(false, true); + owner_->row_item_appearance_changed(false, true); } const QIcon* LogicSignal::get_icon(const char *path)