From: Soeren Apel Date: Wed, 12 Apr 2017 20:06:29 +0000 (+0200) Subject: Move more functionality into DecodeSignal X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ff83d98059f06ac8f57be080ab53e7095aa4748b;p=pulseview.git Move more functionality into DecodeSignal --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 5b2bb31d..7a4a3d11 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -155,6 +155,44 @@ void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int in decoder_stack_->begin_decode(); } +int64_t DecodeSignal::sample_count() const +{ + shared_ptr data; + shared_ptr signalbase; + + // We get the logic data of the first channel in the list. + // This works because we are currently assuming all + // LogicSignals have the same data/segment + for (const shared_ptr &dec : decoder_stack_->stack()) + if (dec && !dec->channels().empty() && + ((signalbase = (*dec->channels().begin()).second)) && + ((data = signalbase->logic_data()))) + break; + + if (!data || data->logic_segments().empty()) + return 0; + + const shared_ptr segment = data->logic_segments().front(); + assert(segment); + + return (int64_t)segment->get_sample_count(); +} + +double DecodeSignal::samplerate() const +{ + return decoder_stack_->samplerate(); +} + +const pv::util::Timestamp& DecodeSignal::start_time() const +{ + return decoder_stack_->start_time(); +} + +int64_t DecodeSignal::samples_decoded() const +{ + return decoder_stack_->samples_decoded(); +} + vector DecodeSignal::visible_rows() const { return decoder_stack_->get_visible_rows(); diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 1444feae..2f7c273e 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -84,6 +84,11 @@ public: void set_initial_pin_state(const uint16_t channel_id, const int init_state); + double samplerate() const; + const pv::util::Timestamp& start_time() const; + int64_t sample_count() const; + int64_t samples_decoded() const; + vector visible_rows() const; /** diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 4ea29755..a4628eab 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -48,7 +48,6 @@ extern "C" { #include #include #include -#include #include #include #include @@ -305,7 +304,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) init_state_map_.clear(); decoder_forms_.clear(); - const list< shared_ptr >& stack = + const list< shared_ptr > &stack = decode_signal_->decoder_stack_list(); if (stack.empty()) { @@ -594,49 +593,24 @@ void DecodeTrace::draw_error(QPainter &p, const QString &message, p.drawText(text_rect, message); } -void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, - int right) const +void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, int right) const { using namespace pv::data; using pv::data::decode::Decoder; double samples_per_pixel, pixels_offset; - shared_ptr decoder_stack = base_->decoder_stack(); - - assert(decoder_stack); - - shared_ptr data; - shared_ptr signalbase; - - 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 - // LogicSignals have the same data/segment - for (const shared_ptr &dec : stack) - if (dec && !dec->channels().empty() && - ((signalbase = (*dec->channels().begin()).second)) && - ((data = signalbase->logic_data()))) - break; - - if (!data || data->logic_segments().empty()) - return; - - const shared_ptr segment = data->logic_segments().front(); - assert(segment); - const int64_t sample_count = (int64_t)segment->get_sample_count(); + const int64_t sample_count = decode_signal_->sample_count(); if (sample_count == 0) return; - const int64_t samples_decoded = decoder_stack->samples_decoded(); + const int64_t samples_decoded = decode_signal_->samples_decoded(); if (sample_count == samples_decoded) return; const int y = get_visual_y(); - tie(pixels_offset, samples_per_pixel) = - get_pixels_offset_samples_per_pixel(); + tie(pixels_offset, samples_per_pixel) = get_pixels_offset_samples_per_pixel(); const double start = max(samples_decoded / samples_per_pixel - pixels_offset, left - 1.0); @@ -655,10 +629,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, pair DecodeTrace::get_pixels_offset_samples_per_pixel() const { - shared_ptr decoder_stack = base_->decoder_stack(); - assert(owner_); - assert(decoder_stack); const View *view = owner_->view(); assert(view); @@ -667,9 +638,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() - decode_signal_->start_time()) / scale).convert_to(); - double samplerate = decoder_stack->samplerate(); + double samplerate = decode_signal_->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) @@ -727,10 +698,7 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point) vector annotations; - shared_ptr decoder_stack = base_->decoder_stack(); - - assert(decoder_stack); - decoder_stack->get_annotation_subset(annotations, visible_rows_[row], + decode_signal_->get_annotation_subset(annotations, visible_rows_[row], sample_range.first, sample_range.second); return (annotations.empty()) ? diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index da9f56cc..7edb30bd 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -50,7 +50,6 @@ namespace pv { class Session; namespace data { -class DecoderStack; class SignalBase; struct DecodeChannel; class DecodeSignal;