1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merge remote-tracking branch 'origin/pt/gcs_uavobj_widget_framework' into next

This commit is contained in:
James Cotton 2012-02-14 14:24:23 -06:00
commit 7c65bcc5ac
60 changed files with 25120 additions and 2149 deletions

View File

@ -10,5 +10,6 @@
<dependency name="UAVTalk" version="1.0.0"/>
<dependency name="UAVObjectUtil" version="1.0.0"/>
<dependency name="UAVSettingsImportExport" version="1.0.0"/>
<dependency name="UAVObjectWidgetUtils" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,7 @@
#include(config_dependencies.pri)
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
include(../../plugins/uavtalk/uavtalk.pri)
# Add the include path to the built-in uavobject include files.
INCLUDEPATH += $$PWD
LIBS *= -l$$qtLibraryName(Config)

View File

@ -1,13 +1,8 @@
TEMPLATE = lib
TARGET = Config
DEFINES += CONFIG_LIBRARY
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../libs/utils/utils.pri)
include(../../plugins/uavtalk/uavtalk.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/uavobjectutil/uavobjectutil.pri)
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
include(config_dependencies.pri)
INCLUDEPATH += ../../libs/eigen
OTHER_FILES += Config.pluginspec
HEADERS += configplugin.h \
@ -19,25 +14,21 @@ HEADERS += configplugin.h \
fancytabwidget.h \
configinputwidget.h \
configoutputwidget.h \
configtaskwidget.h \
configairframewidget.h \
config_pro_hw_widget.h \
config_cc_hw_widget.h \
configahrswidget.h \
configccattitudewidget.h \
mixercurvewidget.h \
mixercurvepoint.h \
mixercurveline.h \
configccpmwidget.h \
configstabilizationwidget.h \
assertions.h \
calibration.h \
defaultattitudewidget.h \
smartsavebutton.h \
defaulthwsettingswidget.h \
inputchannelform.h \
configcamerastabilizationwidget.h \
outputchannelform.h
outputchannelform.h \
config_global.h
SOURCES += configplugin.cpp \
configgadgetconfiguration.cpp \
configgadgetwidget.cpp \
@ -45,7 +36,6 @@ SOURCES += configplugin.cpp \
configgadgetoptionspage.cpp \
configgadget.cpp \
fancytabwidget.cpp \
configtaskwidget.cpp \
configinputwidget.cpp \
configoutputwidget.cpp \
configairframewidget.cpp \
@ -53,9 +43,6 @@ SOURCES += configplugin.cpp \
config_cc_hw_widget.cpp \
configahrswidget.cpp \
configccattitudewidget.cpp \
mixercurvewidget.cpp \
mixercurvepoint.cpp \
mixercurveline.cpp \
configccpmwidget.cpp \
configstabilizationwidget.cpp \
twostep.cpp \
@ -63,7 +50,6 @@ SOURCES += configplugin.cpp \
gyro-calibration.cpp \
alignment-calibration.cpp \
defaultattitudewidget.cpp \
smartsavebutton.cpp \
defaulthwsettingswidget.cpp \
inputchannelform.cpp \
configcamerastabilizationwidget.cpp \

View File

@ -43,7 +43,7 @@ ConfigCCHWWidget::ConfigCCHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
m_telemetry->label_2->setPixmap(QPixmap(":/configgadget/images/coptercontrol.svg"));
setupButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD);
addApplySaveButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD);
addUAVObjectToWidgetRelation("HwSettings","CC_FlexiPort",m_telemetry->cbFlexi);
addUAVObjectToWidgetRelation("HwSettings","CC_MainPort",m_telemetry->cbTele);
addUAVObjectToWidgetRelation("HwSettings","CC_RcvrPort",m_telemetry->cbRcvr);

View File

@ -28,7 +28,7 @@
#define CONFIGCCHWWIDGET_H
#include "ui_cc_hw_settings.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -0,0 +1,8 @@
include(../../openpilotgcsplugin.pri)
include(../../libs/utils/utils.pri)
include(../../plugins/uavtalk/uavtalk.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/uavobjectutil/uavobjectutil.pri)
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
include(../../plugins/uavobjectwidgetutils/uavobjectwidgetutils.pri)

View File

