Commit 4c53c984 authored by Don Gagne's avatar Don Gagne

parent b47b6075
......@@ -126,6 +126,12 @@ bool CorridorScanComplexItem::load(const QJsonObject& complexObject, int sequenc
_ignoreRecalc = false;
_recalcComplexDistance();
if (_cameraShots == 0) {
// Shot count was possibly not available from plan file
_recalcCameraShots();
}
return true;
}
......@@ -459,14 +465,17 @@ void CorridorScanComplexItem::_rebuildTransectsPhase1(void)
}
}
void CorridorScanComplexItem::_rebuildTransectsPhase2(void)
void CorridorScanComplexItem::_recalcComplexDistance(void)
{
// Calculate distance flown for complex item
_complexDistance = 0;
for (int i=0; i<_visualTransectPoints.count() - 1; i++) {
_complexDistance += _visualTransectPoints[i].value<QGeoCoordinate>().distanceTo(_visualTransectPoints[i+1].value<QGeoCoordinate>());
}
emit complexDistanceChanged();
}
void CorridorScanComplexItem::_recalcCameraShots(void)
{
double triggerDistance = _cameraCalc.adjustedFootprintFrontal()->rawValue().toDouble();
if (triggerDistance == 0) {
_cameraShots = 0;
......@@ -478,14 +487,7 @@ void CorridorScanComplexItem::_rebuildTransectsPhase2(void)
_cameraShots = singleTransectImageCount * _transectCount();
}
}
_coordinate = _visualTransectPoints.count() ? _visualTransectPoints.first().value<QGeoCoordinate>() : QGeoCoordinate();
_exitCoordinate = _visualTransectPoints.count() ? _visualTransectPoints.last().value<QGeoCoordinate>() : QGeoCoordinate();
emit cameraShotsChanged();
emit complexDistanceChanged();
emit coordinateChanged(_coordinate);
emit exitCoordinateChanged(_exitCoordinate);
}
bool CorridorScanComplexItem::readyForSave(void) const
......
......@@ -64,7 +64,8 @@ private slots:
// Overrides from TransectStyleComplexItem
void _rebuildTransectsPhase1 (void) final;
void _rebuildTransectsPhase2 (void) final;
void _recalcComplexDistance (void) final;
void _recalcCameraShots (void) final;
private:
int _transectCount (void) const;
......
......@@ -144,6 +144,12 @@ bool SurveyComplexItem::load(const QJsonObject& complexObject, int sequenceNumbe
if (!_loadV4V5(complexObject, sequenceNumber, errorString, version)) {
return false;
}
_recalcComplexDistance();
if (_cameraShots == 0) {
// Shot count was possibly not available from plan file
_recalcCameraShots();
}
} else {
// Must be v2 or v3
QJsonObject v3ComplexObject = complexObject;
......@@ -1385,42 +1391,78 @@ void SurveyComplexItem::_rebuildTransectsFromPolygon(bool refly, const QPolygonF
qCDebug(SurveyComplexItemLog) << "_transects.size() " << _transects.size();
}
void SurveyComplexItem::_rebuildTransectsPhase2(void)
void SurveyComplexItem::_recalcComplexDistance(void)
{
// Calculate distance flown for complex item
_complexDistance = 0;
for (int i=0; i<_visualTransectPoints.count() - 1; i++) {
_complexDistance += _visualTransectPoints[i].value<QGeoCoordinate>().distanceTo(_visualTransectPoints[i+1].value<QGeoCoordinate>());
}
emit complexDistanceChanged();
}
if (triggerDistance() == 0) {
void SurveyComplexItem::_recalcCameraShots(void)
{
double triggerDistance = this->triggerDistance();
if (triggerDistance == 0) {
_cameraShots = 0;
} else {
if (_cameraTriggerInTurnAroundFact.rawValue().toBool()) {
_cameraShots = qCeil(_complexDistance / triggerDistance());
_cameraShots = qCeil(_complexDistance / triggerDistance);
} else {
_cameraShots = 0;
for (const QList<TransectStyleComplexItem::CoordInfo_t>& transect: _transects) {
QGeoCoordinate firstCameraCoord, lastCameraCoord;
if (_hasTurnaround()) {
firstCameraCoord = transect[1].coord;
lastCameraCoord = transect[transect.count() - 2].coord;
if (_loadedMissionItemsParent) {
// We have to do it the hard way based on the mission items themselves
if (hoverAndCaptureEnabled()) {
// Count the number of camera triggers in the mission items
for (const MissionItem* missionItem: _loadedMissionItems) {
_cameraShots += missionItem->command() == MAV_CMD_IMAGE_START_CAPTURE ? 1 : 0;
}
} else {
firstCameraCoord = transect.first().coord;
lastCameraCoord = transect.last().coord;
bool waitingForTriggerStop = false;
QGeoCoordinate distanceStartCoord;
QGeoCoordinate distanceEndCoord;
for (const MissionItem* missionItem: _loadedMissionItems) {
if (missionItem->command() == MAV_CMD_NAV_WAYPOINT) {
if (waitingForTriggerStop) {
distanceEndCoord = QGeoCoordinate(missionItem->param5(), missionItem->param6());
} else {
distanceStartCoord = QGeoCoordinate(missionItem->param5(), missionItem->param6());
}
} else if (missionItem->command() == MAV_CMD_DO_SET_CAM_TRIGG_DIST) {
if (missionItem->param1() > 0) {
// Trigger start
waitingForTriggerStop = true;
} else {
// Trigger stop
waitingForTriggerStop = false;
_cameraShots += qCeil(distanceEndCoord.distanceTo(distanceStartCoord) / triggerDistance);
distanceStartCoord = QGeoCoordinate();
distanceEndCoord = QGeoCoordinate();
}
}
}
}
} else {
// We have transects available, calc from those
for (const QList<TransectStyleComplexItem::CoordInfo_t>& transect: _transects) {
QGeoCoordinate firstCameraCoord, lastCameraCoord;
if (_hasTurnaround() && !hoverAndCaptureEnabled()) {
firstCameraCoord = transect[1].coord;
lastCameraCoord = transect[transect.count() - 2].coord;
} else {
firstCameraCoord = transect.first().coord;
lastCameraCoord = transect.last().coord;
}
_cameraShots += qCeil(firstCameraCoord.distanceTo(lastCameraCoord) / triggerDistance);
}
_cameraShots += qCeil(firstCameraCoord.distanceTo(lastCameraCoord) / triggerDistance());
}
}
}
_coordinate = _visualTransectPoints.count() ? _visualTransectPoints.first().value<QGeoCoordinate>() : QGeoCoordinate();
_exitCoordinate = _visualTransectPoints.count() ? _visualTransectPoints.last().value<QGeoCoordinate>() : QGeoCoordinate();
emit cameraShotsChanged();
emit complexDistanceChanged();
emit coordinateChanged(_coordinate);
emit exitCoordinateChanged(_exitCoordinate);
}
// FIXME: This same exact code is in Corridor Scan. Move to TransectStyleComplex?
......
......@@ -77,8 +77,9 @@ signals:
private slots:
// Overrides from TransectStyleComplexItem
void _rebuildTransectsPhase1(void) final;
void _rebuildTransectsPhase2(void) final;
void _rebuildTransectsPhase1 (void) final;
void _recalcComplexDistance (void) final;
void _recalcCameraShots (void) final;
private:
enum CameraTriggerCode {
......
......@@ -36,7 +36,6 @@ const char* TransectStyleComplexItem::_jsonVisualTransectPointsKey = "Vis
const char* TransectStyleComplexItem::_jsonItemsKey = "Items";
const char* TransectStyleComplexItem::_jsonFollowTerrainKey = "FollowTerrain";
const char* TransectStyleComplexItem::_jsonCameraShotsKey = "CameraShots";
const char* TransectStyleComplexItem::_jsonComplexDistanceKey = "ComplexDistance";
const int TransectStyleComplexItem::_terrainQueryTimeoutMsecs = 1000;
......@@ -142,7 +141,6 @@ void TransectStyleComplexItem::_save(QJsonObject& complexObject)
innerObject[refly90DegreesName] = _refly90DegreesFact.rawValue().toBool();
innerObject[_jsonFollowTerrainKey] = _followTerrain;
innerObject[_jsonCameraShotsKey] = _cameraShots;
innerObject[_jsonComplexDistanceKey] = _complexDistance;
if (_followTerrain) {
innerObject[terrainAdjustToleranceName] = _terrainAdjustToleranceFact.rawValue().toDouble();
......@@ -217,7 +215,6 @@ bool TransectStyleComplexItem::_load(const QJsonObject& complexObject, QString&
{ _jsonItemsKey, QJsonValue::Array, true },
{ _jsonFollowTerrainKey, QJsonValue::Bool, true },
{ _jsonCameraShotsKey, QJsonValue::Double, false }, // Not required since it was missing from initial implementation
{ _jsonComplexDistanceKey, QJsonValue::Double, false }, // Not required since it was missing from initial implementation
};
if (!JsonHelper::validateKeys(innerObject, innerKeyInfoList, errorString)) {
return false;
......@@ -260,9 +257,6 @@ bool TransectStyleComplexItem::_load(const QJsonObject& complexObject, QString&
if (innerObject.contains(_jsonCameraShotsKey)) {
_cameraShots = innerObject[_jsonCameraShotsKey].toInt();
}
if (innerObject.contains(_jsonComplexDistanceKey)) {
_complexDistance = innerObject[_jsonComplexDistanceKey].toDouble();
}
if (_followTerrain) {
QList<JsonHelper::KeyValidateInfo> followTerrainKeyInfoList = {
......@@ -409,7 +403,8 @@ void TransectStyleComplexItem::_rebuildTransects(void)
emit coordinateChanged(_coordinate);
emit exitCoordinateChanged(_exitCoordinate);
_rebuildTransectsPhase2();
_recalcComplexDistance();
_recalcCameraShots();
emit lastSequenceNumberChanged(lastSequenceNumber());
emit timeBetweenShotsChanged();
......
......@@ -129,9 +129,6 @@ signals:
void followTerrainChanged (bool followTerrain);
protected slots:
virtual void _rebuildTransectsPhase1 (void) = 0; ///< Rebuilds the _transects array
virtual void _rebuildTransectsPhase2 (void) = 0; ///< Adjust values associated with _transects array
void _setDirty (void);
void _setIfDirty (bool dirty);
void _updateCoordinateAltitudes (void);
......@@ -139,6 +136,10 @@ protected slots:
void _rebuildTransects (void);
protected:
virtual void _rebuildTransectsPhase1 (void) = 0; ///< Rebuilds the _transects array
virtual void _recalcComplexDistance (void) = 0;
virtual void _recalcCameraShots (void) = 0;
void _save (QJsonObject& saveObject);
bool _load (const QJsonObject& complexObject, QString& errorString);
void _setExitCoordinate (const QGeoCoordinate& coordinate);
......@@ -198,7 +199,6 @@ protected:
static const char* _jsonItemsKey;
static const char* _jsonFollowTerrainKey;
static const char* _jsonCameraShotsKey;
static const char* _jsonComplexDistanceKey;
static const int _terrainQueryTimeoutMsecs;
......
......@@ -115,10 +115,12 @@ void TransectStyleComplexItemTest::_testRebuildTransects(void)
// lastSequenceNumberChanged signal
_adjustSurveAreaPolygon();
QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
QVERIFY(_multiSpy->checkSignalsByMask(coveredAreaChangedMask | lastSequenceNumberChangedMask));
_transectStyleItem->rebuildTransectsPhase1Called = false;
_transectStyleItem->rebuildTransectsPhase2Called = false;
_transectStyleItem->recalcCameraShotsCalled = false;
_transectStyleItem->recalcComplexDistanceCalled = false;
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
......@@ -136,30 +138,36 @@ void TransectStyleComplexItemTest::_testRebuildTransects(void)
qDebug() << fact->name();
changeFactValue(fact);
QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
_transectStyleItem->rebuildTransectsPhase1Called = false;
_transectStyleItem->rebuildTransectsPhase2Called = false;
_transectStyleItem->recalcCameraShotsCalled = false;
_transectStyleItem->recalcComplexDistanceCalled = false;
}
rgFacts.clear();
_transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(false);
_transectStyleItem->rebuildTransectsPhase1Called = false;
_transectStyleItem->rebuildTransectsPhase2Called = false;
_transectStyleItem->recalcCameraShotsCalled = false;
_transectStyleItem->recalcComplexDistanceCalled = false;
changeFactValue(_transectStyleItem->cameraCalc()->imageDensity());
QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
_multiSpy->clearAllSignals();
_transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(true);
_transectStyleItem->rebuildTransectsPhase1Called = false;
_transectStyleItem->rebuildTransectsPhase2Called = false;
_transectStyleItem->recalcCameraShotsCalled = false;
_transectStyleItem->recalcComplexDistanceCalled = false;
changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
_multiSpy->clearAllSignals();
}
......@@ -219,7 +227,8 @@ void TransectStyleComplexItemTest::_testAltMode(void)
TransectStyleItem::TransectStyleItem(Vehicle* vehicle, QObject* parent)
: TransectStyleComplexItem (vehicle, false /* flyView */, QStringLiteral("UnitTestTransect"), parent)
, rebuildTransectsPhase1Called (false)
, rebuildTransectsPhase2Called (false)
, recalcComplexDistanceCalled (false)
, recalcCameraShotsCalled (false)
{
}
......@@ -229,7 +238,12 @@ void TransectStyleItem::_rebuildTransectsPhase1(void)
rebuildTransectsPhase1Called = true;
}
void TransectStyleItem::_rebuildTransectsPhase2(void)
void TransectStyleItem::_recalcComplexDistance(void)
{
rebuildTransectsPhase2Called = true;
recalcComplexDistanceCalled = true;
}
void TransectStyleItem::_recalcCameraShots(void)
{
recalcCameraShotsCalled = true;
}
......@@ -96,10 +96,12 @@ public:
void applyNewAltitude (double newAltitude) final { Q_UNUSED(newAltitude); }
bool rebuildTransectsPhase1Called;
bool rebuildTransectsPhase2Called;
bool recalcComplexDistanceCalled;
bool recalcCameraShotsCalled;
private slots:
// Overrides from TransectStyleComplexItem
void _rebuildTransectsPhase1(void) final;
void _rebuildTransectsPhase2(void) final;
void _rebuildTransectsPhase1 (void) final;
void _recalcComplexDistance (void) final;
void _recalcCameraShots (void) final;
};
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