#include "WimaPolygon.h"

WimaPolygon::WimaPolygon(QObject *parent) :
    QObject                 (parent)
  ,_maxAltitude             (30)
  ,_vehicle                 (parent)
  ,_polygon                 (new QGCMapPolygon(this))
  ,_subPolygons             (new QmlObjectListModel(this))
  ,_subPolylines            (new QmlObjectListModel(this))
{
}

WimaPolygon::WimaPolygon(QGCMapPolygon *other, QObject *parent):
    WimaPolygon(parent)
{
    *_polygon = *other;
}


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::setIsCurrentPolygon(bool isCurrentPolygon)
{
    if(_isCurrentPolygon != isCurrentPolygon){
        _isCurrentPolygon = isCurrentPolygon;
        emit isCurrentPolygonChanged();
    }

}

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


