MeasurementComplexItem.h 6.97 KB
Newer Older
1 2 3
#pragma once

#include <QFutureWatcher>
4
#include <QJsonArray>
5 6 7
#include <QVector>
#include <memory>

Valentin Platzgummer's avatar
Valentin Platzgummer committed
8 9
#include "ComplexMissionItem.h"
#include "QGCQGeoCoordinate.h"
10 11
#include "SettingsFact.h"

12
#include "AreaData.h"
13 14 15 16 17 18 19 20

class RoutingThread;
class RoutingData;

namespace routing {
class GeneratorBase;
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
21
class MeasurementComplexItem : public ComplexMissionItem {
22 23
  Q_OBJECT

24 25
  using PtrGenerator = routing::GeneratorBase *;
  using PtrAreaData = AreaData *;
26
  using PtrRoutingData = std::shared_ptr<RoutingData>;
27
  using PtrWorker = RoutingThread *;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
28
  using Variant = QVariantList;
29

Valentin Platzgummer's avatar
Valentin Platzgummer committed
30
  enum class STATE { IDLE, ROUTING, EDITING };
31 32

public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
33 34 35
  MeasurementComplexItem(PlanMasterController *masterController, bool flyView,
                         const QString &kmlOrShpFile, QObject *parent);
  ~MeasurementComplexItem();
36 37

