WimaAreaData.cc 3.36 KB
Newer Older
1 2
#include "WimaAreaData.h"

3 4
WimaAreaData::WimaAreaData(QObject *parent) : QObject(parent) {
  _maxAltitude = 0;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
5 6
}

7 8
WimaAreaData::~WimaAreaData() {}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
9 10 11 12 13
/*!
 * \fn double WimaAreaData::maxAltitude()
 *
 * Returns the maximum altitude at which vehicles are allowed to fly.
 */
14
double WimaAreaData::maxAltitude() const { return _maxAltitude; }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
15 16 17 18 19 20

/*!
 * \fn double WimaAreaData::maxAltitude()
 *
 * Returns the path (vertex list defining the \l {Simple Polygon}).
 */
21
QVariantList WimaAreaData::path() const { return _path; }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
22

23
QGeoCoordinate WimaAreaData::center() const { return _center; }
24

25 26
const QList<QGeoCoordinate> &WimaAreaData::coordinateList() const {
  return _list;
27 28
}

29 30 31 32 33 34 35 36 37 38 39
bool WimaAreaData::containsCoordinate(const QGeoCoordinate &coordinate) const {
  using namespace PlanimetryCalculus;
  using namespace PolygonCalculus;
  using namespace GeoUtilities;

  if (_path.size() > 2) {
    QPolygonF polygon;
    toCartesianList(this->coordinateList(), coordinate, polygon);
    return PlanimetryCalculus::contains(polygon, QPointF(0, 0));
  } else
    return false;
40 41
}

42
void WimaAreaData::append(const QGeoCoordinate &c) {
43 44
  _list.append(c);
  _path.push_back(QVariant::fromValue(c));
45 46
}

47
void WimaAreaData::push_back(const QGeoCoordinate &c) { append(c); }
48

49
void WimaAreaData::clear() {
50 51
  _list.clear();
  _path.clear();
52 53
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
54 55 56
/*!
 * \fn void WimaAreaData::setMaxAltitude(double maxAltitude)
 *
57 58
 * Sets the maximum altitude member to \a maxAltitude and emits the \c
 * maxAltitudeChanged() signal if \a maxAltitude differs from the members value.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
59
 */
60 61 62
void WimaAreaData::setMaxAltitude(double maxAltitude) {
  if (!qFuzzyCompare(_maxAltitude, maxAltitude)) {
    _maxAltitude = maxAltitude;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
63

64 65
    emit maxAltitudeChanged(_maxAltitude);
  }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
66 67
}

68 69 70 71 72 73
void WimaAreaData::setPath(const QVariantList &coordinateList) {
  _path = coordinateList;
  _list.clear();
  for (auto variant : coordinateList) {
    _list.push_back(variant.value<QGeoCoordinate>());
  }
74 75
}

76 77 78
void WimaAreaData::setCenter(const QGeoCoordinate &center) {
  if (_center != center) {
    _center = center;
79

80 81
    emit centerChanged();
  }
82 83
}

84 85 86 87 88
/*!
 * \fn void WimaAreaData::assign(const WimaAreaData &other)
 *
 * Assigns \a other to the invoking object
 */
89 90 91 92
void WimaAreaData::assign(const WimaAreaData &other) {
  setMaxAltitude(other.maxAltitude());
  setPath(other.path());
  setCenter(other.center());
93
}
94

95 96 97 98
void WimaAreaData::assign(const WimaArea &other) {
  setMaxAltitude(other.maxAltitude());
  setPath(other.path());
  setCenter(other.center());
99 100
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
101 102 103
/*!
 * \fn void WimaAreaData::setPath(const QList<QGeoCoordinate> &coordinateList)
 *
104 105
 * Sets the path member to \a coordinateList by copying all entries of \a
 * coordinateList. Emits the \c pathChanged() signal.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
106
 */
107 108
void WimaAreaData::setPath(const QList<QGeoCoordinate> &coordinateList) {
  _list = coordinateList;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
109

110 111 112 113 114
  _path.clear();
  // copy all coordinates to _path
  for (int i = 0; i < coordinateList.size(); i++) {
    _path.append(QVariant::fromValue(coordinateList.value(i)));
  }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
115

116
  emit pathChanged(_path);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
117 118 119 120 121
}

/*!
 * \class WimaArea::WimaAreaData
 * \brief Class to store and exchange data of a \c WimaArea Object.
122 123 124 125
 * Class to store and exchange data of a \c WimaArea Object. In contrast to \c
 * WimaArea this class does not uses the QGC Fact System. It is designed to
 * exchange data between the \c WimaPlaner and the \c WimaController class. And
 * it is the base class for any derived data objects
Valentin Platzgummer's avatar
Valentin Platzgummer committed
126 127 128
 *
 * \sa WimaArea
 */