QGroundControlQmlGlobal.h 14.4 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Gus Grubba's avatar
Gus Grubba committed
9

10 11 12 13 14 15 16

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

#ifndef QGroundControlQmlGlobal_H
#define QGroundControlQmlGlobal_H

17
#include "QGCToolbox.h"
dogmaphobic's avatar
dogmaphobic committed
18
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
19
#include "LinkManager.h"
20
#include "SettingsFact.h"
Jimmy Johnson's avatar
Jimmy Johnson committed
21
#include "SimulatedPosition.h"
22
#include "QGCLoggingCategory.h"
23
#include "AppSettings.h"
24
#include "AirspaceManager.h"
25
#include "ADSBVehicleManager.h"
26
#include "QGCPalette.h"
Remek Zajac's avatar
Remek Zajac committed
27
#include "QmlUnitsConversion.h"
Gus Grubba's avatar
Gus Grubba committed
28 29 30
#if defined(QGC_ENABLE_PAIRING)
#include "PairingManager.h"
#endif
31 32 33 34 35
#if defined(QGC_GST_TAISYNC_ENABLED)
#include "TaisyncManager.h"
#else
class TaisyncManager;
#endif
36 37 38 39 40
#if defined(QGC_GST_MICROHARD_ENABLED)
#include "MicrohardManager.h"
#else
class MicrohardManager;
#endif
41

42 43 44 45
#ifdef QT_DEBUG
#include "MockLink.h"
#endif

46 47
class QGCToolbox;

48
class QGroundControlQmlGlobal : public QGCTool
49 50 51 52
{
    Q_OBJECT

public:
53
    QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox);
54 55
    ~QGroundControlQmlGlobal();

56 57 58 59 60 61 62 63 64
    enum AltitudeMode {
        AltitudeModeNone,           // Being used as distance value unrelated to ground (for example distance to structure)
        AltitudeModeRelative,       // MAV_FRAME_GLOBAL_RELATIVE_ALT
        AltitudeModeAbsolute,       // MAV_FRAME_GLOBAL
        AltitudeModeAboveTerrain,   // Absolute altitude above terrain calculated from terrain data
        AltitudeModeTerrainFrame    // MAV_FRAME_GLOBAL_TERRAIN_ALT
    };
    Q_ENUM(AltitudeMode)

65 66
    Q_PROPERTY(QString              appName             READ appName                CONSTANT)

Don Gagne's avatar
Don Gagne committed
67 68
    Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
69
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
Jimmy Johnson's avatar
Jimmy Johnson committed
70
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
71
    Q_PROPERTY(MissionCommandTree*  missionCommandTree  READ missionCommandTree     CONSTANT)
