WimaAreaData.cc 3.2 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 35 36 37 38 39 40 41 42 43
QList<QGeoCoordinate> WimaAreaData::coordinateList() const
{
    QList<QGeoCoordinate> coordinateList;

    for ( auto coorinate : _path)
        coordinateList.append(coorinate.value<QGeoCoordinate>());

    return coordinateList;
}

44 45 46 47 48 49 50 51 52 53 54 55 56 57
bool WimaAreaData::containsCoordinate(const QGeoCoordinate &coordinate) const
{
    using namespace PlanimetryCalculus;
    using namespace PolygonCalculus;
    using namespace GeoUtilities;

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


Valentin Platzgummer's avatar
Valentin Platzgummer committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*!
 * \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);
    }
}

73 74 75 76 77 78
void WimaAreaData::setPath(const QVariantList &coordinateList)
{
    _path.clear();
    _path.append(coordinateList);
}

79 80 81 82 83 84 85 86 87
void WimaAreaData::setCenter(const QGeoCoordinate &center)
{
    if (_center != center) {
        _center = center;

        emit centerChanged();
    }
}

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

100 101 102
void WimaAreaData::assign(const WimaArea &other)
{
    setMaxAltitude(other.maxAltitude());
103 104
    setPath(other.path());    
    setCenter(other.center());
105 106
}

107

Valentin Platzgummer's avatar
Valentin Platzgummer committed
108 109 110 111 112 113 114 115 116 117 118 119
/*!
 * \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)
{
    _path.clear();

    // copy all coordinates to _path
    for(int i = 0; i < coordinateList.size(); i++) {
120
        _path.append(QVariant::fromValue(coordinateList.value(i)));
Valentin Platzgummer's avatar
Valentin Platzgummer committed
121 122 123 124 125 126 127 128 129
    }

    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
130 131
 * 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
132 133 134
 *
 * \sa WimaArea
 */