void ConfigMultiRotorWidget::setupUI(SystemSettings::AirframeTypeOptions frameType)
{
    Q_ASSERT(m_aircraft);
    Q_ASSERT(uiowner);
    Q_ASSERT(quad);

    int i;

    // set aircraftType to Multirotor, disable triyaw channel
    setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Multirotor"));
    m_aircraft->triYawChannelBox->setEnabled(false);

    // disable all motor channel boxes
    for (i=1; i <=8; i++) {
        // do it manually so we can turn off any error decorations
        QComboBox *combobox = uiowner->findChild<QComboBox*>("multiMotorChannelBox" + QString::number(i));
        if (combobox) {
            combobox->setEnabled(false);
            combobox->setItemData(0, 0, Qt::DecorationRole);
        }
    }


    switch(frameType) {
    case SystemSettings::AIRFRAMETYPE_TRI:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_TRI));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 3, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);

        m_aircraft->triYawChannelBox->setEnabled(true);
        break;
    case SystemSettings::AIRFRAMETYPE_QUADX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_QUADX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true);

        // init mixer levels
        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_QUADP:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_QUADP));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXA:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXA));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(33);
        setYawMixLevel(33);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXAX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXAX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(33);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(33);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXACOAX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXACOAX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(66);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTO:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTO));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(33);
        m_aircraft->mrPitchMixLevel->setValue(33);
        setYawMixLevel(25);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOV:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOV));
        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(25);
        m_aircraft->mrPitchMixLevel->setValue(25);
        setYawMixLevel(25);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOCOAXP:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOCOAXP));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOCOAXX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOCOAXX));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(50);
        break;
    default:
        Q_ASSERT(0);
        break;
    }

    //Draw the appropriate airframe
    drawAirframe(frameType);
}
/**
   Virtual function to refresh the UI widget values
 */
void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
{
    setupUI(frameType);

    initMixerCurves(frameType);

    UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
    Q_ASSERT(mixer);

    GUIConfigDataUnion config = getConfigData();

    // THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE
    // Retrieve channel setup values
    setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, config.ground.GroundVehicleThrottle1);
    setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, config.ground.GroundVehicleThrottle2);
    setComboCurrentIndex(m_aircraft->gvSteering1ChannelBox, config.ground.GroundVehicleSteering1);
    setComboCurrentIndex(m_aircraft->gvSteering2ChannelBox, config.ground.GroundVehicleSteering2);

    if (frameType == "GroundVehicleDifferential") {
        // Find the channel number for Motor1
        int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
        if (channel > -1) {
            // If for some reason the actuators were incoherent, we might fail here, hence the check.
            m_aircraft->differentialSteeringSlider1->setValue(
                getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW) / 1.27);
        }
        channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
        if (channel > -1) {
            m_aircraft->differentialSteeringSlider2->setValue(
                -getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW) / 1.27);
        }
    }
}
/**
 Virtual function to refresh the UI widget values
 */
void ConfigGroundVehicleWidget::refreshAirframeWidgetsValues(SystemSettings::AirframeTypeOptions frameType)
{
    MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager());
    Q_ASSERT(mixerSettings);

    GUIConfigDataUnion config = GetConfigData();

	//THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE
	// Retrieve channel setup values
    setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, config.ground.GroundVehicleThrottle1);
    setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, config.ground.GroundVehicleThrottle2);
    setComboCurrentIndex(m_aircraft->gvSteering1ChannelBox, config.ground.GroundVehicleSteering1);
    setComboCurrentIndex(m_aircraft->gvSteering2ChannelBox, config.ground.GroundVehicleSteering2);

    if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL) {
		//CURRENTLY BROKEN UNTIL WE DECIDE HOW DIFFERENTIAL SHOULD BEHAVE
		// If the vehicle type is "differential", restore the slider setting
		
		// Find the channel number for Motor1 
        int channel = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
        if (channel > -1) { // If for some reason the actuators were incoherent, we might fail here, hence the check.

            m_aircraft->differentialSteeringSlider1->setValue(getMixerVectorValue(mixerSettings,channel,MixerSettings::MIXER1VECTOR_ROLL)*100);
            m_aircraft->differentialSteeringSlider2->setValue(getMixerVectorValue(mixerSettings,channel,MixerSettings::MIXER1VECTOR_PITCH)*100);
		}
	}
    if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE) {
		//CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE
//		obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
//		Q_ASSERT(obj);
//		int chMixerNumber = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
//		if (chMixerNumber >=0) {
//			field = obj->getField(mixerVectors.at(chMixerNumber));
//			int ti = field->getElementNames().indexOf("Yaw");
//			m_aircraft->differentialSteeringSlider1->setValue(field->getDouble(ti)*100);
//			
//			ti = field->getElementNames().indexOf("Pitch");
//			m_aircraft->differentialSteeringSlider2->setValue(field->getDouble(ti)*100);
//		}
	}
}
/**
   Virtual function to refresh the UI widget values
 */
