signal_helper.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_GUI_INCLUDE_CORBO_GUI_SIGNAL_HELPER_H_
26 #define SRC_GUI_INCLUDE_CORBO_GUI_SIGNAL_HELPER_H_
27 
29 #include <corbo-core/signals.h>
30 #include <QHash>
31 #include <QObject>
32 #include <QSet>
33 #include <QString>
34 #include <map>
35 #include <memory>
36 
37 namespace corbo {
38 namespace gui {
39 
40 class SignalHelper : public QObject
41 {
42  Q_OBJECT
43 
44  public:
45  using Ptr = std::shared_ptr<SignalHelper>;
46  using ConstPtr = std::shared_ptr<const SignalHelper>;
47 
48  static constexpr const int ALL_VALUES = -1;
49 
50  struct SignalData
51  {
52  QString short_name;
53  QString name;
54  QStringList namespaces;
55  int dimension = 1;
56  bool zero_order_hold = false;
58  int task_id = 0;
59  QSet<int> active_indices;
60  QStringList value_labels;
61  };
62  using SignalMap = QHash<QString, SignalData>;
63 
64  explicit SignalHelper(QObject* parent = 0) : QObject(parent) {}
65 
66  void addSignal(const messages::Signal& signal);
67  void addMeasurement(const QString& name, Measurement::ConstPtr measurement);
68  void addTimeSeries(const QString& name, TimeSeriesSignal::Ptr ts);
69  void addIndexedValues(const QString& name, IndexedValuesSignal::Ptr indexed_values);
70  void addIndexedValuesSet(const QString& name, IndexedValuesSetSignal::Ptr indexed_values_set);
71  void addMatrixSignal(const QString& name, MatrixSignal::Ptr matrix_signal);
72  // void addSignal(const QString& name, const SignalInterface::Ptr signal);
73 
74  void removeSignal(const QString& key);
75  void removeSignal(const QString& key, int value_idx);
77  void clearSeries(int task_id);
78  void clearNamespace(const QString& namespace_pattern, int task_id);
79  void clearAll();
80 
81  SignalData* signalData(const QString& key);
82  const SignalData* signalData(const QString& key) const;
83 
84  const SignalMap& signalMap() const { return _signal_map; }
85  SignalMap& signalMap() { return _signal_map; }
86 
87  static void extractNamespace(const QString& name, QStringList& namespaces);
88  static QString name2Key(const QString& name, int id);
89  static bool key2Name(const QString& key, QString& name, int& id);
90 
91  int currentSeriesId() const { return _id; }
92 
93  void startNewSeries()
94  {
95  ++_id;
96  emit newSeries(_id);
97  }
98 
99  const std::map<int, CommonSignalTarget>& getSignalTree() const { return _signal_tree_map; }
100  std::map<int, CommonSignalTarget>& getSignalTreeRef() { return _signal_tree_map; }
101 
102  void printSignals();
103 
104  signals:
105  void newSignal(const QString& key, SignalData& signal_data); // TODO(roesmann) do we actually need write access to the signal data?
106 
107  void newMeasurement(const QString& key, Measurement::ConstPtr measurement, SignalData& signal_data, bool first);
108  void newTimeSeries(const QString& key, TimeSeriesSignal::ConstPtr ts, SignalData& signal_data, bool first);
109  void newIndexedValues(const QString& key, IndexedValuesSignal::ConstPtr indexed_values, SignalData& signal_data, bool first);
110  // void newIndexedValuesSet(const QString& key, IndexedValuesSetSignal::ConstPtr indexed_values, SignalData& signal_data, bool first);
111  void newMatrixSignal(const QString& key, MatrixSignal::ConstPtr matrix_signal, SignalData& signal_data, bool first);
112  void signalRemoved(const QString& key, int value_idx);
113  void newSeries(int task_id);
114 
115  protected:
116  QString name2Key(const QString& name) const;
117 
118  private:
120  std::map<int, CommonSignalTarget> _signal_tree_map;
121 
122  int _id = 0;
123 };
124 
125 } // namespace gui
126 } // namespace corbo
127 
128 #endif // SRC_GUI_INCLUDE_CORBO_GUI_SIGNAL_HELPER_H_
corbo::MatrixSignal::Ptr
std::shared_ptr< MatrixSignal > Ptr
Definition: signals.h:564
corbo::gui::SignalHelper::getSignalTree
const std::map< int, CommonSignalTarget > & getSignalTree() const
Definition: signal_helper.h:165
corbo::gui::SignalHelper::SignalHelper
SignalHelper(QObject *parent=0)
Definition: signal_helper.h:130
corbo::gui::SignalHelper::clearNamespace
void clearNamespace(const QString &namespace_pattern, int task_id)
Definition: signal_helper.cpp:472
corbo::gui::SignalHelper::newSeries
void newSeries(int task_id)
corbo::gui::SignalHelper::newMeasurement
void newMeasurement(const QString &key, Measurement::ConstPtr measurement, SignalData &signal_data, bool first)
corbo::gui::SignalHelper::SignalData::value_labels
QStringList value_labels
Definition: signal_helper.h:126
corbo::gui::SignalHelper::SignalData::namespaces
QStringList namespaces
Definition: signal_helper.h:120
corbo::gui::SignalHelper::SignalData::name
QString name
Definition: signal_helper.h:119
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::gui::SignalHelper::clearSeries
void clearSeries(int task_id)
Definition: signal_helper.cpp:454
corbo::MatrixSignal::ConstPtr
std::shared_ptr< const MatrixSignal > ConstPtr
Definition: signals.h:565
corbo::SignalInterface::Ptr
std::shared_ptr< SignalInterface > Ptr
Definition: signals.h:158
corbo::gui::SignalHelper::signalMap
const SignalMap & signalMap() const
Definition: signal_helper.h:150
corbo::gui::SignalHelper::key2Name
static bool key2Name(const QString &key, QString &name, int &id)
Definition: signal_helper.cpp:435
corbo::gui::SignalHelper::SignalData::zero_order_hold
bool zero_order_hold
Definition: signal_helper.h:122
corbo::gui::SignalHelper::newIndexedValues
void newIndexedValues(const QString &key, IndexedValuesSignal::ConstPtr indexed_values, SignalData &signal_data, bool first)
corbo::gui::SignalHelper::SignalData::short_name
QString short_name
Definition: signal_helper.h:118
corbo::gui::SignalHelper::SignalData::active_indices
QSet< int > active_indices
Definition: signal_helper.h:125
corbo::gui::SignalHelper::addMeasurement
void addMeasurement(const QString &name, Measurement::ConstPtr measurement)
Definition: signal_helper.cpp:166
corbo::gui::SignalHelper::_signal_tree_map
std::map< int, CommonSignalTarget > _signal_tree_map
Definition: signal_helper.h:186
corbo::gui::SignalHelper::addIndexedValuesSet
void addIndexedValuesSet(const QString &name, IndexedValuesSetSignal::Ptr indexed_values_set)
Definition: signal_helper.cpp:286
corbo::gui::SignalHelper::addSignal
void addSignal(const messages::Signal &signal)
Definition: signal_helper.cpp:79
corbo::gui::SignalHelper::name2Key
static QString name2Key(const QString &name, int id)
Definition: signal_helper.cpp:433
corbo::gui::SignalHelper::signalData
SignalData * signalData(const QString &key)
Definition: signal_helper.cpp:411
corbo::gui::SignalHelper::addMatrixSignal
void addMatrixSignal(const QString &name, MatrixSignal::Ptr matrix_signal)
Definition: signal_helper.cpp:326
corbo::gui::SignalHelper::SignalData::dimension
int dimension
Definition: signal_helper.h:121
corbo::gui::SignalHelper::clearAll
void clearAll()
Definition: signal_helper.cpp:492
signals.h
corbo::gui::SignalHelper::SignalData::task_id
int task_id
Definition: signal_helper.h:124
corbo::gui::SignalHelper::addTimeSeries
void addTimeSeries(const QString &name, TimeSeriesSignal::Ptr ts)
Definition: signal_helper.cpp:205
corbo::gui::SignalHelper::removeSignal
void removeSignal(const QString &key)
Definition: signal_helper.cpp:507
common_signal_target.h
corbo::gui::SignalHelper::currentSeriesId
int currentSeriesId() const
Definition: signal_helper.h:157
corbo::IndexedValuesSignal::Ptr
std::shared_ptr< IndexedValuesSignal > Ptr
Definition: signals.h:415
corbo::gui::SignalHelper::signalRemoved
void signalRemoved(const QString &key, int value_idx)
corbo::gui::SignalHelper::newTimeSeries
void newTimeSeries(const QString &key, TimeSeriesSignal::ConstPtr ts, SignalData &signal_data, bool first)
corbo::TimeSeriesSignal::ConstPtr
std::shared_ptr< const TimeSeriesSignal > ConstPtr
Definition: signals.h:270
corbo::gui::SignalHelper::extractNamespace
static void extractNamespace(const QString &name, QStringList &namespaces)
Definition: signal_helper.cpp:430
corbo::gui::SignalHelper::getSignalTreeRef
std::map< int, CommonSignalTarget > & getSignalTreeRef()
Definition: signal_helper.h:166
corbo::gui::SignalHelper::addIndexedValues
void addIndexedValues(const QString &name, IndexedValuesSignal::Ptr indexed_values)
Definition: signal_helper.cpp:248
corbo::IndexedValuesSetSignal::Ptr
std::shared_ptr< IndexedValuesSetSignal > Ptr
Definition: signals.h:499
corbo::gui::SignalHelper::SignalData
Definition: signal_helper.h:116
corbo::gui::SignalHelper::newSignal
void newSignal(const QString &key, SignalData &signal_data)
corbo::IndexedValuesSignal::ConstPtr
std::shared_ptr< const IndexedValuesSignal > ConstPtr
Definition: signals.h:416
corbo::gui::SignalHelper::_id
int _id
Definition: signal_helper.h:188
corbo::gui::SignalHelper::startNewSeries
void startNewSeries()
Definition: signal_helper.h:159
corbo::gui::SignalHelper::SignalMap
QHash< QString, SignalData > SignalMap
Definition: signal_helper.h:128
corbo::gui::SignalHelper::_signal_map
SignalMap _signal_map
Definition: signal_helper.h:185
corbo::gui::SignalHelper::Ptr
std::shared_ptr< SignalHelper > Ptr
Definition: signal_helper.h:111
corbo::gui::SignalHelper::SignalData::signal
SignalInterface::Ptr signal
Definition: signal_helper.h:123
corbo::gui::SignalHelper::printSignals
void printSignals()
Definition: signal_helper.cpp:552
corbo::gui::SignalHelper::newMatrixSignal
void newMatrixSignal(const QString &key, MatrixSignal::ConstPtr matrix_signal, SignalData &signal_data, bool first)
corbo::Measurement::ConstPtr
std::shared_ptr< const Measurement > ConstPtr
Definition: signals.h:197
corbo::gui::SignalHelper::ConstPtr
std::shared_ptr< const SignalHelper > ConstPtr
Definition: signal_helper.h:112
corbo::gui::SignalHelper::clearCurrentSeries
void clearCurrentSeries()
Definition: signal_helper.h:142
corbo::gui::SignalHelper::ALL_VALUES
static constexpr const int ALL_VALUES
Definition: signal_helper.h:114
corbo::TimeSeriesSignal::Ptr
std::shared_ptr< TimeSeriesSignal > Ptr
Definition: signals.h:269


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:12