#include <cassert>
#include <cmath>
+#include <algorithm>
+
#include <QFormLayout>
#include <QToolBar>
#include "view.h"
#include <pv/sigsession.h>
+#include <pv/devicemanager.h>
#include <pv/data/logic.h>
#include <pv/data/logicsnapshot.h>
#include <pv/view/view.h>
using sigrok::Device;
using sigrok::Error;
using sigrok::Trigger;
+using sigrok::TriggerStage;
+using sigrok::TriggerMatch;
using sigrok::TriggerMatchType;
namespace pv {
QColor(0xEE, 0xEE, 0xEC), // White
};
-LogicSignal::LogicSignal(shared_ptr<Device> device,
- shared_ptr<Channel> channel,
- shared_ptr<data::Logic> data) :
- Signal(channel),
+LogicSignal::LogicSignal(
+ pv::SigSession &session,
+ shared_ptr<Device> device,
+ shared_ptr<Channel> channel,
+ shared_ptr<data::Logic> data) :
+ Signal(session, channel),
_device(device),
_data(data),
_trigger_none(NULL),
/* 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)
assert(_channel);
assert(_data);
assert(right >= left);
+ assert(_owner);
- assert(_view);
- const int y = _v_offset - _view->v_offset();
+ const int y = get_y();
- const double scale = _view->scale();
+ const View *const view = _owner->view();
+ assert(view);
+
+ const double scale = view->scale();
assert(scale > 0);
- const double offset = _view->offset();
+ const double offset = view->offset();
if (!_channel->enabled())
return;
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;
{
Glib::VariantContainerBase gvar;
vector<int32_t> trig_types;
- bool is_checked;
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);
trig_types =
Glib::VariantBase::cast_dynamic<Glib::Variant<vector<int32_t>>>(
gvar).get();
for (auto type_id : trig_types) {
auto type = TriggerMatchType::get(type_id);
_trigger_bar->addAction(match_action(type));
- is_checked = _trigger_match == type;
- match_action(type)->setChecked(is_checked);
+ match_action(type)->setChecked(_trigger_match == type);
}
form->addRow(tr("Trigger"), _trigger_bar);
}
+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<TriggerMatch> 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