void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
{
    Q_ASSERT(m_aircraft);

    setupUI(frameType);

    UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
    Q_ASSERT(mixer);

    QList<double> curveValues;
    getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues);

    // is at least one of the curve values != 0?
    if (isValidThrottleCurve(&curveValues)) {
        // yes, use the curve we just read from mixersettings
        m_aircraft->fixedWingThrottle->initCurve(&curveValues);
    } else {
        // no, init a straight curve
        m_aircraft->fixedWingThrottle->initLinearCurve(curveValues.count(), 1.0);
    }

    GUIConfigDataUnion config    = getConfigData();
    fixedGUISettingsStruct fixed = config.fixedwing;

    // Then retrieve how channels are setup
    setComboCurrentIndex(m_aircraft->fwEngineChannelBox, fixed.FixedWingThrottle);
    setComboCurrentIndex(m_aircraft->fwAileron1ChannelBox, fixed.FixedWingRoll1);
    setComboCurrentIndex(m_aircraft->fwAileron2ChannelBox, fixed.FixedWingRoll2);
    setComboCurrentIndex(m_aircraft->fwElevator1ChannelBox, fixed.FixedWingPitch1);
    setComboCurrentIndex(m_aircraft->fwElevator2ChannelBox, fixed.FixedWingPitch2);
    setComboCurrentIndex(m_aircraft->fwRudder1ChannelBox, fixed.FixedWingYaw1);
    setComboCurrentIndex(m_aircraft->fwRudder2ChannelBox, fixed.FixedWingYaw2);

    // Get mixing values for GUI sliders (values stored onboard)
    m_aircraft->elevonSlider3->setValue(getMixerValue(mixer, "RollDifferential"));
    if (frameType == "FixedWingElevon" || frameType == "Elevon") {
        m_aircraft->elevonSlider1->setValue(getMixerValue(mixer, "MixerValueRoll"));
        m_aircraft->elevonSlider2->setValue(getMixerValue(mixer, "MixerValuePitch"));
    } else if (frameType == "FixedWingVtail" || frameType == "Vtail") {
        m_aircraft->elevonSlider1->setValue(getMixerValue(mixer, "MixerValueYaw"));
        m_aircraft->elevonSlider2->setValue(getMixerValue(mixer, "MixerValuePitch"));
    }
}
/**
   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";
}
/**
   Helper function to refresh the UI widget values
 */
void ConfigCustomWidget::refreshWidgetsValues(QString frameType)
{
    Q_ASSERT(m_aircraft);

    setupUI(frameType);

    UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
    Q_ASSERT(system);
    QPointer<UAVObjectField> field = system->getField(QString("AirframeType"));

    // Do not allow table edit until AirframeType == Custom
    // First save set AirframeType to 'Custom' and next modify.
    if (field->getValue().toString() != "Custom") {
        m_aircraft->customMixerTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    } else {
        m_aircraft->customMixerTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
    }

    UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
    Q_ASSERT(mixer);

    getChannelDescriptions();

    QList<double> curveValues;
    getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues);

    // is at least one of the curve values != 0?
    if (isValidThrottleCurve(&curveValues)) {
        // yes, use the curve we just read from mixersettings
        m_aircraft->customThrottle1Curve->initCurve(&curveValues);
    } else {
        // no, init a straight curve
        m_aircraft->customThrottle1Curve->initLinearCurve(curveValues.count(), 1.0);
    }

    double Throttle2CurveMin = m_aircraft->customThrottle2Curve->getMin();

    if (MixerSettings * mxr = qobject_cast<MixerSettings *>(mixer)) {
        MixerSettings::DataFields mixerSettingsData = mxr->getData();
        if (mixerSettingsData.Curve2Source == MixerSettings::CURVE2SOURCE_THROTTLE && Throttle2CurveMin >= 0) {
            m_aircraft->customThrottle2Curve->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);
        } else {
            m_aircraft->customThrottle2Curve->setMixerType(MixerCurve::MIXERCURVE_PITCH);
        }
    }

    // Setup all Throttle2 curves for all types of airframes
    getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, &curveValues);

    if (isValidThrottleCurve(&curveValues)) {
        m_aircraft->customThrottle2Curve->initCurve(&curveValues);
    } else {
        m_aircraft->customThrottle2Curve->initLinearCurve(curveValues.count(), 1.0, m_aircraft->customThrottle2Curve->getMin());
    }

    // Update the mixer table:
    for (int channel = 0; channel < m_aircraft->customMixerTable->columnCount(); channel++) {
        UAVObjectField *field = mixer->getField(mixerTypes.at(channel));
        if (field) {
            QComboBox *q = (QComboBox *)m_aircraft->customMixerTable->cellWidget(0, channel);
            if (q) {
                QString s = field->getValue().toString();
                setComboCurrentIndex(q, q->findText(s));
            }

            m_aircraft->customMixerTable->item(1, channel)->setText(
                QString::number(getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1)));
            m_aircraft->customMixerTable->item(2, channel)->setText(
                QString::number(getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2)));
            m_aircraft->customMixerTable->item(3, channel)->setText(
                QString::number(getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL)));
            m_aircraft->customMixerTable->item(4, channel)->setText(
                QString::number(getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH)));
            m_aircraft->customMixerTable->item(5, channel)->setText(
                QString::number(getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW)));
        }
    }
}
/**
   Virtual function to setup the UI
 */
