Commit b159b443 authored by dogmaphobic's avatar dogmaphobic

Added MavManager QML Interface

Initial rendering of Waypoints
parent 9c058ce8
......@@ -356,6 +356,7 @@ HEADERS += \
src/ViewWidgets/CustomCommandWidgetController.h \
src/ViewWidgets/ViewWidgetController.h \
src/Waypoint.h \
src/QmlControls/QGCMavManager.h
!AndroidBuild {
HEADERS += \
......@@ -485,6 +486,7 @@ SOURCES += \
src/ViewWidgets/CustomCommandWidgetController.cc \
src/ViewWidgets/ViewWidgetController.cc \
src/Waypoint.cc \
src/QmlControls/QGCMavManager.cc
!AndroidBuild {
SOURCES += \
......
......@@ -118,6 +118,8 @@
<file alias="QGroundControl/FlightControls/QGCWaypointEditor.qml">src/ui/qmlcommon/QGCWaypointEditor.qml</file>
<file alias="QGroundControl/FlightControls/QGCMapToolButton.qml">src/ui/qmlcommon/QGCMapToolButton.qml</file>
<file alias="QGroundControl/FlightControls/QGCArtificialHorizon.qml">src/ui/qmlcommon/QGCArtificialHorizon.qml</file>
<!-- QML Map Resources -->
<file alias="QGroundControl/FlightControls/QGCWaypoint.qml">src/ui/qmlcommon/QGCWaypoint.qml</file>
<!-- QML Main UI Resources -->
<file alias="compass.svg">src/ui/qmlcommon/compass.svg</file>
<file alias="compassNeedle.svg">src/ui/qmlcommon/compassNeedle.svg</file>
......
......@@ -58,12 +58,14 @@
#include "QGCTemporaryFile.h"
#include "QGCFileDialog.h"
#include "QGCPalette.h"
#include "ScreenTools.h"
#include "QGCLoggingCategory.h"
#include "ViewWidgetController.h"
#include "ParameterEditorController.h"
#include "CustomCommandWidgetController.h"
#include "ScreenTools.h"
#include "QGCMavManager.h"
#ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h"
#endif
......@@ -96,6 +98,18 @@ static QObject* screenToolsSingletonFactory(QQmlEngine*, QJSEngine*)
return screenTools;
}
/**
* @brief MavManager creation callback
*
* This is called by the QtQuick engine for creating the singleton
**/
static QObject* mavManagerSingletonFactory(QQmlEngine*, QJSEngine*)
{
MavManager* mavManager = new MavManager;
return mavManager;
}
/**
* @brief Constructor for the main application.
*
......@@ -287,9 +301,11 @@ void QGCApplication::_initCommon(void)
qmlRegisterType<ViewWidgetController>("QGroundControl.Controllers", 1, 0, "ViewWidgetController");
qmlRegisterType<ParameterEditorController>("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
qmlRegisterType<CustomCommandWidgetController>("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController");
//-- Create QML Singleton Interfaces
qmlRegisterSingletonType<ScreenTools>("QGroundControl.ScreenTools", 1, 0, "ScreenTools", screenToolsSingletonFactory);
qmlRegisterSingletonType<MavManager>("QGroundControl.MavManager", 1, 0, "MavManager", mavManagerSingletonFactory);
//-- Register Waypoint Interface
qmlRegisterInterface<Waypoint>("Waypoint");
}
bool QGCApplication::_initForNormalAppBoot(void)
......
This diff is collapsed.
This diff is collapsed.
......@@ -45,6 +45,10 @@ class ScreenTools : public QObject
public:
ScreenTools();
Q_PROPERTY(bool isAndroid READ isAndroid CONSTANT)
Q_PROPERTY(bool isiOS READ isiOS CONSTANT)
Q_PROPERTY(bool isMobile READ isMobile CONSTANT)
//! Returns the global mouse X position
Q_PROPERTY(int mouseX READ mouseX)
//! Returns the global mouse Y position
......@@ -110,6 +114,16 @@ public:
double pixelSizeFactor ();
double defaultFontPointSize(void);
#if defined (__android__)
bool isAndroid () { return true; }
bool isiOS () { return false; }
bool isMobile () { return true; }
#else
bool isAndroid () { return false; }
bool isiOS () { return false; }
bool isMobile () { return false; }
#endif
signals:
void repaintRequestedChanged();
void pixelSizeFactorChanged();
......
This diff is collapsed.
......@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project
#include <QObject>
#include <QString>
#include <QtQml>
#include <QTextStream>
#include "QGCMAVLink.h"
#include "QGC.h"
......@@ -42,157 +43,192 @@ This file is part of the PIXHAWK project
class Waypoint : public QObject
{
Q_OBJECT
public:
Waypoint(quint16 id = 0, double x = 0.0, double y = 0.0, double z = 0.0, double param1 = 0.0, double param2 = 0.0, double param3 = 0.0, double param4 = 0.0,
bool autocontinue = true, bool current = false, MAV_FRAME frame=MAV_FRAME_GLOBAL, MAV_CMD action=MAV_CMD_NAV_WAYPOINT, const QString& description=QString(""));
Waypoint(
quint16 id = 0,
double x = 0.0,
double y = 0.0,
double z = 0.0,
double param1 = 0.0,
double param2 = 0.0,
double param3 = 0.0,
double param4 = 0.0,
bool autocontinue = true,
bool current = false,
int frame = MAV_FRAME_GLOBAL,
int action = MAV_CMD_NAV_WAYPOINT,
const QString& description=QString(""));
Waypoint(const Waypoint& other);
~Waypoint();
const Waypoint& operator=(const Waypoint& other);
Q_PROPERTY(double longitude READ longitude NOTIFY longitudeChanged)
Q_PROPERTY(double latitude READ latitude NOTIFY latitudeChanged)
Q_PROPERTY(double altitude READ altitude NOTIFY altitudeChanged)
Q_PROPERTY(quint16 id READ id CONSTANT)
double latitude() { return _x; }
double longitude() { return _y; }
double altitude() { return _z; }
quint16 id() { return _id; }
quint16 getId() const {
return id;
return _id;
}
double getX() const {
return x;
return _x;
}
double getY() const {
return y;
return _y;
}
double getZ() const {
return z;
return _z;
}
double getLatitude() const {
return x;
return _x;
}
double getLongitude() const {
return y;
return _y;
}
double getAltitude() const {
return z;
return _z;
}
double getYaw() const {
return yaw;
return _yaw;
}
bool getAutoContinue() const {
return autocontinue;
return _autocontinue;
}
bool getCurrent() const {
return current;
return _current;
}
double getLoiterOrbit() const {
return orbit;
return _orbit;
}
double getAcceptanceRadius() const {
return param2;
return _param2;
}
double getHoldTime() const {
return param1;
return _param1;
}
double getParam1() const {
return param1;
return _param1;
}
double getParam2() const {
return param2;
return _param2;
}
double getParam3() const {
return orbit;
return _orbit;
}
double getParam4() const {
return yaw;
return _yaw;
}
double getParam5() const {
return x;
return _x;
}
double getParam6() const {
return y;
return _y;
}
double getParam7() const {
return z;
return _z;
}
int getTurns() const {
return param1;
return _param1;
}
MAV_FRAME getFrame() const {
return frame;
// MAV_FRAME
int getFrame() const {
return _frame;
}
MAV_CMD getAction() const {
return action;
// MAV_CMD
int getAction() const {
return _action;
}
const QString& getName() const {
return name;
return _name;
}
const QString& getDescription() const {
return description;
return _description;
}
/** @brief Returns true if x, y, z contain reasonable navigation data */
bool isNavigationType();
/** @brief Get the time this waypoint was reached */
quint64 getReachedTime() const { return _reachedTime; }
void save(QTextStream &saveStream);
bool load(QTextStream &loadStream);
protected:
quint16 id;
double x;
double y;
double z;
double yaw;
MAV_FRAME frame;
MAV_CMD action;
bool autocontinue;
bool current;
double orbit;
double param1;
double param2;
int turns;
QString name;
QString description;
quint64 reachedTime;
public slots:
void setId(quint16 id);
void setX(double x);
void setY(double y);
void setZ(double z);
void setLatitude(double lat);
void setLongitude(double lon);
void setAltitude(double alt);
quint16 _id;
double _x;
double _y;
double _z;
double _yaw;
int _frame;
int _action;
bool _autocontinue;
bool _current;
double _orbit;
double _param1;
double _param2;
int _turns;
QString _name;
QString _description;
quint64 _reachedTime;
public:
void setId (quint16 _id);
void setX (double _x);
void setY (double _y);
void setZ (double _z);
void setLatitude (double lat);
void setLongitude (double lon);
void setAltitude (double alt);
/** @brief Yaw angle in COMPASS DEGREES: 0-360 */
void setYaw(int yaw);
void setYaw (int _yaw);
/** @brief Yaw angle in COMPASS DEGREES: 0-360 */
void setYaw(double yaw);
void setYaw (double _yaw);
/** @brief Set the waypoint action */
void setAction(int action);
void setAction(MAV_CMD action);
void setFrame(MAV_FRAME frame);
void setAction (int _action);
void setFrame (int _frame);
void setAutocontinue(bool autoContinue);
void setCurrent(bool current);
void setLoiterOrbit(double orbit);
void setParam1(double param1);
void setParam2(double param2);
void setParam3(double param3);
void setParam4(double param4);
void setParam5(double param5);
void setParam6(double param6);
void setParam7(double param7);
void setCurrent (bool _current);
void setLoiterOrbit (double _orbit);
void setParam1 (double _param1);
void setParam2 (double _param2);
void setParam3 (double param3);
void setParam4 (double param4);
void setParam5 (double param5);
void setParam6 (double param6);
void setParam7 (double param7);
void setAcceptanceRadius(double radius);
void setHoldTime(int holdTime);
void setHoldTime(double holdTime);
void setHoldTime (int holdTime);
void setHoldTime (double holdTime);
/** @brief Number of turns for loiter waypoints */
void setTurns(int turns);
void setTurns (int _turns);
/** @brief Set waypoint as reached */
void setReached() { reachedTime = QGC::groundTimeMilliseconds(); }
void setReached () { _reachedTime = QGC::groundTimeMilliseconds(); }
/** @brief Wether this waypoint has been reached yet */
bool isReached() { return (reachedTime > 0); }
/** @brief Get the time this waypoint was reached */
quint64 getReachedTime() { return reachedTime; }
bool isReached () { return (_reachedTime > 0); }
void setChanged() {
emit changed(this);
}
signals:
/** @brief Announces a change to the waypoint data */
void changed(Waypoint* wp);
void changed(Waypoint* wp);
void latitudeChanged ();
void longitudeChanged ();
void altitudeChanged ();
};
QML_DECLARE_TYPE(Waypoint)
#endif // WAYPOINT_H
......@@ -417,14 +417,14 @@ void WaypointEditableView::updateValues()
// update frame
MAV_FRAME frame = wp->getFrame();
MAV_FRAME frame = (MAV_FRAME)wp->getFrame();
int frame_index = m_ui->comboBox_frame->findData(frame);
if (m_ui->comboBox_frame->currentIndex() != frame_index) {
m_ui->comboBox_frame->setCurrentIndex(frame_index);
}
// Update action
MAV_CMD action = wp->getAction();
MAV_CMD action = (MAV_CMD)wp->getAction();
int action_index = m_ui->comboBox_action->findData(action);
if (m_ui->comboBox_action->currentIndex() != action_index)
{
......@@ -441,7 +441,7 @@ void WaypointEditableView::updateValues()
}
emit commandBroadcast(wp->getAction());
emit frameBroadcast(wp->getFrame());
emit frameBroadcast((MAV_FRAME)wp->getFrame());
emit param1Broadcast(wp->getParam1());
emit param2Broadcast(wp->getParam2());
emit param3Broadcast(wp->getParam3());
......
This diff is collapsed.
This diff is collapsed.
......@@ -41,120 +41,15 @@ public:
QGCFlightDisplay(QWidget* parent = NULL);
~QGCFlightDisplay();
enum {
ROLL_CHANGED,
PITCH_CHANGED,
HEADING_CHANGED,
GROUNDSPEED_CHANGED,
AIRSPEED_CHANGED,
CLIMBRATE_CHANGED,
ALTITUDERELATIVE_CHANGED,
ALTITUDEWGS84_CHANGED,
ALTITUDEAMSL_CHANGED
};
/// @brief Invokes the Flight Display Options menu
void showOptionsMenu() { emit showOptionsMenuChanged(); }
Q_PROPERTY(float roll READ roll NOTIFY rollChanged)
Q_PROPERTY(float pitch READ pitch NOTIFY pitchChanged)
Q_PROPERTY(float heading READ heading NOTIFY headingChanged)
Q_PROPERTY(float groundSpeed READ groundSpeed NOTIFY groundSpeedChanged)
Q_PROPERTY(float airSpeed READ airSpeed NOTIFY airSpeedChanged)
Q_PROPERTY(float climbRate READ climbRate NOTIFY climbRateChanged)
Q_PROPERTY(float altitudeRelative READ altitudeRelative NOTIFY altitudeRelativeChanged)
Q_PROPERTY(float altitudeWGS84 READ altitudeWGS84 NOTIFY altitudeWGS84Changed)
Q_PROPERTY(float altitudeAMSL READ altitudeAMSL NOTIFY altitudeAMSLChanged)
Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
Q_PROPERTY(float latitude READ latitude NOTIFY latitudeChanged)
Q_PROPERTY(float longitude READ longitude NOTIFY longitudeChanged)
Q_PROPERTY(bool mavPresent READ mavPresent NOTIFY mavPresentChanged)
Q_INVOKABLE void saveSetting (const QString &key, const QString& value);
Q_INVOKABLE QString loadSetting (const QString &key, const QString& defaultValue);
float roll () { return _roll; }
float pitch () { return _pitch; }
float heading () { return _heading; }
float groundSpeed () { return _groundSpeed; }
float airSpeed () { return _airSpeed; }
float climbRate () { return _climbRate; }
float altitudeRelative () { return _altitudeRelative; }
float altitudeWGS84 () { return _altitudeWGS84; }
float altitudeAMSL () { return _altitudeAMSL; }
float latitude () { return _latitude; }
float longitude () { return _longitude; }
bool repaintRequested () { return true; }
bool mavPresent () { return _mav != NULL; }
/** @brief Start updating widget */
void showEvent(QShowEvent* event);
/** @brief Stop updating widget */
void hideEvent(QHideEvent* event);
signals:
void rollChanged ();
void pitchChanged ();
void headingChanged ();
void groundSpeedChanged ();
void airSpeedChanged ();
void climbRateChanged ();
void altitudeRelativeChanged();
void altitudeWGS84Changed ();
void altitudeAMSLChanged ();
void repaintRequestedChanged();
void latitudeChanged ();
void longitudeChanged ();
void mavPresentChanged ();
void showOptionsMenuChanged ();
private slots:
/** @brief Attitude from main autopilot / system state */
void _updateAttitude (UASInterface* uas, double roll, double pitch, double yaw, quint64 timestamp);
/** @brief Attitude from one specific component / redundant autopilot */
void _updateAttitude (UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 timestamp);
/** @brief Speed */
void _updateSpeed (UASInterface* uas, double _groundSpeed, double _airSpeed, quint64 timestamp);
/** @brief Altitude */
void _updateAltitude (UASInterface* uas, double _altitudeAMSL, double _altitudeWGS84, double _altitudeRelative, double _climbRate, quint64 timestamp);
void _updateNavigationControllerErrors (UASInterface* uas, double altitudeError, double speedError, double xtrackError);
void _updateNavigationControllerData (UASInterface *uas, float navRoll, float navPitch, float navBearing, float targetBearing, float targetDistance);
void _forgetUAS (UASInterface* uas);
void _setActiveUAS (UASInterface* uas);
void _checkUpdate ();
private:
bool _isAirplane ();
bool _shouldDisplayNavigationData ();
void _addChange (int id);
float _oneDecimal (float value);
private:
UASInterface* _mav;
float _roll;
float _pitch;
float _heading;
float _altitudeAMSL;
float _altitudeWGS84;
float _altitudeRelative;
float _groundSpeed;
float _airSpeed;
float _climbRate;
float _navigationAltitudeError;
float _navigationSpeedError;
float _navigationCrosstrackError;
float _navigationTargetBearing;
float _latitude;
float _longitude;
QTimer* _refreshTimer;
QList<int> _changes;
};
#endif // QGCFLIGHTDISPLAY_H
......@@ -45,56 +45,6 @@ Rectangle {
property real pitch: isNaN(mapEngine.pitch) ? 0 : mapEngine.pitch
property bool showWaypointEditor: true
function getBool(value) {
return value === '0' ? false : true;
}
function setBool(value) {
return value ? "1" : "0";
}
Component.onCompleted:
{
mapTypeMenu.update();
}
Menu {
id: mapTypeMenu
title: "Map Type..."
ExclusiveGroup { id: currentMapType }
function setCurrentMap(map) {
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
if (map === mapBackground.mapItem.supportedMapTypes[i].name) {
mapBackground.mapItem.activeMapType = mapBackground.mapItem.supportedMapTypes[i]
mapEngine.saveSetting("currentMapType", map);
return;
}
}
}
function addMap(map, checked) {
var mItem = mapTypeMenu.addItem(map);
mItem.checkable = true
mItem.checked = checked
mItem.exclusiveGroup = currentMapType
var menuSlot = function() {setCurrentMap(map);};
mItem.triggered.connect(menuSlot);
}
function update() {
clear()
var map = ''
if (mapBackground.mapItem.supportedMapTypes.length > 0)
map = mapBackground.mapItem.activeMapType.name;
map = mapEngine.loadSetting("currentMapType", map);
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
var name = mapBackground.mapItem.supportedMapTypes[i].name;
addMap(name, map === name);
}
if(map != '')
setCurrentMap(map);
}
}
SplitView {
id: splitView
anchors.fill: parent
......@@ -117,6 +67,9 @@ Rectangle {
heading: isNaN(mapEngine.heading) ? 0 : mapEngine.heading
latitude: 37.803784 // mapEngine.latitude
longitude: -122.462276 // mapEngine.longitude
showWaypoints: true
mapName: 'MainMapDisplay'
// Chevron button at upper right corner of Map Display
Item {
id: openWaypoints
......@@ -164,7 +117,7 @@ Rectangle {
onClicked: {
if (mouse.button == Qt.RightButton)
{
mapTypeMenu.popup()
mapBackground.mapMenu.popup()
}
}
z: splitView.z + 5
......
......@@ -28,25 +28,73 @@ This file is part of the QGROUNDCONTROL project
*/
import QtQuick 2.4
import QtPositioning 5.3
import QtQuick.Controls 1.3
import QtLocation 5.3
import QtPositioning 5.3
import QGroundControl.Controls 1.0
import QGroundControl.FlightControls 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.MavManager 1.0
Item {
id: root
clip: true
Rectangle {
id: root
property real latitude: 37.803784
property real longitude : -122.462276
property real zoomLevel: 18
property real heading: 0
property bool alwaysNorth: true
property bool interactive: true
property alias mapItem: map
property real latitude: 0
property real longitude: 0
property real zoomLevel: 18
property real heading: 0
property bool alwaysNorth: true
property bool interactive: true
property bool showWaypoints: false
property string mapName: 'defaultMap'
property alias mapItem: map
property alias waypoints: polyLine
property alias mapMenu: mapTypeMenu
Component.onCompleted: {
map.zoomLevel = 18
map.markers = []
mapTypeMenu.update();
}
color: Qt.rgba(0,0,0,0)
clip: true
//-- Menu to select supported map types
Menu {
id: mapTypeMenu
title: "Map Type..."
ExclusiveGroup { id: currMapType }
function setCurrentMap(mapID) {
for (var i = 0; i < map.supportedMapTypes.length; i++) {
if (mapID === map.supportedMapTypes[i].name) {
map.activeMapType = map.supportedMapTypes[i]
MavManager.saveSetting(root.mapName + "/currentMapType", mapID);
return;
}
}
}
function addMap(mapID, checked) {
var mItem = mapTypeMenu.addItem(mapID);
mItem.checkable = true
mItem.checked = checked
mItem.exclusiveGroup = currMapType
var menuSlot = function() {setCurrentMap(mapID);};
mItem.triggered.connect(menuSlot);
}
function update() {
clear()
var mapID = ''
if (map.supportedMapTypes.length > 0)
mapID = map.activeMapType.name;
mapID = MavManager.loadSetting(root.mapName + "/currentMapType", mapID);
for (var i = 0; i < map.supportedMapTypes.length; i++) {
var name = map.supportedMapTypes[i].name;
addMap(name, mapID === name);
}
if(mapID != '')
setCurrentMap(mapID);
}
}
function adjustSize() {
if(root.visible) {
......@@ -83,34 +131,65 @@ Rectangle {
return dist
}
function updateWaypoints() {
polyLine.path = []
// Are we initialized?
if (typeof map.markers != 'undefined' && typeof root.longitude != 'undefined') {
map.deleteMarkers()
if(root.showWaypoints) {
for(var i = 0; i < MavManager.waypoints.length; i++) {
var coord = QtPositioning.coordinate(MavManager.waypoints[i].latitude, MavManager.waypoints[i].longitude, MavManager.waypoints[i].altitude);
polyLine.addCoordinate(coord);
map.addMarker(coord, MavManager.waypoints[i].id);
}
root.longitude = MavManager.waypoints[0].longitude
root.latitude = MavManager.waypoints[0].latitude
}
}
}
Plugin {
id: mapPlugin
name: "QGroundControl"
}