@ -0,0 +1,41 @@
/**
******************************************************************************
*
* @file config_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup Congig Plugin
* @{
* @brief The Congig GCS plugin
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONFIG_GLOBAL_H
#define CONFIG_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(CONFIG_LIBRARY)
# define CONFIG_EXPORT Q_DECL_EXPORT
#else
# define CONFIG_EXPORT Q_DECL_IMPORT
#endif
#endif // CONFIG_GLOBAL_H

View File

@ -39,7 +39,7 @@ ConfigProHWWidget::ConfigProHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
m_telemetry = new Ui_PRO_HW_Widget();
m_telemetry->setupUi(this);
setupButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD);
addApplySaveButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD);
addUAVObjectToWidgetRelation("HwSettings","TelemetrySpeed",m_telemetry->telemetrySpeed);
enableControls(false);
populateWidgets();

View File

@ -28,7 +28,7 @@
#define CONFIGPROHWWIDGET_H
#include "ui_pro_hw_settings.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -30,7 +30,7 @@
#include <Eigen/StdVector>
#include "ui_ahrs.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -95,7 +95,7 @@ ConfigAirframeWidget::ConfigAirframeWidget(QWidget *parent) : ConfigTaskWidget(p
m_aircraft = new Ui_AircraftWidget();
m_aircraft->setupUi(this);
setupButtons(m_aircraft->saveAircraftToRAM,m_aircraft->saveAircraftToSD);
addApplySaveButtons(m_aircraft->saveAircraftToRAM,m_aircraft->saveAircraftToSD);
addUAVObject("SystemSettings");
addUAVObject("MixerSettings");
@ -2179,7 +2179,6 @@ void ConfigAirframeWidget::addToDirtyMonitor()
addWidget(m_aircraft->elevonSlider1);
addWidget(m_aircraft->elevonSlider2);
addWidget(m_aircraft->widget_3->m_ccpm->ccpmType);
addWidget(m_aircraft->widget_3->m_ccpm->TabObject);
addWidget(m_aircraft->widget_3->m_ccpm->ccpmTailChannel);
addWidget(m_aircraft->widget_3->m_ccpm->ccpmEngineChannel);
addWidget(m_aircraft->widget_3->m_ccpm->ccpmServoWChannel);

View File

@ -28,7 +28,7 @@
#define CONFIGAIRFRAMEWIDGET_H
#include "ui_airframe.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -28,7 +28,7 @@
#define CONFIGCAMERASTABILIZATIONWIDGET_H
#include "ui_camerastabilization.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -42,7 +42,7 @@ ConfigCCAttitudeWidget::ConfigCCAttitudeWidget(QWidget *parent) :
connect(ui->zeroBias,SIGNAL(clicked()),this,SLOT(startAccelCalibration()));
setupButtons(ui->applyButton,ui->saveButton);
addApplySaveButtons(ui->applyButton,ui->saveButton);
addUAVObject("AttitudeSettings");
// Connect the help button

View File

@ -28,7 +28,7 @@
#define CCATTITUDEWIDGET_H
#include "ui_ccattitude.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -28,7 +28,7 @@
#define CONFIGccpmWIDGET_H
#include "ui_ccpm.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -28,7 +28,7 @@
#define CONFIGGADGET_H
#include <coreplugin/iuavgadget.h>
#include "configgadgetwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
class IUAVGadget;
//class QList<int>;
@ -46,7 +46,7 @@ public:
ConfigGadget(QString classId, ConfigGadgetWidget *widget, QWidget *parent = 0);
~ConfigGadget();
QWidget *widget() { return m_widget; }
QWidget *widget() { return (QWidget*)m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:

View File

@ -40,7 +40,7 @@
#include <QMessageBox>
//#include "fancytabwidget.h"
#include "utils/mytabbedstackwidget.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
class ConfigGadgetWidget: public QWidget
{

View File

@ -54,10 +54,10 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent)
m_config = new Ui_InputWidget();
m_config->setupUi(this);
setupButtons(m_config->saveRCInputToRAM,m_config->saveRCInputToSD);
addApplySaveButtons(m_config->saveRCInputToRAM,m_config->saveRCInputToSD);
unsigned int index=0;
foreach(QString name,manualSettingsObj->getFields().at(0)->getElementNames())
foreach(QString name,manualSettingsObj->getField("ChannelNumber")->getElementNames())
{
Q_ASSERT(index < ManualControlSettings::CHANNELGROUPS_NUMELEM);
inputChannelForm * inp=new inputChannelForm(this,index==0);
@ -1097,7 +1097,7 @@ void ConfigInputWidget::invertControls()
QCheckBox * cb=qobject_cast<QCheckBox *>(wd);
if(cb)
{
int index=manualSettingsObj->getFields().at(0)->getElementNames().indexOf(cb->text());
int index=manualSettingsObj->getField("ChannelNumber")->getElementNames().indexOf(cb->text());
if((cb->isChecked() && (manualSettingsData.ChannelMax[index]>manualSettingsData.ChannelMin[index])) ||
(!cb->isChecked() && (manualSettingsData.ChannelMax[index]<manualSettingsData.ChannelMin[index])))
{

View File

@ -28,7 +28,7 @@
#define CONFIGINPUTWIDGET_H
#include "ui_input.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -50,13 +50,13 @@ ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(paren
m_config->setupUi(this);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
setupButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD);
addApplySaveButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD);
addUAVObject("ActuatorSettings");
UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(stopTests()));
setupButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD);
addApplySaveButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD);
addUAVObject("ActuatorSettings");
// NOTE: we have channel indices from 0 to 9, but the convention for OP is Channel 1 to Channel 10.

View File

@ -28,7 +28,7 @@
#define CONFIGOUTPUTWIDGET_H
#include "ui_output.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -34,298 +34,110 @@
#include <QtGui/QPushButton>
#include <QDesktopServices>
#include <QUrl>
#include <QList>
ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent)
{
stabSettings = StabilizationSettings::GetInstance(getObjectManager());
m_stabilization = new Ui_StabilizationWidget();
m_stabilization->setupUi(this);
autoLoadWidgets();
realtimeUpdates=new QTimer(this);
connect(m_stabilization->realTimeUpdates_6,SIGNAL(stateChanged(int)),this,SLOT(realtimeUpdatesSlot(int)));
connect(m_stabilization->realTimeUpdates_7,SIGNAL(stateChanged(int)),this,SLOT(realtimeUpdatesSlot(int)));
connect(realtimeUpdates,SIGNAL(timeout()),this,SLOT(apply()));
setupButtons(m_stabilization->saveStabilizationToRAM, m_stabilization->saveStabilizationToSD);
connect(m_stabilization->checkBox_7,SIGNAL(stateChanged(int)),this,SLOT(linkCheckBoxes(int)));
connect(m_stabilization->checkBox_2,SIGNAL(stateChanged(int)),this,SLOT(linkCheckBoxes(int)));
connect(m_stabilization->checkBox_8,SIGNAL(stateChanged(int)),this,SLOT(linkCheckBoxes(int)));
connect(m_stabilization->checkBox_3,SIGNAL(stateChanged(int)),this,SLOT(linkCheckBoxes(int)));
addUAVObject("StabilizationSettings");
refreshWidgetsValues();
// Create a timer to regularly send the object update in case
// we want realtime updates.
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateObjectsFromWidgets()));
connect(m_stabilization->realTimeUpdates, SIGNAL(toggled(bool)), this, SLOT(realtimeUpdateToggle(bool)));
// Connect the updates of the stab values
connect(m_stabilization->rateRollKp, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollKP(double)));
connect(m_stabilization->rateRollKi, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollKI(double)));
connect(m_stabilization->rateRollILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollILimit(double)));
connect(m_stabilization->ratePitchKp, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchKP(double)));
connect(m_stabilization->ratePitchKi, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchKI(double)));
connect(m_stabilization->ratePitchILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchILimit(double)));
connect(m_stabilization->rollKp, SIGNAL(valueChanged(double)), this, SLOT(updateRollKP(double)));
connect(m_stabilization->rollKi, SIGNAL(valueChanged(double)), this, SLOT(updateRollKI(double)));
connect(m_stabilization->rollILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRollILimit(double)));
connect(m_stabilization->pitchKp, SIGNAL(valueChanged(double)), this, SLOT(updatePitchKP(double)));
connect(m_stabilization->pitchKi, SIGNAL(valueChanged(double)), this, SLOT(updatePitchKI(double)));
connect(m_stabilization->pitchILimit, SIGNAL(valueChanged(double)), this, SLOT(updatePitchILimit(double)));
addWidget(m_stabilization->rateRollKp);
addWidget(m_stabilization->rateRollKi);
addWidget(m_stabilization->rateRollILimit);
addWidget(m_stabilization->ratePitchKp);
addWidget(m_stabilization->ratePitchKi);
addWidget(m_stabilization->ratePitchILimit);
addWidget(m_stabilization->rateYawKp);
addWidget(m_stabilization->rateYawKi);
addWidget(m_stabilization->rateYawILimit);
addWidget(m_stabilization->rollKp);
addWidget(m_stabilization->rollKi);
addWidget(m_stabilization->rollILimit);
addWidget(m_stabilization->yawILimit);
addWidget(m_stabilization->yawKi);
addWidget(m_stabilization->yawKp);
addWidget(m_stabilization->pitchKp);
addWidget(m_stabilization->pitchKi);
addWidget(m_stabilization->pitchILimit);
addWidget(m_stabilization->rollMax);
addWidget(m_stabilization->pitchMax);
addWidget(m_stabilization->yawMax);
addWidget(m_stabilization->manualRoll);
addWidget(m_stabilization->manualPitch);
addWidget(m_stabilization->manualYaw);
addWidget(m_stabilization->maximumRoll);
addWidget(m_stabilization->maximumPitch);
addWidget(m_stabilization->maximumYaw);
addWidget(m_stabilization->lowThrottleZeroIntegral);
// Connect buttons
connect(m_stabilization->stabilizationResetToDefaults, SIGNAL(clicked()), this, SLOT(resetToDefaults()));
connect(m_stabilization->stabilizationHelp, SIGNAL(clicked()), this, SLOT(openHelp()));
connect(this,SIGNAL(widgetContentsChanged(QWidget*)),this,SLOT(processLinkedWidgets(QWidget*)));
}
ConfigStabilizationWidget::~ConfigStabilizationWidget()
{
// Do nothing
// Do nothing
}
void ConfigStabilizationWidget::updateRateRollKP(double val)
void ConfigStabilizationWidget::realtimeUpdatesSlot(int value)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->ratePitchKp->setValue(val);
m_stabilization->realTimeUpdates_6->setCheckState((Qt::CheckState)value);
m_stabilization->realTimeUpdates_7->setCheckState((Qt::CheckState)value);
if(value==Qt::Checked && !realtimeUpdates->isActive())
realtimeUpdates->start(300);
else if(value==Qt::Unchecked)
realtimeUpdates->stop();
}
void ConfigStabilizationWidget::linkCheckBoxes(int value)
{
if(sender()== m_stabilization->checkBox_7)
m_stabilization->checkBox_3->setCheckState((Qt::CheckState)value);
else if(sender()== m_stabilization->checkBox_3)
m_stabilization->checkBox_7->setCheckState((Qt::CheckState)value);
else if(sender()== m_stabilization->checkBox_8)
m_stabilization->checkBox_2->setCheckState((Qt::CheckState)value);
else if(sender()== m_stabilization->checkBox_2)
m_stabilization->checkBox_8->setCheckState((Qt::CheckState)value);
}
void ConfigStabilizationWidget::processLinkedWidgets(QWidget * widget)
{
if(m_stabilization->checkBox_7->checkState()==Qt::Checked)
{
if(widget== m_stabilization->RateRollKp_2)
{
m_stabilization->RatePitchKp->setValue(m_stabilization->RateRollKp_2->value());
}
else if(widget== m_stabilization->RateRollKi_2)
{
m_stabilization->RatePitchKi->setValue(m_stabilization->RateRollKi_2->value());
}
else if(widget== m_stabilization->RateRollILimit_2)
{
m_stabilization->RatePitchILimit->setValue(m_stabilization->RateRollILimit_2->value());
}
else if(widget== m_stabilization->RatePitchKp)
{
m_stabilization->RateRollKp_2->setValue(m_stabilization->RatePitchKp->value());
}
else if(widget== m_stabilization->RatePitchKi)
{
m_stabilization->RateRollKi_2->setValue(m_stabilization->RatePitchKi->value());
}
else if(widget== m_stabilization->RatePitchILimit)
{
m_stabilization->RateRollILimit_2->setValue(m_stabilization->RatePitchILimit->value());
}
}
if(m_stabilization->checkBox_8->checkState()==Qt::Checked)
{
if(widget== m_stabilization->AttitudeRollKp)
{
m_stabilization->AttitudePitchKp_2->setValue(m_stabilization->AttitudeRollKp->value());
}
else if(widget== m_stabilization->AttitudeRollKi)
{
m_stabilization->AttitudePitchKi_2->setValue(m_stabilization->AttitudeRollKi->value());
}
else if(widget== m_stabilization->AttitudeRollILimit)
{
m_stabilization->AttitudePitchILimit_2->setValue(m_stabilization->AttitudeRollILimit->value());
}
else if(widget== m_stabilization->AttitudePitchKp_2)
{
m_stabilization->AttitudeRollKp->setValue(m_stabilization->AttitudePitchKp_2->value());
}
else if(widget== m_stabilization->AttitudePitchKi_2)
{
m_stabilization->AttitudeRollKi->setValue(m_stabilization->AttitudePitchKi_2->value());
}
else if(widget== m_stabilization->AttitudePitchILimit_2)
{
m_stabilization->AttitudeRollILimit->setValue(m_stabilization->AttitudePitchILimit_2->value());
}
}
}
void ConfigStabilizationWidget::updateRateRollKI(double val)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->ratePitchKi->setValue(val);
}
}
void ConfigStabilizationWidget::updateRateRollILimit(double val)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->ratePitchILimit->setValue(val);
}
}
void ConfigStabilizationWidget::updateRatePitchKP(double val)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->rateRollKp->setValue(val);
}
}
void ConfigStabilizationWidget::updateRatePitchKI(double val)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->rateRollKi->setValue(val);
}
}
void ConfigStabilizationWidget::updateRatePitchILimit(double val)
{
if (m_stabilization->linkRateRP->isChecked()) {
m_stabilization->rateRollILimit->setValue(val);
}
}
void ConfigStabilizationWidget::updateRollKP(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->pitchKp->setValue(val);
}
}
void ConfigStabilizationWidget::updateRollKI(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->pitchKi->setValue(val);
}
}
void ConfigStabilizationWidget::updateRollILimit(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->pitchILimit->setValue(val);
}
}
void ConfigStabilizationWidget::updatePitchKP(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->rollKp->setValue(val);
}
}
void ConfigStabilizationWidget::updatePitchKI(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->rollKi->setValue(val);
}
}
void ConfigStabilizationWidget::updatePitchILimit(double val)
{
if (m_stabilization->linkAttitudeRP->isChecked()) {
m_stabilization->rollILimit->setValue(val);
}
}
/*******************************
* Stabilization Settings
*****************************/
/**
* Refresh UI with new settings of StabilizationSettings object
* (either from active configuration or just loaded defaults
* to be applied or saved)
*/
void ConfigStabilizationWidget::refreshUIValues(StabilizationSettings::DataFields &stabData)
{
// Now fill in all the fields, this is fairly tedious:
m_stabilization->rateRollKp->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KP]);
m_stabilization->rateRollKi->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KI]);
m_stabilization->rateRollILimit->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_ILIMIT]);
m_stabilization->ratePitchKp->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP]);
m_stabilization->ratePitchKi->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI]);
m_stabilization->ratePitchILimit->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_ILIMIT]);
m_stabilization->rateYawKp->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KP]);
m_stabilization->rateYawKi->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KI]);
m_stabilization->rateYawILimit->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_ILIMIT]);
m_stabilization->rollKp->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_KP]);
m_stabilization->rollKi->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_KI]);
m_stabilization->rollILimit->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_ILIMIT]);
m_stabilization->pitchKp->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_KP]);
m_stabilization->pitchKi->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_KI]);
m_stabilization->pitchILimit->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_ILIMIT]);
m_stabilization->yawKp->setValue(stabData.YawPI[StabilizationSettings::YAWPI_KP]);
m_stabilization->yawKi->setValue(stabData.YawPI[StabilizationSettings::YAWPI_KI]);
m_stabilization->yawILimit->setValue(stabData.YawPI[StabilizationSettings::YAWPI_ILIMIT]);
m_stabilization->rollMax->setValue(stabData.RollMax);
m_stabilization->pitchMax->setValue(stabData.PitchMax);
m_stabilization->yawMax->setValue(stabData.YawMax);
m_stabilization->manualRoll->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_ROLL]);
m_stabilization->manualPitch->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_PITCH]);
m_stabilization->manualYaw->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_YAW]);
m_stabilization->maximumRoll->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_ROLL]);
m_stabilization->maximumPitch->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_PITCH]);
m_stabilization->maximumYaw->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_YAW]);
m_stabilization->lowThrottleZeroIntegral->setChecked(stabData.LowThrottleZeroIntegral==StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_TRUE ? true : false);
}
/**
Request stabilization settings from the board
*/
void ConfigStabilizationWidget::refreshWidgetsValues()
{
bool dirty=isDirty();
// Not needed anymore as this slot is only called whenever we get
// a signal that the object was just updated
// stabSettings->requestUpdate();
StabilizationSettings::DataFields stabData = stabSettings->getData();
refreshUIValues(stabData);
setDirty(dirty);
}
/**
Send telemetry settings to the board
*/
void ConfigStabilizationWidget::updateObjectsFromWidgets()
{
StabilizationSettings::DataFields stabData = stabSettings->getData();
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KP] = m_stabilization->rateRollKp->value();
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KI] = m_stabilization->rateRollKi->value();
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_ILIMIT] = m_stabilization->rateRollILimit->value();
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP] = m_stabilization->ratePitchKp->value();
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI] = m_stabilization->ratePitchKi->value();
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_ILIMIT] = m_stabilization->ratePitchILimit->value();
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KP] = m_stabilization->rateYawKp->value();
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KI] = m_stabilization->rateYawKi->value();
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_ILIMIT] = m_stabilization->rateYawILimit->value();
stabData.RollPI[StabilizationSettings::ROLLPI_KP] = m_stabilization->rollKp->value();
stabData.RollPI[StabilizationSettings::ROLLPI_KI] = m_stabilization->rollKi->value();
stabData.RollPI[StabilizationSettings::ROLLPI_ILIMIT] = m_stabilization->rollILimit->value();
stabData.PitchPI[StabilizationSettings::PITCHPI_KP] = m_stabilization->pitchKp->value();
stabData.PitchPI[StabilizationSettings::PITCHPI_KI] = m_stabilization->pitchKi->value();
stabData.PitchPI[StabilizationSettings::PITCHPI_ILIMIT] = m_stabilization->pitchILimit->value();
stabData.YawPI[StabilizationSettings::YAWPI_KP] = m_stabilization->yawKp->value();
stabData.YawPI[StabilizationSettings::YAWPI_KI] = m_stabilization->yawKi->value();
stabData.YawPI[StabilizationSettings::YAWPI_ILIMIT] = m_stabilization->yawILimit->value();
stabData.RollMax = m_stabilization->rollMax->value();
stabData.PitchMax = m_stabilization->pitchMax->value();
stabData.YawMax = m_stabilization->yawMax->value();
stabData.ManualRate[StabilizationSettings::MANUALRATE_ROLL] = m_stabilization->manualRoll->value();
stabData.ManualRate[StabilizationSettings::MANUALRATE_PITCH] = m_stabilization->manualPitch->value();
stabData.ManualRate[StabilizationSettings::MANUALRATE_YAW] = m_stabilization->manualYaw->value();
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_ROLL] = m_stabilization->maximumRoll->value();
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_PITCH] = m_stabilization->maximumPitch->value();
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_YAW] = m_stabilization->maximumYaw->value();
stabData.LowThrottleZeroIntegral = (m_stabilization->lowThrottleZeroIntegral->isChecked() ? StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_TRUE :StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_FALSE);
stabSettings->setData(stabData); // this is atomic
}
void ConfigStabilizationWidget::realtimeUpdateToggle(bool state)
{
if (state) {
updateTimer.start(300);
} else {
updateTimer.stop();
}
}
void ConfigStabilizationWidget::resetToDefaults()
{
StabilizationSettings stabDefaults;
StabilizationSettings::DataFields defaults = stabDefaults.getData();
bool dirty=isDirty();
refreshUIValues(defaults);
setDirty(dirty);
}
void ConfigStabilizationWidget::openHelp()
{
QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Stabilization+panel", QUrl::StrictMode) );
}

View File

@ -28,7 +28,7 @@
#define CONFIGSTABILIZATIONWIDGET_H
#include "ui_stabilization.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
@ -47,32 +47,11 @@ public:
private:
Ui_StabilizationWidget *m_stabilization;
StabilizationSettings* stabSettings;
QTimer updateTimer;
void refreshUIValues(StabilizationSettings::DataFields &stabData);
QTimer * realtimeUpdates;
private slots:
virtual void refreshWidgetsValues();
void updateObjectsFromWidgets();
void realtimeUpdateToggle(bool);
void resetToDefaults();
void openHelp();
void updateRateRollKP(double);
void updateRateRollKI(double);
void updateRateRollILimit(double);
void updateRatePitchKP(double);
void updateRatePitchKI(double);
void updateRatePitchILimit(double);
void updateRollKP(double);
void updateRollKI(double);
void updateRollILimit(double);
void updatePitchKP(double);
void updatePitchKI(double);
void updatePitchILimit(double);
void realtimeUpdatesSlot(int);
void linkCheckBoxes(int value);
void processLinkedWidgets(QWidget*);
};
#endif // CONFIGSTABILIZATIONWIDGET_H
#endif // ConfigStabilizationWidget_H

View File

