]> sigrok.org Git - pulseview.git/blob - pv/view/decodesignal.cpp
Initial decode painting
[pulseview.git] / pv / view / decodesignal.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 extern "C" {
22 #include <libsigrokdecode/libsigrokdecode.h>
23 }
24
25 #include "decodesignal.h"
26
27 #include <pv/data/decoder.h>
28 #include <pv/view/view.h>
29 #include <pv/view/decode/annotation.h>
30
31 using namespace boost;
32 using namespace std;
33
34 namespace pv {
35 namespace view {
36
37 DecodeSignal::DecodeSignal(pv::SigSession &session,
38         boost::shared_ptr<pv::data::Decoder> decoder) :
39         Trace(session, QString(decoder->get_decoder()->name)),
40         _decoder(decoder)
41 {
42         assert(_decoder);
43
44         _colour = Qt::red;
45 }
46
47 void DecodeSignal::init_context_bar_actions(QWidget *parent)
48 {
49         (void)parent;
50 }
51
52 bool DecodeSignal::enabled() const
53 {
54         return true;
55 }
56
57 void DecodeSignal::set_view(pv::view::View *view)
58 {
59         assert(view);
60         Trace::set_view(view);
61 }
62
63 void DecodeSignal::paint(QPainter &p, int left, int right)
64 {
65         using namespace pv::view::decode;
66
67         assert(_view);
68         const int y = _v_offset - _view->v_offset();
69
70         const double scale = _view->scale();
71         assert(scale > 0);
72
73         double samplerate = _decoder->get_samplerate();
74
75         // Show sample rate as 1Hz when it is unknown
76         if (samplerate == 0.0)
77                 samplerate = 1.0;
78
79         const double pixels_offset = (_view->offset() -
80                 _decoder->get_start_time()) / scale;
81         const double samples_per_pixel = samplerate * scale;
82
83         assert(_decoder);
84         vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
85         BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
86                 assert(a);
87                 a->paint(p, left, right, samples_per_pixel, pixels_offset, y);
88         }
89 }
90
91 const list<QAction*> DecodeSignal::get_context_bar_actions()
92 {
93         list<QAction*> actions;
94         return actions;
95 }
96
97 } // namespace view
98 } // namespace pv