#include "WimaPolygon.h"

WimaPolygon::WimaPolygon(QObject *parent) :
    QObject                 (parent)
  ,_maxAltitude             (30)
  ,_vehicle                 (parent)
  ,_polygon                 (new QGCMapPolygon(this))
{
    connect(_polygon, &QGCMapPolygon::interactiveChanged, this, &WimaPolygon::interactiveChanged);
    connect(_polygon, &QGCMapPolygon::countChanged, this, &WimaPolygon::countChanged);
}

WimaPolygon::WimaPolygon(QGCMapPolygon *other, QObject *parent):
    WimaPolygon(parent)
{
    *_polygon = *other;
    connect(_polygon, &QGCMapPolygon::interactiveChanged, this, &WimaPolygon::interactiveChanged);
    connect(_polygon, &QGCMapPolygon::countChanged, this, &WimaPolygon::countChanged);
}

WimaPolygon::~WimaPolygon()
{

}


void WimaPolygon::setMaxAltitude(double alt)
{
    if(alt > 0 && alt != _maxAltitude){
        _maxAltitude = alt;
        emit maxAltitudeChanged();
    }
}


void WimaPolygon::setVehicle(Vehicle *vehicle)
{
    if(_vehicle.vehicle() != vehicle){
        _vehicle.setVehicle(vehicle);
        emit vehicleChanged();
    }
}


void WimaPolygon::setInteractive(bool interactive)
{
    _polygon->setInteractive(interactive);
}

QList<QGCMapPolygon *> *WimaPolygon::splitPolygonArea(QGCMapPolygon *polygonToSplitt, int numberOfFractions)
{
    if(numberOfFractions > 0 && polygonToSplitt != nullptr){
        QGCMapPolygon* poly = new QGCMapPolygon(polygonToSplitt, this);
        QList<QGCMapPolygon*>* list = new QList<QGCMapPolygon*>();
        list->append(poly);
        return list;
    }
    return nullptr;
}


QList<QGCMapPolygon*>* WimaPolygon::splitPolygonArea(int numberOfFractions)
{
    return splitPolygonArea(_polygon, numberOfFractions);
}