@ -1,365 +0,0 @@
/**
******************************************************************************
*
* @file configtaskwidget.cpp
* @author E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Config Plugin
* @{
* @brief The Configuration Gadget used to update settings in the firmware
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "configtaskwidget.h"
#include <QtGui/QWidget>
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
#include "configgadgetwidget.h"
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false)
{
pm = ExtensionSystem::PluginManager::instance();
objManager = pm->getObject<UAVObjectManager>();
connect((ConfigGadgetWidget*)parent, SIGNAL(autopilotConnected()),this, SLOT(onAutopilotConnect()));
connect((ConfigGadgetWidget*)parent, SIGNAL(autopilotDisconnected()),this, SLOT(onAutopilotDisconnect()));
UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(invalidateObjects()));
}
void ConfigTaskWidget::addWidget(QWidget * widget)
{
addUAVObjectToWidgetRelation("","",widget);
}
void ConfigTaskWidget::addUAVObject(QString objectName)
{
addUAVObjectToWidgetRelation(objectName,"",NULL);
}
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, QString index)
{
UAVObject *obj=NULL;
UAVObjectField *_field=NULL;
obj = objManager->getObject(QString(object));
Q_ASSERT(obj);
_field = obj->getField(QString(field));
Q_ASSERT(_field);
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
}
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, int index,int scale)
{
UAVObject *obj=NULL;
UAVObjectField *_field=NULL;
if(!object.isEmpty())
{
obj = objManager->getObject(QString(object));
Q_ASSERT(obj);
objectUpdates.insert(obj,true);
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this, SLOT(objectUpdated(UAVObject*)));
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
//smartsave->addObject(obj);
if(!field.isEmpty() && obj)
_field = obj->getField(QString(field));
objectToWidget * ow=new objectToWidget();
ow->field=_field;
ow->object=obj;
ow->widget=widget;
ow->index=index;
ow->scale=scale;
objOfInterest.append(ow);
if(obj)
smartsave->addObject((UAVDataObject*)obj);
if(widget==NULL)
{
// do nothing
}
else if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
connect(cb,SIGNAL(currentIndexChanged(int)),this,SLOT(widgetsContentsChanged()));
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
connect(cb,SIGNAL(sliderMoved(int)),this,SLOT(widgetsContentsChanged()));
}
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
{
connect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,SLOT(widgetsContentsChanged()));
}
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
{
connect(cb,SIGNAL(cellChanged(int,int)),this,SLOT(widgetsContentsChanged()));
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
connect(cb,SIGNAL(valueChanged(int)),this,SLOT(widgetsContentsChanged()));
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
connect(cb,SIGNAL(valueChanged(double)),this,SLOT(widgetsContentsChanged()));
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
{
connect(cb,SIGNAL(clicked()),this,SLOT(widgetsContentsChanged()));
}
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
{
connect(cb,SIGNAL(clicked()),this,SLOT(widgetsContentsChanged()));
}
}
ConfigTaskWidget::~ConfigTaskWidget()
{
delete smartsave;
}
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
{
qDebug()<<"ConfigTaskWidget::saveObjectToSD";
// saveObjectToSD is now handled by the UAVUtils plugin in one
// central place (and one central queue)
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectUtilManager* utilMngr = pm->getObject<UAVObjectUtilManager>();
utilMngr->saveObjectToSD(obj);
}
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
Q_ASSERT(objMngr);
return objMngr;
}
double ConfigTaskWidget::listMean(QList<double> list)
{
double accum = 0;
for(int i = 0; i < list.size(); i++)
accum += list[i];
return accum / list.size();
}
// ************************************
// telemetry start/stop connect/disconnect signals
void ConfigTaskWidget::onAutopilotDisconnect()
{
isConnected=false;
enableControls(false);
invalidateObjects();
}
void ConfigTaskWidget::onAutopilotConnect()
{
invalidateObjects();
dirty=false;
isConnected=true;
enableControls(true);
refreshWidgetsValues();
}
void ConfigTaskWidget::populateWidgets()
{
bool dirtyBack=dirty;
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL)
{
// do nothing
}
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
{
cb->addItems(ow->field->getOptions());
cb->setCurrentIndex(cb->findText(ow->field->getValue(ow->index).toString()));
}
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
{
cb->setText(ow->field->getValue(ow->index).toString());
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(ow->widget))
{
cb->setChecked(ow->field->getValue(ow->index).toBool());
}
}
setDirty(dirtyBack);
}
void ConfigTaskWidget::refreshWidgetsValues()
{
bool dirtyBack=dirty;
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL)
{
//do nothing
}
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
{
cb->setCurrentIndex(cb->findText(ow->field->getValue(ow->index).toString()));
}
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
{
cb->setText(ow->field->getValue(ow->index).toString());
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(ow->widget))
{
cb->setChecked(ow->field->getValue(ow->index).toBool());
}
}
setDirty(dirtyBack);
}
void ConfigTaskWidget::updateObjectsFromWidgets()
{
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL)
{
//do nothing
}
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
{
ow->field->setValue(cb->currentText(),ow->index);
}
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
{
ow->field->setValue(cb->text(),ow->index);
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
{
ow->field->setValue(cb->value()* ow->scale,ow->index);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
ow->field->setValue(cb->value()* ow->scale,ow->index);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(ow->widget))
{
ow->field->setValue((cb->isChecked()?"TRUE":"FALSE"),ow->index);
}
}
}
void ConfigTaskWidget::setupButtons(QPushButton *update, QPushButton *save)
{
smartsave=new smartSaveButton(update,save);
connect(smartsave,SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
connect(smartsave,SIGNAL(saveSuccessfull()),this,SLOT(clearDirty()));
connect(smartsave,SIGNAL(beginOp()),this,SLOT(disableObjUpdates()));
connect(smartsave,SIGNAL(endOp()),this,SLOT(enableObjUpdates()));
enableControls(false);
}
void ConfigTaskWidget::enableControls(bool enable)
{
if(smartsave)
smartsave->enableControls(enable);
}
void ConfigTaskWidget::widgetsContentsChanged()
{
setDirty(true);
}
void ConfigTaskWidget::clearDirty()
{
setDirty(false);
}
void ConfigTaskWidget::setDirty(bool value)
{
dirty=value;
}
bool ConfigTaskWidget::isDirty()
{
if(isConnected)
return dirty;
else
return false;
}
void ConfigTaskWidget::refreshValues()
{
}
void ConfigTaskWidget::disableObjUpdates()
{
foreach(objectToWidget * obj,objOfInterest)
{
if(obj->object)
disconnect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
}
void ConfigTaskWidget::enableObjUpdates()
{
foreach(objectToWidget * obj,objOfInterest)
{
if(obj->object)
connect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
}
void ConfigTaskWidget::objectUpdated(UAVObject *obj)
{
objectUpdates[obj]=true;
}
bool ConfigTaskWidget::allObjectsUpdated()
{
bool ret=true;
foreach(UAVObject *obj, objectUpdates.keys())
{
ret=ret & objectUpdates[obj];
}
qDebug()<<"ALL OBJECTS UPDATE:"<<ret;
return ret;
}
void ConfigTaskWidget::invalidateObjects()
{
foreach(UAVObject *obj, objectUpdates.keys())
{
objectUpdates[obj]=false;
}
}
/**
@}
@}
*/

View File

