ComplexMissionItem.h 5.99 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
#include "QmlObjectListModel.h"
18

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

21
class PlanMasterController;
22
class MissionController;
23

24
class ComplexMissionItem : public VisualMissionItem
25 26
{
    Q_OBJECT
27

28
public:
29
    ComplexMissionItem(PlanMasterController* masterController, bool flyView, QObject* parent);
30

31 32
    const ComplexMissionItem& operator=(const ComplexMissionItem& other);

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    Q_PROPERTY(QString              patternName         READ patternName            CONSTANT)
    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)
    Q_PROPERTY(double               minAMSLAltitude     READ minAMSLAltitude        NOTIFY minAMSLAltitudeChanged)  ///< Minimum altitude of all coordinates in item
    Q_PROPERTY(double               maxAMSLAltitude     READ maxAMSLAltitude        NOTIFY maxAMSLAltitudeChanged)  ///< Maximum altitude of all coordinates in item
    Q_PROPERTY(bool                 isSingleItem        READ isSingleItem           CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  flightPathSegments  READ flightPathSegments     CONSTANT)
    Q_PROPERTY(bool                 terrainCollision    READ terrainCollision       NOTIFY terrainCollisionChanged)

    QmlObjectListModel* flightPathSegments  (void) { return &_flightPathSegments; }

    virtual QString patternName(void) const = 0;

    /// @return true: This complex item is colliding with terrain
    virtual bool terrainCollision(void) const { return _cTerrainCollisionSegments != 0; }

    /// @return Minimum altitude for the items within this complex items.
    virtual double minAMSLAltitude(void) const = 0;

    /// @return Maximum altitude for the items within this complex items.
    virtual double maxAMSLAltitude(void) const = 0;
56

57
    /// @return The distance covered the complex mission item in meters.
58
    /// Signals complexDistanceChanged
59
    virtual double complexDistance(void) const = 0;
60

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

68 69 70
    /// @return true: Represents a single coordinate (ex: MissionSettingsItem), false: Represents multiple items (ex: Survey)
    virtual bool isSingleItem(void) const { return false; }

Don Gagne's avatar
Don Gagne committed
71 72 73 74 75 76 77 78
    /// 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);

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

Don Gagne's avatar
Don Gagne committed
81

82 83 84
    /// 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
85
    /// Signals greatestDistanceToChanged
86
    virtual double greatestDistanceTo(const QGeoCoordinate &other) const = 0;
87

Don Gagne's avatar
Don Gagne committed
88 89 90 91 92 93 94 95
    /// 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(); }

96 97
    virtual void addKMLVisuals(KMLPlanDomDocument& domDocument);

98 99
    bool presetsSupported   (void) { return !presetsSettingsGroup().isEmpty(); }
    bool isIncomplete       (void) const { return _isIncomplete; }
Don Gagne's avatar
Don Gagne committed
100

Don Gagne's avatar
Don Gagne committed
101 102 103
    /// This mission item attribute specifies the type of the complex item.
    static const char* jsonComplexItemTypeKey;

104
signals:
105
    void complexDistanceChanged     (void);
106
    void boundingCubeChanged        (void);
107
    void greatestDistanceToChanged  (void);
Don Gagne's avatar
Don Gagne committed
108
    void presetNamesChanged         (void);
109
    void isIncompleteChanged        (void);
110 111 112 113 114 115
    void minAMSLAltitudeChanged     (double minAMSLAltitude);
    void maxAMSLAltitudeChanged     (double maxAMSLAltitude);
    void terrainCollisionChanged    (bool terrainCollision);

protected slots:
    virtual void _segmentTerrainCollisionChanged (bool terrainCollision);
Don Gagne's avatar
Don Gagne committed
116 117

protected:
118 119 120
    void        _savePresetJson         (const QString& name, QJsonObject& presetObject);
    QJsonObject _loadPresetJson         (const QString& name);
    void        _appendFlightPathSegment(const QGeoCoordinate& coord1, double coord1AMSLAlt, const QGeoCoordinate& coord2, double coord2AMSLAlt);
Don Gagne's avatar
Don Gagne committed
121

122 123 124
    bool                _isIncomplete =                 true;
    int                 _cTerrainCollisionSegments =    0;
    QmlObjectListModel  _flightPathSegments;                // Contains FlightPathSegment items
Don Gagne's avatar
Don Gagne committed
125 126 127 128

    QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _presetSettingsKey;
129 130 131

    QGCToolbox* _toolbox;
    SettingsManager* _settingsManager;
132 133

private:
134
};