WimaPlaner.h 5.61 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 88 89 90 91 92 93 94 95 96 97 98
  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;
99 100

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

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

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

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

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

136
  bool _joinedAreaValid;
137
  WimaMeasurementArea _measurementArea;
138
  bool _mAreaChanged;
139
  WimaServiceArea _serviceArea;
140
  bool _sAreaChanged;
141
  WimaCorridor _corridor;
142
  bool _corridorChanged;
143 144 145 146 147 148 149 150
  // 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;
151

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

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