@ -1,105 +0,0 @@
/**
******************************************************************************
*
* @file configtaskwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Config Plugin
* @{
* @brief The Configuration Gadget used to update settings in the firmware (task widget)
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONFIGTASKWIDGET_H
#define CONFIGTASKWIDGET_H
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "uavobjectutilmanager.h"
#include <QQueue>
#include <QtGui/QWidget>
#include <QList>
#include <QLabel>
#include "smartsavebutton.h"
#include "mixercurvewidget.h"
#include <QTableWidget>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QPushButton>
class ConfigTaskWidget: public QWidget
{
Q_OBJECT
public:
struct objectToWidget
{
UAVObject * object;
UAVObjectField * field;
QWidget * widget;
int index;
int scale;
};
ConfigTaskWidget(QWidget *parent = 0);
~ConfigTaskWidget();
void saveObjectToSD(UAVObject *obj);
UAVObjectManager* getObjectManager();
static double listMean(QList<double> list);
void addUAVObject(QString objectName);
void addWidget(QWidget * widget);
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,int scale=1);
void setupButtons(QPushButton * update,QPushButton * save);
bool isDirty();
void setDirty(bool value);
void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index);
bool allObjectsUpdated();
public slots:
void onAutopilotDisconnect();
void onAutopilotConnect();
void invalidateObjects();
private slots:
virtual void refreshValues();
virtual void updateObjectsFromWidgets();
void objectUpdated(UAVObject*);
private:
bool isConnected;
QStringList objectsList;
QList <objectToWidget*> objOfInterest;
ExtensionSystem::PluginManager *pm;
UAVObjectManager *objManager;
smartSaveButton *smartsave;
QMap<UAVObject *,bool> objectUpdates;
bool dirty;
protected slots:
virtual void disableObjUpdates();
virtual void enableObjUpdates();
virtual void clearDirty();
virtual void widgetsContentsChanged();
virtual void populateWidgets();
virtual void refreshWidgetsValues();
protected:
virtual void enableControls(bool enable);
};
#endif // CONFIGTASKWIDGET_H

View File

@ -28,7 +28,7 @@
#define DEFAULTATTITUDEWIDGET_H
#include "ui_defaultattitude.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -28,7 +28,7 @@
#define DEFAULTHWSETTINGSt_H
#include "ui_defaulthwsettings.h"
#include "configtaskwidget.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"

View File

@ -1,49 +0,0 @@
#ifndef SMARTSAVEBUTTON_H
#define SMARTSAVEBUTTON_H
#include "uavtalk/telemetrymanager.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QPushButton>
#include <QList>
#include <QEventLoop>
#include "uavobjectutilmanager.h"
#include <QObject>
#include <QDebug>
class smartSaveButton:public QObject
{
public:
Q_OBJECT
public:
smartSaveButton(QPushButton * update,QPushButton * save);
void setObjects(QList<UAVDataObject *>);
void addObject(UAVDataObject *);
void clearObjects();
signals:
void preProcessOperations();
void saveSuccessfull();
void beginOp();
void endOp();
private slots:
void processClick();
void transaction_finished(UAVObject* obj, bool result);
void saving_finished(int,bool);
private:
QPushButton *bupdate;
QPushButton *bsave;
quint32 current_objectID;
UAVDataObject * current_object;
bool up_result;
bool sv_result;
QEventLoop loop;
QList<UAVDataObject *> objects;
protected:
public slots:
void enableControls(bool value);
};
#endif // SMARTSAVEBUTTON_H

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,7 @@ public:
QString contextHelpId() const { return QString(); }
private:
QWidget *m_widget;
QWidget *m_widget;
QList<int> m_context;
};

View File

@ -3,7 +3,6 @@ TARGET = DebugGadget
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/libqxt/core/logengines.pri)
HEADERS += debugplugin.h \
debugengine.h
HEADERS += debuggadget.h

View File

@ -112,6 +112,7 @@ SUBDIRS += plugin_systemhealth
plugin_config.subdir = config
plugin_config.depends = plugin_coreplugin
plugin_config.depends += plugin_uavobjects
plugin_config.depends += plugin_uavobjectwidgetutils
plugin_config.depends += plugin_uavsettingsimportexport
SUBDIRS += plugin_config
@ -190,6 +191,12 @@ plugin_uavobjectutil.depends = plugin_coreplugin
plugin_uavobjectutil.depends += plugin_uavobjects
SUBDIRS += plugin_uavobjectutil
# UAV Object Widget Utility plugin
plugin_uavobjectwidgetutils.subdir = uavobjectwidgetutils
plugin_uavobjectwidgetutils.depends = plugin_coreplugin
plugin_uavobjectwidgetutils.depends += plugin_uavobjects
SUBDIRS += plugin_uavobjectwidgetutils
# Magic Waypoint gadget
plugin_magicwaypoint.subdir = magicwaypoint
plugin_magicwaypoint.depends = plugin_coreplugin

View File

@ -47,6 +47,7 @@ public:
Metadata getMetadata();
UAVMetaObject* getMetaObject();
virtual UAVDataObject* clone(quint32 instID = 0) = 0;
virtual UAVDataObject* dirtyClone() = 0;
private:
UAVMetaObject* mobj;

View File

@ -11,25 +11,25 @@
* @brief The UAVUObjects GCS plugin
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uavobjectfield.h"
#include <QtEndian>
#include <QDebug>
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options, const QString &limits)
{
QStringList elementNames;
// Set element names
@ -38,16 +38,16 @@ UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldT
elementNames.append(QString("%1").arg(n));
}
// Initialize
constructorInitialize(name, units, type, elementNames, options);
constructorInitialize(name, units, type, elementNames, options,limits);
}
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options, const QString &limits)
{
constructorInitialize(name, units, type, elementNames, options);
constructorInitialize(name, units, type, elementNames, options,limits);
}
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options,const QString &limits)
{
// Copy params
this->name = name;
@ -62,38 +62,368 @@ void UAVObjectField::constructorInitialize(const QString& name, const QString& u
// Set field size
switch (type)
{
case INT8:
numBytesPerElement = sizeof(qint8);
break;
case INT16:
numBytesPerElement = sizeof(qint16);
break;
case INT32:
numBytesPerElement = sizeof(qint32);
break;
case UINT8:
numBytesPerElement = sizeof(quint8);
break;
case UINT16:
numBytesPerElement = sizeof(quint16);
break;
case UINT32:
numBytesPerElement = sizeof(quint32);
break;
case FLOAT32:
numBytesPerElement = sizeof(quint32);
break;
case ENUM:
numBytesPerElement = sizeof(quint8);
break;
case STRING:
numBytesPerElement = sizeof(quint8);
break;
default:
numBytesPerElement = 0;
case INT8:
numBytesPerElement = sizeof(qint8);
break;
case INT16:
numBytesPerElement = sizeof(qint16);
break;
case INT32:
numBytesPerElement = sizeof(qint32);
break;
case UINT8:
numBytesPerElement = sizeof(quint8);
break;
case UINT16:
numBytesPerElement = sizeof(quint16);
break;
case UINT32:
numBytesPerElement = sizeof(quint32);
break;
case FLOAT32:
numBytesPerElement = sizeof(quint32);
break;
case ENUM:
numBytesPerElement = sizeof(quint8);
break;
case STRING:
numBytesPerElement = sizeof(quint8);
break;
default:
numBytesPerElement = 0;
}
limitsInitialize(limits);
}
void UAVObjectField::limitsInitialize(const QString &limits)
{
/// format
/// (TY)->type (EQ-equal;NE-not equal;BE-between;BI-bigger;SM-smaller)
/// (VALX)->value
/// %TY:VAL1:VAL2:VAL3,%TY,VAL1,VAL2,VAL3
/// example: first element bigger than 3 and second element inside [2.3,5]
/// "%BI:3,%BE:2.3:5"
if(limits.isEmpty())
return;
QStringList stringPerElement=limits.split(",");
quint32 index=0;
foreach (QString str, stringPerElement) {
QString _str=str.trimmed();
QStringList valuesPerElement=_str.split(":");
LimitStruct lstruc;
bool b1=valuesPerElement.at(0).startsWith("%");
bool b2=(int)(index)<(int)numElements;
if(b1 && b2)
{
if(valuesPerElement.at(0).right(2)=="EQ")
lstruc.type=EQUAL;
else if(valuesPerElement.at(0).right(2)=="NE")
lstruc.type=NOT_EQUAL;
else if(valuesPerElement.at(0).right(2)=="BE")
lstruc.type=BETWEEN;
else if(valuesPerElement.at(0).right(2)=="BI")
lstruc.type=BIGGER;
else if(valuesPerElement.at(0).right(2)=="SM")
lstruc.type=SMALLER;
else
qDebug()<<"limits parsing failed (invalid property) on UAVObjectField"<<name;
valuesPerElement.removeAt(0);
foreach(QString _value,valuesPerElement)
{
QString value=_value.trimmed();
switch (type)
{
case INT8:
case INT16:
case INT32:
case UINT8:
lstruc.values.append((quint32)value.toULong());
break;
case UINT16:
case UINT32:
lstruc.values.append((qint32)value.toLong());
break;
case FLOAT32:
lstruc.values.append((float)value.toFloat());
break;
case ENUM:
lstruc.values.append((QString)value);
break;
case STRING:
lstruc.values.append((QString)value);
break;
default:
lstruc.values.append(QVariant());
}
}
elementLimits.insert(index,lstruc);
++index;
}
else
{
if(!valuesPerElement.at(0).isEmpty() && !b1)
qDebug()<<"limits parsing failed (property doesn't start with %) on UAVObjectField"<<name;
else if(!b2)
qDebug()<<"limits parsing failed (index>numelements) on UAVObjectField"<<name<<"index"<<index<<"numElements"<<numElements;
}
}
}
bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
{
if(!elementLimits.keys().contains(index))
return true;
LimitStruct struc=elementLimits.value(index);
switch(struc.type)
{
case EQUAL:
switch (type)
{
case INT8:
case INT16:
case INT32:
foreach (QVariant vars, struc.values) {
if(var.toInt()==vars.toInt())
return true;
}
return false;
break;
case UINT8:
case UINT16:
case UINT32:
foreach (QVariant vars, struc.values) {
if(var.toUInt()==vars.toUInt())
return true;
}
return false;
break;
case ENUM:
case STRING:
foreach (QVariant vars, struc.values) {
if(var.toString()==vars.toString())
return true;
}
return false;
break;
case FLOAT32:
foreach (QVariant vars, struc.values) {
if(var.toFloat()==vars.toFloat())
return true;
}
return false;
break;
default:
return true;
}
break;
case NOT_EQUAL:
switch (type)
{
case INT8:
case INT16:
case INT32:
foreach (QVariant vars, struc.values) {
if(var.toInt()==vars.toInt())
return false;
}
return true;
break;
case UINT8:
case UINT16:
case UINT32:
foreach (QVariant vars, struc.values) {
if(var.toUInt()==vars.toUInt())
return false;
}
return true;
break;
case ENUM:
case STRING:
foreach (QVariant vars, struc.values) {
if(var.toString()==vars.toString())
return false;
}
return true;
break;
case FLOAT32:
foreach (QVariant vars, struc.values) {
if(var.toFloat()==vars.toFloat())
return false;
}
return true;
break;
default:
return true;
}
break;
case BETWEEN:
if(struc.values.length()<2)
{
qDebug()<<__FUNCTION__<<"between limit with less than 1 pair, aborting; field:"<<name;
return true;
}
if(struc.values.length()>2)
qDebug()<<__FUNCTION__<<"between limit with more than 1 pair, using first; field"<<name;
switch (type)
{
case INT8:
case INT16:
case INT32:
if(!(var.toInt()>=struc.values.at(0).toInt() && var.toInt()<=struc.values.at(1).toInt()))
return false;
return true;
break;
case UINT8:
case UINT16:
case UINT32:
if(!(var.toUInt()>=struc.values.at(0).toUInt() && var.toUInt()<=struc.values.at(1).toUInt()))
return false;
return true;
break;
case ENUM:
if(!(options.indexOf(var.toString())>=options.indexOf(struc.values.at(0).toString()) && options.indexOf(var.toString())<=options.indexOf(struc.values.at(1).toString())))
return false;
return true;
break;
case STRING:
return true;
break;
case FLOAT32:
if(!(var.toFloat()>=struc.values.at(0).toFloat() && var.toFloat()<=struc.values.at(1).toFloat()))
return false;
return true;
break;
default:
return true;
}
break;
case BIGGER:
if(struc.values.length()<1)
{
qDebug()<<__FUNCTION__<<"BIGGER limit with less than 1 value, aborting; field:"<<name;
return true;
}
if(struc.values.length()>1)
qDebug()<<__FUNCTION__<<"BIGGER limit with more than 1 value, using first; field"<<name;
switch (type)
{
case INT8:
case INT16:
case INT32:
if(!(var.toInt()>=struc.values.at(0).toInt()))
return false;
return true;
break;
case UINT8:
case UINT16:
case UINT32:
if(!(var.toUInt()>=struc.values.at(0).toUInt()))
return false;
return true;
break;
case ENUM:
if(!(options.indexOf(var.toString())>=options.indexOf(struc.values.at(0).toString())))
return false;
return true;
break;
case STRING:
return true;
break;
case FLOAT32:
if(!(var.toFloat()>=struc.values.at(0).toFloat()))
return false;
return true;
break;
default:
return true;
}
break;
case SMALLER:
switch (type)
{
case INT8:
case INT16:
case INT32:
if(!(var.toInt()<=struc.values.at(0).toInt()))
return false;
return true;
break;
case UINT8:
case UINT16:
case UINT32:
if(!(var.toUInt()<=struc.values.at(0).toUInt()))
return false;
return true;
break;
case ENUM:
if(!(options.indexOf(var.toString())<=options.indexOf(struc.values.at(0).toString())))
return false;
return true;
break;
case STRING:
return true;
break;
case FLOAT32:
if(!(var.toFloat()<=struc.values.at(0).toFloat()))
return false;
return true;
break;
default:
return true;
}
}
return true;
}
QVariant UAVObjectField::getMaxLimit(quint32 index)
{
if(!elementLimits.keys().contains(index))
return QVariant();
LimitStruct struc=elementLimits.value(index);
switch(struc.type)
{
case EQUAL:
case NOT_EQUAL:
case BIGGER:
return QVariant();
break;
break;
case BETWEEN:
return struc.values.at(1);
break;
case SMALLER:
return struc.values.at(0);
break;
default:
return QVariant();
break;
}
return QVariant();
}
QVariant UAVObjectField::getMinLimit(quint32 index)
{
if(!elementLimits.keys().contains(index))
return QVariant();
LimitStruct struc=elementLimits.value(index);
switch(struc.type)
{
case EQUAL:
case NOT_EQUAL:
case SMALLER:
return QVariant();
break;
break;
case BETWEEN:
return struc.values.at(0);
break;
case BIGGER:
return struc.values.at(0);
break;
default:
return QVariant();
break;
}
return QVariant();
}
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
{
this->data = data;
@ -111,26 +441,26 @@ QString UAVObjectField::getTypeAsString()
{
switch (type)
{
case UAVObjectField::INT8:
return "int8";
case UAVObjectField::INT16:
return "int16";
case UAVObjectField::INT32:
return "int32";
case UAVObjectField::UINT8:
return "uint8";
case UAVObjectField::UINT16:
return "uint16";
case UAVObjectField::UINT32:
return "uint32";
case UAVObjectField::FLOAT32:
return "float32";
case UAVObjectField::ENUM:
return "enum";
case UAVObjectField::STRING:
return "string";
default:
return "";
case UAVObjectField::INT8:
return "int8";
case UAVObjectField::INT16:
return "int16";
case UAVObjectField::INT32:
return "int32";
case UAVObjectField::UINT8:
return "uint8";
case UAVObjectField::UINT16:
return "uint16";
case UAVObjectField::UINT32:
return "uint32";
case UAVObjectField::FLOAT32:
return "float32";
case UAVObjectField::ENUM:
return "enum";
case UAVObjectField::STRING:
return "string";
default:
return "";
}
}
@ -199,64 +529,64 @@ qint32 UAVObjectField::pack(quint8* dataOut)
// Pack each element in output buffer
switch (type)
{
case INT8:
memcpy(dataOut, &data[offset], numElements);
break;
case INT16:
for (quint32 index = 0; index < numElements; ++index)
{
qint16 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
}
break;
case INT32:
for (quint32 index = 0; index < numElements; ++index)
{
qint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case UINT8:
for (quint32 index = 0; index < numElements; ++index)
{
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
}
break;
case UINT16:
for (quint32 index = 0; index < numElements; ++index)
{
quint16 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
}
break;
case UINT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case FLOAT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case ENUM:
for (quint32 index = 0; index < numElements; ++index)
{
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
}
break;
case STRING:
memcpy(dataOut, &data[offset], numElements);
break;
case INT8:
memcpy(dataOut, &data[offset], numElements);
break;
case INT16:
for (quint32 index = 0; index < numElements; ++index)
{
qint16 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
}
break;
case INT32:
for (quint32 index = 0; index < numElements; ++index)
{
qint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case UINT8:
for (quint32 index = 0; index < numElements; ++index)
{
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
}
break;
case UINT16:
for (quint32 index = 0; index < numElements; ++index)
{
quint16 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
}
break;
case UINT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case FLOAT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
}
break;
case ENUM:
for (quint32 index = 0; index < numElements; ++index)
{
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
}
break;
case STRING:
memcpy(dataOut, &data[offset], numElements);
break;
}
// Done
return getNumBytes();
@ -268,64 +598,64 @@ qint32 UAVObjectField::unpack(const quint8* dataIn)
// Unpack each element from input buffer
switch (type)
{
case INT8:
memcpy(&data[offset], dataIn, numElements);
break;
case INT16:
for (quint32 index = 0; index < numElements; ++index)
{
qint16 value;
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case INT32:
for (quint32 index = 0; index < numElements; ++index)
{
qint32 value;
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case UINT8:
for (quint32 index = 0; index < numElements; ++index)
{
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
}
break;
case UINT16:
for (quint32 index = 0; index < numElements; ++index)
{
quint16 value;
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case UINT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case FLOAT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case ENUM:
for (quint32 index = 0; index < numElements; ++index)
{
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
}
break;
case STRING:
memcpy(&data[offset], dataIn, numElements);
break;
case INT8:
memcpy(&data[offset], dataIn, numElements);
break;
case INT16:
for (quint32 index = 0; index < numElements; ++index)
{
qint16 value;
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case INT32:
for (quint32 index = 0; index < numElements; ++index)
{
qint32 value;
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case UINT8:
for (quint32 index = 0; index < numElements; ++index)
{
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
}
break;
case UINT16:
for (quint32 index = 0; index < numElements; ++index)
{
quint16 value;
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case UINT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case FLOAT32:
for (quint32 index = 0; index < numElements; ++index)
{
quint32 value;
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
}
break;
case ENUM:
for (quint32 index = 0; index < numElements; ++index)
{
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
}
break;
case STRING:
memcpy(&data[offset], dataIn, numElements);
break;
}
// Done
return getNumBytes();
@ -340,35 +670,35 @@ bool UAVObjectField::isNumeric()
{
switch (type)
{
case INT8:
return true;
break;
case INT16:
return true;
break;
case INT32:
return true;
break;
case UINT8:
return true;
break;
case UINT16:
return true;
break;
case UINT32:
return true;
break;
case FLOAT32:
return true;
break;
case ENUM:
return false;
break;
case STRING:
return false;
break;
default:
return false;
case INT8:
return true;
break;
case INT16:
return true;
break;
case INT32:
return true;
break;
case UINT8:
return true;
break;
case UINT16:
return true;
break;
case UINT32:
return true;
break;
case FLOAT32:
return true;
break;
case ENUM:
return false;
break;
case STRING:
return false;
break;
default:
return false;
}
}
@ -376,35 +706,35 @@ bool UAVObjectField::isText()
{
switch (type)
{
case INT8:
return false;
break;
case INT16:
return false;
break;
case INT32:
return false;
break;
case UINT8:
return false;
break;
case UINT16:
return false;
break;
case UINT32:
return false;
break;
case FLOAT32:
return false;
break;
case ENUM:
return true;
break;
case STRING:
return true;
break;
default:
return false;
case INT8:
return false;
break;
case INT16:
return false;
break;
case INT32:
return false;
break;
case UINT8:
return false;
break;
case UINT16:
return false;
break;
case UINT32:
return false;
break;
case FLOAT32:
return false;
break;
case ENUM:
return true;
break;
case STRING:
return true;
break;
default:
return false;
}
}
@ -419,74 +749,74 @@ QVariant UAVObjectField::getValue(quint32 index)
// Get value
switch (type)
{
case INT8:
{
qint8 tmpint8;
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint8);
break;
}
case INT16:
{
qint16 tmpint16;
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint16);
break;
}
case INT32:
{
qint32 tmpint32;
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint32);
break;
}
case UINT8:
{
quint8 tmpuint8;
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint8);
break;
}
case UINT16:
{
quint16 tmpuint16;
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint16);
break;
}
case UINT32:
{
quint32 tmpuint32;
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint32);
break;
}
case FLOAT32:
{
float tmpfloat;
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpfloat);
break;
}
case ENUM:
{
quint8 tmpenum;
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
// Q_ASSERT((tmpenum < options.length()) && (tmpenum >= 0)); // catch bad enum settings
if(tmpenum >= options.length()) {
qDebug() << "Invalid value for" << name;
return QVariant( QString("Bad Value") );
}
return QVariant( options[tmpenum] );
break;
}
case STRING:
{
data[offset + numElements - 1] = '\0';
QString str((char*)&data[offset]);
return QVariant( str );
break;
case INT8:
{
qint8 tmpint8;
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint8);
break;
}
case INT16:
{
qint16 tmpint16;
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint16);
break;
}
case INT32:
{
qint32 tmpint32;
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpint32);
break;
}
case UINT8:
{
quint8 tmpuint8;
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint8);
break;
}
case UINT16:
{
quint16 tmpuint16;
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint16);
break;
}
case UINT32:
{
quint32 tmpuint32;
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpuint32);
break;
}
case FLOAT32:
{
float tmpfloat;
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
return QVariant(tmpfloat);
break;
}
case ENUM:
{
quint8 tmpenum;
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
// Q_ASSERT((tmpenum < options.length()) && (tmpenum >= 0)); // catch bad enum settings
if(tmpenum >= options.length()) {
qDebug() << "Invalid value for" << name;
return QVariant( QString("Bad Value") );
}
return QVariant( options[tmpenum] );
break;
}
case STRING:
{
data[offset + numElements - 1] = '\0';
QString str((char*)&data[offset]);
return QVariant( str );
break;
}
}
// If this point is reached then we got an invalid type
return QVariant();
@ -499,7 +829,7 @@ bool UAVObjectField::checkValue(const QVariant& value, quint32 index)
if ( index >= numElements )
{
return false;
}
}
// Get metadata
UAVObject::Metadata mdata = obj->getMetadata();
// Update value if the access mode permits
@ -507,28 +837,29 @@ bool UAVObjectField::checkValue(const QVariant& value, quint32 index)
{
switch (type)
{
case INT8:
case INT16:
case INT32:
case UINT8:
case UINT16:
case UINT32:
case FLOAT32:
case STRING:
return true;
break;
case ENUM:
{
qint8 tmpenum = options.indexOf( value.toString() );
return ((tmpenum < 0) ? false : true);
break;
}
default:
qDebug() << "checkValue: other types" << type;
Q_ASSERT(0); // To catch any programming errors where we tried to test invalid values
break;
case INT8:
case INT16:
case INT32:
case UINT8:
case UINT16:
case UINT32:
case FLOAT32:
case STRING:
return true;
break;
case ENUM:
{
qint8 tmpenum = options.indexOf( value.toString() );
return ((tmpenum < 0) ? false : true);
break;
}
default:
qDebug() << "checkValue: other types" << type;
Q_ASSERT(0); // To catch any programming errors where we tried to test invalid values
break;
}
}
return true;
}
void UAVObjectField::setValue(const QVariant& value, quint32 index)
@ -538,7 +869,7 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
if ( index >= numElements )
{
return;
}
}
// Get metadata
UAVObject::Metadata mdata = obj->getMetadata();
// Update value if the access mode permits
@ -546,67 +877,67 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
{
switch (type)
{
case INT8:
case INT8:
{
qint8 tmpint8 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
break;
}
case INT16:
{
qint16 tmpint16 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
break;
}
case INT32:
{
qint32 tmpint32 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
break;
}
case UINT8:
{
quint8 tmpuint8 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
break;
}
case UINT16:
{
quint16 tmpuint16 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
break;
}
case UINT32:
{
quint32 tmpuint32 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
break;
}
case FLOAT32:
{
float tmpfloat = value.toFloat();
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
break;
}
case ENUM:
{
qint8 tmpenum = options.indexOf( value.toString() );
Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
break;
}
case STRING:
{
QString str = value.toString();
QByteArray barray = str.toAscii();
quint32 index;
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
{
qint8 tmpint8 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
break;
}
case INT16:
{
qint16 tmpint16 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
break;
}
case INT32:
{
qint32 tmpint32 = value.toInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
break;
}
case UINT8:
{
quint8 tmpuint8 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
break;
}
case UINT16:
{
quint16 tmpuint16 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
break;
}
case UINT32:
{
quint32 tmpuint32 = value.toUInt();
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
break;
}
case FLOAT32:
{
float tmpfloat = value.toFloat();
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
break;
}
case ENUM:
{
qint8 tmpenum = options.indexOf( value.toString() );
Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
break;
}
case STRING:
{
QString str = value.toString();
QByteArray barray = str.toAscii();
quint32 index;
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
{
data[offset+index] = barray[index];
}
barray[index] = '\0';
break;
data[offset+index] = barray[index];
}
barray[index] = '\0';
break;
}
}
}
}

View File

@ -32,6 +32,8 @@
#include "uavobject.h"
#include <QStringList>
#include <QVariant>
#include <QList>
#include <QMap>
class UAVObject;
@ -41,9 +43,15 @@ class UAVOBJECTS_EXPORT UAVObjectField: public QObject
public:
typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType;
typedef enum { EQUAL,NOT_EQUAL,BETWEEN,BIGGER,SMALLER } LimitType;
typedef struct
{
LimitType type;
QList<QVariant> values;
} LimitStruct;
UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options);
UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options,const QString& limits=QString::QString());
UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options,const QString& limits=QString::QString());
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj);
UAVObject* getObject();
FieldType getType();
@ -67,6 +75,9 @@ public:
bool isText();
QString toString();
bool isWithinLimits(QVariant var, quint32 index);
QVariant getMaxLimit(quint32 index);
QVariant getMinLimit(quint32 index);
signals:
void fieldUpdated(UAVObjectField* field);
@ -81,9 +92,10 @@ protected:
quint32 offset;
quint8* data;
UAVObject* obj;
QMap<quint32,LimitStruct> elementLimits;
void clear();
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options, const QString &limits);
void limitsInitialize(const QString &limits);
};

View File

@ -127,6 +127,15 @@ UAVDataObject* $(NAME)::clone(quint32 instID)
return obj;
}
/**
* Create a clone of this object only to be used to retrieve defaults
*/
UAVDataObject* $(NAME)::dirtyClone()
{
$(NAME)* obj = new $(NAME)();
return obj;
}
/**
* Static function to retrieve an instance of the object.
*/

