]>
Commit | Line | Data |
---|---|---|
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 | |
18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
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" | |
29 | #include "pv/data/segment.hpp" | |
30 | ||
31 | using std::shared_ptr; | |
32 | ||
33 | namespace pv { | |
34 | namespace views { | |
35 | ||
36 | const char* ViewTypeNames[ViewTypeCount] = { | |
37 | "Trace View", | |
38 | #ifdef ENABLE_DECODE | |
39 | "Binary Decoder Output View", | |
40 | "Tabular Decoder Output View" | |
41 | #endif | |
42 | }; | |
43 | ||
44 | const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz | |
45 | ||
46 | ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) : | |
47 | // Note: Place defaults in ViewBase::reset_view_state(), not here | |
48 | QWidget(parent), | |
49 | session_(session), | |
50 | is_main_view_(is_main_view) | |
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))); | |
58 | connect(&session_, SIGNAL(new_segment(int)), | |
59 | this, SLOT(on_new_segment(int))); | |
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); | |
65 | } | |
66 | ||
67 | bool ViewBase::is_main_view() const | |
68 | { | |
69 | return is_main_view_; | |
70 | } | |
71 | ||
72 | void ViewBase::reset_view_state() | |
73 | { | |
74 | current_segment_ = 0; | |
75 | } | |
76 | ||
77 | Session& ViewBase::session() | |
78 | { | |
79 | return session_; | |
80 | } | |
81 | ||
82 | const Session& ViewBase::session() const | |
83 | { | |
84 | return session_; | |
85 | } | |
86 | ||
87 | vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const | |
88 | { | |
89 | return signalbases_; | |
90 | } | |
91 | ||
92 | void ViewBase::clear_signalbases() | |
93 | { | |
94 | for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) { | |
95 | disconnect(signalbase.get(), SIGNAL(samples_cleared()), | |
96 | this, SLOT(on_data_updated())); | |
97 | disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), | |
98 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
99 | } | |
100 | ||
101 | signalbases_.clear(); | |
102 | } | |
103 | ||
104 | void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase) | |
105 | { | |
106 | signalbases_.push_back(signalbase); | |
107 | ||
108 | connect(signalbase.get(), SIGNAL(samples_cleared()), | |
109 | this, SLOT(on_data_updated())); | |
110 | connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), | |
111 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
112 | } | |
113 | ||
114 | void ViewBase::remove_signalbase(const shared_ptr<data::SignalBase> signalbase) | |
115 | { | |
116 | disconnect(signalbase.get(), SIGNAL(samples_cleared()), | |
117 | this, SLOT(on_data_updated())); | |
118 | disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), | |
119 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
120 | ||
121 | signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), | |
122 | [&](shared_ptr<data::SignalBase> s) { return s == signalbase; }), | |
123 | signalbases_.end()); | |
124 | } | |
125 | ||
126 | #ifdef ENABLE_DECODE | |
127 | void ViewBase::clear_decode_signals() | |
128 | { | |
129 | decode_signals_.clear(); | |
130 | } | |
131 | ||
132 | void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
133 | { | |
134 | decode_signals_.push_back(signal); | |
135 | } | |
136 | ||
137 | void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
138 | { | |
139 | decode_signals_.erase(std::remove_if( | |
140 | decode_signals_.begin(), decode_signals_.end(), | |
141 | [&](shared_ptr<data::DecodeSignal> s) { return s == signal; }), | |
142 | decode_signals_.end()); | |
143 | } | |
144 | #endif | |
145 | ||
146 | void ViewBase::save_settings(QSettings &settings) const | |
147 | { | |
148 | (void)settings; | |
149 | } | |
150 | ||
151 | void ViewBase::restore_settings(QSettings &settings) | |
152 | { | |
153 | (void)settings; | |
154 | } | |
155 | ||
156 | void ViewBase::focus_on_range(uint64_t start_sample, uint64_t end_sample) | |
157 | { | |
158 | (void)start_sample; | |
159 | (void)end_sample; | |
160 | } | |
161 | ||
162 | void ViewBase::trigger_event(int segment_id, util::Timestamp location) | |
163 | { | |
164 | (void)segment_id; | |
165 | (void)location; | |
166 | } | |
167 | ||
168 | void ViewBase::signals_changed() | |
169 | { | |
170 | } | |
171 | ||
172 | void ViewBase::on_new_segment(int new_segment_id) | |
173 | { | |
174 | (void)new_segment_id; | |
175 | } | |
176 | ||
177 | void ViewBase::on_segment_completed(int new_segment_id) | |
178 | { | |
179 | (void)new_segment_id; | |
180 | } | |
181 | ||
182 | void ViewBase::capture_state_updated(int state) | |
183 | { | |
184 | (void)state; | |
185 | } | |
186 | ||
187 | void ViewBase::perform_delayed_view_update() | |
188 | { | |
189 | } | |
190 | ||
191 | void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample, | |
192 | uint64_t end_sample) | |
193 | { | |
194 | (void)start_sample; | |
195 | (void)end_sample; | |
196 | ||
197 | if (segment_id != current_segment_) | |
198 | return; | |
199 | ||
200 | if (!delayed_view_updater_.isActive()) | |
201 | delayed_view_updater_.start(); | |
202 | } | |
203 | ||
204 | void ViewBase::on_data_updated() | |
205 | { | |
206 | if (!delayed_view_updater_.isActive()) | |
207 | delayed_view_updater_.start(); | |
208 | } | |
209 | ||
210 | } // namespace views | |
211 | } // namespace pv |