]> sigrok.org Git - pulseview.git/blob - pv/data/decodesignal.cpp
253e3a987c6dbeb59e1f6344deff7d76c5aa4692
[pulseview.git] / pv / data / decodesignal.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
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, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "logic.hpp"
21 #include "logicsegment.hpp"
22 #include "decodesignal.hpp"
23 #include "signaldata.hpp"
24
25 #include <pv/binding/decoder.hpp>
26 #include <pv/data/decode/decoder.hpp>
27 #include <pv/data/decode/row.hpp>
28 #include <pv/data/decoderstack.hpp>
29 #include <pv/session.hpp>
30
31 using std::make_shared;
32 using std::shared_ptr;
33 using pv::data::decode::Decoder;
34 using pv::data::decode::Row;
35
36 namespace pv {
37 namespace data {
38
39 DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack) :
40         SignalBase(nullptr, SignalBase::DecodeChannel),
41         decoder_stack_(decoder_stack)
42 {
43         set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name));
44
45         connect(decoder_stack_.get(), SIGNAL(new_annotations()),
46                 this, SLOT(on_new_annotations()));
47 }
48
49 DecodeSignal::~DecodeSignal()
50 {
51 }
52
53 bool DecodeSignal::is_decode_signal() const
54 {
55         return true;
56 }
57
58 shared_ptr<pv::data::DecoderStack> DecodeSignal::decoder_stack() const
59 {
60         return decoder_stack_;
61 }
62
63 const list< shared_ptr<Decoder> >& DecodeSignal::decoder_stack_list() const
64 {
65         return decoder_stack_->stack();
66 }
67
68 void DecodeSignal::stack_decoder(srd_decoder *decoder)
69 {
70         assert(decoder);
71         assert(decoder_stack);
72         decoder_stack_->push(make_shared<data::decode::Decoder>(decoder));
73         decoder_stack_->begin_decode();
74 }
75
76 void DecodeSignal::remove_decoder(int index)
77 {
78         decoder_stack_->remove(index);
79         decoder_stack_->begin_decode();
80 }
81
82 bool DecodeSignal::toggle_decoder_visibility(int index)
83 {
84         const list< shared_ptr<Decoder> > stack(decoder_stack_->stack());
85
86         auto iter = stack.cbegin();
87         for (int i = 0; i < index; i++, iter++)
88                 assert(iter != stack.end());
89
90         shared_ptr<Decoder> dec = *iter;
91
92         // Toggle decoder visibility
93         bool state = false;
94         if (dec) {
95                 state = !dec->shown();
96                 dec->show(state);
97         }
98
99         return state;
100 }
101
102 QString DecodeSignal::error_message() const
103 {
104         return decoder_stack_->error_message();
105 }
106
107 vector<Row> DecodeSignal::visible_rows() const
108 {
109         return decoder_stack_->get_visible_rows();
110 }
111
112 void DecodeSignal::get_annotation_subset(
113         vector<pv::data::decode::Annotation> &dest,
114         const decode::Row &row, uint64_t start_sample,
115         uint64_t end_sample) const
116 {
117         return decoder_stack_->get_annotation_subset(dest, row,
118                 start_sample, end_sample);
119 }
120
121 void DecodeSignal::on_new_annotations()
122 {
123         // Forward the signal to the frontend
124         new_annotations();
125 }
126
127 } // namespace data
128 } // namespace pv