View File

@ -65,7 +65,8 @@ $(DATAFIELDINFO)
void setData(const DataFields& data);
Metadata getDefaultMetadata();
UAVDataObject* clone(quint32 instID);
UAVDataObject* dirtyClone();
static $(NAME)* GetInstance(UAVObjectManager* objMngr, quint32 instID = 0);
$(PROPERTY_GETTERS)

View File

@ -6,6 +6,6 @@
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,13 @@
<plugin name="UAVObjectWidgetUtils" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>Utils classes for UAVObjects to Widget relations</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
<dependency name="UAVObjectUtil" version="1.0.0"/>
<dependency name="UAVSettingsImportExport" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,1120 @@
/**
******************************************************************************
*
* @file configtaskwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "configtaskwidget.h"
#include <QtGui/QWidget>
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
/**
* Constructor
*/
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false),outOfLimitsStyle("background-color: rgb(255, 0, 0);")
{
pm = ExtensionSystem::PluginManager::instance();
objManager = pm->getObject<UAVObjectManager>();
TelemetryManager* telMngr = pm->getObject<TelemetryManager>();
connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
connect(telMngr, SIGNAL(connected()), this, SIGNAL(autoPilotConnected()));
connect(telMngr, SIGNAL(disconnected()), this, SIGNAL(autoPilotDisconnected()));
UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(invalidateObjects()));
}
/**
* Add a widget to the dirty detection pool
* @param widget to add to the detection pool
*/
void ConfigTaskWidget::addWidget(QWidget * widget)
{
addUAVObjectToWidgetRelation("","",widget);
}
/**
* Add an object to the management system
* @param objectName name of the object to add to the management system
*/
void ConfigTaskWidget::addUAVObject(QString objectName)
{
addUAVObjectToWidgetRelation(objectName,"",NULL);
}
/**
* Add an UAVObject field to widget relation to the management system
* @param object name of the object to add
* @param field name of the field to add
* @param widget pointer to the widget whitch will display/define the field value
* @param index index of the field element to add to this relation
*/
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, QString index)
{
UAVObject *obj=NULL;
UAVObjectField *_field=NULL;
obj = objManager->getObject(QString(object));
Q_ASSERT(obj);
_field = obj->getField(QString(field));
Q_ASSERT(_field);
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
}
/**
* Add a UAVObject field to widget relation to the management system
* @param object name of the object to add
* @param field name of the field to add
* @param widget pointer to the widget whitch will display/define the field value
* @param element name of the element of the field element to add to this relation
* @param scale scale value of this relation
* @param isLimited bool to signal if this widget contents is limited in value
* @param defaultReloadGroups default and reload groups this relation belongs to
* @param instID instance ID of the object used on this relation
*/
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString element, double scale, bool isLimited, QList<int> *defaultReloadGroups, quint32 instID)
{
UAVObject *obj=objManager->getObject(QString(object),instID);
Q_ASSERT(obj);
UAVObjectField *_field;
int index=0;
if(!field.isEmpty() && obj)
{
_field = obj->getField(QString(field));
if(!element.isEmpty())
index=_field->getElementNames().indexOf(QString(element));
}
addUAVObjectToWidgetRelation(object, field, widget,index,scale,isLimited,defaultReloadGroups,instID);
}
/**
* Add an UAVObject field to widget relation to the management system
* @param object name of the object to add
* @param field name of the field to add
* @param widget pointer to the widget whitch will display/define the field value
* @param index index of the element of the field to add to this relation
* @param scale scale value of this relation
* @param isLimited bool to signal if this widget contents is limited in value
* @param defaultReloadGroups default and reload groups this relation belongs to
* @param instID instance ID of the object used on this relation
*/
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, int index,double scale,bool isLimited,QList<int>* defaultReloadGroups, quint32 instID)
{
if(addShadowWidget(object,field,widget,index,scale,isLimited,defaultReloadGroups,instID))
return;
UAVObject *obj=NULL;
UAVObjectField *_field=NULL;
if(!object.isEmpty())
{
obj = objManager->getObject(QString(object),instID);
Q_ASSERT(obj);
objectUpdates.insert(obj,true);
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this, SLOT(objectUpdated(UAVObject*)));
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
if(!field.isEmpty() && obj)
_field = obj->getField(QString(field));
objectToWidget * ow=new objectToWidget();
ow->field=_field;
ow->object=obj;
ow->widget=widget;
ow->index=index;
ow->scale=scale;
ow->isLimited=isLimited;
objOfInterest.append(ow);
if(obj)
{
if(smartsave)
{
smartsave->addObject((UAVDataObject*)obj);
}
}
if(widget==NULL)
{
// do nothing
}
else
{
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
if(defaultReloadGroups)
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
shadowsList.insert(widget,ow);
loadWidgetLimits(widget,_field,index,isLimited,scale);
}
}
/**
* destructor
*/
ConfigTaskWidget::~ConfigTaskWidget()
{
if(smartsave)
delete smartsave;
foreach(QList<objectToWidget*>* pointer,defaultReloadGroups.values())
{
if(pointer)
delete pointer;
}
foreach (objectToWidget* oTw, objOfInterest)
{
if(oTw)
delete oTw;
}
}
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
{
// saveObjectToSD is now handled by the UAVUtils plugin in one
// central place (and one central queue)
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectUtilManager* utilMngr = pm->getObject<UAVObjectUtilManager>();
utilMngr->saveObjectToSD(obj);
}
/**
* Util function to get a pointer to the object manager
* @return pointer to the UAVObjectManager
*/
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
Q_ASSERT(objMngr);
return objMngr;
}
/**
* Utility function which calculates the Mean value of a list of values
* @param list list of double values
* @returns Mean value of the list of parameter values
*/
double ConfigTaskWidget::listMean(QList<double> list)
{
double accum = 0;
for(int i = 0; i < list.size(); i++)
accum += list[i];
return accum / list.size();
}
// ************************************
// telemetry start/stop connect/disconnect signals
void ConfigTaskWidget::onAutopilotDisconnect()
{
isConnected=false;
enableControls(false);
invalidateObjects();
}
void ConfigTaskWidget::onAutopilotConnect()
{
invalidateObjects();
dirty=false;
isConnected=true;
enableControls(true);
refreshWidgetsValues();
}
/**
* SLOT Function used to populate the widgets with the initial values
* Overwrite this if you need to change the default behavior
*/
void ConfigTaskWidget::populateWidgets()
{
bool dirtyBack=dirty;
emit populateWidgetsRequested();
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
{
// do nothing
}
else
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
}
setDirty(dirtyBack);
}
/**
* SLOT function used to refresh the widgets contents of the widgets with relation to
* object field added to the framework pool
* Overwrite this if you need to change the default behavior
*/
void ConfigTaskWidget::refreshWidgetsValues()
{
bool dirtyBack=dirty;
emit refreshWidgetsValuesRequested();
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
{
//do nothing
}
else
{
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
}
}
setDirty(dirtyBack);
}
/**
* SLOT function used to update the uavobject fields from widgets with relation to
* object field added to the framework pool
* Overwrite this if you need to change the default behavior
*/
void ConfigTaskWidget::updateObjectsFromWidgets()
{
emit updateObjectsFromWidgetsRequested();
foreach(objectToWidget * ow,objOfInterest)
{
if(ow->object==NULL || ow->field==NULL)
{
}
else
setFieldFromWidget(ow->widget,ow->field,ow->index,ow->scale);
}
}
/**
* SLOT function used handle help button presses
* Overwrite this if you need to change the default behavior
*/
void ConfigTaskWidget::helpButtonPressed()
{
QString url=helpButtonList.value((QPushButton*)sender(),QString::QString());
if(!url.isEmpty())
QDesktopServices::openUrl( QUrl(url, QUrl::StrictMode) );
}
/**
* Add update and save buttons to the form
* multiple buttons can be added for the same function
* @param update pointer to the update button
* @param save pointer to the save button
*/
void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save)
{
if(!smartsave)
{
smartsave=new smartSaveButton();
connect(smartsave,SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
connect(smartsave,SIGNAL(saveSuccessfull()),this,SLOT(clearDirty()));
connect(smartsave,SIGNAL(beginOp()),this,SLOT(disableObjUpdates()));
connect(smartsave,SIGNAL(endOp()),this,SLOT(enableObjUpdates()));
}
if(update && save)
smartsave->addButtons(save,update);
else if (update)
smartsave->addApplyButton(update);
else if (save)
smartsave->addSaveButton(save);
if(objOfInterest.count()>0)
{
foreach(objectToWidget * oTw,objOfInterest)
{
smartsave->addObject((UAVDataObject*)oTw->object);
}
}
TelemetryManager* telMngr = pm->getObject<TelemetryManager>();
if(telMngr->isConnected())
enableControls(true);
else
enableControls(false);
}
/**
* SLOT function used the enable or disable the SAVE, UPLOAD and RELOAD buttons
* @param enable set to true to enable the buttons or false to disable them
* @param field name of the field to add
*/
void ConfigTaskWidget::enableControls(bool enable)
{
if(smartsave)
smartsave->enableControls(enable);
foreach (QPushButton * button, reloadButtonList) {
button->setEnabled(enable);
}
}
/**
* SLOT function called when on of the widgets contents added to the framework changes
*/
void ConfigTaskWidget::widgetsContentsChanged()
{
emit widgetContentsChanged((QWidget*)sender());
double scale;
objectToWidget * oTw= shadowsList.value((QWidget*)sender(),NULL);
if(oTw)
{
if(oTw->widget==(QWidget*)sender())
{
scale=oTw->scale;
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),oTw->scale),oTw->scale);
}
else
{
foreach (shadow * sh, oTw->shadowsList)
{
if(sh->widget==(QWidget*)sender())
{
scale=sh->scale;
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),scale);
}
}
}
if(oTw->widget!=(QWidget *)sender())
{
disconnectWidgetUpdatesToSlot((QWidget*)oTw->widget,SLOT(widgetsContentsChanged()));
checkWidgetsLimits(oTw->widget,oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
setWidgetFromVariant(oTw->widget,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
emit widgetContentsChanged((QWidget*)oTw->widget);
connectWidgetUpdatesToSlot((QWidget*)oTw->widget,SLOT(widgetsContentsChanged()));
}
foreach (shadow * sh, oTw->shadowsList)
{
if(sh->widget!=(QWidget*)sender())
{
disconnectWidgetUpdatesToSlot((QWidget*)sh->widget,SLOT(widgetsContentsChanged()));
checkWidgetsLimits(sh->widget,oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),sh->scale);
setWidgetFromVariant(sh->widget,getVariantFromWidget((QWidget*)sender(),scale),sh->scale);
emit widgetContentsChanged((QWidget*)sh->widget);
connectWidgetUpdatesToSlot((QWidget*)sh->widget,SLOT(widgetsContentsChanged()));
}
}
}
setDirty(true);
}
/**
* SLOT function used clear the forms dirty status flag
*/
void ConfigTaskWidget::clearDirty()
{
setDirty(false);
}
/**
* Sets the form's dirty status flag
* @param value
*/
void ConfigTaskWidget::setDirty(bool value)
{
dirty=value;
}
/**
* Checks if the form is dirty (unsaved changes)
* @return true if the form has unsaved changes
*/
bool ConfigTaskWidget::isDirty()
{
if(isConnected)
return dirty;
else
return false;
}
/**
* SLOT function used to disable widget contents changes when related object field changes
*/
void ConfigTaskWidget::disableObjUpdates()
{
foreach(objectToWidget * obj,objOfInterest)
{
if(obj->object)
disconnect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
}
/**
* SLOT function used to enable widget contents changes when related object field changes
*/
void ConfigTaskWidget::enableObjUpdates()
{
foreach(objectToWidget * obj,objOfInterest)
{
if(obj->object)
connect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
}
/**
* Called when an uav object is updated
* @param obj pointer to the object whitch has just been updated
*/
void ConfigTaskWidget::objectUpdated(UAVObject *obj)
{
objectUpdates[obj]=true;
}
/**
* Checks if all objects added to the pool have already been updated
* @return true if all objects added to the pool have already been updated
*/
bool ConfigTaskWidget::allObjectsUpdated()
{
bool ret=true;
foreach(UAVObject *obj, objectUpdates.keys())
{
ret=ret & objectUpdates[obj];
}
return ret;
}
/**
* Adds a new help button
* @param button pointer to the help button
* @param url url to open in the browser when the help button is pressed
*/
void ConfigTaskWidget::addHelpButton(QPushButton *button, QString url)
{
helpButtonList.insert(button,url);
connect(button,SIGNAL(clicked()),this,SLOT(helpButtonPressed()));
}
/**
* Invalidates all the uav objects "is updated" flag
*/
void ConfigTaskWidget::invalidateObjects()
{
foreach(UAVObject *obj, objectUpdates.keys())
{
objectUpdates[obj]=false;
}
}
/**
* SLOT call this to apply changes to uav objects
*/
void ConfigTaskWidget::apply()
{
if(smartsave)
smartsave->apply();
}
/**
* SLOT call this to save changes to uav objects
*/
void ConfigTaskWidget::save()
{
if(smartsave)
smartsave->save();
}
/**
* Adds a new shadow widget
* shadow widgets are widgets whitch have a relation to an object already present on the framework pool i.e. already added trough addUAVObjectToWidgetRelation
* This function doesn't have to be used directly, addUAVObjectToWidgetRelation will call it if a previous relation exhists.
* @return returns false if the shadow widget relation failed to be added (no previous relation exhisted)
*/
bool ConfigTaskWidget::addShadowWidget(QString object, QString field, QWidget *widget, int index, double scale, bool isLimited,QList<int>* defaultReloadGroups,quint32 instID)
{
foreach(objectToWidget * oTw,objOfInterest)
{
if(!oTw->object || !oTw->widget)
continue;
if(oTw->object->getName()==object && oTw->field->getName()==field && oTw->index==index && oTw->object->getInstID()==instID)
{
shadow * sh=NULL;
//prefer anything else to QLabel
if(qobject_cast<QLabel *>(oTw->widget) && !qobject_cast<QLabel *>(widget))
{
sh=new shadow;
sh->isLimited=oTw->isLimited;
sh->scale=oTw->scale;
sh->widget=oTw->widget;
oTw->isLimited=isLimited;
oTw->scale=scale;
oTw->widget=widget;
}
//prefer QDoubleSpinBox to anything else
else if(!qobject_cast<QDoubleSpinBox *>(oTw->widget) && qobject_cast<QDoubleSpinBox *>(widget))
{
sh=new shadow;
sh->isLimited=oTw->isLimited;
sh->scale=oTw->scale;
sh->widget=oTw->widget;
oTw->isLimited=isLimited;
oTw->scale=scale;
oTw->widget=widget;
}
else
{
sh=new shadow;
sh->isLimited=isLimited;
sh->scale=scale;
sh->widget=widget;
}
shadowsList.insert(widget,oTw);
oTw->shadowsList.append(sh);
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
if(defaultReloadGroups)
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
loadWidgetLimits(widget,oTw->field,oTw->index,isLimited,scale);
return true;
}
}
return false;
}
/**
* Auto loads widgets based on the Dynamic property named "objrelation"
* Check the wiki for more information
*/
void ConfigTaskWidget::autoLoadWidgets()
{
QPushButton * saveButtonWidget=NULL;
QPushButton * applyButtonWidget=NULL;
foreach(QWidget * widget,this->findChildren<QWidget*>())
{
QVariant info=widget->property("objrelation");
if(info.isValid())
{
uiRelationAutomation uiRelation;
uiRelation.buttonType=none;
uiRelation.scale=1;
uiRelation.element=QString();
uiRelation.haslimits=false;
foreach(QString str, info.toStringList())
{
QString prop=str.split(":").at(0);
QString value=str.split(":").at(1);
if(prop== "objname")
uiRelation.objname=value;
else if(prop== "fieldname")
uiRelation.fieldname=value;
else if(prop=="element")
uiRelation.element=value;
else if(prop== "scale")
{
if(value=="null")
uiRelation.scale=1;
else
uiRelation.scale=value.toDouble();
}
else if(prop== "haslimits")
{
if(value=="yes")
uiRelation.haslimits=true;
else
uiRelation.haslimits=false;
}
else if(prop== "button")
{
if(value=="save")
uiRelation.buttonType=save_button;
else if(value=="apply")
uiRelation.buttonType=apply_button;
else if(value=="reload")
uiRelation.buttonType=reload_button;
else if(value=="default")
uiRelation.buttonType=default_button;
else if(value=="help")
uiRelation.buttonType=help_button;
}
else if(prop== "buttongroup")
{
foreach(QString s,value.split(","))
{
uiRelation.buttonGroup.append(s.toInt());
}
}
else if(prop=="url")
uiRelation.url=str.mid(str.indexOf(":")+1);
}
if(!uiRelation.buttonType==none)
{
QPushButton * button=NULL;
switch(uiRelation.buttonType)
{
case save_button:
saveButtonWidget=qobject_cast<QPushButton *>(widget);
if(saveButtonWidget)
addApplySaveButtons(NULL,saveButtonWidget);
break;
case apply_button:
applyButtonWidget=qobject_cast<QPushButton *>(widget);
if(applyButtonWidget)
addApplySaveButtons(applyButtonWidget,NULL);
break;
case default_button:
button=qobject_cast<QPushButton *>(widget);
if(button)
addDefaultButton(button,uiRelation.buttonGroup.at(0));
break;
case reload_button:
button=qobject_cast<QPushButton *>(widget);
if(button)
addReloadButton(button,uiRelation.buttonGroup.at(0));
break;
case help_button:
button=qobject_cast<QPushButton *>(widget);
if(button)
addHelpButton(button,uiRelation.url);
break;
default:
break;
}
}
else
{
QWidget * wid=qobject_cast<QWidget *>(widget);
if(wid)
addUAVObjectToWidgetRelation(uiRelation.objname,uiRelation.fieldname,wid,uiRelation.element,uiRelation.scale,uiRelation.haslimits,&uiRelation.buttonGroup);
}
}
}
refreshWidgetsValues();
}
/**
* Adds a widget to a list of default/reload groups
* default/reload groups are groups of widgets to be set with default or reloaded (values from persistent memory) when a defined button is pressed
* @param widget pointer to the widget to be added to the groups
* @param groups list of the groups on which to add the widget
*/
void ConfigTaskWidget::addWidgetToDefaultReloadGroups(QWidget *widget, QList<int> * groups)
{
foreach(objectToWidget * oTw,objOfInterest)
{
bool addOTW=false;
if(oTw->widget==widget)
addOTW=true;
else
{
foreach(shadow * sh, oTw->shadowsList)
{
if(sh->widget==widget)
addOTW=true;
}
}
if(addOTW)
{
foreach(int i,*groups)
{
if(defaultReloadGroups.contains(i))
{
defaultReloadGroups.value(i)->append(oTw);
}
else
{
defaultReloadGroups.insert(i,new QList<objectToWidget*>());
defaultReloadGroups.value(i)->append(oTw);
}
}
}
}
}
/**
* Adds a button to a default group
* @param button pointer to the default button
* @param buttongroup number of the group
*/
void ConfigTaskWidget::addDefaultButton(QPushButton *button, int buttonGroup)
{
button->setProperty("group",buttonGroup);
connect(button,SIGNAL(clicked()),this,SLOT(defaultButtonClicked()));
}
/**
* Adds a button to a reload group
* @param button pointer to the reload button
* @param buttongroup number of the group
*/
void ConfigTaskWidget::addReloadButton(QPushButton *button, int buttonGroup)
{
button->setProperty("group",buttonGroup);
reloadButtonList.append(button);
connect(button,SIGNAL(clicked()),this,SLOT(reloadButtonClicked()));
}
/**
* Called when a default button is clicked
*/
void ConfigTaskWidget::defaultButtonClicked()
{
int group=sender()->property("group").toInt();
QList<objectToWidget*> * list=defaultReloadGroups.value(group);
foreach(objectToWidget * oTw,*list)
{
if(!oTw->object)
continue;
UAVDataObject * temp=((UAVDataObject*)oTw->object)->dirtyClone();
setWidgetFromField(oTw->widget,temp->getField(oTw->field->getName()),oTw->index,oTw->scale,oTw->isLimited);
}
}
/**
* Called when a reload button is clicked
*/
void ConfigTaskWidget::reloadButtonClicked()
{
int group=sender()->property("group").toInt();
QList<objectToWidget*> * list=defaultReloadGroups.value(group,NULL);
if(!list)
return;
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
QTimer * timeOut=new QTimer(this);
QEventLoop * eventLoop=new QEventLoop(this);
connect(timeOut, SIGNAL(timeout()),eventLoop,SLOT(quit()));
connect(objper, SIGNAL(objectUpdated(UAVObject*)), eventLoop, SLOT(quit()));
foreach(objectToWidget * oTw,*list)
{
if (oTw->object != NULL)
{
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_LOAD;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = oTw->object->getObjID();
data.InstanceID = oTw->object->getInstID();
objper->setData(data);
objper->updated();
timeOut->start(500);
eventLoop->exec();
if(timeOut->isActive())
{
setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited);
}
timeOut->stop();
}
}
delete eventLoop;
delete timeOut;
}
/**
* Connects widgets "contents changed" signals to a slot
*/
void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget * widget,const char* function)
{
if(!widget)
return;
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
connect(cb,SIGNAL(currentIndexChanged(int)),this,function);
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
connect(cb,SIGNAL(valueChanged(int)),this,function);
}
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
{
connect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,function);
}
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
{
connect(cb,SIGNAL(cellChanged(int,int)),this,function);
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
connect(cb,SIGNAL(valueChanged(int)),this,function);
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
connect(cb,SIGNAL(valueChanged(double)),this,function);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
{
connect(cb,SIGNAL(stateChanged(int)),this,function);
}
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
{
connect(cb,SIGNAL(clicked()),this,function);
}
else
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
}
/**
* Disconnects widgets "contents changed" signals to a slot
*/
void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget * widget,const char* function)
{
if(!widget)
return;
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
disconnect(cb,SIGNAL(currentIndexChanged(int)),this,function);
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
disconnect(cb,SIGNAL(valueChanged(int)),this,function);
}
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
{
disconnect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,function);
}
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
{
disconnect(cb,SIGNAL(cellChanged(int,int)),this,function);
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
disconnect(cb,SIGNAL(valueChanged(int)),this,function);
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
disconnect(cb,SIGNAL(valueChanged(double)),this,function);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
{
disconnect(cb,SIGNAL(stateChanged(int)),this,function);
}
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
{
disconnect(cb,SIGNAL(clicked()),this,function);
}
else
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
}
/**
* Sets a widget value from an UAVObject field
* @param widget pointer for the widget to set
* @param field pointer to the UAVObject field to use
* @param index index of the element to use
* @param scale scale to be used on the assignement
* @return returns true if the assignement was successfull
*/
bool ConfigTaskWidget::setFieldFromWidget(QWidget * widget,UAVObjectField * field,int index,double scale)
{
if(!widget || !field)
return false;
QVariant ret=getVariantFromWidget(widget,scale);
if(ret.isValid())
{
field->setValue(ret,index);
return true;
}
{
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
return false;
}
}
/**
* Gets a variant from a widget
* @param widget pointer to the widget from where to get the value
* @param scale scale to be used on the assignement
* @return returns the value of the widget times the scale
*/
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget * widget,double scale)
{
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
return (QString)cb->currentText();
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
return (double)(cb->value()* scale);
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
return (double)(cb->value()* scale);
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
return(double)(cb->value()* scale);
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
{
return (QString)(cb->isChecked()?"TRUE":"FALSE");
}
else
return QVariant();
}
/**
* Sets a widget from a variant
* @param widget pointer for the widget to set
* @param scale scale to be used on the assignement
* @param value value to be used on the assignement
* @return returns true if the assignement was successfull
*/
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale)
{
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
cb->setCurrentIndex(cb->findText(value.toString()));
return true;
}
else if(QLabel * cb=qobject_cast<QLabel *>(widget))
{
if(scale==0)
cb->setText(value.toString());
else
cb->setText(QString::number((value.toDouble()/scale)));
return true;
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
cb->setValue((double)(value.toDouble()/scale));
return true;
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
cb->setValue((int)qRound(value.toDouble()/scale));
return true;
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
cb->setValue((int)qRound(value.toDouble()/scale));
return true;
}
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
{
bool bvalue=value.toString()=="TRUE";
cb->setChecked(bvalue);
return true;
}
else
return false;
}
/**
* Sets a widget from a UAVObject field
* @param widget pointer to the widget to set
* @param field pointer to the field from where to get the value from
* @param index index of the element to use
* @param scale scale to be used on the assignement
* @param hasLimits set to true if you want to limit the values (check wiki)
* @return returns true if the assignement was successfull
*/
bool ConfigTaskWidget::setWidgetFromField(QWidget * widget,UAVObjectField * field,int index,double scale,bool hasLimits)
{
if(!widget || !field)
return false;
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
if(cb->count()==0)
loadWidgetLimits(cb,field,index,hasLimits,scale);
}
QVariant var=field->getValue(index);
checkWidgetsLimits(widget,field,index,hasLimits,var,scale);
bool ret=setWidgetFromVariant(widget,var,scale);
if(ret)
return true;
else
{
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
return false;
}
}
void ConfigTaskWidget::checkWidgetsLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits, QVariant value, double scale)
{
if(!hasLimits)
return;
if(!field->isWithinLimits(value,index))
{
if(!widget->property("styleBackup").isValid())
widget->setProperty("styleBackup",widget->styleSheet());
widget->setStyleSheet(outOfLimitsStyle);
widget->setProperty("wasOverLimits",(bool)true);
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
if(cb->findText(value.toString())==-1)
cb->addItem(value.toString());
}
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
if((double)(value.toDouble()/scale)>cb->maximum())
{
cb->setMaximum((double)(value.toDouble()/scale));
}
else if((double)(value.toDouble()/scale)<cb->minimum())
{
cb->setMinimum((double)(value.toDouble()/scale));
}
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
if((int)qRound(value.toDouble()/scale)>cb->maximum())
{
cb->setMaximum((int)qRound(value.toDouble()/scale));
}
else if((int)qRound(value.toDouble()/scale)<cb->minimum())
{
cb->setMinimum((int)qRound(value.toDouble()/scale));
}
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
if((int)qRound(value.toDouble()/scale)>cb->maximum())
{
cb->setMaximum((int)qRound(value.toDouble()/scale));
}
else if((int)qRound(value.toDouble()/scale)<cb->minimum())
{
cb->setMinimum((int)qRound(value.toDouble()/scale));
}
}
}
else if(widget->property("wasOverLimits").isValid())
{
if(widget->property("wasOverLimits").toBool())
{
widget->setProperty("wasOverLimits",(bool)false);
if(widget->property("styleBackup").isValid())
{
QString style=widget->property("styleBackup").toString();
widget->setStyleSheet(style);
}
loadWidgetLimits(widget,field,index,hasLimits,scale);
}
}
}
void ConfigTaskWidget::loadWidgetLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits,double scale)
{
if(!widget || !field)
return;
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
{
cb->clear();
QStringList option=field->getOptions();
if(hasLimits)
{
foreach(QString str,option)
{
if(field->isWithinLimits(str,index))
cb->addItem(str);
}
}
else
cb->addItems(option);
}
if(!hasLimits)
return;
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
{
if(field->getMaxLimit(index).isValid())
{
cb->setMaximum((double)(field->getMaxLimit(index).toDouble()/scale));
}
if(field->getMinLimit(index).isValid())
{
cb->setMinimum((double)(field->getMinLimit(index).toDouble()/scale));
}
}
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
{
if(field->getMaxLimit(index).isValid())
{
cb->setMaximum((int)qRound(field->getMaxLimit(index).toDouble()/scale));
}
if(field->getMinLimit(index).isValid())
{
cb->setMinimum((int)qRound(field->getMinLimit(index).toDouble()/scale));
}
}
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
{
if(field->getMaxLimit(index).isValid())
{
cb->setMaximum((int)qRound(field->getMaxLimit(index).toDouble()/scale));
}
if(field->getMinLimit(index).isValid())
{
cb->setMinimum((int)(field->getMinLimit(index).toDouble()/scale));
}
}
}
/**
@}
@}
*/

