AutoPilotPlugin.cc 2.36 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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11 12 13 14

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "AutoPilotPlugin.h"
15
#include "QGCApplication.h"
16
#include "FirmwarePlugin.h"
Don Gagne's avatar
Don Gagne committed
17

18 19 20
AutoPilotPlugin::AutoPilotPlugin(Vehicle* vehicle, QObject* parent)
    : QObject(parent)
    , _vehicle(vehicle)
21
    , _firmwarePlugin(vehicle->firmwarePlugin())
DonLakeFlyer's avatar
DonLakeFlyer committed
22
    , _setupComplete(false)
Don Gagne's avatar
Don Gagne committed
23
{
24

25 26
}

27 28
AutoPilotPlugin::~AutoPilotPlugin()
{
29

30 31
}

32 33
void AutoPilotPlugin::_recalcSetupComplete(void)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
34 35
    bool newSetupComplete = true;

36
    for(const QVariant componentVariant: vehicleComponents()) {
DonLakeFlyer's avatar
DonLakeFlyer committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
        VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
        if (component) {
            if (!component->setupComplete()) {
                newSetupComplete = false;
                break;
            }
        } else {
            qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
        }
    }

    if (_setupComplete != newSetupComplete) {
        _setupComplete = newSetupComplete;
        emit setupCompleteChanged(_setupComplete);
    }
52 53 54 55
}

bool AutoPilotPlugin::setupComplete(void)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
56
    return _setupComplete;
57 58
}

59
void AutoPilotPlugin::parametersReadyPreChecks(void)
60
{
61
    _recalcSetupComplete();
62 63

    // Connect signals in order to keep setupComplete up to date
64
    for(const QVariant componentVariant: vehicleComponents()) {
65 66 67 68 69 70 71 72
        VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
        if (component) {
            connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
        } else {
            qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
        }
    }

73
    if (!_setupComplete) {
Don Gagne's avatar
Don Gagne committed
74
        qgcApp()->showMessage(tr("One or more vehicle components require setup prior to flight."));
75

76 77 78
        // Take the user to Vehicle Summary
        qgcApp()->showSetupView();
        qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
Don Gagne's avatar
Don Gagne committed
79
    }
80
}