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  {
79  ~SignalData()
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_
corbo::gui::ScopeWidget::removeSelectedSignals
void removeSelectedSignals()
Definition: scope_widget.cpp:779
corbo::gui::ScopeWidget::_layout
QVBoxLayout * _layout
Definition: scope_widget.h:200
corbo::gui::ScopeWidget::scopeContextMenuRequest
void scopeContextMenuRequest(const QPoint &point)
Definition: scope_widget.cpp:718
corbo::gui::ScopeWidget::isGraphActive
bool isGraphActive(const QCPGraph *graph) const
Definition: scope_widget.cpp:801
corbo::gui::ScopeWidget::scopeMousePress
void scopeMousePress()
Definition: scope_widget.cpp:692
qcustomplot.h
signal_collection_widget.h
corbo::gui::ScopeWidget::ScopeWidget
ScopeWidget(SignalHelper::ConstPtr signal_helper, QWidget *parent=0)
Definition: scope_widget.cpp:82
corbo::gui::ScopeWidget::SignalData::~SignalData
~SignalData()
Definition: scope_widget.h:145
corbo::gui::ScopeWidget::getActiveSignal
QHash< QString, SignalData >::iterator getActiveSignal(const QString &value_encoded_key)
Definition: scope_widget.cpp:610
corbo::gui::ScopeWidget::SignalData::zero_order_hold
bool zero_order_hold
Definition: scope_widget.h:152
corbo::gui::ScopeWidget::SignalData::ts_sequence
TimeSeriesSequence::ConstPtr ts_sequence
Definition: scope_widget.h:156
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::gui::ScopeWidget::removeAllSignals
void removeAllSignals()
Definition: scope_widget.cpp:795
corbo::gui::ScopeWidget::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event) override
Definition: scope_widget.cpp:170
corbo::gui::ScopeWidget::removeSignal
void removeSignal(const QString &key, int value_idx)
Definition: scope_widget.cpp:547
QCustomPlot::replot
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
Definition: qcustomplot.cpp:14423
corbo::gui::ScopeWidget::SignalData::task_id
int task_id
Definition: scope_widget.h:151
corbo::gui::ScopeWidget::setGraphActive
void setGraphActive(QCPGraph *graph, bool active)
Definition: scope_widget.cpp:811
QCustomPlot::removePlottable
bool removePlottable(QCPAbstractPlottable *plottable)
Definition: qcustomplot.cpp:13540
corbo::gui::ScopeWidget::SignalData::plottable
QCPAbstractPlottable * plottable
Definition: scope_widget.h:155
QCPGraph
A plottable representing a graph in a plot.
Definition: qcustomplot.h:5163
corbo::gui::ScopeWidget::initializeTask
void initializeTask(int task_id, bool inherit_signals)
Definition: scope_widget.cpp:569
corbo::gui::ScopeWidget::ResizeDragStratPositions
ResizeDragStratPositions
Definition: scope_widget.h:117
corbo::gui::ScopeWidget::dropEvent
void dropEvent(QDropEvent *event) override
Definition: scope_widget.cpp:175
corbo::gui::ScopeWidget::_resize_drag_start_geometry
QRect _resize_drag_start_geometry
Definition: scope_widget.h:196
corbo::gui::ScopeWidget::_current_preview_time
double _current_preview_time
determine which TimeSeries of a TimeSeriesSequence should be plotted
Definition: scope_widget.h:198
corbo::gui::ScopeWidget::~ScopeWidget
virtual ~ScopeWidget()
Definition: scope_widget.cpp:126
corbo::gui::ScopeWidget::_plot
QCustomPlot * _plot
Definition: scope_widget.h:184
corbo::gui::ScopeWidget::SignalData::graph_color
QColor graph_color
Definition: scope_widget.h:153
corbo::gui::ScopeWidget::replot
void replot()
Definition: scope_widget.h:132
corbo::gui::ScopeWidget::_active_signals
QHash< QString, SignalData > _active_signals
Definition: scope_widget.h:186
corbo::IndexedValuesSetSignal
Signal containing values indexed by an integer (int to double[] map)
Definition: signals.h:496
corbo::gui::ScopeWidget::inactive
@ inactive
Definition: scope_widget.h:117
corbo::gui::ScopeWidget::setPreviewTime
void setPreviewTime(double preview_time)
Definition: scope_widget.cpp:449
QCPAbstractPlottable
The abstract base class for all data representing objects in a plot.
Definition: qcustomplot.h:3295
corbo::TimeSeriesSequence::ConstPtr
std::shared_ptr< const TimeSeriesSequence > ConstPtr
Definition: time_series.h:286
corbo::gui::ScopeWidget::_signal_helper
SignalHelper::ConstPtr _signal_helper
Definition: scope_widget.h:188
corbo::gui::ScopeWidget::rescaleAxes
void rescaleAxes()
Definition: scope_widget.cpp:595
corbo::TimeSeries
Time Series (trajectory resp. sequence of values w.r.t. time)
Definition: time_series.h:76
QCustomPlot
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition: qcustomplot.h:3590
corbo::gui::ScopeWidget::addBoxPlot
QCPAbstractPlottable * addBoxPlot(const IndexedValuesSetSignal &indexed_values_set, const QColor &color, const QString &legend_text, bool replot=true)
Definition: scope_widget.cpp:502
corbo::gui::ScopeWidget::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Definition: scope_widget.cpp:187
corbo::gui::SearchType
SearchType
Definition: gui/include/corbo-gui/utilities.h:89
corbo::gui::ScopeWidget::SignalData::legend_text
QString legend_text
Definition: scope_widget.h:154
corbo::gui::ScopeWidget::findActiveSignal
QVector< QHash< QString, SignalData >::iterator > findActiveSignal(const QString &key, SearchType search_type)
Definition: scope_widget.cpp:623
corbo::gui::ScopeWidget::addMeasurement
void addMeasurement(const QString &key, Measurement::ConstPtr measurement, const SignalHelper::SignalData &data)
Definition: scope_widget.cpp:406
corbo::gui::ScopeWidget::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event) override
Definition: scope_widget.cpp:196
corbo::gui::ScopeWidget::_drag_start_pos
ResizeDragStratPositions _drag_start_pos
Definition: scope_widget.h:194
corbo::gui::ScopeWidget::setupLegend
void setupLegend()
Definition: scope_widget.cpp:130
corbo::Time
Representation of time stamps.
Definition: time.h:273
corbo::gui::ScopeWidget::_resize_drag_start_position
QPoint _resize_drag_start_position
Definition: scope_widget.h:195
corbo::gui::ScopeWidget::hasSignal
bool hasSignal(const QString &key, int value_idx) const
Definition: scope_widget.cpp:602
corbo::gui::ScopeWidget::scopeMouseWheel
void scopeMouseWheel()
Definition: scope_widget.cpp:705
corbo::gui::ScopeWidget::updateTimeSeriesGraph
void updateTimeSeriesGraph(SignalData &data, double t, double value, bool enlarge_axis, bool replot=true)
Definition: scope_widget.cpp:347
corbo::gui::ScopeWidget::SignalData::value_idx
int value_idx
Definition: scope_widget.h:150
corbo::gui::ScopeWidget::addSignal
void addSignal(const QString &signal_key, int value_idx)
Definition: scope_widget.cpp:244
corbo::gui::ScopeWidget::_last_signal_header_time
Time _last_signal_header_time
Definition: scope_widget.h:192
corbo::gui::ScopeWidget::sizeHint
QSize sizeHint() const override
Definition: scope_widget.cpp:128
QCPLayerable::parentPlot
QCustomPlot * parentPlot() const
Definition: qcustomplot.h:713
corbo::gui::ScopeWidget::bottom
@ bottom
Definition: scope_widget.h:117
corbo::gui::ScopeWidget::toValueEncodedKey
QString toValueEncodedKey(const QString &key, int value_idx) const
Definition: scope_widget.cpp:659
corbo::gui::ScopeWidget::updateTimeSeriesSequenceGraph
void updateTimeSeriesSequenceGraph(SignalData &data, bool replot=true)
Definition: scope_widget.cpp:460
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::ScopeWidget::_legend_initialized
bool _legend_initialized
Definition: scope_widget.h:190
corbo::gui::ScopeWidget::fromValueEncodedKey
bool fromValueEncodedKey(const QString &value_encoded_key, QString &key, int &value_idx)
Definition: scope_widget.cpp:664
corbo::gui::ScopeWidget::addTimeSeriesGraph
QCPAbstractPlottable * addTimeSeriesGraph(const TimeSeries &time_series, int value_idx, const QColor &color, const QString &legend_text, bool zero_order_hold, bool replot)
Definition: scope_widget.cpp:305
utilities.h
corbo::gui::ScopeWidget::top
@ top
Definition: scope_widget.h:117


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