View File

@ -0,0 +1,176 @@
/**
******************************************************************************
*
* @file configtaskwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONFIGTASKWIDGET_H
#define CONFIGTASKWIDGET_H
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "uavobjectutilmanager.h"
#include <QQueue>
#include <QtGui/QWidget>
#include <QList>
#include <QLabel>
#include "smartsavebutton.h"
#include "mixercurvewidget.h"
#include <QTableWidget>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QPushButton>
#include "uavobjectwidgetutils_global.h"
#include <QDesktopServices>
#include <QUrl>
class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget: public QWidget
{
Q_OBJECT
public:
struct shadow
{
QWidget * widget;
double scale;
bool isLimited;
};
struct objectToWidget
{
UAVObject * object;
UAVObjectField * field;
QWidget * widget;
int index;
double scale;
bool isLimited;
QList<shadow *> shadowsList;
};
enum buttonTypeEnum {none,save_button,apply_button,reload_button,default_button,help_button};
struct uiRelationAutomation
{
QString objname;
QString fieldname;
QString element;
QString url;
double scale;
bool haslimits;
buttonTypeEnum buttonType;
QList<int> buttonGroup;
};
ConfigTaskWidget(QWidget *parent = 0);
~ConfigTaskWidget();
void saveObjectToSD(UAVObject *obj);
UAVObjectManager* getObjectManager();
static double listMean(QList<double> list);
void addUAVObject(QString objectName);
void addWidget(QWidget * widget);
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,double scale=1,bool isLimited=false,QList<int>* defaultReloadGroups=0,quint32 instID=0);
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,QString element,double scale,bool isLimited=false,QList<int>* defaultReloadGroups=0,quint32 instID=0);
void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index);
//BUTTONS//
void addApplySaveButtons(QPushButton * update,QPushButton * save);
void addReloadButton(QPushButton * button,int buttonGroup);
void addDefaultButton(QPushButton * button,int buttonGroup);
//////////
void addWidgetToDefaultReloadGroups(QWidget * widget, QList<int> *groups);
bool addShadowWidget(QWidget * masterWidget, QWidget * shadowWidget,double shadowScale=1,bool shadowIsLimited=false);
bool addShadowWidget(QString object,QString field,QWidget * widget,int index=0,double scale=1,bool isLimited=false, QList<int> *defaultReloadGroups=NULL, quint32 instID=0);
void autoLoadWidgets();
bool isDirty();
void setDirty(bool value);
bool allObjectsUpdated();
void setOutOfLimitsStyle(QString style){outOfLimitsStyle=style;}
void addHelpButton(QPushButton * button,QString url);
public slots:
void onAutopilotDisconnect();
void onAutopilotConnect();
void invalidateObjects();
void apply();
void save();
signals:
//fired when a widgets contents changes
void widgetContentsChanged(QWidget * widget);
//fired when the framework requests that the widgets values be populated, use for custom behaviour
void populateWidgetsRequested();
//fired when the framework requests that the widgets values be refreshed, use for custom behaviour
void refreshWidgetsValuesRequested();
//fired when the framework requests that the UAVObject values be updated from the widgets value, use for custom behaviour
void updateObjectsFromWidgetsRequested();
//fired when the autopilot connects
void autoPilotConnected();
//fired when the autopilot disconnects
void autoPilotDisconnected();
private slots:
void objectUpdated(UAVObject*);
void defaultButtonClicked();
void reloadButtonClicked();
private:
bool isConnected;
QStringList objectsList;
QList <objectToWidget*> objOfInterest;
ExtensionSystem::PluginManager *pm;
UAVObjectManager *objManager;
smartSaveButton *smartsave;
QMap<UAVObject *,bool> objectUpdates;
QMap<int,QList<objectToWidget*> *> defaultReloadGroups;
QMap<QWidget *,objectToWidget*> shadowsList;
QMap<QPushButton *,QString> helpButtonList;
QList<QPushButton *> reloadButtonList;
bool dirty;
bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale);
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits);
QVariant getVariantFromWidget(QWidget *widget, double scale);
bool setWidgetFromVariant(QWidget *widget,QVariant value,double scale);
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, double sclale);
QString outOfLimitsStyle;
protected slots:
virtual void disableObjUpdates();
virtual void enableObjUpdates();
virtual void clearDirty();
virtual void widgetsContentsChanged();
virtual void populateWidgets();
virtual void refreshWidgetsValues();
virtual void updateObjectsFromWidgets();
virtual void helpButtonPressed();
protected:
virtual void enableControls(bool enable);
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
};
#endif // CONFIGTASKWIDGET_H

View File

@ -2,13 +2,12 @@
******************************************************************************
*
* @file mixercurveline.h
* @author Edouard Lafargue Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Configuration Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A line connecting two mixer points
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify

View File

@ -2,13 +2,12 @@
******************************************************************************
*
* @file mixercurveline.h
* @author Edouard Lafargue Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Configuration Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A line connecting two mixer points
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify

View File

@ -2,13 +2,12 @@
******************************************************************************
*
* @file mixercurvepoint.h
* @author Edouard Lafargue Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Configuration Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A point on the mixer curve
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify

View File

@ -2,13 +2,12 @@
******************************************************************************
*
* @file mixercurvepoint.h
* @author Edouard Lafargue Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Configuration Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A point on the mixer curve
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify

View File

@ -2,12 +2,12 @@
******************************************************************************
*
* @file mixercurvewidget.cpp
* @author Edouard Lafargue Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Config Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A widget which displays an adjustable mixer curve
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify

View File

@ -2,12 +2,12 @@
******************************************************************************
*
* @file mixercurvewidget.h
* @author Edouard Lafargue Copyright (C) 2010.
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Configuration Plugin
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief A widget which displays a mixer curve
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
@ -33,9 +33,9 @@
#include <QtSvg/QGraphicsSvgItem>
#include "mixercurvepoint.h"
#include "mixercurveline.h"
#include "uavobjectwidgetutils_global.h"
class MixerCurveWidget : public QGraphicsView
class UAVOBJECTWIDGETUTILS_EXPORT MixerCurveWidget : public QGraphicsView
{
Q_OBJECT

View File

@ -1,24 +1,74 @@
/**
******************************************************************************
*
* @file smartsavebutton.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "smartsavebutton.h"
smartSaveButton::smartSaveButton(QPushButton * update, QPushButton * save):bupdate(update),bsave(save)
smartSaveButton::smartSaveButton()
{
connect(bsave,SIGNAL(clicked()),this,SLOT(processClick()));
connect(bupdate,SIGNAL(clicked()),this,SLOT(processClick()));
}
void smartSaveButton::addButtons(QPushButton *save, QPushButton *apply)
{
buttonList.insert(save,save_button);
buttonList.insert(apply,apply_button);
connect(save,SIGNAL(clicked()),this,SLOT(processClick()));
connect(apply,SIGNAL(clicked()),this,SLOT(processClick()));
}
void smartSaveButton::addApplyButton(QPushButton *apply)
{
buttonList.insert(apply,apply_button);
connect(apply,SIGNAL(clicked()),this,SLOT(processClick()));
}
void smartSaveButton::addSaveButton(QPushButton *save)
{
buttonList.insert(save,save_button);
connect(save,SIGNAL(clicked()),this,SLOT(processClick()));
}
void smartSaveButton::processClick()
{
emit beginOp();
bool save=false;
QPushButton *button=bupdate;
if(sender()==bsave)
{
QPushButton *button=qobject_cast<QPushButton *>(sender());
if(!button)
return;
if(buttonList.value(button)==save_button)
save=true;
button=bsave;
}
processOperation(button,save);
}
void smartSaveButton::processOperation(QPushButton * button,bool save)
{
emit preProcessOperations();
button->setEnabled(false);
button->setIcon(QIcon(":/uploader/images/system-run.svg"));
if(button)
{
button->setEnabled(false);
button->setIcon(QIcon(":/uploader/images/system-run.svg"));
}
QTimer timer;
timer.setSingleShot(true);
bool error=false;
@ -78,15 +128,18 @@ void smartSaveButton::processClick()
}
}
}
button->setEnabled(true);
if(button)
button->setEnabled(true);
if(!error)
{
button->setIcon(QIcon(":/uploader/images/dialog-apply.svg"));
if(button)
button->setIcon(QIcon(":/uploader/images/dialog-apply.svg"));
emit saveSuccessfull();
}
else
{
button->setIcon(QIcon(":/uploader/images/process-stop.svg"));
if(button)
button->setIcon(QIcon(":/uploader/images/process-stop.svg"));
}
emit endOp();
}
@ -101,7 +154,15 @@ void smartSaveButton::addObject(UAVDataObject * obj)
if(!objects.contains(obj))
objects.append(obj);
}
void smartSaveButton::removeObject(UAVDataObject * obj)
{
if(objects.contains(obj))
objects.removeAll(obj);
}
void smartSaveButton::removeAllObjects()
{
objects.clear();
}
void smartSaveButton::clearObjects()
{
objects.clear();
@ -127,6 +188,18 @@ void smartSaveButton::saving_finished(int id, bool result)
void smartSaveButton::enableControls(bool value)
{
bupdate->setEnabled(value);
bsave->setEnabled(value);
foreach(QPushButton * button,buttonList.keys())
button->setEnabled(value);
}
void smartSaveButton::apply()
{
processOperation(NULL,false);
}
void smartSaveButton::save()
{
processOperation(NULL,true);
}

View File

@ -0,0 +1,84 @@
/**
******************************************************************************
*
* @file smartsavebutton.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SMARTSAVEBUTTON_H
#define SMARTSAVEBUTTON_H
#include "uavtalk/telemetrymanager.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QPushButton>
#include <QList>
#include <QEventLoop>
#include "uavobjectutilmanager.h"
#include <QObject>
#include <QDebug>
class smartSaveButton:public QObject
{
enum buttonTypeEnum {save_button,apply_button};
public:
Q_OBJECT
public:
smartSaveButton();
void addButtons(QPushButton * save,QPushButton * apply);
void setObjects(QList<UAVDataObject *>);
void addObject(UAVDataObject *);
void clearObjects();
void removeObject(UAVDataObject *obj);
void removeAllObjects();
void addApplyButton(QPushButton *apply);
void addSaveButton(QPushButton *save);
signals:
void preProcessOperations();
void saveSuccessfull();
void beginOp();
void endOp();
public slots:
void apply();
void save();
private slots:
void processClick();
void processOperation(QPushButton *button, bool save);
void transaction_finished(UAVObject* obj, bool result);
void saving_finished(int,bool);
private:
quint32 current_objectID;
UAVDataObject * current_object;
bool up_result;
bool sv_result;
QEventLoop loop;
QList<UAVDataObject *> objects;
QMap<QPushButton *,buttonTypeEnum> buttonList;
protected:
public slots:
void enableControls(bool value);
};
#endif // SMARTSAVEBUTTON_H

View File

@ -0,0 +1,6 @@
include(uavobjectwidgetutils_dependencies.pri)
# Add the include path to the built-in uavobject include files.
INCLUDEPATH += $$PWD
LIBS *= -l$$qtLibraryName(UAVObjectWidgetUtils)

View File

@ -0,0 +1,22 @@
TEMPLATE = lib
TARGET = UAVObjectWidgetUtils
DEFINES += UAVOBJECTWIDGETUTILS_LIBRARY
QT += svg
include(../../openpilotgcsplugin.pri)
include(uavobjectwidgetutils_dependencies.pri)
HEADERS += uavobjectwidgetutils_global.h \
uavobjectwidgetutilsplugin.h \
configtaskwidget.h \
mixercurvewidget.h \
mixercurvepoint.h \
mixercurveline.h \
smartsavebutton.h
SOURCES += uavobjectwidgetutilsplugin.cpp \
configtaskwidget.cpp \
mixercurvewidget.cpp \
mixercurvepoint.cpp \
mixercurveline.cpp \
smartsavebutton.cpp
OTHER_FILES += UAVObjectWidgetUtils.pluginspec

View File

@ -0,0 +1,6 @@
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/utils/utils.pri)
include(../../plugins/uavobjects/uavobjects.pri)
include(../uavobjectutil/uavobjectutil.pri)
include(../uavsettingsimportexport/uavsettingsimportexport.pri)
include(../uavtalk/uavtalk.pri)

View File

@ -0,0 +1,39 @@
/**
******************************************************************************
*
* @file uavobjectwidgetutils_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UAVOBJECTWIDGETUTILS_GLOBAL_H
#define UAVOBJECTWIDGETUTILS_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(UAVOBJECTWIDGETUTILS_LIBRARY)
# define UAVOBJECTWIDGETUTILS_EXPORT Q_DECL_EXPORT
#else
# define UAVOBJECTWIDGETUTILS_EXPORT Q_DECL_IMPORT
#endif
#endif

View File

@ -0,0 +1,54 @@
/**
******************************************************************************
*
* @file uavobjectutilplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uavobjectwidgetutilsplugin.h"
UAVObjectWidgetUtilsPlugin::UAVObjectWidgetUtilsPlugin()
{
}
UAVObjectWidgetUtilsPlugin::~UAVObjectWidgetUtilsPlugin()
{
}
void UAVObjectWidgetUtilsPlugin::extensionsInitialized()
{
}
bool UAVObjectWidgetUtilsPlugin::initialize(const QStringList & arguments, QString * errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
return true;
}
void UAVObjectWidgetUtilsPlugin::shutdown()
{
}
Q_EXPORT_PLUGIN(UAVObjectWidgetUtilsPlugin)

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file uavobjectwidgetutilsplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectWidgetUtils Plugin
* @{
* @brief Utility plugin for UAVObject to Widget relation management
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UAVOBJECTWIDGETUTILSPLUGIN_H
#define UAVOBJECTWIDGETUTILSPLUGIN_H
#include "uavobjectwidgetutils_global.h"
#include <extensionsystem/iplugin.h>
#include <QtPlugin>
class UAVOBJECTWIDGETUTILS_EXPORT UAVObjectWidgetUtilsPlugin: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
UAVObjectWidgetUtilsPlugin();
~UAVObjectWidgetUtilsPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif

View File

@ -224,19 +224,21 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo* info)
.arg(varOptionName)
.arg(options[m]) );
}
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::ENUM, %3, %4) );\n")
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::ENUM, %3, %4, QString(\"%5\")));\n")
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(varElemName)
.arg(varOptionName) );
.arg(varOptionName)
.arg(info->fields[n]->limitValues));
}
// For all other types
else {
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::%3, %4, QStringList()) );\n")
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::%3, %4, QStringList(), QString(\"%5\")));\n")
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(fieldTypeStrCPPClass[info->fields[n]->type])
.arg(varElemName) );
.arg(varElemName)
.arg(info->fields[n]->limitValues));
}
}
outCode.replace(QString("$(FIELDSINIT)"), finit);

View File

@ -469,6 +469,13 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
}
field->defaultValues = defaults;
}
elemAttr = elemAttributes.namedItem("limits");
if ( elemAttr.isNull() ) {
field->limitValues=QString();
}
else{
field->limitValues=elemAttr.nodeValue();
}
// Add field to object
info->fields.append(field);
// Done

View File

@ -52,11 +52,12 @@ typedef struct {
QString units;
FieldType type;
int numElements;
int numBytes;
int numBytes;
QStringList elementNames;
QStringList options; // for enums only
bool defaultElementNames;
QStringList defaultValues;
QString limitValues;
} FieldInfo;
/**
@ -69,13 +70,13 @@ typedef enum {
UPDATEMODE_NEVER /** Object is never updated */
} UpdateMode;
typedef enum {
ACCESS_READWRITE = 0,
ACCESS_READONLY = 1
} AccessMode;
typedef struct {
QString name;
QString namelc; /** name in lowercase */
@ -110,8 +111,8 @@ public:
quint32 getObjectID(int objIndex);
ObjectInfo* getObjectByIndex(int objIndex);
int getNumBytes(int objIndex);
QStringList all_units;
int getNumBytes(int objIndex);
QStringList all_units;
private:
QList<ObjectInfo*> objInfo;

View File

@ -1,18 +1,18 @@
<xml>
<object name="StabilizationSettings" singleinstance="true" settings="true">
<description>PID settings used by the Stabilization module to combine the @ref AttitudeActual and @ref AttitudeDesired to compute @ref ActuatorDesired</description>
<field name="RollMax" units="degrees" type="uint8" elements="1" defaultvalue="55"/>
<field name="PitchMax" units="degrees" type="uint8" elements="1" defaultvalue="55"/>
<field name="YawMax" units="degrees" type="uint8" elements="1" defaultvalue="35"/>
<field name="ManualRate" units="degrees/sec" type="float" elementnames="Roll,Pitch,Yaw" defaultvalue="150,150,150"/>
<field name="MaximumRate" units="degrees/sec" type="float" elementnames="Roll,Pitch,Yaw" defaultvalue="300,300,300"/>
<field name="RollMax" units="degrees" type="uint8" elements="1" defaultvalue="55" limits="%BE:0:180"/>
<field name="PitchMax" units="degrees" type="uint8" elements="1" defaultvalue="55" limits="%BE:0:180"/>
<field name="YawMax" units="degrees" type="uint8" elements="1" defaultvalue="35" limits="%BE:0:180"/>
<field name="ManualRate" units="degrees/sec" type="float" elementnames="Roll,Pitch,Yaw" defaultvalue="150,150,150" limits="%BE:0:500,%BE:0:500,%BE:0:500"/>
<field name="MaximumRate" units="degrees/sec" type="float" elementnames="Roll,Pitch,Yaw" defaultvalue="300,300,300" limits="%BE:0:500,%BE:0:500,%BE:0:500"/>
<field name="RollRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.002,0,0,0.3"/>
<field name="PitchRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.002,0,0,0.3"/>
<field name="YawRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.0035,0.0035,0,0.3"/>
<field name="RollPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50"/>
<field name="PitchPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50"/>
<field name="YawPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50"/>
<field name="RollRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.002,0,0,0.3" limits="%BE:0:0.01,%BE:0:0.01,, "/>
<field name="PitchRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.002,0,0,0.3" limits="%BE:0:0.01,%BE:0:0.01,, "/>
<field name="YawRatePID" units="" type="float" elementnames="Kp,Ki,Kd,ILimit" defaultvalue="0.0035,0.0035,0,0.3" limits="%BE:0:0.01,%BE:0:0.01,, "/>
<field name="RollPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50" limits="%BE:0:10,%BE:0:10,"/>
<field name="PitchPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50" limits="%BE:0:10,%BE:0:10,"/>
<field name="YawPI" units="" type="float" elementnames="Kp,Ki,ILimit" defaultvalue="2,0,50" limits="%BE:0:10,%BE:0:10,"/>
<field name="GyroTau" units="" type="float" elements="1" defaultvalue="0.005"/>