QCodeEditor: Update to current cpeditor/QCodeEditor fork, commit ed1196a
[smuview.git] / src / channels / basechannel.hpp
blobd8028126f99b1eebb3ebfc7a6a1cacd721d3a922
1 /*
2 * This file is part of the SmuView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
6 * Copyright (C) 2016-2021 Frank Stettner <frank-stettner@gmx.net>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef CHANNELS_BASECHANNEL_HPP
23 #define CHANNELS_BASECHANNEL_HPP
25 #include <memory>
26 #include <set>
27 #include <string>
28 #include <vector>
30 #include <QObject>
31 #include <QSettings>
32 #include <QString>
34 #include "src/data/datautil.hpp"
36 using std::map;
37 using std::set;
38 using std::shared_ptr;
39 using std::string;
40 using std::vector;
41 using sv::data::measured_quantity_t;
43 namespace sigrok {
44 class Channel;
47 namespace sv {
49 namespace data {
50 class AnalogTimeSignal;
51 class BaseSignal;
54 namespace devices {
55 class BaseDevice;
58 namespace channels {
60 enum class ChannelType {
61 /**
62 * Channels with analog data (Power supplies, loads, DMMs)
64 AnalogChannel,
65 /**
66 * Virtual channel for calculated data
68 MathChannel,
69 /**
70 * Virtual channel for user generated data (e.g. scripts)
72 UserChannel
75 class BaseChannel :
76 public QObject,
77 public std::enable_shared_from_this<BaseChannel>
79 Q_OBJECT
81 public:
82 BaseChannel(
83 shared_ptr<sigrok::Channel> sr_channel,
84 shared_ptr<devices::BaseDevice> parent_device,
85 const set<string> &channel_group_names,
86 double channel_start_timestamp);
87 virtual ~BaseChannel();
89 public:
90 /**
91 * Return the underlying sigrok channel.
93 * HardwareChannels always have a sigrok channel, UserChannels only have a
94 * sigrok channel when created in a UserDevice!
96 shared_ptr<sigrok::Channel> sr_channel() const;
98 /**
99 * Get the name of this channel, i.e. how the device calls it.
101 string name() const;
104 * Set the name of the signal.
106 void set_name(const string &name);
109 * Get the display name of this channel.
111 QString display_name() const;
114 * Get the index number of this channel, i.e. a unique ID assigned by
115 * the device driver.
117 unsigned int index() const;
120 * Get the type of this channel.
122 ChannelType type() const;
125 * Return enabled status of this channel.
127 bool enabled() const;
130 * Set the enabled status of this channel.
132 void set_enabled(bool enabled);
135 * Does this channel have just one signal, thats quantity doesn't change?
137 bool fixed_signal() const;
140 * Set if this channel has just one signal, thats quantity doesn't change
142 void set_fixed_signal(bool fixed_signal);
145 * Return the device, this channel belongs to.
147 shared_ptr<devices::BaseDevice> parent_device();
150 * Get the channel group name, the channel is in. Returns "" if the channel
151 * is not in a channel group.
153 set<string> channel_group_names() const;
156 * Add a channel group name
158 void add_channel_group_name(const string &channel_group_name);
161 * Add a signal to the channel. For now only AnalogTimeSignals
162 * are supported.
164 void add_signal(shared_ptr<data::AnalogTimeSignal> signal);
167 * Add a signal by its quantity, quantity_flags and unit.
169 shared_ptr<data::BaseSignal> add_signal(
170 data::Quantity quantity,
171 set<data::QuantityFlag> quantity_flags,
172 data::Unit unit,
173 string custom_name = "");
176 * Get the actual signal
178 shared_ptr<data::BaseSignal> actual_signal();
181 * Get all signals for this channel. Normaly a measurement quantity only
182 * has one corresponding signal, but for user channels this can be
183 * different.
185 map<measured_quantity_t, vector<shared_ptr<data::BaseSignal>>> signal_map();
188 * Get all signals for this channel.
189 * This function is especially for the Python bindings.
191 vector<shared_ptr<data::BaseSignal>> signals();
194 * Delete all signals from this channel
196 void clear_signals();
198 virtual void save_settings(QSettings &settings) const;
199 virtual void restore_settings(QSettings &settings);
201 protected:
202 static const size_t size_of_double_ = sizeof(double);
204 /** The corresponding sigrok channel object. */
205 shared_ptr<sigrok::Channel> sr_channel_;
206 /** Name of this channel. */
207 string name_;
208 /** Index of this channel. */
209 unsigned int index_;
210 /** Type of this channel. */
211 ChannelType type_;
212 /** Timestamp when this channel was created/started. */
213 double channel_start_timestamp_;
215 /** The device this channel belongs to. */
216 shared_ptr<devices::BaseDevice> parent_device_;
217 /** The channel group names this channel belongs to. */
218 set<string> channel_group_names_;
220 bool fixed_signal_;
221 shared_ptr<data::BaseSignal> actual_signal_;
222 map<measured_quantity_t, vector<shared_ptr<data::BaseSignal>>> signal_map_;
224 public Q_SLOTS:
225 void on_aquisition_start_timestamp_changed(double timestamp);
227 Q_SIGNALS:
228 void channel_start_timestamp_changed(double timestamp);
229 void enabled_changed(const bool enabled);
230 void name_changed(const std::string &name);
231 void signal_added(shared_ptr<sv::data::BaseSignal> signal);
232 void signal_changed(shared_ptr<sv::data::BaseSignal> signal);
236 } // namespace channels
237 } // namespace sv
239 #endif // CHANNELS_BASECHANNEL_HPP