ComplexMissionItem.h 3.84 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
#include "KMLPlanDomDocument.h"
17

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

20 21
class PlanMasterController;

22
class ComplexMissionItem : public VisualMissionItem
23 24
{
    Q_OBJECT
25

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

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

31 32 33 34
    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)
35

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

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

Don Gagne's avatar
Don Gagne committed
47 48 49 50 51 52 53 54
    /// 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);

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

Don Gagne's avatar
Don Gagne committed
57

58 59 60
    /// 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
61
    /// Signals greatestDistanceToChanged
62
    virtual double greatestDistanceTo(const QGeoCoordinate &other) const = 0;
63

Don Gagne's avatar
Don Gagne committed
64 65 66 67 68 69 70 71
    /// 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(); }

72 73
    virtual void addKMLVisuals(KMLPlanDomDocument& domDocument);

74 75
    bool presetsSupported   (void) { return !presetsSettingsGroup().isEmpty(); }
    bool isIncomplete       (void) const { return _isIncomplete; }
Don Gagne's avatar
Don Gagne committed
76

Don Gagne's avatar
Don Gagne committed
77 78 79
    /// This mission item attribute specifies the type of the complex item.
    static const char* jsonComplexItemTypeKey;

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

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

91
    bool _isIncomplete = true;
Don Gagne's avatar
Don Gagne committed
92 93 94 95

    QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _presetSettingsKey;
96 97 98

    QGCToolbox* _toolbox;
    SettingsManager* _settingsManager;
99
};