diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index a3a9ac9b1bcb3791ef76d2f37830d8084642af74..942ee057ce58b03d64bd9200b99bb69c7ac653a2 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -220,6 +220,7 @@ src/WimaView/WimaGOperationAreaEditor.qml src/WimaView/WimaServiceAreaEditor.qml src/WimaView/WimaVCorridorMapVisual.qml + src/WimaView/WimaAreaMapVisual.qml src/Settings/APMMavlinkStreamRate.SettingsGroup.json diff --git a/src/QmlControls/QGroundControl.Controls.qmldir b/src/QmlControls/QGroundControl.Controls.qmldir index fdfc2a1655ac5ceafe815b03f4dfdc56c4c4a30c..d6d7e8ed2d808b4b242c407009954b0be5bd7f9d 100644 --- a/src/QmlControls/QGroundControl.Controls.qmldir +++ b/src/QmlControls/QGroundControl.Controls.qmldir @@ -89,6 +89,7 @@ WimaMapVisual 1.0 WimaMapVisual.qml WimaGOperationAreaMapVisual 1.0 WimaGOperationAreaMapVisual.qml WimaGOperationAreaEditor 1.0 WimaGOperationAreaEditor.qml WimaServiceAreaMapVisual 1.0 WimaServiceAreaMapVisual.qml +WimaAreaMapVisual 1.0 WimaAreaMapVisual.qml WimaServiceAreaEditor 1.0 WimaServiceAreaEditor.qml WimaVCorridorMapVisual 1.0 WimaVCorridorMapVisual.qml WimaItemEditor 1.0 WimaItemEditor.qml diff --git a/src/Wima/WimaArea.cc b/src/Wima/WimaArea.cc index 9757cb93f99d1dd7a4b2d4b10ad57b7ca999da87..6288a873276bac7b8da3cf0b077e39e901679bb3 100644 --- a/src/Wima/WimaArea.cc +++ b/src/Wima/WimaArea.cc @@ -108,17 +108,16 @@ QGCMapPolygon* WimaArea::toQGCPolygon(WimaArea *poly) } } -WimaArea *WimaArea::joinPolygons(QList* polyList) +void WimaArea::join(QList* polyList, WimaArea* joinedPoly) { - return nullptr; + return; } -WimaArea *WimaArea::joinPolygons(WimaArea *poly1, WimaArea *poly2) +void WimaArea::join(WimaArea *poly1, WimaArea *poly2, WimaArea* joinedPoly) { if (poly1 != nullptr && poly2 != nullptr) { if (poly1->count() >= 3 && poly2->count() >= 3) { - WimaArea* joinedPolygon = new WimaArea(this); poly1->verifyClockwiseWinding(); poly2->verifyClockwiseWinding(); @@ -127,62 +126,117 @@ WimaArea *WimaArea::joinPolygons(WimaArea *poly1, WimaArea *poly2) WimaArea* crossPoly = poly2; // check for crossings with this polygon while "walking" // and swicht to this polygon on a intersection, // continue to walk towards higher indices - QGCMapPolyline lineSegment; // segment of walkerPoly, containing only two coordinates - int currentPolyIndex = 0; - QGeoCoordinate currentVertex = walkerPoly->vertexCoordinate(currentPolyIndex); + + // begin with the first index which is not inside crosspoly, if all Vertices are inside crosspoly return crosspoly + int startIndex = 0; + bool crossContainsWalker = true; + for (int i = 0; i < walkerPoly->count(); i++) { + if ( !crossPoly->containsCoordinate(walkerPoly->vertexCoordinate(i)) ) { + crossContainsWalker = false; + startIndex = i; + break; + } + } + + + if ( crossContainsWalker == true) { + joinedPoly->appendVertices(crossPoly->coordinateList()); + return; + } + + + QGeoCoordinate currentVertex = walkerPoly->vertexCoordinate(startIndex); + QGeoCoordinate startVertex = currentVertex; // possible nextVertex (if no intersection between currentVertex and protoVertex with crossPoly) - QGeoCoordinate protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(currentPolyIndex)); - do { - joinedPolygon->appendVertex(currentVertex); + QGeoCoordinate protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(startIndex)); + + int nextVertexIndex = walkerPoly->nextVertexIndex(startIndex); + while (1) { + qDebug("nextVertexIndex: %i", nextVertexIndex); + joinedPoly->appendVertex(currentVertex); QGCMapPolyline walkerPolySegment; walkerPolySegment.appendVertex(currentVertex); walkerPolySegment.appendVertex(protoNextVertex); - QList* intersectionList = intersects(&walkerPolySegment, crossPoly); + QList> neighbourList; + QList intersectionList; + qDebug("IntersectionList.size() on init: %i", intersectionList.size()); + intersects(&walkerPolySegment, crossPoly, &intersectionList, &neighbourList); + + qDebug("IntersectionList.size(): %i", intersectionList.size()); - if (intersectionList != nullptr) { - if (intersectionList->size() > 1*3) { + if (intersectionList.size() >= 1) { + int minDistIndex = 0; - } else if ( intersectionList->size() == 1*3) { - // intersectionList->takeAt(0); intersection pt. - // intersectionList->takeAt(1); neighbour of intersec. pt. inside crossPoly, lower index - // intersectionList->takeAt(2); neighbour of intersec. pt. inside crossPoly, higher index - currentVertex = intersectionList->takeAt(0); - protoNextVertex = intersectionList->takeAt(2); + if (intersectionList.size() > 1) { + double minDist = currentVertex.distanceTo(intersectionList.value(minDistIndex)); + for (int i = 1; i < intersectionList.size(); i++) { + double currentDist = currentVertex.distanceTo(intersectionList.value(i)); - //currentPolyIndex = crossPoly-> + if ( minDist > currentDist ) { + minDist = currentDist; + minDistIndex = i; + } + } + } + qDebug("MinDistIndex: %i", minDistIndex); + QGeoCoordinate protoCurrentVertex = intersectionList.value(minDistIndex); + // take numerical erros into account + if (protoCurrentVertex.distanceTo(currentVertex) > WimaArea::numericalAccuracy) { + currentVertex = protoCurrentVertex; + QPair neighbours = neighbourList.value(minDistIndex); + protoNextVertex = crossPoly->vertexCoordinate(neighbours.second); + nextVertexIndex = neighbours.second; + + // swap walker and cross poly + WimaArea* temp = walkerPoly; + walkerPoly = crossPoly; + crossPoly = temp; } else { - currentPolyIndex++; - currentVertex = walkerPoly->vertexCoordinate(currentPolyIndex);// change req. - protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(currentPolyIndex)); + currentVertex = walkerPoly->vertexCoordinate(nextVertexIndex); + protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(nextVertexIndex)); + nextVertexIndex = walkerPoly->nextVertexIndex(nextVertexIndex); } + } else { - return nullptr; + currentVertex = walkerPoly->vertexCoordinate(nextVertexIndex); + protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(nextVertexIndex)); + nextVertexIndex = walkerPoly->nextVertexIndex(nextVertexIndex); + } + + if (currentVertex == startVertex) { + return; } - } while (currentPolyIndex != 0 || walkerPoly != poly1); + } - return joinedPolygon; } else { qWarning("WimaArea::joinPolygons(poly1, poly2): poly->count() < 3"); - return nullptr; + return; } } else { qWarning("WimaArea::joinPolygons(poly1, poly2): nullptr"); - return nullptr; + return; } } +void WimaArea::join(WimaArea *poly) +{ + WimaArea joinedArea(this); + join(this, poly, &joinedArea); + this->setPath(joinedArea.path()); + return; +} bool WimaArea::isDisjunct(QList* polyList) { // needs improvement if (polyList != nullptr){ for (int i = 0;i < polyList->size()-1; i++) { - WimaArea* currPoly = polyList->takeAt(i); + WimaArea* currPoly = polyList->value(i); for (int j = i+1; i < polyList->size(); j++) { - if (isDisjunct(currPoly, polyList->takeAt(j))) { + if (isDisjunct(currPoly, polyList->value(j))) { return false; } } @@ -236,82 +290,126 @@ int WimaArea::previousVertexIndex(int index) } } -QGeoCoordinate* WimaArea::intersects(QGCMapPolyline *geoLine1, QGCMapPolyline *geoLine2) +bool WimaArea::intersects(QGCMapPolyline *line1, QGCMapPolyline *line2, QGeoCoordinate *intersectionPt) { - if (geoLine1 != nullptr && geoLine2 != nullptr) { - if (geoLine1->count() == 2 && geoLine2->count() == 2 ) { + if (line1 != nullptr && line2 != nullptr && intersectionPt != nullptr) { + if (line1->count() == 2 && line2->count() == 2 ) { QPointF pt11(0, 0); double x, y, z; - QGeoCoordinate origin = geoLine1->vertexCoordinate(0); - convertGeoToNed(geoLine1->vertexCoordinate(1), origin, &x, &y, &z); + QGeoCoordinate origin = line1->vertexCoordinate(0); + convertGeoToNed(line1->vertexCoordinate(1), origin, &x, &y, &z); QPointF pt12(x, y); QLineF kartLine1(pt11, pt12); - convertGeoToNed(geoLine2->vertexCoordinate(0), origin, &x, &y, &z); + convertGeoToNed(line2->vertexCoordinate(0), origin, &x, &y, &z); QPointF pt21(x, y); - convertGeoToNed(geoLine2->vertexCoordinate(1), origin, &x, &y, &z); + convertGeoToNed(line2->vertexCoordinate(1), origin, &x, &y, &z); QPointF pt22(x, y); QLineF kartLine2(pt21, pt22); QPointF intersectionPoint; - if (kartLine1.intersect(kartLine2, &intersectionPoint) != QLineF::NoIntersection) { - QGeoCoordinate* retValue = new QGeoCoordinate(); - convertNedToGeo(intersectionPoint.x(), intersectionPoint.y(), origin.altitude(), origin, retValue); - - return retValue; + if (kartLine1.intersect(kartLine2, &intersectionPoint) == QLineF::BoundedIntersection) { + convertNedToGeo(intersectionPoint.x(), intersectionPoint.y(), origin.altitude(), origin, intersectionPt); + return true; } else { - return nullptr; + return false; } } else { - qWarning("WimaArea::intersect(geoLine1, geoLine2): geoLine1->count() != 2 || geoLine2->count() != 2!"); - return nullptr; + qWarning("WimaArea::intersect(line1, line2): line1->count() != 2 || line2->count() != 2!"); + return false; } + + } else { - qWarning("WimaArea::intersect(geoLine1, geoLine2): geoLine1 == nullptr || geoLine2 == nullptr!"); - return nullptr; + qWarning("WimaArea::intersect(line1, line2): nullptr!"); + return false; } } -QList* WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly) +bool WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly, QList *intersectionList, QList > *neighbourlist) { - QList* intersectionList = new QList(); - if (line != nullptr && poly != nullptr) { + if (line != nullptr && poly != nullptr && neighbourlist != nullptr && intersectionList != nullptr) { + neighbourlist->clear(); + intersectionList->clear(); + if (line->count() == 2 && poly->count() >= 3) { - QVariantList polyPath = poly->path(); - QGeoCoordinate pt1; - QGeoCoordinate pt2; + for (int i = 0; i < poly->count(); i++) { QGCMapPolyline polySegment; - QGeoCoordinate currentVertex = polyPath.takeAt(i).value(); - QGeoCoordinate nextVertex = polyPath.takeAt(poly->nextVertexIndex(i)).value(); + QGeoCoordinate currentVertex = poly->vertexCoordinate(i); + QGeoCoordinate nextVertex = poly->vertexCoordinate(poly->nextVertexIndex(i)); polySegment.appendVertex(currentVertex); polySegment.appendVertex(nextVertex); - QGeoCoordinate* intersectionPoint = intersects(line, &polySegment); + QGeoCoordinate intersectionPoint; + bool retVal = intersects(line, &polySegment, &intersectionPoint); + + + if (retVal != false){ + intersectionList->append(intersectionPoint); - if (intersectionPoint != nullptr){ - intersectionList->append(*intersectionPoint); - intersectionList->append(currentVertex); - intersectionList->append(nextVertex); + QPair neighbours; + neighbours.first = i; + neighbours.second = poly->nextVertexIndex(i); + neighbourlist->append(neighbours); } } - return intersectionList; + + if (intersectionList->count() > 0) { + return true; + } else { + return false; + } } else { qWarning("WimaArea::intersects(line, poly): line->count() != 2 || poly->count() < 3"); - return nullptr; + return false; } } else { - qWarning("WimaArea::intersects(line, poly): line == nullptr || poly == nullptr!"); - return nullptr; + qWarning("WimaArea::intersects(line, poly): nullptr!"); + return false; } } +double WimaArea::distInsidePoly(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly) +{ + if (c1 != nullptr && c2 != nullptr && poly != nullptr) { + QGCMapPolyline line; + line.appendVertex(*c1); + line.appendVertex(*c2); + QList intersectionList; + QList > neighbourlist; + if (poly->containsCoordinate(*c1) && poly->containsCoordinate(*c2) && !intersects(&line, poly, &intersectionList, &neighbourlist)) { + return c1->distanceTo(*c2); + } else { + return std::numeric_limits::infinity(); + } + } else { + qWarning("WimaArea::distInsidePoly(QGeoCoordinate*, QGeoCoordinate*, WimaArea*): nullptr!"); + return std::numeric_limits::infinity(); + } +} + +void WimaArea::dijkstraPath(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly, QGCMapPolyline* dijkistraPath) +{ + if (c1 != nullptr && c2 != nullptr && poly != nullptr && dijkistraPath != nullptr) { + struct Node{ + QGeoCoordinate c; + double predecessorIndex; + double distane; + }; + + QList nodeList; + QList visitedNodesList; + } else { + qWarning(" WimaArea::dijkstraPath(QGeoCoordinate*, QGeoCoordinate*, WimaArea*): nullptr!"); + } +} diff --git a/src/Wima/WimaArea.h b/src/Wima/WimaArea.h index b96fa2d3b9effbe1a1525d0e0ac2907b93f73438..533e45a8148136ab052dcdb8d042eb251da82543 100644 --- a/src/Wima/WimaArea.h +++ b/src/Wima/WimaArea.h @@ -9,6 +9,7 @@ #include #include #include "QGCGeo.h" +#include class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas { @@ -42,34 +43,41 @@ public: template QList* 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); + 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* polyList); + QGeoCoordinate getClosestVertex (QGeoCoordinate coordinate); + QGCMapPolygon* toQGCPolygon (WimaArea* poly); + static void join (QList* polyList, WimaArea* joinedPoly); /// 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* polyList); - bool isDisjunct (WimaArea* poly1, WimaArea* poly2); + static void join (WimaArea* poly1, WimaArea* poly2, WimaArea* joinedPoly); + void join (WimaArea* poly); + bool isDisjunct (QList* 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); + 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); + 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); + /// @param intersectionPt Coordinate item to store intersection pt. in. + /// @return false on error or no intersection, true else + static bool intersects(QGCMapPolyline* line1, QGCMapPolyline* line2, QGeoCoordinate* intersectionPt); /// 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 and the two neares neighbours of poly to the intersection point if line intersects poly, or an empty list else. - /// The first entry is the first intersec. pt. (if existing). The second and third entries are the nearest neighbours of the first intersec. pt. in poly - /// The fourth entry is the second intersec. pt. (if existing). The fifth and sixth entries are the nearest neighbours of the second intersec. pt. in poly - QList* intersects(QGCMapPolyline* line, WimaArea* poly); + /// @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.) + /// @return false on error or no intersection, true else + static bool intersects(QGCMapPolyline* line, WimaArea* poly, QList* intersectionList, QList>* 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(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly); + /// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm + static void dijkstraPath(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly, QGCMapPolyline *dijkstraPath); // Accurracy used to compute isDisjunct static const double numericalAccuracy; diff --git a/src/Wima/WimaController.cc b/src/Wima/WimaController.cc index eb20d011196e186a060d5ea0bcacddd7b97d9c66..83ec4179ba34278916613a638498415f98659686 100644 --- a/src/Wima/WimaController.cc +++ b/src/Wima/WimaController.cc @@ -73,55 +73,13 @@ void WimaController::addServiceArea() emit visualItemsChanged(); } -bool WimaController::addVehicleCorridor(WimaGOperationArea *opArea, WimaServiceArea *serviceArea) +void WimaController::addVehicleCorridor() { - WimaVCorridor* corridor = nullptr; - if (opArea != nullptr && serviceArea != nullptr){ - for (int i = 0; i < _visualItems->count(); i++) { - corridor = qobject_cast(_visualItems->get(i)); - if (corridor != nullptr){ - if (corridor->serviceArea() == serviceArea && corridor->opArea() == opArea){ - break; - }else { - corridor = nullptr; - } - } - } - - bool newCorridorCreated = false; - if(corridor == nullptr){ - corridor = new WimaVCorridor(opArea); - newCorridorCreated = true; - }else { - corridor->clear(); - } - - QList opAreaPolyline = opArea->polyline()->coordinateList(); - QList serAreaPolyline = serviceArea->polyline()->coordinateList(); - if (opAreaPolyline.size() > 1 && serAreaPolyline.size() > 1){ - corridor->appendVertices(opAreaPolyline); - corridor->appendVertices(serAreaPolyline); - - if (newCorridorCreated){ - corridor->setServiceArea(serviceArea); - corridor->setOpArea(opArea); - serviceArea->setVehicleCorridor(corridor); - opArea->setVehicleCorridor(corridor); - _visualItems->append(corridor); - emit visualItemsChanged(); - } - - return true; - }else { - qWarning("WimaController::addVehicleCorridor(): OpArea or serviceArea polyline size <= 1!"); - if (newCorridorCreated){ - corridor->deleteLater(); - } - return false; - } - }else { - return false; - } + WimaVCorridor* corridor = new WimaVCorridor(this); + _visualItems->append(corridor); + int newIndex = _visualItems->count()-1; + setCurrentPolygonIndex(newIndex); + emit visualItemsChanged(); } void WimaController::startMission() @@ -166,14 +124,23 @@ bool WimaController::updateMission() } } - // calc. vehicle corridor - if (opArea != nullptr && serArea != nullptr){ - if(!addVehicleCorridor(opArea, serArea)){ - return false; + // pick first WimaVCorridor + WimaVCorridor* corridor = nullptr; + for (int i = 0; i < _visualItems->count(); i++) { + WimaVCorridor* currentArea = qobject_cast(_visualItems->get(i)); + if (currentArea != nullptr){ + corridor = currentArea; + break; } - }else{ - return false; } + + + // join service area and op area + WimaArea* joinedArea = new WimaArea(this); + WimaArea::join(corridor, serArea, joinedArea); + joinedArea->join(opArea); + + _visualItems->append(joinedArea); // reset visual items _missionController->removeAll(); diff --git a/src/Wima/WimaController.h b/src/Wima/WimaController.h index 8a03d90b874e886492f6dd1a4974b21a75e4b2b2..49ee502ea97a61d68663d7343398ed7800fbd4ac 100644 --- a/src/Wima/WimaController.h +++ b/src/Wima/WimaController.h @@ -50,7 +50,7 @@ public: Q_INVOKABLE void removeArea(int index); Q_INVOKABLE void addServiceArea(); /// @return true if a vehicle corridor was added sucessfully and false otherwise. - bool addVehicleCorridor(WimaGOperationArea* opArea, WimaServiceArea* serviceArea); + Q_INVOKABLE void addVehicleCorridor(); Q_INVOKABLE void startMission(); Q_INVOKABLE void abortMission(); diff --git a/src/WimaView/WimaAreaMapVisual.qml b/src/WimaView/WimaAreaMapVisual.qml new file mode 100644 index 0000000000000000000000000000000000000000..da3aa230878319c695630ec6557b56aac7e07c2e --- /dev/null +++ b/src/WimaView/WimaAreaMapVisual.qml @@ -0,0 +1,87 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtLocation 5.3 +import QtPositioning 5.3 + +import QGroundControl 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.FlightMap 1.0 + +/// Wima Area visuals +Item { + id: _root + + property var map ///< Map control to place item in + property var qgcView ///< QGCView to use for popping dialogs + + property var areaItem: object + property var _polygon: areaItem + + signal clicked(int sequenceNumber) + + /// Add an initial 4 sided polygon if there is none + function _addInitialPolygon() { + if (_polygon.count < 3) { + // Initial polygon is inset to take 2/3rds space + var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) + rect.x += (rect.width * 0.25) / 2 + rect.y += (rect.height * 0.25) / 2 + rect.width *= 0.75 + rect.height *= 0.75 + + var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) + var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) + var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) + var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) + var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) + + // Adjust polygon to max size + var maxSize = 100 + var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 + var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 + topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) + topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) + bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) + bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) + + _polygon.appendVertex(topLeftCoord) + _polygon.appendVertex(topRightCoord) + _polygon.appendVertex(bottomRightCoord) + _polygon.appendVertex(bottomLeftCoord) + } + } + + + + + + Component.onCompleted: { + _addInitialPolygon() + } + + Component.onDestruction: { + } + + + WimaMapPolygonVisuals { + qgcView: _root.qgcView + mapControl: map + mapPolygon: _polygon + borderWidth: 1 + borderColor: "black" + interiorColor: "gray" + interiorOpacity: 0.25 + } + +} diff --git a/src/WimaView/WimaMapPolygonVisuals.qml b/src/WimaView/WimaMapPolygonVisuals.qml index 212439abcc690be0ed7e5f29d35c38e54ba29090..39ea42181bbc7ea30439f7601b122cacce865ac2 100644 --- a/src/WimaView/WimaMapPolygonVisuals.qml +++ b/src/WimaView/WimaMapPolygonVisuals.qml @@ -33,6 +33,7 @@ Item { property int borderWidth: 0 property color borderColor: "black" property bool initPolygon: false + property bool showVertexIndex: true property var _polygonComponent property var _dragHandlesComponent @@ -417,6 +418,13 @@ Item { color: Qt.rgba(1,1,1,0.8) border.color: Qt.rgba(0,0,0,0.25) border.width: 1 + + QGCLabel { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + color: "black" + text: showVertexIndex ? polygonVertex : "" + } } } } diff --git a/src/WimaView/WimaVCorridorMapVisual.qml b/src/WimaView/WimaVCorridorMapVisual.qml index a22033a2cbff35b9561783c7675f89402a2fc4a6..bdc411ca38c13f95e502f54b62d66875d788619d 100644 --- a/src/WimaView/WimaVCorridorMapVisual.qml +++ b/src/WimaView/WimaVCorridorMapVisual.qml @@ -71,7 +71,7 @@ Item { Component.onCompleted: { - //_addInitialPolygon() + _addInitialPolygon() //_addInitialPolyline() } @@ -85,7 +85,6 @@ Item { borderWidth: 1 borderColor: "black" interiorColor: "blue" - interactive: false interiorOpacity: 0.2 } diff --git a/src/WimaView/WimaView.qml b/src/WimaView/WimaView.qml index 1dbb9a2cc3b6a06bdcd21f73f8c0cbe36f29dabd..d0066150949b208b23269b8b99b8275021410dc2 100644 --- a/src/WimaView/WimaView.qml +++ b/src/WimaView/WimaView.qml @@ -576,11 +576,15 @@ QGCView { dropPanelComponent: syncDropPanel }, { - name: qsTr("Global Area"), + name: qsTr("Global"), iconSource: "/qmlimages/Target.svg" }, { - name: qsTr("Service Area"), + name: qsTr("Service"), + iconSource: "/qmlimages/noFlyArea.svg" + }, + { + name: qsTr("Corridor"), iconSource: "/qmlimages/noFlyArea.svg" }, { @@ -621,16 +625,19 @@ QGCView { _addWaypointOnClick = false*/ break case 3: + wimaController.addVehicleCorridor(); + break + case 4: /*if (_singleComplexItem) { addComplexItem(_missionController.complexMissionItemNames[0]) }*/ wimaController.updateMission(); break - case 5: + case 6: editorMap.zoomLevel += 0.5 break - case 6: + case 7: editorMap.zoomLevel -= 0.5 break }