void ConfigGroundVehicleWidget::setupUI(QString frameType)
{
    // Setup the UI

    Q_ASSERT(m_aircraft);
    QSvgRenderer *renderer = new QSvgRenderer();
    renderer->load(QString(":/configgadget/images/ground-shapes.svg"));
    m_vehicleImg = new QGraphicsSvgItem();
    m_vehicleImg->setSharedRenderer(renderer);

    UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
    Q_ASSERT(system);
    QPointer<UAVObjectField> frameTypeSaved = system->getField(QString("AirframeType"));

    m_aircraft->differentialSteeringSlider1->setEnabled(false);
    m_aircraft->differentialSteeringSlider2->setEnabled(false);

    m_aircraft->gvThrottleCurve1GroupBox->setEnabled(true);
    m_aircraft->gvThrottleCurve2GroupBox->setEnabled(true);

    m_aircraft->groundVehicleThrottle1->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);
    m_aircraft->groundVehicleThrottle2->setMixerType(MixerCurve::MIXERCURVE_PITCH);

    initMixerCurves(frameType);


    if (frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)") {
        // Tank
        m_vehicleImg->setElementId("tank");
        setComboCurrentIndex(m_aircraft->groundVehicleType,
                             m_aircraft->groundVehicleType->findText("Differential (tank)"));
        m_aircraft->gvMotor1ChannelBox->setEnabled(true);
        m_aircraft->gvMotor2ChannelBox->setEnabled(true);

        m_aircraft->gvThrottleCurve1GroupBox->setEnabled(false);

        m_aircraft->gvMotor1Label->setText("Left motor");
        m_aircraft->gvMotor2Label->setText("Right motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(false);
        m_aircraft->gvSteering2ChannelBox->setEnabled(false);

        m_aircraft->gvSteering1Label->setText("Front steering");
        m_aircraft->gvSteering2Label->setText("Rear steering");

        m_aircraft->differentialSteeringSlider1->setEnabled(true);
        m_aircraft->differentialSteeringSlider2->setEnabled(true);

        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Throttle curve1");
        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Throttle curve2 ");

        m_aircraft->groundVehicleThrottle2->setMixerType(MixerCurve::MIXERCURVE_PITCH);
        m_aircraft->groundVehicleThrottle1->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);

        initMixerCurves(frameType);

        // If new setup, set sliders to defaults and set curves values
        if (frameTypeSaved->getValue().toString() != "GroundVehicleDifferential") {
            m_aircraft->differentialSteeringSlider1->setValue(100);
            m_aircraft->differentialSteeringSlider2->setValue(100);
            m_aircraft->groundVehicleThrottle1->initLinearCurve(5, 1.0, 0.0);
            m_aircraft->groundVehicleThrottle2->initLinearCurve(5, 1.0, 0.0);
        }
    } else if (frameType == "GroundVehicleMotorcycle" || frameType == "Motorcycle") {
        // Motorcycle
        m_vehicleImg->setElementId("motorbike");
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Motorcycle"));

        m_aircraft->gvMotor1ChannelBox->setEnabled(true);
        m_aircraft->gvMotor2ChannelBox->setEnabled(false);

        m_aircraft->gvMotor2Label->setText("Rear motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(true);
        m_aircraft->gvSteering2ChannelBox->setEnabled(true);

        m_aircraft->gvSteering1Label->setText("Front steering");
        m_aircraft->gvSteering2Label->setText("Balancing");

        // Curve1 for Motorcyle
        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Throttle curve1");
        m_aircraft->gvThrottleCurve1GroupBox->setEnabled(true);
        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Throttle curve2");
        m_aircraft->gvThrottleCurve2GroupBox->setEnabled(true);

        m_aircraft->groundVehicleThrottle2->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);
        m_aircraft->groundVehicleThrottle1->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);

        initMixerCurves(frameType);

        // If new setup, set curves values
        if (frameTypeSaved->getValue().toString() != "GroundVehicleMotorCycle") {
            m_aircraft->groundVehicleThrottle2->initLinearCurve(5, 1.0, 0.0);
            m_aircraft->groundVehicleThrottle1->initLinearCurve(5, 1.0, 0.0);
        }
    } else {
        // Car
        m_vehicleImg->setElementId("car");
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Turnable (car)"));

        m_aircraft->gvMotor1ChannelBox->setEnabled(true);
        m_aircraft->gvMotor2ChannelBox->setEnabled(true);

        m_aircraft->gvMotor1Label->setText("Front motor");
        m_aircraft->gvMotor2Label->setText("Rear motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(true);
        m_aircraft->gvSteering2ChannelBox->setEnabled(true);

        m_aircraft->gvSteering1Label->setText("Front steering");
        m_aircraft->gvSteering2Label->setText("Rear steering");

        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Throttle curve2");
        m_aircraft->gvThrottleCurve2GroupBox->setEnabled(true);
        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Throttle curve1");
        m_aircraft->gvThrottleCurve1GroupBox->setEnabled(true);

        m_aircraft->groundVehicleThrottle2->setMixerType(MixerCurve::MIXERCURVE_PITCH);
        m_aircraft->groundVehicleThrottle1->setMixerType(MixerCurve::MIXERCURVE_THROTTLE);

        initMixerCurves(frameType);

        // If new setup, set curves values
        if (frameTypeSaved->getValue().toString() != "GroundVehicleCar") {
            m_aircraft->groundVehicleThrottle1->initLinearCurve(5, 1.0, 0.0);
            m_aircraft->groundVehicleThrottle2->initLinearCurve(5, 1.0, 0.0);
        }
    }

    QGraphicsScene *scene = new QGraphicsScene();
    scene->addItem(m_vehicleImg);
    scene->setSceneRect(m_vehicleImg->boundingRect());
    m_aircraft->groundShape->fitInView(m_vehicleImg, Qt::KeepAspectRatio);
    m_aircraft->groundShape->setScene(scene);
}
/**
   Virtual function to setup the UI
 */