72
    Q_PROPERTY(VideoManager*        videoManager        READ videoManager           CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
73
    Q_PROPERTY(MAVLinkLogManager*   mavlinkLogManager   READ mavlinkLogManager      CONSTANT)
74
    Q_PROPERTY(QGCCorePlugin*       corePlugin          READ corePlugin             CONSTANT)
75
    Q_PROPERTY(SettingsManager*     settingsManager     READ settingsManager        CONSTANT)
76
    Q_PROPERTY(FactGroup*           gpsRtk              READ gpsRtkFactGroup        CONSTANT)
77
    Q_PROPERTY(AirspaceManager*     airspaceManager     READ airspaceManager        CONSTANT)
78
    Q_PROPERTY(ADSBVehicleManager*  adsbVehicleManager  READ adsbVehicleManager     CONSTANT)
79
    Q_PROPERTY(bool                 airmapSupported     READ airmapSupported        CONSTANT)
80 81
    Q_PROPERTY(TaisyncManager*      taisyncManager      READ taisyncManager         CONSTANT)
    Q_PROPERTY(bool                 taisyncSupported    READ taisyncSupported       CONSTANT)
82 83
    Q_PROPERTY(MicrohardManager*    microhardManager    READ microhardManager       CONSTANT)
    Q_PROPERTY(bool                 microhardSupported  READ microhardSupported     CONSTANT)
84
    Q_PROPERTY(bool                 supportsPairing     READ supportsPairing        CONSTANT)
85
    Q_PROPERTY(QGCPalette*          globalPalette       MEMBER _globalPalette       CONSTANT)   // This palette will always return enabled colors
Remek Zajac's avatar
Remek Zajac committed
86
    Q_PROPERTY(QmlUnitsConversion*  unitsConversion     READ unitsConversion        CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
87 88 89
#if defined(QGC_ENABLE_PAIRING)
    Q_PROPERTY(PairingManager*      pairingManager      READ pairingManager         CONSTANT)
#endif
90
    Q_PROPERTY(int      supportedFirmwareCount          READ supportedFirmwareCount CONSTANT)
91
    Q_PROPERTY(int      supportedVehicleCount           READ supportedVehicleCount  CONSTANT)
92
    Q_PROPERTY(bool     px4ProFirmwareSupported         READ px4ProFirmwareSupported CONSTANT)
93
    Q_PROPERTY(int      apmFirmwareSupported            READ apmFirmwareSupported   CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
94

DonLakeFlyer's avatar
DonLakeFlyer committed
95 96 97 98 99 100 101
    Q_PROPERTY(qreal zOrderTopMost              READ zOrderTopMost              CONSTANT) ///< z order for top most items, toolbar, main window sub view
    Q_PROPERTY(qreal zOrderWidgets              READ zOrderWidgets              CONSTANT) ///< z order value to widgets, for example: zoom controls, hud widgetss
    Q_PROPERTY(qreal zOrderMapItems             READ zOrderMapItems             CONSTANT)
    Q_PROPERTY(qreal zOrderVehicles             READ zOrderVehicles             CONSTANT)
    Q_PROPERTY(qreal zOrderWaypointIndicators   READ zOrderWaypointIndicators   CONSTANT)
    Q_PROPERTY(qreal zOrderTrajectoryLines      READ zOrderTrajectoryLines      CONSTANT)
    Q_PROPERTY(qreal zOrderWaypointLines        READ zOrderWaypointLines        CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
102

Gus Grubba's avatar
Gus Grubba committed
103
    //-------------------------------------------------------------------------
104
    // MavLink Protocol
Don Gagne's avatar
Don Gagne committed
105
    Q_PROPERTY(bool     isVersionCheckEnabled   READ isVersionCheckEnabled      WRITE setIsVersionCheckEnabled      NOTIFY isVersionCheckEnabledChanged)
106
    Q_PROPERTY(int      mavlinkSystemID         READ mavlinkSystemID            WRITE setMavlinkSystemID            NOTIFY mavlinkSystemIDChanged)
107
    Q_PROPERTY(bool     hasAPMSupport           READ hasAPMSupport              CONSTANT)
108
    Q_PROPERTY(bool     hasMAVLinkInspector     READ hasMAVLinkInspector        CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
109

110 111
    Q_PROPERTY(QGeoCoordinate flightMapPosition     READ flightMapPosition      WRITE setFlightMapPosition          NOTIFY flightMapPositionChanged)
    Q_PROPERTY(double         flightMapZoom         READ flightMapZoom          WRITE setFlightMapZoom              NOTIFY flightMapZoomChanged)
112
    Q_PROPERTY(double         flightMapInitialZoom  MEMBER _flightMapInitialZoom                                    CONSTANT)                               ///< Zoom level to use when either gcs or vehicle shows up for first time
Don Gagne's avatar
Don Gagne committed
113

Don Gagne's avatar
Don Gagne committed
114 115 116 117
    Q_PROPERTY(QString  parameterFileExtension  READ parameterFileExtension CONSTANT)
    Q_PROPERTY(QString  missionFileExtension    READ missionFileExtension   CONSTANT)
    Q_PROPERTY(QString  telemetryFileExtension  READ telemetryFileExtension CONSTANT)

118 119
    Q_PROPERTY(QString qgcVersion       READ qgcVersion         CONSTANT)
    Q_PROPERTY(bool    skipSetupPage    READ skipSetupPage      WRITE setSkipSetupPage NOTIFY skipSetupPageChanged)
120

121 122 123 124 125
    Q_INVOKABLE void    saveGlobalSetting       (const QString& key, const QString& value);
    Q_INVOKABLE QString loadGlobalSetting       (const QString& key, const QString& defaultValue);
    Q_INVOKABLE void    saveBoolGlobalSetting   (const QString& key, bool value);
    Q_INVOKABLE bool    loadBoolGlobalSetting   (const QString& key, bool defaultValue);

126 127
    Q_INVOKABLE void    deleteAllSettingsNextBoot       () { _app->deleteAllSettingsNextBoot(); }
    Q_INVOKABLE void    clearDeleteAllSettingsNextBoot  () { _app->clearDeleteAllSettingsNextBoot(); }
128

129 130 131 132
    Q_INVOKABLE void    startPX4MockLink            (bool sendStatusText);
    Q_INVOKABLE void    startGenericMockLink        (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduCopterMockLink  (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduPlaneMockLink   (bool sendStatusText);
133
    Q_INVOKABLE void    startAPMArduSubMockLink     (bool sendStatusText);
134
    Q_INVOKABLE void    startAPMArduRoverMockLink   (bool sendStatusText);
Don Gagne's avatar
Don Gagne committed
135
    Q_INVOKABLE void    stopOneMockLink             (void);
136

137 138 139 140
    /// Returns the list of available logging category names.
    Q_INVOKABLE QStringList loggingCategories(void) const { return QGCLoggingCategoryRegister::instance()->registeredCategories(); }

    /// Turns on/off logging for the specified category. State is saved in app settings.
Don Gagne's avatar
Don Gagne committed
141
    Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable) { QGCLoggingCategoryRegister::instance()->setCategoryLoggingOn(category, enable); }
142 143

    /// Returns true if logging is turned on for the specified category.
Don Gagne's avatar
Don Gagne committed
144
    Q_INVOKABLE bool categoryLoggingOn(const QString& category) { return QGCLoggingCategoryRegister::instance()->categoryLoggingOn(category); }
145 146 147 148

    /// Updates the logging filter rules after settings have changed
    Q_INVOKABLE void updateLoggingFilterRules(void) { QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(QString()); }

149 150
    Q_INVOKABLE bool linesIntersect(QPointF xLine1, QPointF yLine1, QPointF xLine2, QPointF yLine2);

151
    // Property accesors
Gus Grubba's avatar
Gus Grubba committed
152

153
    QString                 appName             ()  { return qgcApp()->applicationName(); }
154 155 156 157 158 159 160 161 162
    LinkManager*            linkManager         ()  { return _linkManager; }
    MultiVehicleManager*    multiVehicleManager ()  { return _multiVehicleManager; }
    QGCMapEngineManager*    mapEngineManager    ()  { return _mapEngineManager; }
    QGCPositionManager*     qgcPositionManger   ()  { return _qgcPositionManager; }
    MissionCommandTree*     missionCommandTree  ()  { return _missionCommandTree; }
    VideoManager*           videoManager        ()  { return _videoManager; }
    MAVLinkLogManager*      mavlinkLogManager   ()  { return _mavlinkLogManager; }
    QGCCorePlugin*          corePlugin          ()  { return _corePlugin; }
    SettingsManager*        settingsManager     ()  { return _settingsManager; }
163
    FactGroup*              gpsRtkFactGroup     ()  { return _gpsRtkFactGroup; }
164
    AirspaceManager*        airspaceManager     ()  { return _airspaceManager; }
165
    ADSBVehicleManager*     adsbVehicleManager  ()  { return _adsbVehicleManager; }
Remek Zajac's avatar
Remek Zajac committed
166
    QmlUnitsConversion*     unitsConversion     ()  { return &_unitsConversion; }
Gus Grubba's avatar
Gus Grubba committed
167
#if defined(QGC_ENABLE_PAIRING)
168
    bool                    supportsPairing     ()  { return true; }
Gus Grubba's avatar
Gus Grubba committed
169
    PairingManager*         pairingManager      ()  { return _pairingManager; }
170 171
#else
    bool                    supportsPairing     ()  { return false; }
Gus Grubba's avatar
Gus Grubba committed
172
#endif
173 174
    static QGeoCoordinate   flightMapPosition   ()  { return _coord; }
    static double           flightMapZoom       ()  { return _zoom; }
175

176 177
    TaisyncManager*         taisyncManager      ()  { return _taisyncManager; }
#if defined(QGC_GST_TAISYNC_ENABLED)
178
    bool                    taisyncSupported    ()  { return true; }
179 180 181 182
#else
    bool                    taisyncSupported    () { return false; }
#endif

183
    MicrohardManager*       microhardManager    () { return _microhardManager; }
184 185 186 187 188 189
#if defined(QGC_GST_TAISYNC_ENABLED)
    bool                    microhardSupported  () { return true; }
#else
    bool                    microhardSupported  () { return false; }
#endif

DonLakeFlyer's avatar
DonLakeFlyer committed
190 191 192 193 194 195 196
    qreal zOrderTopMost             () { return 1000; }
    qreal zOrderWidgets             () { return 100; }
    qreal zOrderMapItems            () { return 50; }
    qreal zOrderWaypointIndicators  () { return 50; }
    qreal zOrderVehicles            () { return 49; }
    qreal zOrderTrajectoryLines     () { return 48; }
    qreal zOrderWaypointLines       () { return 47; }
Gus Grubba's avatar
Gus Grubba committed
197

Don Gagne's avatar
Don Gagne committed
198
    bool    isVersionCheckEnabled   () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
199
    int     mavlinkSystemID         () { return _toolbox->mavlinkProtocol()->getSystemId(); }
200 201 202 203 204
#if defined(NO_ARDUPILOT_DIALECT)
    bool    hasAPMSupport           () { return false; }
#else
    bool    hasAPMSupport           () { return true; }
#endif
205

206 207 208 209 210 211
#if defined(QGC_ENABLE_MAVLINK_INSPECTOR)
    bool    hasMAVLinkInspector     () { return true; }
#else
    bool    hasMAVLinkInspector     () { return false; }
#endif

212
    int     supportedFirmwareCount  ();
213
    int     supportedVehicleCount   ();
214 215
    bool    px4ProFirmwareSupported ();
    bool    apmFirmwareSupported    ();
216 217
    bool    skipSetupPage           () { return _skipSetupPage; }
    void    setSkipSetupPage        (bool skip);
Gus Grubba's avatar
Gus Grubba committed
218

Don Gagne's avatar
Don Gagne committed
219
    void    setIsVersionCheckEnabled    (bool enable);
220
    void    setMavlinkSystemID          (int  id);
221 222
    void    setFlightMapPosition        (QGeoCoordinate& coordinate);
    void    setFlightMapZoom            (double zoom);
dogmaphobic's avatar
dogmaphobic committed
223

224 225 226
    QString parameterFileExtension  (void) const  { return AppSettings::parameterFileExtension; }
    QString missionFileExtension    (void) const    { return AppSettings::missionFileExtension; }
    QString telemetryFileExtension  (void) const  { return AppSettings::telemetryFileExtension; }
Don Gagne's avatar
Don Gagne committed
227

228
    QString qgcVersion              (void) const;
229

230 231 232 233 234
#if defined(QGC_AIRMAP_ENABLED)
    bool    airmapSupported() { return true; }
#else
    bool    airmapSupported() { return false; }
#endif
235

236 237 238
    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

dogmaphobic's avatar
dogmaphobic committed
239 240
signals:
    void isMultiplexingEnabledChanged   (bool enabled);
Don Gagne's avatar
Don Gagne committed
241
    void isVersionCheckEnabledChanged   (bool enabled);
242
    void mavlinkSystemIDChanged         (int id);
243
    void flightMapPositionChanged       (QGeoCoordinate flightMapPosition);
244
    void flightMapZoomChanged           (double flightMapZoom);
245
    void skipSetupPageChanged           ();
dogmaphobic's avatar
dogmaphobic committed
246

247
private:
248 249 250 251 252 253 254 255 256 257 258 259 260 261
    double                  _flightMapInitialZoom   = 17.0;
    LinkManager*            _linkManager            = nullptr;
    MultiVehicleManager*    _multiVehicleManager    = nullptr;
    QGCMapEngineManager*    _mapEngineManager       = nullptr;
    QGCPositionManager*     _qgcPositionManager     = nullptr;
    MissionCommandTree*     _missionCommandTree     = nullptr;
    VideoManager*           _videoManager           = nullptr;
    MAVLinkLogManager*      _mavlinkLogManager      = nullptr;
    QGCCorePlugin*          _corePlugin             = nullptr;
    FirmwarePluginManager*  _firmwarePluginManager  = nullptr;
    SettingsManager*        _settingsManager        = nullptr;
    FactGroup*              _gpsRtkFactGroup        = nullptr;
    AirspaceManager*        _airspaceManager        = nullptr;
    TaisyncManager*         _taisyncManager         = nullptr;
262
    MicrohardManager*       _microhardManager       = nullptr;
263
    ADSBVehicleManager*     _adsbVehicleManager     = nullptr;
264
    QGCPalette*             _globalPalette          = nullptr;
Remek Zajac's avatar
Remek Zajac committed
265
    QmlUnitsConversion      _unitsConversion;
Gus Grubba's avatar
Gus Grubba committed
266 267 268
#if defined(QGC_ENABLE_PAIRING)
    PairingManager*         _pairingManager         = nullptr;
#endif
269 270

    bool                    _skipSetupPage          = false;
271 272 273 274 275

    static const char* _flightMapPositionSettingsGroup;
    static const char* _flightMapPositionLatitudeSettingsKey;
    static const char* _flightMapPositionLongitudeSettingsKey;
    static const char* _flightMapZoomSettingsKey;
276 277 278

    static QGeoCoordinate   _coord;
    static double           _zoom;
279 280 281
};

#endif