// Remove all stored data and reset all views
for (shared_ptr<views::ViewBase> view : views_) {
- view->clear_signals();
+ view->clear_signalbases();
#ifdef ENABLE_DECODE
view->clear_decode_signals();
#endif
signalbases_.clear();
logic_data_.reset();
for (shared_ptr<views::ViewBase>& view : views_) {
- view->clear_signals();
+ view->clear_signalbases();
#ifdef ENABLE_DECODE
view->clear_decode_signals();
#endif
signalbases_.clear();
logic_data_.reset();
for (shared_ptr<views::ViewBase>& view : views_) {
- view->clear_signals();
+ view->clear_signalbases();
#ifdef ENABLE_DECODE
view->clear_decode_signals();
#endif
[] (shared_ptr<Channel> channel) {
return channel->type() == sigrok::ChannelType::LOGIC; });
- // Create data containers for the logic data segments
+ // Create a common data container for the logic signalbases
{
lock_guard<recursive_mutex> data_lock(data_mutex_);
logic_data_.reset();
} else if (!logic_data_ ||
logic_data_->num_channels() != logic_channel_count) {
- logic_data_.reset(new data::Logic(
- logic_channel_count));
+ logic_data_.reset(new data::Logic(logic_channel_count));
assert(logic_data_);
}
}
- // Make the signals list
- for (shared_ptr<views::ViewBase>& viewbase : views_) {
- views::trace::View *trace_view =
- qobject_cast<views::trace::View*>(viewbase.get());
-
- if (trace_view) {
- vector< shared_ptr<Signal> > prev_sigs(trace_view->signals());
- trace_view->clear_signals();
-
- for (auto channel : sr_dev->channels()) {
- shared_ptr<data::SignalBase> signalbase;
- shared_ptr<Signal> signal;
-
- // Find the channel in the old signals
- const auto iter = find_if(
- prev_sigs.cbegin(), prev_sigs.cend(),
- [&](const shared_ptr<Signal> &s) {
- return s->base()->channel() == channel;
- });
- if (iter != prev_sigs.end()) {
- // Copy the signal from the old set to the new
- signal = *iter;
- trace_view->add_signal(signal);
- } else {
- // Find the signalbase for this channel if possible
- signalbase.reset();
- for (const shared_ptr<data::SignalBase>& b : signalbases_)
- if (b->channel() == channel)
- signalbase = b;
-
- shared_ptr<Signal> signal;
-
- switch(channel->type()->id()) {
- case SR_CHANNEL_LOGIC:
- if (!signalbase) {
- signalbase = make_shared<data::SignalBase>(channel,
- data::SignalBase::LogicChannel);
- signalbases_.push_back(signalbase);
-
- all_signal_data_.insert(logic_data_);
- signalbase->set_data(logic_data_);
-
- connect(this, SIGNAL(capture_state_changed(int)),
- signalbase.get(), SLOT(on_capture_state_changed(int)));
- }
-
- signal = shared_ptr<Signal>(new LogicSignal(*this, device_, signalbase));
- break;
-
- case SR_CHANNEL_ANALOG:
- {
- if (!signalbase) {
- signalbase = make_shared<data::SignalBase>(channel,
- data::SignalBase::AnalogChannel);
- signalbases_.push_back(signalbase);
-
- shared_ptr<data::Analog> data(new data::Analog());
- all_signal_data_.insert(data);
- signalbase->set_data(data);
-
- connect(this, SIGNAL(capture_state_changed(int)),
- signalbase.get(), SLOT(on_capture_state_changed(int)));
- }
-
- signal = shared_ptr<Signal>(new AnalogSignal(*this, signalbase));
- break;
- }
-
- default:
- assert(false);
- break;
- }
-
- // New views take their signal settings from the main view
- if (!viewbase->is_main_view()) {
- shared_ptr<pv::views::trace::View> main_tv =
- dynamic_pointer_cast<pv::views::trace::View>(main_view_);
- shared_ptr<Signal> main_signal =
- main_tv->get_signal_by_signalbase(signalbase);
- signal->restore_settings(main_signal->save_settings());
- }
-
- trace_view->add_signal(signal);
- }
+ // Create signalbases if necessary
+ for (auto channel : sr_dev->channels()) {
+
+ // Try to find the channel in the list of existing signalbases
+ const auto iter = find_if(signalbases_.cbegin(), signalbases_.cend(),
+ [&](const shared_ptr<SignalBase> &sb) { return sb->channel() == channel; });
+
+ // Not found, let's make a signalbase for it
+ if (iter == signalbases_.cend()) {
+ shared_ptr<SignalBase> signalbase;
+ switch(channel->type()->id()) {
+ case SR_CHANNEL_LOGIC:
+ signalbase = make_shared<data::SignalBase>(channel, data::SignalBase::LogicChannel);
+ signalbases_.push_back(signalbase);
+
+ all_signal_data_.insert(logic_data_);
+ signalbase->set_data(logic_data_);
+
+ connect(this, SIGNAL(capture_state_changed(int)),
+ signalbase.get(), SLOT(on_capture_state_changed(int)));
+ break;
+
+ case SR_CHANNEL_ANALOG:
+ signalbase = make_shared<data::SignalBase>(channel, data::SignalBase::AnalogChannel);
+ signalbases_.push_back(signalbase);
+
+ shared_ptr<data::Analog> data(new data::Analog());
+ all_signal_data_.insert(data);
+ signalbase->set_data(data);
+
+ connect(this, SIGNAL(capture_state_changed(int)),
+ signalbase.get(), SLOT(on_capture_state_changed(int)));
+ break;
}
}
}
+ for (shared_ptr<views::ViewBase>& viewbase : views_) {
+ vector< shared_ptr<SignalBase> > view_signalbases =
+ viewbase->signalbases();
+
+ // Add all non-decode signalbases that don't yet exist in the view
+ for (shared_ptr<SignalBase>& session_sb : signalbases_) {
+ if (session_sb->type() == SignalBase::DecodeChannel)
+ continue;
+
+ const auto iter = find_if(view_signalbases.cbegin(), view_signalbases.cend(),
+ [&](const shared_ptr<SignalBase> &sb) { return sb == session_sb; });
+
+ if (iter == view_signalbases.cend())
+ viewbase->add_signalbase(session_sb);
+ }
+
+ // Remove all non-decode signalbases that no longer exist
+ for (shared_ptr<SignalBase>& view_sb : view_signalbases) {
+ if (view_sb->type() == SignalBase::DecodeChannel)
+ continue;
+
+ const auto iter = find_if(signalbases_.cbegin(), signalbases_.cend(),
+ [&](const shared_ptr<SignalBase> &sb) { return sb == view_sb; });
+
+ if (iter == signalbases_.cend())
+ viewbase->remove_signalbase(view_sb);
+ }
+ }
+
signals_changed();
}
using std::copy_if;
using std::count_if;
using std::inserter;
+using std::lock_guard;
using std::max;
using std::make_pair;
using std::make_shared;
return ret_val;
}
-void View::clear_signals()
+void View::clear_signalbases()
{
- ViewBase::clear_signals();
+ ViewBase::clear_signalbases();
signals_.clear();
}
-void View::add_signal(const shared_ptr<Signal> signal)
+void View::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
{
- ViewBase::add_signalbase(signal->base());
+ ViewBase::add_signalbase(signalbase);
+
+ shared_ptr<Signal> signal;
+
+ switch (signalbase->type()) {
+ case SignalBase::LogicChannel:
+ signal = shared_ptr<Signal>(new LogicSignal(session_, session_.device(), signalbase));
+ break;
+
+ case SignalBase::AnalogChannel:
+ signal = shared_ptr<Signal>(new AnalogSignal(session_, signalbase));
+ break;
+
+ default:
+ qDebug() << "Unknown signalbase type:" << signalbase->type();
+ assert(false);
+ break;
+ }
+
signals_.push_back(signal);
signal->set_segment_display_mode(segment_display_mode_);
signal->set_current_segment(current_segment_);
+ // Secondary views use the signal's settings in the main view
+ if (!is_main_view()) {
+ shared_ptr<View> main_tv = dynamic_pointer_cast<View>(session_.main_view());
+ shared_ptr<Signal> main_signal = main_tv->get_signal_by_signalbase(signalbase);
+ if (main_signal)
+ signal->restore_settings(main_signal->save_settings());
+ }
+
connect(signal->base().get(), SIGNAL(name_changed(const QString&)),
this, SLOT(on_signal_name_changed()));
}
+void View::remove_signalbase(const shared_ptr<data::SignalBase> signalbase)
+{
+ ViewBase::remove_signalbase(signalbase);
+}
+
#ifdef ENABLE_DECODE
void View::clear_decode_signals()
{
if (!left_time || !right_time)
return make_pair(0, 0);
- assert(*left_time < *right_time);
+ assert(*left_time <= *right_time);
return make_pair(*left_time, *right_time);
}
{
using sigrok::Channel;
+ lock_guard<mutex> lock(signal_mutex_);
+
vector< shared_ptr<Channel> > channels;
shared_ptr<sigrok::Device> sr_dev;
bool signals_added_or_removed = false;
vector< shared_ptr<TraceTreeItem> > new_top_level_items;
// Make a list of traces that are being added, and a list of traces
- // that are being removed
+ // that are being removed. The set_difference() algorithms require
+ // both sets to be in the exact same order, which means that PD signals
+ // must always be last as they interrupt the sort order otherwise
const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>();
const set<shared_ptr<Trace>> prev_traces(
prev_trace_list.begin(), prev_trace_list.end());