ComplexMissionItem.h 3.74 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.
 *
 ****************************************************************************/
9

10
#pragma once
11

12
#include "VisualMissionItem.h"
13
#include "QGCGeo.h"
14 15
#include "QGCToolbox.h"
#include "SettingsManager.h"
16

Don Gagne's avatar
Don Gagne committed
17 18
#include <QSettings>

19 20
class PlanMasterController;

21
class ComplexMissionItem : public VisualMissionItem
22 23
{
    Q_OBJECT
24

25
public:
26
    ComplexMissionItem(PlanMasterController* masterController, bool flyView, QObject* parent);
27

28 29
    const ComplexMissionItem& operator=(const ComplexMissionItem& other);

30 31 32 33
    Q_PROPERTY(double       complexDistance     READ complexDistance    NOTIFY complexDistanceChanged)
    Q_PROPERTY(bool         presetsSupported    READ presetsSupported   CONSTANT)
    Q_PROPERTY(QStringList  presetNames         READ presetNames        NOTIFY presetNamesChanged)
    Q_PROPERTY(bool         isIncomplete        READ isIncomplete       NOTIFY isIncompleteChanged)
34

35
    /// @return The distance covered the complex mission item in meters.
36
    /// Signals complexDistanceChanged
37
    virtual double complexDistance(void) const = 0;
38

39 40
    /// Load the complex mission item from Json
    ///     @param complexObject Complex mission item json object
Don Gagne's avatar
Don Gagne committed
41
    ///     @param sequenceNumber Sequence number for first MISSION_ITEM in survey
42 43
    ///     @param[out] errorString Error if load fails
    /// @return true: load success, false: load failed, errorString set
Don Gagne's avatar
Don Gagne committed
44
    virtual bool load(const QJsonObject& complexObject, int sequenceNumber, QString& errorString) = 0;
45

Don Gagne's avatar
Don Gagne committed
46 47 48 49 50 51 52 53
    /// Loads the specified preset into the complex item.
    ///     @param name Preset name.
    Q_INVOKABLE virtual void loadPreset(const QString& name);

    /// Saves the current state of the complex item as the named preset.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    Q_INVOKABLE virtual void savePreset(const QString& name);

Don Gagne's avatar
Don Gagne committed
54 55
     Q_INVOKABLE void deletePreset(const QString& name);

Don Gagne's avatar
Don Gagne committed
56

57 58 59
    /// Get the point of complex mission item furthest away from a coordinate
    ///     @param other QGeoCoordinate to which distance is calculated
    /// @return the greatest distance from any point of the complex item to some coordinate
60
    /// Signals greatestDistanceToChanged
61
    virtual double greatestDistanceTo(const QGeoCoordinate &other) const = 0;
62

Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69 70
    /// Returns the list of currently saved presets for this complex item type.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    virtual QStringList presetNames(void);

    /// Returns the name of the settings group for presets.
    ///     Empty string signals no support for presets.
    virtual QString presetsSettingsGroup(void) { return QString(); }

71 72
    bool presetsSupported   (void) { return !presetsSettingsGroup().isEmpty(); }
    bool isIncomplete       (void) const { return _isIncomplete; }
Don Gagne's avatar
Don Gagne committed
73

Don Gagne's avatar
Don Gagne committed
74 75 76
    /// This mission item attribute specifies the type of the complex item.
    static const char* jsonComplexItemTypeKey;

77
signals:
78
    void complexDistanceChanged     (void);
79
    void boundingCubeChanged        (void);
80
    void greatestDistanceToChanged  (void);
Don Gagne's avatar
Don Gagne committed
81
    void presetNamesChanged         (void);
82
    void isIncompleteChanged        (void);
Don Gagne's avatar
Don Gagne committed
83 84 85 86 87

protected:
    void        _savePresetJson (const QString& name, QJsonObject& presetObject);
    QJsonObject _loadPresetJson (const QString& name);

88
    bool _isIncomplete = true;
Don Gagne's avatar
Don Gagne committed
89 90 91 92

    QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _presetSettingsKey;
93 94 95

    QGCToolbox* _toolbox;
    SettingsManager* _settingsManager;
96
};