QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AutoPilotPlugin.cc
Go to the documentation of this file.
1#include "AutoPilotPlugin.h"
2#include "FirmwarePlugin.h"
3#include "AppMessages.h"
4#include "QGCApplication.h"
6#include "Vehicle.h"
7#include "VehicleComponent.h"
8
9#include <QtCore/QCoreApplication>
10
11QGC_LOGGING_CATEGORY(AutoPilotPluginLog, "AutoPilotPlugins.AutoPilotPlugin");
12
13AutoPilotPlugin::AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
14 : QObject(parent)
15 , _vehicle(vehicle)
16 , _firmwarePlugin(vehicle->firmwarePlugin())
17{
18 qCDebug(AutoPilotPluginLog) << this;
19}
20
22{
23 qCDebug(AutoPilotPluginLog) << this;
24}
25
26void AutoPilotPlugin::_recalcSetupComplete()
27{
28 bool newSetupComplete = true;
29
30 for (const QVariant &componentVariant : vehicleComponents()) {
31 const VehicleComponent *const component = qobject_cast<const VehicleComponent*>(qvariant_cast<const QObject*>(componentVariant));
32 if (component) {
33 if (!component->setupComplete()) {
34 newSetupComplete = false;
35 break;
36 }
37 } else {
38 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
39 }
40 }
41
42 if (_setupComplete != newSetupComplete) {
43 _setupComplete = newSetupComplete;
45 }
46}
47
49{
50 _recalcSetupComplete();
51
52 // Connect signals in order to keep setupComplete up to date
53 for (QVariant componentVariant : vehicleComponents()) {
54 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject*>(componentVariant));
55 if (component) {
56 (void) connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
57 } else {
58 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
59 }
60 }
61
62 if (!_setupComplete) {
63 // Take the user to Vehicle Config Summary
64 qgcApp()->showVehicleConfig();
65 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
66 QGC::showAppMessage(tr("One or more vehicle components require setup prior to flight."));
67 }
68}
69
71{
72 if (knownVehicleComponent != UnknownVehicleComponent) {
73 for (const QVariant &componentVariant: vehicleComponents()) {
74 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
75 if (component && (component->KnownVehicleComponent() == knownVehicleComponent)) {
76 return component;
77 }
78 }
79 }
80
81 return nullptr;
82}
#define qgcApp()
#define QGC_LOGGING_CATEGORY(name, categoryStr)
virtual void parametersReadyPreChecks()
AutoPilotPlugin(Vehicle *vehicle, QObject *parent=nullptr)
< false: One or more vehicle components require setup
virtual ~AutoPilotPlugin()
void setupCompleteChanged()
Q_INVOKABLE VehicleComponent * findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
Returns the VehicleComponent for the knownVehicleComponent. Returns nullptr if not available.
virtual const QVariantList & vehicleComponents()=0
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
void setupCompleteChanged()
virtual bool setupComplete() const =0
AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent() const
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9