6 #include "../core/document.h"     7 #include "../core/struct.h"     8 #include "../core/timeseries.h"     9 #include "../core/topic.h"    10 #include "../core/workspace.h"    12 #include <condition_variable>    19 AUTO_STRUCT_BEGIN(PlotMargins);
    20 AUTO_STRUCT_FIELD(
double, left, 0.0, step_scale = 10, min = 0);
    21 AUTO_STRUCT_FIELD(
double, bottom, 0.0, step_scale = 10, min = 0);
    22 AUTO_STRUCT_FIELD(
double, right, 0.0, step_scale = 10, min = 0);
    23 AUTO_STRUCT_FIELD(
double, top, 0.0, step_scale = 10, min = 0);
    26 AUTO_STRUCT_BEGIN(PlotAxis);
    27 AUTO_STRUCT_FIELD(std::string, label);
    28 AUTO_STRUCT_EXTRA(PlotAxis(
const std::string &label) : label(label){});
    31 AUTO_STRUCT_BEGIN(PlotAxes);
    32 AUTO_STRUCT_FIELD(
double, lineWidth, 2, step_scale = 10, min = 0);
    33 AUTO_STRUCT_FIELD(
double, fontSize, 18, step_scale = 10, min = 0);
    34 AUTO_STRUCT_FIELD(PlotAxis, x, PlotAxis(
""));
    35 AUTO_STRUCT_FIELD(PlotAxis, y, PlotAxis(
""));
    38 AUTO_STRUCT_BEGIN(PlotTicksX);
    39 AUTO_STRUCT_FIELD(
double, stride, 100, step_scale = 10, min = 10);
    42 AUTO_STRUCT_BEGIN(PlotTicksY);
    43 AUTO_STRUCT_FIELD(
double, stride, 100, step_scale = 10, min = 10);
    44 AUTO_STRUCT_FIELD(
double, width, 60, step_scale = 10, min = 10);
    47 AUTO_STRUCT_BEGIN(PlotTicks);
    48 AUTO_STRUCT_FIELD(
double, length, 10, step_scale = 10, min = 0);
    49 AUTO_STRUCT_FIELD(
double, width, 1.5, step_scale = 10, min = 0);
    50 AUTO_STRUCT_FIELD(
double, fontSize, 18, step_scale = 10, min = 0);
    51 AUTO_STRUCT_FIELD(PlotTicksX, x);
    52 AUTO_STRUCT_FIELD(PlotTicksY, y);
    55 AUTO_STRUCT_BEGIN(PlotTitle);
    56 AUTO_STRUCT_FIELD(
bool, enable, 
false);
    57 AUTO_STRUCT_FIELD(std::string, text, 
"Title");
    58 AUTO_STRUCT_FIELD(
double, fontSize, 18, step_scale = 10, min = 0);
    61 AUTO_STRUCT_BEGIN(PlotGrid);
    62 AUTO_STRUCT_FIELD(
bool, enable, 
true);
    63 AUTO_STRUCT_FIELD(
double, width, 1.0);
    67 AUTO_STRUCT_BEGIN(PlotSpacing);
    68 AUTO_STRUCT_FIELD(
double, left, 5.0, step_scale = 10, min = 0);
    69 AUTO_STRUCT_FIELD(
double, bottom, 10.0, step_scale = 10, min = 0);
    70 AUTO_STRUCT_FIELD(
double, right, 5.0, step_scale = 10, min = 0);
    71 AUTO_STRUCT_FIELD(
double, top, 10.0, step_scale = 10, min = 0);
    74 AUTO_STRUCT_BEGIN(PlotStyle);
    75 AUTO_STRUCT_FIELD(PlotAxes, axes);
    76 AUTO_STRUCT_FIELD(PlotMargins, margins);
    77 AUTO_STRUCT_FIELD(PlotSpacing, spacing);
    78 AUTO_STRUCT_FIELD(PlotTicks, ticks);
    79 AUTO_STRUCT_FIELD(
double, frameWidth, 1.5, step_scale = 10, min = 0);
    80 AUTO_STRUCT_FIELD(
double, graphWidth, 2, step_scale = 10, min = 0);
    81 AUTO_STRUCT_FIELD(
double, padding, 5, step_scale = 10, min = 0);
    82 AUTO_STRUCT_FIELD(
Color3, backgroundColor, 
Color3(1, 1, 1));
    83 AUTO_STRUCT_FIELD(
Color3, foregroundColor, 
Color3(0.2, 0.2, 0.2));
    84 AUTO_STRUCT_FIELD(PlotTitle, title);
    85 AUTO_STRUCT_FIELD(PlotGrid, grid);
    88 AUTO_STRUCT_BEGIN(PlotQuery);
    91 AUTO_STRUCT_EXTRA(
bool empty() 
const { 
return query.empty(); });
    94 AUTO_STRUCT_BEGIN(PlotTopic);
    96 AUTO_STRUCT_FIELD(std::vector<PlotQuery>, queries);
    97 AUTO_STRUCT_EXTRA(
bool empty() 
const {
    98   return topic.topic().empty() &&
    99          (queries.size() == 0 ||
   100           (queries.size() == 1 && queries.front().empty()));
   102 AUTO_STRUCT_EXTRA(std::weak_ptr<TimeSeriesSubscriber> subscriber);
   109   PROPERTY(
double, duration, 10.0, min = 0.0);
   110   PROPERTY(std::vector<PlotTopic>, topics);
   111   PROPERTY(PlotStyle, style);
   112   template <
class T> 
static void filterArray(std::vector<T> &data) {
   113     for (
auto it = data.begin(); it + 1 < data.end();) {
   120     if (data.empty() || !data.back().empty()) {
   124   virtual void refresh()
 override {
   125     filterArray(topics());
   126     for (
auto &v : topics()) {
   127       filterArray(v.queries);
   128       for (
auto &q : v.queries) {
   129         q.query.subscriber(v.topic.subscriber());
   137   struct PlotRendererQuery {
   138     std::vector<std::pair<int64_t, double>> points;
   139     std::shared_ptr<TimeSeriesQuery> query;
   142   struct PlotRendererTopic {
   143     std::shared_ptr<TimeSeriesSubscriber> subscriber;
   144     std::vector<PlotRendererQuery> queries;
   147   struct PlotRendererData {
   148     std::shared_ptr<PlotDisplay> display;
   149     std::vector<PlotRendererTopic> topics;
   152   std::shared_ptr<PlotRendererData> _data =
   153       std::make_shared<PlotRendererData>();
   155   double _duration = 1.0;
   156   std::vector<PlotRendererTopic> _topics_async;
   157   std::shared_ptr<BagPlayer> _bag_player;
   160   std::shared_ptr<PlotDisplay> plotDisplay()
 const { 
return _data->display; }
   161   PlotRenderer(
const std::shared_ptr<PlotDisplay> &display);
   163   void renderAsync(QPainter *painter);