OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / scope / scopegadgetconfiguration.cpp
blob0dd99f35d676c9d2953192a6d929269e38335e1e
1 /**
2 ******************************************************************************
4 * @file scopegadgetconfiguration.cpp
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 #include "scopegadgetconfiguration.h"
30 ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings *qSettings, QObject *parent) :
31 IUAVGadgetConfiguration(classId, parent),
32 m_plotType((int)ChronoPlot),
33 m_dataSize(60),
34 m_refreshInterval(1000),
35 m_mathFunctionType(0)
37 uint currentStreamVersion = 0;
38 int plotCurveCount = 0;
41 // If a saved configuration exists load it
42 if (qSettings != 0) {
43 currentStreamVersion = qSettings->value("configurationStreamVersion").toUInt();
45 if (currentStreamVersion != m_configurationStreamVersion) {
46 return;
49 m_plotType = qSettings->value("plotType").toInt();
50 m_dataSize = qSettings->value("dataSize").toInt();
51 m_refreshInterval = qSettings->value("refreshInterval").toInt();
52 plotCurveCount = qSettings->value("plotCurveCount").toInt();
54 for (int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
55 qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
57 PlotCurveConfiguration *plotCurveConf = new PlotCurveConfiguration();
58 plotCurveConf->uavObject = qSettings->value("uavObject").toString();
59 plotCurveConf->uavField = qSettings->value("uavField").toString();
60 plotCurveConf->color = qSettings->value("color").value<QRgb>();
61 plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt();
62 plotCurveConf->mathFunction = qSettings->value("mathFunction").toString();
63 plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
64 plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
65 plotCurveConf->drawAntialiased = qSettings->value("drawAntialiased", true).toBool();
66 plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble();
67 plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble();
68 m_plotCurveConfigs.append(plotCurveConf);
70 qSettings->endGroup();
73 m_loggingEnabled = qSettings->value("LoggingEnabled").toBool();
74 m_loggingNewFileOnConnect = qSettings->value("LoggingNewFileOnConnect").toBool();
75 m_loggingPath = qSettings->value("LoggingPath").toString();
79 void ScopeGadgetConfiguration::clearPlotData()
81 PlotCurveConfiguration *plotCurveConfig;
83 while (m_plotCurveConfigs.size() > 0) {
84 plotCurveConfig = m_plotCurveConfigs.first();
85 m_plotCurveConfigs.pop_front();
86 delete plotCurveConfig;
90 /**
91 * Clones a configuration.
94 IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
96 int plotCurveCount = 0;
97 int plotDatasLoadIndex = 0;
99 ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
101 m->setPlotType(m_plotType);
102 m->setDataSize(m_dataSize);
103 m->setMathFunctionType(m_mathFunctionType);
104 m->setRefreashInterval(m_refreshInterval);
106 plotCurveCount = m_plotCurveConfigs.size();
108 for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
109 PlotCurveConfiguration *currentPlotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
111 PlotCurveConfiguration *newPlotCurveConf = new PlotCurveConfiguration();
112 newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject;
113 newPlotCurveConf->uavField = currentPlotCurveConf->uavField;
114 newPlotCurveConf->color = currentPlotCurveConf->color;
115 newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
116 newPlotCurveConf->yMeanSamples = currentPlotCurveConf->yMeanSamples;
117 newPlotCurveConf->mathFunction = currentPlotCurveConf->mathFunction;
118 newPlotCurveConf->drawAntialiased = currentPlotCurveConf->drawAntialiased;
119 newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
120 newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
122 m->addPlotCurveConfig(newPlotCurveConf);
125 m->setLoggingEnabled(m_loggingEnabled);
126 m->setLoggingNewFileOnConnect(m_loggingNewFileOnConnect);
127 m->setLoggingPath(m_loggingPath);
129 return m;
134 * Saves a configuration. //REDEFINES saveConfig CHILD BEHAVIOR?
137 void ScopeGadgetConfiguration::saveConfig(QSettings *qSettings) const
139 int plotCurveCount = m_plotCurveConfigs.size();
140 int plotDatasLoadIndex = 0;
142 qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion);
143 qSettings->setValue("plotType", m_plotType);
144 qSettings->setValue("dataSize", m_dataSize);
145 qSettings->setValue("refreshInterval", m_refreshInterval);
146 qSettings->setValue("plotCurveCount", plotCurveCount);
148 for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
149 qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
151 PlotCurveConfiguration *plotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
152 qSettings->setValue("uavObject", plotCurveConf->uavObject);
153 qSettings->setValue("uavField", plotCurveConf->uavField);
154 qSettings->setValue("color", plotCurveConf->color);
155 qSettings->setValue("mathFunction", plotCurveConf->mathFunction);
156 qSettings->setValue("yScalePower", plotCurveConf->yScalePower);
157 qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples);
158 qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
159 qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
160 qSettings->setValue("drawAntialiased", plotCurveConf->drawAntialiased);
162 qSettings->endGroup();
165 qSettings->setValue("LoggingEnabled", m_loggingEnabled);
166 qSettings->setValue("LoggingNewFileOnConnect", m_loggingNewFileOnConnect);
167 qSettings->setValue("LoggingPath", m_loggingPath);
170 void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration *> newPlotCurveConfigs)
172 clearPlotData();
174 m_plotCurveConfigs.append(newPlotCurveConfigs);
177 ScopeGadgetConfiguration::~ScopeGadgetConfiguration()
179 clearPlotData();