Commit c82f5a2a authored by Valentin Platzgummer's avatar Valentin Platzgummer

adding json saving thing

parent 730535d4
#include "WimaArea.h" #include "WimaArea.h"
const double WimaArea::numericalAccuracy = 1e-3; // meters const double WimaArea::numericalAccuracy = 1e-3; // meters
const char* WimaArea::maxAltitudeName = "maxAltitude";
const char* WimaArea::wimaAreaName = "WimaArea";
const char* WimaArea::areaTypeName = "AreaType";
WimaArea::WimaArea(QObject *parent) : WimaArea::WimaArea(QObject *parent) :
WimaArea (nullptr, parent) WimaArea (nullptr, parent)
...@@ -11,6 +15,7 @@ WimaArea::WimaArea(QObject *parent) : ...@@ -11,6 +15,7 @@ WimaArea::WimaArea(QObject *parent) :
WimaArea::WimaArea(QGCMapPolygon *other, QObject *parent) WimaArea::WimaArea(QGCMapPolygon *other, QObject *parent)
: QGCMapPolygon (other, parent) : QGCMapPolygon (other, parent)
{ {
this->setObjectName(wimaAreaName);
WimaArea* wimaPoly = qobject_cast<WimaArea*>(other); WimaArea* wimaPoly = qobject_cast<WimaArea*>(other);
if (wimaPoly != nullptr) { if (wimaPoly != nullptr) {
_maxAltitude = wimaPoly->maxAltitude(); _maxAltitude = wimaPoly->maxAltitude();
...@@ -62,7 +67,7 @@ QList<QGCMapPolygon*>* WimaArea::splitArea(int numberOfFractions) ...@@ -62,7 +67,7 @@ QList<QGCMapPolygon*>* WimaArea::splitArea(int numberOfFractions)
return splitPolygonArea(this, numberOfFractions); return splitPolygonArea(this, numberOfFractions);
}*/ }*/
int WimaArea::getClosestVertexIndex(QGeoCoordinate coordinate) int WimaArea::getClosestVertexIndex(const QGeoCoordinate &coordinate) const
{ {
if (this->count() == 0) { if (this->count() == 0) {
qWarning("Polygon count == 0!"); qWarning("Polygon count == 0!");
...@@ -84,25 +89,20 @@ int WimaArea::getClosestVertexIndex(QGeoCoordinate coordinate) ...@@ -84,25 +89,20 @@ int WimaArea::getClosestVertexIndex(QGeoCoordinate coordinate)
} }
} }
QGeoCoordinate WimaArea::getClosestVertex(QGeoCoordinate coordinate) QGeoCoordinate WimaArea::getClosestVertex(const QGeoCoordinate& coordinate) const
{ {
return this->vertexCoordinate(getClosestVertexIndex(coordinate)); return this->vertexCoordinate(getClosestVertexIndex(coordinate));
} }
QGCMapPolygon* WimaArea::toQGCPolygon(WimaArea *poly) QGCMapPolygon &WimaArea::toQGCPolygon(const WimaArea &poly) const
{ {
if (poly != nullptr) { QGCMapPolygon* qgcPoly = new QGCMapPolygon();
QGCMapPolygon* qgcPoly = new QGCMapPolygon(this); qgcPoly->setPath(poly.path());
qgcPoly->setPath(poly->path()); qgcPoly->setCenter(poly.center());
qgcPoly->setCenter(poly->center()); qgcPoly->setCenterDrag(poly.centerDrag());
qgcPoly->setCenterDrag(poly->centerDrag()); qgcPoly->setInteractive(poly.interactive());
qgcPoly->setInteractive(poly->interactive());
return *qgcPoly;
return qgcPoly;
} else {
qWarning("WimaArea::toQGCPolygon(): poly == nullptr");
return nullptr;
}
} }
void WimaArea::join(QList<WimaArea *>* polyList, WimaArea* joinedPoly) void WimaArea::join(QList<WimaArea *>* polyList, WimaArea* joinedPoly)
...@@ -110,17 +110,18 @@ void WimaArea::join(QList<WimaArea *>* polyList, WimaArea* joinedPoly) ...@@ -110,17 +110,18 @@ void WimaArea::join(QList<WimaArea *>* polyList, WimaArea* joinedPoly)
return; return;
} }
void WimaArea::join(const WimaArea &poly1, const WimaArea &poly2, WimaArea &joinedPoly)
void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly)
{ {
if (poly1 != nullptr && poly2 != nullptr) {
if (poly1->count() >= 3 && poly2->count() >= 3) {
poly1->verifyClockwiseWinding(); if (poly1.count() >= 3 && poly2.count() >= 3) {
poly2->verifyClockwiseWinding();
WimaArea* walkerPoly = poly1; // "walk" on this polygon towards higher indices WimaArea cpoly1(poly1);
WimaArea* crossPoly = poly2; // check for crossings with this polygon while "walking" WimaArea cpoly2(poly2);
cpoly1.verifyClockwiseWinding();
cpoly2.verifyClockwiseWinding();
WimaArea* walkerPoly = &cpoly1; // "walk" on this polygon towards higher indices
WimaArea* crossPoly = &cpoly2; // check for crossings with this polygon while "walking"
// and swicht to this polygon on a intersection, // and swicht to this polygon on a intersection,
// continue to walk towards higher indices // continue to walk towards higher indices
...@@ -137,7 +138,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly) ...@@ -137,7 +138,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly)
if ( crossContainsWalker == true) { if ( crossContainsWalker == true) {
joinedPoly->appendVertices(crossPoly->coordinateList()); joinedPoly.appendVertices(crossPoly->coordinateList());
return; return;
} }
...@@ -150,7 +151,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly) ...@@ -150,7 +151,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly)
int nextVertexIndex = walkerPoly->nextVertexIndex(startIndex); int nextVertexIndex = walkerPoly->nextVertexIndex(startIndex);
while (1) { while (1) {
//qDebug("nextVertexIndex: %i", nextVertexIndex); //qDebug("nextVertexIndex: %i", nextVertexIndex);
joinedPoly->appendVertex(currentVertex); joinedPoly.appendVertex(currentVertex);
QGCMapPolyline walkerPolySegment; QGCMapPolyline walkerPolySegment;
walkerPolySegment.appendVertex(currentVertex); walkerPolySegment.appendVertex(currentVertex);
...@@ -159,7 +160,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly) ...@@ -159,7 +160,7 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly)
QList<QPair<int, int>> neighbourList; QList<QPair<int, int>> neighbourList;
QList<QGeoCoordinate> intersectionList; QList<QGeoCoordinate> intersectionList;
//qDebug("IntersectionList.size() on init: %i", intersectionList.size()); //qDebug("IntersectionList.size() on init: %i", intersectionList.size());
intersects(&walkerPolySegment, crossPoly, &intersectionList, &neighbourList); intersects(walkerPolySegment, crossPoly, intersectionList, neighbourList);
//qDebug("IntersectionList.size(): %i", intersectionList.size()); //qDebug("IntersectionList.size(): %i", intersectionList.size());
...@@ -212,16 +213,12 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly) ...@@ -212,16 +213,12 @@ void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly)
qWarning("WimaArea::joinPolygons(poly1, poly2): poly->count() < 3"); qWarning("WimaArea::joinPolygons(poly1, poly2): poly->count() < 3");
return; return;
} }
} else {
qWarning("WimaArea::joinPolygons(poly1, poly2): nullptr");
return;
}
} }
void WimaArea::join(WimaArea *poly)
void WimaArea::join(const WimaArea &poly)
{ {
WimaArea joinedArea(this); WimaArea joinedArea(this);
join(this, poly, &joinedArea); join(this, poly, joinedArea);
this->setPath(joinedArea.path()); this->setPath(joinedArea.path());
return; return;
} }
...@@ -263,7 +260,7 @@ bool WimaArea::isDisjunct(WimaArea *poly1, WimaArea *poly2) ...@@ -263,7 +260,7 @@ bool WimaArea::isDisjunct(WimaArea *poly1, WimaArea *poly2)
} }
} }
int WimaArea::nextVertexIndex(int index) int WimaArea::nextVertexIndex(int index) const
{ {
if (index >= 0 && index < count()-1) { if (index >= 0 && index < count()-1) {
return index + 1; return index + 1;
...@@ -275,7 +272,7 @@ int WimaArea::nextVertexIndex(int index) ...@@ -275,7 +272,7 @@ int WimaArea::nextVertexIndex(int index)
} }
} }
int WimaArea::previousVertexIndex(int index) int WimaArea::previousVertexIndex(int index) const
{ {
if (index > 0 && index < count()) { if (index > 0 && index < count()) {
return index - 1; return index - 1;
...@@ -287,31 +284,31 @@ int WimaArea::previousVertexIndex(int index) ...@@ -287,31 +284,31 @@ int WimaArea::previousVertexIndex(int index)
} }
} }
bool WimaArea::intersects(QGCMapPolyline *line1, QGCMapPolyline *line2, QGeoCoordinate *intersectionPt) bool WimaArea::intersects(const QGCMapPolyline &line1, const QGCMapPolyline &line2, QGeoCoordinate &intersectionPt)
{ {
if (line1 != nullptr && line2 != nullptr && intersectionPt != nullptr) {
if (line1->count() == 2 && line2->count() == 2 ) { if (line1.count() == 2 && line2.count() == 2 ) {
QPointF pt11(0, 0); QPointF pt11(0, 0);
double x, y, z; double x, y, z;
QGeoCoordinate origin = line1->vertexCoordinate(0); QGeoCoordinate origin = line1.vertexCoordinate(0);
convertGeoToNed(line1->vertexCoordinate(1), origin, &x, &y, &z); convertGeoToNed(line1.vertexCoordinate(1), origin, &x, &y, &z);
QPointF pt12(x, y); QPointF pt12(x, y);
QLineF kartLine1(pt11, pt12); QLineF kartLine1(pt11, pt12);
convertGeoToNed(line2->vertexCoordinate(0), origin, &x, &y, &z); convertGeoToNed(line2.vertexCoordinate(0), origin, &x, &y, &z);
QPointF pt21(x, y); QPointF pt21(x, y);
convertGeoToNed(line2->vertexCoordinate(1), origin, &x, &y, &z); convertGeoToNed(line2.vertexCoordinate(1), origin, &x, &y, &z);
QPointF pt22(x, y); QPointF pt22(x, y);
QLineF kartLine2(pt21, pt22); QLineF kartLine2(pt21, pt22);
QPointF intersectionPoint; QPointF intersectionPoint;
if (kartLine1.intersect(kartLine2, &intersectionPoint) == QLineF::BoundedIntersection) { if (kartLine1.intersect(kartLine2, &intersectionPoint) == QLineF::BoundedIntersection) {
convertNedToGeo(intersectionPoint.x(), intersectionPoint.y(), origin.altitude(), origin, intersectionPt); convertNedToGeo(intersectionPoint.x(), intersectionPoint.y(), origin.altitude(), origin, &intersectionPt);
return true; return true;
} else { } else {
return false; return false;
...@@ -322,45 +319,38 @@ bool WimaArea::intersects(QGCMapPolyline *line1, QGCMapPolyline *line2, QGeoCoor ...@@ -322,45 +319,38 @@ bool WimaArea::intersects(QGCMapPolyline *line1, QGCMapPolyline *line2, QGeoCoor
qWarning("WimaArea::intersect(line1, line2): line1->count() != 2 || line2->count() != 2!"); qWarning("WimaArea::intersect(line1, line2): line1->count() != 2 || line2->count() != 2!");
return false; return false;
} }
} else {
qWarning("WimaArea::intersect(line1, line2): nullptr!");
return false;
}
} }
bool WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly, QList<QGeoCoordinate> *intersectionList, QList<QPair<int, int> > *neighbourlist) bool WimaArea::intersects(const QGCMapPolyline& line, const WimaArea& poly, QList<QGeoCoordinate>& intersectionList, QList<QPair<int, int> >& neighbourlist)
{ {
if (line != nullptr && poly != nullptr && neighbourlist != nullptr && intersectionList != nullptr) { neighbourlist.clear();
neighbourlist->clear(); intersectionList.clear();
intersectionList->clear();
if (line->count() == 2 && poly->count() >= 3) { if (line.count() == 2 && poly.count() >= 3) {
for (int i = 0; i < poly->count(); i++) { for (int i = 0; i < poly.count(); i++) {
QGCMapPolyline polySegment; QGCMapPolyline polySegment;
QGeoCoordinate currentVertex = poly->vertexCoordinate(i); QGeoCoordinate currentVertex = poly.vertexCoordinate(i);
QGeoCoordinate nextVertex = poly->vertexCoordinate(poly->nextVertexIndex(i)); QGeoCoordinate nextVertex = poly.vertexCoordinate(poly.nextVertexIndex(i));
polySegment.appendVertex(currentVertex); polySegment.appendVertex(currentVertex);
polySegment.appendVertex(nextVertex); polySegment.appendVertex(nextVertex);
QGeoCoordinate intersectionPoint; QGeoCoordinate intersectionPoint;
//bool retVal2 = intersects(line, line, &intersectionPoint); //bool retVal2 = intersects(line, line, &intersectionPoint);
bool retVal = intersects(line, &polySegment, &intersectionPoint); bool retVal = intersects(line, polySegment, intersectionPoint);
if (retVal != false){ if (retVal != false){
intersectionList->append(intersectionPoint); intersectionList.append(intersectionPoint);
QPair<int, int> neighbours; QPair<int, int> neighbours;
neighbours.first = i; neighbours.first = i;
neighbours.second = poly->nextVertexIndex(i); neighbours.second = poly.nextVertexIndex(i);
neighbourlist->append(neighbours); neighbourlist.append(neighbours);
} }
} }
if (intersectionList->count() > 0) { if (intersectionList.count() > 0) {
return true; return true;
} else { } else {
return false; return false;
...@@ -369,49 +359,33 @@ bool WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly, QList<QGeoCoordi ...@@ -369,49 +359,33 @@ bool WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly, QList<QGeoCoordi
qWarning("WimaArea::intersects(line, poly): line->count() != 2 || poly->count() < 3"); qWarning("WimaArea::intersects(line, poly): line->count() != 2 || poly->count() < 3");
return false; return false;
} }
} else {
qWarning("WimaArea::intersects(line, poly): nullptr!");
return false;
}
} }
double WimaArea::distInsidePoly(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly) double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate &c2, const WimaArea &poly)
{ {
if (c1 != nullptr && c2 != nullptr && poly != nullptr) { WimaArea bigPoly(poly);
// conditions which must be fullfilled bigPoly.offset(0.01); // hack to compensate for numerical issues, migh be replaced in the future...
bool c1InPolyRim = poly->coordinateList().contains(*c1); if ( bigPoly.containsCoordinate(c1) && bigPoly.containsCoordinate(c2)) {
bool c2InPolyRim = poly->coordinateList().contains(*c2);
bool c1InsidePoly = poly->containsCoordinate(*c1);
bool c2InsidePoly = poly->containsCoordinate(*c2);
WimaArea bigPoly = *poly;
bigPoly.offset(0.1);
if ( (c1InPolyRim || c1InsidePoly) && (c2InPolyRim || c2InsidePoly)) {
QList<QGeoCoordinate> intersectionList; QList<QGeoCoordinate> intersectionList;
QList<QPair<int, int>> neighbourlist; QList<QPair<int, int>> neighbourlist;
QGCMapPolyline line; QGCMapPolyline line;
line.appendVertex(*c1); line.appendVertex(c1);
line.appendVertex(*c2); line.appendVertex(c2);
intersects(&line, &bigPoly, &intersectionList, &neighbourlist); intersects(line, bigPoly, intersectionList, neighbourlist);
//if ( intersectionList.size() == (c1InPolyRim || c2InPolyRim ? 2:0) ){ //if ( intersectionList.size() == (c1InPolyRim || c2InPolyRim ? 2:0) ){
if ( intersectionList.size() == 0 ){ if ( intersectionList.size() == 0 ){
return c1->distanceTo(*c2); return c1.distanceTo(c2);
} }
}
return std::numeric_limits<qreal>::infinity();
} else { } else {
qWarning("WimaArea::distInsidePoly(QGeoCoordinate*, QGeoCoordinate*, WimaArea*): nullptr!");
return std::numeric_limits<qreal>::infinity(); return std::numeric_limits<qreal>::infinity();
} }
} }
void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea *poly, QList<QGeoCoordinate>* dijkistraPath) void WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &end, const WimaArea &poly, QList<QGeoCoordinate> &dijkstraPath)
{ {
if (start != nullptr && end != nullptr && poly != nullptr && dijkistraPath != nullptr) {
struct Node{ struct Node{
QGeoCoordinate coordinate; QGeoCoordinate coordinate;
double distance = std::numeric_limits<qreal>::infinity(); double distance = std::numeric_limits<qreal>::infinity();
...@@ -425,20 +399,20 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea ...@@ -425,20 +399,20 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea
// initialize // initialize
// start // start
Node startNode; Node startNode;
startNode.coordinate = *start; startNode.coordinate = start;
startNode.distance = 0; startNode.distance = 0;
nodeList.append(startNode); nodeList.append(startNode);
//poly //poly
for (int i = 0; i < poly->count(); i++) { for (int i = 0; i < poly.count(); i++) {
Node node; Node node;
node.coordinate = poly->vertexCoordinate(i); node.coordinate = poly.vertexCoordinate(i);
nodeList.append(node); nodeList.append(node);
} }
//end //end
Node endNode; Node endNode;
endNode.coordinate = *end; endNode.coordinate = end;
nodeList.append(endNode); nodeList.append(endNode);
// working set // working set
...@@ -470,7 +444,7 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea ...@@ -470,7 +444,7 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea
Node* v = workingSet[i]; Node* v = workingSet[i];
// is neighbour? // is neighbour?
double dist = distInsidePoly(&u->coordinate, &v->coordinate, poly); double dist = distInsidePoly(u->coordinate, v->coordinate, poly);
double alternative = u->distance + dist; double alternative = u->distance + dist;
if (alternative < v->distance) { if (alternative < v->distance) {
v->distance = alternative; v->distance = alternative;
...@@ -488,7 +462,7 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea ...@@ -488,7 +462,7 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea
} }
while (1) { while (1) {
dijkistraPath->prepend(Node->coordinate); dijkstraPath.prepend(Node->coordinate);
//Update Node //Update Node
Node = Node->predecessorNode; Node = Node->predecessorNode;
...@@ -496,11 +470,29 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea ...@@ -496,11 +470,29 @@ void WimaArea::dijkstraPath(QGeoCoordinate *start, QGeoCoordinate *end, WimaArea
break; break;
} }
} }
}
void WimaArea::saveToJson(QJsonObject &json)
{
this->QGCMapPolygon::saveToJson(json);
json[maxAltitudeName] = _maxAltitude;
json[areaTypeName] = wimaAreaName;
// add WimaVehicle if necessary..
}
bool WimaArea::loadFromJson(const QJsonObject &json, QString& errorString)
{
if ( this->QGCMapPolygon::loadFromJson(json, false /*no poly required*/, errorString) ) {
if ( json.contains(maxAltitudeName) && json[maxAltitudeName].isDouble()) {
_maxAltitude = json[maxAltitudeName].toDouble();
return true;
} else { } else {
qWarning(" WimaArea::dijkstraPath(QGeoCoordinate*, QGeoCoordinate*, WimaArea*): nullptr!"); errorString.append("Could not load Maximum Altitude value!\n");
return; return false;
}
} else {
qWarning() << errorString;
return false;
} }
} }
...@@ -42,44 +42,51 @@ public: ...@@ -42,44 +42,51 @@ public:
template <class T> template <class T>
QList<T*>* splitArea (int numberOfFractions); // use QScopedPointer to store return value*/ 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 //iterates over all vertices in _polygon and returns the index of that one closest to coordinate
int getClosestVertexIndex (QGeoCoordinate coordinate); int getClosestVertexIndex (const QGeoCoordinate& coordinate) const;
//iterates over all vertices in _polygon and returns that one closest to coordinate //iterates over all vertices in _polygon and returns that one closest to coordinate
QGeoCoordinate getClosestVertex (QGeoCoordinate coordinate); QGeoCoordinate getClosestVertex (const QGeoCoordinate& coordinate) const;
QGCMapPolygon* toQGCPolygon (WimaArea* poly); QGCMapPolygon& toQGCPolygon (const WimaArea& poly) const;
static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly); 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) /// 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 /// see https://en.wikipedia.org/wiki/Simple_polygon
/// @return the joined polygon of poly1 and poly2 if possible, poly1 else /// @return the joined polygon of poly1 and poly2 if possible, poly1 else
static void join (WimaArea* poly1, WimaArea* poly2, WimaArea* joinedPoly); static void join (const WimaArea& poly1, const WimaArea& poly2, WimaArea& joinedPoly);
void join (WimaArea* poly); void join (const WimaArea& poly);
bool isDisjunct (QList<WimaArea*>* polyList); bool isDisjunct (QList<WimaArea*>* polyList);// change to & notation, if necessary
bool isDisjunct (WimaArea* poly1, WimaArea* poly2); bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
/// calculates the next polygon vertex index /// 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 /// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else
int nextVertexIndex (int index); int nextVertexIndex (int index) const;
/// calculates the previous polygon vertex 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 /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
int previousVertexIndex (int index); int previousVertexIndex (int index) const;
/// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected) /// 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 line1 line containing two coordinates, height not taken into account
/// @param line2 line containing two coordinates, height not taken into account /// @param line2 line containing two coordinates, height not taken into account
/// @param intersectionPt Coordinate item to store intersection pt. in. /// @param intersectionPt Coordinate item to store intersection pt. in.
/// @return false on error or no intersection, true else /// @return false on error or no intersection, true else
static bool intersects(QGCMapPolyline* line1, QGCMapPolyline* line2, QGeoCoordinate* intersectionPt); static bool intersects(const QGCMapPolyline& line1, const QGCMapPolyline& line2, QGeoCoordinate& intersectionPt);
/// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected) /// 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 /// @param line line containing two coordinates, height not taken into account
/// @param intersectionList Empty list to store intersection points in. /// @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.) /// @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 /// @return false on error or no intersection, true else
static bool intersects(QGCMapPolyline* line, WimaArea* poly, QList<QGeoCoordinate>* intersectionList, QList<QPair<int, int>>* neighbourlist); 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. /// 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. /// @return the distance if the path lies within the polygon and inf. else.
static double distInsidePoly(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly); static double distInsidePoly(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly);
/// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm /// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
static void dijkstraPath(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly, QList<QGeoCoordinate> *dijkstraPath); static void dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
void saveToJson(QJsonObject& jsonObject);
bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);
// static Members
// Accurracy used to compute isDisjunct // Accurracy used to compute isDisjunct
static const double numericalAccuracy; static const double numericalAccuracy;
static const char* maxAltitudeName;
static const char* wimaAreaName;
static const char* areaTypeName;
signals: signals:
void maxAltitudeChanged (void); void maxAltitudeChanged (void);
......
#include "WimaController.h" #include "WimaController.h"
const char* WimaController::wimaFileExtension = "wima";
WimaController::WimaController(QObject *parent) : WimaController::WimaController(QObject *parent) :
QObject (parent) QObject (parent)
,_planView (true) ,_planView (true)
...@@ -135,16 +137,16 @@ bool WimaController::updateMission() ...@@ -135,16 +137,16 @@ bool WimaController::updateMission()
} }
// join service area and op area // join service area and op area
WimaArea* joinedArea = new WimaArea(this); WimaArea joinedArea(this);
if (corridor != nullptr) { if (corridor != nullptr) {
WimaArea::join(corridor, serArea, joinedArea); WimaArea::join(*corridor, *serArea, joinedArea);
joinedArea->join(opArea); joinedArea.join(*opArea);
} else { } else {
WimaArea::join(serArea, opArea, joinedArea); WimaArea::join(serArea, opArea, joinedArea);
} }
_visualItems->append(joinedArea); _visualItems->append(&joinedArea);
// reset visual items // reset visual items
...@@ -177,7 +179,7 @@ bool WimaController::updateMission() ...@@ -177,7 +179,7 @@ bool WimaController::updateMission()
QGeoCoordinate start = serArea->center(); QGeoCoordinate start = serArea->center();
QGeoCoordinate end = survey->visualTransectPoints().first().value<QGeoCoordinate>(); QGeoCoordinate end = survey->visualTransectPoints().first().value<QGeoCoordinate>();
QList<QGeoCoordinate> path; QList<QGeoCoordinate> path;
WimaArea::dijkstraPath(&start, &end, joinedArea, &path); WimaArea::dijkstraPath(start, end, joinedArea, path);
for (int i = 1; i < path.count()-1; i++) { for (int i = 1; i < path.count()-1; i++) {
_missionController->insertSimpleMissionItem(path.value(i), i+1); _missionController->insertSimpleMissionItem(path.value(i), i+1);
index++; index++;
...@@ -187,7 +189,7 @@ bool WimaController::updateMission() ...@@ -187,7 +189,7 @@ bool WimaController::updateMission()
start = survey->visualTransectPoints().last().value<QGeoCoordinate>(); start = survey->visualTransectPoints().last().value<QGeoCoordinate>();
end = serArea->center(); end = serArea->center();
path.clear(); path.clear();
WimaArea::dijkstraPath(&start, &end, joinedArea, &path); WimaArea::dijkstraPath(start, end, joinedArea, path);
for (int i = 1; i < path.count()-1; i++) { for (int i = 1; i < path.count()-1; i++) {
_missionController->insertSimpleMissionItem(path.value(i), index++); _missionController->insertSimpleMissionItem(path.value(i), index++);
} }
...@@ -209,12 +211,39 @@ bool WimaController::updateMission() ...@@ -209,12 +211,39 @@ bool WimaController::updateMission()
return true; return true;
} }
void WimaController::saveMission() void WimaController::saveToCurrent()
{
}
void WimaController::saveToFile(const QString& filename)
{ {
if (filename.isEmpty()) {
return;
}
QString planFilename = filename;
if (!QFileInfo(filename).fileName().contains(".")) {
planFilename += QString(".%1").arg(wimaFileExtension);
}
QFile file(planFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(tr("Plan save error %1 : %2").arg(filename).arg(file.errorString()));
_currentFile.clear();
emit currentFileChanged();
} else {
QJsonDocument saveDoc = saveToJson();
file.write(saveDoc.toJson());
if(_currentFile != planFilename) {
_currentFile = planFilename;
emit currentFileChanged();
}
}
} }
void WimaController::loadMission() void WimaController::loadFromFile()
{ {
} }
...@@ -259,5 +288,49 @@ void WimaController::setInteractive() ...@@ -259,5 +288,49 @@ void WimaController::setInteractive()
recalcPolygonInteractivity(_currentPolygonIndex); recalcPolygonInteractivity(_currentPolygonIndex);
} }
QJsonDocument WimaController::saveToJson()
{
QJsonArray jsonArray;
for (int i = 0; i < _visualItems->count(); i++) {
QJsonObject json;
WimaArea* area = qobject_cast<WimaArea*>(_visualItems->get(i));
if (area == nullptr) {
qWarning("WimaController::saveToJson(): Internal error, area == nullptr!");
return QJsonDocument();
}
WimaGOperationArea* opArea = qobject_cast<WimaGOperationArea*>(area);
if (opArea != nullptr) {
opArea->saveToJson(json);
jsonArray.append(json);
break;
}
WimaServiceArea* serArea = qobject_cast<WimaServiceArea*>(area);
if (serArea != nullptr) {
serArea->saveToJson(json);
jsonArray.append(json);
break;
}
WimaVCorridor* corridor = qobject_cast<WimaVCorridor*>(area);
if (corridor != nullptr) {
corridor->saveToJson(json);
jsonArray.append(json);
break;
}
// if non of the obove branches was trigger, type must be WimaArea
area->saveToJson(json);
jsonArray.append(json);
}
return QJsonDocument(jsonArray);
}
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "QGCMapPolygon.h" #include "QGCMapPolygon.h"
...@@ -27,13 +27,15 @@ public: ...@@ -27,13 +27,15 @@ public:
Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged) Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged)
Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged) Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged)
Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged) Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged)
Q_PROPERTY(const QString currentFile READ currentFile NOTIFY currentFileChanged)
// Property accessors // Property accessors
PlanMasterController* masterController (void) const { return _masterController;} PlanMasterController* masterController (void) const { return _masterController; }
MissionController* missionController (void) const { return _missionController;} MissionController* missionController (void) const { return _missionController; }
QmlObjectListModel* visualItems (void) { return _visualItems; } QmlObjectListModel* visualItems (void) const { return _visualItems; }
int currentPolygonIndex (void) const { return _currentPolygonIndex; } int currentPolygonIndex (void) const { return _currentPolygonIndex; }
const QString& currentFile (void) const { return _currentFile; }
...@@ -59,19 +61,28 @@ public: ...@@ -59,19 +61,28 @@ public:
/// Recalculates vehicle corridor, flight path, etc. /// Recalculates vehicle corridor, flight path, etc.
Q_INVOKABLE bool updateMission(); Q_INVOKABLE bool updateMission();
Q_INVOKABLE void saveMission(); Q_INVOKABLE void saveToCurrent();
Q_INVOKABLE void loadMission(); Q_INVOKABLE void saveToFile(const QString& filename);
Q_INVOKABLE void loadFromFile();
Q_INVOKABLE void resetAllInteractive(void); Q_INVOKABLE void resetAllInteractive(void);
Q_INVOKABLE void setInteractive(void); Q_INVOKABLE void setInteractive(void);
// static Members
static const char* wimaFileExtension;
// Member Methodes
QJsonDocument saveToJson();
signals: signals:
void masterControllerChanged (void); void masterControllerChanged (void);
void missionControllerChanged (void); void missionControllerChanged (void);
void visualItemsChanged (void); void visualItemsChanged (void);
void currentPolygonIndexChanged (int index); void currentPolygonIndexChanged (int index);
void currentFileChanged ();
private slots: private slots:
void recalcVehicleCorridor(); void recalcVehicleCorridor();
...@@ -86,5 +97,6 @@ private: ...@@ -86,5 +97,6 @@ private:
PlanMasterController* _masterController; PlanMasterController* _masterController;
MissionController* _missionController; MissionController* _missionController;
int _currentPolygonIndex; int _currentPolygonIndex;
QString _currentFile;
}; };
...@@ -6,6 +6,7 @@ const char* WimaGOperationArea::bottomLayerAltitudeName = "BottomLayerAl ...@@ -6,6 +6,7 @@ const char* WimaGOperationArea::bottomLayerAltitudeName = "BottomLayerAl
const char* WimaGOperationArea::numberOfLayersName = "NumberOfLayers"; const char* WimaGOperationArea::numberOfLayersName = "NumberOfLayers";
const char* WimaGOperationArea::layerDistanceName = "LayerDistance"; const char* WimaGOperationArea::layerDistanceName = "LayerDistance";
const char* WimaGOperationArea::borderPolygonOffsetName = "BorderPolygonOffset"; const char* WimaGOperationArea::borderPolygonOffsetName = "BorderPolygonOffset";
const char* WimaGOperationArea::wimaGOperationAreaName = "Operation Area";
WimaGOperationArea::WimaGOperationArea(QObject *parent) WimaGOperationArea::WimaGOperationArea(QObject *parent)
: WimaGOperationArea (nullptr, parent) : WimaGOperationArea (nullptr, parent)
...@@ -20,11 +21,9 @@ WimaGOperationArea::WimaGOperationArea(WimaArea *other, QObject *parent) ...@@ -20,11 +21,9 @@ WimaGOperationArea::WimaGOperationArea(WimaArea *other, QObject *parent)
, _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName]) , _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName])
, _layerDistance (settingsGroup, _metaDataMap[layerDistanceName]) , _layerDistance (settingsGroup, _metaDataMap[layerDistanceName])
, _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName]) , _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName])
, _polyline (new WimaTrackerPolyline(this))
, _borderPolygon (new QGCMapPolygon(this)) , _borderPolygon (new QGCMapPolygon(this))
{ {
this->setObjectName("Operation Area"); this->setObjectName(wimaGOperationAreaName);
_polyline.bindPolygon(this);
connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon); connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon);
connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon); connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon);
//qWarning("Here I am!"); //qWarning("Here I am!");
...@@ -62,13 +61,62 @@ void WimaGOperationArea::setVehicleCorridor(WimaVCorridor *corridor) ...@@ -62,13 +61,62 @@ void WimaGOperationArea::setVehicleCorridor(WimaVCorridor *corridor)
} }
} }
void WimaGOperationArea::saveToJson(QJsonObject &json)
{
this->WimaArea::saveToJson(json);
json[bottomLayerAltitudeName] = _bottomLayerAltitude.rawValue().toDouble();
json[numberOfLayersName] = _numberOfLayers.rawValue().toInt();
json[layerDistanceName] = _layerDistance.rawValue().toDouble();
json[borderPolygonOffsetName] = _borderPolygonOffset.rawValue().toDouble();
json[areaTypeName] = wimaGOperationAreaName;
}
bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorString)
{
if (this->WimaArea::loadFromJson(json, errorString)) {
bool retVal = true;
if ( json.contains(bottomLayerAltitudeName) && json[bottomLayerAltitudeName].isDouble() ) {
_bottomLayerAltitude.setRawValue(json[bottomLayerAltitudeName].toDouble());
} else {
errorString.append("Could not load Bottom Layer Altitude!\n");
retVal = false;
}
if ( json.contains(numberOfLayersName) && json[numberOfLayersName].isDouble() ) {
_numberOfLayers.setRawValue(json[numberOfLayersName].toInt());
} else {
errorString.append("Could not load Number of Layers!\n");
retVal = false;
}
if ( json.contains(layerDistanceName) && json[layerDistanceName].isDouble() ) {
_layerDistance.setRawValue(json[layerDistanceName].toDouble());
} else {
errorString.append("Could not load Layer Distance!\n");
retVal = false;
}
if ( json.contains(borderPolygonOffsetName) && json[borderPolygonOffsetName].isDouble() ) {
_borderPolygonOffset.setRawValue(json[borderPolygonOffsetName].toDouble());
} else {
errorString.append("Could not load Border Polygon Offset!\n");
retVal = false;
}
return retVal;
} else {
return false;
}
}
void WimaGOperationArea::recalcBorderPolygon() void WimaGOperationArea::recalcBorderPolygon()
{ {
//qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble()); //qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble());
QGCMapPolygon* polyCopy = this->toQGCPolygon(this); QGCMapPolygon polyCopy = this->toQGCPolygon(this);
polyCopy->offset(_borderPolygonOffset.rawValue().toDouble()); polyCopy.offset(_borderPolygonOffset.rawValue().toDouble());
_borderPolygon.setPath(polyCopy->path()); _borderPolygon.setPath(polyCopy.path());
polyCopy->deleteLater(); polyCopy.deleteLater();
emit borderPolygonChanged(); emit borderPolygonChanged();
} }
......
...@@ -21,7 +21,6 @@ public: ...@@ -21,7 +21,6 @@ public:
Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT) Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT)
/*Q_PROPERTY(QmlObjectListModel* vehicleList READ vehicleList NOTIFY vehicleListChanged) /*Q_PROPERTY(QmlObjectListModel* vehicleList READ vehicleList NOTIFY vehicleListChanged)
Q_PROPERTY(QmlObjectListModel* vehiclePolygons READ vehiclePolygons NOTIFY vehiclePolygonsChanged)*/ Q_PROPERTY(QmlObjectListModel* vehiclePolygons READ vehiclePolygons NOTIFY vehiclePolygonsChanged)*/
Q_PROPERTY(WimaTrackerPolyline* polyline READ polyline CONSTANT)
Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged)
...@@ -46,16 +45,20 @@ public: ...@@ -46,16 +45,20 @@ public:
Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;} Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;}
/*QmlObjectListModel* vehicleList (void) const { return _vehicleList;} /*QmlObjectListModel* vehicleList (void) const { return _vehicleList;}
QmlObjectListModel* vehiclePolygons (void) const { return _vehiclePolygons;}*/ QmlObjectListModel* vehiclePolygons (void) const { return _vehiclePolygons;}*/
WimaTrackerPolyline* polyline (void) { return &_polyline;}
WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;} WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;}
QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;} QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;}
// Member Methodes
void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString &errorString);
static const char* settingsGroup; static const char* settingsGroup;
static const char* bottomLayerAltitudeName; static const char* bottomLayerAltitudeName;
static const char* numberOfLayersName; static const char* numberOfLayersName;
static const char* layerDistanceName; static const char* layerDistanceName;
static const char* borderPolygonOffsetName; static const char* borderPolygonOffsetName;
static const char* wimaGOperationAreaName;
signals: signals:
...@@ -83,7 +86,6 @@ private: ...@@ -83,7 +86,6 @@ private:
/*QmlObjectListModel* _vehicleList; /*QmlObjectListModel* _vehicleList;
QmlObjectListModel* _vehiclePolygons;*/ QmlObjectListModel* _vehiclePolygons;*/
WimaTrackerPolyline _polyline;
WimaVCorridor* _vehicleCorridor; WimaVCorridor* _vehicleCorridor;
QGCMapPolygon _borderPolygon; QGCMapPolygon _borderPolygon;
......
#include "WimaServiceArea.h" #include "WimaServiceArea.h"
const char* WimaServiceArea::wimaServiceAreaName = "Service Area";
WimaServiceArea::WimaServiceArea(QObject *parent): WimaServiceArea::WimaServiceArea(QObject *parent):
WimaServiceArea (nullptr, parent) WimaServiceArea (nullptr, parent)
{ {
...@@ -9,38 +11,52 @@ WimaServiceArea::WimaServiceArea(QObject *parent): ...@@ -9,38 +11,52 @@ WimaServiceArea::WimaServiceArea(QObject *parent):
WimaServiceArea::WimaServiceArea(WimaArea *other, QObject *parent): WimaServiceArea::WimaServiceArea(WimaArea *other, QObject *parent):
WimaArea (other, parent) WimaArea (other, parent)
{ {
_polyline.bindPolygon(this); this->setObjectName(wimaServiceAreaName);
this->setObjectName("Service Area");
} }
void WimaServiceArea::setTakeOffPosition(QGeoCoordinate* coordinate) void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate)
{ {
if(_takeOffPosition != *coordinate){ if(_takeOffPosition != coordinate){
_takeOffPosition = *coordinate; _takeOffPosition = coordinate;
emit takeOffPositionChanged(); emit takeOffPositionChanged();
} }
} }
void WimaServiceArea::setLandPosition(QGeoCoordinate* coordinate) void WimaServiceArea::setLandPosition(const QGeoCoordinate &coordinate)
{ {
if(_landPosition != *coordinate){ if(_landPosition != coordinate){
_landPosition = *coordinate; _landPosition = coordinate;
emit landPositionChanged(); emit landPositionChanged();
} }
} }
void WimaServiceArea::setVehicleCorridor(WimaVCorridor *corridor) void WimaServiceArea::setVehicleCorridor(WimaVCorridor &corridor)
{ {
if(corridor != nullptr){
if (corridor != _vehicleCorridor){ if (&corridor != _vehicleCorridor){
_vehicleCorridor = corridor; _vehicleCorridor = &corridor;
emit vehicleCorridorChanged(_vehicleCorridor); emit vehicleCorridorChanged(*_vehicleCorridor);
} }
else { else {
qWarning("WimaServiceArea::setVehicleCorridor(): new corridor equals old _vehicleCorridor!"); qWarning("WimaServiceArea::setVehicleCorridor(): new corridor equals old _vehicleCorridor!");
} }
}else{ }
qWarning("WimaServiceArea::setVehicleCorridor(): corridor == nullptr!");
void WimaServiceArea::saveToJson(QJsonObject &json)
{
this->WimaArea::saveToJson(json);
json[areaTypeName] = wimaServiceAreaName;
}
bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString)
{
if ( this->WimaArea::loadFromJson(json, errorString)) {
bool retVal = true;
// code for loading here
return retVal;
} else {
qWarning() << errorString;
return false;
} }
} }
...@@ -11,9 +11,8 @@ public: ...@@ -11,9 +11,8 @@ public:
WimaServiceArea(QObject* parent = nullptr); WimaServiceArea(QObject* parent = nullptr);
WimaServiceArea(WimaArea* other = nullptr, QObject* parent = nullptr); WimaServiceArea(WimaArea* other = nullptr, QObject* parent = nullptr);
Q_PROPERTY(QGeoCoordinate* takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged) Q_PROPERTY(const QGeoCoordinate& takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged)
Q_PROPERTY(QGeoCoordinate* landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged) Q_PROPERTY(const QGeoCoordinate& landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged)
Q_PROPERTY(WimaTrackerPolyline* polyline READ polyline CONSTANT)
// Overrides from WimaPolygon // Overrides from WimaPolygon
...@@ -21,23 +20,28 @@ public: ...@@ -21,23 +20,28 @@ public:
QString editorQML (void) const { return "WimaServiceAreaEditor.qml";} QString editorQML (void) const { return "WimaServiceAreaEditor.qml";}
// Property acessors // Property acessors
QGeoCoordinate* takeOffPosition (void) { return &_takeOffPosition;} const QGeoCoordinate& takeOffPosition (void) const { return _takeOffPosition;}
QGeoCoordinate* landPosition (void) { return &_landPosition;} const QGeoCoordinate& landPosition (void) const { return _landPosition;}
WimaTrackerPolyline* polyline (void) { return &_polyline;} WimaVCorridor& vehicleCorridor (void) const { return *_vehicleCorridor;}
WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;}
// Property setters // Property setters
void setTakeOffPosition (QGeoCoordinate* coordinate); void setTakeOffPosition (const QGeoCoordinate& coordinate);
void setLandPosition (QGeoCoordinate* coordinate); void setLandPosition (const QGeoCoordinate& coordinate);
void setVehicleCorridor (WimaVCorridor* corridor); void setVehicleCorridor (WimaVCorridor& corridor);
// Member Methodes
void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString& errorString);
// static Members
static const char* wimaServiceAreaName;
signals: signals:
void takeOffPositionChanged (void); void takeOffPositionChanged (void);
void landPositionChanged (void); void landPositionChanged (void);
void vehicleCorridorChanged (WimaVCorridor* corridor); void vehicleCorridorChanged (WimaVCorridor& corridor);
private: private:
WimaTrackerPolyline _polyline;
QGeoCoordinate _takeOffPosition; QGeoCoordinate _takeOffPosition;
QGeoCoordinate _landPosition; QGeoCoordinate _landPosition;
WimaVCorridor* _vehicleCorridor; WimaVCorridor* _vehicleCorridor;
......
#include "WimaVCorridor.h" #include "WimaVCorridor.h"
const char* WimaVCorridor::wimaVCorridorName = "Corridor";
WimaVCorridor::WimaVCorridor(QObject *parent): WimaVCorridor::WimaVCorridor(QObject *parent):
WimaVCorridor(nullptr, parent) WimaVCorridor(nullptr, parent)
{ {
...@@ -11,35 +13,43 @@ WimaVCorridor::WimaVCorridor(WimaArea *other, QObject *parent): ...@@ -11,35 +13,43 @@ WimaVCorridor::WimaVCorridor(WimaArea *other, QObject *parent):
,_serviceArea (nullptr) ,_serviceArea (nullptr)
,_opArea (nullptr) ,_opArea (nullptr)
{ {
this->setObjectName("Corridor"); this->setObjectName(wimaVCorridorName);
} }
void WimaVCorridor::setServiceArea(WimaServiceArea *serviceArea) void WimaVCorridor::setServiceArea(WimaServiceArea &serviceArea)
{ {
if (serviceArea != nullptr){ if(&serviceArea != _serviceArea){
if(serviceArea != _serviceArea){ _serviceArea = &serviceArea;
_serviceArea = serviceArea;
emit serviceAreaChanged(_serviceArea); emit serviceAreaChanged(_serviceArea);
}else { }else {
qWarning("WimaVCorridor::setServiceArea(): new serviceArea does not differ from old _serviceArea!"); qWarning("WimaVCorridor::setServiceArea(): new serviceArea does not differ from old _serviceArea!");
} }
}else {
qWarning("WimaVCorridor::setServiceArea(): serviceArea == nullptr!");
}
} }
void WimaVCorridor::setOpArea(WimaGOperationArea *opArea) void WimaVCorridor::setOpArea(WimaGOperationArea &opArea)
{ {
if (opArea != nullptr){ if(&opArea != _opArea){
if(&opArea != &_opArea){ _opArea = &opArea;
_opArea = opArea;
emit opAreaChanged(_opArea); emit opAreaChanged(_opArea);
}else { }else {
qWarning("WimaVCorridor::setOpArea(): new opArea does not differ from old _opArea!"); qWarning("WimaVCorridor::setOpArea(): new opArea does not differ from old _opArea!");
} }
}
}else { void WimaVCorridor::saveToJson(QJsonObject &json)
qWarning("WimaVCorridor::setOpArea(): opArea == nullptr!"); {
this->WimaArea::saveToJson(json);
json[areaTypeName] = wimaVCorridorName;
}
bool WimaVCorridor::loadFromJson(const QJsonObject &json, QString &errorString)
{
if ( this->WimaArea::loadFromJson(json, errorString)) {
bool retVal = true;
// code for loading here
return retVal;
} else {
qWarning() << errorString;
return false;
} }
} }
...@@ -17,10 +17,15 @@ public: ...@@ -17,10 +17,15 @@ public:
QString editorQML (void) const { return "WimaVCorridorEditor.qml";} QString editorQML (void) const { return "WimaVCorridorEditor.qml";}
// Methodes // Methodes
void setServiceArea (WimaServiceArea* serviceArea); void setServiceArea (WimaServiceArea& serviceArea);
void setOpArea (WimaGOperationArea* opArea); void setOpArea (WimaGOperationArea& opArea);
WimaServiceArea* serviceArea (void) const {return _serviceArea;} WimaServiceArea& serviceArea (void) const {return *_serviceArea;}
WimaGOperationArea* opArea (void) const {return _opArea;} WimaGOperationArea& opArea (void) const {return *_opArea;}
void saveToJson (QJsonObject& json);
bool loadFromJson (const QJsonObject& json, QString& errorString);
// static Members
static const char* wimaVCorridorName;
signals: signals:
void serviceAreaChanged (WimaServiceArea* serviceArea); void serviceAreaChanged (WimaServiceArea* serviceArea);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment