From 0db3daafb9d4f439293e649277dfd8fd72b6a4fe Mon Sep 17 00:00:00 2001 From: uclaros Date: Sun, 27 Oct 2024 20:59:07 +0200 Subject: [PATCH] Tidy up tiled scene layer 3d identify results --- src/3d/qgstiledscenechunkloader_p.cpp | 8 ++-- src/app/3d/qgs3dmaptoolidentify.cpp | 60 ++++++++++++++------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/3d/qgstiledscenechunkloader_p.cpp b/src/3d/qgstiledscenechunkloader_p.cpp index 8ccdc5773512..67ae246117dc 100644 --- a/src/3d/qgstiledscenechunkloader_p.cpp +++ b/src/3d/qgstiledscenechunkloader_p.cpp @@ -412,10 +412,10 @@ QVector QgsTiledSceneLayerChunkedEntity::rayIntersec QVariantMap vm; QgsTiledSceneTile tile = mIndex.getTile( minNode->tileId().uniqueId ); // at this point this is mostly for debugging - we may want to change/rename what's returned here - vm["node_id"] = tile.id(); - vm["node_error"] = tile.geometricError(); - vm["node_content"] = tile.resources().value( QStringLiteral( "content" ) ); - vm["triangle_index"] = minTriangleIndex; + vm[ QStringLiteral( "node_id" ) ] = tile.id(); + vm[ QStringLiteral( "node_error" ) ] = tile.geometricError(); + vm[ QStringLiteral( "node_content" ) ] = tile.resources().value( QStringLiteral( "content" ) ); + vm[ QStringLiteral( "triangle_index" ) ] = minTriangleIndex; QgsRayCastingUtils::RayHit hit( minDist, intersectionPoint, FID_NULL, vm ); result.append( hit ); } diff --git a/src/app/3d/qgs3dmaptoolidentify.cpp b/src/app/3d/qgs3dmaptoolidentify.cpp index e65d1dae21af..920ec48bfb68 100644 --- a/src/app/3d/qgs3dmaptoolidentify.cpp +++ b/src/app/3d/qgs3dmaptoolidentify.cpp @@ -25,6 +25,7 @@ #include "qgisapp.h" #include "qgsmapcanvas.h" +#include "qgscoordinateutils.h" #include "qgsmaptoolidentifyaction.h" #include "qgspointcloudlayer.h" @@ -64,9 +65,8 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) QHash> allHits = Qgs3DUtils::castRay( mCanvas->scene(), ray, QgsRayCastingUtils::RayCastContext( false, mCanvas->size(), mCanvas->cameraController()->camera()->farPlane() ) ); QHash> pointCloudResults; - QHash> tiledSceneResults; - QList identifyResults; + QList pointCloudIdentifyResults; QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool(); identifyTool2D->clearResults(); @@ -83,7 +83,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) identifyTool2D->showResultsForFeature( vlayer, hit.fid, pt ); showTerrainResults = false; } - // We need to restructure point cloud layer results to display them later + // We need to restructure point cloud layer results to display them later. We may have multiple hits for each layer. else if ( QgsPointCloudLayer *pclayer = qobject_cast( it->first ) ) { pointCloudResults[ pclayer ] = QVector(); @@ -94,11 +94,34 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) } else if ( QgsTiledSceneLayer *tslayer = qobject_cast( it->first ) ) { - tiledSceneResults[ tslayer ] = QVector(); - for ( const QgsRayCastingUtils::RayHit &hit : it->second ) + Q_UNUSED( tslayer ) + // We are only handling a single hit for each layer + const QgsRayCastingUtils::RayHit hit = it->second.first(); + const QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( hit.pos, mCanvas->mapSettings()->origin() ); + + QMap< QString, QString > derivedAttributes; + QString x; + QString y; + QgsCoordinateUtils::formatCoordinatePartsForProject( + QgsProject::instance(), + QgsPointXY( mapCoords.x(), mapCoords.y() ), + QgsProject::instance()->crs(), + 6, x, y + ); + + derivedAttributes.insert( tr( "(clicked coordinate X)" ), x ); + derivedAttributes.insert( tr( "(clicked coordinate Y)" ), y ); + derivedAttributes.insert( tr( "(clicked coordinate Z)" ), QLocale().toString( mapCoords.z(), 'f' ) ); + + const QList keys = hit.attributes.keys(); + for ( const QString &key : keys ) { - tiledSceneResults[ tslayer ].append( hit.attributes ); + derivedAttributes[key] = hit.attributes[key].toString(); } + QString nodeId = derivedAttributes[ QStringLiteral( "node_id" ) ]; + // only derived attributes are supported for now, so attributes is empty + QgsMapToolIdentify::IdentifyResult res( it->first, nodeId, {}, derivedAttributes ); + identifyTool2D->showIdentifyResults( { res } ); } } @@ -140,32 +163,13 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) } // Finally add all point cloud layers' results + // We add those last as the list can be quite big. for ( auto it = pointCloudResults.constKeyValueBegin(); it != pointCloudResults.constKeyValueEnd(); ++it ) { QgsMapToolIdentify identifyTool( nullptr ); - identifyTool.fromPointCloudIdentificationToIdentifyResults( it->first, it->second, identifyResults ); - identifyTool2D->showIdentifyResults( identifyResults ); + identifyTool.fromPointCloudIdentificationToIdentifyResults( it->first, it->second, pointCloudIdentifyResults ); + identifyTool2D->showIdentifyResults( pointCloudIdentifyResults ); } - - for ( auto it = tiledSceneResults.constKeyValueBegin(); it != tiledSceneResults.constKeyValueEnd(); ++it ) - { - // for the whole layer - for ( const QVariantMap &hitAttributes : it->second ) - { - QMap derivedAttributes; - const QList keys = hitAttributes.keys(); - for ( const QString &key : keys ) - { - derivedAttributes[key] = hitAttributes[key].toString(); - } - QString nodeId = hitAttributes["node_id"].toString(); - QgsMapToolIdentify::IdentifyResult res( it->first, nodeId, QMap(), derivedAttributes ); - identifyResults.append( res ); - } - - identifyTool2D->showIdentifyResults( identifyResults ); - } - } void Qgs3DMapToolIdentify::activate()