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
56 class QwtPlotCurve;
57 class QwtThermo;
58 class QStackedLayout;
59 class QwtPlotMarker;
60 
61 namespace armarx
62 {
63  class ArmarXPlotterDialog;
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:
157  void ButtonAddSensorChannelClicked();
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
armarx::PlotterController
Definition: PlotterController.h:75
JSONObject.h
armarx::ArmarXPlotter::timer
QTimer * timer
Definition: ArmarXPlotter.h:118
armarx::ArmarXPlotter::ui
Ui::ArmarXPlotter ui
Definition: ArmarXPlotter.h:116
armarx::ArmarXPlotter::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: ArmarXPlotter.h:134
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
DataFieldIdentifier.h
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
armarx::ArmarXPlotter::handler
ConditionHandlerInterfacePrx handler
Definition: ArmarXPlotter.h:119
ObserverItemModel.h
IceInternal::Handle< JSONObject >
ArmarXComponentWidgetController.h
armarx::ArmarXPlotter::loggingDir
QString loggingDir
Definition: ArmarXPlotter.h:121
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
filename
std::string filename
Definition: VisualizationRobot.cpp:86
PlotterController.h
armarx::ArmarXPlotter::onStartReplay
void onStartReplay(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXPlotter.h:79
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
Component.h
armarx::ArmarXPlotter::dialog
QPointer< ArmarXPlotterDialog > dialog
Definition: ArmarXPlotter.h:117
armarx::ArmarXPlotter::settings
std::shared_ptr< QSettings > settings
Definition: ArmarXPlotter.h:165
armarx::ArmarXPlotter::GetWidgetName
static QString GetWidgetName()
Definition: ArmarXPlotter.h:128
armarx::ArmarXPlotter
Definition: ArmarXPlotter.h:71
AbstractFactoryMethod.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ImportExportComponent.h
armarx::ArmarXPlotter::onStopReply
void onStopReply(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ArmarXPlotter.h:99