From 97f1b5353901acdd96247c2a780e4b32550c62ff Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Fri, 6 Jan 2017 19:16:35 +0100 Subject: [PATCH] LP-467 vehicle config : fix controls enabled/disabled state management --- .../cfg_vehicletypes/configccpmwidget.cpp | 59 +++++++++++-------- .../cfg_vehicletypes/configccpmwidget.h | 9 +-- .../configfixedwingwidget.cpp | 2 - .../cfg_vehicletypes/configfixedwingwidget.h | 3 +- .../configgroundvehiclewidget.cpp | 2 - .../configgroundvehiclewidget.h | 3 +- .../configmultirotorwidget.cpp | 2 - .../cfg_vehicletypes/configmultirotorwidget.h | 3 +- .../config/cfg_vehicletypes/vehicleconfig.cpp | 6 ++ .../config/cfg_vehicletypes/vehicleconfig.h | 6 +- .../config/configvehicletypewidget.cpp | 47 ++++++++++++--- .../plugins/config/configvehicletypewidget.h | 4 +- .../uavobjectwidgetutils/configtaskwidget.h | 5 +- 13 files changed, 96 insertions(+), 55 deletions(-) diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp b/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp index 6aae50eb2..9532fe5a5 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp @@ -337,6 +337,13 @@ void ConfigCcpmWidget::resetActuators(GUIConfigDataUnion *configData) configData->heli.ServoIndexZ = 0; } +void ConfigCcpmWidget::enableControls(bool enable) +{ + if (enable) { + SetUIComponentVisibilities(); + } +} + void ConfigCcpmWidget::refreshWidgetsValues(QString frameType) { Q_UNUSED(frameType); @@ -411,28 +418,28 @@ void ConfigCcpmWidget::UpdateType() m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360)); m_aircraft->ccpmAngleY->setValue(0); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleY->setEnabled(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleY->setEnabled(false); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoYChannel->setCurrentIndex(0); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoYChannel->setEnabled(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoYChannel->setEnabled(false); + m_aircraft->ccpmServoZChannel->setEnabled(false); NumServosDefined = 2; } else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 90º"), Qt::CaseInsensitive) == 0) { m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0); m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360)); m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 180, 360)); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoZChannel->setEnabled(false); NumServosDefined = 3; } else if (typeText.compare(QString::fromUtf8("CCPM 4 Servo 90º"), Qt::CaseInsensitive) == 0) { m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0); m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360)); m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 180, 360)); m_aircraft->ccpmAngleZ->setValue(fmod(AdjustmentAngle + 270, 360)); - m_aircraft->ccpmSingleServo->setEnabled(0); + m_aircraft->ccpmSingleServo->setEnabled(false); m_aircraft->ccpmSingleServo->setCurrentIndex(0); NumServosDefined = 4; } else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 120º"), Qt::CaseInsensitive) == 0) { @@ -440,33 +447,33 @@ void ConfigCcpmWidget::UpdateType() m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 120, 360)); m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 240, 360)); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoZChannel->setEnabled(false); NumServosDefined = 3; } else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 140º"), Qt::CaseInsensitive) == 0) { m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0); m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 140, 360)); m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 220, 360)); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoZChannel->setEnabled(false); NumServosDefined = 3; } else if (typeText.compare(QString::fromUtf8("FP 2 Servo 90º"), Qt::CaseInsensitive) == 0) { m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0); m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360)); m_aircraft->ccpmAngleY->setValue(0); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleY->setEnabled(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleY->setEnabled(false); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoYChannel->setCurrentIndex(0); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoYChannel->setEnabled(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoYChannel->setEnabled(false); + m_aircraft->ccpmServoZChannel->setEnabled(false); - m_aircraft->ccpmCollectivespinBox->setEnabled(0); - m_aircraft->ccpmCollectiveSlider->setEnabled(0); + m_aircraft->ccpmCollectivespinBox->setEnabled(false); + m_aircraft->ccpmCollectiveSlider->setEnabled(false); m_aircraft->ccpmCollectivespinBox->setValue(0); m_aircraft->ccpmCollectiveSlider->setValue(0); m_aircraft->PitchCurve->setVisible(0); @@ -476,15 +483,15 @@ void ConfigCcpmWidget::UpdateType() m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360)); m_aircraft->ccpmAngleY->setValue(0); m_aircraft->ccpmAngleZ->setValue(0); - m_aircraft->ccpmAngleY->setEnabled(0); - m_aircraft->ccpmAngleZ->setEnabled(0); + m_aircraft->ccpmAngleY->setEnabled(false); + m_aircraft->ccpmAngleZ->setEnabled(false); m_aircraft->ccpmServoYChannel->setCurrentIndex(0); m_aircraft->ccpmServoZChannel->setCurrentIndex(0); - m_aircraft->ccpmServoYChannel->setEnabled(0); - m_aircraft->ccpmServoZChannel->setEnabled(0); + m_aircraft->ccpmServoYChannel->setEnabled(false); + m_aircraft->ccpmServoZChannel->setEnabled(false); - m_aircraft->ccpmCollectivespinBox->setEnabled(0); - m_aircraft->ccpmCollectiveSlider->setEnabled(0); + m_aircraft->ccpmCollectivespinBox->setEnabled(false); + m_aircraft->ccpmCollectiveSlider->setEnabled(false); m_aircraft->ccpmCollectivespinBox->setValue(0); m_aircraft->ccpmCollectiveSlider->setValue(0); m_aircraft->PitchCurve->setVisible(0); @@ -1291,7 +1298,7 @@ void ConfigCcpmWidget::SwashLvlPrevNextButtonPressed() m_aircraft->SwashLvlPrevButton->setEnabled(true); m_aircraft->SwashLvlCancelButton->setEnabled(true); m_aircraft->SwashLvlFinishButton->setEnabled(true); - + break; default: // restore collective/cyclic setting // restore pitch curve @@ -1481,7 +1488,7 @@ void ConfigCcpmWidget::enableSwashplateLevellingControl(bool state) m_aircraft->TabObject->setTabEnabled(0, 0); m_aircraft->TabObject->setTabEnabled(2, 0); m_aircraft->TabObject->setTabEnabled(3, 0); - m_aircraft->ccpmType->setEnabled(0); + m_aircraft->ccpmType->setEnabled(false); } else { // Restore metadata mdata = SwashLvlaccInitialData; @@ -1490,7 +1497,7 @@ void ConfigCcpmWidget::enableSwashplateLevellingControl(bool state) m_aircraft->TabObject->setTabEnabled(0, 1); m_aircraft->TabObject->setTabEnabled(2, 1); m_aircraft->TabObject->setTabEnabled(3, 1); - m_aircraft->ccpmType->setEnabled(1); + m_aircraft->ccpmType->setEnabled(true); } obj->setMetadata(mdata); } diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h b/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h index 73dec0617..dade24f74 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h @@ -73,6 +73,8 @@ protected: void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); + virtual void enableControls(bool enable); + private: Ui_CcpmConfigWidget *m_aircraft; @@ -100,10 +102,6 @@ private: virtual void resetActuators(GUIConfigDataUnion *configData); int ShowDisclaimer(int messageID); - virtual void enableControls(bool enable) - { - Q_UNUSED(enable) - }; // Not used by this widget bool updatingFromHardware; bool updatingToHardware; @@ -128,9 +126,6 @@ private slots: void SwashLvlCancelButtonPressed(); void SwashLvlFinishButtonPressed(); - // void UpdateCCPMOptionsFromUI(); - // void UpdateCCPMUIFromOptions(); - void SetUIComponentVisibilities(); void enableSwashplateLevellingControl(bool state); diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp b/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp index 2f2decadb..c22bb2ff1 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp @@ -802,8 +802,6 @@ void ConfigFixedWingWidget::setupRcOutputs(QList rcOutputList) void ConfigFixedWingWidget::enableControls(bool enable) { - ConfigTaskWidget::enableControls(enable); - if (enable) { setupUI(m_aircraft->fixedWingType->currentText()); } diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h b/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h index bd7513cce..2d6cd872d 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h @@ -68,10 +68,11 @@ private: void updateRcCurvesUsed(); protected: - void enableControls(bool enable); void resizeEvent(QResizeEvent *); void showEvent(QShowEvent *); + virtual void enableControls(bool enable); + private slots: virtual void setupUI(QString airframeType); virtual bool throwConfigError(QString airframeType); diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp b/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp index f835dc84e..cba9c8dba 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp @@ -284,8 +284,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType) void ConfigGroundVehicleWidget::enableControls(bool enable) { - ConfigTaskWidget::enableControls(enable); - if (enable) { setupUI(m_aircraft->groundVehicleType->currentText()); } diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h b/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h index 31bdd167f..460f6bb23 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h @@ -54,10 +54,11 @@ public: virtual QString updateConfigObjectsFromWidgets(); protected: - void enableControls(bool enable); void resizeEvent(QResizeEvent *); void showEvent(QShowEvent *); + virtual void enableControls(bool enable); + private: Ui_GroundConfigWidget *m_aircraft; QGraphicsSvgItem *m_vehicleImg; diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp b/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp index 2f0af653d..c84572661 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp @@ -1317,8 +1317,6 @@ void ConfigMultiRotorWidget::resizeEvent(QResizeEvent *event) void ConfigMultiRotorWidget::enableControls(bool enable) { - ConfigTaskWidget::enableControls(enable); - if (enable) { setupEnabledControls(m_aircraft->multirotorFrameType->currentText()); } diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h b/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h index f38495913..7fa79c3cf 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h @@ -57,7 +57,8 @@ public: protected: void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); - void enableControls(bool enable); + + virtual void enableControls(bool enable); private: Ui_MultiRotorConfigWidget *m_aircraft; diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp b/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp index 70848b651..a5cf586d0 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp @@ -133,6 +133,12 @@ void VehicleConfig::resetActuators(GUIConfigDataUnion *configData) Q_UNUSED(configData); } +void VehicleConfig::enableControls(bool enable) +{ + Q_UNUSED(enable); + + // do nothing. no need to call parent. +} void VehicleConfig::registerWidgets(ConfigTaskWidget &parent) { diff --git a/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h b/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h index 225c36b3d..d771da355 100644 --- a/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h +++ b/ground/gcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h @@ -157,7 +157,7 @@ typedef union { customGUISettingsStruct custom; } GUIConfigDataUnion; -class ConfigTaskWidget; +class ConfigVehicleTypeWidget; /* * This class handles vehicle specific configuration UI and associated logic. @@ -173,6 +173,8 @@ class ConfigTaskWidget; class VehicleConfig : public ConfigTaskWidget { Q_OBJECT + friend ConfigVehicleTypeWidget; + public: /* Enumeration options for ThrottleCurves */ @@ -223,6 +225,7 @@ public: virtual void registerWidgets(ConfigTaskWidget &parent); virtual void refreshWidgetsValues(QString frameType); + virtual QString updateConfigObjectsFromWidgets(); double getMixerValue(UAVDataObject *mixer, QString elementName); @@ -249,6 +252,7 @@ protected: double getCurveMin(QList *curve); double getCurveMax(QList *curve); + virtual void enableControls(bool enable); virtual void refreshWidgetsValuesImpl(UAVObject *obj); virtual void updateObjectsFromWidgetsImpl(); diff --git a/ground/gcs/src/plugins/config/configvehicletypewidget.cpp b/ground/gcs/src/plugins/config/configvehicletypewidget.cpp index 9e35c40d6..2de1d2240 100644 --- a/ground/gcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/gcs/src/plugins/config/configvehicletypewidget.cpp @@ -160,8 +160,26 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget() void ConfigVehicleTypeWidget::switchAirframeType(int index) { - m_aircraft->airframesWidget->setCurrentWidget(getVehicleConfigWidget(index)); - setDirty(true); + VehicleConfig *vehicleConfig = getVehicleConfigWidget(index); + if (vehicleConfig) { + m_aircraft->airframesWidget->setCurrentWidget(vehicleConfig); + // enable controls + enableControls(isConnected()); + // and flag vehicle config as dirty (frame type was changed...) + setDirty(true); + } +} + +void ConfigVehicleTypeWidget::enableControls(bool enable) +{ + ConfigTaskWidget::enableControls(enable); + + int category = frameCategory(frameType()); + + VehicleConfig *vehicleConfig = getVehicleConfigWidget(category); + if (vehicleConfig) { + vehicleConfig->enableControls(enable); + } } /** @@ -267,6 +285,18 @@ void ConfigVehicleTypeWidget::updateObjectsFromWidgetsImpl() refreshWidgetsValues(); } +QString ConfigVehicleTypeWidget::frameType() +{ + // Get the Airframe type from the system settings + UAVDataObject *system = dynamic_cast(getObjectManager()->getObject("SystemSettings")); + Q_ASSERT(system); + + UAVObjectField *field = system->getField("AirframeType"); + Q_ASSERT(field); + + return field->getValue().toString(); +} + int ConfigVehicleTypeWidget::frameCategory(QString frameType) { if (frameType == "FixedWing" || frameType == "Aileron" || frameType == "FixedWingElevon" @@ -303,12 +333,11 @@ VehicleConfig *ConfigVehicleTypeWidget::getVehicleConfigWidget(int frameCategory // create config widget vehicleConfig = createVehicleConfigWidget(frameCategory); - // add config widget to UI - int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehicleConfig); - m_vehicleIndexMap[frameCategory] = index; - - // and enable controls (needed?) - updateEnableControls(); + if (vehicleConfig) { + // add config widget to UI + int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehicleConfig); + m_vehicleIndexMap[frameCategory] = index; + } } int index = m_vehicleIndexMap.value(frameCategory); vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->widget(index); @@ -340,7 +369,7 @@ VehicleConfig *ConfigVehicleTypeWidget::createVehicleConfigWidget(int frameCateg break; } if (vehicleConfig) { - // bind config widget "field" to this ConfigTaskWodget + // bind config widget "field" to this ConfigTaskWidget // this is necessary to get "dirty" state management vehicleConfig->registerWidgets(*this); } diff --git a/ground/gcs/src/plugins/config/configvehicletypewidget.h b/ground/gcs/src/plugins/config/configvehicletypewidget.h index 1885cdbb7..88e85987a 100644 --- a/ground/gcs/src/plugins/config/configvehicletypewidget.h +++ b/ground/gcs/src/plugins/config/configvehicletypewidget.h @@ -61,6 +61,7 @@ public: ~ConfigVehicleTypeWidget(); protected: + virtual void enableControls(bool enable); virtual void refreshWidgetsValuesImpl(UAVObject *obj); virtual void updateObjectsFromWidgetsImpl(); @@ -73,7 +74,8 @@ private: QMap m_vehicleIndexMap; - int frameCategory(QString frameType); + QString frameType(); + static int frameCategory(QString frameType); VehicleConfig *getVehicleConfigWidget(int frameCategory); VehicleConfig *createVehicleConfigWidget(int frameCategory); diff --git a/ground/gcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/gcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index b0f0cc7eb..40034ff77 100644 --- a/ground/gcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/gcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -176,10 +176,12 @@ protected: return m_currentBoardId; } bool expertMode() const; - virtual void enableControls(bool enable); virtual QString mapObjectName(const QString objectName); virtual UAVObject *getObject(const QString name, quint32 instId = 0); virtual void buildOptionComboBox(QComboBox *combo, UAVObjectField *field, int index, bool applyLimits); + + virtual void enableControls(bool enable); + void updateEnableControls(); bool isConnected() const; @@ -192,7 +194,6 @@ protected slots: void clearDirty(); virtual void widgetsContentsChanged(); - // void populateWidgets(); void refreshWidgetsValues(UAVObject *obj = NULL); void updateObjectsFromWidgets();