WimaPlaner.h 5.65 KB
Newer Older
1
#pragma once
2

3
#include "QmlObjectListModel.h"
4
#include <QObject>
5
#include <QSharedPointer>
6

7 8 9 10
#include "Geometry/WimaCorridor.h"
#include "Geometry/WimaCorridorData.h"
#include "Geometry/WimaJoinedArea.h"
#include "Geometry/WimaJoinedAreaData.h"
11 12 13 14
#include "Geometry/WimaMeasurementArea.h"
#include "Geometry/WimaMeasurementAreaData.h"
#include "Geometry/WimaServiceArea.h"
#include "Geometry/WimaServiceAreaData.h"
15
#include "WimaPlanData.h"
16 17

#include "JsonHelper.h"
18

19 20 21
class MissionController;
class PlanMasterController;
class WimaBridge;
22

23 24
class WimaPlaner : public QObject {
  Q_OBJECT
25

26
  enum FileType { WimaFile, PlanFile };
27

28
public:
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  WimaPlaner(QObject *parent = nullptr);
  template <class T> WimaPlaner(T t, QObject *parent = nullptr) = delete;
  template <class T> WimaPlaner(T t) = delete;

  Q_PROPERTY(PlanMasterController *masterController READ masterController WRITE
                 setMasterController NOTIFY masterControllerChanged)
  Q_PROPERTY(MissionController *missionController READ missionController WRITE
                 setMissionController NOTIFY missionControllerChanged)
  Q_PROPERTY(QmlObjectListModel *visualItems READ visualItems NOTIFY
                 visualItemsChanged)
  Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE
                 setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged)
  Q_PROPERTY(QString currentFile READ currentFile NOTIFY currentFileChanged)
  Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT)
  Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT)
  Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT)
  Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT)
  Q_PROPERTY(WimaBridge *wimaBridge READ wimaBridge WRITE setWimaBridge NOTIFY
                 wimaBridgeChanged)
48 49
  Q_PROPERTY(bool synchronized READ synchronized NOTIFY synchronizedChanged)
  Q_PROPERTY(bool needsUpdate READ needsUpdate NOTIFY needsUpdateChanged)
50 51

  // Property accessors
52 53
  PlanMasterController *masterController(void);
  MissionController *missionController(void);
54
  QmlObjectListModel *visualItems(void);
55 56
  int currentPolygonIndex(void) const;
  QString currentFile(void) const;
57 58
  QStringList loadNameFilters(void) const;
  QStringList saveNameFilters(void) const;
59
  QString fileExtension(void) const;
60
  QGeoCoordinate joinedAreaCenter(void) const;
61
  WimaBridge *wimaBridge(void);
62 63
  bool synchronized();
  bool needsUpdate();
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

  // Property setters
  void setMasterController(PlanMasterController *masterController);
  void setMissionController(MissionController *missionController);
  /// Sets the integer index pointing to the current polygon. Current polygon is
  /// set interactive.
  void setCurrentPolygonIndex(int index);
  void setWimaBridge(WimaBridge *bridge);

  Q_INVOKABLE WimaPlaner *thisPointer();
  Q_INVOKABLE bool addMeasurementArea();
  /// Removes an area from _visualItems
  /// @param index Index of the area to be removed
  Q_INVOKABLE void removeArea(int index);
  Q_INVOKABLE bool addServiceArea();
  Q_INVOKABLE bool addCorridor();
  /// Remove all areas from WimaPlaner and all mission items from
  /// MissionController
  Q_INVOKABLE void removeAll();
  /// Recalculates vehicle corridor, flight path, etc.
84
  Q_INVOKABLE bool update();
85
  /// Pushes the generated mission data to the wimaController.
86
  Q_INVOKABLE void synchronize();
87
  Q_INVOKABLE bool readyForSynchronization();
88 89 90 91 92 93 94 95 96 97 98 99
  Q_INVOKABLE void saveToCurrent();
  Q_INVOKABLE void saveToFile(const QString &filename);
  Q_INVOKABLE bool loadFromCurrent();
  Q_INVOKABLE bool loadFromFile(const QString &filename);
  Q_INVOKABLE void resetAllInteractive(void);
  Q_INVOKABLE void setInteractive(void);

  QJsonDocument saveToJson(FileType fileType);
  // static Members
  static const char *wimaFileExtension;
  static const char *areaItemsName;
  static const char *missionItemsName;
100 101

signals:
102 103 104 105 106 107
  void masterControllerChanged(void);
  void missionControllerChanged(void);
  void visualItemsChanged(void);
  void currentPolygonIndexChanged(int index);
  void currentFileChanged();
  void wimaBridgeChanged();
108 109
  void synchronizedChanged(void);
  void needsUpdateChanged(void);
110 111

private slots:
112
  void updatePolygonInteractivity(int index);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
113
#ifndef NDEBUG
114
  void autoLoadMission(void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
115
#endif
116

117 118
private:
signals:
119 120
  void joinedAreaValidChanged();

121
private:
122
  // Member Functions
123
  QSharedPointer<WimaPlanData> toPlanData();
124 125 126 127
  bool shortestPath(const QGeoCoordinate &start,
                    const QGeoCoordinate &destination,
                    QVector<QGeoCoordinate> &path);
  void setNeedsUpdate(bool needsUpdate);
128 129 130 131 132

  // Member Variables
  PlanMasterController *_masterController;
  MissionController *_missionController;
  int _currentAreaIndex;
133 134 135 136
  QString _currentFile;
  // container for data exchange with WimaController
  WimaBridge *_wimaBridge;

137
  bool _joinedAreaValid;
138
  WimaMeasurementArea _measurementArea;
139
  bool _mAreaChanged;
140
  WimaServiceArea _serviceArea;
141
  bool _sAreaChanged;
142
  WimaCorridor _corridor;
143
  bool _corridorChanged;
144 145 146 147 148 149 150 151
  // contains all visible areas
  QmlObjectListModel _visualItems;
  // joined area fromed by _measurementArea, _serviceArea, _corridor
  WimaJoinedArea _joinedArea;
  // path from takeoff to first measurement point
  unsigned long _arrivalPathLength;
  // path from last measurement point to land
  unsigned long _returnPathLength;
152

153 154
  CircularSurvey *_TSComplexItem;
  bool _surveyChanged;
155
  // sync stuff
156 157 158
  bool _synchronized; // true if planData is synchronized with
                      // wimaController
  bool _needsUpdate;  // gets set by updateMission and calcArrivalAndReturnPath
159

Valentin Platzgummer's avatar
Valentin Platzgummer committed
160
#ifndef NDEBUG
161 162
  QTimer _autoLoadTimer; // timer to auto load mission after some time, prevents
                         // seg. faults
Valentin Platzgummer's avatar
Valentin Platzgummer committed
163
#endif
164
};