  Q_PROPERTY(Fact *variant READ variant CONSTANT)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
38
  Q_PROPERTY(Fact *altitude READ variant CONSTANT)
39 40 41 42 43
  Q_PROPERTY(
      QStringList variantNames READ variantNames NOTIFY variantNamesChanged)
  Q_PROPERTY(QStringList generatorNameList READ generatorNameList NOTIFY
                 generatorNameListChanged)
  Q_PROPERTY(bool calculating READ calculating NOTIFY calculatingChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
44
  Q_PROPERTY(bool editing READ editing NOTIFY editingChanged)
45
  Q_PROPERTY(bool idle READ idle NOTIFY idleChanged)
46 47 48
  Q_PROPERTY(
      routing::GeneratorBase *generator READ generator NOTIFY generatorChanged)
  Q_PROPERTY(int generatorIndex READ generatorIndex NOTIFY generatorChanged)
49
  Q_PROPERTY(AreaData *areaData READ areaData NOTIFY areaDataChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
50
  Q_PROPERTY(QVariantList route READ route NOTIFY routeChanged)
51

Valentin Platzgummer's avatar
Valentin Platzgummer committed
52
  Q_INVOKABLE void reverseRoute(void);
53

Valentin Platzgummer's avatar
Valentin Platzgummer committed
54 55 56 57
  // Overrides from ComplexMissionItem
  virtual QString patternName(void) const override final;
  virtual double complexDistance(void) const override final;
  virtual int lastSequenceNumber(void) const final;
58 59
  virtual bool load(const QJsonObject &complexObject, int sequenceNumber,
                    QString &errorString) override final;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
60 61
  virtual double
  greatestDistanceTo(const QGeoCoordinate &other) const override final;
62
  virtual QString mapVisualQML(void) const override final;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
63 64 65 66 67

  // Overrides from VisualMissionItem
  virtual bool dirty(void) const override final;
  virtual bool isSimpleItem(void) const override final;
  virtual bool isStandaloneCoordinate(void) const override final;
68
  virtual bool specifiesCoordinate(void) const override final;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
69 70 71 72 73 74 75 76 77 78 79 80 81
  virtual bool specifiesAltitudeOnly(void) const override final;
  virtual QGeoCoordinate coordinate(void) const override final;
  virtual QGeoCoordinate exitCoordinate(void) const override final;
  virtual int sequenceNumber(void) const override final;
  virtual double specifiedFlightSpeed(void) final override;
  virtual double specifiedGimbalYaw(void) final override;
  virtual double specifiedGimbalPitch(void) final override;
  virtual void appendMissionItems(QList<MissionItem *> &items,
                                  QObject *missionItemParent) final override;
  virtual void setMissionFlightStatus(
      const MissionController::MissionFlightStatus_t &missionFlightStatus)
      final override;
  virtual void applyNewAltitude(double newAltitude) override final;
82
  virtual double additionalTimeDelay(void) const override final;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
83 84 85 86 87
  virtual ReadyForSaveState readyForSaveState(void) const override final;
  virtual bool exitCoordinateSameAsEntry(void) const override final;
  virtual void setDirty(bool dirty) override final;
  virtual void setCoordinate(const QGeoCoordinate &coordinate) override final;
  virtual void setSequenceNumber(int sequenceNumber) override final;
88
  virtual void save(QJsonArray &missionItems) override final;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
89 90 91 92
  virtual double amslEntryAlt(void) const override final;
  virtual double amslExitAlt(void) const override final;
  virtual double minAMSLAltitude(void) const override final;
  virtual double maxAMSLAltitude(void) const override final;
93 94 95
  virtual QString commandDescription(void) const override final;
  virtual QString commandName(void) const override final;
  virtual QString abbreviation(void) const override final;
96 97

  // Generator
98 99 100
  bool addGenerator(const QString &name, routing::GeneratorBase *g);
  bool removeGenerator(const QString &name);
  bool removeGenerator(int index);
101 102
  Q_INVOKABLE bool switchToGenerator(const QString &name);
  Q_INVOKABLE bool switchToGenerator(int index);
103
  Q_INVOKABLE void resetGenerators();
104
  QStringList generatorNameList() const;
105
  routing::GeneratorBase *generator();
106 107 108 109
  const routing::GeneratorBase *generator() const;
  routing::GeneratorBase *generator(int index);
  const routing::GeneratorBase *generator(int index) const;
  int generatorIndex() const;
110

111 112
  // Editing.
  //!
113
  //! \brief startEditing Starts area data editing.
114
  //!
Valentin Platzgummer's avatar
Valentin Platzgummer committed
115
  //! Starts area data editing. Route will not be updated bewteen a call
116 117
  //! sequence of editingStart() and editingStop().
  //!
118
  Q_INVOKABLE void startEditing();
119
  //!
120
  //! \brief stopEditing Stops area editing.
121 122
  //!
  //! Stops area editing. Will reset area data to the state before
Valentin Platzgummer's avatar
Valentin Platzgummer committed
123
  //! editingStart() if it is invalid. Triggers a route update.
124
  //!
125 126 127 128 129
  //! \param doUpdate No route update will be triggered if false, route update
  //! will eventually be triggered if true. \return Returns true if a route
  //! update was triggered, false either.
  //!
  Q_INVOKABLE bool stopEditing(bool doUpdate = true);
130 131 132 133 134 135 136
  //!
  //! \brief abortEditing Aborts area editing.
  //!
  //! Will reset area data to the state before
  //! editingStart().
  //!
  Q_INVOKABLE void abortEditing();
137

Valentin Platzgummer's avatar
Valentin Platzgummer committed
138 139 140
  // Property getters
  const AreaData *areaData() const;
  AreaData *areaData();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
141 142
  QVariantList route();

Valentin Platzgummer's avatar
Valentin Platzgummer committed
143 144 145
  Fact *variant();
  Fact *altitude();
  QStringList variantNames() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
146

Valentin Platzgummer's avatar
Valentin Platzgummer committed
147 148
  bool calculating() const;
  bool editing() const;
149
  bool idle() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
150 151
  bool followTerrain() const;

152 153 154 155 156 157
  static const char *settingsGroup;
  static const char *jsonComplexItemTypeValue;
  static const QString name;

signals:
  void variantNamesChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
158

159 160
  void generatorNameListChanged();
  void generatorChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
161 162

  void calculatingChanged();
163
  void editingChanged();
164
  void idleChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
165

166
  void areaDataChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
167
  void routeChanged();
168 169 170 171

private slots:

  // Worker functions.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
172
  void _storeRoutingData(PtrRoutingData pRoute);
173
  void _updateRoute();
174
  void _changeVariant();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
175
  void _reverseRoute();
176 177

private:
178
  bool _setGenerator(PtrGenerator newG);
179
  void _setState(STATE state);
180
  void _setAreaData(PtrAreaData data);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
181 182
  static bool _calculating(STATE state);
  static bool _editing(STATE state);
183
  static bool _idle(STATE state);
184
  void _updateFlightpathSegments();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
185 186 187 188

  // Hirarcical stuff.
  int _sequenceNumber;
  bool _followTerrain;
189 190 191 192

  // State.
  STATE _state;

193
  // Facts
194
  QMap<QString, FactMetaData *> _metaDataMap;
195
  SettingsFact _altitude;
196 197 198 199
  SettingsFact _variant;
  QStringList _variantNames;

  // Area data
200 201 202
  PtrAreaData _pAreaData;
  PtrAreaData _pEditorData;
  PtrAreaData _pCurrentData;
203 204 205 206 207 208 209 210

  // Generators
  QList<PtrGenerator> _generatorList;
  QStringList _generatorNameList;
  PtrGenerator _pGenerator;

  // Routing.
  QVector<Variant> _variantVector;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
211
  Variant _route;
212 213
  PtrWorker _pWorker;
};