ArmarXPlotter.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::Gui
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25//ignore errors about extra ; from qwt
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wpedantic"
28#include <ArmarXGui/gui-plugins/PlotterPlugin/ui_ArmarXPlotter.h>
29#pragma GCC diagnostic pop
30
31// ArmarX
36#include <ArmarXCore/interface/components/TopicRecorderInterface.h>
37#include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
41
44// QT
45#include <fstream>
46#include <mutex>
47#include <vector>
48
49#include <QDateTime>
50#include <QDialog>
51#include <QWidget>
52
54
55//forward declarations
56class QwtPlotCurve;
57class QwtThermo;
58class QStackedLayout;
59class QwtPlotMarker;
60
61namespace armarx
62{
64
65 /*!
66 * \page ArmarXGui-GuiPlugins-PlotterPlugin Live Plotter
67 * \brief The plotter widget allows the user to plot any sensor channel.
68 * \image html PlotterGUI.png
69 * A sensor channel can be selected for plotting by clicking the wrench button at the bottom.
70 */
72 public ArmarXComponentWidgetControllerTemplate<ArmarXPlotter>,
73 public TopicReplayerListenerInterface
74
75 {
76 Q_OBJECT
77 public:
78 void
79 onStartReplay(const std::string& filename,
80 const Ice::Current& c = Ice::emptyCurrent) override
81 {
82 if (!syncDataLogging)
83 {
84 return;
85 }
86
87 if (!ui.btnLogToFile->isChecked())
88 {
89 this->filename = filename;
90 ui.btnLogToFile->setChecked(true);
91 }
92 else
93 {
94 ARMARX_WARNING << "already logging to file";
95 }
96 }
97
98 void
99 onStopReply(const Ice::Current& c = Ice::emptyCurrent) override
100 {
101 if (!syncDataLogging)
102 {
103 return;
104 }
105
106 if (ui.btnLogToFile->isChecked())
107 {
108 ui.btnLogToFile->setChecked(false);
109 }
110 else
111 {
112 ARMARX_WARNING << "not logging to file.";
113 }
114 }
115
116 Ui::ArmarXPlotter ui;
117 QPointer<ArmarXPlotterDialog> dialog;
118 QTimer* timer;
119 ConditionHandlerInterfacePrx handler;
120 // QStringList selectedChannels;
121 QString loggingDir;
122
123 explicit ArmarXPlotter();
124 ~ArmarXPlotter() override;
125
126 //inherited from ArmarXWidget
127 static QString
129 {
130 return "Observers.LivePlotter";
131 }
132
133 static QIcon
135 {
136 return QIcon("://icons/combo_chart.svg");
137 }
138
139 void loadSettings(QSettings* settings) override;
140 void saveSettings(QSettings* settings) override;
141 //for AbstractFactoryMethod class
142
143 // inherited from Component
144 void onInitComponent() override;
145 void onConnectComponent() override;
146 void onExitComponent() override;
147
148 /**
149 * emits the closeRequest signal
150 */
151 void onCloseWidget(QCloseEvent* event);
152 QwtPlotCurve* createCurve(const QString& label);
153 QwtThermo* createBar(const QString& label);
154 signals:
155
156 public slots:
158 void configDialog();
159 void configDone();
160 void toggleLogging(bool toggled);
161 void onGraphStyleChanged(const QString& style);
162 void logToFile(long timestamp, const std::map<std::string, VariantPtr>& dataMaptoAppend);
163
164 protected:
165 std::shared_ptr<QSettings> settings;
166
167 private:
168 QDateTime startUpTime;
169 std::map<std::string, ObserverInterfacePrx> proxyMap;
170 bool __plottingPaused;
171 JSONObjectPtr json;
172
173 std::mutex dataMutex;
174 bool syncDataLogging;
175 std::vector<std::string> csvHeader;
176 std::ofstream logstream;
177 IceUtil::Time logStartTime;
178 std::string filename = "";
179
180 std::mutex mutex;
181
182 std::mutex fileMutex;
183
184 PlotterController* plotterController;
185 };
186} // namespace armarx
std::string timestamp()
#define ARMARXCOMPONENT_IMPORT_EXPORT
constexpr T c
ConditionHandlerInterfacePrx handler
void toggleLogging(bool toggled)
void onStopReply(const Ice::Current &c=Ice::emptyCurrent) override
QwtPlotCurve * createCurve(const QString &label)
std::shared_ptr< QSettings > settings
QwtThermo * createBar(const QString &label)
void onGraphStyleChanged(const QString &style)
Ui::ArmarXPlotter ui
void logToFile(long timestamp, const std::map< std::string, VariantPtr > &dataMaptoAppend)
QPointer< ArmarXPlotterDialog > dialog
void onStartReplay(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
static QString GetWidgetName()
static QIcon GetWidgetIcon()
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34