X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Flogicsignal.cpp;h=75a125a7eae58f334427edd86b73f5531058b825;hb=448a72cf7f0225eace2335ec05b979c4e9a6b882;hp=7541bd1375aa90908d903ed9e3277e7b500d5614;hpb=7c4b01a19188234695a05f5d2ed2be290eca5cba;p=pulseview.git diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 7541bd13..75a125a7 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -30,6 +32,7 @@ #include "view.h" #include +#include #include #include #include @@ -38,6 +41,7 @@ using std::deque; using std::max; +using std::make_pair; using std::min; using std::pair; using std::shared_ptr; @@ -48,11 +52,16 @@ using sigrok::ConfigKey; using sigrok::Device; using sigrok::Error; using sigrok::Trigger; +using sigrok::TriggerStage; +using sigrok::TriggerMatch; 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); @@ -72,10 +81,12 @@ const QColor LogicSignal::SignalColours[10] = { QColor(0xEE, 0xEE, 0xEC), // White }; -LogicSignal::LogicSignal(shared_ptr device, - shared_ptr channel, - shared_ptr data) : - Signal(channel), +LogicSignal::LogicSignal( + pv::SigSession &session, + shared_ptr device, + shared_ptr channel, + shared_ptr data) : + Signal(session, channel), _device(device), _data(data), _trigger_none(NULL), @@ -92,7 +103,7 @@ LogicSignal::LogicSignal(shared_ptr device, /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ _trigger_match = nullptr; - if ((trigger = SigSession::_sr_session->trigger())) + if ((trigger = _session.session()->trigger())) for (auto stage : trigger->stages()) for (auto match : stage->matches()) if (match->channel() == _channel) @@ -113,10 +124,15 @@ shared_ptr LogicSignal::logic_data() const return _data; } +std::pair LogicSignal::v_extents() const +{ + return make_pair(-SignalHeight - SignalMargin, SignalMargin); +} + void LogicSignal::paint_back(QPainter &p, int left, int right) { if (_channel->enabled()) - paint_axis(p, get_y(), left, right); + paint_axis(p, get_visual_y(), left, right); } void LogicSignal::paint_mid(QPainter &p, int left, int right) @@ -130,19 +146,22 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) assert(_channel); assert(_data); assert(right >= left); + assert(_owner); + + const int y = get_visual_y(); - assert(_view); - const int y = _v_offset - _view->v_offset(); + const View *const view = _owner->view(); + assert(view); - const double scale = _view->scale(); + const double scale = view->scale(); assert(scale > 0); - const double offset = _view->offset(); + const double offset = view->offset(); if (!_channel->enabled()) return; - const float high_offset = y - View::SignalHeight + 0.5f; + const float high_offset = y - SignalHeight + 0.5f; const float low_offset = y + 0.5f; const deque< shared_ptr > &snapshots = @@ -258,24 +277,26 @@ QAction* LogicSignal::match_action(const TriggerMatchType *type) QAction *action; action = _trigger_none; - switch (type->id()) { - case SR_TRIGGER_ZERO: - action = _trigger_low; - break; - case SR_TRIGGER_ONE: - action = _trigger_high; - break; - case SR_TRIGGER_RISING: - action = _trigger_rising; - break; - case SR_TRIGGER_FALLING: - action = _trigger_falling; - break; - case SR_TRIGGER_EDGE: - action = _trigger_change; - break; - default: - assert(0); + if (type) { + switch (type->id()) { + case SR_TRIGGER_ZERO: + action = _trigger_low; + break; + case SR_TRIGGER_ONE: + action = _trigger_high; + break; + case SR_TRIGGER_RISING: + action = _trigger_rising; + break; + case SR_TRIGGER_FALLING: + action = _trigger_falling; + break; + case SR_TRIGGER_EDGE: + action = _trigger_change; + break; + default: + assert(0); + } } return action; @@ -313,6 +334,7 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) _trigger_bar = new QToolBar(parent); init_trigger_actions(_trigger_bar); _trigger_bar->addAction(_trigger_none); + _trigger_none->setChecked(!_trigger_match); trig_types = Glib::VariantBase::cast_dynamic>>( gvar).get(); @@ -325,16 +347,46 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) } +void LogicSignal::modify_trigger() +{ + auto trigger = _session.session()->trigger(); + auto new_trigger = _session.device_manager().context()->create_trigger("pulseview"); + + if (trigger) { + for (auto stage : trigger->stages()) { + const auto &matches = stage->matches(); + if (std::none_of(begin(matches), end(matches), + [&](shared_ptr match) { + return match->channel() != _channel; })) + continue; + + auto new_stage = new_trigger->add_stage(); + for (auto match : stage->matches()) { + if (match->channel() == _channel) + continue; + new_stage->add_match(match->channel(), match->type()); + } + } + } + + if (_trigger_match) + new_trigger->add_stage()->add_match(_channel, _trigger_match); + + _session.session()->set_trigger( + new_trigger->stages().empty() ? nullptr : new_trigger); +} + void LogicSignal::on_trigger() { QAction *action; - match_action(_trigger_match)->setChecked(FALSE); + match_action(_trigger_match)->setChecked(false); action = (QAction *)sender(); - action->setChecked(TRUE); + action->setChecked(true); _trigger_match = action_match(action); + modify_trigger(); } } // namespace view