APMAirframeComponent.cc 3.07 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
{
46 47
    return tr("Airframe Setup is used to select the airframe which matches your vehicle. "
              "You can also the load default parameter values associated with known vehicle types.");
48 49 50 51
}

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

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

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

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

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

    return list;
82 83 84 85
}

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

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