]> sigrok.org Git - pulseview.git/commitdiff
Paint the unresolved area to show the decode progress
authorJoel Holdsworth <redacted>
Sat, 30 Nov 2013 22:58:28 +0000 (22:58 +0000)
committerJoel Holdsworth <redacted>
Mon, 2 Dec 2013 18:56:42 +0000 (18:56 +0000)
pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/view/decode/annotation.cpp
pv/view/decodetrace.cpp
pv/view/decodetrace.h
pv/view/trace.cpp

index bc26f9fccf1a93a2acaa38bea1a86621bca53687..d6fa17cafe8b6780239be558eeec88486923c1be 100644 (file)
@@ -47,7 +47,8 @@ const int64_t DecoderStack::DecodeChunkLength = 4096;
 
 mutex DecoderStack::_global_decode_mutex;
 
-DecoderStack::DecoderStack(const srd_decoder *const dec)
+DecoderStack::DecoderStack(const srd_decoder *const dec) :
+       _samples_decoded(0)
 {
        _stack.push_back(shared_ptr<decode::Decoder>(
                new decode::Decoder(dec)));
@@ -87,6 +88,12 @@ void DecoderStack::remove(int index)
        _stack.erase(iter);
 }
 
+int64_t DecoderStack::samples_decoded() const
+{
+       lock_guard<mutex> decode_lock(_mutex);
+       return _samples_decoded;
+}
+
 const vector< shared_ptr<view::decode::Annotation> >
        DecoderStack::annotations() const
 {
@@ -108,6 +115,8 @@ void DecoderStack::begin_decode()
        _decode_thread.interrupt();
        _decode_thread.join();
 
+       _samples_decoded = 0;
+
        _annotations.clear();
 
        // We get the logic data of the first probe in the list.
@@ -200,6 +209,11 @@ void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
                        _error_message = tr("Failed to initialise decoder");
                        break;
                }
+
+               {
+                       lock_guard<mutex> lock(_mutex);
+                       _samples_decoded = chunk_end;
+               }
        }
 
        // Destroy the session
index fe03df0aca3011f4f0d1d2c3a116621b6068e23c..4de7ae4c24ab85cdfd9e93e52c465f8d3ed6d105 100644 (file)
@@ -76,6 +76,8 @@ public:
        void push(boost::shared_ptr<decode::Decoder> decoder);
        void remove(int index);
 
+       int64_t samples_decoded() const;
+
        const std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
                annotations() const;
 
@@ -107,6 +109,7 @@ private:
        std::list< boost::shared_ptr<decode::Decoder> > _stack;
 
        mutable boost::mutex _mutex;
+       int64_t _samples_decoded;
        std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
                _annotations;
        QString _error_message;
index 7650b29e7715f48f419250ccc4787df1c5d40a02..a2db331d4f2d0c466f0a0772435b0261ca9b1324 100644 (file)
@@ -67,11 +67,10 @@ Annotation::Annotation(const srd_proto_data *const pdata) :
        }
 }
 
-void Annotation::paint(QPainter &p, QColor text_color, int text_height,
+void Annotation::paint(QPainter &p, QColor text_color, int h,
        int left, int right, double samples_per_pixel, double pixels_offset,
        int y)
 {
-       const int h = (text_height * 5) / 4;
        const double start = _start_sample / samples_per_pixel -
                pixels_offset;
        const double end = _end_sample / samples_per_pixel -
index b67c0f7abeb256d0ae472f456d878b9cca5c468c..beb83b1f20634febe91707867fca8ca0af93c77f 100644 (file)
@@ -38,6 +38,8 @@ extern "C" {
 #include <pv/sigsession.h>
 #include <pv/data/decoderstack.h>
 #include <pv/data/decode/decoder.h>
+#include <pv/data/logic.h>
+#include <pv/data/logicsnapshot.h>
 #include <pv/view/logicsignal.h>
 #include <pv/view/view.h>
 #include <pv/view/decode/annotation.h>
@@ -58,6 +60,7 @@ const QColor DecodeTrace::DecodeColours[4] = {
 };
 
 const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29);
+const QColor DecodeTrace::NoDecodeColour = QColor(0x88, 0x8A, 0x85);
 
 DecodeTrace::DecodeTrace(pv::SigSession &session,
        boost::shared_ptr<pv::data::DecoderStack> decoder_stack, int index) :
@@ -93,6 +96,7 @@ void DecodeTrace::set_view(pv::view::View *view)
 
 void DecodeTrace::paint_back(QPainter &p, int left, int right)
 {
+       Trace::paint_back(p, left, right);
        paint_axis(p, get_y(), left, right);
 }
 
@@ -100,16 +104,6 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
 {
        using namespace pv::view::decode;
 
-       assert(_decoder_stack);
-       const QString err = _decoder_stack->error_message();
-       if (!err.isEmpty()) {
-               draw_error(p, err, left, right);
-               return;
-       }
-
-       assert(_view);
-       const int y = get_y();
-
        const double scale = _view->scale();
        assert(scale > 0);
 
@@ -123,13 +117,31 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
                _decoder_stack->get_start_time()) / scale;
        const double samples_per_pixel = samplerate * scale;
 
+       const int h = (_text_size.height() * 5) / 4;
+
+       assert(_decoder_stack);
+       const QString err = _decoder_stack->error_message();
+       if (!err.isEmpty())
+       {
+               draw_error(p, err, left, right);
+               draw_unresolved_period(p, h, left, right, samples_per_pixel,
+                       pixels_offset);
+               return;
+       }
+
+       assert(_view);
+       const int y = get_y();
+
        assert(_decoder_stack);
        vector< shared_ptr<Annotation> > annotations(_decoder_stack->annotations());
        BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
                assert(a);
-               a->paint(p, get_text_colour(), _text_size.height(),
-                       left, right, samples_per_pixel, pixels_offset, y);
+               a->paint(p, get_text_colour(), h, left, right,
+                       samples_per_pixel, pixels_offset, y);
        }
+
+       draw_unresolved_period(p, h, left, right,
+               samples_per_pixel, pixels_offset);
 }
 
 void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
