]> sigrok.org Git - pulseview.git/commitdiff
Move more functionality into DecodeSignal
authorSoeren Apel <redacted>
Wed, 12 Apr 2017 20:06:29 +0000 (22:06 +0200)
committerSoeren Apel <redacted>
Tue, 4 Jul 2017 21:14:36 +0000 (23:14 +0200)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp

index 5b2bb31d75e1217e7567d634f289eaab0985bd03..7a4a3d11269d0b22b397099cbf23a563133829cc 100644 (file)
@@ -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<Logic> data;
+       shared_ptr<data::SignalBase> 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<Decoder> &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<LogicSegment> 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<Row> DecodeSignal::visible_rows() const
 {
        return decoder_stack_->get_visible_rows();
index 1444feae5e8d431e4c498d51735dbf3d922e3af6..2f7c273e978bfa2ec09618d89ddb1d273c1be676 100644 (file)
@@ -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<decode::Row> visible_rows() const;
 
        /**
index 4ea297555260ddd3a2491d554d176b4440c8e72b..a4628eab9fbfdac55c9125e765f5c6cc0976ebcd 100644 (file)
@@ -48,7 +48,6 @@ extern "C" {
 #include <pv/data/decodesignal.hpp>
 #include <pv/data/decode/annotation.hpp>
 #include <pv/data/decode/decoder.hpp>
-#include <pv/data/decoderstack.hpp>
 #include <pv/data/logic.hpp>
 #include <pv/data/logicsegment.hpp>
 #include <pv/widgets/decodergroupbox.hpp>
@@ -305,7 +304,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
        init_state_map_.clear();
        decoder_forms_.clear();
 
-       const list< shared_ptr<Decoder> >stack =
+       const list< shared_ptr<Decoder> > &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<pv::data::DecoderStack> decoder_stack = base_->decoder_stack();
-
-       assert(decoder_stack);
-
-       shared_ptr<Logic> data;
-       shared_ptr<data::SignalBase> signalbase;
-
-       const list< shared_ptr<Decoder> > &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<Decoder> &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<LogicSegment> 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<double, double> DecodeTrace::get_pixels_offset_samples_per_pixel() const
 {
-       shared_ptr<pv::data::DecoderStack> decoder_stack = base_->decoder_stack();
-
        assert(owner_);
-       assert(decoder_stack);
 
        const View *view = owner_->view();
        assert(view);
@@ -667,9 +638,9 @@ pair<double, double> DecodeTrace::get_pixels_offset_samples_per_pixel() const
        assert(scale > 0);
 
        const double pixels_offset =
-               ((view->offset() - decoder_stack->start_time()) / scale).convert_to<double>();
+               ((view->offset() - decode_signal_->start_time()) / scale).convert_to<double>();
 
-       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<pv::data::decode::Annotation> annotations;
 
-       shared_ptr<pv::data::DecoderStack> 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()) ?
index da9f56ccb76d5546e0fc4baccc6413c729b56ab1..7edb30bde3c96b6591e1190d080a7b368e4862c4 100644 (file)
@@ -50,7 +50,6 @@ namespace pv {
 class Session;
 
 namespace data {
-class DecoderStack;
 class SignalBase;
 struct DecodeChannel;
 class DecodeSignal;