scope_widget.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_SCOPE_WIDGET_H_
26 #define SRC_GUI_INCLUDE_CORBO_GUI_SCOPE_WIDGET_H_
27 
28 #include <corbo-communication/messages/core/signals.pb.h>
30 #include <corbo-gui/utilities.h>
31 
32 #include <qcustomplot.h>
33 
34 #include <QColor>
35 #include <QHash>
36 #include <QString>
37 #include <QVector>
38 #include <QWidget>
39 
40 namespace corbo {
41 namespace gui {
42 
43 class ScopeWidget : public QWidget
44 {
45  Q_OBJECT
46 
47  public:
48  explicit ScopeWidget(SignalHelper::ConstPtr signal_helper, QWidget* parent = 0);
49  virtual ~ScopeWidget();
50 
52 
53  QSize sizeHint() const override;
54 
55  bool hasSignal(const QString& key, int value_idx) const;
56 
57  public slots:
58  void addSignal(const QString& signal_key, int value_idx);
59  void addSignal(const QString& signal_key, int value_idx, const SignalHelper::SignalData& signal_data);
60 
61  void addMeasurement(const QString& key, Measurement::ConstPtr measurement, const SignalHelper::SignalData& data);
62  void setPreviewTime(double preview_time);
63  void removeSignal(const QString& key, int value_idx);
64  void initializeTask(int task_id, bool inherit_signals);
65  void rescaleAxes();
66  void replot() { _plot->replot(); }
67 
68  void removeSelectedSignals();
69  void removeAllSignals();
70 
71  protected:
72  void dragEnterEvent(QDragEnterEvent* event) override;
73  void dropEvent(QDropEvent* event) override;
74  void mousePressEvent(QMouseEvent* event) override;
75  void mouseMoveEvent(QMouseEvent* event) override;
76 
77  struct SignalData
78  {
80  {
81  // erase graph from plot
83  }
84  int value_idx = 0;
85  int task_id = -1;
86  bool zero_order_hold = false;
87  QColor graph_color = QColor("blue");
88  QString legend_text;
90  TimeSeriesSequence::ConstPtr ts_sequence; // only set if signal contains a TimeSeriesSequence
91  };
92  QHash<QString, SignalData>::iterator getActiveSignal(const QString& value_encoded_key);
93  QHash<QString, SignalData>::iterator getActiveSignal(const QString& key, int value_idx);
94  QVector<QHash<QString, SignalData>::iterator> findActiveSignal(const QString& key, SearchType search_type);
95  QString toValueEncodedKey(const QString& key, int value_idx) const;
96  bool fromValueEncodedKey(const QString& value_encoded_key, QString& key, int& value_idx);
97 
98  bool isGraphActive(const QCPGraph* graph) const;
99  void setGraphActive(QCPGraph* graph, bool active);
100 
101  void setupLegend();
102 
103  protected slots:
104  QCPAbstractPlottable* addTimeSeriesGraph(const TimeSeries& time_series, int value_idx, const QColor& color, const QString& legend_text,
105  bool zero_order_hold, bool replot);
106  void updateTimeSeriesGraph(SignalData& data, double t, double value, bool enlarge_axis, bool replot = true);
107  void updateTimeSeriesGraph(SignalData& data, const TimeSeries& time_series, bool enlarge_axis, bool replace_data, bool replot = true);
108  void updateTimeSeriesSequenceGraph(SignalData& data, bool replot = true);
109 
110  QCPAbstractPlottable* addBoxPlot(const IndexedValuesSetSignal& indexed_values_set, const QColor& color, const QString& legend_text,
111  bool replot = true);
112 
113  void scopeMousePress();
114  void scopeMouseWheel();
115  void scopeContextMenuRequest(const QPoint& point);
116 
117  private:
119 
120  QHash<QString, SignalData> _active_signals;
121 
123 
124  bool _legend_initialized = false;
125 
127 
131 
132  double _current_preview_time = 0.0;
133 
134  QVBoxLayout* _layout;
135 };
136 
137 } // namespace gui
138 } // namespace corbo
139 
140 #endif // SRC_GUI_INCLUDE_CORBO_GUI_SCOPE_WIDGET_H_
void setGraphActive(QCPGraph *graph, bool active)
QCustomPlot * parentPlot() const
Definition: qcustomplot.h:713
void updateTimeSeriesGraph(SignalData &data, double t, double value, bool enlarge_axis, bool replot=true)
QVector< QHash< QString, SignalData >::iterator > findActiveSignal(const QString &key, SearchType search_type)
Time Series (trajectory resp. sequence of values w.r.t. time)
Definition: time_series.h:54
ScopeWidget(SignalHelper::ConstPtr signal_helper, QWidget *parent=0)
QString toValueEncodedKey(const QString &key, int value_idx) const
void removeSignal(const QString &key, int value_idx)
void dropEvent(QDropEvent *event) override
bool isGraphActive(const QCPGraph *graph) const
std::shared_ptr< const TimeSeriesSequence > ConstPtr
Definition: time_series.h:264
void addMeasurement(const QString &key, Measurement::ConstPtr measurement, const SignalHelper::SignalData &data)
QCPAbstractPlottable * addTimeSeriesGraph(const TimeSeries &time_series, int value_idx, const QColor &color, const QString &legend_text, bool zero_order_hold, bool replot)
bool removePlottable(QCPAbstractPlottable *plottable)
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
QCPAbstractPlottable * plottable
Definition: scope_widget.h:89
void initializeTask(int task_id, bool inherit_signals)
TimeSeriesSequence::ConstPtr ts_sequence
Definition: scope_widget.h:90
Representation of time stamps.
Definition: time.h:251
std::shared_ptr< const SignalHelper > ConstPtr
Definition: signal_helper.h:46
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition: qcustomplot.h:3590
void mousePressEvent(QMouseEvent *event) override
QHash< QString, SignalData > _active_signals
Definition: scope_widget.h:120
std::shared_ptr< const Measurement > ConstPtr
Definition: signals.h:175
SignalHelper::ConstPtr _signal_helper
Definition: scope_widget.h:122
void mouseMoveEvent(QMouseEvent *event) override
bool fromValueEncodedKey(const QString &value_encoded_key, QString &key, int &value_idx)
double _current_preview_time
determine which TimeSeries of a TimeSeriesSequence should be plotted
Definition: scope_widget.h:132
bool hasSignal(const QString &key, int value_idx) const
ResizeDragStratPositions _drag_start_pos
Definition: scope_widget.h:128
QCPAbstractPlottable * addBoxPlot(const IndexedValuesSetSignal &indexed_values_set, const QColor &color, const QString &legend_text, bool replot=true)
void setPreviewTime(double preview_time)
void addSignal(const QString &signal_key, int value_idx)
QSize sizeHint() const override
A plottable representing a graph in a plot.
Definition: qcustomplot.h:5163
The abstract base class for all data representing objects in a plot.
Definition: qcustomplot.h:3295
void updateTimeSeriesSequenceGraph(SignalData &data, bool replot=true)
void dragEnterEvent(QDragEnterEvent *event) override
QHash< QString, SignalData >::iterator getActiveSignal(const QString &value_encoded_key)
Signal containing values indexed by an integer (int to double[] map)
Definition: signals.h:474
void scopeContextMenuRequest(const QPoint &point)


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:07:16