void ConfigGroundVehicleWidget::setupUI(QString frameType)
{
    // Setup the UI

    m_aircraft->gvEngineChannelBox->setEnabled(false);
    m_aircraft->gvAileron1ChannelBox->setEnabled(false);
    m_aircraft->gvAileron2ChannelBox->setEnabled(false);

    m_aircraft->differentialSteeringSlider1->setEnabled(false);
    m_aircraft->differentialSteeringSlider2->setEnabled(false);

    if (frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)") {
        // Tank
        setComboCurrentIndex(m_aircraft->groundVehicleType,
                             m_aircraft->groundVehicleType->findText("Differential (tank)"));
        m_aircraft->gvMotor1ChannelBox->setEnabled(true);
        m_aircraft->gvMotor2ChannelBox->setEnabled(true);

        m_aircraft->gvMotor1Label->setText("Left motor");
        m_aircraft->gvMotor2Label->setText("Right motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(false);
        m_aircraft->gvSteering2ChannelBox->setEnabled(false);

        m_aircraft->gvSteering2Label->setText("Rear steering");

        m_aircraft->differentialSteeringSlider1->setEnabled(true);
        m_aircraft->differentialSteeringSlider2->setEnabled(true);

        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Left throttle curve");
        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Right throttle curve");
    } else if (frameType == "GroundVehicleMotorcycle" || frameType == "Motorcycle") {
        // Motorcycle
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Motorcycle"));
        m_aircraft->gvMotor1ChannelBox->setEnabled(false);
        m_aircraft->gvMotor2ChannelBox->setEnabled(true);

        m_aircraft->gvMotor1Label->setText("Front motor");
        m_aircraft->gvMotor2Label->setText("Rear motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(true);
        m_aircraft->gvSteering2ChannelBox->setEnabled(true);

        m_aircraft->gvSteering2Label->setText("Balancing");

        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
    } else {
        // Car
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Turnable (car)"));

        m_aircraft->gvMotor1ChannelBox->setEnabled(true);
        m_aircraft->gvMotor2ChannelBox->setEnabled(true);

        m_aircraft->gvMotor1Label->setText("Front motor");
        m_aircraft->gvMotor2Label->setText("Rear motor");

        m_aircraft->gvSteering1ChannelBox->setEnabled(true);
        m_aircraft->gvSteering2ChannelBox->setEnabled(true);

        m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
        m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
    }
}
/**
   Virtual function to refresh the UI widget values
 */
void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
{
    setupUI(frameType);

    UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
    Q_ASSERT(mixer);

    QList<double> curveValues;
    getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues);

    // is at least one of the curve values != 0?
    if (isValidThrottleCurve(&curveValues)) {
        // yes, use the curve we just read from mixersettings
        m_aircraft->groundVehicleThrottle1->initCurve(&curveValues);
    } else {
        // no, init a straight curve
        m_aircraft->groundVehicleThrottle1->initLinearCurve(curveValues.count(), 1.0);
    }

    // Setup all Throttle2 curves for all types of airframes
    getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, &curveValues);

    if (isValidThrottleCurve(&curveValues)) {
        m_aircraft->groundVehicleThrottle2->initCurve(&curveValues);
    } else {
        m_aircraft->groundVehicleThrottle2->initLinearCurve(curveValues.count(), 1.0);
    }
    GUIConfigDataUnion config = getConfigData();

    // THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE
    // Retrieve channel setup values
    setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, config.ground.GroundVehicleThrottle1);
    setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, config.ground.GroundVehicleThrottle2);
    setComboCurrentIndex(m_aircraft->gvSteering1ChannelBox, config.ground.GroundVehicleSteering1);
    setComboCurrentIndex(m_aircraft->gvSteering2ChannelBox, config.ground.GroundVehicleSteering2);

    if (frameType == "GroundVehicleDifferential") {
        // CURRENTLY BROKEN UNTIL WE DECIDE HOW DIFFERENTIAL SHOULD BEHAVE
        // If the vehicle type is "differential", restore the slider setting

        // Find the channel number for Motor1
        // obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
        // Q_ASSERT(obj);
        int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
        if (channel > -1) {
            // If for some reason the actuators were incoherent, we might fail here, hence the check.
            m_aircraft->differentialSteeringSlider1->setValue(
                getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL) * 100);
            m_aircraft->differentialSteeringSlider2->setValue(
                getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH) * 100);
        }
    } else if (frameType == "GroundVehicleMotorcycle") {
        // CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE
// obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
// Q_ASSERT(obj);
// int chMixerNumber = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
// if (chMixerNumber >=0) {
// field = obj->getField(mixerVectors.at(chMixerNumber));
// int ti = field->getElementNames().indexOf("Yaw");
// m_aircraft->differentialSteeringSlider1->setValue(field->getDouble(ti)*100);
//
// ti = field->getElementNames().indexOf("Pitch");
// m_aircraft->differentialSteeringSlider2->setValue(field->getDouble(ti)*100);
// }
    }
}
/**
 Virtual function to setup the UI
 */
