PlotterController.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <QBoxLayout>
27#include <QObject>
28#include <QPointer>
29#include <QStackedLayout>
30#include <QTextEdit>
31#include <QTimer>
32
33//ignore errors about extra ; from qwt
34#pragma GCC diagnostic push
35#pragma GCC diagnostic ignored "-Wpedantic"
36#include <qwt_legend.h>
37#include <qwt_plot.h>
38#include <qwt_plot_canvas.h>
39#include <qwt_plot_curve.h>
40#include <qwt_plot_magnifier.h>
41#include <qwt_plot_marker.h>
42#include <qwt_plot_panner.h>
43#include <qwt_scale_draw.h>
44#include <qwt_series_data.h>
45#include <qwt_thermo.h>
46#pragma GCC diagnostic pop
47
51#include <ArmarXCore/interface/observers/ObserverInterface.h>
57
58namespace armarx
59{
60 using QwtPlotMarkerPtr = QwtPlotMarker*;
61
62 struct TimeData
63 {
64 TimeData(const IceUtil::Time& time, const VariantPtr& data) : time(time), data(data)
65 {
66 }
67
68 IceUtil::Time time;
70 };
71
72 using ProxyMap = std::map<std::string, ObserverInterfacePrx>;
73 using GraphDataMap = std::map<std::string, std::vector<TimeData>>;
74
75 class PlotterController : public QObject
76 {
77 Q_OBJECT
78 public:
79 PlotterController(QObject* parent);
80 ~PlotterController() override;
81 QWidget* getPlotterWidget();
82
83 void pollingExec();
84
85
86 public slots:
87 void updateGraph();
88 void showCurve(QwtPlotItem* item, bool on);
89
90 void autoScale(bool toggled);
91
92 void plottingPaused(bool toggled);
93 void setupCurves(int samplingIntervalMs = -1);
94 void clearHistory();
95
96 /**
97 * Required for Qt5.
98 * This can't be deactivated via #if, because the moc ignores all preprocessor code.
99 * Hence there is a dummy implementation for Qt4
100 */
101 void legendChecked(const QVariant& itemInfo, bool on);
102
103 public:
104 std::map<std::string, VariantPtr> getData(const QStringList& channels);
105
106 protected:
107 QwtPlotCurve* createCurve(const QString& label);
108
109 QwtThermo* createBar(const QString& label);
110
111 public:
112 QStringList getSelectedDatafields() const;
113 std::vector<std::string> getSelectedDatafieldsKeys() const;
114 /**
115 * @brief Changes the datafields that are plotted
116 * @param value
117 * @param samplingIntervalMs
118 */
119 void setSelectedDatafields(const QStringList& value, int samplingIntervalMs = -1);
120
121 int getPollingInterval() const;
122 void setPollingInterval(int value);
123
124 int getUpdateInterval() const;
125 void setUpdateInterval(int value);
126
127 void setIceManager(const IceManagerPtr& value);
128
129 void clearBarList();
130 void clear();
131
132 int getShownInterval() const;
133 void setShownInterval(int value);
134
135 bool getAutoScale() const;
136 void setAutoScale(bool value);
137
138 std::string getGraphStyle() const;
139
140 std::vector<Qt::GlobalColor> getCurveColors() const;
141 void setCurveColors(const std::vector<Qt::GlobalColor>& value);
142
143 signals:
144 void newDataAvailable(long timestamp, const std::map<std::string, VariantPtr>& newData);
145 public slots:
146 void setGraphStyle(const std::string& style);
147
148 protected:
149 // Configuration Parameters
153 std::string graphStyle = "Curve (line, interpolate)";
154 bool autoScalePlot = true;
155 bool __plottingPaused = false;
156 QPointer<QWidget> widget;
157 QPointer<QwtPlot> plotter;
162 QTimer timer;
163 mutable std::recursive_mutex dataMutex;
166 std::map<std::string, QwtPlotCurve*> curves;
167 std::vector<Qt::GlobalColor> curveColors;
168 std::map<std::string, QwtThermo*> bars;
169 std::map<std::string, std::map<IceUtil::Time, std::map<std::string, QwtPlotMarkerPtr>>>
171
172 QStackedLayout* stackedLayout;
173 QHBoxLayout* barlayout;
174 };
175
176
177} // namespace armarx
std::string timestamp()
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::map< std::string, QwtThermo * > bars
std::map< std::string, VariantPtr > getData(const QStringList &channels)
void plottingPaused(bool toggled)
void newDataAvailable(long timestamp, const std::map< std::string, VariantPtr > &newData)
QwtPlotCurve * createCurve(const QString &label)
QStringList getSelectedDatafields() const
void setIceManager(const IceManagerPtr &value)
void setGraphStyle(const std::string &style)
QPointer< QwtPlot > plotter
std::recursive_mutex dataMutex
PeriodicTask< PlotterController >::pointer_type pollingTask
QwtThermo * createBar(const QString &label)
void legendChecked(const QVariant &itemInfo, bool on)
Required for Qt5.
std::map< std::string, std::map< IceUtil::Time, std::map< std::string, QwtPlotMarkerPtr > > > markers
void setSelectedDatafields(const QStringList &value, int samplingIntervalMs=-1)
Changes the datafields that are plotted.
void setupCurves(int samplingIntervalMs=-1)
std::map< std::string, QwtPlotCurve * > curves
std::string getGraphStyle() const
std::vector< std::string > getSelectedDatafieldsKeys() const
std::vector< Qt::GlobalColor > curveColors
void showCurve(QwtPlotItem *item, bool on)
std::vector< Qt::GlobalColor > getCurveColors() const
void setCurveColors(const std::vector< Qt::GlobalColor > &value)
This file offers overloads of toIce() and fromIce() functions for STL container types.
QwtPlotMarker * QwtPlotMarkerPtr
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
std::map< std::string, ObserverInterfacePrx > ProxyMap
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
Definition ArmarXFwd.h:39
std::map< std::string, std::vector< TimeData > > GraphDataMap
TimeData(const IceUtil::Time &time, const VariantPtr &data)