Skip to content
WimaArea.h 4.37 KiB
Newer Older
#pragma once
#include "QGCMapPolygon.h"
#include "QGCMapPolyline.h"
#include "Vehicle.h"
#include "qobject.h"
#include "WimaVehicle.h"
#include "WimaArea.h"
#include <QLineF>
#include <QPointF>
#include "QGCGeo.h"
class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas
public:
    WimaArea(QObject* parent = nullptr);
    WimaArea(QGCMapPolygon* other = nullptr, QObject* parent = nullptr);
    ~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;}

    QString                 mapVisualQML    (void) const { return "WimaAreaMapVisual.qml";}
    QString                 editorQML       (void) const { return "WimaAreaEditor.qml";}

    //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
    int                     getClosestVertexIndex   (QGeoCoordinate coordinate);
    //iterates over all vertices in _polygon and returns that one closest to coordinate
    QGeoCoordinate          getClosestVertex        (QGeoCoordinate coordinate);
    QGCMapPolygon*          toQGCPolygon            (WimaArea* poly);
    WimaArea*               joinPolygons            (QList<WimaArea*>* polyList);
    /// 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
    WimaArea*               joinPolygons            (WimaArea* poly1, WimaArea* poly2);
    bool                    isDisjunct              (QList<WimaArea*>* polyList);
    bool                    isDisjunct              (WimaArea* poly1, WimaArea* poly2);
    /// 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
    int                     nextVertexIndex         (int index);
    /// calculates the previous polygon vertex index
    /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
    int                     previousVertexIndex     (int index);
    /// 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
    /// @return the intersection point if line1 intersects line2, nullptr else
    QGeoCoordinate*         intersects(QGCMapPolyline* line1, QGCMapPolyline* line2);
    /// 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
    /// @return a list of intersection points if line intersects poly, or an empty list else
    QList<QGeoCoordinate*>*  intersects(QGCMapPolyline* line, WimaArea* poly);

    // Accurracy used to compute isDisjunct
    static const double numericalAccuracy;

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


protected:
    double                  _maxAltitude;
    WimaVehicle*            _wimaVehicle;