datastreamer_base.h
Go to the documentation of this file.
1 #ifndef DATA_STREAMER_TEMPLATE_H
2 #define DATA_STREAMER_TEMPLATE_H
3 
4 #include <mutex>
5 #include <unordered_set>
6 #include "PlotJuggler/plotdata.h"
8 
18 {
19  Q_OBJECT
20 public:
21 
24  {
25 
26  }
27 
28  virtual bool start(QStringList*) = 0;
29 
30  virtual void shutdown() = 0;
31 
32  virtual bool isRunning() const = 0;
33 
34  virtual ~DataStreamer() {}
35 
36  std::mutex& mutex()
37  {
38  return _mutex;
39  }
40 
41  void setMaximumRange(double range);
42 
43  virtual std::vector<QString> appendData(PlotDataMapRef& destination);
44 
46  {
47  return _data_map;
48  }
49 
50  const PlotDataMapRef& dataMap() const
51  {
52  return _data_map;
53  }
54 
55 signals:
56 
57  void clearBuffers();
58 
59  void dataUpdated();
60 
61  void connectionClosed();
62 
63 private:
64  std::mutex _mutex;
66  QAction* _start_streamer;
67 };
68 
69 QT_BEGIN_NAMESPACE
70 
71 #define DataStream_iid "com.icarustechnology.PlotJuggler.DataStreamer"
72 
73 
74 
75 Q_DECLARE_INTERFACE(DataStreamer, DataStream_iid)
76 
77 QT_END_NAMESPACE
78 
79 
80 inline
81 void DataStreamer::setMaximumRange(double range)
82 {
83  std::lock_guard<std::mutex> lock( mutex() );
84  for (auto& it : dataMap().numeric ) {
85  it.second.setMaximumRangeX( range );
86  }
87  for (auto& it: dataMap().user_defined) {
88  it.second.setMaximumRangeX( range );
89  }
90 }
91 
92 inline
93 std::vector<QString> DataStreamer::appendData(PlotDataMapRef &destination)
94 {
95  PlotDataMapRef &source = _data_map;
96 
97  std::vector<QString> added_curves;
98  for (auto& it: _data_map.numeric)
99  {
100  const std::string& name = it.first;
101  if( it.second.size()>0 && destination.numeric.count(name) == 0)
102  {
103  added_curves.push_back( QString::fromStdString( name ) );
104  }
105  }
106 
107  for (auto& it: source.numeric)
108  {
109  const std::string& name = it.first;
110  auto& source_plot = it.second;
111  auto plot_with_same_name = destination.numeric.find(name);
112 
113  // this is a new plot
114  if( plot_with_same_name == destination.numeric.end() )
115  {
116  plot_with_same_name = destination.numeric.emplace(
117  std::piecewise_construct,
118  std::forward_as_tuple(name),
119  std::forward_as_tuple(name)
120  ).first;
121  }
122  auto& destination_plot = plot_with_same_name->second;
123  for (size_t i=0; i< source_plot.size(); i++)
124  {
125  destination_plot.pushBack( source_plot.at(i) );
126  }
127  source_plot.clear();
128  }
129 
130  for (auto& it: source.user_defined)
131  {
132  const std::string& name = it.first;
133  auto& source_plot = it.second;
134  auto plot_with_same_name = destination.user_defined.find(name);
135 
136  // this is a new plot
137  if( plot_with_same_name == destination.user_defined.end() )
138  {
139  plot_with_same_name = destination.user_defined.emplace(
140  std::piecewise_construct,
141  std::forward_as_tuple(name),
142  std::forward_as_tuple(name)
143  ).first;
144  }
145  auto& destination_plot = plot_with_same_name->second;
146  for (size_t i=0; i< source_plot.size(); i++)
147  {
148  destination_plot.pushBack( source_plot.at(i) );
149  }
150  source_plot.clear();
151  }
152  return added_curves;
153 }
154 
155 #endif
156 
std::unordered_map< std::string, PlotData > numeric
Definition: plotdata.h:144
PlotDataMapRef & dataMap()
std::mutex & mutex()
void connectionClosed()
void clearBuffers()
virtual ~DataStreamer()
const PlotDataMapRef & dataMap() const
void dataUpdated()
virtual void shutdown()=0
std::unordered_map< std::string, PlotDataAny > user_defined
Definition: plotdata.h:145
PlotDataMapRef _data_map
virtual const char * name() const =0
virtual bool isRunning() const =0
std::mutex _mutex
void setMaximumRange(double range)
QAction * _start_streamer
virtual bool start(QStringList *)=0
int i
The DataStreamer base class to create your own plugin.
virtual std::vector< QString > appendData(PlotDataMapRef &destination)
#define DataStream_iid


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17