From c878bb8aa83b2038ec4347fea7d12ec961d7407a Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Wed, 26 Jun 2019 16:58:23 +0200 Subject: [PATCH] WimaController renamed to WimaPlaner, WimaController is now responsible for coordination purposes in flyView --- qgroundcontrol.pro | 7 +- src/MissionManager/QGCMapPolygon.cc | 20 +-- src/MissionManager/QGCMapPolygon.h | 23 +-- src/Wima/WimaArea.cc | 117 ++++++------ src/Wima/WimaArea.h | 75 ++++---- src/Wima/WimaController.cc | 268 +++++++++++----------------- src/Wima/WimaController.h | 49 +++-- src/Wima/WimaDataContainer.cc | 24 +-- src/Wima/WimaDataContainer.h | 39 ++-- src/Wima/WimaGOperationArea.cc | 46 +++-- src/Wima/WimaGOperationArea.h | 43 ++--- src/Wima/WimaPlaner.cc | 6 + src/Wima/WimaPlaner.h | 11 ++ src/Wima/WimaServiceArea.cc | 22 +-- src/Wima/WimaServiceArea.h | 20 +-- src/Wima/WimaVCorridor.cc | 19 +- src/Wima/WimaVCorridor.h | 6 +- 17 files changed, 367 insertions(+), 428 deletions(-) create mode 100644 src/Wima/WimaPlaner.cc create mode 100644 src/Wima/WimaPlaner.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index c99ebf2fc..78514a88d 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -414,7 +414,9 @@ HEADERS += \ src/Wima/WimaTrackerPolyline.h \ src/Wima/WimaController.h \ src/Wima/WimaVehicle.h \ - src/Wima/WimaDataContainer.h + src/Wima/WimaDataContainer.h \ + src/Wima/WimaPlaner.h \ + src/Wima/WimaPlaner.h SOURCES += \ src/api/QGCCorePlugin.cc \ src/api/QGCOptions.cc \ @@ -428,7 +430,8 @@ SOURCES += \ src/Wima/WimaTrackerPolyline.cc \ src/Wima/WimaController.cc \ src/Wima/WimaVehicle.cc \ - src/Wima/WimaDataContainer.cc + src/Wima/WimaDataContainer.cc \ + src/Wima/WimaPlaner.cc # # Unit Test specific configuration goes here (requires full debug build with all plugins) diff --git a/src/MissionManager/QGCMapPolygon.cc b/src/MissionManager/QGCMapPolygon.cc index 4de88a90e..af4d65fef 100644 --- a/src/MissionManager/QGCMapPolygon.cc +++ b/src/MissionManager/QGCMapPolygon.cc @@ -234,6 +234,8 @@ QList QGCMapPolygon::coordinateList(void) const void QGCMapPolygon::splitPolygonSegment(int vertexIndex) { int nextIndex = vertexIndex + 1; + + if (nextIndex > _polygonPath.length() - 1) { nextIndex = 0; } @@ -367,6 +369,11 @@ void QGCMapPolygon::setInteractive(bool interactive) } } +void QGCMapPolygon::update(const QGCMapPolygon &poly) +{ + this->setPath(poly.path()); +} + void print(const QGCMapPolygon &poly) { QString message; @@ -391,19 +398,6 @@ void print(const QGCMapPolygon &poly, QString &outputString) 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()) { diff --git a/src/MissionManager/QGCMapPolygon.h b/src/MissionManager/QGCMapPolygon.h index 4e8cbec6c..f98a0f25b 100644 --- a/src/MissionManager/QGCMapPolygon.h +++ b/src/MissionManager/QGCMapPolygon.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** * * (c) 2009-2016 QGROUNDCONTROL PROJECT * @@ -99,14 +99,10 @@ public: QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; } QmlObjectListModel& pathModel (void) { return _polygonModel; } - void setPath (const QList& path); - void setPath (const QVariantList& path); - void setCenter (QGeoCoordinate newCenter); - void setCenterDrag (bool centerDrag); - void setInteractive (bool interactive); + /// Updates this with data from poly + void update(const QGCMapPolygon &poly); // Friends - friend void swap(QGCMapPolygon& poly1, QGCMapPolygon& poly2); friend void print(const QGCMapPolygon& poly, QString& outputString); friend void print(const QGCMapPolygon& poly); @@ -122,10 +118,17 @@ signals: void centerDragChanged (bool centerDrag); void interactiveChanged (bool interactive); +public slots: + void setPath (const QList& path); + void setPath (const QVariantList& path); + void setCenter (QGeoCoordinate newCenter); + void setCenterDrag (bool centerDrag); + void setInteractive (bool interactive); + private slots: - void _polygonModelCountChanged(int count); - void _polygonModelDirtyChanged(bool dirty); - void _updateCenter(void); + void _polygonModelCountChanged (int count); + void _polygonModelDirtyChanged (bool dirty); + void _updateCenter (void); private: void _init(void); diff --git a/src/Wima/WimaArea.cc b/src/Wima/WimaArea.cc index 7f7e7bfcc..571a9fb12 100644 --- a/src/Wima/WimaArea.cc +++ b/src/Wima/WimaArea.cc @@ -26,42 +26,14 @@ WimaArea::WimaArea(const WimaArea &other, QObject *parent) _maxAltitude = other.maxAltitude(); } -WimaArea &WimaArea::operator=(WimaArea other) -{ - swap(*this, other); // copy-swap-idiom - - return *this; -} - void WimaArea::setMaxAltitude(double alt) { - if(alt > 0 && alt != _maxAltitude){ + if ( alt > 0 && qFuzzyCompare(alt, _maxAltitude) ) { _maxAltitude = alt; emit maxAltitudeChanged(); } } - - -/*QList* WimaArea::splitArea(WimaArea *polygonToSplitt, int numberOfFractions) -{ - if(numberOfFractions > 0 && polygonToSplitt != nullptr){ - WimaArea* poly; - if(p) - = new WimaArea(polygonToSplitt, this); - QList* list = new QList(); - list->append(poly); - return list; - } - return nullptr; -} - - -QList* WimaArea::splitArea(int numberOfFractions) -{ - return splitPolygonArea(this, numberOfFractions); -}*/ - int WimaArea::getClosestVertexIndex(const QGeoCoordinate &coordinate) const { if (this->count() == 0) { @@ -327,32 +299,39 @@ bool WimaArea::intersects(const QGCMapPolyline &line1, const QGCMapPolyline &lin } } -bool WimaArea::intersects(const QGCMapPolyline& line, const WimaArea& poly, QList& intersectionList, QList >& neighbourlist) +bool WimaArea::intersects(const QGCMapPolyline &line, + const WimaArea &poly, + QList &intersectionList, + QList > &neighbourList) { - neighbourlist.clear(); + // ================ Brief Explanation ================ + // This function checks whether line intersects with the border line of poly + // Returns true if at least one intersection occurs, false else. + // Stores the intersection points inside intersectionList. + // Stores the indices of the cloest two polygon vetices for each of coorespoinding intersection points in neighbourList intersectionList.clear(); + neighbourList.clear(); - if (line.count() == 2 && poly.count() >= 3) { - for (int i = 0; i < poly.count(); i++) { - QGCMapPolyline polySegment; - QGeoCoordinate currentVertex = poly.vertexCoordinate(i); - QGeoCoordinate nextVertex = poly.vertexCoordinate(poly.nextVertexIndex(i)); - polySegment.appendVertex(currentVertex); - polySegment.appendVertex(nextVertex); + if (line.count() == 2 && poly.count() >= 3) { // are line a proper line and poly a proper poly? - QGeoCoordinate intersectionPoint; - //bool retVal2 = intersects(line, line, &intersectionPoint); - bool retVal = intersects(line, polySegment, intersectionPoint); + // Asseble a line form each tow consecutive polygon vertices and check whether it intersects with line + for (int i = 0; i < poly.count(); i++) { + QGCMapPolyline interatorLine; + QGeoCoordinate currentVertex = poly.vertexCoordinate(i); + QGeoCoordinate nextVertex = poly.vertexCoordinate(poly.nextVertexIndex(i)); + interatorLine.appendVertex(currentVertex); + interatorLine.appendVertex(nextVertex); - if (retVal != false){ + QGeoCoordinate intersectionPoint; + if ( intersects(line, interatorLine, intersectionPoint) ){ intersectionList.append(intersectionPoint); QPair neighbours; neighbours.first = i; neighbours.second = poly.nextVertexIndex(i); - neighbourlist.append(neighbours); + neighbourList.append(neighbours); } } @@ -390,42 +369,54 @@ double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate & } } -bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &end, const WimaArea &poly, QList &dijkstraPath) +bool WimaArea::dijkstraPath(const QGeoCoordinate &start, + const QGeoCoordinate &end, + const WimaArea &poly, + QList &dijkstraPath) { + // ================ Brief Explanation ================ + // This function calculates the shortes Path between two GeoCoordinates (start, end) using the Dijkstra Algorithm. + // The path will be inside the polygon poly if possible. + // Stores the result inside dijkstraPath + // Returns true if a valid path was found. if ( isSelfIntersecting(poly) ) { return false; } + // Each QGeoCoordinate gets stuff into a Node + /// @param distance is the distance between the Node and it's predecessor struct Node{ QGeoCoordinate coordinate; double distance = std::numeric_limits::infinity(); Node* predecessorNode = nullptr; }; + // The list with all Nodes (start, end + poly.path()) QList nodeList; + // This list will be initalized with (pointer to) all elements of nodeList. + // Elements will be successively remove during the execution of the Dijkstra Algorithm. QList workingSet; - - // initialize - // start + // initialize nodeList + // start cooridnate Node startNode; startNode.coordinate = start; startNode.distance = 0; nodeList.append(startNode); - //poly + //poly cooridnates for (int i = 0; i < poly.count(); i++) { Node node; node.coordinate = poly.vertexCoordinate(i); nodeList.append(node); } - //end + //end coordinate Node endNode; endNode.coordinate = end; nodeList.append(endNode); - // working set + // initialize working set for (int i = 0; i < nodeList.size(); i++) { Node* nodePtr = &nodeList[i]; workingSet.append(nodePtr); @@ -453,8 +444,9 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e for (int i = 0; i < workingSet.size(); i++) { Node* v = workingSet[i]; - // is neighbour? + // is neighbour? dist == infinity if no neihbour double dist = distInsidePoly(u->coordinate, v->coordinate, poly); + // is ther a alternative path which is shorter? double alternative = u->distance + dist; if (alternative < v->distance) { v->distance = alternative; @@ -463,14 +455,17 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e } } + // end Djikstra Algorithm + - // create path + // check it the Algorithm was sucessful Node* Node = &nodeList.last(); if (Node->predecessorNode == nullptr) { qWarning("WimaArea::dijkstraPath(): Error, no path found!"); return false; } + // assemble path while (1) { dijkstraPath.prepend(Node->coordinate); @@ -540,6 +535,12 @@ bool WimaArea::loadFromJson(const QJsonObject &json, QString& errorString) } } +void WimaArea::update(const WimaArea &area) +{ + this->QGCMapPolygon::update(area); + this->setMaxAltitude(area.maxAltitude()); +} + void WimaArea::init() { this->setObjectName(wimaAreaName); @@ -554,16 +555,8 @@ void print(const WimaArea &area) void print(const WimaArea &area, QString &outputString) { - outputString.append(QString("Type: %s").arg(area.objectName())); + outputString.append(QString("Type: %1").arg(area.objectName())); print(static_cast(area), outputString); - outputString.append(QString("Maximum Altitude: %.3f").arg(area._maxAltitude)); -} - - -void swap(WimaArea &area1, WimaArea &area2) -{ - using std::swap; - swap(static_cast(area1), static_cast(area2)); - swap(area1._maxAltitude, area2._maxAltitude); + outputString.append(QString("Maximum Altitude: %1").arg(area._maxAltitude)); } diff --git a/src/Wima/WimaArea.h b/src/Wima/WimaArea.h index e95950309..b8a02d1d2 100644 --- a/src/Wima/WimaArea.h +++ b/src/Wima/WimaArea.h @@ -17,72 +17,73 @@ class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas public: 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(double maxAltitude READ maxAltitude WRITE setMaxAltitude NOTIFY maxAltitudeChanged) + Q_PROPERTY(QString mapVisualQML READ mapVisualQML CONSTANT) + Q_PROPERTY(QString editorQML READ editorQML CONSTANT) //Property accessors - double maxAltitude (void) const { return _maxAltitude;} + double maxAltitude (void) const { return _maxAltitude;} + // overrides from WimaArea virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";} virtual QString editorQML (void) const { return "WimaAreaEditor.qml";} - //Property setters - void setMaxAltitude (double alt); - void setVehicle (WimaVehicle* vehicle); - // Member Methodes //iterates over all vertices in _polygon and returns the index of that one closest to coordinate - int getClosestVertexIndex (const QGeoCoordinate& coordinate) const; + int getClosestVertexIndex (const QGeoCoordinate& coordinate) const; //iterates over all vertices in _polygon and returns that one closest to coordinate - QGeoCoordinate getClosestVertex (const QGeoCoordinate& coordinate) const; - static QGCMapPolygon toQGCPolygon (const WimaArea& poly); - QGCMapPolygon toQGCPolygon () const; - static void join (QList* 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 true if polygons have been joined, false else - static bool join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly); - bool join (WimaArea &poly); - bool isDisjunct (QList* polyList);// change to & notation, if necessary - bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary + QGeoCoordinate getClosestVertex (const QGeoCoordinate& coordinate) const; + QGCMapPolygon toQGCPolygon () const; + void join (QList* polyList, WimaArea* joinedPoly);// change to & notation + bool join (WimaArea &poly); + bool isDisjunct (QList* polyList);// change to & notation, if necessary + bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary /// 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) const; + int nextVertexIndex (int index) const; /// 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) const; + int previousVertexIndex (int index) const; + + + void saveToJson (QJsonObject& jsonObject); + bool loadFromJson (const QJsonObject &jsonObject, QString& errorString); + + // static Methodes + static QGCMapPolygon toQGCPolygon (const WimaArea& poly); + /// 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 true if polygons have been joined, false else + static bool join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly); /// 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 /// @param intersectionPt Coordinate item to store intersection pt. in. /// @return false on error or no intersection, true else - static bool intersects(const QGCMapPolyline& line1, const 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) /// @param line line containing two coordinates, height not taken into account /// @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(const QGCMapPolyline& line, const WimaArea& poly, QList& intersectionList, QList>& neighbourlist); + static bool intersects (const QGCMapPolyline& line, const 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(const QGeoCoordinate& c1, const QGeoCoordinate& c2, 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 /// @return true if path was found, false else - static bool dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList& dijkstraPath); + static bool dijkstraPath (const QGeoCoordinate& c1, const QGeoCoordinate& c2, + const WimaArea& poly, QList& 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); + static bool isSelfIntersecting (const WimaArea& poly); + bool isSelfIntersecting (); // 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 @@ -99,8 +100,12 @@ signals: void maxAltitudeChanged (void); void vehicleChanged (void); +public slots: + void setMaxAltitude (double alt); + /// Updates this with data from area + void update(const WimaArea& area); -protected: +private: double _maxAltitude; private: diff --git a/src/Wima/WimaController.cc b/src/Wima/WimaController.cc index 5568bae1a..7f9ef2399 100644 --- a/src/Wima/WimaController.cc +++ b/src/Wima/WimaController.cc @@ -6,7 +6,6 @@ const char* WimaController::missionItemsName = "MissionItems"; WimaController::WimaController(QObject *parent) : QObject (parent) - , _flyView (true) , _readyForSaveSend (false) , _currentPolygonIndex (-1) , _container (nullptr) @@ -18,7 +17,7 @@ WimaController::WimaController(QObject *parent) connect(this, &WimaController::currentPolygonIndexChanged, this, &WimaController::recalcPolygonInteractivity); } -const QmlObjectListModel* WimaController::visualItems() const +QmlObjectListModel* WimaController::visualItems() { return &_visualItems; } @@ -76,33 +75,18 @@ void WimaController::setDataContainer(WimaDataContainer *container) if (_container == nullptr && container != nullptr) { _container = container; - if (_flyView) { - downloadFromContainer(); - _visualItems.append(&_opArea); - _visualItems.append(&_serArea); - _visualItems.append(&_joinedArea); - - connect(_container, &WimaDataContainer::opAreaChanged, this, &WimaController::setOpArea); - connect(_container, &WimaDataContainer::serAreaChanged, this, &WimaController::setSerArea); - connect(_container, &WimaDataContainer::corridorChanged, this, &WimaController::setCorridor); - connect(_container, &WimaDataContainer::joinedAreaChanged, this, &WimaController::setJoinedArea); - } - emit dataContainerChanged(); } } void WimaController::startWimaController(bool flyView) { - _flyView = flyView; + } void WimaController::removeArea(int index) { if(index >= 0 && index < _visualItems.count()){ - if (_flyView) { //not editing allowed in flyView - return; - } WimaArea* area = qobject_cast(_visualItems.removeAt(index)); if ( area == nullptr) { @@ -133,7 +117,7 @@ void WimaController::removeArea(int index) bool WimaController::addGOperationArea() { - if (!_flyView && !_visualItems.contains(&_opArea)) { + if (!_visualItems.contains(&_opArea)) { _visualItems.append(&_opArea); int newIndex = _visualItems.count()-1; @@ -148,7 +132,7 @@ bool WimaController::addGOperationArea() bool WimaController::addServiceArea() { - if (!_flyView && !_visualItems.contains(&_serArea)) { + if (!_visualItems.contains(&_serArea)) { _visualItems.append(&_serArea); int newIndex = _visualItems.count()-1; @@ -163,7 +147,7 @@ bool WimaController::addServiceArea() bool WimaController::addVehicleCorridor() { - if (!_flyView && !_visualItems.contains(&_corridor)) { + if (!_visualItems.contains(&_corridor)) { _visualItems.append(&_corridor); int newIndex = _visualItems.count()-1; @@ -178,10 +162,6 @@ bool WimaController::addVehicleCorridor() void WimaController::removeAll() { - if (_flyView) { - return; - } - bool changesApplied = false; while (_visualItems.count() > 0) { removeArea(0); @@ -219,111 +199,105 @@ void WimaController::resumeMission() bool WimaController::updateMission() { - if (!_flyView) { - setReadyForSaveSend(false); - #define debug 0 - - if ( !updateJoinedArea()) { - qgcApp()->showMessage(tr("Not able to join areas. Areas must be overlapping")); - return false; - } + setReadyForSaveSend(false); + #define debug 0 - #if debug - _visualItems.append(&_joinedArea); - #endif + if ( !recalcJoinedArea()) { + qgcApp()->showMessage(tr("Not able to join areas. Areas must be overlapping")); + return false; + } + #if debug + _visualItems.append(&_joinedArea); + #endif - // reset visual items - _missionController->removeAll(); - QmlObjectListModel* missionItems = _missionController->visualItems(); - // set home position to serArea center - MissionSettingsItem* settingsItem= qobject_cast(missionItems->get(0)); - if (settingsItem == nullptr){ - qWarning("WimaController::updateMission(): settingsItem == nullptr"); - return false; - } + // reset visual items + _missionController->removeAll(); + QmlObjectListModel* missionItems = _missionController->visualItems(); + // set home position to serArea center + MissionSettingsItem* settingsItem= qobject_cast(missionItems->get(0)); + if (settingsItem == nullptr){ + qWarning("WimaController::updateMission(): settingsItem == nullptr"); + return false; + } - // set altitudes, temporary measure to solve bugs - QGeoCoordinate center = _serArea.center(); - center.setAltitude(0); - _serArea.setCenter(center); - center = _opArea.center(); - center.setAltitude(0); - _opArea.setCenter(center); - center = _corridor.center(); - center.setAltitude(0); - _corridor.setCenter(center); + // set altitudes, temporary measure to solve bugs + QGeoCoordinate center = _serArea.center(); + center.setAltitude(0); + _serArea.setCenter(center); + center = _opArea.center(); + center.setAltitude(0); + _opArea.setCenter(center); + center = _corridor.center(); + center.setAltitude(0); + _corridor.setCenter(center); - // set HomePos. to serArea center - settingsItem->setCoordinate(_serArea.center()); + // set HomePos. to serArea center + settingsItem->setCoordinate(_serArea.center()); - // create take off position item - int sequenceNumber = _missionController->insertSimpleMissionItem(_serArea.center(), missionItems->count()); - _missionController->setCurrentPlanViewIndex(sequenceNumber, true); + // create take off position item + int sequenceNumber = _missionController->insertSimpleMissionItem(_serArea.center(), missionItems->count()); + _missionController->setCurrentPlanViewIndex(sequenceNumber, true); - // create survey item, will be extened with more()-> mission types in the future - _missionController->insertComplexMissionItem(_missionController->surveyComplexItemName(), _opArea.center(), missionItems->count()); - SurveyComplexItem* survey = qobject_cast(missionItems->get(missionItems->count()-1)); - if (survey == nullptr){ - qWarning("WimaController::updateMission(): survey == nullptr"); - return false; - } else { - survey->surveyAreaPolygon()->clear(); - survey->surveyAreaPolygon()->appendVertices(_opArea.coordinateList()); - //survey-> - } - - // calculate path from take off to opArea - QGeoCoordinate start = _serArea.center(); - QGeoCoordinate end = survey->visualTransectPoints().first().value(); - QList path; - if ( !WimaArea::dijkstraPath(start, end, _joinedArea, path)) { - qgcApp()->showMessage(tr("Not able to calculate the path from takeoff position to measurement area.")); - return false; - } - for (int i = 1; i < path.count()-1; i++) { - sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()-1); - _missionController->setCurrentPlanViewIndex(sequenceNumber, true); - } + // create survey item, will be extened with more()-> mission types in the future + _missionController->insertComplexMissionItem(_missionController->surveyComplexItemName(), _opArea.center(), missionItems->count()); + SurveyComplexItem* survey = qobject_cast(missionItems->get(missionItems->count()-1)); + if (survey == nullptr){ + qWarning("WimaController::updateMission(): survey == nullptr"); + return false; + } else { + survey->surveyAreaPolygon()->clear(); + survey->surveyAreaPolygon()->appendVertices(_opArea.coordinateList()); + //survey-> + } - // calculate return path - start = survey->visualTransectPoints().last().value(); - end = _serArea.center(); - path.clear(); - if ( ! WimaArea::dijkstraPath(start, end, _joinedArea, path)) { - qgcApp()->showMessage(tr("Not able to calculate the path from measurement area to landing position.")); - return false; - } - for (int i = 1; i < path.count()-1; i++) { - sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()); - _missionController->setCurrentPlanViewIndex(sequenceNumber, true); - } + // calculate path from take off to opArea + QGeoCoordinate start = _serArea.center(); + QGeoCoordinate end = survey->visualTransectPoints().first().value(); + QList path; + if ( !WimaArea::dijkstraPath(start, end, _joinedArea, path)) { + qgcApp()->showMessage(tr("Not able to calculate the path from takeoff position to measurement area.")); + return false; + } + for (int i = 1; i < path.count()-1; i++) { + sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()-1); + _missionController->setCurrentPlanViewIndex(sequenceNumber, true); + } - // create land position item - sequenceNumber = _missionController->insertSimpleMissionItem(_serArea.center(), missionItems->count()); + // calculate return path + start = survey->visualTransectPoints().last().value(); + end = _serArea.center(); + path.clear(); + if ( ! WimaArea::dijkstraPath(start, end, _joinedArea, path)) { + qgcApp()->showMessage(tr("Not able to calculate the path from measurement area to landing position.")); + return false; + } + for (int i = 1; i < path.count()-1; i++) { + sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()); _missionController->setCurrentPlanViewIndex(sequenceNumber, true); - SimpleMissionItem* landItem = qobject_cast(missionItems->get(missionItems->count()-1)); - if (landItem == nullptr){ - qWarning("WimaController::updateMission(): landItem == nullptr"); - return false; - } else { - Vehicle* controllerVehicle = _masterController->controllerVehicle(); - MAV_CMD landCmd = controllerVehicle->vtol() ? MAV_CMD_NAV_VTOL_LAND : MAV_CMD_NAV_LAND; - if (controllerVehicle->firmwarePlugin()->supportedMissionCommands().contains(landCmd)) { - landItem->setCommand(landCmd); - } - } + } - updateContainer(); - setReadyForSaveSend(true); - return true; + // create land position item + sequenceNumber = _missionController->insertSimpleMissionItem(_serArea.center(), missionItems->count()); + _missionController->setCurrentPlanViewIndex(sequenceNumber, true); + SimpleMissionItem* landItem = qobject_cast(missionItems->get(missionItems->count()-1)); + if (landItem == nullptr){ + qWarning("WimaController::updateMission(): landItem == nullptr"); + return false; } else { - return true; + Vehicle* controllerVehicle = _masterController->controllerVehicle(); + MAV_CMD landCmd = controllerVehicle->vtol() ? MAV_CMD_NAV_VTOL_LAND : MAV_CMD_NAV_LAND; + if (controllerVehicle->firmwarePlugin()->supportedMissionCommands().contains(landCmd)) { + landItem->setCommand(landCmd); + } } + updateContainer(); + setReadyForSaveSend(true); + return true; } void WimaController::saveToCurrent() @@ -405,23 +379,26 @@ bool WimaController::loadFromFile(const QString &filename) } QJsonObject json = jsonDoc.object(); - // AreaItems QJsonArray areaArray = json[areaItemsName].toArray(); _visualItems.clear(); - for( int i = 0; i < areaArray.size(); i++) { + int validAreaCounter = 0; + for( int i = 0; i < areaArray.size() && validAreaCounter < 3; i++) { QJsonObject jsonArea = areaArray[i].toObject(); if (jsonArea.contains(WimaArea::areaTypeName) && jsonArea[WimaArea::areaTypeName].isString()) { if ( jsonArea[WimaArea::areaTypeName] == WimaGOperationArea::wimaGOperationAreaName) { + print(_opArea); bool success = _opArea.loadFromJson(jsonArea, errorString); + print(_opArea); if ( !success ) { qgcApp()->showMessage(errorMessage.arg(errorString)); return false; } + validAreaCounter++; _visualItems.append(&_opArea); emit visualItemsChanged(); } else if ( jsonArea[WimaArea::areaTypeName] == WimaServiceArea::wimaServiceAreaName) { @@ -432,6 +409,7 @@ bool WimaController::loadFromFile(const QString &filename) return false; } + validAreaCounter++; _visualItems.append(&_serArea); emit visualItemsChanged(); } else if ( jsonArea[WimaArea::areaTypeName] == WimaVCorridor::wimaVCorridorName) { @@ -442,6 +420,7 @@ bool WimaController::loadFromFile(const QString &filename) return false; } + validAreaCounter++; _visualItems.append(&_corridor); emit visualItemsChanged(); } else { @@ -458,7 +437,7 @@ bool WimaController::loadFromFile(const QString &filename) _currentFile.sprintf("%s/%s.%s", fileInfo.path().toLocal8Bit().data(), fileInfo.completeBaseName().toLocal8Bit().data(), wimaFileExtension); emit currentFileChanged(); - updateJoinedArea(); + recalcJoinedArea(); // MissionItems // extrac MissionItems part @@ -519,13 +498,14 @@ void WimaController::recalcPolygonInteractivity(int index) } } -bool WimaController::updateJoinedArea() +bool WimaController::recalcJoinedArea() { // join service area, op area and corridor _joinedArea = _serArea; _joinedArea.join(_corridor); + if ( !_joinedArea.join(_opArea) ) - return false; + return false; // this happens if all areas are pairwise disjoint else { emit joinedAreaChanged() ; return true; @@ -536,56 +516,21 @@ bool WimaController::updateJoinedArea() void WimaController::updateContainer() { + // Sets the pointers (inside _container) to the areas (of this). + // Should be called only (once) after a _container has been assigned. if (_container != nullptr) { - _container->setOpArea(_opArea); - _container->setSerArea(_serArea); - _container->setCorridor(_corridor); - _container->setJoinedArea(_joinedArea); + _container->setOpArea(&_opArea); + _container->setSerArea(&_serArea); + _container->setCorridor(&_corridor); + _container->setJoinedArea(&_joinedArea); } else { qWarning("WimaController::uploadToContainer(): no container assigned."); } } -void WimaController::downloadFromContainer() -{ - if (_flyView) { - _opArea = _container->opArea(); - _serArea = _container->serArea(); - _corridor = _container->corridor(); - _joinedArea = _container->joinedArea(); - } -} - -void WimaController::setOpArea(const WimaGOperationArea &area) -{ - if (_flyView) { - _opArea = area; - } -} - -void WimaController::setSerArea(const WimaServiceArea &area) -{ - if (_flyView) { - _serArea = area; - } -} - -void WimaController::setCorridor(const WimaVCorridor &area) -{ - if (_flyView) { - _corridor = area; - } -} - -void WimaController::setJoinedArea(const WimaArea &area) -{ - if (_flyView) { - _joinedArea = area; - } -} - void WimaController::resetAllInteractive() { + // Marks all areas as inactive (area.interactive == false) int itemCount = _visualItems.count(); if (itemCount > 0){ for (int i = 0; i < itemCount; i++) { @@ -602,6 +547,8 @@ void WimaController::setInteractive() QJsonDocument WimaController::saveToJson(FileType fileType) { + /// This function save all areas (of WimaController) and all mission items (of MissionController) to a QJsonDocument + /// @param fileType is either WimaFile or PlanFile (enum), if fileType == PlanFile only mission items are stored QJsonObject json; if ( fileType == FileType::WimaFile ) { @@ -617,6 +564,7 @@ QJsonDocument WimaController::saveToJson(FileType fileType) return QJsonDocument(); } + // check the type of area, create and append the JsonObject to the JsonArray once determined WimaGOperationArea* opArea = qobject_cast(area); if (opArea != nullptr) { opArea->saveToJson(json); diff --git a/src/Wima/WimaController.h b/src/Wima/WimaController.h index 9718a107b..f241a3215 100644 --- a/src/Wima/WimaController.h +++ b/src/Wima/WimaController.h @@ -29,25 +29,25 @@ public: WimaController(QObject *parent = nullptr); - Q_PROPERTY(PlanMasterController* masterController READ masterController WRITE setMasterController NOTIFY masterControllerChanged) - Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged) - 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(bool flyView READ flyView CONSTANT) - Q_PROPERTY(WimaDataContainer* dataContainer READ dataContainer WRITE setDataContainer NOTIFY dataContainerChanged) - Q_PROPERTY(bool readyForSaveSend READ readyForSaveSend NOTIFY readyForSaveSendChanged) + 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(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(bool flyView READ flyView CONSTANT) + Q_PROPERTY(WimaDataContainer* 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; } - const QmlObjectListModel* visualItems (void) const; + QmlObjectListModel* visualItems (void) ; int currentPolygonIndex (void) const { return _currentPolygonIndex; } QString currentFile (void) const { return _currentFile; } QStringList loadNameFilters (void) const; @@ -55,8 +55,6 @@ public: QString fileExtension (void) const { return wimaFileExtension; } QGeoCoordinate joinedAreaCenter (void) const; WimaArea joinedArea (void) const; - WimaDataContainer* dataContainer (void) const { return _container; } - bool flyView (void) const { return _flyView; } bool readyForSaveSend (void) const { return _readyForSaveSend; } @@ -76,6 +74,7 @@ public: Q_INVOKABLE void removeArea(int index); Q_INVOKABLE bool addServiceArea(); Q_INVOKABLE bool addVehicleCorridor(); + /// Remove all areas from WimaController and all mission items from MissionController Q_INVOKABLE void removeAll(); Q_INVOKABLE void startMission(); @@ -115,23 +114,17 @@ signals: private slots: 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); - + bool recalcJoinedArea (); + void updateContainer ();// only executed if flyView == false + void downloadFromContainer ();// only executed if flyView == true private: - bool _flyView; bool _readyForSaveSend; - PlanMasterController* _masterController; - MissionController* _missionController; + PlanMasterController *_masterController; + MissionController *_missionController; int _currentPolygonIndex; QString _currentFile; - WimaDataContainer* _container; + WimaDataContainer *_container; QmlObjectListModel _visualItems; WimaArea _joinedArea; WimaGOperationArea _opArea; diff --git a/src/Wima/WimaDataContainer.cc b/src/Wima/WimaDataContainer.cc index fed86faf5..075ee370e 100644 --- a/src/Wima/WimaDataContainer.cc +++ b/src/Wima/WimaDataContainer.cc @@ -2,44 +2,44 @@ WimaDataContainer::WimaDataContainer(QObject *parent) : QObject (parent) - , _joinedArea (this) - , _opArea (this) - , _serArea (this) - , _corridor (this) + , _joinedArea (nullptr) + , _opArea (nullptr) + , _serArea (nullptr) + , _corridor (nullptr) { } -void WimaDataContainer::setJoinedArea(const WimaArea &joinedArea) +void WimaDataContainer::setJoinedArea(const WimaArea *joinedArea) { - if (_joinedArea.path() != joinedArea.path()) { + if (_joinedArea != joinedArea) { _joinedArea = joinedArea; emit joinedAreaChanged(_joinedArea); } } -void WimaDataContainer::setOpArea(const WimaGOperationArea &opArea) +void WimaDataContainer::setOpArea(const WimaGOperationArea *opArea) { - if (_opArea.path() != opArea.path()) { + if (_opArea != opArea) { _opArea = opArea; emit opAreaChanged(_opArea); } } -void WimaDataContainer::setSerArea(const WimaServiceArea &serArea) +void WimaDataContainer::setSerArea(const WimaServiceArea *serArea) { - if (_serArea.path() != serArea.path()) { + if (_serArea != serArea) { _serArea = serArea; emit serAreaChanged(_serArea); } } -void WimaDataContainer::setCorridor(const WimaVCorridor &corridor) +void WimaDataContainer::setCorridor(const WimaVCorridor *corridor) { - if (_corridor.path() != corridor.path()) { + if (_corridor != corridor) { _corridor = corridor; emit corridorChanged(_corridor); diff --git a/src/Wima/WimaDataContainer.h b/src/Wima/WimaDataContainer.h index 79dd1c87d..41ffa99b2 100644 --- a/src/Wima/WimaDataContainer.h +++ b/src/Wima/WimaDataContainer.h @@ -1,5 +1,4 @@ -#ifndef WIMADATACONTAINER_H -#define WIMADATACONTAINER_H +#pragma once #include @@ -15,30 +14,30 @@ class WimaDataContainer : public QObject Q_OBJECT public: explicit WimaDataContainer(QObject *parent = nullptr); + WimaDataContainer(WimaDataContainer &other, QObject *parent = nullptr) = delete; + WimaDataContainer(WimaDataContainer &other) = delete; - 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 setOpArea (const WimaGOperationArea& opArea); - void setSerArea (const WimaServiceArea& serArea); - void setCorridor (const WimaVCorridor& corridor); + const WimaArea * joinedArea (void) { return _joinedArea; } + const WimaGOperationArea * opArea (void) { return _opArea; } + const WimaServiceArea * serArea (void) { return _serArea; } + const WimaVCorridor * corridor (void) { return _corridor; } signals: - void joinedAreaChanged (const WimaArea& area); - void opAreaChanged (const WimaGOperationArea& area); - void serAreaChanged (const WimaServiceArea& area); - void corridorChanged (const WimaVCorridor& area); + void joinedAreaChanged (const WimaArea *area); + void opAreaChanged (const WimaGOperationArea *area); + void serAreaChanged (const WimaServiceArea *area); + void corridorChanged (const WimaVCorridor *area); public slots: + void setJoinedArea (const WimaArea *joinedArea); + void setOpArea (const WimaGOperationArea *opArea); + void setSerArea (const WimaServiceArea *serArea); + void setCorridor (const WimaVCorridor *corridor); private: - WimaArea _joinedArea; - WimaGOperationArea _opArea; - WimaServiceArea _serArea; - WimaVCorridor _corridor; + const WimaArea *_joinedArea; + const WimaGOperationArea *_opArea; + const WimaServiceArea *_serArea; + const WimaVCorridor *_corridor; }; -#endif // WIMADATACONTAINER_H diff --git a/src/Wima/WimaGOperationArea.cc b/src/Wima/WimaGOperationArea.cc index 4824d6719..b600f7266 100644 --- a/src/Wima/WimaGOperationArea.cc +++ b/src/Wima/WimaGOperationArea.cc @@ -21,13 +21,6 @@ WimaGOperationArea::WimaGOperationArea(const WimaGOperationArea &other, QObject init(); } -WimaGOperationArea &WimaGOperationArea::operator=(WimaGOperationArea other) -{ - swap(*this, other); - - return *this; -} - void WimaGOperationArea::saveToJson(QJsonObject &json) { this->WimaArea::saveToJson(json); @@ -77,6 +70,23 @@ bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorStr } } +void WimaGOperationArea::update(const WimaGOperationArea &area) +{ + this->WimaArea::update(area); + + this->setBottomLayerAltitude(area.bottomLayerAltitude()); + this->setNumberOfLayers(area.numberOfLayers()); + this->setLayerDistance(area.layerDistance()); + this->setBorderPolygonOffset(area.borderPolygonOffset()); + + recalcBorderPolygon(); +} + +void WimaGOperationArea::setBottomLayerAltitude(double altitude) +{ + +} + void print(const WimaGOperationArea &area) { QString message; @@ -87,30 +97,18 @@ void print(const WimaGOperationArea &area) void print(const WimaGOperationArea &area, QString outputStr) { print(static_cast(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("Bottom Layer Altitude: %1\n").arg(area._bottomLayerAltitude.rawValue().toDouble())); + outputStr.append(QString("Number of Layers: %1\n").arg(area._numberOfLayers.rawValue().toInt())); + outputStr.append(QString("Layer Distance: %1\n").arg(area._layerDistance.rawValue().toDouble())); + outputStr.append(QString("Border Polygon Offset: %1\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))); + outputStr.append(QString("%1\n").arg(coordinate.toString(QGeoCoordinate::Degrees))); } } -void swap(WimaGOperationArea &area1, WimaGOperationArea &area2) -{ - using std::swap; - - swap(area1._metaDataMap, area2._metaDataMap); - swap(area1._bottomLayerAltitude, area2._bottomLayerAltitude); - swap(area1._numberOfLayers, area2._numberOfLayers); - swap(area1._layerDistance, area2._layerDistance); - swap(area1._borderPolygonOffset, area2._borderPolygonOffset); - swap(area1._borderPolygon, area2._borderPolygon); -} - void WimaGOperationArea::recalcBorderPolygon() { //qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble()); diff --git a/src/Wima/WimaGOperationArea.h b/src/Wima/WimaGOperationArea.h index 8fa301672..1a9966a3d 100644 --- a/src/Wima/WimaGOperationArea.h +++ b/src/Wima/WimaGOperationArea.h @@ -13,35 +13,34 @@ class WimaGOperationArea : public WimaArea Q_OBJECT public: WimaGOperationArea(QObject* parent = nullptr); - WimaGOperationArea(const WimaGOperationArea& other, QObject* parent = nullptr); - WimaGOperationArea& operator=(WimaGOperationArea other); + WimaGOperationArea(const WimaGOperationArea &other, QObject *parent = nullptr); - Q_PROPERTY(Fact* bottomLayerAltitude READ bottomLayerAltitude CONSTANT) - Q_PROPERTY(Fact* numberOfLayers READ numberOfLayers CONSTANT) - Q_PROPERTY(Fact* layerDistance READ layerDistance CONSTANT) - Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT) - Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) - - - void setVehicleCorridor (WimaVCorridor* corridor); + Q_PROPERTY(Fact* bottomLayerAltitude READ bottomLayerAltitudeFact CONSTANT) + Q_PROPERTY(Fact* numberOfLayers READ numberOfLayersFact CONSTANT) + Q_PROPERTY(Fact* layerDistance READ layerDistanceFact CONSTANT) + Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffsetFact CONSTANT) + Q_PROPERTY(QGCMapPolygon borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) // Overrides from WimaPolygon QString mapVisualQML (void) const { return "WimaGOperationAreaMapVisual.qml";} QString editorQML (void) const { return "WimaGOperationAreaEditor.qml";} // Property accessors - Fact* bottomLayerAltitude (void) { return &_bottomLayerAltitude;} - Fact* numberOfLayers (void) { return &_numberOfLayers;} - Fact* layerDistance (void) { return &_layerDistance;} - Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;} - QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;} + Fact* bottomLayerAltitudeFact (void) { return &_bottomLayerAltitude;} + Fact* numberOfLayersFact (void) { return &_numberOfLayers;} + Fact* layerDistanceFact (void) { return &_layerDistance;} + Fact* borderPolygonOffsetFact (void) { return &_borderPolygonOffset;} + double bottomLayerAltitude (void) const { return _bottomLayerAltitude.rawValue().toDouble();} + int numberOfLayers (void) const { return _numberOfLayers.rawValue().toInt();} + double layerDistance (void) const { return _layerDistance.rawValue().toDouble();} + double borderPolygonOffset (void) const { return _borderPolygonOffset.rawValue().toDouble();} + QGCMapPolygon borderPolygon (void) const { return _borderPolygon;} // Member Methodes void saveToJson(QJsonObject& json); bool loadFromJson(const QJsonObject& json, QString &errorString); // Friends - friend void swap(WimaGOperationArea& area1, WimaGOperationArea& area2); friend void print(const WimaGOperationArea& area, QString outputStr); friend void print(const WimaGOperationArea& area); @@ -53,21 +52,23 @@ public: static const char* borderPolygonOffsetName; static const char* wimaGOperationAreaName; - signals: void bottomLayerAltitudeChanged (void); void numberOfLayersChanged (void); void layerDistanceChanged (void); - //void vehicleListChanged (void); void polylineChanged (void); - //void vehiclePolygonsChanged (void); void vehicleCorridorChanged (WimaVCorridor* corridor); void borderPolygonChanged (void); +public slots: + /// Updates this with data from area + void update(const WimaGOperationArea &area); + void setBottomLayerAltitude (double altitude); + void setNumberOfLayers (double numLayers); + void setLayerDistance (double layerDistance); + void setBorderPolygonOffset (double offset); private slots: void recalcBorderPolygon (void); - - private: // Member Methodes void init(); diff --git a/src/Wima/WimaPlaner.cc b/src/Wima/WimaPlaner.cc new file mode 100644 index 000000000..bbd65e63d --- /dev/null +++ b/src/Wima/WimaPlaner.cc @@ -0,0 +1,6 @@ +#include "WimaPlaner.h" + +WimaPlaner::WimaPlaner() +{ + +} diff --git a/src/Wima/WimaPlaner.h b/src/Wima/WimaPlaner.h new file mode 100644 index 000000000..7bed0f495 --- /dev/null +++ b/src/Wima/WimaPlaner.h @@ -0,0 +1,11 @@ +#ifndef WIMAPLANER_H +#define WIMAPLANER_H + + +class WimaPlaner +{ +public: + WimaPlaner(); +}; + +#endif // WIMAPLANER_H \ No newline at end of file diff --git a/src/Wima/WimaServiceArea.cc b/src/Wima/WimaServiceArea.cc index 7c5e216db..daf6f1b61 100644 --- a/src/Wima/WimaServiceArea.cc +++ b/src/Wima/WimaServiceArea.cc @@ -16,13 +16,6 @@ WimaServiceArea::WimaServiceArea(const WimaServiceArea &other, QObject *parent) init(); } -WimaServiceArea &WimaServiceArea::operator=(WimaServiceArea other) -{ - swap(*this, other); - - return *this; -} - void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate) { if(_takeOffPosition != coordinate){ @@ -57,6 +50,13 @@ bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString } } +void WimaServiceArea::update(const WimaServiceArea &area) +{ + this->WimaArea::update(area); + this->setTakeOffPosition(area.takeOffPosition()); + this->setLandPosition(area.landPosition()); +} + void print(const WimaServiceArea &area) { QString message; @@ -71,14 +71,6 @@ void print(const WimaServiceArea &area, QString &outputStr) outputStr.append(QString("Land Position: %s\n").arg(area._landPosition.toString(QGeoCoordinate::Degrees))); } -void swap(WimaServiceArea &area1, WimaServiceArea &area2) -{ - using std::swap; - - swap(area1._takeOffPosition, area2._takeOffPosition); - swap(area1._landPosition, area2._landPosition); -} - void WimaServiceArea::init() { this->setObjectName(wimaServiceAreaName); diff --git a/src/Wima/WimaServiceArea.h b/src/Wima/WimaServiceArea.h index 8512fe0a4..e53445d9a 100644 --- a/src/Wima/WimaServiceArea.h +++ b/src/Wima/WimaServiceArea.h @@ -10,12 +10,10 @@ class WimaServiceArea : public WimaArea public: WimaServiceArea(QObject* parent = nullptr); WimaServiceArea(const WimaServiceArea& other, QObject* parent); - WimaServiceArea& operator=(WimaServiceArea other); Q_PROPERTY(const QGeoCoordinate& takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged) Q_PROPERTY(const QGeoCoordinate& landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged) - // Overrides from WimaPolygon QString mapVisualQML (void) const { return "WimaServiceAreaMapVisual.qml";} QString editorQML (void) const { return "WimaServiceAreaEditor.qml";} @@ -24,27 +22,29 @@ public: const QGeoCoordinate& takeOffPosition (void) const { return _takeOffPosition;} const QGeoCoordinate& landPosition (void) const { return _landPosition;} - - // Property setters - void setTakeOffPosition (const QGeoCoordinate& coordinate); - void setLandPosition (const QGeoCoordinate& coordinate); - // Member Methodes void saveToJson(QJsonObject& json); bool loadFromJson(const QJsonObject& json, QString& errorString); - // static Members - static const char* wimaServiceAreaName; + // Friends - friend void swap(WimaServiceArea& area1, WimaServiceArea& area2); friend void print(const WimaServiceArea& area, QString& outputStr); friend void print(const WimaServiceArea& area); + // static Members + static const char* wimaServiceAreaName; signals: void takeOffPositionChanged (void); void landPositionChanged (void); void vehicleCorridorChanged (WimaVCorridor& corridor); + +public slots: + void setTakeOffPosition (const QGeoCoordinate& coordinate); + void setLandPosition (const QGeoCoordinate& coordinate); + /// Updates this with data from area + void update(const WimaServiceArea &area); + private: // Member Methodes void init(); diff --git a/src/Wima/WimaVCorridor.cc b/src/Wima/WimaVCorridor.cc index 45ed7c010..6c13e68a0 100644 --- a/src/Wima/WimaVCorridor.cc +++ b/src/Wima/WimaVCorridor.cc @@ -16,13 +16,6 @@ WimaVCorridor::WimaVCorridor(const WimaVCorridor &other, QObject *parent) init(); } -WimaVCorridor &WimaVCorridor::operator=(WimaVCorridor other) -{ - swap(*this, other); - - return *this; -} - void WimaVCorridor::saveToJson(QJsonObject &json) { this->WimaArea::saveToJson(json); @@ -41,6 +34,11 @@ bool WimaVCorridor::loadFromJson(const QJsonObject &json, QString &errorString) } } +void WimaVCorridor::update(const WimaVCorridor &area) +{ + this->WimaArea::update(area); +} + void WimaVCorridor::init() { this->setObjectName(wimaVCorridorName); @@ -57,10 +55,3 @@ void print(const WimaVCorridor &area, QString &outputString) { print(static_cast(area), outputString); } - -void swap(WimaVCorridor &area1, WimaVCorridor &area2) -{ - using std::swap; - - swap(static_cast(area1), static_cast(area2)); -} diff --git a/src/Wima/WimaVCorridor.h b/src/Wima/WimaVCorridor.h index 2239385e6..514837669 100644 --- a/src/Wima/WimaVCorridor.h +++ b/src/Wima/WimaVCorridor.h @@ -11,7 +11,6 @@ class WimaVCorridor : public WimaArea public: WimaVCorridor(QObject* parent = nullptr); WimaVCorridor(const WimaVCorridor& other, QObject* parent = nullptr); - WimaVCorridor& operator=(WimaVCorridor other); // Overrides from WimaPolygon QString mapVisualQML (void) const { return "WimaVCorridorMapVisual.qml";} @@ -25,7 +24,6 @@ public: static const char* wimaVCorridorName; // Friends - friend void swap(WimaVCorridor& area1, WimaVCorridor& area2); friend void print(const WimaVCorridor& area, QString& outputString); friend void print(const WimaVCorridor& area); @@ -33,6 +31,10 @@ signals: void serviceAreaChanged (WimaServiceArea* serviceArea); void opAreaChanged (WimaGOperationArea* opArea); +public slots: + /// Updates this with data from area + void update(const WimaVCorridor& area); + private: void init(); -- 2.22.0