]>
Commit | Line | Data |
---|---|---|
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 | ||
d67b0972 SA |
20 | #include <cassert> |
21 | ||
6a26fc44 SA |
22 | #include <pv/data/decode/decoder.hpp> |
23 | #include <pv/data/decode/row.hpp> | |
24 | #include <pv/data/decode/rowdata.hpp> | |
f9101a91 JH |
25 | |
26 | using std::vector; | |
27 | ||
28 | namespace pv { | |
29 | namespace data { | |
30 | namespace decode { | |
31 | ||
6a26fc44 | 32 | RowData::RowData(Row* row) : |
5a9146ac SA |
33 | row_(row), |
34 | prev_ann_start_sample_(0) | |
6a26fc44 SA |
35 | { |
36 | assert(row); | |
37 | } | |
38 | ||
f9101a91 JH |
39 | uint64_t RowData::get_max_sample() const |
40 | { | |
8dbbc7f0 | 41 | if (annotations_.empty()) |
f9101a91 | 42 | return 0; |
8dbbc7f0 | 43 | return annotations_.back().end_sample(); |
f9101a91 JH |
44 | } |
45 | ||
f994f496 SA |
46 | uint64_t RowData::get_annotation_count() const |
47 | { | |
48 | return annotations_.size(); | |
49 | } | |
50 | ||
f9101a91 | 51 | void RowData::get_annotation_subset( |
462941e2 | 52 | deque<const pv::data::decode::Annotation*> &dest, |
f9101a91 JH |
53 | uint64_t start_sample, uint64_t end_sample) const |
54 | { | |
6a26fc44 SA |
55 | // Determine whether we must apply per-class filtering or not |
56 | bool all_ann_classes_enabled = true; | |
57 | bool all_ann_classes_disabled = true; | |
58 | ||
59 | uint32_t max_ann_class_id = 0; | |
60 | for (AnnotationClass* c : row_->ann_classes()) { | |
61 | if (!c->visible) | |
62 | all_ann_classes_enabled = false; | |
63 | else | |
64 | all_ann_classes_disabled = false; | |
65 | if (c->id > max_ann_class_id) | |
66 | max_ann_class_id = c->id; | |
67 | } | |
68 | ||
69 | if (all_ann_classes_enabled) { | |
70 | // No filtering, send everyting out as-is | |
71 | for (const auto& annotation : annotations_) | |
72 | if ((annotation.end_sample() > start_sample) && | |
73 | (annotation.start_sample() <= end_sample)) | |
5a9146ac | 74 | dest.push_back(&annotation); |
6a26fc44 SA |
75 | } else { |
76 | if (!all_ann_classes_disabled) { | |
77 | // Filter out invisible annotation classes | |
78 | vector<size_t> class_visible; | |
79 | class_visible.resize(max_ann_class_id + 1, 0); | |
80 | for (AnnotationClass* c : row_->ann_classes()) | |
81 | if (c->visible) | |
82 | class_visible[c->id] = 1; | |
83 | ||
84 | for (const auto& annotation : annotations_) | |
462941e2 | 85 | if ((class_visible[annotation.ann_class_id()]) && |
81dc0221 SA |
86 | (annotation.end_sample() > start_sample) && |
87 | (annotation.start_sample() <= end_sample)) | |
5a9146ac | 88 | dest.push_back(&annotation); |
6a26fc44 SA |
89 | } |
90 | } | |
f9101a91 JH |
91 | } |
92 | ||
f54e68b0 | 93 | const Annotation* RowData::emplace_annotation(srd_proto_data *pdata) |
f9101a91 | 94 | { |
f54e68b0 SA |
95 | const Annotation* result = nullptr; |
96 | ||
5a9146ac SA |
97 | // We insert the annotation in a way so that the annotation list |
98 | // is sorted by start sample. Otherwise, we'd have to sort when | |
99 | // painting, which is expensive | |
100 | ||
101 | if (pdata->start_sample < prev_ann_start_sample_) { | |
102 | // Find location to insert the annotation at | |
103 | ||
104 | auto it = annotations_.end(); | |
105 | do { | |
106 | it--; | |
107 | } while ((it->start_sample() > pdata->start_sample) && (it != annotations_.begin())); | |
108 | ||
109 | // Allow inserting at the front | |
110 | if (it != annotations_.begin()) | |
111 | it++; | |
112 | ||
f54e68b0 SA |
113 | it = annotations_.emplace(it, pdata, row_); |
114 | result = &(*it); | |
5a9146ac SA |
115 | } else { |
116 | annotations_.emplace_back(pdata, row_); | |
f54e68b0 | 117 | result = &(annotations_.back()); |
5a9146ac SA |
118 | prev_ann_start_sample_ = pdata->start_sample; |
119 | } | |
f54e68b0 SA |
120 | |
121 | return result; | |
f9101a91 JH |
122 | } |
123 | ||
870ea3db UH |
124 | } // namespace decode |
125 | } // namespace data | |
126 | } // namespace pv |