WimaArea.h 5.33 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
    WimaArea(QObject* parent = nullptr);
19
    WimaArea(QGCMapPolygon* other = nullptr, QObject* parent = nullptr);
20 21 22 23 24 25 26 27 28 29 30 31 32
    ~WimaArea();



    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
33 34
    virtual QString                 mapVisualQML    (void) const { return "WimaAreaMapVisual.qml";}
    virtual QString                 editorQML       (void) const { return "WimaAreaEditor.qml";}
35 36 37 38 39 40 41 42 43 44 45

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

    // Accurracy used to compute isDisjunct
    static const double numericalAccuracy;
84 85 86 87 88 89 90 91 92

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


protected:
    double                  _maxAltitude;
    WimaVehicle*            _wimaVehicle;
93 94
};

95