void ConfigGroundVehicleWidget::setupUI(SystemSettings::AirframeTypeOptions frameType)
{
	m_aircraft->differentialSteeringMixBox->setHidden(true);			
	//STILL NEEDS WORK
	// Setup the UI
    setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Ground"));
	
	m_aircraft->gvEngineChannelBox->setEnabled(false);
	m_aircraft->gvEngineLabel->setEnabled(false);

	
	m_aircraft->gvAileron1ChannelBox->setEnabled(false);
	m_aircraft->gvAileron1Label->setEnabled(false);
	
	m_aircraft->gvAileron2ChannelBox->setEnabled(false);
	m_aircraft->gvAileron2Label->setEnabled(false);
	
    if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL){ //Tank
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Differential (tank)"));
		m_aircraft->gvMotor1ChannelBox->setEnabled(true);
		m_aircraft->gvMotor1Label->setEnabled(true);
		
		m_aircraft->gvMotor2ChannelBox->setEnabled(true);
		m_aircraft->gvMotor2Label->setEnabled(true);

		m_aircraft->gvMotor1Label->setText("Left motor");
		m_aircraft->gvMotor2Label->setText("Right motor");

		m_aircraft->gvSteering1ChannelBox->setEnabled(false);
		m_aircraft->gvSteering1Label->setEnabled(false);       
		
		m_aircraft->gvSteering2ChannelBox->setEnabled(false);
		m_aircraft->gvSteering2Label->setEnabled(false);

		m_aircraft->gvSteering2Label->setText("Rear steering");

		m_aircraft->differentialSteeringMixBox->setHidden(false);

		m_aircraft->gvThrottleCurve1GroupBox->setTitle("Left throttle curve");
		m_aircraft->gvThrottleCurve2GroupBox->setTitle("Right throttle curve");

	}
    else if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE){ //Motorcycle
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Motorcycle"));
		m_aircraft->gvMotor1ChannelBox->setEnabled(false);
		m_aircraft->gvMotor1Label->setEnabled(false);

		m_aircraft->gvMotor2ChannelBox->setEnabled(true);
		m_aircraft->gvMotor2Label->setEnabled(true);

		m_aircraft->gvMotor1Label->setText("Front motor");
		m_aircraft->gvMotor2Label->setText("Rear motor");

		m_aircraft->gvSteering1ChannelBox->setEnabled(true);
		m_aircraft->gvSteering1Label->setEnabled(true);       
		
		m_aircraft->gvSteering2ChannelBox->setEnabled(true);
		m_aircraft->gvSteering2Label->setEnabled(true);

		m_aircraft->gvSteering2Label->setText("Balancing");

		m_aircraft->differentialSteeringMixBox->setHidden(true);
		
		m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
		m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
	}
	else {//Car
        setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Turnable (car)"));
		
		m_aircraft->gvMotor1ChannelBox->setEnabled(true);
		m_aircraft->gvMotor1Label->setEnabled(true);

		m_aircraft->gvMotor2ChannelBox->setEnabled(true);
		m_aircraft->gvMotor2Label->setEnabled(true);
		
		m_aircraft->gvMotor1Label->setText("Front motor");
		m_aircraft->gvMotor2Label->setText("Rear motor");
		
		m_aircraft->gvSteering1ChannelBox->setEnabled(true);
		m_aircraft->gvSteering1Label->setEnabled(true);       
		
		m_aircraft->gvSteering2ChannelBox->setEnabled(true);
		m_aircraft->gvSteering2Label->setEnabled(true);
		
		m_aircraft->differentialSteeringMixBox->setHidden(true);			
		
		m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
		m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
	}
}
/**
   Virtual function to setup the UI
 */
