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 
58 namespace armarx
59 {
60  using QwtPlotMarkerPtr = QwtPlotMarker*;
61 
62  struct TimeData
63  {
65  {
66  }
67 
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
150  int pollingInterval = 33;
151  int updateInterval = 33;
152  int shownInterval = 60;
153  std::string graphStyle = "Curve (line, interpolate)";
154  bool autoScalePlot = true;
155  bool __plottingPaused = false;
156  QPointer<QWidget> widget;
157  QPointer<QwtPlot> plotter;
158  QStringList selectedDatafields;
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
armarx::PlotterController::setPollingInterval
void setPollingInterval(int value)
Definition: PlotterController.cpp:866
armarx::PlotterController::setIceManager
void setIceManager(const IceManagerPtr &value)
Definition: PlotterController.cpp:886
armarx::PlotterController::selectedDatafields
QStringList selectedDatafields
Definition: PlotterController.h:158
armarx::PlotterController
Definition: PlotterController.h:75
armarx::PlotterController::updateGraph
void updateGraph()
Definition: PlotterController.cpp:126
armarx::PlotterController::bars
std::map< std::string, QwtThermo * > bars
Definition: PlotterController.h:168
armarx::PlotterController::proxyMap
ProxyMap proxyMap
Definition: PlotterController.h:165
armarx::PlotterController::widget
QPointer< QWidget > widget
Definition: PlotterController.h:156
armarx::PlotterController::dataMutex
std::recursive_mutex dataMutex
Definition: PlotterController.h:163
armarx::PlotterController::getPlotterWidget
QWidget * getPlotterWidget()
Definition: PlotterController.cpp:113
JSONObject.h
armarx::PlotterController::showCurve
void showCurve(QwtPlotItem *item, bool on)
Definition: PlotterController.cpp:292
armarx::PlotterController::setAutoScale
void setAutoScale(bool value)
Definition: PlotterController.cpp:944
InvalidChannelException.h
armarx::PlotterController::pollingInterval
int pollingInterval
Definition: PlotterController.h:150
armarx::PlotterController::curveColors
std::vector< Qt::GlobalColor > curveColors
Definition: PlotterController.h:167
armarx::PlotterController::timer
QTimer timer
Definition: PlotterController.h:162
PeriodicTask.h
armarx::TimeData::TimeData
TimeData(const IceUtil::Time &time, const VariantPtr &data)
Definition: PlotterController.h:64
armarx::PlotterController::newDataAvailable
void newDataAvailable(long timestamp, const std::map< std::string, VariantPtr > &newData)
armarx::PlotterController::updateInterval
int updateInterval
Definition: PlotterController.h:151
armarx::PlotterController::getPollingInterval
int getPollingInterval() const
Definition: PlotterController.cpp:861
armarx::PlotterController::createBar
QwtThermo * createBar(const QString &label)
Definition: PlotterController.cpp:756
DataFieldIdentifier.h
armarx::PlotterController::barlayout
QHBoxLayout * barlayout
Definition: PlotterController.h:173
armarx::PlotterController::json
JSONObjectPtr json
Definition: PlotterController.h:159
armarx::PlotterController::autoScale
void autoScale(bool toggled)
Definition: PlotterController.cpp:321
armarx::PlotterController::clearBarList
void clearBarList()
Definition: PlotterController.cpp:893
armarx::PlotterController::getAutoScale
bool getAutoScale() const
Definition: PlotterController.cpp:939
armarx::PlotterController::iceManager
IceManagerPtr iceManager
Definition: PlotterController.h:160
armarx::PlotterController::~PlotterController
~PlotterController() override
Definition: PlotterController.cpp:99
IceInternal::Handle< Variant >
armarx::PlotterController::getSelectedDatafields
QStringList getSelectedDatafields() const
Definition: PlotterController.cpp:785
armarx::PlotterController::dataMap
GraphDataMap dataMap
Definition: PlotterController.h:164
armarx::TimeData::time
IceUtil::Time time
Definition: PlotterController.h:68
armarx::PlotterController::__plottingPaused
bool __plottingPaused
Definition: PlotterController.h:155
armarx::QwtPlotMarkerPtr
QwtPlotMarker * QwtPlotMarkerPtr
Definition: PlotterController.h:60
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PlotterController::curves
std::map< std::string, QwtPlotCurve * > curves
Definition: PlotterController.h:166
armarx::PlotterController::setupCurves
void setupCurves(int samplingIntervalMs=-1)
Definition: PlotterController.cpp:579
armarx::PlotterController::setUpdateInterval
void setUpdateInterval(int value)
Definition: PlotterController.cpp:880
armarx::PlotterController::stackedLayout
QStackedLayout * stackedLayout
Definition: PlotterController.h:172
armarx::TimeData::data
VariantPtr data
Definition: PlotterController.h:69
armarx::PlotterController::legendChecked
void legendChecked(const QVariant &itemInfo, bool on)
Required for Qt5.
Definition: PlotterController.cpp:728
armarx::PlotterController::plottingPaused
void plottingPaused(bool toggled)
Definition: PlotterController.cpp:330
armarx::PlotterController::getGraphStyle
std::string getGraphStyle() const
Definition: PlotterController.cpp:949
armarx::PlotterController::clear
void clear()
Definition: PlotterController.cpp:909
armarx::PlotterController::clearHistory
void clearHistory()
Definition: PlotterController.cpp:920
armarx::PlotterController::graphStyle
std::string graphStyle
Definition: PlotterController.h:153
InvalidDataFieldException.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::PlotterController::pollingTask
PeriodicTask< PlotterController >::pointer_type pollingTask
Definition: PlotterController.h:161
armarx::GraphDataMap
std::map< std::string, std::vector< TimeData > > GraphDataMap
Definition: PlotterController.h:73
armarx::PlotterController::getShownInterval
int getShownInterval() const
Definition: PlotterController.cpp:926
armarx::PlotterController::createCurve
QwtPlotCurve * createCurve(const QString &label)
Definition: PlotterController.cpp:741
armarx::PlotterController::pollingExec
void pollingExec()
Definition: PlotterController.cpp:118
armarx::PlotterController::PlotterController
PlotterController(QObject *parent)
Definition: PlotterController.cpp:36
armarx::PlotterController::getData
std::map< std::string, VariantPtr > getData(const QStringList &channels)
Definition: PlotterController.cpp:351
armarx::PlotterController::shownInterval
int shownInterval
Definition: PlotterController.h:152
TimeUtil.h
armarx::PlotterController::setGraphStyle
void setGraphStyle(const std::string &style)
Definition: PlotterController.cpp:954
IceUtil::Handle< IceManager >
armarx::PlotterController::plotter
QPointer< QwtPlot > plotter
Definition: PlotterController.h:157
armarx::PlotterController::getUpdateInterval
int getUpdateInterval() const
Definition: PlotterController.cpp:875
armarx::PlotterController::autoScalePlot
bool autoScalePlot
Definition: PlotterController.h:154
armarx::PlotterController::markers
std::map< std::string, std::map< IceUtil::Time, std::map< std::string, QwtPlotMarkerPtr > > > markers
Definition: PlotterController.h:170
armarx::PlotterController::getCurveColors
std::vector< Qt::GlobalColor > getCurveColors() const
Definition: PlotterController.cpp:984
Logging.h
armarx::PlotterController::getSelectedDatafieldsKeys
std::vector< std::string > getSelectedDatafieldsKeys() const
Definition: PlotterController.cpp:793
armarx::PlotterController::setShownInterval
void setShownInterval(int value)
Definition: PlotterController.cpp:931
armarx::PlotterController::setCurveColors
void setCurveColors(const std::vector< Qt::GlobalColor > &value)
Definition: PlotterController.cpp:989
armarx::TimeData
Definition: PlotterController.h:62
Variant.h
armarx::PlotterController::setSelectedDatafields
void setSelectedDatafields(const QStringList &value, int samplingIntervalMs=-1)
Changes the datafields that are plotted.
Definition: PlotterController.cpp:848
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ProxyMap
std::map< std::string, ObserverInterfacePrx > ProxyMap
Definition: PlotterController.h:72