]>
Commit | Line | Data |
---|---|---|
55d3603d JH |
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 | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
55d3603d JH |
18 | */ |
19 | ||
f4e57597 SA |
20 | #ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP |
21 | #define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP | |
55d3603d | 22 | |
5a9146ac | 23 | #include <config.h> |
2acdb232 | 24 | #include "trace.hpp" |
55d3603d | 25 | |
7491a29f | 26 | #include <list> |
4e5a4405 | 27 | #include <map> |
f9abf97e | 28 | #include <memory> |
50631798 | 29 | #include <vector> |
4e5a4405 | 30 | |
9ba13f5e | 31 | #include <QColor> |
c6b4e925 | 32 | #include <QCheckBox> |
5a9146ac | 33 | #include <QElapsedTimer> |
74bf6666 | 34 | #include <QPolygon> |
cf0a3c9c | 35 | #include <QPushButton> |
613d097c | 36 | #include <QSignalMapper> |
5b6ae103 | 37 | #include <QTimer> |
613d097c | 38 | |
3cc9ad7b | 39 | #include <pv/binding/decoder.hpp> |
a82325d1 | 40 | #include <pv/data/decode/decoder.hpp> |
20d90d22 | 41 | #include <pv/data/decode/annotation.hpp> |
2acdb232 | 42 | #include <pv/data/decode/row.hpp> |
aca9aa83 | 43 | #include <pv/data/signalbase.hpp> |
4e5a4405 | 44 | |
5a9146ac SA |
45 | #define DECODETRACE_SHOW_RENDER_TIME 0 |
46 | ||
84002113 | 47 | using std::deque; |
6f925ba9 UH |
48 | using std::list; |
49 | using std::map; | |
84002113 | 50 | using std::mutex; |
6f925ba9 UH |
51 | using std::pair; |
52 | using std::shared_ptr; | |
53 | using std::vector; | |
54 | ||
5a9146ac SA |
55 | using pv::data::SignalBase; |
56 | using pv::data::decode::Annotation; | |
57 | using pv::data::decode::Decoder; | |
6a26fc44 SA |
58 | using pv::data::decode::Row; |
59 | ||
8bd26d8b | 60 | struct srd_channel; |
e563a7c0 | 61 | struct srd_decoder; |
4e5a4405 | 62 | |
55d3603d | 63 | namespace pv { |
119aff65 | 64 | |
2b81ae46 | 65 | class Session; |
83c23cc9 | 66 | |
119aff65 | 67 | namespace data { |
9f97b357 | 68 | struct DecodeChannel; |
ad908057 | 69 | class DecodeSignal; |
7491a29f JH |
70 | |
71 | namespace decode { | |
72 | class Decoder; | |
6a26fc44 | 73 | class Row; |
7491a29f | 74 | } |
20f59e95 | 75 | } // namespace data |
119aff65 | 76 | |
dd048a7e JH |
77 | namespace widgets { |
78 | class DecoderGroupBox; | |
79 | } | |
80 | ||
f4e57597 | 81 | namespace views { |
1573bf16 | 82 | namespace trace { |
55d3603d | 83 | |
6a26fc44 | 84 | struct DecodeTraceRow { |
84002113 SA |
85 | // When adding a field, make sure it's initialized properly in |
86 | // DecodeTrace::update_rows() | |
87 | ||
6a26fc44 | 88 | Row* decode_row; |
74bf6666 | 89 | unsigned int height, expanded_height, title_width, animation_step; |
81dc0221 | 90 | bool exists, currently_visible, has_hidden_classes; |
74bf6666 SA |
91 | bool expand_marker_highlighted, expanding, expanded, collapsing; |
92 | QPolygon expand_marker_shape; | |
93 | float anim_height, anim_shape; | |
dca3cbee SA |
94 | |
95 | QWidget* container; | |
c6b4e925 SA |
96 | QWidget* header_container; |
97 | QWidget* selector_container; | |
98 | vector<QCheckBox*> selectors; | |
bdb97140 SA |
99 | |
100 | QColor row_color; | |
101 | map<uint32_t, QColor> ann_class_color; | |
84002113 SA |
102 | }; |
103 | ||
b9329558 | 104 | class DecodeTrace : public Trace |
55d3603d | 105 | { |
e0fc5810 JH |
106 | Q_OBJECT |
107 | ||
06bb4e6a | 108 | private: |
641574bc SA |
109 | static const QColor ErrorBgColor; |
110 | static const QColor NoDecodeColor; | |
81dc0221 | 111 | static const QColor ExpandMarkerWarnColor; |
c6b4e925 SA |
112 | static const uint8_t ExpansionAreaHeaderAlpha; |
113 | static const uint8_t ExpansionAreaAlpha; | |
06bb4e6a | 114 | |
88908838 | 115 | static const int ArrowSize; |
06e810f2 | 116 | static const double EndCapWidth; |
aee9dcf3 | 117 | static const int RowTitleMargin; |
06e810f2 JH |
118 | static const int DrawPadding; |
119 | ||
5b6ae103 | 120 | static const int MaxTraceUpdateRate; |
74bf6666 | 121 | static const unsigned int AnimationDurationInTicks; |
5b6ae103 | 122 | |
55d3603d | 123 | public: |
5a9146ac | 124 | DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase, |
6e89374a | 125 | int index); |
55d3603d | 126 | |
ab185f78 SA |
127 | ~DecodeTrace(); |
128 | ||
55d3603d JH |
129 | bool enabled() const; |
130 | ||
5a9146ac | 131 | shared_ptr<SignalBase> base() const; |
bb7dd726 | 132 | |
a5d93c27 JH |
133 | /** |
134 | * Computes the vertical extents of the contents of this row item. | |
135 | * @return A pair containing the minimum and maximum y-values. | |
136 | */ | |
6f925ba9 | 137 | pair<int, int> v_extents() const; |
a5d93c27 | 138 | |
55d3603d | 139 | /** |
fe08b6e8 JH |
140 | * Paints the background layer of the trace with a QPainter |
141 | * @param p the QPainter to paint into. | |
3eb29afd | 142 | * @param pp the painting parameters object to paint with.. |
223d0c37 | 143 | */ |
60938e04 | 144 | void paint_back(QPainter &p, ViewItemPaintParams &pp); |
fe08b6e8 JH |
145 | |
146 | /** | |
147 | * Paints the mid-layer of the trace with a QPainter | |
55d3603d | 148 | * @param p the QPainter to paint into. |
3eb29afd | 149 | * @param pp the painting parameters object to paint with. |
223d0c37 | 150 | */ |
60938e04 | 151 | void paint_mid(QPainter &p, ViewItemPaintParams &pp); |
55d3603d | 152 | |
88908838 JH |
153 | /** |
154 | * Paints the foreground layer of the trace with a QPainter | |
155 | * @param p the QPainter to paint into. | |
3eb29afd | 156 | * @param pp the painting parameters object to paint with. |
223d0c37 | 157 | */ |
60938e04 | 158 | void paint_fore(QPainter &p, ViewItemPaintParams &pp); |
88908838 | 159 | |
4e5a4405 JH |
160 | void populate_popup_form(QWidget *parent, QFormLayout *form); |
161 | ||
9e773fec | 162 | QMenu* create_header_context_menu(QWidget *parent); |
c51482b3 | 163 | |
be843692 SA |
164 | virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos); |
165 | ||
74bf6666 SA |
166 | virtual void delete_pressed(); |
167 | ||
168 | virtual void hover_point_changed(const QPoint &hp); | |
169 | ||
170 | virtual void mouse_left_press_event(const QMouseEvent* event); | |
5ed1adf5 | 171 | |
ad50ac1a | 172 | private: |
5a9146ac | 173 | void draw_annotations(vector<const Annotation*> annotations, QPainter &p, |
bdb97140 | 174 | const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row); |
50631798 | 175 | |
bdb97140 SA |
176 | void draw_annotation(const Annotation* a, QPainter &p, |
177 | const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row) const; | |
06e810f2 | 178 | |
5a9146ac | 179 | void draw_annotation_block(qreal start, qreal end, Annotation::Class ann_class, |
bdb97140 | 180 | bool use_ann_format, QPainter &p, int y, const DecodeTraceRow& row) const; |
50631798 | 181 | |
bdb97140 | 182 | void draw_instant(const Annotation* a, QPainter &p, qreal x, int y) const; |
06e810f2 | 183 | |
bdb97140 | 184 | void draw_range(const Annotation* a, QPainter &p, qreal start, qreal end, |
5a9146ac | 185 | int y, const ViewItemPaintParams &pp, int row_title_width) const; |
06e810f2 | 186 | |
5a9146ac | 187 | void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp); |
ad50ac1a | 188 | |
bdb97140 | 189 | void draw_unresolved_period(QPainter &p, int left, int right) const; |
7f8517f6 | 190 | |
6f925ba9 | 191 | pair<double, double> get_pixels_offset_samples_per_pixel() const; |
7f8517f6 SA |
192 | |
193 | /** | |
194 | * Determines the start and end sample for a given pixel range. | |
195 | * @param x_start the X coordinate of the start sample in the view | |
196 | * @param x_end the X coordinate of the end sample in the view | |
197 | * @return Returns a pair containing the start sample and the end | |
198 | * sample that correspond to the start and end coordinates. | |
199 | */ | |
67fb15bf | 200 | pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const; |
5dfeb70f | 201 | |
9ba13f5e SA |
202 | QColor get_row_color(int row_index) const; |
203 | QColor get_annotation_color(QColor row_color, int annotation_index) const; | |
204 | ||
6a26fc44 | 205 | unsigned int get_row_y(const DecodeTraceRow* row) const; |
84002113 | 206 | |
6a26fc44 | 207 | DecodeTraceRow* get_row_at_point(const QPoint &point); |
e2f90c50 | 208 | |
117cdea3 | 209 | const QString get_annotation_at_point(const QPoint &point); |
e2f90c50 | 210 | |
cf0a3c9c SA |
211 | void update_stack_button(); |
212 | ||
5a9146ac | 213 | void create_decoder_form(int index, shared_ptr<Decoder> &dec, |
7491a29f JH |
214 | QWidget *parent, QFormLayout *form); |
215 | ||
6ac6242b | 216 | QComboBox* create_channel_selector(QWidget *parent, |
a82325d1 | 217 | const data::decode::DecodeChannel *ch); |
9f97b357 | 218 | QComboBox* create_channel_selector_init_state(QWidget *parent, |
a82325d1 | 219 | const data::decode::DecodeChannel *ch); |
4e5a4405 | 220 | |
5a9146ac | 221 | void export_annotations(vector<const Annotation*> *annotations) const; |
5a914348 | 222 | |
6a26fc44 | 223 | void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id); |
84002113 SA |
224 | void update_rows(); |
225 | ||
c6b4e925 SA |
226 | /** |
227 | * Sets row r to expanded state without forcing an update of the view | |
228 | */ | |
6a26fc44 | 229 | void set_row_expanded(DecodeTraceRow* r); |
c6b4e925 SA |
230 | |
231 | /** | |
232 | * Sets row r to collapsed state without forcing an update of the view | |
233 | */ | |
6a26fc44 | 234 | void set_row_collapsed(DecodeTraceRow* r); |
c6b4e925 SA |
235 | |
236 | void update_expanded_rows(); | |
237 | ||
e9213170 | 238 | private Q_SLOTS: |
ab185f78 SA |
239 | void on_setting_changed(const QString &key, const QVariant &value); |
240 | ||
ad908057 | 241 | void on_new_annotations(); |
5b6ae103 | 242 | void on_delayed_trace_update(); |
eee3eab9 | 243 | void on_decode_reset(); |
1b56c646 | 244 | void on_decode_finished(); |
556259d2 | 245 | void on_pause_decode(); |
9cef9567 | 246 | |
c51482b3 JH |
247 | void on_delete(); |
248 | ||
6ac6242b | 249 | void on_channel_selected(int); |
4e5a4405 | 250 | |
9f97b357 SA |
251 | void on_channels_updated(); |
252 | ||
253 | void on_init_state_changed(int); | |
407c9ebe | 254 | |
7491a29f JH |
255 | void on_stack_decoder(srd_decoder *decoder); |
256 | ||
613d097c JH |
257 | void on_delete_decoder(int index); |
258 | ||
dd048a7e | 259 | void on_show_hide_decoder(int index); |
6a26fc44 SA |
260 | void on_show_hide_row(int row_id); |
261 | void on_show_hide_class(QWidget* sender); | |
dd048a7e | 262 | |
c764c995 SA |
263 | void on_copy_annotation_to_clipboard(); |
264 | ||
be843692 | 265 | void on_export_row(); |
5a914348 | 266 | void on_export_all_rows(); |
99ba5f28 SA |
267 | void on_export_row_with_cursor(); |
268 | void on_export_all_rows_with_cursor(); | |
be843692 | 269 | void on_export_row_from_here(); |
5a914348 | 270 | void on_export_all_rows_from_here(); |
be843692 | 271 | |
74bf6666 SA |
272 | void on_animation_timer(); |
273 | ||
55d3603d | 274 | private: |
2b81ae46 | 275 | pv::Session &session_; |
ad908057 | 276 | shared_ptr<data::DecodeSignal> decode_signal_; |
e0fc5810 | 277 | |
6a26fc44 | 278 | deque<DecodeTraceRow> rows_; |
84002113 | 279 | mutable mutex row_modification_mutex_; |
4e5a4405 | 280 | |
9f97b357 SA |
281 | map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID |
282 | map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID | |
6f925ba9 | 283 | list< shared_ptr<pv::binding::Decoder> > bindings_; |
4e5a4405 | 284 | |
6a26fc44 | 285 | const Row* selected_row_; |
99ba5f28 | 286 | pair<uint64_t, uint64_t> selected_sample_range_; |
be843692 | 287 | |
6f925ba9 | 288 | vector<pv::widgets::DecoderGroupBox*> decoder_forms_; |
cf0a3c9c | 289 | QPushButton* stack_button_; |
613d097c | 290 | |
9741d6e0 SA |
291 | unsigned int default_row_height_, annotation_height_; |
292 | unsigned int visible_rows_, max_visible_rows_; | |
88908838 | 293 | |
752281db | 294 | int min_useful_label_width_; |
84002113 | 295 | bool always_show_all_rows_; |
752281db | 296 | |
6a26fc44 SA |
297 | QSignalMapper delete_mapper_, show_hide_mapper_; |
298 | QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_; | |
5b6ae103 | 299 | |
74bf6666 SA |
300 | QTimer delayed_trace_updater_, animation_timer_; |
301 | ||
302 | QPolygon default_marker_shape_; | |
5a9146ac SA |
303 | |
304 | #if DECODETRACE_SHOW_RENDER_TIME | |
305 | QElapsedTimer render_time_; | |
306 | #endif | |
55d3603d JH |
307 | }; |
308 | ||
1573bf16 | 309 | } // namespace trace |
f4e57597 | 310 | } // namespace views |
55d3603d JH |
311 | } // namespace pv |
312 | ||
f4e57597 | 313 | #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP |