2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup ScopePlugin Scope Gadget Plugin
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
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
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>
43 #include <uavdataobject.h>
46 \brief Defines the different type of plots.
48 enum PlotType
{ SequentialPlot
, ChronoPlot
};
51 \brief Base class that keeps the data for each curve in the plot.
53 class PlotData
: public QObject
{
57 PlotData(UAVObject
*object
, UAVObjectField
*field
, int element
, int scaleOrderFactor
, int meanSamples
,
58 QString mathFunction
, double plotDataSize
, QPen pen
, bool antialiased
);
61 QString
plotName() const
66 UAVObject
*object() const
70 UAVObjectField
*field() const
78 QString
elementName() const
83 bool isVisible() const;
84 void setVisible(bool visible
);
86 bool wantsInitialData()
91 virtual bool append(UAVObject
*obj
) = 0;
92 virtual PlotType
plotType() const = 0;
93 virtual void removeStaleData() = 0;
95 void updatePlotData();
99 QString
lastDataAsString();
101 void attach(QwtPlot
*plot
);
104 void visibilityChanged(QwtPlotItem
*item
);
107 // This is the power to which each value must be raised
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
;
121 UAVObjectField
*m_field
;
123 QString m_elementName
;
124 QwtPlotCurve
*m_plotCurve
;
126 QList
<QwtPlotMarker
*> m_enumMarkerList
;
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
{
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
{
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
)
170 bool append(UAVObject
*obj
);
171 PlotType
plotType() const
175 void removeStaleData();