From 1f7b06471499ab065fa253c546acdd322dc5542b Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 5 Mar 2017 20:06:49 -0800 Subject: [PATCH] Camera list for survey comes from FirmwarePlugin --- qgroundcontrol.pro | 2 + src/FirmwarePlugin/CameraMetaData.cc | 28 ++++++ src/FirmwarePlugin/CameraMetaData.h | 45 ++++++++++ src/FirmwarePlugin/FirmwarePlugin.cc | 67 ++++++++++++++ src/FirmwarePlugin/FirmwarePlugin.h | 6 ++ src/MissionEditor/SurveyItemEditor.qml | 116 +++++++------------------ src/Vehicle/Vehicle.cc | 10 +++ src/Vehicle/Vehicle.h | 3 + 8 files changed, 191 insertions(+), 86 deletions(-) create mode 100644 src/FirmwarePlugin/CameraMetaData.cc create mode 100644 src/FirmwarePlugin/CameraMetaData.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 51e7f3146..7e3837254 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -754,6 +754,7 @@ HEADERS+= \ src/AutoPilotPlugins/Common/MotorComponent.h \ src/AutoPilotPlugins/Common/RadioComponentController.h \ src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h \ + src/FirmwarePlugin/CameraMetaData.h \ src/FirmwarePlugin/FirmwarePlugin.h \ src/FirmwarePlugin/FirmwarePluginManager.h \ src/Vehicle/MultiVehicleManager.h \ @@ -776,6 +777,7 @@ SOURCES += \ src/AutoPilotPlugins/Common/MotorComponent.cc \ src/AutoPilotPlugins/Common/RadioComponentController.cc \ src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.cc \ + src/FirmwarePlugin/CameraMetaData.cc \ src/FirmwarePlugin/FirmwarePlugin.cc \ src/FirmwarePlugin/FirmwarePluginManager.cc \ src/Vehicle/MultiVehicleManager.cc \ diff --git a/src/FirmwarePlugin/CameraMetaData.cc b/src/FirmwarePlugin/CameraMetaData.cc new file mode 100644 index 000000000..bf865762e --- /dev/null +++ b/src/FirmwarePlugin/CameraMetaData.cc @@ -0,0 +1,28 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#include "CameraMetaData.h" + +CameraMetaData::CameraMetaData(const QString& name, + double sensorWidth, + double sensorHeight, + double imageWidth, + double imageHeight, + double focalLength, + QObject* parent) + : QObject(parent) + , _name(name) + , _sensorWidth(sensorWidth) + , _sensorHeight(sensorHeight) + , _imageWidth(imageWidth) + , _imageHeight(imageHeight) + , _focalLength(focalLength) +{ + +} diff --git a/src/FirmwarePlugin/CameraMetaData.h b/src/FirmwarePlugin/CameraMetaData.h new file mode 100644 index 000000000..80b8e7728 --- /dev/null +++ b/src/FirmwarePlugin/CameraMetaData.h @@ -0,0 +1,45 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#ifndef CameraMetaData_H +#define CameraMetaData_H + +#include + +/// Set of meta data which describes a camera available on the vehicle +class CameraMetaData : public QObject +{ + Q_OBJECT + +public: + CameraMetaData(const QString& name, + double sensorWidth, + double sensorHeight, + double imageWidth, + double imageHeight, + double focalLength, + QObject* parent = NULL); + + Q_PROPERTY(QString name MEMBER _name CONSTANT) ///< Camera name + Q_PROPERTY(double sensorWidth MEMBER _sensorWidth CONSTANT) ///< Sensor size in millimeters + Q_PROPERTY(double sensorHeight MEMBER _sensorHeight CONSTANT) ///< Sensor size in millimeters + Q_PROPERTY(double imageWidth MEMBER _imageWidth CONSTANT) ///< Image size in pixels + Q_PROPERTY(double imageHeight MEMBER _imageHeight CONSTANT) ///< Image size in pixels + Q_PROPERTY(double focalLength MEMBER _focalLength CONSTANT) ///< Focal length in millimeters + +private: + QString _name; + double _sensorWidth; + double _sensorHeight; + double _imageWidth; + double _imageHeight; + double _focalLength; +}; + +#endif diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 7271ede19..ac018b68b 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -10,6 +10,7 @@ #include "FirmwarePlugin.h" #include "QGCApplication.h" #include "Generic/GenericAutoPilotPlugin.h" +#include "CameraMetaData.h" #include @@ -17,6 +18,8 @@ static FirmwarePluginFactoryRegister* _instance = NULL; const char* guided_mode_not_supported_by_vehicle = "Guided mode not supported by Vehicle."; +QVariantList FirmwarePlugin::_cameraList; + const char* FirmwarePlugin::px4FollowMeFlightMode = "Follow Me"; FirmwarePluginFactory::FirmwarePluginFactory(void) @@ -352,3 +355,67 @@ QVariantList& FirmwarePlugin::toolBarIndicators(const Vehicle* vehicle) } return _toolBarIndicatorList; } + +const QVariantList& FirmwarePlugin::cameraList(const Vehicle* vehicle) +{ + Q_UNUSED(vehicle); + + if (_cameraList.size() == 0) { + CameraMetaData* metaData; + + metaData = new CameraMetaData(tr("Typhoon H CGO3+"), // Camera name + 6.264, // sensorWidth + 4.698, // sensorHeight + 4000, // imageWidth + 3000, // imageHeight + 14, // focalLength + this); // parent + _cameraList.append(QVariant::fromValue(metaData)); + + metaData = new CameraMetaData(tr("Sony ILCE-QX1"), //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-qx1-body-kit/specifications + 23.2, //http://www.sony.com/electronics/camera-lenses/sel16f28/specifications + 15.4, + 5456, + 3632, + 16, + this); + _cameraList.append(QVariant::fromValue(metaData)); + + metaData = new CameraMetaData(tr("Canon S100 PowerShot"), + 7.6, + 5.7, + 4000, + 3000, + 5.2, + this); + _cameraList.append(QVariant::fromValue(metaData)); + + metaData = new CameraMetaData(tr("Canon SX260 HS PowerShot"), + 6.17, + 4.55, + 4000, + 3000, + 4.5, + this); + + metaData = new CameraMetaData(tr("Canon EOS-M 22mm"), + 22.3, + 14.9, + 5184, + 3456, + 22, + this); + _cameraList.append(QVariant::fromValue(metaData)); + + metaData = new CameraMetaData(tr("Sony a6000 16mm"), //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-6000-body-kit#product_details_default + 23.5, + 15.6, + 6000, + 4000, + 16, + this); + _cameraList.append(QVariant::fromValue(metaData)); + } + + return _cameraList; +} diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index 175a6c235..45954d300 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -261,12 +261,18 @@ public: /// @return A list of QUrl with the indicators (see MainToolBarIndicators.qml) virtual QVariantList& toolBarIndicators(const Vehicle* vehicle); + /// Returns a list of CameraMetaData objects for available cameras on the vehicle. + virtual const QVariantList& cameraList(const Vehicle* vehicle); + // FIXME: Hack workaround for non pluginize FollowMe support static const char* px4FollowMeFlightMode; protected: QVariantList _toolBarIndicatorList; +private: + static QVariantList _cameraList; ///< Standard QGC camera list + }; class FirmwarePluginFactory : public QObject diff --git a/src/MissionEditor/SurveyItemEditor.qml b/src/MissionEditor/SurveyItemEditor.qml index d45c3a797..26a613660 100644 --- a/src/MissionEditor/SurveyItemEditor.qml +++ b/src/MissionEditor/SurveyItemEditor.qml @@ -23,78 +23,32 @@ Rectangle { //property real availableWidth ///< Width for control //property var missionItem ///< Mission Item for editor - property real _margin: ScreenTools.defaultFontPixelWidth * 0.25 - property int _cameraIndex: 1 - property real _fieldWidth: ScreenTools.defaultFontPixelWidth * 10.5 + property real _margin: ScreenTools.defaultFontPixelWidth * 0.25 + property int _cameraIndex: 1 + property real _fieldWidth: ScreenTools.defaultFontPixelWidth * 10.5 + property var _cameraList: [ qsTr("Manual Grid (no camera specs)"), qsTr("Custom Camera Grid") ] + property var _vehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle + property var _vehicleCameraList: _vehicle.cameraList readonly property int _gridTypeManual: 0 readonly property int _gridTypeCustomCamera: 1 readonly property int _gridTypeCamera: 2 - ListModel { - id: cameraModelList - - Component.onCompleted: { - cameraModelList.setProperty(_gridTypeCustomCamera, "sensorWidth", missionItem.cameraSensorWidth.rawValue) - cameraModelList.setProperty(_gridTypeCustomCamera, "sensorHeight", missionItem.cameraSensorHeight.rawValue) - cameraModelList.setProperty(_gridTypeCustomCamera, "imageWidth", missionItem.cameraResolutionWidth.rawValue) - cameraModelList.setProperty(_gridTypeCustomCamera, "imageHeight", missionItem.cameraResolutionHeight.rawValue) - cameraModelList.setProperty(_gridTypeCustomCamera, "focalLength", missionItem.cameraFocalLength.rawValue) - } - - ListElement { - text: qsTr("Manual Grid (no camera specs)") - } - ListElement { - text: qsTr("Custom Camera Grid") - } - ListElement { - text: qsTr("Typhoon H CGO3+") - sensorWidth: 6.264 - sensorHeight: 4.698 - imageWidth: 4000 - imageHeight: 3000 - focalLength: 14 + Component.onCompleted: { + for (var i=0; i<_vehicle.cameraList.length; i++) { + _cameraList.push(_vehicle.cameraList[i].name) } - ListElement { - text: qsTr("Sony ILCE-QX1") //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-qx1-body-kit/specifications - sensorWidth: 23.2 //http://www.sony.com/electronics/camera-lenses/sel16f28/specifications - sensorHeight: 15.4 - imageWidth: 5456 - imageHeight: 3632 - focalLength: 16 - } - ListElement { - text: qsTr("Canon S100 PowerShot") - sensorWidth: 7.6 - sensorHeight: 5.7 - imageWidth: 4000 - imageHeight: 3000 - focalLength: 5.2 - } - ListElement { - text: qsTr("Canon SX260 HS PowerShot") - sensorWidth: 6.17 - sensorHeight: 4.55 - imageWidth: 4000 - imageHeight: 3000 - focalLength: 4.5 - } - ListElement { - text: qsTr("Canon EOS-M 22mm") - sensorWidth: 22.3 - sensorHeight: 14.9 - imageWidth: 5184 - imageHeight: 3456 - focalLength: 22 - } - ListElement { - text: qsTr("Sony a6000 16mm") //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-6000-body-kit#product_details_default - sensorWidth: 23.5 - sensorHeight: 15.6 - imageWidth: 6000 - imageHeight: 4000 - focalLength: 16 + gridTypeCombo.model = _cameraList + if (missionItem.manualGrid) { + gridTypeCombo.currentIndex = _gridTypeManual + } else { + var index = gridTypeCombo.find(missionItem.camera) + if (index == -1) { + console.log("Couldn't find camera", missionItem.camera) + gridTypeCombo.currentIndex = _gridTypeManual + } else { + gridTypeCombo.currentIndex = index + } } } @@ -258,35 +212,25 @@ Rectangle { id: gridTypeCombo anchors.left: parent.left anchors.right: parent.right - model: cameraModelList + model: _cameraList currentIndex: -1 - Component.onCompleted: { - if (missionItem.manualGrid) { - gridTypeCombo.currentIndex = _gridTypeManual - } else { - var index = gridTypeCombo.find(missionItem.camera) - if (index == -1) { - console.log("Couldn't find camera", missionItem.camera) - gridTypeCombo.currentIndex = _gridTypeManual - } else { - gridTypeCombo.currentIndex = index - } - } - } - onActivated: { if (index == _gridTypeManual) { missionItem.manualGrid = true + } else if (index == _gridTypeCustomCamera) { + missionItem.manualGrid = false + missionItem.camera = gridTypeCombo.textAt(index) } else { missionItem.manualGrid = false missionItem.camera = gridTypeCombo.textAt(index) _noCameraValueRecalc = true - missionItem.cameraSensorWidth.rawValue = cameraModelList.get(index).sensorWidth - missionItem.cameraSensorHeight.rawValue = cameraModelList.get(index).sensorHeight - missionItem.cameraResolutionWidth.rawValue = cameraModelList.get(index).imageWidth - missionItem.cameraResolutionHeight.rawValue = cameraModelList.get(index).imageHeight - missionItem.cameraFocalLength.rawValue = cameraModelList.get(index).focalLength + var listIndex = index - _gridTypeCamera + missionItem.cameraSensorWidth.rawValue = _vehicleCameraList[listIndex].sensorWidth + missionItem.cameraSensorHeight.rawValue = _vehicleCameraList[listIndex].sensorHeight + missionItem.cameraResolutionWidth.rawValue = _vehicleCameraList[listIndex].imageWidth + missionItem.cameraResolutionHeight.rawValue = _vehicleCameraList[listIndex].imageHeight + missionItem.cameraFocalLength.rawValue = _vehicleCameraList[listIndex].focalLength _noCameraValueRecalc = false recalcFromCameraValues() } diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index fdfae329a..d3fd9db5e 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -2384,6 +2384,16 @@ QVariantList& Vehicle::toolBarIndicators() return emptyList; } +const QVariantList& Vehicle::cameraList(void) const +{ + if (_firmwarePlugin) { + return _firmwarePlugin->cameraList(this); + } + static QVariantList emptyList; + return emptyList; +} + + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index bd4e01db9..f3e226d2f 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -308,6 +308,7 @@ public: Q_PROPERTY(unsigned int telemetryLNoise READ telemetryLNoise NOTIFY telemetryLNoiseChanged) Q_PROPERTY(unsigned int telemetryRNoise READ telemetryRNoise NOTIFY telemetryRNoiseChanged) Q_PROPERTY(QVariantList toolBarIndicators READ toolBarIndicators CONSTANT) + Q_PROPERTY(QVariantList cameraList READ cameraList CONSTANT) /// true: Vehicle is flying, false: Vehicle is on ground Q_PROPERTY(bool flying READ flying WRITE setFlying NOTIFY flyingChanged) @@ -653,6 +654,8 @@ public: QString vehicleImageCompass () const; QVariantList& toolBarIndicators(); + const QVariantList& cameraList(void) const; + public slots: /// Sets the firmware plugin instance data associated with this Vehicle. This object will be parented to the Vehicle -- 2.22.0