Unverified Commit 96ca8e47 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #5911 from DonLakeFlyer/CameraCalcFixesVersioning

Fixes to CameraCalc loading plus versioning
parents 868eb627 e6718b14
This diff is collapsed.
......@@ -20,32 +20,25 @@ class CameraCalc : public CameraSpec
public:
CameraCalc(Vehicle* vehicle, QObject* parent = NULL);
Q_ENUMS(CameraSpecType)
Q_PROPERTY(CameraSpecType cameraSpecType READ cameraSpecType WRITE setCameraSpecType NOTIFY cameraSpecTypeChanged)
Q_PROPERTY(QString knownCameraName READ knownCameraName WRITE setKnownCameraName NOTIFY knownCameraNameChanged)
Q_PROPERTY(Fact* valueSetIsDistance READ valueSetIsDistance CONSTANT) ///< true: distance specified, resolution calculated
Q_PROPERTY(Fact* distanceToSurface READ distanceToSurface CONSTANT) ///< Distance to surface for image foot print calculation
Q_PROPERTY(Fact* imageDensity READ imageDensity CONSTANT) ///< Image density on surface (cm/px)
Q_PROPERTY(Fact* frontalOverlap READ frontalOverlap CONSTANT)
Q_PROPERTY(Fact* sideOverlap READ sideOverlap CONSTANT)
Q_PROPERTY(Fact* adjustedFootprintSide READ adjustedFootprintSide CONSTANT) ///< Side footprint adjusted down for overlap
Q_PROPERTY(Fact* adjustedFootprintFrontal READ adjustedFootprintFrontal CONSTANT) ///< Frontal footprint adjusted down for overlap
Q_PROPERTY(QString cameraName READ cameraName WRITE setCameraName NOTIFY cameraNameChanged)
Q_PROPERTY(QString customCameraName READ customCameraName CONSTANT) // Camera name for custom camera setting
Q_PROPERTY(QString manualCameraName READ manualCameraName CONSTANT) // Camera name for manual camera setting
Q_PROPERTY(Fact* valueSetIsDistance READ valueSetIsDistance CONSTANT) ///< true: distance specified, resolution calculated
Q_PROPERTY(Fact* distanceToSurface READ distanceToSurface CONSTANT) ///< Distance to surface for image foot print calculation
Q_PROPERTY(Fact* imageDensity READ imageDensity CONSTANT) ///< Image density on surface (cm/px)
Q_PROPERTY(Fact* frontalOverlap READ frontalOverlap CONSTANT)
Q_PROPERTY(Fact* sideOverlap READ sideOverlap CONSTANT)
Q_PROPERTY(Fact* adjustedFootprintSide READ adjustedFootprintSide CONSTANT) ///< Side footprint adjusted down for overlap
Q_PROPERTY(Fact* adjustedFootprintFrontal READ adjustedFootprintFrontal CONSTANT) ///< Frontal footprint adjusted down for overlap
// The following values are calculated from the camera properties
Q_PROPERTY(double imageFootprintSide READ imageFootprintSide NOTIFY imageFootprintSideChanged) ///< Size of image size side in meters
Q_PROPERTY(double imageFootprintFrontal READ imageFootprintFrontal NOTIFY imageFootprintFrontalChanged) ///< Size of image size frontal in meters
Q_PROPERTY(double imageFootprintSide READ imageFootprintSide NOTIFY imageFootprintSideChanged) ///< Size of image size side in meters
Q_PROPERTY(double imageFootprintFrontal READ imageFootprintFrontal NOTIFY imageFootprintFrontalChanged) ///< Size of image size frontal in meters
enum CameraSpecType {
CameraSpecNone,
CameraSpecCustom,
CameraSpecKnown
};
CameraSpecType cameraSpecType(void) const { return _cameraSpecType; }
QString knownCameraName(void) const { return _knownCameraName; }
void setCameraSpecType(CameraSpecType cameraSpecType);
void setKnownCameraName(QString knownCameraName);
static QString customCameraName(void);
static QString manualCameraName(void);
QString cameraName(void) const { return _cameraName; }
void setCameraName(QString cameraName);
Fact* valueSetIsDistance (void) { return &_valueSetIsDistanceFact; }
Fact* distanceToSurface (void) { return &_distanceToSurfaceFact; }
......@@ -65,21 +58,18 @@ public:
bool load(const QJsonObject& json, QString& errorString);
signals:
void cameraSpecTypeChanged (CameraSpecType cameraSpecType);
void knownCameraNameChanged (QString knownCameraName);
void cameraNameChanged (QString cameraName);
void dirtyChanged (bool dirty);
void imageFootprintSideChanged (double imageFootprintSide);
void imageFootprintFrontalChanged (double imageFootprintFrontal);
private slots:
void _knownCameraNameChanged(QString knownCameraName);
void _recalcTriggerDistance(void);
private:
Vehicle* _vehicle;
bool _dirty;
CameraSpecType _cameraSpecType;
QString _knownCameraName;
QString _cameraName;
bool _disableRecalc;
QMap<QString, FactMetaData*> _metaDataMap;
......@@ -104,6 +94,15 @@ private:
static const char* _sideOverlapName;
static const char* _adjustedFootprintSideName;
static const char* _adjustedFootprintFrontalName;
static const char* _jsonCameraNameKey;
// The following are deprecated usage and only included in order to convert older formats
enum CameraSpecType {
CameraSpecNone,
CameraSpecCustom,
CameraSpecKnown
};
static const char* _jsonCameraSpecTypeKey;
static const char* _jsonKnownCameraNameKey;
};
......@@ -125,7 +125,7 @@ public:
bool loadTextFile(QFile& file, QString& errorString);
// Overrides from PlanElementController
bool supported (void) const final { return true; };
bool supported (void) const final { return true; }
void start (bool editMode) final;
void save (QJsonObject& json) final;
bool load (const QJsonObject& json, QString& errorString) final;
......
......@@ -273,7 +273,7 @@ void PlanMasterController::sendToVehicle(void)
void PlanMasterController::loadFromFile(const QString& filename)
{
QString errorString;
QString errorMessage = tr("Error reading Plan file (%1). %2").arg(filename).arg("%1");
QString errorMessage = tr("Error loading Plan file (%1). %2").arg(filename).arg("%1");
if (filename.isEmpty()) {
return;
......
......@@ -148,10 +148,6 @@ Item {
setCircleRadius(center, radius)
}
function loadKMLFile() {
mapPolygon.loadKMLFile("/Users/Don/Downloads/polygon.kml")
}
onInteractiveChanged: {
if (interactive) {
addHandles()
......@@ -418,7 +414,7 @@ Item {
MenuItem {
text: qsTr("Set radius..." )
enabled: _circle
visible: _circle
onTriggered: radiusDialog.visible = true
}
......
......@@ -87,7 +87,7 @@ StructureScanComplexItem::StructureScanComplexItem(Vehicle* vehicle, QObject* pa
connect(&_flightPolygon, &QGCMapPolygon::pathChanged, this, &StructureScanComplexItem::_flightPathChanged);
connect(_cameraCalc.distanceToSurface(), &Fact::valueChanged, this, &StructureScanComplexItem::_rebuildFlightPolygon);
connect(&_cameraCalc, &CameraCalc::cameraSpecTypeChanged, this, &StructureScanComplexItem::_cameraSpecTypeChanged);
connect(&_cameraCalc, &CameraCalc::cameraNameChanged, this, &StructureScanComplexItem::_resetGimbal);
connect(&_flightPolygon, &QGCMapPolygon::pathChanged, this, &StructureScanComplexItem::_recalcCameraShots);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &StructureScanComplexItem::_recalcCameraShots);
......@@ -205,12 +205,17 @@ bool StructureScanComplexItem::load(const QJsonObject& complexObject, int sequen
int version = complexObject[JsonHelper::jsonVersionKey].toInt();
if (version != 1) {
errorString = tr("Version %1 not supported").arg(version);
errorString = tr("%1 complex item version %2 not supported").arg(jsonComplexItemTypeValue).arg(version);
return false;
}
setSequenceNumber(sequenceNumber);
// Load CameraCalc first since it will trigger camera name change which will trounce gimbal angles
if (!_cameraCalc.load(complexObject[_jsonCameraCalcKey].toObject(), errorString)) {
return false;
}
_gimbalPitchFact.setRawValue(complexObject[_gimbalPitchFactName].toDouble());
_gimbalYawFact.setRawValue (complexObject[_gimbalYawFactName].toDouble());
_altitudeFact.setRawValue (complexObject[_altitudeFactName].toDouble());
......@@ -218,9 +223,6 @@ bool StructureScanComplexItem::load(const QJsonObject& complexObject, int sequen
_altitudeRelative = complexObject[_jsonAltitudeRelativeKey].toBool(true);
_yawVehicleToStructure = complexObject[_jsonYawVehicleToStructureKey].toBool(true);
if (!_cameraCalc.load(complexObject[_jsonCameraCalcKey].toObject(), errorString)) {
return false;
}
if (!_structurePolygon.loadFromJson(complexObject, true /* required */, errorString)) {
_structurePolygon.clear();
return false;
......@@ -455,10 +457,8 @@ void StructureScanComplexItem::_recalcCameraShots(void)
_setCameraShots(cameraShots * _layersFact.rawValue().toInt());
}
void StructureScanComplexItem::_cameraSpecTypeChanged(CameraCalc::CameraSpecType cameraSpecType)
void StructureScanComplexItem::_resetGimbal(void)
{
Q_UNUSED(cameraSpecType);
_gimbalPitchFact.setCookedValue(0);
_gimbalYawFact.setCookedValue(90);
}
......
......@@ -113,7 +113,7 @@ private slots:
void _updateCoordinateAltitudes (void);
void _rebuildFlightPolygon (void);
void _recalcCameraShots (void);
void _cameraSpecTypeChanged (CameraCalc::CameraSpecType cameraSpecType);
void _resetGimbal (void);
private:
void _setExitCoordinate(const QGeoCoordinate& coordinate);
......
......@@ -99,7 +99,7 @@ void StructureScanComplexItemTest::_initItem(void)
mapPolygon->appendVertex(vertex);
}
_structureScanItem->cameraCalc()->setCameraSpecType(CameraCalc::CameraSpecNone);
_structureScanItem->cameraCalc()->setCameraName(CameraCalc::manualCameraName());
_structureScanItem->gimbalPitch()->setCookedValue(45);
_structureScanItem->gimbalYaw()->setCookedValue(45);
_structureScanItem->layers()->setCookedValue(2);
......@@ -118,7 +118,7 @@ void StructureScanComplexItemTest::_validateItem(StructureScanComplexItem* item)
QCOMPARE(expectedVertex, actualVertex);
}
QCOMPARE((int)item->cameraCalc()->cameraSpecType(), (int)CameraCalc::CameraSpecNone);
QCOMPARE(_structureScanItem->cameraCalc()->cameraName() , CameraCalc::manualCameraName());
QCOMPARE(item->gimbalPitch()->cookedValue().toDouble(), 45.0);
QCOMPARE(item->gimbalYaw()->cookedValue().toDouble(), 45.0);
QCOMPARE(item->layers()->cookedValue().toInt(), 2);
......@@ -144,8 +144,8 @@ void StructureScanComplexItemTest::_testGimbalAngleUpdate(void)
// This sets the item to CameraCalc::CameraSpecNone and non-standard gimbal angles
_initItem();
// Switching to a camera specific setup should set gimbal angles to defaults surface scan
_structureScanItem->cameraCalc()->setCameraSpecType(CameraCalc::CameraSpecCustom);
// Switching to a camera specific setup should set gimbal angles to defaults
_structureScanItem->cameraCalc()->setCameraName(CameraCalc::customCameraName());
QCOMPARE(_structureScanItem->gimbalPitch()->cookedValue().toDouble(), 0.0);
QCOMPARE(_structureScanItem->gimbalYaw()->cookedValue().toDouble(), 90.0);
}
......
......@@ -23,7 +23,7 @@ Column {
property real _margin: ScreenTools.defaultFontPixelWidth / 2
property int _cameraIndex: 1
property real _fieldWidth: ScreenTools.defaultFontPixelWidth * 10.5
property var _cameraList: [ qsTr("Manual (no camera specs)"), qsTr("Custom Camera") ]
property var _cameraList: [ ]
property var _vehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle
property var _vehicleCameraList: _vehicle ? _vehicle.staticCameraList : []
......@@ -32,31 +32,18 @@ Column {
readonly property int _gridTypeCamera: 2
Component.onCompleted: {
_cameraList.push(cameraCalc.manualCameraName)
_cameraList.push(cameraCalc.customCameraName)
for (var i=0; i<_vehicle.staticCameraList.length; i++) {
_cameraList.push(_vehicle.staticCameraList[i].name)
}
gridTypeCombo.model = _cameraList
if (cameraCalc.cameraSpecType === CameraCalc.CameraSpecNone) {
gridTypeCombo.currentIndex = _gridTypeManual
var knownCameraIndex = gridTypeCombo.find(cameraCalc.cameraName)
if (knownCameraIndex != -1) {
gridTypeCombo.currentIndex = knownCameraIndex
} else {
var index = -1
for (index=0; index<_cameraList.length; index++) {
if (_cameraList[index] == cameraCalc.knownCameraName) {
break;
}
}
cameraCalc.fixedOrientation.value = false
if (index == _cameraList.length) {
gridTypeCombo.currentIndex = _gridTypeCustomCamera
} else {
gridTypeCombo.currentIndex = index
if (index != 1) {
// Specific camera is selected
var camera = _vehicleCameraList[index - _gridTypeCamera]
cameraCalc.fixedOrientation.value = camera.fixedOrientation
cameraCalc.minTriggerInterval.value = camera.minTriggerInterval
}
}
console.log("Internal error: Known camera not found", cameraCalc.cameraName)
gridTypeCombo.currentIndex = _gridTypeCustomCamera
}
}
......@@ -86,21 +73,7 @@ Column {
anchors.right: parent.right
model: _cameraList
currentIndex: -1
onActivated: {
if (index == _gridTypeManual) {
cameraCalc.cameraSpecType = CameraCalc.CameraSpecNone
cameraCalc.valueSetIsDistance.value = false
} else if (index == _gridTypeCustomCamera) {
cameraCalc.cameraSpecType = CameraCalc.CameraSpecCustom
cameraCalc.knownCameraName = gridTypeCombo.textAt(index)
cameraCalc.fixedOrientation.value = false
cameraCalc.minTriggerInterval.value = 0
} else {
cameraCalc.cameraSpecType = CameraCalc.CameraSpecKnown
cameraCalc.knownCameraName = gridTypeCombo.textAt(index)
}
}
onActivated: cameraCalc.cameraName = gridTypeCombo.textAt(index)
} // QGCComboxBox
// Camera based grid ui
......@@ -108,7 +81,7 @@ Column {
anchors.left: parent.left
anchors.right: parent.right
spacing: _margin
visible: cameraCalc.cameraSpecType !== CameraCalc.CameraSpecNone
visible: cameraCalc.cameraName !== cameraCalc.manualCameraName
Row {
spacing: _margin
......@@ -138,7 +111,7 @@ Column {
anchors.left: parent.left
anchors.right: parent.right
spacing: _margin
visible: cameraCalc.cameraSpecType === CameraCalc.CameraSpecCustom
visible: cameraCalc.cameraName === cameraCalc.customCameraName
RowLayout {
anchors.left: parent.left
......@@ -306,7 +279,7 @@ Column {
columnSpacing: _margin
rowSpacing: _margin
columns: 2
visible: cameraCalc.cameraSpecType === CameraCalc.CameraSpecNone
visible: cameraCalc.cameraName === cameraCalc.manualCameraName
QGCLabel { text: distanceToSurfaceLabel }
FactTextField {
......
......@@ -92,7 +92,7 @@ Rectangle {
columnSpacing: ScreenTools.defaultFontPixelWidth / 2
rowSpacing: 0
columns: 3
enabled: missionItem.cameraCalc.cameraSpecType === CameraCalc.CameraSpecNone
enabled: missionItem.cameraCalc.cameraName === missionItem.cameraCalc.manualCameraName
Item { width: 1; height: 1 }
QGCLabel { text: qsTr("Pitch") }
......
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