OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / scope / plotdata.h
blob07ae1afcecd4d6e894fd3783b0417a215ff2fcd1
1 /**
2 ******************************************************************************
4 * @file plotdata.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup ScopePlugin Scope Gadget Plugin
9 * @{
10 * @brief The scope Gadget, graphically plots the states of UAVObjects
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef PLOTDATA_H
29 #define PLOTDATA_H
31 #include "uavobject.h"
33 #include "qwt/src/qwt.h"
34 #include "qwt/src/qwt_plot.h"
35 #include "qwt/src/qwt_plot_curve.h"
36 #include "qwt/src/qwt_scale_draw.h"
37 #include "qwt/src/qwt_scale_widget.h"
38 #include <qwt/src/qwt_plot_marker.h>
40 #include <QTimer>
41 #include <QTime>
42 #include <QVector>
43 #include <uavdataobject.h>
45 /*!
46 \brief Defines the different type of plots.
48 enum PlotType { SequentialPlot, ChronoPlot };
50 /*!
51 \brief Base class that keeps the data for each curve in the plot.
53 class PlotData : public QObject {
54 Q_OBJECT
56 public:
57 PlotData(UAVObject *object, UAVObjectField *field, int element, int scaleOrderFactor, int meanSamples,
58 QString mathFunction, double plotDataSize, QPen pen, bool antialiased);
59 ~PlotData();
61 QString plotName() const
63 return m_plotName;
66 UAVObject *object() const
68 return m_object;
70 UAVObjectField *field() const
72 return m_field;
74 int element() const
76 return m_element;
78 QString elementName() const
80 return m_elementName;
83 bool isVisible() const;
84 void setVisible(bool visible);
86 bool wantsInitialData()
88 return m_isEnumPlot;
91 virtual bool append(UAVObject *obj) = 0;
92 virtual PlotType plotType() const = 0;
93 virtual void removeStaleData() = 0;
95 void updatePlotData();
96 void clear();
98 bool hasData() const;
99 QString lastDataAsString();
101 void attach(QwtPlot *plot);
103 public slots:
104 void visibilityChanged(QwtPlotItem *item);
106 protected:
107 // This is the power to which each value must be raised
108 int m_scalePower;
109 int m_meanSamples;
110 double m_meanSum;
111 QString m_mathFunction;
112 double m_correctionSum;
113 int m_correctionCount;
114 double m_plotDataSize;
116 QVector<double> m_xDataEntries;
117 QVector<double> m_yDataEntries;
118 QVector<double> m_yDataHistory;
120 UAVObject *m_object;
121 UAVObjectField *m_field;
122 int m_element;
123 QString m_elementName;
124 QwtPlotCurve *m_plotCurve;
125 QString m_plotName;
126 QList<QwtPlotMarker *> m_enumMarkerList;
127 bool m_isVisible;
128 QPen m_pen;
129 bool m_isEnumPlot;
130 virtual void calcMathFunction(double currentValue);
131 QwtPlotMarker *createMarker(QString value);
135 \brief The sequential plot have a fixed size buffer of data. All the curves in one plot
136 have the same size buffer.
138 class SequentialPlotData : public PlotData {
139 Q_OBJECT
140 public:
141 SequentialPlotData(UAVObject *object, UAVObjectField *field, int element,
142 int scaleFactor, int meanSamples, QString mathFunction,
143 double plotDataSize, QPen pen, bool antialiased)
144 : PlotData(object, field, element, scaleFactor, meanSamples,
145 mathFunction, plotDataSize, pen, antialiased) {}
146 ~SequentialPlotData() {}
148 bool append(UAVObject *obj);
149 PlotType plotType() const
151 return SequentialPlot;
153 void removeStaleData() {}
157 \brief The chrono plot have a variable sized buffer of data, where the data is for a specified time period.
159 class ChronoPlotData : public PlotData {
160 Q_OBJECT
161 public:
162 ChronoPlotData(UAVObject *object, UAVObjectField *field, int element,
163 int scaleFactor, int meanSamples, QString mathFunction,
164 double plotDataSize, QPen pen, bool antialiased)
165 : PlotData(object, field, element, scaleFactor, meanSamples,
166 mathFunction, plotDataSize, pen, antialiased)
168 ~ChronoPlotData() {}
170 bool append(UAVObject *obj);
171 PlotType plotType() const
173 return ChronoPlot;
175 void removeStaleData();
178 #endif // PLOTDATA_H