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
34 
38 #include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
43 #include <ArmarXCore/interface/components/TopicRecorderInterface.h>
44 // QT
45 #include <QWidget>
46 #include <QDialog>
47 #include <QDateTime>
48 
49 #include <vector>
50 #include <fstream>
51 #include <mutex>
52 
54 
55 //forward declarations
56 class QwtPlotCurve;
57 class QwtThermo;
58 class QStackedLayout;
59 class QwtPlotMarker;
60 
61 namespace armarx
62 {
63  class ArmarXPlotterDialog;
64  /*!
65  * \page ArmarXGui-GuiPlugins-PlotterPlugin Live Plotter
66  * \brief The plotter widget allows the user to plot any sensor channel.
67  * \image html PlotterGUI.png
68  * A sensor channel can be selected for plotting by clicking the wrench button at the bottom.
69  */
72  public ArmarXComponentWidgetControllerTemplate<ArmarXPlotter>,
73  public TopicReplayerListenerInterface
74 
75  {
76  Q_OBJECT
77  public:
78  void onStartReplay(const std::string& filename, const Ice::Current& c = Ice::emptyCurrent) override
79  {
80  if (!syncDataLogging)
81  {
82  return;
83  }
84 
85  if (!ui.btnLogToFile->isChecked())
86  {
87  this->filename = filename;
88  ui.btnLogToFile->setChecked(true);
89  }
90  else
91  {
92  ARMARX_WARNING << "already logging to file";
93  }
94  }
95 
96  void onStopReply(const Ice::Current& c = Ice::emptyCurrent) override
97  {
98  if (!syncDataLogging)
99  {
100  return;
101  }
102 
103  if (ui.btnLogToFile->isChecked())
104  {
105  ui.btnLogToFile->setChecked(false);
106  }
107  else
108  {
109  ARMARX_WARNING << "not logging to file.";
110  }
111  }
112 
113  Ui::ArmarXPlotter ui;
114  QPointer<ArmarXPlotterDialog> dialog;
115  QTimer* timer;
116  ConditionHandlerInterfacePrx handler;
117  // QStringList selectedChannels;
118  QString loggingDir;
119 
120  explicit ArmarXPlotter();
121  ~ArmarXPlotter() override;
122  //inherited from ArmarXWidget
123  static QString GetWidgetName()
124  {
125  return "Observers.LivePlotter";
126  }
127  static QIcon GetWidgetIcon()
128  {
129  return QIcon("://icons/combo_chart.svg");
130  }
131  void loadSettings(QSettings* settings) override;
132  void saveSettings(QSettings* settings) override;
133  //for AbstractFactoryMethod class
134 
135  // inherited from Component
136  void onInitComponent() override;
137  void onConnectComponent() override;
138  void onExitComponent() override;
139 
140  /**
141  * emits the closeRequest signal
142  */
143  void onCloseWidget(QCloseEvent* event);
144  QwtPlotCurve* createCurve(const QString& label);
145  QwtThermo* createBar(const QString& label);
146  signals:
147 
148  public slots:
149  void ButtonAddSensorChannelClicked();
150  void configDialog();
151  void configDone();
152  void toggleLogging(bool toggled);
153  void onGraphStyleChanged(const QString& style);
154  void logToFile(long timestamp, const std::map<std::string, VariantPtr>& dataMaptoAppend);
155 
156  protected:
157  std::shared_ptr<QSettings> settings;
158  private:
159 
160  QDateTime startUpTime;
161  std::map< std::string, ObserverInterfacePrx> proxyMap;
162  bool __plottingPaused;
163  JSONObjectPtr json;
164 
165  std::mutex dataMutex;
166  bool syncDataLogging;
167  std::vector<std::string> csvHeader;
168  std::ofstream logstream;
169  IceUtil::Time logStartTime;
170  std::string filename = "";
171 
172  std::mutex mutex;
173 
174  std::mutex fileMutex;
175 
176  PlotterController* plotterController;
177  };
178 }
armarx::PlotterController
Definition: PlotterController.h:75
JSONObject.h
armarx::ArmarXPlotter::timer
QTimer * timer
Definition: ArmarXPlotter.h:115
armarx::ArmarXPlotter::ui
Ui::ArmarXPlotter ui
Definition: ArmarXPlotter.h:113
armarx::ArmarXPlotter::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: ArmarXPlotter.h:127
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
DataFieldIdentifier.h
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
armarx::ArmarXPlotter::handler
ConditionHandlerInterfacePrx handler
Definition: ArmarXPlotter.h:116
ObserverItemModel.h
IceInternal::Handle< JSONObject >
ArmarXComponentWidgetController.h
armarx::ArmarXPlotter::loggingDir
QString loggingDir
Definition: ArmarXPlotter.h:118
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
filename
std::string filename
Definition: VisualizationRobot.cpp:83
PlotterController.h
armarx::ArmarXPlotter::onStartReplay
void onStartReplay(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXPlotter.h:78
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
Component.h
armarx::ArmarXPlotter::dialog
QPointer< ArmarXPlotterDialog > dialog
Definition: ArmarXPlotter.h:114
armarx::ArmarXPlotter::settings
std::shared_ptr< QSettings > settings
Definition: ArmarXPlotter.h:157
armarx::ArmarXPlotter::GetWidgetName
static QString GetWidgetName()
Definition: ArmarXPlotter.h:123
armarx::ArmarXPlotter
Definition: ArmarXPlotter.h:70
AbstractFactoryMethod.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ImportExportComponent.h
armarx::ArmarXPlotter::onStopReply
void onStopReply(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXPlotter.h:96