From: Soeren Apel Date: Tue, 13 Jun 2017 19:32:04 +0000 (+0200) Subject: Rework decode channel auto-assignment X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=132a5c6d4b3c220d1cb6d942bf9d7e8b180ab1c3;p=pulseview.git Rework decode channel auto-assignment --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 6bc691ab..5b2bb31d 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -36,13 +36,16 @@ using pv::data::decode::Row; namespace pv { namespace data { -DecodeSignal::DecodeSignal(shared_ptr decoder_stack) : +DecodeSignal::DecodeSignal(shared_ptr decoder_stack, + const unordered_set< shared_ptr > &all_signals) : SignalBase(nullptr, SignalBase::DecodeChannel), - decoder_stack_(decoder_stack) + decoder_stack_(decoder_stack), + all_signals_(all_signals) { set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name)); update_channel_list(); + auto_assign_signals(); connect(decoder_stack_.get(), SIGNAL(new_annotations()), this, SLOT(on_new_annotations())); @@ -72,7 +75,11 @@ void DecodeSignal::stack_decoder(srd_decoder *decoder) assert(decoder); assert(decoder_stack); decoder_stack_->push(make_shared(decoder)); + + // Include the newly created decode channels in the channel list update_channel_list(); + + auto_assign_signals(); decoder_stack_->begin_decode(); } @@ -113,6 +120,19 @@ const list DecodeSignal::get_channels() const return channels_; } +void DecodeSignal::auto_assign_signals() +{ + // Try to auto-select channels that don't have signals assigned yet + for (data::DecodeChannel &ch : channels_) { + if (ch.assigned_signal) + continue; + + for (shared_ptr s : all_signals_) + if (s->logic_data() && (ch.name.toLower().contains(s->name().toLower()))) + ch.assigned_signal = s.get(); + } +} + void DecodeSignal::assign_signal(const uint16_t channel_id, const SignalBase *signal) { for (data::DecodeChannel &ch : channels_) diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index f9b866e2..1444feae 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -20,6 +20,7 @@ #ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP #define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP +#include #include #include @@ -29,6 +30,7 @@ #include using std::list; +using std::unordered_set; using std::vector; using std::shared_ptr; @@ -62,7 +64,8 @@ class DecodeSignal : public SignalBase Q_OBJECT public: - DecodeSignal(shared_ptr decoder_stack); + DecodeSignal(shared_ptr decoder_stack, + const unordered_set< shared_ptr > &all_signals); virtual ~DecodeSignal(); bool is_decode_signal() const; @@ -76,6 +79,7 @@ public: QString error_message() const; const list get_channels() const; + void auto_assign_signals(); void assign_signal(const uint16_t channel_id, const SignalBase *signal); void set_initial_pin_state(const uint16_t channel_id, const int init_state); @@ -102,6 +106,7 @@ private Q_SLOTS: private: shared_ptr decoder_stack_; + const unordered_set< shared_ptr > &all_signals_; list channels_; }; diff --git a/pv/session.cpp b/pv/session.cpp index fa5f95bb..07917e58 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -665,23 +665,6 @@ bool Session::add_decoder(srd_decoder *const dec) // Create the decoder decoder_stack = make_shared(*this, dec); - // Make a list of all the channels - vector all_channels; - for (const GSList *i = dec->channels; i; i = i->next) - all_channels.push_back((const srd_channel*)i->data); - for (const GSList *i = dec->opt_channels; i; i = i->next) - all_channels.push_back((const srd_channel*)i->data); - - // Auto select the initial channels - for (const srd_channel *pdch : all_channels) - for (shared_ptr b : signalbases_) { - if (b->logic_data()) { - if (QString::fromUtf8(pdch->name).toLower(). - contains(b->name().toLower())) - channels[pdch] = b; - } - } - assert(decoder_stack); assert(!decoder_stack->stack().empty()); assert(decoder_stack->stack().front()); @@ -689,7 +672,7 @@ bool Session::add_decoder(srd_decoder *const dec) // Create the decode signal shared_ptr signal = - make_shared(decoder_stack); + make_shared(decoder_stack, signalbases_); signalbases_.insert(signal);