]> sigrok.org Git - pulseview.git/blame - pv/data/decode/rowdata.cpp
DecodeTrace: Highlight row expand markers when a class is hidden
[pulseview.git] / pv / data / decode / rowdata.cpp
CommitLineData
f9101a91
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
f9101a91
JH
18 */
19
6a26fc44
SA
20#include <pv/data/decode/decoder.hpp>
21#include <pv/data/decode/row.hpp>
22#include <pv/data/decode/rowdata.hpp>
f9101a91
JH
23
24using std::vector;
25
26namespace pv {
27namespace data {
28namespace decode {
29
6a26fc44
SA
30RowData::RowData(Row* row) :
31 row_(row)
32{
33 assert(row);
34}
35
f9101a91
JH
36uint64_t RowData::get_max_sample() const
37{
8dbbc7f0 38 if (annotations_.empty())
f9101a91 39 return 0;
8dbbc7f0 40 return annotations_.back().end_sample();
f9101a91
JH
41}
42
f994f496
SA
43uint64_t RowData::get_annotation_count() const
44{
45 return annotations_.size();
46}
47
f9101a91 48void RowData::get_annotation_subset(
21ea5e70 49 vector<pv::data::decode::Annotation> &dest,
f9101a91
JH
50 uint64_t start_sample, uint64_t end_sample) const
51{
6a26fc44
SA
52 // Determine whether we must apply per-class filtering or not
53 bool all_ann_classes_enabled = true;
54 bool all_ann_classes_disabled = true;
55
56 uint32_t max_ann_class_id = 0;
57 for (AnnotationClass* c : row_->ann_classes()) {
58 if (!c->visible)
59 all_ann_classes_enabled = false;
60 else
61 all_ann_classes_disabled = false;
62 if (c->id > max_ann_class_id)
63 max_ann_class_id = c->id;
64 }
65
66 if (all_ann_classes_enabled) {
67 // No filtering, send everyting out as-is
68 for (const auto& annotation : annotations_)
69 if ((annotation.end_sample() > start_sample) &&
70 (annotation.start_sample() <= end_sample))
71 dest.push_back(annotation);
72 } else {
73 if (!all_ann_classes_disabled) {
74 // Filter out invisible annotation classes
75 vector<size_t> class_visible;
76 class_visible.resize(max_ann_class_id + 1, 0);
77 for (AnnotationClass* c : row_->ann_classes())
78 if (c->visible)
79 class_visible[c->id] = 1;
80
81 for (const auto& annotation : annotations_)
81dc0221
SA
82 if ((class_visible[annotation.ann_class()]) &&
83 (annotation.end_sample() > start_sample) &&
84 (annotation.start_sample() <= end_sample))
6a26fc44
SA
85 dest.push_back(annotation);
86 }
87 }
f9101a91
JH
88}
89
6a26fc44 90void RowData::emplace_annotation(srd_proto_data *pdata)
f9101a91 91{
6a26fc44 92 annotations_.emplace_back(pdata, row_);
f9101a91
JH
93}
94
870ea3db
UH
95} // namespace decode
96} // namespace data
97} // namespace pv