Skip to content

Commit

Permalink
The 3D View settings are moved to Fly View settings, and a 3D view en…
Browse files Browse the repository at this point in the history
…abled switch is added
  • Loading branch information
omid-esrafilian authored and DonLakeFlyer committed Feb 25, 2024
1 parent 1418ef9 commit fb32624
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 156 deletions.
1 change: 0 additions & 1 deletion qgcimages.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
<file alias="Yield.svg">src/ui/toolbar/Images/Yield.svg</file>
<file alias="ZoomMinus.svg">src/FlightMap/Images/ZoomMinus.svg</file>
<file alias="ZoomPlus.svg">src/FlightMap/Images/ZoomPlus.svg</file>
<file alias="Viewer3D/GearIcon.png">src/Viewer3D/Images/gear_icon.png</file>
<file alias="Viewer3D/City3DMapIcon.svg">src/Viewer3D/Images/city_3d_map_icon.svg</file>
</qresource>
</RCC>
1 change: 0 additions & 1 deletion qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@
<file alias="VirtualJoystick.qml">src/FlightDisplay/VirtualJoystick.qml</file>
<file alias="VTOLLandingPatternEditor.qml">src/PlanView/VTOLLandingPatternEditor.qml</file>
<file alias="QGroundControl/FlightDisplay/FlyViewInsetViewer.qml">src/FlightDisplay/FlyViewInsetViewer.qml</file>
<file alias="Viewer3D/Viewer3DSettingsDialog.qml">src/Viewer3D/Viewer3D/Viewer3DSettingsDialog.qml</file>
<file alias="Viewer3D/Viewer3D.qml">src/Viewer3D/Viewer3D/Viewer3D.qml</file>
<file alias="Viewer3D/qmldir">src/Viewer3D/Viewer3D/qmldir</file>
<file alias="Viewer3D/Models3D/CameraLightModel.qml">src/Viewer3D/Viewer3D/Models3D/CameraLightModel.qml</file>
Expand Down
46 changes: 18 additions & 28 deletions src/FlightDisplay/FlyViewToolStripActionList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,41 @@ ToolStripActionList {
id: _root

signal displayPreFlightChecklist
property bool _viewer3DEnabled: QGroundControl.settingsManager.viewer3DSettings.enabled.rawValue

model: [
ToolStripAction {
text: qsTr("Plan")
iconSource: "/qmlimages/Plan.svg"
onTriggered:{
mainWindow.showPlanView()
map_icon.showFlyMap()
mapIcon.showFlyMap()
}
},
ToolStripAction {
id: map_icon
property bool _is3DViewOpen: viewer3DWindow.isOpen

id: mapIcon
visible: _viewer3DEnabled
text: qsTr("3D View")
iconSource: "/qmlimages/Viewer3D/City3DMapIcon.svg"
onTriggered:{
if(viewer3DWindow.isOpen === false){
show3dMap();
if(_is3DViewOpen === false){
viewer3DWindow.open()
}else{
showFlyMap();
viewer3DWindow.close()
}
}

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

function showFlyMap(){
viewer3DWindow.close()
iconSource = "/qmlimages/Viewer3D/City3DMapIcon.svg"
text = qsTr("3D View")
city_map_setting_icon.enabled = false
city_map_setting_icon.checked = false
}
},
ToolStripAction {
id: city_map_setting_icon
text: qsTr("Setting")
iconSource: "/qmlimages/Viewer3D/GearIcon.png"
enabled: false
visible: enabled
onTriggered:{
viewer3DWindow.showSettingsDialog()
on_Is3DViewOpenChanged: {
if(_is3DViewOpen === true){
mapIcon.iconSource = "/qmlimages/PaperPlane.svg"
text= qsTr("Fly")
}else{
viewer3DWindow.close()
iconSource = "/qmlimages/Viewer3D/City3DMapIcon.svg"
text = qsTr("3D View")
}
}
},
PreFlightCheckListShowAction { onTriggered: displayPreFlightChecklist() },
Expand Down
6 changes: 6 additions & 0 deletions src/Settings/Viewer3D.SettingsGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"fileType": "FactMetaData",
"QGC.MetaData.Facts":
[
{
"name": "enabled",
"shortDesc": "Enable the 3D viewer",
"type": "bool",
"default": false
},
{
"name": "osmFilePath",
"shortDesc": "Path to the OSM file for the 3D viewer.",
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Viewer3DSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DECLARE_SETTINGGROUP(Viewer3D, "Viewer3D")
qmlRegisterUncreatableType<Viewer3DSettings>("QGroundControl.SettingsManager", 1, 0, "Viewer3DSettings", "Reference only");
}

DECLARE_SETTINGSFACT(Viewer3DSettings, enabled)
DECLARE_SETTINGSFACT(Viewer3DSettings, osmFilePath)
DECLARE_SETTINGSFACT(Viewer3DSettings, buildingLevelHeight)
DECLARE_SETTINGSFACT(Viewer3DSettings, altitudeBias)
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Viewer3DSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Viewer3DSettings : public SettingsGroup

DEFINE_SETTING_NAME_GROUP()

DEFINE_SETTINGFACT(enabled)
DEFINE_SETTINGFACT(osmFilePath)
DEFINE_SETTINGFACT(buildingLevelHeight)
DEFINE_SETTINGFACT(altitudeBias)
Expand Down
8 changes: 8 additions & 0 deletions src/Viewer3D/CityMapGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void CityMapGeometry::setOsmFilePath(QVariant value)
return;
}

clearViewer();
_mapLoadedFlag = 0;
_osmFilePath = value.toString();
emit osmFilePathChanged();
Expand Down Expand Up @@ -90,3 +91,10 @@ void CityMapGeometry::updateViewer()
update();
}
}

void CityMapGeometry::clearViewer()
{
clear();
_vertexData.clear();
update();
}
1 change: 1 addition & 0 deletions src/Viewer3D/CityMapGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CityMapGeometry : public QQuick3DGeometry

private:
void updateViewer();
void clearViewer();

QString _modelName;
QString _osmFilePath;
Expand Down
Binary file removed src/Viewer3D/Images/gear_icon.png
Binary file not shown.
29 changes: 23 additions & 6 deletions src/Viewer3D/OsmParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OsmParser::OsmParser(QObject *parent)
_viewer3DSettings = qgcApp()->toolbox()->settingsManager()->viewer3DSettings();

_gpsRefSet = false;
_mapLoadedFlag = false;

setBuildingLevelHeight(_viewer3DSettings->buildingLevelHeight()->rawValue()); // meters
connect(_viewer3DSettings->buildingLevelHeight(), &Fact::rawValueChanged, this, &OsmParser::setBuildingLevelHeight);
Expand All @@ -32,7 +33,14 @@ void OsmParser::setGpsRef(QGeoCoordinate gpsRef)
{
_gpsRefPoint = gpsRef;
_gpsRefSet = true;
emit gpsRefChanged(_gpsRefPoint);
emit gpsRefChanged(_gpsRefPoint, _gpsRefSet);
}

void OsmParser::resetGpsRef()
{
_gpsRefPoint = QGeoCoordinate(0, 0, 0);
_gpsRefSet = false;
emit gpsRefChanged(_gpsRefPoint, _gpsRefSet);
}

void OsmParser::setBuildingLevelHeight(QVariant value)
Expand All @@ -43,6 +51,20 @@ void OsmParser::setBuildingLevelHeight(QVariant value)

void OsmParser::parseOsmFile(QString filePath)
{
if(filePath == "Please select an OSM file"){
if(_mapLoadedFlag){
qDebug("The 3D View has been cleared!");
_mapNodes.clear();
_mapBuildings.clear();
_gpsRefSet = false;
_mapLoadedFlag = false;
resetGpsRef();
}else{
qDebug("No OSM File is selected!");
}
return;
}

//The QDomDocument class represents an XML document.
QDomDocument xml_content;
// Load xml file as raw data
Expand All @@ -65,11 +87,6 @@ void OsmParser::parseOsmFile(QString filePath)

QDomElement component = root.firstChild().toElement();

_mapNodes.clear();
_mapBuildings.clear();
_gpsRefSet = false;
_mapLoadedFlag = false;

while(!component.isNull()) {
decodeNodeTags(component, _mapNodes);
decodeBuildings(component, _mapBuildings, _mapNodes, _gpsRefPoint);
Expand Down
3 changes: 2 additions & 1 deletion src/Viewer3D/OsmParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class OsmParser : public QObject
explicit OsmParser(QObject *parent = nullptr);

void setGpsRef(QGeoCoordinate gpsRef);
void resetGpsRef();
QGeoCoordinate getGpsRef(){ return _gpsRefPoint;}

float buildingLevelHeight(void){return _buildingLevelHeight;}
Expand All @@ -59,7 +60,7 @@ class OsmParser : public QObject


signals:
void gpsRefChanged(QGeoCoordinate newGpsRef);
void gpsRefChanged(QGeoCoordinate newGpsRef, bool isRefSet);
void mapChanged();
void buildingLevelHeightChanged(void);

Expand Down
16 changes: 16 additions & 0 deletions src/Viewer3D/Viewer3D/Models3D/CameraLightModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ Node {
property real _pan: 0.001
property real _zoom: 1500

function resetCamera(){
camNode.position = Qt.vector3d(0, 0, 0);
camNode.eulerRotation = Qt.vector3d(90, 0, 0);

cameraPerspectiveThree.position = Qt.vector3d(0, 0, 0);
cameraPerspectiveThree.eulerRotation = Qt.vector3d(0, 0, 0);

cameraPerspectiveTwo.position = Qt.vector3d(_zoom * Math.sin(_tilt) * Math.cos(_pan),
_zoom * Math.cos(_tilt),
_zoom * Math.sin(_tilt) * Math.sin(_pan));
cameraPerspectiveTwo.eulerRotation = Qt.vector3d(0, 0, 0);

cameraPerspectiveOne.position = Qt.vector3d(0, 0, 0);
cameraPerspectiveOne.eulerRotation = Qt.vector3d(-90, 0, 0);
}


DirectionalLight {
eulerRotation.x: 180
Expand Down
5 changes: 5 additions & 0 deletions src/Viewer3D/Viewer3D/Models3D/Viewer3DModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import QGroundControl.Vehicle
View3D {
id: topView
property var viewer3DManager: null
readonly property var _gpsRef: viewer3DManager.qmlBackend.gpsRef
property bool isViewer3DOpen: false
property real rotationSpeed: 0.1
property real movementSpeed: 1
Expand Down Expand Up @@ -70,6 +71,10 @@ View3D {
standAloneScene.cameraTwoPosition.z += dz
}

on_GpsRefChanged:{
standAloneScene.resetCamera();
}

camera: standAloneScene.cameraOne
importScene: CameraLightModel{
id: standAloneScene
Expand Down
31 changes: 16 additions & 15 deletions src/Viewer3D/Viewer3D/Viewer3D.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts

import QGroundControl
import QGroundControl.Palette
import QGroundControl.ScreenTools
import QGroundControl.Controls
Expand All @@ -16,20 +17,29 @@ import Viewer3D.Models3D
Item{
id: viewer3DBody
property bool isOpen: false
property bool _viewer3DEnabled: QGroundControl.settingsManager.viewer3DSettings.enabled.rawValue


function open(){
view3DManagerLoader.sourceComponent = viewer3DManagerComponent
viewer3DBody.z = 1
isOpen = true;
if(_viewer3DEnabled === true){
view3DManagerLoader.sourceComponent = viewer3DManagerComponent
view3DManagerLoader.active = true;
viewer3DBody.z = 1
isOpen = true;
}
}

function close(){
viewer3DBody.z = 0
isOpen = false;
}

function showSettingsDialog(){
settingsDialogComponent.createObject(mainWindow).open()
on_Viewer3DEnabledChanged: {
if(_viewer3DEnabled === false){
viewer3DBody.close();
view3DLoader.active = false;
view3DManagerLoader.active = false;
}
}

Component{
Expand All @@ -45,6 +55,7 @@ Item{

onLoaded: {
view3DLoader.source = "Models3D/Viewer3DModel.qml"
view3DLoader.active = true;
}
}

Expand All @@ -63,14 +74,4 @@ Item{
value: isOpen
when: view3DLoader.status == Loader.Ready
}

Component {
id: settingsDialogComponent

Viewer3DSettingsDialog{
id: view3DSettingsDialog
viewer3DManager: view3DManagerLoader.item
visible: true
}
}
}
Loading

0 comments on commit fb32624

Please sign in to comment.