void ConfigFixedWingWidget::setupUI(QString frameType)
{
    Q_ASSERT(m_aircraft);
    QSvgRenderer *renderer = new QSvgRenderer();
    renderer->load(QString(":/configgadget/images/fixedwing-shapes.svg"));
    planeimg = new QGraphicsSvgItem();
    planeimg->setSharedRenderer(renderer);

    UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
    Q_ASSERT(system);
    QPointer<UAVObjectField> field = system->getField(QString("AirframeType"));

    UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
    Q_ASSERT(mixer);

    if (frameType == "FixedWing" || frameType == "Aileron") {
        planeimg->setElementId("aileron");
        setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Aileron"));
        m_aircraft->fwRudder1ChannelBox->setEnabled(true);
        m_aircraft->fwRudder2ChannelBox->setEnabled(true);
        m_aircraft->fwElevator1ChannelBox->setEnabled(true);
        m_aircraft->fwElevator2ChannelBox->setEnabled(true);
        m_aircraft->fwAileron1ChannelBox->setEnabled(true);
        m_aircraft->fwAileron2ChannelBox->setEnabled(true);

        m_aircraft->fwAileron1Label->setText("Aileron 1");
        m_aircraft->fwAileron2Label->setText("Aileron 2");
        m_aircraft->fwElevator1Label->setText("Elevator 1");
        m_aircraft->fwElevator2Label->setText("Elevator 2");

        m_aircraft->elevonSlider1->setEnabled(false);
        m_aircraft->elevonSlider2->setEnabled(false);
        m_aircraft->elevonSlider3->setEnabled(true);

        m_aircraft->elevonSlider1->setValue(100);
        m_aircraft->elevonSlider2->setValue(100);

        // Get values saved if frameType = current frameType set on board
        if (field->getValue().toString() == "FixedWing") {
            m_aircraft->elevonSlider3->setValue(getMixerValue(mixer, "RollDifferential"));
        } else {
            m_aircraft->elevonSlider3->setValue(0);
        }
    } else if (frameType == "FixedWingElevon" || frameType == "Elevon") {
        planeimg->setElementId("elevon");
        setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Elevon"));
        m_aircraft->fwAileron1Label->setText("Elevon 1");
        m_aircraft->fwAileron2Label->setText("Elevon 2");
        m_aircraft->fwElevator1ChannelBox->setEnabled(false);
        m_aircraft->fwElevator2ChannelBox->setEnabled(false);
        m_aircraft->fwRudder1ChannelBox->setEnabled(true);
        m_aircraft->fwElevator1ChannelBox->setCurrentText("None");
        m_aircraft->fwRudder2ChannelBox->setEnabled(true);
        m_aircraft->fwElevator2ChannelBox->setCurrentText("None");
        m_aircraft->fwElevator1Label->setText("Elevator 1");
        m_aircraft->fwElevator2Label->setText("Elevator 2");
        m_aircraft->elevonLabel1->setText("Roll");
        m_aircraft->elevonLabel2->setText("Pitch");

        m_aircraft->elevonSlider1->setEnabled(true);
        m_aircraft->elevonSlider2->setEnabled(true);
        m_aircraft->elevonSlider3->setEnabled(true);

        // Get values saved if frameType = current frameType set on board
        if (field->getValue().toString() == "FixedWingElevon") {
            m_aircraft->elevonSlider1->setValue(getMixerValue(mixer, "MixerValueRoll"));
            m_aircraft->elevonSlider2->setValue(getMixerValue(mixer, "MixerValuePitch"));
            m_aircraft->elevonSlider3->setValue(getMixerValue(mixer, "RollDifferential"));
        } else {
            m_aircraft->elevonSlider1->setValue(100);
            m_aircraft->elevonSlider2->setValue(100);
            m_aircraft->elevonSlider3->setValue(0);
        }
    } else if (frameType == "FixedWingVtail" || frameType == "Vtail") {
        planeimg->setElementId("vtail");
        setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Vtail"));
        m_aircraft->fwRudder1ChannelBox->setEnabled(false);
        m_aircraft->fwRudder1ChannelBox->setCurrentText("None");
        m_aircraft->fwRudder1ChannelBox->setToolTip("");
        m_aircraft->fwRudder2ChannelBox->setEnabled(false);
        m_aircraft->fwRudder2ChannelBox->setCurrentText("None");
        m_aircraft->fwRudder2ChannelBox->setToolTip("");

        m_aircraft->fwElevator1Label->setText("Vtail 1");
        m_aircraft->fwElevator1ChannelBox->setEnabled(true);

        m_aircraft->fwElevator2Label->setText("Vtail 2");
        m_aircraft->fwElevator2ChannelBox->setEnabled(true);

        m_aircraft->fwAileron1Label->setText("Aileron 1");
        m_aircraft->fwAileron2Label->setText("Aileron 2");
        m_aircraft->elevonLabel1->setText("Rudder");
        m_aircraft->elevonLabel2->setText("Pitch");

        m_aircraft->elevonSlider1->setEnabled(true);
        m_aircraft->elevonSlider2->setEnabled(true);
        m_aircraft->elevonSlider3->setEnabled(true);

        // Get values saved if frameType = current frameType set on board
        if (field->getValue().toString() == "FixedWingVtail") {
            m_aircraft->elevonSlider1->setValue(getMixerValue(mixer, "MixerValueYaw"));
            m_aircraft->elevonSlider2->setValue(getMixerValue(mixer, "MixerValuePitch"));
            m_aircraft->elevonSlider3->setValue(getMixerValue(mixer, "RollDifferential"));
        } else {
            m_aircraft->elevonSlider1->setValue(100);
            m_aircraft->elevonSlider2->setValue(100);
            m_aircraft->elevonSlider3->setValue(0);
        }
    }

    QGraphicsScene *scene = new QGraphicsScene();
    scene->addItem(planeimg);
    scene->setSceneRect(planeimg->boundingRect());
    m_aircraft->planeShape->fitInView(planeimg, Qt::KeepAspectRatio);
    m_aircraft->planeShape->setScene(scene);
}
/**
 Helper function to refresh the UI widget values
 */
