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

3 4
WimaAreaData::WimaAreaData(QObject *parent)
    : QObject(parent)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
{
    _maxAltitude = 0;
}

/*!
 * \fn double WimaAreaData::maxAltitude()
 *
 * Returns the maximum altitude at which vehicles are allowed to fly.
 */
double WimaAreaData::maxAltitude() const
{
    return _maxAltitude;
}

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

29 30 31 32 33
QGeoCoordinate WimaAreaData::center() const
{
    return _center;
}

34
const QList<QGeoCoordinate> &WimaAreaData::coordinateList() const
35
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
36
    return _list;
37 38
}

39 40 41 42 43 44 45
bool WimaAreaData::containsCoordinate(const QGeoCoordinate &coordinate) const
{
    using namespace PlanimetryCalculus;
    using namespace PolygonCalculus;
    using namespace GeoUtilities;

    if (_path.size() > 2) {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
46 47
        QPolygonF polygon;
        toCartesianList(this->coordinateList(), coordinate, polygon);
48 49 50 51 52
        return PlanimetryCalculus::contains(polygon, QPointF(0,0));
    } else
        return false;
}

53
void WimaAreaData::append(const QGeoCoordinate &c) {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
54
    _list.append(c);
55 56 57 58
    _path.push_back(QVariant::fromValue(c));
}

void WimaAreaData::clear() {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
59
    _list.clear();
60 61 62
    _path.clear();
}

63

Valentin Platzgummer's avatar
Valentin Platzgummer committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
/*!
 * \fn void WimaAreaData::setMaxAltitude(double maxAltitude)
 *
 * Sets the maximum altitude member to \a maxAltitude and emits the \c maxAltitudeChanged() signal if
 * \a maxAltitude differs from the members value.
 */
void WimaAreaData::setMaxAltitude(double maxAltitude)
{
    if ( !qFuzzyCompare(_maxAltitude, maxAltitude) ) {
        _maxAltitude = maxAltitude;

        emit maxAltitudeChanged(_maxAltitude);
    }
}

79 80
void WimaAreaData::setPath(const QVariantList &coordinateList)
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
81 82 83 84 85
    _path = coordinateList;
    _list.clear();
    for (auto variant : coordinateList) {
        _list.push_back(variant.value<QGeoCoordinate>());
    }
86 87
}

88 89 90 91 92 93 94 95 96
void WimaAreaData::setCenter(const QGeoCoordinate &center)
{
    if (_center != center) {
        _center = center;

        emit centerChanged();
    }
}

97 98 99 100 101
/*!
 * \fn void WimaAreaData::assign(const WimaAreaData &other)
 *
 * Assigns \a other to the invoking object
 */
102 103
void WimaAreaData::assign(const WimaAreaData &other)
{
104 105
    setMaxAltitude(other.maxAltitude());
    setPath(other.path());
106
    setCenter(other.center());
107
}
108

109 110 111
void WimaAreaData::assign(const WimaArea &other)
{
    setMaxAltitude(other.maxAltitude());
112
    setPath(other.path());
113
    setCenter(other.center());
114 115
}

116

Valentin Platzgummer's avatar
Valentin Platzgummer committed
117 118 119 120 121 122 123 124
/*!
 * \fn void WimaAreaData::setPath(const QList<QGeoCoordinate> &coordinateList)
 *
 * Sets the path member to \a coordinateList by copying all entries of \a coordinateList.
 * Emits the \c pathChanged() signal.
 */
void WimaAreaData::setPath(const QList<QGeoCoordinate> &coordinateList)
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
125
    _list = coordinateList;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
126

Valentin Platzgummer's avatar
Valentin Platzgummer committed
127
    _path.clear();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
128 129
    // copy all coordinates to _path
    for(int i = 0; i < coordinateList.size(); i++) {
130
        _path.append(QVariant::fromValue(coordinateList.value(i)));
Valentin Platzgummer's avatar
Valentin Platzgummer committed
131 132 133 134 135 136 137 138 139
    }

    emit pathChanged(_path);
}

/*!
 * \class WimaArea::WimaAreaData
 * \brief Class to store and exchange data of a \c WimaArea Object.
 * Class to store and exchange data of a \c WimaArea Object. In contrast to \c WimaArea this class
140 141
 * 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
142 143 144
 *
 * \sa WimaArea
 */