mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-31 16:52:10 +01:00
LP-467 vehicle config : fix controls enabled/disabled state management
This commit is contained in:
parent
a0a2f30788
commit
97f1b53539
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -802,8 +802,6 @@ void ConfigFixedWingWidget::setupRcOutputs(QList<QString> rcOutputList)
|
||||
|
||||
void ConfigFixedWingWidget::enableControls(bool enable)
|
||||
{
|
||||
ConfigTaskWidget::enableControls(enable);
|
||||
|
||||
if (enable) {
|
||||
setupUI(m_aircraft->fixedWingType->currentText());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -284,8 +284,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
|
||||
|
||||
void ConfigGroundVehicleWidget::enableControls(bool enable)
|
||||
{
|
||||
ConfigTaskWidget::enableControls(enable);
|
||||
|
||||
if (enable) {
|
||||
setupUI(m_aircraft->groundVehicleType->currentText());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1317,8 +1317,6 @@ void ConfigMultiRotorWidget::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void ConfigMultiRotorWidget::enableControls(bool enable)
|
||||
{
|
||||
ConfigTaskWidget::enableControls(enable);
|
||||
|
||||
if (enable) {
|
||||
setupEnabledControls(m_aircraft->multirotorFrameType->currentText());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<double> *curve);
|
||||
double getCurveMax(QList<double> *curve);
|
||||
|
||||
virtual void enableControls(bool enable);
|
||||
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
|
||||
virtual void updateObjectsFromWidgetsImpl();
|
||||
|
||||
|
@ -160,8 +160,26 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget()
|
||||
|
||||
void ConfigVehicleTypeWidget::switchAirframeType(int index)
|
||||
{
|
||||
m_aircraft->airframesWidget->setCurrentWidget(getVehicleConfigWidget(index));
|
||||
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<UAVDataObject *>(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);
|
||||
|
||||
if (vehicleConfig) {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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<int, int> m_vehicleIndexMap;
|
||||
|
||||
|
||||
int frameCategory(QString frameType);
|
||||
QString frameType();
|
||||
static int frameCategory(QString frameType);
|
||||
|
||||
VehicleConfig *getVehicleConfigWidget(int frameCategory);
|
||||
VehicleConfig *createVehicleConfigWidget(int frameCategory);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user