void ConfigMultiRotorWidget::refreshAirframeWidgetsValues(SystemSettings::AirframeTypeOptions frameType)
{
    int channel;
    double value;

    GUIConfigDataUnion config = GetConfigData();
    multiGUISettingsStruct multi = config.multi;

    MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager());
    Q_ASSERT(mixerSettings);


    if (frameType == SystemSettings::AIRFRAMETYPE_QUADP)
    {
        // Motors 1/2/3/4 are: N / E / S / W
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.

        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( -qRound(value/1.27) );

            channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27));

        }
    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_QUADX)
    {
        // Motors 1/2/3/4 are: NW / NE / SE / SW
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.
        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( -qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27));

        }

    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_HEXA)
    {
        // Motors 1/2/3 4/5/6 are: N / NE / SE / S / SW / NW

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.

        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( -qRound(value/1.27) );

            //change channels
            channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );

        }


    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_HEXAX)
    {
        // Motors 1/2/3 4/5/6 are: NE / E / SE / SW / W / NW

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.

        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( -qRound(value/1.27) );

            channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
        }
    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_HEXACOAX)
    {
        // Motors 1/2/3 4/5/6 are: NW/W NE/E S/SE

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSE);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.
        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) );

            channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );
        }
    }
    else if (frameType ==  SystemSettings::AIRFRAMETYPE_OCTO ||
             frameType == SystemSettings::AIRFRAMETYPE_OCTOV ||
             frameType == SystemSettings::AIRFRAMETYPE_OCTOCOAXP)
    {
        // Motors 1 to 8 are N / NE / E / etc

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorNW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.
        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            if (frameType == SystemSettings::AIRFRAMETYPE_OCTO) {
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
                m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
                setYawMixLevel( -qRound(value/1.27) );

                //change channels
                channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
                m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
            }
            else if (frameType == SystemSettings::AIRFRAMETYPE_OCTOV) {
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
                m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
                setYawMixLevel( -qRound(value/1.27) );

                //change channels
                channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
                m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
            }
            else if (frameType == SystemSettings::AIRFRAMETYPE_OCTOCOAXP) {
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
                m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
                setYawMixLevel( -qRound(value/1.27) );

                //change channels
                channel = m_aircraft->multiMotorChannelBox3->currentIndex() - 1;
                value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
                m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
            }

        }
    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_OCTOCOAXX)
    {
        // Motors 1 to 8 are N / NE / E / etc

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorN);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorSW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorW);

        // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
        // This assumes that all vectors are identical - if not, the user should use the
        // "custom" setting.
        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_YAW);
            setYawMixLevel( -qRound(value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );
        }
    }
    else if (frameType == SystemSettings::AIRFRAMETYPE_TRI)
    {
        // Motors 1 to 8 are N / NE / E / etc

        setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS);
        setComboCurrentIndex(m_aircraft->triYawChannelBox,multi.TRIYaw);

        channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
        if (channel > -1)
        {
            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_PITCH);
            m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) );

            value = getMixerVectorValue(mixerSettings, channel, MixerSettings::MIXER1VECTOR_ROLL);
            m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );

        }
    }

    drawAirframe(frameType);
}