@@ -219,6 +231,58 @@ 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, double samples_per_pixel, double pixels_offset) 
+{
+       using namespace pv::data;
+       using pv::data::decode::Decoder;
+
+       assert(_decoder_stack); 
+
+       shared_ptr<Logic> data;
+       shared_ptr<LogicSignal> logic_signal;
+
+       const list< shared_ptr<Decoder> > &stack = _decoder_stack->stack();
+
+       // We get the logic data of the first probe in the list.
+       // This works because we are currently assuming all
+       // LogicSignals have the same data/snapshot
+       BOOST_FOREACH (const shared_ptr<Decoder> &dec, stack)
+               if (dec && !dec->probes().empty() &&
+                       ((logic_signal = (*dec->probes().begin()).second)) &&
+                       ((data = logic_signal->data())))
+                       break;
+
+       if (!data || data->get_snapshots().empty())
+               return;
+
+       const shared_ptr<LogicSnapshot> snapshot =
+               data->get_snapshots().front();
+       assert(snapshot);
+       const int64_t sample_count = (int64_t)snapshot->get_sample_count();
+       if (sample_count == 0)
+               return;
+
+       const int64_t samples_decoded = _decoder_stack->samples_decoded();
+       if (sample_count == samples_decoded)
+               return;
+
+       const int y = get_y();
+       const double start = max(samples_decoded /
+               samples_per_pixel - pixels_offset, left - 1.0);
+       const double end = min(sample_count / samples_per_pixel -
+               pixels_offset, right + 1.0);
+       const QRectF no_decode_rect(start, y - h/2 + 0.5, end - start, h);
+
+       p.setPen(QPen(Qt::NoPen));
+       p.setBrush(Qt::white);
+       p.drawRect(no_decode_rect);
+
+       p.setPen(NoDecodeColour);
+       p.setBrush(QBrush(NoDecodeColour, Qt::Dense6Pattern));
+       p.drawRect(no_decode_rect);
+}
+
 void DecodeTrace::create_decoder_form(int index,
        shared_ptr<data::decode::Decoder> &dec, QWidget *parent,
        QFormLayout *form)
index ccf4a0f7bbe4d64d9c421b3eb25c446fc0e67934..02ea023bf87e5f6f697a3c9958846099b80605e3 100644 (file)
@@ -64,6 +64,7 @@ private:
 private:
        static const QColor DecodeColours[4];
        static const QColor ErrorBgColour;
+       static const QColor NoDecodeColour;
 
 public:
        DecodeTrace(pv::SigSession &session,
@@ -102,6 +103,9 @@ private:
        void draw_error(QPainter &p, const QString &message,
                int left, int right);
 
+       void draw_unresolved_period(QPainter &p, int h, int left,
+               int right, double samples_per_pixel, double pixels_offset);
+
        void create_decoder_form(int index,
                boost::shared_ptr<pv::data::decode::Decoder> &dec,
                QWidget *parent, QFormLayout *form);
index 464cadcde2ede54aaa6b4c8e0f3fcae9a1308e9f..d06c24b5e63ed98d98a7f190851ed2667f9d5ccc 100644 (file)
@@ -88,6 +88,8 @@ void Trace::paint_back(QPainter &p, int left, int right)
        (void)p;
        (void)left;
        (void)right;
+
+       compute_text_size(p);
 }
 
 void Trace::paint_mid(QPainter &p, int left, int right)