WimaArea.h 5.89 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:
18 19 20
    WimaArea(QObject* parent = nullptr);
    WimaArea(const WimaArea& other, QObject* parent = nullptr);
    WimaArea& operator=(WimaArea other);
21 22 23 24 25 26 27 28 29


    Q_PROPERTY(double                   maxAltitude                 READ maxAltitude                WRITE setMaxAltitude                NOTIFY maxAltitudeChanged)
    Q_PROPERTY(QString                  mapVisualQML                READ mapVisualQML                                                   CONSTANT)
    Q_PROPERTY(QString                  editorQML                   READ editorQML                                                      CONSTANT)

    //Property accessors
    double                  maxAltitude         (void) const    { return _maxAltitude;}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
30 31
    virtual QString                 mapVisualQML    (void) const { return "WimaAreaMapVisual.qml";}
    virtual QString                 editorQML       (void) const { return "WimaAreaEditor.qml";}
32 33 34 35 36 37 38

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

    // Member Methodes
    //iterates over all vertices in _polygon and returns the index of that one closest to coordinate
39
    int                     getClosestVertexIndex   (const QGeoCoordinate& coordinate) const;
40
    //iterates over all vertices in _polygon and returns that one closest to coordinate
41 42 43 44
    QGeoCoordinate          getClosestVertex        (const QGeoCoordinate& coordinate) const;
    static QGCMapPolygon    toQGCPolygon            (const WimaArea& poly);
    QGCMapPolygon           toQGCPolygon            () const;
    static void             join                    (QList<WimaArea*>* polyList,  WimaArea* joinedPoly);// change to & notation
45 46
    /// 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
47 48 49
    /// @return true if polygons have been joined, false else
    static bool             join                    (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
    bool                    join                    (WimaArea &poly);
50 51
    bool                    isDisjunct              (QList<WimaArea*>* polyList);// change to & notation, if necessary
    bool                    isDisjunct              (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
52 53
    /// 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
54
    int                     nextVertexIndex         (int index) const;
55 56
    /// calculates the previous polygon vertex index
    /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
57
    int                     previousVertexIndex     (int index) const;
58 59 60
    /// 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
61 62
    /// @param intersectionPt Coordinate item to store intersection pt. in.
    /// @return false on error or no intersection, true else
63
    static bool            intersects(const QGCMapPolyline& line1, const QGCMapPolyline& line2, QGeoCoordinate& intersectionPt);
64 65
    /// 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
66 67 68
    /// @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
69
    static bool            intersects(const QGCMapPolyline& line, const WimaArea& poly, QList<QGeoCoordinate>& intersectionList, QList<QPair<int, int>>& neighbourlist);
70 71
    /// 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.
72
    static double          distInsidePoly(const QGeoCoordinate& c1, const QGeoCoordinate& c2, WimaArea poly);
73
    /// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
74 75 76 77 78 79
    /// @return true if path was found, false else
    static bool            dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
    /// @return true if the polygon is self intersecting
    static bool            isSelfIntersecting(const WimaArea& poly);
           bool            isSelfIntersecting();

80

81 82 83
    void saveToJson(QJsonObject& jsonObject);
    bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);

84 85 86 87 88 89 90
    // Friends
    friend void swap(WimaArea& area1, WimaArea& area2);
    /// prints the member values of area to the outputString
    friend void print(const WimaArea& area, QString& outputString);
    /// prints the member values of area to the console
    friend void print(const WimaArea& area);

91
    // static Members
92 93
    // Accurracy used to compute isDisjunct
    static const double numericalAccuracy;
94 95 96
    static const char*  maxAltitudeName;
    static const char*  wimaAreaName;
    static const char*  areaTypeName;
97 98 99 100 101 102 103 104

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


protected:
    double                  _maxAltitude;
105 106 107

private:
    void init();
108 109
};

110