From: Soeren Apel Date: Thu, 7 May 2020 20:26:14 +0000 (+0200) Subject: SignalBase: Add SignalGroup class and handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=554af71bf515d2763ca13c3829dbeb2064cc4c83;p=pulseview.git SignalBase: Add SignalGroup class and handling --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 2b38fe1e..70580aef 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -45,9 +45,55 @@ const int SignalBase::ColorBGAlpha = 8 * 256 / 100; const uint64_t SignalBase::ConversionBlockSize = 4096; const uint32_t SignalBase::ConversionDelay = 1000; // 1 second + +SignalGroup::SignalGroup(const QString& name) +{ + name_ = name; +} + +void SignalGroup::append_signal(shared_ptr signal) +{ + if (!signal) + return; + + signals_.push_back(signal); + signal->set_group(this); +} + +void SignalGroup::remove_signal(shared_ptr signal) +{ + if (!signal) + return; + + signals_.erase(std::remove_if(signals_.begin(), signals_.end(), + [&](shared_ptr s) { return s == signal; }), + signals_.end()); +} + +deque> SignalGroup::signals() const +{ + return signals_; +} + +void SignalGroup::clear() +{ + for (shared_ptr sb : signals_) + sb->set_group(nullptr); + + signals_.clear(); +} + +const QString SignalGroup::name() const +{ + return name_; +} + + + SignalBase::SignalBase(shared_ptr channel, ChannelType channel_type) : channel_(channel), channel_type_(channel_type), + group_(nullptr), conversion_type_(NoConversion), min_value_(0), max_value_(0) @@ -73,39 +119,6 @@ shared_ptr SignalBase::channel() const return channel_; } -QString SignalBase::name() const -{ - return (channel_) ? QString::fromStdString(channel_->name()) : name_; -} - -QString SignalBase::internal_name() const -{ - return internal_name_; -} - -void SignalBase::set_internal_name(QString internal_name) -{ - internal_name_ = internal_name; -} - -QString SignalBase::display_name() const -{ - if ((name() != internal_name_) && (!internal_name_.isEmpty())) - return name() + " (" + internal_name_ + ")"; - else - return name(); -} - -void SignalBase::set_name(QString name) -{ - if (channel_) - channel_->set_name(name.toUtf8().constData()); - - name_ = name; - - name_changed(name); -} - bool SignalBase::enabled() const { return (channel_) ? channel_->enabled() : true; @@ -142,6 +155,49 @@ unsigned int SignalBase::logic_bit_index() const return 0; } +void SignalBase::set_group(SignalGroup* group) +{ + group_ = group; +} + +SignalGroup* SignalBase::group() const +{ + return group_; +} + +QString SignalBase::name() const +{ + return (channel_) ? QString::fromStdString(channel_->name()) : name_; +} + +QString SignalBase::internal_name() const +{ + return internal_name_; +} + +void SignalBase::set_internal_name(QString internal_name) +{ + internal_name_ = internal_name; +} + +QString SignalBase::display_name() const +{ + if ((name() != internal_name_) && (!internal_name_.isEmpty())) + return name() + " (" + internal_name_ + ")"; + else + return name(); +} + +void SignalBase::set_name(QString name) +{ + if (channel_) + channel_->set_name(name.toUtf8().constData()); + + name_ = name; + + name_changed(name); +} + QColor SignalBase::color() const { return color_; diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 7e119652..f646a40d 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -22,6 +22,7 @@ #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP #include +#include #include #include #include @@ -39,6 +40,8 @@ using std::atomic; using std::condition_variable; +using std::deque; +using std::enable_shared_from_this; using std::map; using std::mutex; using std::pair; @@ -58,9 +61,30 @@ class DecoderStack; class Logic; class LogicSegment; class Segment; +class SignalBase; class SignalData; -class SignalBase : public QObject +class SignalGroup : public QObject +{ + Q_OBJECT + +public: + SignalGroup(const QString& name); + + void append_signal(shared_ptr signal); + void remove_signal(shared_ptr signal); + deque> signals() const; + void clear(); + + const QString name() const; + +private: + deque> signals_; + QString name_; +}; + + +class SignalBase : public QObject, public enable_shared_from_this { Q_OBJECT @@ -141,6 +165,16 @@ public: */ unsigned int logic_bit_index() const; + /** + * Sets the signal group this signal belongs to + */ + void set_group(SignalGroup* group); + + /** + * Returns the signal group this signal belongs to or nullptr if none + */ + SignalGroup* group() const; + /** * Gets the name of this signal. */ @@ -351,6 +385,7 @@ private Q_SLOTS: protected: shared_ptr channel_; ChannelType channel_type_; + SignalGroup* group_; shared_ptr data_; shared_ptr converted_data_; ConversionType conversion_type_; diff --git a/pv/session.cpp b/pv/session.cpp index 85b6c0b4..9ec8bd07 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -105,6 +105,7 @@ using Gst::ElementFactory; using Gst::Pipeline; #endif +using pv::data::SignalGroup; using pv::util::Timestamp; using pv::views::trace::Signal; using pv::views::trace::AnalogSignal; @@ -131,6 +132,11 @@ Session::~Session() // Stop and join to the thread stop_capture(); + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } } DeviceManager& Session::device_manager() @@ -509,8 +515,16 @@ void Session::set_device(shared_ptr device) #endif view->reset_view_state(); } + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } + signal_groups_.clear(); + for (const shared_ptr& d : all_signal_data_) d->clear(); + all_signal_data_.clear(); signalbases_.clear(); cur_logic_segment_.reset(); @@ -885,17 +899,6 @@ void Session::remove_generated_signal(shared_ptr signal) update_signals(); } -bool Session::all_segments_complete(uint32_t segment_id) const -{ - bool all_complete = true; - - for (const shared_ptr& base : signalbases_) - if (!base->segment_is_complete(segment_id)) - all_complete = false; - - return all_complete; -} - #ifdef ENABLE_DECODE shared_ptr Session::add_decode_signal() { @@ -936,6 +939,17 @@ void Session::remove_decode_signal(shared_ptr signal) } #endif +bool Session::all_segments_complete(uint32_t segment_id) const +{ + bool all_complete = true; + + for (const shared_ptr& base : signalbases_) + if (!base->segment_is_complete(segment_id)) + all_complete = false; + + return all_complete; +} + MetadataObjManager* Session::metadata_obj_manager() { return &metadata_obj_manager_; @@ -1028,7 +1042,7 @@ void Session::update_signals() signalbase->set_data(logic_data_); connect(this, SIGNAL(capture_state_changed(int)), - signalbase.get(), SLOT(on_capture_state_changed(int))); + signalbase.get(), SLOT(on_capture_state_changed(int))); break; case SR_CHANNEL_ANALOG: @@ -1040,12 +1054,34 @@ void Session::update_signals() signalbase->set_data(data); connect(this, SIGNAL(capture_state_changed(int)), - signalbase.get(), SLOT(on_capture_state_changed(int))); + signalbase.get(), SLOT(on_capture_state_changed(int))); break; } } } + // Create and assign default signal groups if needed + if (signal_groups_.empty()) { + for (auto& entry : sr_dev->channel_groups()) { + const shared_ptr& group = entry.second; + + if (group->channels().size() <= 1) + continue; + + SignalGroup* sg = new SignalGroup(QString::fromStdString(entry.first)); + for (const shared_ptr& channel : group->channels()) { + for (shared_ptr s : signalbases_) { + if (s->channel() == channel) { + sg->append_signal(s); + break; + } + } + } + signal_groups_.emplace_back(sg); + } + } + + // Update all views for (shared_ptr& viewbase : views_) { vector< shared_ptr > view_signalbases = viewbase->signalbases(); diff --git a/pv/session.hpp b/pv/session.hpp index 77a20e3c..cfc69d4a 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -25,6 +25,7 @@ #include #endif +#include #include #include #include @@ -48,6 +49,7 @@ #include "util.hpp" #include "views/viewbase.hpp" +using std::deque; using std::function; using std::map; using std::mutex; @@ -93,6 +95,7 @@ class Logic; class LogicSegment; class SignalBase; class SignalData; +class SignalGroup; } namespace devices { @@ -192,14 +195,14 @@ public: void add_generated_signal(shared_ptr signal); void remove_generated_signal(shared_ptr signal); - bool all_segments_complete(uint32_t segment_id) const; - #ifdef ENABLE_DECODE shared_ptr add_decode_signal(); void remove_decode_signal(shared_ptr signal); #endif + bool all_segments_complete(uint32_t segment_id) const; + MetadataObjManager* metadata_obj_manager(); private: @@ -279,6 +282,7 @@ private: vector< shared_ptr > signalbases_; unordered_set< shared_ptr > all_signal_data_; + deque signal_groups_; /// trigger_list_ contains pairs of values vector< std::pair > trigger_list_;