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

LP-467 update custom mixers when saving vehicle config

This commit is contained in:
Philippe Renon 2017-01-08 19:04:57 +01:00
parent 97f1b53539
commit f646ef1d37
8 changed files with 107 additions and 83 deletions

View File

@ -62,9 +62,6 @@ public:
ConfigCcpmWidget(QWidget *parent = 0);
~ConfigCcpmWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
public slots:
void getMixer();
void setMixer();
@ -74,6 +71,8 @@ protected:
void resizeEvent(QResizeEvent *event);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private:
Ui_CcpmConfigWidget *m_aircraft;

View File

@ -49,13 +49,13 @@ public:
ConfigCustomWidget(QWidget *parent = 0);
~ConfigCustomWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private:
Ui_CustomConfigWidget *m_aircraft;

View File

@ -50,9 +50,6 @@ public:
ConfigFixedWingWidget(QWidget *parent = 0);
~ConfigFixedWingWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private:
Ui_FixedWingConfigWidget *m_aircraft;
QGraphicsSvgItem *planeimg;
@ -72,6 +69,8 @@ protected:
void showEvent(QShowEvent *);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private slots:
virtual void setupUI(QString airframeType);

View File

@ -49,15 +49,15 @@ public:
ConfigGroundVehicleWidget(QWidget *parent = 0);
~ConfigGroundVehicleWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual void initMixerCurves(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
protected:
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private:
Ui_GroundConfigWidget *m_aircraft;

View File

@ -51,21 +51,21 @@ public:
ConfigMultiRotorWidget(QWidget *parent = 0);
~ConfigMultiRotorWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual void registerWidgets(ConfigTaskWidget &parent);
private:
Ui_MultiRotorConfigWidget *m_aircraft;
QGraphicsSvgItem *quad;
bool invertMotors;
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
virtual void resetRcOutputs(GUIConfigDataUnion *configData);

View File

@ -222,12 +222,6 @@ public:
VehicleConfig(QWidget *parent = 0);
~VehicleConfig();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
double getMixerValue(UAVDataObject *mixer, QString elementName);
void setMixerValue(UAVDataObject *mixer, QString elementName, double value);
@ -256,6 +250,10 @@ protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
private:
static UAVObjectManager *getUAVObjectManager();

View File

@ -161,6 +161,7 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget()
void ConfigVehicleTypeWidget::switchAirframeType(int index)
{
VehicleConfig *vehicleConfig = getVehicleConfigWidget(index);
if (vehicleConfig) {
m_aircraft->airframesWidget->setCurrentWidget(vehicleConfig);
// enable controls
@ -177,6 +178,7 @@ void ConfigVehicleTypeWidget::enableControls(bool enable)
int category = frameCategory(frameType());
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
if (vehicleConfig) {
vehicleConfig->enableControls(enable);
}
@ -195,50 +197,26 @@ void ConfigVehicleTypeWidget::refreshWidgetsValuesImpl(UAVObject *obj)
return;
}
// Get the Airframe type from the system settings:
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
Q_ASSERT(system);
UAVObjectField *field = system->getField(QString("AirframeType"));
Q_ASSERT(field);
// At this stage, we will need to have some hardcoded settings in this code
QString frameType = field->getValue().toString();
// Always update custom tab from others airframe settings : debug/learn hardcoded mixers
int category = frameCategory("Custom");
// update current vehicle tab
QString ft = frameType();
int category = frameCategory(ft);
m_aircraft->aircraftType->setCurrentIndex(category);
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues(ft);
}
// update custom tab from others frame settings (to debug/learn hard coded mixers)
if (ft != "Custom") {
int customCategory = frameCategory("Custom");
VehicleConfig *vehicleConfig = getVehicleConfigWidget(customCategory);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues("Custom");
}
// Switch to Airframe currently used
category = frameCategory(frameType);
if (frameType != "Custom") {
m_aircraft->aircraftType->setCurrentIndex(category);
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues(frameType);
}
}
field = system->getField(QString("VehicleName"));
Q_ASSERT(field);
QString name;
for (uint i = 0; i < field->getNumElements(); ++i) {
QChar chr = field->getValue(i).toChar();
if (chr != 0) {
name.append(chr);
} else {
break;
}
}
// update vehicle name
QString name = vehicleName();
m_aircraft->nameEdit->setText(name);
}
@ -252,26 +230,87 @@ void ConfigVehicleTypeWidget::refreshWidgetsValuesImpl(UAVObject *obj)
void ConfigVehicleTypeWidget::updateObjectsFromWidgetsImpl()
{
// Airframe type defaults to Custom
QString airframeType = "Custom";
QString ft = "Custom";
VehicleConfig *vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->currentWidget();
if (vehicleConfig) {
airframeType = vehicleConfig->updateConfigObjectsFromWidgets();
ft = vehicleConfig->updateConfigObjectsFromWidgets();
}
// set the airframe type
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
// airframe type
setFrameType(ft);
// vehicle name
QString name = m_aircraft->nameEdit->text();
setVehicleName(name);
// update custom tab from others frame settings (to debug/learn hard coded mixers)
if (ft != "Custom") {
int customCategory = frameCategory("Custom");
VehicleConfig *vehicleConfig = getVehicleConfigWidget(customCategory);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues("Custom");
}
}
}
QString ConfigVehicleTypeWidget::frameType()
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField(QString("AirframeType"));
if (field) {
field->setValue(airframeType);
}
field = system->getField(QString("VehicleName"));
UAVObjectField *field = system->getField("AirframeType");
Q_ASSERT(field);
QString name = m_aircraft->nameEdit->text();
return field->getValue().toString();
}
void ConfigVehicleTypeWidget::setFrameType(QString frameType)
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("AirframeType");
Q_ASSERT(field);
if (field) {
field->setValue(frameType);
}
}
QString ConfigVehicleTypeWidget::vehicleName()
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("VehicleName");
Q_ASSERT(field);
QString name;
for (uint i = 0; i < field->getNumElements(); ++i) {
QChar chr = field->getValue(i).toChar();
if (chr != 0) {
name.append(chr);
} else {
break;
}
}
return name;
}
void ConfigVehicleTypeWidget::setVehicleName(QString name)
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("VehicleName");
Q_ASSERT(field);
for (uint i = 0; i < field->getNumElements(); ++i) {
if (i < (uint)name.length()) {
field->setValue(name.at(i).toLatin1(), i);
@ -279,22 +318,6 @@ void ConfigVehicleTypeWidget::updateObjectsFromWidgetsImpl()
field->setValue(0, i);
}
}
// call refreshWidgetsValues() to reflect actual saved values
// TODO is this needed ?
refreshWidgetsValues();
}
QString ConfigVehicleTypeWidget::frameType()
{
// Get the Airframe type from the system settings
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("AirframeType");
Q_ASSERT(field);
return field->getValue().toString();
}
int ConfigVehicleTypeWidget::frameCategory(QString frameType)

View File

@ -75,6 +75,11 @@ private:
QString frameType();
void setFrameType(QString frameType);
QString vehicleName();
void setVehicleName(QString name);
static int frameCategory(QString frameType);
VehicleConfig *getVehicleConfigWidget(int frameCategory);