]> sigrok.org Git - pulseview.git/blobdiff - pv/view/analogsignal.cpp
Add a spin box widget for timestamp values
[pulseview.git] / pv / view / analogsignal.cpp
index 8a19cc210180abeedaedeb6305e96942b046686a..8e541dac1672da902233105215f49d0c4c271c01 100644 (file)
 
 #include "analogsignal.hpp"
 #include "pv/data/analog.hpp"
-#include "pv/data/analogsnapshot.hpp"
+#include "pv/data/analogsegment.hpp"
 #include "pv/view/view.hpp"
 
-#include <libsigrok/libsigrok.hpp>
+#include <libsigrokcxx/libsigrokcxx.hpp>
 
 using std::max;
 using std::make_pair;
@@ -87,70 +87,61 @@ std::pair<int, int> AnalogSignal::v_extents() const
        return make_pair(-NominalHeight / 2, NominalHeight / 2);
 }
 
-void AnalogSignal::paint_back(QPainter &p, int left, int right)
+void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
 {
        if (channel_->enabled())
-               paint_axis(p, get_visual_y(), left, right);
+               paint_axis(p, pp, get_visual_y());
 }
 
-void AnalogSignal::paint_mid(QPainter &p, int left, int right)
+void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
 {
        assert(data_);
-       assert(right >= left);
        assert(owner_);
 
        const int y = get_visual_y();
 
-       const View *const view = owner_->view();
-       assert(view);
-
-       const double scale = view->scale();
-       assert(scale > 0);
-
-       const double offset = view->offset();
-
        if (!channel_->enabled())
                return;
 
-       const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots =
-               data_->get_snapshots();
-       if (snapshots.empty())
+       const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
+               data_->analog_segments();
+       if (segments.empty())
                return;
 
-       const shared_ptr<pv::data::AnalogSnapshot> &snapshot =
-               snapshots.front();
+       const shared_ptr<pv::data::AnalogSegment> &segment =
+               segments.front();
 
-       const double pixels_offset = offset / scale;
-       const double samplerate = data_->samplerate();
-       const double start_time = data_->get_start_time();
-       const int64_t last_sample = snapshot->get_sample_count() - 1;
-       const double samples_per_pixel = samplerate * scale;
-       const double start = samplerate * (offset - start_time);
-       const double end = start + samples_per_pixel * (right - left);
+       const double pixels_offset = pp.pixels_offset();
+       const double samplerate = segment->samplerate();
+       const pv::util::Timestamp& start_time = segment->start_time();
+       const int64_t last_sample = segment->get_sample_count() - 1;
+       const double samples_per_pixel = samplerate * pp.scale();
+       const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
+       const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
 
-       const int64_t start_sample = min(max((int64_t)floor(start),
+       const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
                (int64_t)0), last_sample);
-       const int64_t end_sample = min(max((int64_t)ceil(end) + 1,
+       const int64_t end_sample = min(max((ceil(end) + 1).convert_to<int64_t>(),
                (int64_t)0), last_sample);
 
        if (samples_per_pixel < EnvelopeThreshold)
-               paint_trace(p, snapshot, y, left,
+               paint_trace(p, segment, y, pp.left(),
                        start_sample, end_sample,
                        pixels_offset, samples_per_pixel);
        else
-               paint_envelope(p, snapshot, y, left,
+               paint_envelope(p, segment, y, pp.left(),
                        start_sample, end_sample,
                        pixels_offset, samples_per_pixel);
 }
 
 void AnalogSignal::paint_trace(QPainter &p,
-       const shared_ptr<pv::data::AnalogSnapshot> &snapshot,
+       const shared_ptr<pv::data::AnalogSegment> &segment,
        int y, int left, const int64_t start, const int64_t end,
        const double pixels_offset, const double samples_per_pixel)
 {
        const int64_t sample_count = end - start;
 
-       const float *const samples = snapshot->get_samples(start, end);
+       const float *const samples = segment->get_samples(start, end);
        assert(samples);
 
        p.setPen(colour_);
@@ -172,14 +163,14 @@ void AnalogSignal::paint_trace(QPainter &p,
 }
 
 void AnalogSignal::paint_envelope(QPainter &p,
-       const shared_ptr<pv::data::AnalogSnapshot> &snapshot,
+       const shared_ptr<pv::data::AnalogSegment> &segment,
        int y, int left, const int64_t start, const int64_t end,
        const double pixels_offset, const double samples_per_pixel)
 {
-       using pv::data::AnalogSnapshot;
+       using pv::data::AnalogSegment;
 
-       AnalogSnapshot::EnvelopeSection e;
-       snapshot->get_envelope_section(e, start, end, samples_per_pixel);
+       AnalogSegment::EnvelopeSection e;
+       segment->get_envelope_section(e, start, end, samples_per_pixel);
 
        if (e.length < 2)
                return;
@@ -190,10 +181,10 @@ void AnalogSignal::paint_envelope(QPainter &p,
        QRectF *const rects = new QRectF[e.length];
        QRectF *rect = rects;
 
-       for(uint64_t sample = 0; sample < e.length-1; sample++) {
+       for (uint64_t sample = 0; sample < e.length-1; sample++) {
                const float x = ((e.scale * sample + e.start) /
                        samples_per_pixel - pixels_offset) + left;
-               const AnalogSnapshot::EnvelopeSample *const s =
+               const AnalogSegment::EnvelopeSample *const s =
                        e.samples + sample;
 
                // We overlap this sample with the next so that vertical
@@ -202,9 +193,9 @@ void AnalogSignal::paint_envelope(QPainter &p,
                const float t = y - min(s->min, (s+1)->max) * scale_;
 
                float h = b - t;
-               if(h >= 0.0f && h <= 1.0f)
+               if (h >= 0.0f && h <= 1.0f)
                        h = 1.0f;
-               if(h <= 0.0f && h >= -1.0f)
+               if (h <= 0.0f && h >= -1.0f)
                        h = -1.0f;
 
                *rect++ = QRectF(x, t, 1.0f, h);