APMAirframeComponent.cc 2.97 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10
#include "APMAirframeComponent.h"
11
#include "ArduCopterFirmwarePlugin.h"
12
#include "ParameterManager.h"
13

14 15 16
const char* APMAirframeComponent::_oldFrameParam = "FRAME";
const char* APMAirframeComponent::_newFrameParam = "FRAME_CLASS";

17
APMAirframeComponent::APMAirframeComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
18
    : VehicleComponent(vehicle, autopilot, parent)
19
    , _requiresFrameSetup(false)
Don Gagne's avatar
Don Gagne committed
20
    , _name(tr("Airframe"))
21
{
22
    if (qobject_cast<ArduCopterFirmwarePlugin*>(_vehicle->firmwarePlugin()) != NULL) {
23
        ParameterManager* paramMgr = _vehicle->parameterManager();
24
        _requiresFrameSetup = true;
25 26 27 28 29 30 31 32 33 34
        if (paramMgr->parameterExists(FactSystem::defaultComponentId, _oldFrameParam)) {
            _useNewFrameParam = false;
            _frameParamFact = paramMgr->getParameter(FactSystem::defaultComponentId, _oldFrameParam);
            MAV_TYPE vehicleType = vehicle->vehicleType();
            if (vehicleType == MAV_TYPE_TRICOPTER || vehicleType == MAV_TYPE_HELICOPTER) {
                _requiresFrameSetup = false;
            }
        } else {
            _useNewFrameParam = true;
            _frameParamFact = paramMgr->getParameter(FactSystem::defaultComponentId, _newFrameParam);
35 36
        }
    }
37 38 39 40 41 42 43 44 45
}

QString APMAirframeComponent::name(void) const
{
    return _name;
}

QString APMAirframeComponent::description(void) const
{
Don Gagne's avatar
Don Gagne committed
46
    return tr("Airframe Setup is used to select the airframe which matches your vehicle.");
47 48 49 50
}

QString APMAirframeComponent::iconResource(void) const
{
51
    return QStringLiteral("/qmlimages/AirframeComponentIcon.png");
52 53 54 55
}

bool APMAirframeComponent::requiresSetup(void) const
{
56
    return _requiresFrameSetup;
57 58 59 60
}

bool APMAirframeComponent::setupComplete(void) const
{
61
    if (_requiresFrameSetup) {
62 63 64 65 66
        if (_useNewFrameParam) {
            return _frameParamFact->rawValue().toInt() > 0;
        } else {
            return _frameParamFact->rawValue().toInt() >= 0;
        }
67 68 69
    } else {
        return true;
    }
70 71 72 73
}

QStringList APMAirframeComponent::setupCompleteChangedTriggerList(void) const
{
74 75
    QStringList list;

76
    if (_requiresFrameSetup) {
77
        list << (_useNewFrameParam ? _newFrameParam : _oldFrameParam);
78 79 80
    }

    return list;
81 82 83 84
}

QUrl APMAirframeComponent::setupSource(void) const
{
85
    if (_requiresFrameSetup) {
86
        return QUrl::fromUserInput(QStringLiteral("qrc:/qml/APMAirframeComponent.qml"));
87 88 89
    } else {
        return QUrl();
    }
90 91 92 93
}

QUrl APMAirframeComponent::summaryQmlSource(void) const
{
94
    if (_requiresFrameSetup) {
95
        return QUrl::fromUserInput(QStringLiteral("qrc:/qml/APMAirframeComponentSummary.qml"));
96 97 98
    } else {
        return QUrl();
    }
99
}