Commit 6cda7cf4 authored by Valentin Platzgummer's avatar Valentin Platzgummer

solved some bugs, circ survey update, interactivity wimaArea, wimaPlaner autoupdate

parent e02648a3
......@@ -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()
......
......@@ -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<CoordInfo_t>& transect);
double _altitudeBetweenCoords (const QGeoCoordinate& fromCoord, const QGeoCoordinate& toCoord, double percentTowardsTo);
int _maxPathHeight (const TerrainPathQuery::PathHeightInfo_t& pathHeightInfo, int fromIndex, int toIndex, double& maxHeight);
};
#include "CircularSurveyComplexItem.h"
#include "CircularSurveyComplexItem.h"
#include "JsonHelper.h"
#include "QGCApplication.h"
#include <chrono>
......@@ -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<MissionItem *> &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<MissionItem *> &items,
void CircularSurveyComplexItem::_appendLoadedMissionItems(QList<MissionItem*>& items, QObject* missionItemParent)
{
//qCDebug(SurveyComplexItemLog) << "_appendLoadedMissionItems";
if (_transectsDiry)
if (_transectsDirty)
return;
int seqNum = _sequenceNumber;
......@@ -239,7 +232,7 @@ void CircularSurveyComplexItem::_buildAndAppendMissionItems(QList<MissionItem*>&
// 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;
}
......@@ -377,27 +371,11 @@ void CircularSurveyComplexItem::_rebuildTransectsSlow()
using namespace PolygonCalculus;
using namespace PlanimetryCalculus;
_transects.clear();
QPolygonF surveyPolygon = toQPolygonF(toCartesian2D(_surveyAreaPolygon.coordinateList(), _referencePoint));
if (!_rebuildTransectsInputCheck(surveyPolygon))
return;
// If the transects are getting rebuilt then any previously loaded mission items are now invalid
if (_loadedMissionItemsParent) {
_loadedMissionItems.clear();
_loadedMissionItemsParent->deleteLater();
_loadedMissionItemsParent = nullptr;
}
if (_reverseOnly) { // reverse transects and return
_reverseOnly = false;
if (_transects.size() > 1) {
QList<QList<CoordInfo_t>> transectsReverse;
transectsReverse.reserve(_transects.size());
for (auto list : _transects) {
QList<CoordInfo_t> listReverse;
for (auto coordinate : list)
......@@ -409,6 +387,18 @@ void CircularSurveyComplexItem::_rebuildTransectsSlow()
return;
}
_transects.clear();
QPolygonF surveyPolygon = toQPolygonF(toCartesian2D(_surveyAreaPolygon.coordinateList(), _referencePoint));
if (!_rebuildTransectsInputCheck(surveyPolygon))
return;
// If the transects are getting rebuilt then any previously loaded mission items are now invalid
if (_loadedMissionItemsParent) {
_loadedMissionItems.clear();
_loadedMissionItemsParent->deleteLater();
_loadedMissionItemsParent = nullptr;
}
QVector<QVector<QPointF>> transectPath;
......@@ -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<QGeoCoordinate>().distanceTo(_visualTransectPoints[i+1].value<QGeoCoordinate>());
......@@ -496,7 +487,7 @@ void CircularSurveyComplexItem::_recalcCameraShots()
void CircularSurveyComplexItem::_reverseTransects()
{
_reverseOnly = true;
_rebuildTransectsSlow();
_triggerSlowRecalc();
}
bool CircularSurveyComplexItem::_shortestPath(const QGeoCoordinate &start, const QGeoCoordinate &destination, QVector<QGeoCoordinate> &shortestPath)
......
......@@ -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;
};
......
......@@ -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 {
......
......@@ -9,7 +9,7 @@
namespace PolygonCalculus {
enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow};
enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow, Error};
typedef QList<QVector3D> QVector3DList;
typedef QList<QPointF> QPointFList;
......
......@@ -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);
}
}
}
......
......@@ -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,6 +473,7 @@ void WimaPlaner::recalcPolygonInteractivity(int index)
if (index >= 0 && index < _visualItems.count()) {
resetAllInteractive();
WimaArea* interactivePoly = qobject_cast<WimaArea*>(_visualItems.get(index));
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 {
......
......@@ -37,9 +37,9 @@ Rectangle {
polyline.interactive = polylineInteractive;
}*/
onPolygonInteractiveChanged: {
polygon.interactive = polygonInteractive;
}
// onPolygonInteractiveChanged: {
// polygon.interactive = polygonInteractive;
// }
/*function editPolyline(){
if (polylineInteractive){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment