Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3d] Measurement tool #30299

Merged
merged 59 commits into from Jul 8, 2019
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c065e9e
Add measurement tool bar.
ismailsunni Jun 10, 2019
ae12659
Add class for measure line.
ismailsunni Jun 10, 2019
a4922ad
Get coordinate of clicked point.
ismailsunni Jun 10, 2019
743bfc8
Add clicked point to string line.
ismailsunni Jun 13, 2019
b094e7f
Store clicekd points to layer.
ismailsunni Jun 13, 2019
1b76805
Try to render the measurement line.
ismailsunni Jun 13, 2019
1f9fcda
Render the measurement line (with some problems).
ismailsunni Jun 14, 2019
a132e75
Store points in vector.
ismailsunni Jun 16, 2019
4ca01d1
Make identify and measure tool exlusive to each other.
ismailsunni Jun 16, 2019
a928b61
Add measurement dialog.
ismailsunni Jun 16, 2019
20836bf
Fix only one action must active.
ismailsunni Jun 16, 2019
36116e2
Some code suggestion from Martin.
ismailsunni Jun 17, 2019
6e7fb1c
Revert code to show the line.
ismailsunni Jun 20, 2019
f583b53
Show segment length and the total.
ismailsunni Jun 20, 2019
08affad
Implement close dialog means restart 3d measurement.
ismailsunni Jun 20, 2019
64a67b5
Add new button.
ismailsunni Jun 20, 2019
495b8ad
Add unit combo box.
ismailsunni Jun 20, 2019
d78c67d
Fix shadowing private member of class.
ismailsunni Jun 20, 2019
6b45df3
Add slot to combo box unit changes.
ismailsunni Jun 20, 2019
893934e
Hide ellipsoid and cartesian radio button.
ismailsunni Jun 20, 2019
73fce21
Add measure line for QgsPoint.
ismailsunni Jun 20, 2019
dd08644
Add unit changes feature.
ismailsunni Jun 20, 2019
8c134ec
Add help (pointed to 2D measurement tool).
ismailsunni Jun 20, 2019
4222bb2
Add finish measurement using right click.
ismailsunni Jun 20, 2019
7313b7a
Remove keypress event, it does not make sense.
ismailsunni Jun 20, 2019
54bf924
Add remove-last-point with middle button.
ismailsunni Jun 20, 2019
9ab0961
Add crsChanged event.
ismailsunni Jun 20, 2019
2299ef9
Remove confusing tooltip.
ismailsunni Jun 20, 2019
37851df
Add pan (camera control) action tool for clear state of 3d map tool.
ismailsunni Jun 20, 2019
1c4b7a1
Change 3D identify tool cursor.
ismailsunni Jun 20, 2019
52ecd33
Fix distance 2D to 3D.
ismailsunni Jun 23, 2019
96b5e97
Remove unclear method.
ismailsunni Jun 23, 2019
1dc3c0b
Add unit test for measureLine3D.
ismailsunni Jun 23, 2019
d4c13b8
Add 3D measurement setting.
ismailsunni Jun 23, 2019
78d59b0
Add header.
ismailsunni Jun 23, 2019
8550f2c
Make extra 3D renderers refresh the scene when they are updated
wonder-sk Jun 24, 2019
1dd6aad
Set Altitude clamping to absolute.
ismailsunni Jun 28, 2019
dd42b0f
Remove options for 3D measurement line.
ismailsunni Jun 28, 2019
604fa07
Remove help button in 3D measurement dialog.
ismailsunni Jun 28, 2019
aea2b21
Merge duplicate code for handle clicked position.
ismailsunni Jun 28, 2019
e3fe10d
Use color for 3d measure line from 2d one.
ismailsunni Jun 28, 2019
070e395
Remove unneeded reimplementation method.
ismailsunni Jun 28, 2019
d733929
Remove 2D canvas reference.
ismailsunni Jun 29, 2019
5e1cbd0
Unify update measurement layer.
ismailsunni Jun 30, 2019
f77eb90
Create measurement layer once.
ismailsunni Jun 30, 2019
f0003a7
Use data provider to change the geometry.
ismailsunni Jun 30, 2019
e959eff
Add length3D for QgsLineString.
ismailsunni Jun 30, 2019
1c3cdb2
Simplify distance calculation and presentation. Remove QgsDistanceAre…
ismailsunni Jun 30, 2019
a9d5338
Descaled z value based on the terrain vertical scale.
ismailsunni Jun 30, 2019
6a1aeeb
Remove line when tool is deactivated.
ismailsunni Jun 30, 2019
4b3eacc
Enable changing the line color from setting, but after re-activation.
ismailsunni Jun 30, 2019
fd02211
Update color of measurement line after saving option.
ismailsunni Jun 30, 2019
99ccf83
Remove debug message.
ismailsunni Jun 30, 2019
de85302
Remove 3D length calculation from distancearea.
ismailsunni Jun 30, 2019
06493ef
Merge remote-tracking branch 'origin/master' into measurement-tool
ismailsunni Jun 30, 2019
d02d621
Handle 2D case for length3D, more unit test, and docstring.
ismailsunni Jul 1, 2019
109afac
Fix typos.
ismailsunni Jul 1, 2019
cea418a
Addressing Martin's and Nyall's review.
ismailsunni Jul 2, 2019
b2f9093
Remove setMeasurement to avoid confussion.
ismailsunni Jul 3, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Make extra 3D renderers refresh the scene when they are updated

+ update the 3D renderer every time the measurement line layer is modified
  • Loading branch information...
wonder-sk committed Jun 24, 2019
commit 8550f2c922d3dc566401014d5b23fadfda2dd30f
@@ -101,14 +101,11 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *
connect( &map, &Qgs3DMapSettings::terrainShadingChanged, this, &Qgs3DMapScene::createTerrain );
connect( &map, &Qgs3DMapSettings::pointLightsChanged, this, &Qgs3DMapScene::updateLights );
connect( &map, &Qgs3DMapSettings::fieldOfViewChanged, this, &Qgs3DMapScene::updateCameraLens );
connect( &map, &Qgs3DMapSettings::renderersChanged, this, &Qgs3DMapScene::onRenderersChanged );

// create entities of renderers

Q_FOREACH ( const QgsAbstract3DRenderer *renderer, map.renderers() )
{
Qt3DCore::QEntity *newEntity = renderer->createEntity( map );
newEntity->setParent( this );
}
onRenderersChanged();

// listen to changes of layers in order to add/remove 3D renderer entities
connect( &map, &Qgs3DMapSettings::layersChanged, this, &Qgs3DMapScene::onLayersChanged );
@@ -496,6 +493,26 @@ void Qgs3DMapScene::updateCameraLens()
onCameraChanged();
}

void Qgs3DMapScene::onRenderersChanged()
{
// remove entities (if any)
qDeleteAll( mRenderersEntities.values() );
mRenderersEntities.clear();

// re-add entites from new set of renderers
const QList<QgsAbstract3DRenderer *> renderers = mMap.renderers();
for ( const QgsAbstract3DRenderer *renderer : renderers )
{
Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
if ( newEntity )
{
newEntity->setParent( this );
finalizeNewEntity( newEntity );
mRenderersEntities[renderer] = newEntity;
}
}
}

void Qgs3DMapScene::onLayerRenderer3DChanged()
{
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
@@ -572,17 +589,7 @@ void Qgs3DMapScene::addLayerEntity( QgsMapLayer *layer )
connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapScene::onLayerEntityPickEvent );
}

// this is probably not the best place for material-specific configuration,
// maybe this could be more generalized when other materials need some specific treatment
for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
{
connect( mCameraController, &QgsCameraController::viewportChanged, lm, [lm, this]
{
lm->setViewportSize( mCameraController->viewport().size() );
} );

lm->setViewportSize( cameraController()->viewport().size() );
}
finalizeNewEntity( newEntity );
}
}

@@ -610,6 +617,21 @@ void Qgs3DMapScene::removeLayerEntity( QgsMapLayer *layer )
}
}

void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
{
// this is probably not the best place for material-specific configuration,
// maybe this could be more generalized when other materials need some specific treatment
for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
{
connect( mCameraController, &QgsCameraController::viewportChanged, lm, [lm, this]
{
lm->setViewportSize( mCameraController->viewport().size() );
} );

lm->setViewportSize( cameraController()->viewport().size() );
}
}

void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
{
mEntityCameraViewCenter = new Qt3DCore::QEntity;
@@ -38,6 +38,7 @@ namespace Qt3DExtras
}

class QgsAbstract3DEngine;
class QgsAbstract3DRenderer;
class QgsMapLayer;
class QgsCameraController;
class Qgs3DMapScenePickHandler;
@@ -108,6 +109,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
void onLayerEntityPickEvent( Qt3DRender::QPickEvent *event );
void updateLights();
void updateCameraLens();
void onRenderersChanged();
private:
void addLayerEntity( QgsMapLayer *layer );
void removeLayerEntity( QgsMapLayer *layer );
@@ -116,6 +118,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
void updateSceneState();
void updateScene();
bool updateCameraNearFarPlanes();
void finalizeNewEntity( Qt3DCore::QEntity *newEntity );

private:
const Qgs3DMapSettings &mMap;
@@ -129,6 +132,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
//! Keeps track of entities that belong to a particular layer
QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
bool mTerrainUpdateScheduled = false;
SceneState mSceneState = Ready;
//! List of currently registered pick handlers (used by identify tool)
@@ -464,7 +464,11 @@ void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )

void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
{
qDeleteAll( mRenderers );

mRenderers = renderers;

emit renderersChanged();
}

void Qgs3DMapSettings::setShowTerrainBoundingBoxes( bool enabled )
@@ -369,6 +369,13 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
* \since QGIS 3.6
*/
void terrainMapThemeChanged();

/**
* Emitted when the list of map's extra renderers have been modified
* \since QGIS 3.10
*/
void renderersChanged();

//! Emitted when the flag whether terrain's bounding boxes are shown has changed
void showTerrainBoundingBoxesChanged();
//! Emitted when the flag whether terrain's tile info is shown has changed
@@ -138,7 +138,7 @@ void Qgs3DMapToolMeasureLine::activate()

// Add layer to canvas
qInfo() << "Current layer: " << mCanvas->map()->layers();
This conversation was marked as resolved by ismailsunni

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jun 27, 2019

Contributor

Remove in final version

This comment has been minimized.

Copy link
@ismailsunni

ismailsunni Jun 30, 2019

Author Contributor

done

mCanvas->map()->setLayers( mCanvas->map()->layers() << mMeasurementLayer );
//mCanvas->map()->setLayers( mCanvas->map()->layers() << mMeasurementLayer );
mCanvas->map()->setRenderers( QList<QgsAbstract3DRenderer *>() << mMeasurementLayer->renderer3D()->clone() );

qInfo() << "Current layer after adding: " << mCanvas->map()->layers();
This conversation was marked as resolved by ismailsunni

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jun 27, 2019

Contributor

Remove all of these

@@ -161,6 +161,8 @@ void Qgs3DMapToolMeasureLine::deactivate()
mMeasurementLayer->commitChanges();
mMeasurementLine->clear();

mCanvas->map()->setRenderers( QList<QgsAbstract3DRenderer *>() << mMeasurementLayer->renderer3D()->clone() );

mCanvas->scene()->unregisterPickHandler( mPickHandler.get() );

// Hide dialog
@@ -245,6 +247,8 @@ void Qgs3DMapToolMeasureLine::addPoint( const QgsPoint &point )
mMeasurementLayer->commitChanges();

mDialog->addPoint();

mCanvas->map()->setRenderers( QList<QgsAbstract3DRenderer *>() << mMeasurementLayer->renderer3D()->clone() );
}

void Qgs3DMapToolMeasureLine::restart()
@@ -259,6 +263,8 @@ void Qgs3DMapToolMeasureLine::restart()
qInfo() << "Current line: " << newMeasurementLine->asWkt();
mMeasurementLayer->changeGeometry( mMeasurementFeature->id(), *newMeasurementLine );
mMeasurementLayer->commitChanges();
This conversation was marked as resolved by ismailsunni

This comment has been minimized.

Copy link
@wonder-sk

wonder-sk Jun 25, 2019

Member

It would be good to have a single function e.g. updateMeasurementLayer() that would change geometry and commit changes based on mPoints - and multiple functions can use it do de-duplicate code.

This comment has been minimized.

Copy link
@ismailsunni

ismailsunni Jun 30, 2019

Author Contributor

Done


mCanvas->map()->setRenderers( QList<QgsAbstract3DRenderer *>() << mMeasurementLayer->renderer3D()->clone() );
}

void Qgs3DMapToolMeasureLine::undo()
@@ -286,6 +292,8 @@ void Qgs3DMapToolMeasureLine::undo()
mMeasurementLayer->changeGeometry( mMeasurementFeature->id(), *newMeasurementLine );
mMeasurementLayer->commitChanges();

mCanvas->map()->setRenderers( QList<QgsAbstract3DRenderer *>() << mMeasurementLayer->renderer3D()->clone() );

mDialog->removeLastPoint();
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.