diff --git a/src/MissionManager/TransectStyleComplexItem.cc b/src/MissionManager/TransectStyleComplexItem.cc index eb82695267afd39ba8d3fc9eb45d2e797d3e6ebb..a722d6f1e9cc9f4735f4eb792790ebf356e59993 100644 --- a/src/MissionManager/TransectStyleComplexItem.cc +++ b/src/MissionManager/TransectStyleComplexItem.cc @@ -59,6 +59,7 @@ TransectStyleComplexItem::TransectStyleComplexItem(Vehicle* vehicle, bool flyVie , _terrainAdjustToleranceFact (settingsGroup, _metaDataMap[terrainAdjustToleranceName]) , _terrainAdjustMaxClimbRateFact (settingsGroup, _metaDataMap[terrainAdjustMaxClimbRateName]) , _terrainAdjustMaxDescentRateFact (settingsGroup, _metaDataMap[terrainAdjustMaxDescentRateName]) + , _transectsDirty(true) { _terrainQueryTimer.setInterval(_terrainQueryTimeoutMsecs); _terrainQueryTimer.setSingleShot(true); @@ -419,6 +420,9 @@ void TransectStyleComplexItem::_rebuildTransects(void) emit lastSequenceNumberChanged(lastSequenceNumber()); emit timeBetweenShotsChanged(); emit additionalTimeDelayChanged(); + + if (!_transectsDirty) + emit missionItemReady(); } void TransectStyleComplexItem::_updateTransectAltitude() diff --git a/src/MissionManager/TransectStyleComplexItem.h b/src/MissionManager/TransectStyleComplexItem.h index e584575402ff4eebf798b8a56f379dc62addd140..ba819eb3c870ad35925ff10aab58665fa8fec76c 100644 --- a/src/MissionManager/TransectStyleComplexItem.h +++ b/src/MissionManager/TransectStyleComplexItem.h @@ -127,6 +127,7 @@ signals: void visualTransectPointsChanged (void); void coveredAreaChanged (void); void followTerrainChanged (bool followTerrain); + void missionItemReady (void); protected slots: void _setDirty (void); @@ -208,6 +209,9 @@ private slots: void _reallyQueryTransectsPathHeightInfo(void); void _followTerrainChanged (bool followTerrain); +protected: + bool _transectsDirty; + private: void _queryTransectsPathHeightInfo (void); void _adjustTransectsForTerrain (void); @@ -216,4 +220,6 @@ private: void _adjustForTolerance (QList& transect); double _altitudeBetweenCoords (const QGeoCoordinate& fromCoord, const QGeoCoordinate& toCoord, double percentTowardsTo); int _maxPathHeight (const TerrainPathQuery::PathHeightInfo_t& pathHeightInfo, int fromIndex, int toIndex, double& maxHeight); + + }; diff --git a/src/Wima/CircularSurveyComplexItem.cc b/src/Wima/CircularSurveyComplexItem.cc index 1119cb083a3e268f9902360f8fa17d24c94dc2c5..01eed20198af1c556219f4b748cb78c6521428f1 100644 --- a/src/Wima/CircularSurveyComplexItem.cc +++ b/src/Wima/CircularSurveyComplexItem.cc @@ -1,4 +1,4 @@ -#include "CircularSurveyComplexItem.h" +#include "CircularSurveyComplexItem.h" #include "JsonHelper.h" #include "QGCApplication.h" #include @@ -35,9 +35,7 @@ CircularSurveyComplexItem::CircularSurveyComplexItem(Vehicle *vehicle, bool flyV , _maxWaypoints (settingsGroup, _metaDataMap[maxWaypointsName]) , _isInitialized (false) , _reverseOnly (false) - , _referencePointBeingChanged (false) , _updateCounter (0) - , _transectsDiry (true) { Q_UNUSED(kmlOrShpFile) _editorQml = "qrc:/qml/CircularSurveyItemEditor.qml"; @@ -100,11 +98,6 @@ bool CircularSurveyComplexItem::isInitialized() return _isInitialized; } -bool CircularSurveyComplexItem::referencePointBeingChanged() -{ - return _referencePointBeingChanged; -} - bool CircularSurveyComplexItem::load(const QJsonObject &complexObject, int sequenceNumber, QString &errorString) { // We need to pull version first to determine what validation/conversion needs to be performed @@ -207,7 +200,7 @@ void CircularSurveyComplexItem::save(QJsonArray &planItems) void CircularSurveyComplexItem::appendMissionItems(QList &items, QObject *missionItemParent) { - if (_transectsDiry) + if (_transectsDirty) return; if (_loadedMissionItems.count()) { // We have mission items from the loaded plan, use those @@ -221,7 +214,7 @@ void CircularSurveyComplexItem::appendMissionItems(QList &items, void CircularSurveyComplexItem::_appendLoadedMissionItems(QList& items, QObject* missionItemParent) { //qCDebug(SurveyComplexItemLog) << "_appendLoadedMissionItems"; - if (_transectsDiry) + if (_transectsDirty) return; int seqNum = _sequenceNumber; @@ -239,7 +232,7 @@ void CircularSurveyComplexItem::_buildAndAppendMissionItems(QList& // Now build the mission items from the transect points - if (_transectsDiry) + if (_transectsDirty) return; MissionItem* item; @@ -291,11 +284,11 @@ double CircularSurveyComplexItem::additionalTimeDelay() const return 0; } void CircularSurveyComplexItem::_rebuildTransectsPhase1(void){ - if (_fastRecalc){ + if (_doFastRecalc){ _rebuildTransectsFast(); } else { _rebuildTransectsSlow(); - _fastRecalc = true; + _doFastRecalc = true; } } @@ -366,7 +359,8 @@ void CircularSurveyComplexItem::_rebuildTransectsFast() _rebuildTransectsToGeo(optiPath, _referencePoint); - + _transectsDirty = true; + //_triggerSlowRecalcTimer.start(triggerTime); qDebug() << "CircularSurveyComplexItem::_rebuildTransectsPhase1(): calls: " << _updateCounter; } @@ -375,7 +369,24 @@ void CircularSurveyComplexItem::_rebuildTransectsSlow() { using namespace GeoUtilities; using namespace PolygonCalculus; - using namespace PlanimetryCalculus; + using namespace PlanimetryCalculus; + + if (_reverseOnly) { // reverse transects and return + _reverseOnly = false; + + QList> transectsReverse; + transectsReverse.reserve(_transects.size()); + for (auto list : _transects) { + QList listReverse; + for (auto coordinate : list) + listReverse.prepend(coordinate); + + transectsReverse.prepend(listReverse); + } + _transects = transectsReverse; + + return; + } _transects.clear(); @@ -390,27 +401,6 @@ void CircularSurveyComplexItem::_rebuildTransectsSlow() _loadedMissionItemsParent = nullptr; } - - if (_reverseOnly) { // reverse transects and return - _reverseOnly = false; - - if (_transects.size() > 1) { - QList> transectsReverse; - transectsReverse.reserve(_transects.size()); - - for (auto list : _transects) { - QList listReverse; - for (auto coordinate : list) - listReverse.prepend(coordinate); - - transectsReverse.prepend(listReverse); - } - _transects = transectsReverse; - - return; - } - } - QVector> transectPath; if(!_generateTransectPath(transectPath, surveyPolygon)) return; @@ -465,21 +455,22 @@ void CircularSurveyComplexItem::_rebuildTransectsSlow() return; _rebuildTransectsToGeo(optimizedPath, _referencePoint); - _transectsDiry = false; + + _transectsDirty = false; + //_triggerSlowRecalcTimer.stop(); // stop any pending slow recalculations + return; } void CircularSurveyComplexItem::_triggerSlowRecalc() { - _fastRecalc = false; + _doFastRecalc = false; _rebuildTransects(); } - - void CircularSurveyComplexItem::_recalcComplexDistance() { _complexDistance = 0; - if (_transectsDiry) + if (_transectsDirty) return; for (int i=0; i<_visualTransectPoints.count() - 1; i++) { _complexDistance += _visualTransectPoints[i].value().distanceTo(_visualTransectPoints[i+1].value()); @@ -496,7 +487,7 @@ void CircularSurveyComplexItem::_recalcCameraShots() void CircularSurveyComplexItem::_reverseTransects() { _reverseOnly = true; - _rebuildTransectsSlow(); + _triggerSlowRecalc(); } bool CircularSurveyComplexItem::_shortestPath(const QGeoCoordinate &start, const QGeoCoordinate &destination, QVector &shortestPath) diff --git a/src/Wima/CircularSurveyComplexItem.h b/src/Wima/CircularSurveyComplexItem.h index 2e9b42183a18aa2c3915c731d787631d539aa539..642ef04791db93cc9f290674bfb0585b8f58a1f7 100644 --- a/src/Wima/CircularSurveyComplexItem.h +++ b/src/Wima/CircularSurveyComplexItem.h @@ -83,6 +83,8 @@ public: static const char* jsonReferencePointLatKey; static const char* jsonReferencePointAltKey; + static const long triggerTime = 50; // trigger time (ms) for _triggerSlowRecalcTimer + signals: void refPointChanged(); void isInitializedChanged(); @@ -122,15 +124,13 @@ private: SettingsFact _reverse; // reverses the _transects path SettingsFact _maxWaypoints; // the maximum number of waypoints _transects (TransectStyleComplexItem) can contain (to avoid performance hits) - QTimer _updateTimer; + QTimer _triggerSlowRecalcTimer; bool _isInitialized; // indicates if the polygon and refpoint etc. are initialized, prevents reinitialisation from gui and execution of _rebuildTransectsPhase1 during init from gui bool _reverseOnly; // if this is true _rebuildTransectsPhase1() will reverse the path only, _rebuildTransectsPhase1() resets _reverseOnly - bool _referencePointBeingChanged; // is set to true by gui, if user is changeing the reference point - bool _fastRecalc; // see _rebuildTransectsPhase1 for explanation + bool _doFastRecalc; // fast recalc of transects if set, see _rebuildTransectsPhase1 for furhter explanation int _updateCounter; - int _transectsDiry; }; diff --git a/src/Wima/PolygonCalculus.cc b/src/Wima/PolygonCalculus.cc index cd63fc3d554e8fcd1b0bbefd53143516a559ae14..4ffe93baa50c0826ee23b5ed2bdbe294671d3ced 100644 --- a/src/Wima/PolygonCalculus.cc +++ b/src/Wima/PolygonCalculus.cc @@ -139,6 +139,11 @@ namespace PolygonCalculus { if ( !isSimplePolygon(polygon1) || !isSimplePolygon(polygon2)) { return JoinPolygonError::NotSimplePolygon; } + + if (polygon1 == polygon2) { + joinedPolygon = polygon1; + return JoinPolygonError::PolygonJoined; + } if ( !hasClockwiseWinding(polygon1)) { reversePath(polygon1); } @@ -171,6 +176,7 @@ namespace PolygonCalculus { // possible nextVertex (if no intersection between currentVertex and protoVertex with crossPoly) int nextVertexNumber = nextVertexIndex(walkerPoly->size(), startIndex); QPointF protoNextVertex = walkerPoly->value(nextVertexNumber); + long counter = 0; while (1) { //qDebug("nextVertexNumber: %i", nextVertexNumber); joinedPolygon.append(currentVertex); @@ -232,6 +238,12 @@ namespace PolygonCalculus { return PolygonJoined; } } + + counter++; + if (counter > 1e5) { + qWarning("PolygonCalculus::join(): no successfull termination!"); + return Error; + } } } else { diff --git a/src/Wima/PolygonCalculus.h b/src/Wima/PolygonCalculus.h index 46ca02c66e88c989b4dcc9dd612ef3ecdb229ca5..6914a1555c855f5e5aebe120d89bda1f68e784a6 100644 --- a/src/Wima/PolygonCalculus.h +++ b/src/Wima/PolygonCalculus.h @@ -9,7 +9,7 @@ namespace PolygonCalculus { - enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow}; + enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow, Error}; typedef QList QVector3DList; typedef QList QPointFList; diff --git a/src/Wima/WimaArea.cc b/src/Wima/WimaArea.cc index 1dff8e84e1173fdd9fc015ff8f0d03f64890a926..55496273ee55305232104adbf1a330fcf198c5b7 100644 --- a/src/Wima/WimaArea.cc +++ b/src/Wima/WimaArea.cc @@ -143,15 +143,15 @@ void WimaArea::updatePolygonConnections(QVariant showBorderPolygon) void WimaArea::recalcInteractivity() { if ( _wimaAreaInteractive == false) { - this->setWimaAreaInteractive(false); + QGCMapPolygon::setInteractive(false); _borderPolygon.setInteractive(false); } else { if (_showBorderPolygon.rawValue().toBool() == true) { _borderPolygon.setInteractive(true); - this->setInteractive(false); + QGCMapPolygon::setInteractive(false); } else { _borderPolygon.setInteractive(false); - this->setInteractive(true); + QGCMapPolygon::setInteractive(true); } } } diff --git a/src/Wima/WimaPlaner.cc b/src/Wima/WimaPlaner.cc index 705c8b22f49aa833b7d51b915ab501e5ecf22c9f..2a23d5a530ebdcb859e64faf06f94ece1ace04df 100644 --- a/src/Wima/WimaPlaner.cc +++ b/src/Wima/WimaPlaner.cc @@ -29,9 +29,9 @@ WimaPlaner::WimaPlaner(QObject *parent) _lastServiceAreaPath = _serviceArea.path(); _lastCorridorPath = _corridor.path(); - connect(this, &WimaPlaner::currentPolygonIndexChanged, this, &WimaPlaner::recalcPolygonInteractivity); - connect(&_updateTimer, &QTimer::timeout, this, &WimaPlaner::updateTimerSlot); - connect(this, &WimaPlaner::joinedAreaValidChanged, this, &WimaPlaner::updateMission); + connect(this, &WimaPlaner::currentPolygonIndexChanged, this, &WimaPlaner::recalcPolygonInteractivity); + connect(&_updateTimer, &QTimer::timeout, this, &WimaPlaner::updateTimerSlot); + connect(this, &WimaPlaner::joinedAreaValidChanged, this, &WimaPlaner::updateMission); _updateTimer.setInterval(500); // 250 ms means: max update time 2*250 ms _updateTimer.start(); @@ -242,19 +242,13 @@ bool WimaPlaner::updateMission() _lastSurveyRefPoint = _measurementArea.center(); _surveyRefChanging = false; _circularSurvey->setIsInitialized(true); // prevents reinitialisation from gui -// connect(_circularSurvey->deltaR(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->deltaAlpha(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->isSnakePath(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->transectMinLength(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->reverse(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); - connect(_circularSurvey, &TransectStyleComplexItem::visualTransectPointsChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); + connect(_circularSurvey, &TransectStyleComplexItem::missionItemReady, this, &WimaPlaner::calcArrivalAndReturnPath); } // update survey area _circularSurvey->surveyAreaPolygon()->clear(); _circularSurvey->surveyAreaPolygon()->appendVertices(_measurementArea.coordinateList()); - - //calcArrivalAndReturnPath(); + _circularSurvey->comprehensiveUpdate(); setReadyForSync(true); return true; @@ -445,12 +439,7 @@ bool WimaPlaner::loadFromFile(const QString &filename) _lastSurveyRefPoint = _circularSurvey->refPoint(); _surveyRefChanging = false; _circularSurvey->setIsInitialized(true); // prevents reinitialisation from gui -// connect(_circularSurvey->deltaR(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->deltaAlpha(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->isSnakePath(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->transectMinLength(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); -// connect(_circularSurvey->reverse(), &Fact::rawValueChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); - connect(_circularSurvey, &TransectStyleComplexItem::visualTransectPointsChanged, this, &WimaPlaner::startCalcArrivalAndReturnTimer); + connect(_circularSurvey, &TransectStyleComplexItem::missionItemReady, this, &WimaPlaner::calcArrivalAndReturnPath); break; } } @@ -484,7 +473,8 @@ void WimaPlaner::recalcPolygonInteractivity(int index) if (index >= 0 && index < _visualItems.count()) { resetAllInteractive(); WimaArea* interactivePoly = qobject_cast(_visualItems.get(index)); - interactivePoly->setWimaAreaInteractive(true); + if (interactivePoly != nullptr) + interactivePoly->setWimaAreaInteractive(true); } } @@ -637,8 +627,8 @@ bool WimaPlaner::recalcJoinedArea() _joinedArea.setPath(_serviceArea.path()); _joinedArea.join(_corridor); if ( !_joinedArea.join(_measurementArea) ) { - qgcApp()->showMessage(tr("Not able to join areas. Service area and measurement" - " must have a overlapping section, or be connected through a corridor.")); + /*qgcApp()->showMessage(tr("Not able to join areas. Service area and measurement" + " must have a overlapping section, or be connected through a corridor."));*/ return false; // this happens if all areas are pairwise disjoint } @@ -789,6 +779,7 @@ void WimaPlaner::updateTimerSlot() if (_measurementAreaChanging) { if (_measurementArea.path() == _lastMeasurementAreaPath) { // is it still changing? recalcJoinedArea(); + calcArrivalAndReturnPath(); _measurementAreaChanging = false; } } else { @@ -800,6 +791,7 @@ void WimaPlaner::updateTimerSlot() if (_corridorChanging) { if (_corridor.path() == _lastCorridorPath) { // is it still changing? recalcJoinedArea(); + calcArrivalAndReturnPath(); _corridorChanging = false; } } else { @@ -811,6 +803,7 @@ void WimaPlaner::updateTimerSlot() if (_serviceAreaChanging) { if (_serviceArea.path() == _lastServiceAreaPath) { // is it still changing? recalcJoinedArea(); + calcArrivalAndReturnPath(); _serviceAreaChanging = false; } } else { diff --git a/src/WimaView/WimaServiceAreaEditor.qml b/src/WimaView/WimaServiceAreaEditor.qml index 84b94229fdfa6a547379a0e92f1ce03d580c732d..8f642f82306dd4ef3b79cc2bc101a3d3721c1c84 100644 --- a/src/WimaView/WimaServiceAreaEditor.qml +++ b/src/WimaView/WimaServiceAreaEditor.qml @@ -37,9 +37,9 @@ Rectangle { polyline.interactive = polylineInteractive; }*/ - onPolygonInteractiveChanged: { - polygon.interactive = polygonInteractive; - } +// onPolygonInteractiveChanged: { +// polygon.interactive = polygonInteractive; +// } /*function editPolyline(){ if (polylineInteractive){