Commit 81769297 authored by Valentin Platzgummer's avatar Valentin Platzgummer

changed wima classes to copy and swap idiom

parent 2b61da4b
......@@ -367,6 +367,43 @@ void QGCMapPolygon::setInteractive(bool interactive)
}
}
void print(const QGCMapPolygon &poly)
{
QString message;
print(poly, message);
qWarning() << message;
}
void print(const QGCMapPolygon &poly, QString &outputString)
{
outputString.append(QString("Coordinates:\n"));
for (int i = 0; i < poly.count(); i++) {
QGeoCoordinate coordinate = poly.vertexCoordinate(i);
outputString.append(QString("%s\n").arg(coordinate.toString(QGeoCoordinate::Degrees)));
}
outputString.append(QString("Dirty: %s\n").arg(QVariant(poly._dirty).toString()));
outputString.append(QString("Center: %s\n").arg(poly._center.toString(QGeoCoordinate::Degrees)));
outputString.append(QString("Center Drag: %s\n").arg(QVariant(poly._centerDrag).toString()));
outputString.append(QString("Ignore Center Updates: %s\n").arg(QVariant(poly._centerDrag).toString()));
outputString.append(QString("Interactive: %s\n").arg(QVariant(poly._interactive).toString()));
}
void swap(QGCMapPolygon &poly1, QGCMapPolygon &poly2)
{
using std::swap;
poly1._polygonPath.swap(poly2._polygonPath);
swap(poly1._polygonModel, poly2._polygonModel);
swap(poly1._dirty, poly2._dirty);
swap(poly1._center, poly2._center);
swap(poly1._centerDrag, poly2._centerDrag);
swap(poly1._ignoreCenterUpdates, poly2._ignoreCenterUpdates);
swap(poly1._interactive, poly2._interactive);
}
QGeoCoordinate QGCMapPolygon::vertexCoordinate(int vertex) const
{
if (vertex >= 0 && vertex < _polygonPath.count()) {
......
......@@ -105,6 +105,12 @@ public:
void setCenterDrag (bool centerDrag);
void setInteractive (bool interactive);
// Friends
friend void swap(QGCMapPolygon& poly1, QGCMapPolygon& poly2);
friend void print(const QGCMapPolygon& poly, QString& outputString);
friend void print(const QGCMapPolygon& poly);
// static Variables
static const char* jsonPolygonKey;
signals:
......
......@@ -268,3 +268,12 @@ void QmlObjectListModel::clearAndDeleteContents()
clear();
endResetModel();
}
void swap(QmlObjectListModel &list1, QmlObjectListModel &list2)
{
using std::swap;
swap(list1._objectList, list2._objectList);
swap(list1._dirty, list2._dirty);
swap(list1._skipDirtyFirstItem, list2._skipDirtyFirstItem);
}
......@@ -59,6 +59,9 @@ public:
void beginReset () { beginResetModel(); }
void endReset () { endResetModel(); }
// Friends
friend void swap(QmlObjectListModel& list1, QmlObjectListModel& list2);
signals:
void countChanged (int count);
void dirtyChanged (bool dirtyChanged);
......
......@@ -6,42 +6,32 @@ const char* WimaArea::wimaAreaName = "WimaArea";
const char* WimaArea::areaTypeName = "AreaType";
WimaArea::WimaArea()
: QGCMapPolygon (nullptr)
{
this->setObjectName(wimaAreaName);
_maxAltitude = 30;
_wimaVehicle = new WimaVehicle(this);
}
WimaArea::WimaArea(QObject *parent)
: QGCMapPolygon (parent)
{
this->setObjectName(wimaAreaName);
_maxAltitude = 30;
_wimaVehicle = new WimaVehicle(this);
}
WimaArea::WimaArea(const QGCMapPolygon &other, QObject *parent)
: QGCMapPolygon (other, parent)
WimaArea::WimaArea(QObject *parent)
: QGCMapPolygon (parent)
{
this->setObjectName(wimaAreaName);
init();
_maxAltitude = 30;
_wimaVehicle = new WimaVehicle(this);
}
WimaArea::WimaArea(const WimaArea &other, QObject *parent)
: WimaArea (parent)
: QGCMapPolygon (other, parent)
{
this->setObjectName(wimaAreaName);
init();
this->setPath(other.path());
this->setCenter(other.center());
this->setCenterDrag(other.centerDrag());
this->setInteractive(other.interactive());
_maxAltitude = other.maxAltitude();
_wimaVehicle = other.vehicle();
}
WimaArea &WimaArea::operator=(WimaArea other)
{
swap(*this, other); // copy-swap-idiom
return *this;
}
void WimaArea::setMaxAltitude(double alt)
{
......@@ -51,14 +41,7 @@ void WimaArea::setMaxAltitude(double alt)
}
}
void WimaArea::setVehicle(WimaVehicle *vehicle)
{
if(_wimaVehicle != vehicle){
_wimaVehicle->deleteLater();
_wimaVehicle = vehicle;
emit vehicleChanged();
}
}
/*QList<WimaArea *>* WimaArea::splitArea<T>(WimaArea *polygonToSplitt, int numberOfFractions)
{
......@@ -127,7 +110,7 @@ void WimaArea::join(QList<WimaArea *>* polyList, WimaArea* joinedPoly)
return;
}
void WimaArea::join(WimaArea &poly1, WimaArea &poly2, WimaArea &joinedPoly)
bool WimaArea::join(WimaArea &poly1, WimaArea &poly2, WimaArea &joinedPoly)
{
if (poly1.count() >= 3 && poly2.count() >= 3) {
......@@ -156,7 +139,7 @@ void WimaArea::join(WimaArea &poly1, WimaArea &poly2, WimaArea &joinedPoly)
if ( crossContainsWalker == true) {
joinedPoly.appendVertices(crossPoly->coordinateList());
return;
return true;
}
......@@ -222,22 +205,28 @@ void WimaArea::join(WimaArea &poly1, WimaArea &poly2, WimaArea &joinedPoly)
}
if (currentVertex == startVertex) {
return;
if (poly1.count() == joinedPoly.count()) { // is the case if poly1 and poly2 don't intersect
return false;
} else {
return true;
}
}
}
} else {
qWarning("WimaArea::joinPolygons(poly1, poly2): poly->count() < 3");
return;
return false;
}
}
void WimaArea::join(WimaArea &poly)
bool WimaArea::join(WimaArea &poly)
{
WimaArea joinedArea;
join(*this, poly, joinedArea);
this->setPath(joinedArea.path());
return;
if ( join(*this, poly, joinedArea) ) {
this->setPath(joinedArea.path());
return true;
} else {
return false;
}
}
bool WimaArea::isDisjunct(QList<WimaArea *>* polyList)
......@@ -378,20 +367,18 @@ bool WimaArea::intersects(const QGCMapPolyline& line, const WimaArea& poly, QLis
}
}
double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate &c2, const WimaArea &poly)
double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate &c2, WimaArea poly)
{
WimaArea bigPoly(poly);
bigPoly.offset(0.1); // hack to compensate for numerical issues, migh be replaced in the future...
if ( bigPoly.containsCoordinate(c1) && bigPoly.containsCoordinate(c2)) {
poly.offset(0.1); // hack to compensate for numerical issues, migh be replaced in the future...
if ( poly.containsCoordinate(c1) && poly.containsCoordinate(c2)) {
QList<QGeoCoordinate> intersectionList;
QList<QPair<int, int>> neighbourlist;
QGCMapPolyline line;
line.appendVertex(c1);
line.appendVertex(c2);
intersects(line, bigPoly, intersectionList, neighbourlist);
intersects(line, poly, intersectionList, neighbourlist);
//if ( intersectionList.size() == (c1InPolyRim || c2InPolyRim ? 2:0) ){
if ( intersectionList.size() == 0 ){
return c1.distanceTo(c2);
} else {
......@@ -403,8 +390,12 @@ double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate &
}
}
void WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &end, const WimaArea &poly, QList<QGeoCoordinate> &dijkstraPath)
bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &end, const WimaArea &poly, QList<QGeoCoordinate> &dijkstraPath)
{
if ( isSelfIntersecting(poly) ) {
return false;
}
struct Node{
QGeoCoordinate coordinate;
double distance = std::numeric_limits<qreal>::infinity();
......@@ -477,7 +468,7 @@ void WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e
Node* Node = &nodeList.last();
if (Node->predecessorNode == nullptr) {
qWarning("WimaArea::dijkstraPath(): Error, no path found!");
return;
return false;
}
while (1) {
......@@ -489,6 +480,40 @@ void WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e
break;
}
}
return true;
}
bool WimaArea::isSelfIntersecting(const WimaArea &poly)
{
int i = 0;
if (poly.count() > 3) {
while(i < poly.count()-1) {
QGCMapPolyline refLine;
refLine.appendVertex(poly.vertexCoordinate(i));
refLine.appendVertex(poly.vertexCoordinate(poly.nextVertexIndex(i)));
int j = poly.nextVertexIndex(i);
while(j < poly.count()) {
QGeoCoordinate dummy;
QGCMapPolyline iteratorLine;
iteratorLine.appendVertex(poly.vertexCoordinate(j));
iteratorLine.appendVertex(poly.vertexCoordinate(poly.nextVertexIndex(j)));
if ( intersects(refLine, iteratorLine, dummy) )
return true;
j++;
}
i++;
}
}
return false;
}
bool WimaArea::isSelfIntersecting()
{
return isSelfIntersecting(*this);
}
void WimaArea::saveToJson(QJsonObject &json)
......@@ -515,3 +540,30 @@ bool WimaArea::loadFromJson(const QJsonObject &json, QString& errorString)
}
}
void WimaArea::init()
{
this->setObjectName(wimaAreaName);
}
void print(const WimaArea &area)
{
QString message;
print(area, message);
qWarning() << message;
}
void print(const WimaArea &area, QString &outputString)
{
outputString.append(QString("Type: %s").arg(area.objectName()));
print(static_cast<const QGCMapPolygon&>(area), outputString);
outputString.append(QString("Maximum Altitude: %.3f").arg(area._maxAltitude));
}
void swap(WimaArea &area1, WimaArea &area2)
{
using std::swap;
swap(static_cast<QGCMapPolygon&>(area1), static_cast<QGCMapPolygon&>(area2));
swap(area1._maxAltitude, area2._maxAltitude);
}
......@@ -15,21 +15,17 @@ class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas
{
Q_OBJECT
public:
WimaArea();
WimaArea(QObject* parent);
WimaArea(const QGCMapPolygon& other, QObject* parent);
WimaArea(const WimaArea& other, QObject* parent);
WimaArea(QObject* parent = nullptr);
WimaArea(const WimaArea& other, QObject* parent = nullptr);
WimaArea& operator=(WimaArea other);
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;}
virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";}
virtual QString editorQML (void) const { return "WimaAreaEditor.qml";}
......@@ -39,10 +35,6 @@ public:
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 (const QGeoCoordinate& coordinate) const;
//iterates over all vertices in _polygon and returns that one closest to coordinate
......@@ -52,9 +44,9 @@ public:
static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly);// change to & notation
/// 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
static void join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
void join (WimaArea &poly);
/// @return true if polygons have been joined, false else
static bool join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
bool join (WimaArea &poly);
bool isDisjunct (QList<WimaArea*>* polyList);// change to & notation, if necessary
bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
/// calculates the next polygon vertex index
......@@ -77,13 +69,25 @@ public:
static bool intersects(const QGCMapPolyline& line, const 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(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly);
static double distInsidePoly(const QGeoCoordinate& c1, const QGeoCoordinate& c2, WimaArea poly);
/// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
static void dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
/// @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();
void saveToJson(QJsonObject& jsonObject);
bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);
// 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);
// static Members
// Accurracy used to compute isDisjunct
static const double numericalAccuracy;
......@@ -98,7 +102,9 @@ signals:
protected:
double _maxAltitude;
WimaVehicle* _wimaVehicle;
private:
void init();
};
This diff is collapsed.
......@@ -31,32 +31,33 @@ public:
Q_PROPERTY(PlanMasterController* masterController READ masterController WRITE setMasterController NOTIFY masterControllerChanged)
Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged)
Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged)
Q_PROPERTY(const QmlObjectListModel*visualItems READ visualItems NOTIFY visualItemsChanged)
Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged)
Q_PROPERTY(QString currentFile READ currentFile NOTIFY currentFileChanged)
Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT)
Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT)
Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT)
Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT)
Q_PROPERTY(WimaArea* joinedArea READ joinedArea NOTIFY joinedAreaChanged)
Q_PROPERTY(WimaArea joinedArea READ joinedArea NOTIFY joinedAreaChanged)
Q_PROPERTY(bool flyView READ flyView CONSTANT)
Q_PROPERTY(WimaDataContainer* dataContainer READ dataContainer WRITE setDataContainer NOTIFY dataContainerChanged)
Q_PROPERTY(bool readyForSaveSend READ readyForSaveSend NOTIFY readyForSaveSendChanged)
// Property accessors
PlanMasterController* masterController (void) const { return _masterController; }
MissionController* missionController (void) const { return _missionController; }
QmlObjectListModel* visualItems (void) const;
const QmlObjectListModel* visualItems (void) const;
int currentPolygonIndex (void) const { return _currentPolygonIndex; }
QString currentFile (void) const { return _currentFile; }
QStringList loadNameFilters (void) const;
QStringList saveNameFilters (void) const;
QString fileExtension (void) const { return wimaFileExtension; }
QGeoCoordinate joinedAreaCenter (void) const;
WimaArea* joinedArea (void) const;
WimaArea joinedArea (void) const;
WimaDataContainer* dataContainer (void) const { return _container; }
bool flyView (void) const { return _flyView; }
bool readyForSaveSend (void) const { return _readyForSaveSend; }
......@@ -100,6 +101,7 @@ public:
// Member Methodes
QJsonDocument saveToJson(FileType fileType);
void setReadyForSaveSend(bool ready);
signals:
void masterControllerChanged (void);
......@@ -109,26 +111,30 @@ signals:
void currentFileChanged ();
void joinedAreaChanged ();
void dataContainerChanged ();
void readyForSaveSendChanged (bool ready);
private slots:
void recalcVehicleCorridor();
void recalcVehicleMeasurementAreas();
void recalcAll();
void recalcPolygonInteractivity(int index);
void updateJoinedArea();
void uploadToContainer();
void downloadFromContainer();
void recalcPolygonInteractivity (int index);
bool updateJoinedArea ();
void updateContainer ();
void downloadFromContainer ();
void setOpArea (const WimaGOperationArea& area);
void setSerArea (const WimaServiceArea& area);
void setCorridor (const WimaVCorridor& area);
void setJoinedArea (const WimaArea& area);
private:
bool _flyView;
bool _readyForSaveSend;
PlanMasterController* _masterController;
MissionController* _missionController;
int _currentPolygonIndex;
QString _currentFile;
WimaDataContainer* _container;
QmlObjectListModel* _visualItems;
WimaArea* _joinedArea;
QmlObjectListModel _visualItems;
WimaArea _joinedArea;
WimaGOperationArea _opArea;
WimaServiceArea _serArea;
WimaVCorridor _corridor;
};
#include "WimaDataContainer.h"
WimaDataContainer::WimaDataContainer(QObject *parent)
: QObject(parent)
, _visualItems(this)
, _joinedArea(this)
: QObject (parent)
, _joinedArea (this)
, _opArea (this)
, _serArea (this)
, _corridor (this)
{
}
void WimaDataContainer::setJoinedArea(const WimaArea &joinedArea)
{
if (_joinedArea.path() != joinedArea.path()) {
_joinedArea = joinedArea;
emit joinedAreaChanged(_joinedArea);
}
}
void WimaDataContainer::setOpArea(const WimaGOperationArea &opArea)
{
if (_opArea.path() != opArea.path()) {
_opArea = opArea;
emit opAreaChanged(_opArea);
}
}
void WimaDataContainer::setSerArea(const WimaServiceArea &serArea)
{
if (_serArea.path() != serArea.path()) {
_serArea = serArea;
emit serAreaChanged(_serArea);
}
}
void WimaDataContainer::setCorridor(const WimaVCorridor &corridor)
{
if (_corridor.path() != corridor.path()) {
_corridor = corridor;
emit corridorChanged(_corridor);
}
}
......@@ -6,6 +6,9 @@
#include "QmlObjectListModel.h"
#include "WimaArea.h"
#include "WimaGOperationArea.h"
#include "WimaServiceArea.h"
#include "WimaVCorridor.h"
class WimaDataContainer : public QObject
{
......@@ -13,21 +16,29 @@ class WimaDataContainer : public QObject
public:
explicit WimaDataContainer(QObject *parent = nullptr);
QmlObjectListModel* visualItems (void) { return &_visualItems; } //use setVisualItems to modify list
WimaArea joinedArea (void) { return _joinedArea; }
WimaGOperationArea opArea (void) { return _opArea; }
WimaServiceArea serArea (void) { return _serArea; }
WimaVCorridor corridor (void) { return _corridor; }
void setJoinedArea(const WimaArea& joinedArea);
void setVisualItems(const QmlObjectListModel& list);
void setJoinedArea (const WimaArea& joinedArea);
void setOpArea (const WimaGOperationArea& opArea);
void setSerArea (const WimaServiceArea& serArea);
void setCorridor (const WimaVCorridor& corridor);
signals:
void joinedAreaChanged();
void visualItemsChanged();
void joinedAreaChanged (const WimaArea& area);
void opAreaChanged (const WimaGOperationArea& area);
void serAreaChanged (const WimaServiceArea& area);
void corridorChanged (const WimaVCorridor& area);
public slots:
private:
QmlObjectListModel _visualItems;
WimaArea _joinedArea;
WimaGOperationArea _opArea;
WimaServiceArea _serArea;
WimaVCorridor _corridor;
};
#endif // WIMADATACONTAINER_H
......@@ -8,69 +8,24 @@ const char* WimaGOperationArea::layerDistanceName = "LayerDistance
const char* WimaGOperationArea::borderPolygonOffsetName = "BorderPolygonOffset";
const char* WimaGOperationArea::wimaGOperationAreaName = "Operation Area";
WimaGOperationArea::WimaGOperationArea()
: WimaGOperationArea(nullptr)
{
}
WimaGOperationArea::WimaGOperationArea(QObject *parent)
: WimaArea (parent)
, _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaGOperationArea.SettingsGroup.json"), this /* QObject parent */))
, _bottomLayerAltitude (settingsGroup, _metaDataMap[bottomLayerAltitudeName])
, _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName])
, _layerDistance (settingsGroup, _metaDataMap[layerDistanceName])
, _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName])
, _borderPolygon (new QGCMapPolygon(this))
{
this->setObjectName(wimaGOperationAreaName);
connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon);
connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon);
init();
}
WimaGOperationArea::WimaGOperationArea(const WimaArea &other, QObject *parent)
WimaGOperationArea::WimaGOperationArea(const WimaGOperationArea &other, QObject *parent)
: WimaArea(other, parent)
, _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaGOperationArea.SettingsGroup.json"), this /* QObject parent */))
, _bottomLayerAltitude (settingsGroup, _metaDataMap[bottomLayerAltitudeName])
, _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName])
, _layerDistance (settingsGroup, _metaDataMap[layerDistanceName])
, _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName])
, _borderPolygon (new QGCMapPolygon(this))
{
this->setObjectName(wimaGOperationAreaName);
connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon);
connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon);
}
void WimaGOperationArea::addVehicle(WimaVehicle *vehicle)
{
if(vehicle != nullptr){
_wimaVehicle = vehicle;
emit vehicleChanged();
}
init();
}
void WimaGOperationArea::removeVehicle(int vehicleIndex)
WimaGOperationArea &WimaGOperationArea::operator=(WimaGOperationArea other)
{
if(vehicleIndex >= 0){
_wimaVehicle = nullptr;
emit vehicleChanged();
}
}
swap(*this, other);
void WimaGOperationArea::setVehicleCorridor(WimaVCorridor *corridor)
{
if(corridor != nullptr){
if (corridor != _vehicleCorridor){
_vehicleCorridor = corridor;
emit vehicleCorridorChanged(_vehicleCorridor);
}
else {
qWarning("WimaGOperationArea::setVehicleCorridor(): new corridor equals old _vehicleCorridor!");
}
}else{
qWarning("WimaGOperationArea::setVehicleCorridor(): corridor == nullptr!");
}
return *this;
}
void WimaGOperationArea::saveToJson(QJsonObject &json)
......@@ -122,77 +77,64 @@ bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorStr
}
}
void WimaGOperationArea::recalcBorderPolygon()
void print(const WimaGOperationArea &area)
{
//qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble());
QGCMapPolygon polyCopy = this->toQGCPolygon(*this);
polyCopy.offset(_borderPolygonOffset.rawValue().toDouble());
_borderPolygon.setPath(polyCopy.path());
polyCopy.deleteLater();
emit borderPolygonChanged();
QString message;
print(area, message);
qWarning() << message;
}
/*void WimaGOperationArea::recalculatesubPolygons()
void print(const WimaGOperationArea &area, QString outputStr)
{
int vehicleCount = _vehicleList->count();
QScopedPointer<QList<QGCMapPolygon*>> listQGCPoly(this->splitPolygonArea(vehicleCount));
int polyCount = listQGCPoly->size();
_vehiclePolygons->clear();
for(int i = 0; i < polyCount; i++){
WimaVehicleMeasurementPolygon* subPoly = new WimaVehicleMeasurementPolygon(listQGCPoly->takeAt(i), this);
_vehiclePolygons->append(subPoly);
print(static_cast<const WimaArea&>(area), outputStr);
outputStr.append(QString("Bottom Layer Altitude: %.3f\n").arg(area._bottomLayerAltitude.rawValue().toDouble()));
outputStr.append(QString("Number of Layers: %i\n").arg(area._numberOfLayers.rawValue().toInt()));
outputStr.append(QString("Layer Distance: %.3f\n").arg(area._layerDistance.rawValue().toDouble()));
outputStr.append(QString("Border Polygon Offset: %.3f\n").arg(area._borderPolygonOffset.rawValue().toDouble()));
outputStr.append(QString("Border Polygon Coordinates\n").arg(area._borderPolygonOffset.rawValue().toDouble()));
for (int i = 0; i < area._borderPolygon.count(); i++) {
QGeoCoordinate coordinate = area._borderPolygon.vertexCoordinate(i);
outputStr.append(QString("%s\n").arg(coordinate.toString(QGeoCoordinate::Degrees)));
}
}
void WimaGOperationArea::removeAllVehicles()
void swap(WimaGOperationArea &area1, WimaGOperationArea &area2)
{
int count = _vehicleList->count();