]> sigrok.org Git - pulseview.git/commitdiff
Rework decode channel auto-assignment
authorSoeren Apel <redacted>
Tue, 13 Jun 2017 19:32:04 +0000 (21:32 +0200)
committerSoeren Apel <redacted>
Tue, 4 Jul 2017 21:14:36 +0000 (23:14 +0200)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/session.cpp

index 6bc691abb5d49a29185a6b404c80bb88f22a548f..5b2bb31d75e1217e7567d634f289eaab0985bd03 100644 (file)
@@ -36,13 +36,16 @@ using pv::data::decode::Row;
 namespace pv {
 namespace data {
 
-DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack) :
+DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack,
+       const unordered_set< shared_ptr<data::SignalBase> > &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<data::decode::Decoder>(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<data::DecodeChannel> 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<data::SignalBase> 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_)
index f9b866e27e583ce66b593516e6983e55937477ba..1444feae5e8d431e4c498d51735dbf3d922e3af6 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
 #define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
 
+#include <unordered_set>
 #include <vector>
 
 #include <QString>
@@ -29,6 +30,7 @@
 #include <pv/data/signalbase.hpp>
 
 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<pv::data::DecoderStack> decoder_stack);
+       DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack,
+               const unordered_set< shared_ptr<data::SignalBase> > &all_signals);
        virtual ~DecodeSignal();
 
        bool is_decode_signal() const;
@@ -76,6 +79,7 @@ public:
        QString error_message() const;
 
        const list<data::DecodeChannel> 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<pv::data::DecoderStack> decoder_stack_;
+       const unordered_set< shared_ptr<data::SignalBase> > &all_signals_;
        list<data::DecodeChannel> channels_;
 };
 
index fa5f95bb2ca7832cb6ba478524a70a564ba06ed3..07917e582ff2846d537fecaf755dfa4e125daae7 100644 (file)
@@ -665,23 +665,6 @@ bool Session::add_decoder(srd_decoder *const dec)
                // Create the decoder
                decoder_stack = make_shared<data::DecoderStack>(*this, dec);
 
-               // Make a list of all the channels
-               vector<const srd_channel*> 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<data::SignalBase> 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<data::DecodeSignal> signal =
-                       make_shared<data::DecodeSignal>(decoder_stack);
+                       make_shared<data::DecodeSignal>(decoder_stack, signalbases_);
 
                signalbases_.insert(signal);