/** Sends the config to the board (airframe type) We do all the tasks common to all airframes, or family of airframes, and we call additional methods for specific frames, so that we do not have a code that is too heavy. Note: The default behavior of ConfigTaskWidget is bypassed. Therefore no automatic synchronization of UI to UAV Objects is done. */ void ConfigVehicleTypeWidget::updateObjectsFromWidgets() { // Airframe type defaults to Custom QString airframeType = "Custom"; VehicleConfig *vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->currentWidget(); if (vehicleConfig) { airframeType = vehicleConfig->updateConfigObjectsFromWidgets(); } // set the airframe type UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings"))); Q_ASSERT(system); QPointer<UAVObjectField> field = system->getField(QString("AirframeType")); if (field) { field->setValue(airframeType); } // Update feed forward settings UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); QPointer<VehicleConfig> vconfig = new VehicleConfig(); vconfig->setMixerValue(mixer, "FeedForward", m_aircraft->feedForwardSlider->value() / 100.0); vconfig->setMixerValue(mixer, "AccelTime", m_aircraft->accelTime->value()); vconfig->setMixerValue(mixer, "DecelTime", m_aircraft->decelTime->value()); vconfig->setMixerValue(mixer, "MaxAccel", m_aircraft->maxAccelSlider->value()); // TODO call refreshWidgetsValues() to reflect actual saved values ? updateFeedForwardUI(); }
/** Refreshes the current value of the SystemSettings which holds the aircraft type Note: The default behavior of ConfigTaskWidget is bypassed. Therefore no automatic synchronization of UAV Objects to UI is done. */ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o) { Q_UNUSED(o); if (!allObjectsUpdated()) { return; } bool dirty = isDirty(); // 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"); m_aircraft->aircraftType->setCurrentIndex(category); VehicleConfig *vehicleConfig = getVehicleConfigWidget(category); 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; } } m_aircraft->nameEdit->setText(name); updateFeedForwardUI(); setDirty(dirty); }
/** Sends the config to the board (airframe type) We do all the tasks common to all airframes, or family of airframes, and we call additional methods for specific frames, so that we do not have a code that is too heavy. Note: The default behavior of ConfigTaskWidget is bypassed. Therefore no automatic synchronization of UI to UAV Objects is done. */ void ConfigVehicleTypeWidget::updateObjectsFromWidgets() { // Airframe type defaults to Custom QString airframeType = "Custom"; VehicleConfig *vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->currentWidget(); if (vehicleConfig) { airframeType = vehicleConfig->updateConfigObjectsFromWidgets(); } // set the airframe type UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings"))); Q_ASSERT(system); QPointer<UAVObjectField> field = system->getField(QString("AirframeType")); if (field) { field->setValue(airframeType); } // Update feed forward settings UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); QPointer<VehicleConfig> vconfig = new VehicleConfig(); vconfig->setMixerValue(mixer, "FeedForward", m_aircraft->feedForwardSlider->value() / 100.0); vconfig->setMixerValue(mixer, "AccelTime", m_aircraft->accelTime->value()); vconfig->setMixerValue(mixer, "DecelTime", m_aircraft->decelTime->value()); vconfig->setMixerValue(mixer, "MaxAccel", m_aircraft->maxAccelSlider->value()); field = system->getField(QString("VehicleName")); Q_ASSERT(field); QString name = m_aircraft->nameEdit->text(); for (uint i = 0; i < field->getNumElements(); ++i) { if (i < (uint)name.length()) { field->setValue(name.at(i).toLatin1(), i); } else { field->setValue(0, i); } } // call refreshWidgetsValues() to reflect actual saved values refreshWidgetsValues(); updateFeedForwardUI(); }
VehicleConfig *ConfigVehicleTypeWidget::getVehicleConfigWidget(QString frameCategory) { VehicleConfig *vehiculeConfig; if (!vehicleIndexMap.contains(frameCategory)) { // create config widget vehiculeConfig = createVehicleConfigWidget(frameCategory); // bind config widget "field" to this ConfigTaskWodget // this is necessary to get "dirty" state management vehiculeConfig->registerWidgets(*this); // add config widget to UI int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehiculeConfig); vehicleIndexMap[frameCategory] = index; } int index = vehicleIndexMap.value(frameCategory); vehiculeConfig = (VehicleConfig *)m_aircraft->airframesWidget->widget(index); return vehiculeConfig; }
/** Refreshes the current value of the SystemSettings which holds the aircraft type Note: The default behavior of ConfigTaskWidget is bypassed. Therefore no automatic synchronization of UAV Objects to UI is done. */ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o) { Q_UNUSED(o); if (!allObjectsUpdated()) { return; } bool dirty = isDirty(); // 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, this // is not ideal, but there you go. QString frameType = field->getValue().toString(); qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - frame type:" << frameType; QString category = frameCategory(frameType); setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText(category)); VehicleConfig *vehicleConfig = getVehicleConfigWidget(category); if (vehicleConfig) { vehicleConfig->refreshWidgetsValues(frameType); } updateFeedForwardUI(); setDirty(dirty); qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - end"; }