WimaArea.h 5.82 KB
Newer Older
1
#pragma once
2

3
#include "QGCMapPolygon.h"
4
#include "QGCMapPolyline.h"
5 6 7
#include "Vehicle.h"
#include "qobject.h"
#include "WimaVehicle.h"
8 9 10 11
#include "WimaArea.h"
#include <QLineF>
#include <QPointF>
#include "QGCGeo.h"
12
#include <QPair>
13

14
class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas
15
{
16
    Q_OBJECT
17
public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
18 19 20 21
    WimaArea();
    WimaArea(QObject* parent);
    WimaArea(const QGCMapPolygon& other, QObject* parent);
    WimaArea(const WimaArea& other, QObject* parent);
22 23 24 25 26 27 28 29 30 31 32 33



    Q_PROPERTY(double                   maxAltitude                 READ maxAltitude                WRITE setMaxAltitude                NOTIFY maxAltitudeChanged)
    Q_PROPERTY(QString                  mapVisualQML                READ mapVisualQML                                                   CONSTANT)
    Q_PROPERTY(QString                  editorQML                   READ editorQML                                                      CONSTANT)
    Q_PROPERTY(WimaVehicle*             vehicle                     READ vehicle                    WRITE setVehicle                    NOTIFY vehicleChanged)

    //Property accessors
    double                  maxAltitude         (void) const    { return _maxAltitude;}
    WimaVehicle*            vehicle             (void) const    { return _wimaVehicle;}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
34 35
    virtual QString                 mapVisualQML    (void) const { return "WimaAreaMapVisual.qml";}
    virtual QString                 editorQML       (void) const { return "WimaAreaEditor.qml";}
36 37 38 39 40 41 42 43 44 45 46

    //Property setters
    void        setMaxAltitude     (double alt);
    void        setVehicle         (WimaVehicle* vehicle);

    // Member Methodes
    /*template <class T>
    QList<T*>*      splitArea        (WimaArea *polygonToSplitt, int numberOfFractions); // use QScopedPointer to store return value
    template <class T>
    QList<T*>*      splitArea        (int numberOfFractions); // use QScopedPointer to store return value*/
    //iterates over all vertices in _polygon and returns the index of that one closest to coordinate
47
    int             getClosestVertexIndex   (const QGeoCoordinate& coordinate) const;
48
    //iterates over all vertices in _polygon and returns that one closest to coordinate
49
    QGeoCoordinate  getClosestVertex        (const QGeoCoordinate& coordinate) const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
50
    QGCMapPolygon   toQGCPolygon            (const WimaArea& poly) const;
51
    static void     join                    (QList<WimaArea*>* polyList,  WimaArea* joinedPoly);// change to & notation
52 53 54
    /// joins the poly1 and poly2 if possible, joins the polygons to form a simple polygon (no holes)
    /// see https://en.wikipedia.org/wiki/Simple_polygon
    /// @return the joined polygon of poly1 and poly2 if possible, poly1 else
Valentin Platzgummer's avatar
Valentin Platzgummer committed
55 56
    static void     join                    (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
    void            join                    (WimaArea &poly);
57 58
    bool            isDisjunct              (QList<WimaArea*>* polyList);// change to & notation, if necessary
    bool            isDisjunct              (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
59 60
    /// calculates the next polygon vertex index
    /// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else
61
    int             nextVertexIndex         (int index) const;
62 63
    /// calculates the previous polygon vertex index
    /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
64
    int             previousVertexIndex     (int index) const;
65 66 67
    /// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected)
    /// @param line1 line containing two coordinates, height not taken into account
    /// @param line2 line containing two coordinates, height not taken into account
68 69
    /// @param intersectionPt Coordinate item to store intersection pt. in.
    /// @return false on error or no intersection, true else
70
    static bool            intersects(const QGCMapPolyline& line1, const QGCMapPolyline& line2, QGeoCoordinate& intersectionPt);
71 72
    /// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected)
    /// @param line line containing two coordinates, height not taken into account
73 74 75
    /// @param intersectionList Empty list to store intersection points in.
    /// @param neighbourList Empty list to store the indices of the neighbours (the two Vertices of poly with the smallest distance to the intersection pt.)
    /// @return false on error or no intersection, true else
76
    static bool            intersects(const QGCMapPolyline& line, const WimaArea& poly, QList<QGeoCoordinate>& intersectionList, QList<QPair<int, int>>& neighbourlist);
77 78
    /// calculates the distance between to geo coordinates, returns the distance if the path lies within the polygon and inf. else.
    /// @return the distance if the path lies within the polygon and inf. else.
79
    static double          distInsidePoly(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly);
80
    /// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
81
    static void            dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
82

83 84 85 86
    void saveToJson(QJsonObject& jsonObject);
    bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);

    // static Members
87 88
    // Accurracy used to compute isDisjunct
    static const double numericalAccuracy;
89 90 91
    static const char*  maxAltitudeName;
    static const char*  wimaAreaName;
    static const char*  areaTypeName;
92 93 94 95 96 97 98 99 100

signals:
    void    maxAltitudeChanged      (void);
    void    vehicleChanged          (void);


protected:
    double                  _maxAltitude;
    WimaVehicle*            _wimaVehicle;
101 102
};

103