]>
Commit | Line | Data |
---|---|---|
f4e57597 SA |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
efdec55a | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
f4e57597 SA |
19 | */ |
20 | ||
21 | #ifdef ENABLE_DECODE | |
22 | #include <libsigrokdecode/libsigrokdecode.h> | |
23 | #endif | |
24 | ||
25 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
26 | ||
27 | #include "pv/session.hpp" | |
28 | #include "pv/util.hpp" | |
8c339741 | 29 | #include "pv/data/segment.hpp" |
f4e57597 SA |
30 | |
31 | using std::shared_ptr; | |
32 | ||
33 | namespace pv { | |
34 | namespace views { | |
35 | ||
baf867ed | 36 | const char* ViewTypeNames[ViewTypeCount] = { |
03408f5f | 37 | "Trace View", |
baf867ed | 38 | #ifdef ENABLE_DECODE |
24d69d27 SA |
39 | "Binary Decoder Output View", |
40 | "Tabular Decoder Output View" | |
baf867ed SA |
41 | #endif |
42 | }; | |
43 | ||
5ed05b69 SA |
44 | const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz |
45 | ||
a24412db | 46 | ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) : |
5a206446 | 47 | // Note: Place defaults in ViewBase::reset_view_state(), not here |
79926d3f | 48 | QWidget(parent), |
143d322d | 49 | session_(session), |
5a206446 | 50 | is_main_view_(is_main_view) |
f4e57597 SA |
51 | { |
52 | (void)parent; | |
53 | ||
54 | connect(&session_, SIGNAL(signals_changed()), | |
55 | this, SLOT(signals_changed())); | |
56 | connect(&session_, SIGNAL(capture_state_changed(int)), | |
57 | this, SLOT(capture_state_updated(int))); | |
4e86ec70 SA |
58 | connect(&session_, SIGNAL(new_segment(int)), |
59 | this, SLOT(on_new_segment(int))); | |
5ed05b69 SA |
60 | |
61 | connect(&delayed_view_updater_, SIGNAL(timeout()), | |
62 | this, SLOT(perform_delayed_view_update())); | |
63 | delayed_view_updater_.setSingleShot(true); | |
64 | delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate); | |
f4e57597 SA |
65 | } |
66 | ||
0a952555 SA |
67 | bool ViewBase::is_main_view() const |
68 | { | |
69 | return is_main_view_; | |
70 | } | |
71 | ||
5a206446 SA |
72 | void ViewBase::reset_view_state() |
73 | { | |
5a206446 SA |
74 | current_segment_ = 0; |
75 | } | |
76 | ||
f4e57597 SA |
77 | Session& ViewBase::session() |
78 | { | |
79 | return session_; | |
80 | } | |
81 | ||
82 | const Session& ViewBase::session() const | |
83 | { | |
84 | return session_; | |
85 | } | |
86 | ||
87 | void ViewBase::clear_signals() | |
88 | { | |
03408f5f | 89 | clear_signalbases(); |
f4e57597 SA |
90 | } |
91 | ||
533b67b7 | 92 | vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const |
5ed05b69 SA |
93 | { |
94 | return signalbases_; | |
95 | } | |
96 | ||
97 | void ViewBase::clear_signalbases() | |
98 | { | |
f4ab4b5c | 99 | for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) { |
5ed05b69 SA |
100 | disconnect(signalbase.get(), SIGNAL(samples_cleared()), |
101 | this, SLOT(on_data_updated())); | |
7f894d95 SA |
102 | disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), |
103 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
5ed05b69 SA |
104 | } |
105 | ||
106 | signalbases_.clear(); | |
107 | } | |
108 | ||
109 | void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase) | |
110 | { | |
533b67b7 | 111 | signalbases_.push_back(signalbase); |
5ed05b69 SA |
112 | |
113 | connect(signalbase.get(), SIGNAL(samples_cleared()), | |
114 | this, SLOT(on_data_updated())); | |
7f894d95 SA |
115 | connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), |
116 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
5ed05b69 SA |
117 | } |
118 | ||
f4e57597 SA |
119 | #ifdef ENABLE_DECODE |
120 | void ViewBase::clear_decode_signals() | |
121 | { | |
e77de61f | 122 | decode_signals_.clear(); |
f4e57597 SA |
123 | } |
124 | ||
ad908057 | 125 | void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal) |
f4e57597 | 126 | { |
533b67b7 | 127 | decode_signals_.push_back(signal); |
f4e57597 SA |
128 | } |
129 | ||
ad908057 | 130 | void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal) |
f4e57597 | 131 | { |
533b67b7 SA |
132 | decode_signals_.erase(std::remove_if( |
133 | decode_signals_.begin(), decode_signals_.end(), | |
134 | [&](shared_ptr<data::DecodeSignal> s) { return s == signal; }), | |
135 | decode_signals_.end()); | |
f4e57597 SA |
136 | } |
137 | #endif | |
138 | ||
139 | void ViewBase::save_settings(QSettings &settings) const | |
140 | { | |
141 | (void)settings; | |
142 | } | |
143 | ||
144 | void ViewBase::restore_settings(QSettings &settings) | |
145 | { | |
146 | (void)settings; | |
147 | } | |
148 | ||
9a35b05d SA |
149 | void ViewBase::focus_on_range(uint64_t start_sample, uint64_t end_sample) |
150 | { | |
151 | (void)start_sample; | |
152 | (void)end_sample; | |
153 | } | |
154 | ||
7ea2a4ff | 155 | void ViewBase::trigger_event(int segment_id, util::Timestamp location) |
f4e57597 | 156 | { |
7ea2a4ff | 157 | (void)segment_id; |
f4e57597 SA |
158 | (void)location; |
159 | } | |
160 | ||
161 | void ViewBase::signals_changed() | |
162 | { | |
163 | } | |
164 | ||
4e86ec70 SA |
165 | void ViewBase::on_new_segment(int new_segment_id) |
166 | { | |
167 | (void)new_segment_id; | |
168 | } | |
169 | ||
558ad6ce SA |
170 | void ViewBase::on_segment_completed(int new_segment_id) |
171 | { | |
172 | (void)new_segment_id; | |
173 | } | |
174 | ||
f4e57597 SA |
175 | void ViewBase::capture_state_updated(int state) |
176 | { | |
177 | (void)state; | |
178 | } | |
179 | ||
5ed05b69 SA |
180 | void ViewBase::perform_delayed_view_update() |
181 | { | |
182 | } | |
183 | ||
7f894d95 | 184 | void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample, |
8c339741 SA |
185 | uint64_t end_sample) |
186 | { | |
187 | (void)start_sample; | |
188 | (void)end_sample; | |
189 | ||
7f894d95 | 190 | if (segment_id != current_segment_) |
8c339741 SA |
191 | return; |
192 | ||
193 | if (!delayed_view_updater_.isActive()) | |
194 | delayed_view_updater_.start(); | |
195 | } | |
196 | ||
5ed05b69 | 197 | void ViewBase::on_data_updated() |
f4e57597 | 198 | { |
5ed05b69 SA |
199 | if (!delayed_view_updater_.isActive()) |
200 | delayed_view_updater_.start(); | |
f4e57597 SA |
201 | } |
202 | ||
870ea3db | 203 | } // namespace views |
f4e57597 | 204 | } // namespace pv |