From: Soeren Apel Date: Tue, 16 Aug 2016 19:32:56 +0000 (+0200) Subject: Move view-independent data from view::DecodeTrace to SignalBase X-Git-Tag: pulseview-0.4.0~270 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bb7dd726eb7159ddd80d94ede791f2e2a9eaef0f;p=pulseview.git Move view-independent data from view::DecodeTrace to SignalBase --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 62881528..3adf3338 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -23,6 +23,9 @@ #include "logic.hpp" #include "signalbase.hpp" #include "signaldata.hpp" +#include "decode/row.hpp" + +#include using std::dynamic_pointer_cast; using std::shared_ptr; @@ -124,6 +127,23 @@ shared_ptr SignalBase::logic_data() const return shared_ptr(); } +#ifdef ENABLE_DECODE +bool SignalBase::is_decode_signal() const +{ + return (decoder_stack_ != nullptr); +} + +std::shared_ptr SignalBase::decoder_stack() const +{ + return decoder_stack_; +} + +void SignalBase::set_decoder_stack(std::shared_ptr + decoder_stack) +{ + decoder_stack_ = decoder_stack; +} +#endif } // namespace data } // namespace pv diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index ca3cd5c4..a682a56e 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -38,6 +38,7 @@ namespace pv { namespace data { class Analog; +class DecoderStack; class Logic; class SignalData; @@ -119,6 +120,14 @@ public: */ std::shared_ptr logic_data() const; +#ifdef ENABLE_DECODE + bool is_decode_signal() const; + + std::shared_ptr decoder_stack() const; + + void set_decoder_stack(std::shared_ptr + decoder_stack); +#endif Q_SIGNALS: void enabled_changed(const bool &value); @@ -131,6 +140,10 @@ private: std::shared_ptr channel_; std::shared_ptr data_; +#ifdef ENABLE_DECODE + std::shared_ptr decoder_stack_; +#endif + QString name_; QColor colour_, bgcolour_; }; diff --git a/pv/session.cpp b/pv/session.cpp index 852de298..74cb82dc 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -144,8 +144,12 @@ void Session::set_device(shared_ptr device) device_.reset(); // Remove all stored data - for (std::shared_ptr view : views_) + for (std::shared_ptr view : views_) { view->clear_signals(); +#ifdef ENABLE_DECODE + view->clear_decode_traces(); +#endif + } for (const shared_ptr d : all_signal_data_) d->clear(); all_signal_data_.clear(); @@ -158,7 +162,6 @@ void Session::set_device(shared_ptr device) } logic_data_.reset(); - decode_traces_.clear(); signals_changed(); @@ -314,10 +317,10 @@ bool Session::add_decoder(srd_decoder *const dec) shared_ptr signalbase = shared_ptr(new data::SignalBase(nullptr)); - shared_ptr d( - new view::DecodeTrace(*this, signalbase, decoder_stack, - decode_traces_.size())); - decode_traces_.push_back(d); + signalbase->set_decoder_stack(decoder_stack); + + for (std::shared_ptr view : views_) + view->add_decode_trace(signalbase); } catch (std::runtime_error e) { return false; } @@ -330,19 +333,10 @@ bool Session::add_decoder(srd_decoder *const dec) return true; } -vector< shared_ptr > Session::get_decode_signals() const +void Session::remove_decode_signal(shared_ptr signalbase) { - return decode_traces_; -} - -void Session::remove_decode_signal(view::DecodeTrace *signal) -{ - for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++) - if ((*i).get() == signal) { - decode_traces_.erase(i); - signals_changed(); - return; - } + for (std::shared_ptr view : views_) + view->remove_decode_trace(signalbase); } #endif @@ -365,8 +359,12 @@ void Session::update_signals() if (!device_) { signalbases_.clear(); logic_data_.reset(); - for (std::shared_ptr view : views_) + for (std::shared_ptr view : views_) { view->clear_signals(); +#ifdef ENABLE_DECODE + view->clear_decode_traces(); +#endif + } return; } @@ -376,8 +374,12 @@ void Session::update_signals() if (!sr_dev) { signalbases_.clear(); logic_data_.reset(); - for (std::shared_ptr view : views_) + for (std::shared_ptr view : views_) { view->clear_signals(); +#ifdef ENABLE_DECODE + view->clear_decode_traces(); +#endif + } return; } diff --git a/pv/session.hpp b/pv/session.hpp index 83a73f4a..a4fc352d 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -73,7 +73,6 @@ class Device; } namespace view { -class DecodeTrace; class View; } @@ -126,10 +125,7 @@ public: #ifdef ENABLE_DECODE bool add_decoder(srd_decoder *const dec); - std::vector< std::shared_ptr > - get_decode_signals() const; - - void remove_decode_signal(view::DecodeTrace *signal); + void remove_decode_signal(std::shared_ptr signalbase); #endif private: @@ -164,8 +160,6 @@ private: std::unordered_set< std::shared_ptr > views_; - std::vector< std::shared_ptr > decode_traces_; - mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_. capture_state capture_state_; diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 1f21b024..832b249d 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -128,18 +128,17 @@ const QColor DecodeTrace::OutlineColours[16] = { }; DecodeTrace::DecodeTrace(pv::Session &session, - shared_ptr signalbase, - std::shared_ptr decoder_stack, int index) : + shared_ptr signalbase, int index) : Trace(signalbase), session_(session), signalbase_(signalbase), - decoder_stack_(decoder_stack), row_height_(0), max_visible_rows_(0), delete_mapper_(this), show_hide_mapper_(this) { - assert(decoder_stack_); + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); // Determine shortest string we want to see displayed in full QFontMetrics m(QApplication::font()); @@ -148,7 +147,7 @@ DecodeTrace::DecodeTrace(pv::Session &session, signalbase_->set_name(QString::fromUtf8(decoder_stack->stack().front()->decoder()->name)); signalbase_->set_colour(DecodeColours[index % countof(DecodeColours)]); - connect(decoder_stack_.get(), SIGNAL(new_decode_data()), + connect(decoder_stack.get(), SIGNAL(new_decode_data()), this, SLOT(on_new_decode_data())); connect(&delete_mapper_, SIGNAL(mapped(int)), this, SLOT(on_delete_decoder(int))); @@ -161,9 +160,9 @@ bool DecodeTrace::enabled() const return true; } -const std::shared_ptr& DecodeTrace::decoder() const +std::shared_ptr DecodeTrace::base() const { - return decoder_stack_; + return base_; } pair DecodeTrace::v_extents() const @@ -186,12 +185,15 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) { using namespace pv::data::decode; + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + const int text_height = ViewItemPaintParams::text_height(); row_height_ = (text_height * 6) / 4; const int annotation_height = (text_height * 5) / 4; - assert(decoder_stack_); - const QString err = decoder_stack_->error_message(); + assert(decoder_stack); + const QString err = decoder_stack->error_message(); if (!err.isEmpty()) { draw_unresolved_period( p, annotation_height, pp.left(), pp.right()); @@ -207,8 +209,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) pair sample_range = get_sample_range( pp.left(), pp.right()); - assert(decoder_stack_); - const vector rows(decoder_stack_->get_visible_rows()); + const vector rows(decoder_stack->get_visible_rows()); visible_rows_.clear(); for (const Row& row : rows) { @@ -231,7 +232,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) base_colour >>= 16; vector annotations; - decoder_stack_->get_annotation_subset(annotations, row, + decoder_stack->get_annotation_subset(annotations, row, sample_range.first, sample_range.second); if (!annotations.empty()) { draw_annotations(annotations, p, annotation_height, pp, y, @@ -297,9 +298,12 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) { using pv::data::decode::Decoder; + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + assert(form); assert(parent); - assert(decoder_stack_); + assert(decoder_stack); // Add the standard options Trace::populate_popup_form(parent, form); @@ -309,7 +313,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) channel_selectors_.clear(); decoder_forms_.clear(); - const list< shared_ptr >& stack = decoder_stack_->stack(); + const list< shared_ptr >& stack = decoder_stack->stack(); if (stack.empty()) { QLabel *const l = new QLabel( @@ -600,12 +604,15 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, double samples_per_pixel, pixels_offset; - assert(decoder_stack_); + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + + assert(decoder_stack); shared_ptr data; shared_ptr signalbase; - const list< shared_ptr > &stack = decoder_stack_->stack(); + const list< shared_ptr > &stack = decoder_stack->stack(); // We get the logic data of the first channel in the list. // This works because we are currently assuming all @@ -626,7 +633,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, if (sample_count == 0) return; - const int64_t samples_decoded = decoder_stack_->samples_decoded(); + const int64_t samples_decoded = decoder_stack->samples_decoded(); if (sample_count == samples_decoded) return; @@ -652,8 +659,11 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, pair DecodeTrace::get_pixels_offset_samples_per_pixel() const { + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + assert(owner_); - assert(decoder_stack_); + assert(decoder_stack); const View *view = owner_->view(); assert(view); @@ -662,9 +672,9 @@ pair DecodeTrace::get_pixels_offset_samples_per_pixel() const assert(scale > 0); const double pixels_offset = - ((view->offset() - decoder_stack_->start_time()) / scale).convert_to(); + ((view->offset() - decoder_stack->start_time()) / scale).convert_to(); - double samplerate = decoder_stack_->samplerate(); + double samplerate = decoder_stack->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) @@ -722,8 +732,11 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point) vector annotations; - assert(decoder_stack_); - decoder_stack_->get_annotation_subset(annotations, visible_rows_[row], + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + + assert(decoder_stack); + decoder_stack->get_annotation_subset(annotations, visible_rows_[row], sample_range.first, sample_range.second); return (annotations.empty()) ? @@ -828,9 +841,12 @@ void DecodeTrace::create_decoder_form(int index, channel_selectors_.push_back(s); } + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + // Add the options shared_ptr binding( - new binding::Decoder(decoder_stack_, dec)); + new binding::Decoder(decoder_stack, dec)); binding->add_properties_to_form(decoder_form, true); bindings_.push_back(binding); @@ -908,11 +924,14 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec void DecodeTrace::commit_channels() { - assert(decoder_stack_); - for (shared_ptr dec : decoder_stack_->stack()) + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + + assert(decoder_stack); + for (shared_ptr dec : decoder_stack->stack()) commit_decoder_channels(dec); - decoder_stack_->begin_decode(); + decoder_stack->begin_decode(); } void DecodeTrace::on_new_decode_data() @@ -928,7 +947,7 @@ void DecodeTrace::delete_pressed() void DecodeTrace::on_delete() { - session_.remove_decode_signal(this); + session_.remove_decode_signal(base_); } void DecodeTrace::on_channel_selected(int) @@ -938,30 +957,39 @@ void DecodeTrace::on_channel_selected(int) void DecodeTrace::on_stack_decoder(srd_decoder *decoder) { + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + assert(decoder); - assert(decoder_stack_); - decoder_stack_->push(shared_ptr( + assert(decoder_stack); + decoder_stack->push(shared_ptr( new data::decode::Decoder(decoder))); - decoder_stack_->begin_decode(); + decoder_stack->begin_decode(); create_popup_form(); } void DecodeTrace::on_delete_decoder(int index) { - decoder_stack_->remove(index); + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + + decoder_stack->remove(index); // Update the popup create_popup_form(); - decoder_stack_->begin_decode(); + decoder_stack->begin_decode(); } void DecodeTrace::on_show_hide_decoder(int index) { using pv::data::decode::Decoder; - const list< shared_ptr > stack(decoder_stack_->stack()); + std::shared_ptr decoder_stack = + signalbase_->decoder_stack(); + + const list< shared_ptr > stack(decoder_stack->stack()); // Find the decoder in the stack auto iter = stack.cbegin(); diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index 96332d97..f5695320 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -45,6 +45,7 @@ class Session; namespace data { class DecoderStack; +class SignalBase; namespace decode { class Annotation; @@ -86,13 +87,14 @@ private: public: DecodeTrace(pv::Session &session, std::shared_ptr signalbase, - std::shared_ptr decoder_stack, int index); bool enabled() const; const std::shared_ptr& decoder() const; + std::shared_ptr base() const; + /** * Computes the vertical extents of the contents of this row item. * @return A pair containing the minimum and maximum y-values. @@ -198,8 +200,8 @@ private Q_SLOTS: private: pv::Session &session_; std::shared_ptr signalbase_; - std::shared_ptr decoder_stack_; + std::vector visible_rows_; uint64_t decode_start_, decode_end_; std::list< std::shared_ptr > @@ -208,7 +210,6 @@ private: std::list channel_selectors_; std::vector decoder_forms_; - std::vector visible_rows_; std::map row_title_widths_; int row_height_, max_visible_rows_; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 7e47140c..3f832474 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -201,6 +201,30 @@ void View::add_signal(const shared_ptr signal) signals_.insert(signal); } +#ifdef ENABLE_DECODE +void View::clear_decode_traces() +{ + decode_traces_.clear(); +} + +void View::add_decode_trace(shared_ptr signalbase) +{ + shared_ptr d( + new view::DecodeTrace(session_, signalbase, decode_traces_.size())); + decode_traces_.push_back(d); +} + +void View::remove_decode_trace(shared_ptr signalbase) +{ + for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++) + if ((*i)->base() == signalbase) { + decode_traces_.erase(i); + signals_changed(); + return; + } +} +#endif + View* View::view() { return this; @@ -967,9 +991,7 @@ void View::signals_changed() set< shared_ptr > traces(signals_.begin(), signals_.end()); #ifdef ENABLE_DECODE - const vector< shared_ptr > decode_traces( - session().get_decode_signals()); - traces.insert(decode_traces.begin(), decode_traces.end()); + traces.insert(decode_traces_.begin(), decode_traces_.end()); #endif set< shared_ptr > add_traces; diff --git a/pv/view/view.hpp b/pv/view/view.hpp index d699be4f..eeb43ec8 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -51,6 +51,7 @@ class Session; namespace view { class CursorHeader; +class DecodeTrace; class Header; class Ruler; class Signal; @@ -91,6 +92,14 @@ public: void add_signal(const std::shared_ptr signal); +#ifdef ENABLE_DECODE + void clear_decode_traces(); + + void add_decode_trace(std::shared_ptr signalbase); + + void remove_decode_trace(std::shared_ptr signalbase); +#endif + /** * Returns the view of the owner. */ @@ -367,6 +376,10 @@ private: std::unordered_set< std::shared_ptr > signals_; +#ifdef ENABLE_DECODE + std::vector< std::shared_ptr > decode_traces_; +#endif + /// The view time scale in seconds per pixel. double scale_;