Skip to content

Commit

Permalink
adding Viewr3DSettings to SettingsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
omid-esrafilian authored and DonLakeFlyer committed Feb 25, 2024
1 parent 4c4ddfc commit 1418ef9
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 145 deletions.
1 change: 1 addition & 0 deletions src/FlightDisplay/FlyView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Item {
pipMode: !_mainWindowIsMap
toolInsets: customOverlay.totalToolInsets
mapName: "FlightDisplayView"
enabled: !viewer3DWindow.isOpen
}

FlyViewVideo {
Expand Down
20 changes: 7 additions & 13 deletions src/FlightDisplay/FlyViewToolStripActionList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,25 @@ ToolStripActionList {
text: qsTr("3D View")
iconSource: "/qmlimages/Viewer3D/City3DMapIcon.svg"
onTriggered:{
if(viewer3DWindow.viewer3DOpen === false)
{
if(viewer3DWindow.isOpen === false){
show3dMap();
}
else
{
}else{
showFlyMap();
}
}

function show3dMap()
{
viewer3DWindow.viewer3DOpen = true
function show3dMap(){
viewer3DWindow.open()
map_icon.iconSource = "/qmlimages/PaperPlane.svg"
text= qsTr("Fly")
city_map_setting_icon.enabled = true
}

function showFlyMap()
{
viewer3DWindow.viewer3DOpen = false
function showFlyMap(){
viewer3DWindow.close()
iconSource = "/qmlimages/Viewer3D/City3DMapIcon.svg"
text = qsTr("3D View")
city_map_setting_icon.enabled = false
viewer3DWindow.settingsDialogOpen = false
city_map_setting_icon.checked = false
}
},
Expand All @@ -66,7 +60,7 @@ ToolStripActionList {
enabled: false
visible: enabled
onTriggered:{
viewer3DWindow.settingsDialogOpen = !viewer3DWindow.settingsDialogOpen
viewer3DWindow.showSettingsDialog()
}
},
PreFlightCheckListShowAction { onTriggered: displayPreFlightChecklist() },
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/SettingsManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SettingsManager::SettingsManager(QGCApplication* app, QGCToolbox* toolbox)
, _adsbVehicleManagerSettings (nullptr)
, _batteryIndicatorSettings (nullptr)
, _mapsSettings (nullptr)
, _viewer3DSettings (nullptr)
#if !defined(NO_ARDUPILOT_DIALECT)
, _apmMavlinkStreamRateSettings (nullptr)
#endif
Expand Down Expand Up @@ -58,6 +59,7 @@ void SettingsManager::setToolbox(QGCToolbox *toolbox)
_adsbVehicleManagerSettings = new ADSBVehicleManagerSettings (this);
_batteryIndicatorSettings = new BatteryIndicatorSettings (this);
_mapsSettings = new MapsSettings (this);
_viewer3DSettings = new Viewer3DSettings (this);
#if !defined(NO_ARDUPILOT_DIALECT)
_apmMavlinkStreamRateSettings = new APMMavlinkStreamRateSettings(this);
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/Settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "BatteryIndicatorSettings.h"
#include <QVariantList>
#include "RemoteIDSettings.h"
#include "Viewer3DSettings.h"

/// Provides access to all app settings
class SettingsManager : public QGCTool
Expand All @@ -56,6 +57,7 @@ class SettingsManager : public QGCTool
Q_PROPERTY(QObject* adsbVehicleManagerSettings READ adsbVehicleManagerSettings CONSTANT)
Q_PROPERTY(QObject* batteryIndicatorSettings READ batteryIndicatorSettings CONSTANT)
Q_PROPERTY(QObject* mapsSettings READ mapsSettings CONSTANT)
Q_PROPERTY(QObject* viewer3DSettings READ viewer3DSettings CONSTANT)
#if !defined(NO_ARDUPILOT_DIALECT)
Q_PROPERTY(QObject* apmMavlinkStreamRateSettings READ apmMavlinkStreamRateSettings CONSTANT)
#endif
Expand All @@ -78,6 +80,7 @@ class SettingsManager : public QGCTool
ADSBVehicleManagerSettings* adsbVehicleManagerSettings (void) { return _adsbVehicleManagerSettings; }
BatteryIndicatorSettings* batteryIndicatorSettings (void) { return _batteryIndicatorSettings; }
MapsSettings* mapsSettings (void) { return _mapsSettings; }
Viewer3DSettings* viewer3DSettings (void) { return _viewer3DSettings; }
#if !defined(NO_ARDUPILOT_DIALECT)
APMMavlinkStreamRateSettings* apmMavlinkStreamRateSettings(void) { return _apmMavlinkStreamRateSettings; }
#endif
Expand All @@ -98,6 +101,7 @@ class SettingsManager : public QGCTool
ADSBVehicleManagerSettings* _adsbVehicleManagerSettings;
BatteryIndicatorSettings* _batteryIndicatorSettings;
MapsSettings* _mapsSettings;
Viewer3DSettings* _viewer3DSettings;
#if !defined(NO_ARDUPILOT_DIALECT)
APMMavlinkStreamRateSettings* _apmMavlinkStreamRateSettings;
#endif
Expand Down
14 changes: 11 additions & 3 deletions src/Viewer3D/CityMapGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

#include<QThread>

#include "QGCApplication.h"
#include "SettingsManager.h"


CityMapGeometry::CityMapGeometry()
{
_osmParser = nullptr;
_modelName = "city_map_defualt_name";
_vertexData.clear();
_mapLoadedFlag = 0;

_viewer3DSettings = qgcApp()->toolbox()->settingsManager()->viewer3DSettings();

setOsmFilePath(_viewer3DSettings->osmFilePath()->rawValue());
connect(_viewer3DSettings->osmFilePath(), &Fact::rawValueChanged, this, &CityMapGeometry::setOsmFilePath);
}

void CityMapGeometry::setModelName(QString modelName)
Expand All @@ -19,14 +27,14 @@ void CityMapGeometry::setModelName(QString modelName)
emit modelNameChanged();
}

void CityMapGeometry::setOsmFilePath(QString filePath)
void CityMapGeometry::setOsmFilePath(QVariant value)
{
if(_osmFilePath.compare(filePath) == 0){
if(_osmFilePath.compare(value.toString()) == 0){
return;
}

_mapLoadedFlag = 0;
_osmFilePath = filePath;
_osmFilePath = value.toString();
emit osmFilePathChanged();
loadOsmMap();
}
Expand Down
10 changes: 8 additions & 2 deletions src/Viewer3D/CityMapGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

/// @author Omid Esrafilian <[email protected]>

class Viewer3DSettings;

class CityMapGeometry : public QQuick3DGeometry
{
Q_OBJECT
Q_PROPERTY(QString modelName READ modelName WRITE setModelName NOTIFY modelNameChanged)
Q_PROPERTY(QString osmFilePath READ osmFilePath WRITE setOsmFilePath NOTIFY osmFilePathChanged)
Q_PROPERTY(OsmParser* osmParser READ osmParser WRITE setOsmParser NOTIFY osmParserChanged)

public:
Expand All @@ -24,7 +25,6 @@ class CityMapGeometry : public QQuick3DGeometry
void setModelName(QString modelName);

QString osmFilePath() const {return _osmFilePath;}
void setOsmFilePath(QString filePath);

OsmParser* osmParser(){ return _osmParser;}
void setOsmParser(OsmParser* newOsmParser);
Expand All @@ -44,6 +44,12 @@ class CityMapGeometry : public QQuick3DGeometry
QByteArray _vertexData;
OsmParser *_osmParser;
bool _mapLoadedFlag;
Viewer3DSettings* _viewer3DSettings = nullptr;

private slots:
void setOsmFilePath(QVariant value);


};

#endif // CITYMAPGEOMETRY_H
22 changes: 15 additions & 7 deletions src/Viewer3D/OsmParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "earcut.hpp"
#include "Viewer3DUtils.h"

#include "QGCApplication.h"
#include "SettingsManager.h"

typedef union {
uint array[3];
Expand All @@ -19,11 +20,12 @@ typedef union {
OsmParser::OsmParser(QObject *parent)
: QObject{parent}
{
_mainThread = new QThread(this);
_viewer3DSettings = qgcApp()->toolbox()->settingsManager()->viewer3DSettings();

this->moveToThread(_mainThread);
_gpsRefSet = false;
_buildingLevelHeight = 0; // meters

setBuildingLevelHeight(_viewer3DSettings->buildingLevelHeight()->rawValue()); // meters
connect(_viewer3DSettings->buildingLevelHeight(), &Fact::rawValueChanged, this, &OsmParser::setBuildingLevelHeight);
}

void OsmParser::setGpsRef(QGeoCoordinate gpsRef)
Expand All @@ -33,6 +35,12 @@ void OsmParser::setGpsRef(QGeoCoordinate gpsRef)
emit gpsRefChanged(_gpsRefPoint);
}

void OsmParser::setBuildingLevelHeight(QVariant value)
{
_buildingLevelHeight = value.toFloat();
emit buildingLevelHeightChanged();
}

void OsmParser::parseOsmFile(QString filePath)
{
//The QDomDocument class represents an XML document.
Expand Down Expand Up @@ -151,8 +159,8 @@ void OsmParser::decodeBuildings(QDomElement &xmlComponent, QMap<uint64_t, Buildi
}

if(bld_points.size() > 2 && (bld_tmp.height > 0 || bld_tmp.levels > 0)) {
// float bld_height = (bld_tmp.height >= bld_tmp.levels * _buildingLevelHeight)?(bld_tmp.height):(bld_tmp.levels * _buildingLevelHeight);
// bld_tmp.height = bld_height;
// float bld_height = (bld_tmp.height >= bld_tmp.levels * _buildingLevelHeight)?(bld_tmp.height):(bld_tmp.levels * _buildingLevelHeight);
// bld_tmp.height = bld_height;
bld_tmp.points_gps = bld_points;
bld_tmp.points_local = bld_points_local;
bld_tmp.bb_max = QVector2D(bld_x_max, bld_y_max);
Expand All @@ -172,7 +180,7 @@ QByteArray OsmParser::buildingToMesh()
std::vector<std::vector<std::array<float, 2> > > polygon;
std::vector<QVector3D> triangulated_mesh;

// bld_height = (ii.value().height >= ii.value().levels * _buildingLevelHeight)?(ii.value().height):(ii.value().levels * _buildingLevelHeight);
// bld_height = (ii.value().height >= ii.value().levels * _buildingLevelHeight)?(ii.value().height):(ii.value().levels * _buildingLevelHeight);

if(ii.value().height > 0){
bld_height = ii.value().height;
Expand Down
12 changes: 9 additions & 3 deletions src/Viewer3D/OsmParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <QVector3D>
#include <QVector2D>
#include "qgeocoordinate.h"
#include <QVariant>

/// @author Omid Esrafilian <[email protected]>

class Viewer3DSettings;

class OsmParser : public QObject
{
struct BuildingType
Expand All @@ -26,14 +29,14 @@ class OsmParser : public QObject

Q_OBJECT

Q_PROPERTY(float buildingLevelHeight READ buildingLevelHeight WRITE setBuildingLevelHeight NOTIFY buildingLevelHeightChanged)
// Q_PROPERTY(float buildingLevelHeight READ buildingLevelHeight WRITE setBuildingLevelHeight NOTIFY buildingLevelHeightChanged)

public:
explicit OsmParser(QObject *parent = nullptr);

void setGpsRef(QGeoCoordinate gpsRef);
QGeoCoordinate getGpsRef(){ return _gpsRefPoint;}
void setBuildingLevelHeight(float levelHeight){_buildingLevelHeight = levelHeight; emit buildingLevelHeightChanged();}

float buildingLevelHeight(void){return _buildingLevelHeight;}
void parseOsmFile(QString filePath);
void decodeNodeTags(QDomElement& xmlComponent, QMap<uint64_t, QGeoCoordinate> &nodeMap);
Expand All @@ -45,21 +48,24 @@ class OsmParser : public QObject
void trianglateRectangle(std::vector<QVector3D>& triangulatedMesh, std::vector<QVector3D> verticesCcw, bool invertNormal);

private:
QThread* _mainThread;
QGeoCoordinate _gpsRefPoint;
QMap<uint64_t, QGeoCoordinate> _mapNodes;
QMap<uint64_t, BuildingType> _mapBuildings;

bool _gpsRefSet;
float _buildingLevelHeight;
bool _mapLoadedFlag;
Viewer3DSettings* _viewer3DSettings = nullptr;


signals:
void gpsRefChanged(QGeoCoordinate newGpsRef);
void mapChanged();
void buildingLevelHeightChanged(void);

private slots:
void setBuildingLevelHeight(QVariant value);

};

#endif // OSMPARSER_H
11 changes: 5 additions & 6 deletions src/Viewer3D/Viewer3D/Models3D/Viewer3DModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import QGroundControl.Vehicle
View3D {
id: topView
property var viewer3DManager: null
property bool viewer3DOpen: false
property bool isViewer3DOpen: false
property real rotationSpeed: 0.1
property real movementSpeed: 1
property real zoomSpeed: 0.3
Expand Down Expand Up @@ -89,7 +89,6 @@ View3D {
geometry: CityMapGeometry {
id: cityMapGeometry
modelName: "city_map"
osmFilePath: (viewer3DManager)?(viewer3DManager.qmlBackend.osmFilePath):("nan")
osmParser: (viewer3DManager)?(viewer3DManager.osmParser):(null)
}

Expand Down Expand Up @@ -133,7 +132,7 @@ View3D {
target: null
acceptedModifiers: Qt.NoModifier
acceptedButtons: Qt.LeftButton
enabled: viewer3DOpen
enabled: isViewer3DOpen

onCentroidChanged: {
if(_isMoving){
Expand Down Expand Up @@ -161,7 +160,7 @@ View3D {
acceptedModifiers: Qt.NoModifier
acceptedButtons: Qt.RightButton
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
enabled: viewer3DOpen
enabled: isViewer3DOpen

onCentroidChanged: {
if(_isRotating){
Expand All @@ -187,7 +186,7 @@ View3D {
property bool _isRotating: false
property point _lastPose;
property real _lastZoomValue;
enabled: viewer3DOpen
enabled: isViewer3DOpen

onCentroidChanged: {
if(_isRotating){
Expand Down Expand Up @@ -217,7 +216,7 @@ View3D {
orientation: Qt.Vertical
target: null
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
enabled: viewer3DOpen
enabled: isViewer3DOpen

onWheel: event => {
zoomCamera(-event.angleDelta.y)
Expand Down
11 changes: 7 additions & 4 deletions src/Viewer3D/Viewer3D/Models3D/Viewer3DVehicleItems.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Node {
property var _vehicle: null
property var _planMasterController: null
property var _missionController: (_planMasterController)?(_planMasterController.missionController):(null)
property var _viewer3DSetting: QGroundControl.settingsManager.viewer3DSettings
property var _altitudeBias: _viewer3DSetting.altitudeBias.rawValue


function addMissionItemsToListModel() {
missionWaypointListModel.clear()
Expand Down Expand Up @@ -85,7 +88,7 @@ Node {
id: droneDji3DModel
vehicle: _vehicle
modelScale: Qt.vector3d(0.05, 0.05, 0.05)
altitudeBias: _backendQml.altitudeBias
altitudeBias: _altitudeBias
gpsRef: _backendQml.gpsRef
}

Expand All @@ -96,7 +99,7 @@ Node {
delegate: Waypoint3DModel{
opacity: 0.8
missionItem: model
altitudeBias: _backendQml.altitudeBias
altitudeBias: _altitudeBias
}
}

Expand All @@ -105,8 +108,8 @@ Node {
model: missionPathModel

delegate: Line3D{
p_1: Qt.vector3d(model.x_1 * 10, model.y_1 * 10, (model.z_1 + _backendQml.altitudeBias) * 10)
p_2: Qt.vector3d(model.x_2 * 10, model.y_2 * 10, (model.z_2 + _backendQml.altitudeBias) * 10)
p_1: Qt.vector3d(model.x_1 * 10, model.y_1 * 10, (model.z_1 + _altitudeBias) * 10)
p_2: Qt.vector3d(model.x_2 * 10, model.y_2 * 10, (model.z_2 + _altitudeBias) * 10)
lineWidth:8
color: "orange"
}
Expand Down
Loading

0 comments on commit 1418ef9

Please sign in to comment.