Gazebo Gui

API Reference

6.8.0
gz/gui/PlottingInterface.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_GUI_PLOTTINGINTERFACE_HH_
18 #define GZ_GUI_PLOTTINGINTERFACE_HH_
19 
20 #include <QObject>
21 #include <QString>
22 #include <QMap>
23 #include <QVariant>
24 #ifdef _MSC_VER
25 #pragma warning(push, 0)
26 #endif
27 #include <google/protobuf/message.h>
28 #include <google/protobuf/descriptor.h>
29 #ifdef _MSC_VER
30 #pragma warning(pop)
31 #endif
32 #include <map>
33 #include <set>
34 #include <string>
35 #include <memory>
36 #include <limits>
37 
38 #include "gz/gui/Export.hh"
39 
40 namespace ignition
41 {
42 namespace gui
43 {
44 class PlotDataPrivate;
45 
49 class IGNITION_GUI_VISIBLE PlotData
50 {
52  public: PlotData();
53 
55  public: ~PlotData();
56 
59  public: void SetValue(const double _value);
60 
63  public: double Value() const;
64 
67  public: void SetTime(const double _time);
68 
71  public: double Time() const;
72 
75  public: void AddChart(int _chart);
76 
78  public: void RemoveChart(int _chart);
79 
82  public: int ChartCount() const;
83 
86  public: std::set<int> &Charts();
87 
89  private: std::unique_ptr<PlotDataPrivate> dataPtr;
90 };
91 
92 class TopicPrivate;
93 
95 class IGNITION_GUI_VISIBLE Topic : public QObject
96 {
97  Q_OBJECT
98 
100  public: explicit Topic(const std::string &_name);
101 
103  public: ~Topic();
104 
107  public: std::string &Name() const;
108 
112  public: void Register(const std::string &_fieldPath, int _chart);
113 
117  public: void UnRegister(const std::string &_fieldPath, int _chart);
118 
121  public: int FieldCount() const;
122 
125  public: std::map<std::string, PlotData *> &Fields();
126 
129  public: void Callback(const google::protobuf::Message &_msg);
130 
134  public: bool HasHeader(const google::protobuf::Message &_msg,
135  double &_headerTime);
136 
139  public: void UpdateGui(const std::string &_field);
140 
146  signals: void plot(int _chart, QString _fieldID, double _x, double _y);
147 
150  public: void SetPlottingTimeRef(const std::shared_ptr<double> &_time);
151 
153  private: std::unique_ptr<TopicPrivate> dataPtr;
154 };
155 
156 class TransportPrivate;
157 
159 class IGNITION_GUI_VISIBLE Transport : public QObject
160 {
161  Q_OBJECT
162 
164  public: Transport();
165 
167  public: ~Transport();
168 
173  public: void Unsubscribe(const std::string &_topic,
174  const std::string &_fieldPath,
175  int _chart);
176 
182  public: void Subscribe(const std::string &_topic,
183  const std::string &_fieldPath,
184  int _chart, const std::shared_ptr<double> &_time);
185 
187  public slots: void UnsubscribeOutdatedTopics();
188 
191  public: const std::map<std::string, Topic*> &Topics();
192 
198  public slots: void onPlot(int _chart, QString _fieldID, double _x, double _y);
199 
205  signals: void plot(int _chart, QString _fieldID, double _x, double _y);
206 
208  private: std::unique_ptr<TransportPrivate> dataPtr;
209 };
210 
211 class PlottingIfacePrivate;
212 
217 class IGNITION_GUI_VISIBLE PlottingInterface : public QObject
218 {
219  Q_OBJECT
220 
222  public: explicit PlottingInterface();
223 
225  public: ~PlottingInterface();
226 
231  public slots: void subscribe(int _chart,
232  QString _fieldPath,
233  QString _topic);
234 
239  public slots: void unsubscribe(int _chart,
240  QString _fieldPath,
241  QString _topic);
242 
245  public: float Timeout() const;
246 
252  public slots: void onPlot(int _chart, QString _fieldID, double _x, double _y);
253 
259  signals: void plot(int _chart, QString _fieldID, double _x, double _y);
260 
267  public slots: void onComponentSubscribe(QString _entity,
268  QString _typeId,
269  QString _type,
270  QString _attribute,
271  int _chart);
272 
278  public slots: void onComponentUnSubscribe(QString _entity,
279  QString _typeId,
280  QString _attribute,
281  int _chart);
282 
289  signals: void ComponentSubscribe(uint64_t _entity,
290  uint64_t _typeId,
291  const std::string &_type,
292  const std::string &_attribute,
293  int _chart);
294 
300  signals: void ComponentUnSubscribe(uint64_t _entity,
301  uint64_t _typeId,
302  const std::string &_attribute,
303  int _chart);
304 
309  public slots: std::string FilePath(QString _path, std::string _name,
310  std::string _extention);
311 
317  public slots: bool exportCSV(QString _path, int _chart,
318  QMap< QString, QVariant> _serieses);
319 
323  signals: std::string ComponentName(uint64_t _typeId);
324 
326  public: void InitTimer();
327 
329  public slots: void UpdateTime();
330 
332  private: std::unique_ptr<PlottingIfacePrivate> dataPtr;
333 };
334 
335 }
336 }
337 
338 #endif
PlotData()
Constructor.
STL class.
STL class.
void UnsubscribeOutdatedTopics()
Unsubscribe from non-exist topics in the transport.
void subscribe(int _chart, QString _fieldPath, QString _topic)
subscribe to a field to plotted on a chart
void UpdateTime()
update the plotting tool time
void SetValue(const double _value)
Set the field Value.
std::string ComponentName(uint64_t _typeId)
Get Component Name based on its type Id.
double Value() const
Get the field value.
void InitTimer()
configration of the timer
Topic(const std::string &_name)
Constructor.
int FieldCount() const
size of registered fields
int ChartCount() const
Number of registered charts.
void plot(int _chart, QString _fieldID, double _x, double _y)
notify the Plotting Interface to plot
std::string & Name() const
Get topic name.
float Timeout() const
Get the timeout of updating the plot.
void onComponentSubscribe(QString _entity, QString _typeId, QString _type, QString _attribute, int _chart)
called by Qml to register a chart to a component attribute
void plot(int _chart, QString _fieldID, double _x, double _y)
plot a point to a chart
void Unsubscribe(const std::string &_topic, const std::string &_fieldPath, int _chart)
Unsubscribe/deattatch a field from a certain chart.
void SetPlottingTimeRef(const std::shared_ptr< double > &_time)
update the current time with the default time of the plotting timer
void Register(const std::string &_fieldPath, int _chart)
Register a chart to a field.
void RemoveChart(int _chart)
UnRegister a chart from plotting that field.
double Time() const
Get the arrival time.
~Topic()
Destructor.
std::string FilePath(QString _path, std::string _name, std::string _extention)
Create suitable file path with unique name and extention.
void ComponentSubscribe(uint64_t _entity, uint64_t _typeId, const std::string &_type, const std::string &_attribute, int _chart)
Notify the gazebo plugin to subscribe to a component data.
void unsubscribe(int _chart, QString _fieldPath, QString _topic)
unsubscribe from a field and deattach it from a chart
STL class.
const std::map< std::string, Topic * > & Topics()
Get the registered topics.
void Callback(const google::protobuf::Message &_msg)
Callback to receive messages.
void onComponentUnSubscribe(QString _entity, QString _typeId, QString _attribute, int _chart)
called by Qml to remove a chart from a component attribute
void ComponentUnSubscribe(uint64_t _entity, uint64_t _typeId, const std::string &_attribute, int _chart)
Notify the gazebo plugin to unsubscribe a component data.
void UpdateGui(const std::string &_field)
update the plot
Plotting Topic to handle published topics & their registered fields.
Definition: gz/gui/PlottingInterface.hh:95
bool exportCSV(QString _path, int _chart, QMap< QString, QVariant > _serieses)
export plot graphs to csv files
void UnRegister(const std::string &_fieldPath, int _chart)
Remove field from the plot.
Plot Data containter to hold value and registered charts Can be a Field or a PlotComponent Used by Pl...
Definition: gz/gui/PlottingInterface.hh:49
void AddChart(int _chart)
Register a chart that plot that field.
STL class.
bool HasHeader(const google::protobuf::Message &_msg, double &_headerTime)
Check if msg has header field and get its time.
std::map< std::string, PlotData * > & Fields()
Get the registered fields.
Handle transport topics subscribing for one object (Chart)
Definition: gz/gui/PlottingInterface.hh:159
void onPlot(int _chart, QString _fieldID, double _x, double _y)
slot to get triggered to plot a point and send its data to the UI
std::set< int > & Charts()
Get all registered charts to that field.
void Subscribe(const std::string &_topic, const std::string &_fieldPath, int _chart, const std::shared_ptr< double > &_time)
Subscribe/attatch a field from a certain chart.
void plot(int _chart, QString _fieldID, double _x, double _y)
update the GUI and plot the topic's fields values
Plotting Interface Responsible for plotting transport msgs-fields Used by TransportPlotting Plugin & ...
Definition: gz/gui/PlottingInterface.hh:217
void SetTime(const double _time)
Set the field arrival time.
void onPlot(int _chart, QString _fieldID, double _x, double _y)
Slot for receiving topics signal at each topic callback to plot.