Skip to content

Commit

Permalink
qgs3dmapconfigwidget: Live extent change
Browse files Browse the repository at this point in the history
With this change, the 3D scene extent is updated as soon as one of the
parameter from the extent configuration dialog is changed.
  • Loading branch information
ptitjano committed Jul 10, 2024
1 parent 383b47e commit 93909c8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ void Qgs3DMapCanvasWidget::configure()
|| map->terrainGenerator()->type() == QgsTerrainGenerator::Mesh );
};

connect( buttons, &QDialogButtonBox::rejected, mConfigureDialog, &QDialog::reject );
connect( buttons, &QDialogButtonBox::rejected, mConfigureDialog, [ = ]()
{
configWidget->reject();
mConfigureDialog->reject();
} );
connect( buttons, &QDialogButtonBox::clicked, mConfigureDialog, [ = ]( QAbstractButton * button )
{
if ( button == buttons->button( QDialogButtonBox::Apply ) || button == buttons->button( QDialogButtonBox::Ok ) )
Expand Down
67 changes: 53 additions & 14 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

#include "qgs3dmapsettings.h"
#include "qgsdemterraingenerator.h"
#include "qgsextent3dwidget.h"
#include "qgsflatterraingenerator.h"
#include "qgsonlineterraingenerator.h"
#include "qgsmeshterraingenerator.h"
#include "qgs3dutils.h"
#include "qgsguiutils.h"
#include "qgsmapcanvas.h"
#include "qgsorientedbox3d.h"
#include "qgsrasterlayer.h"
#include "qgsmeshlayer.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -248,6 +248,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
const QgsOrientedBox3D sceneBox = mMap->box();
const double rotationZ = sceneBox.eulerAngles().z();
QgsRectangle horizontalExtent = mMap->extent();
mOldSceneBox = sceneBox;
if ( rotationZ != 0.0 )
{
// rotation is counter-clockwise
Expand All @@ -260,6 +261,21 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
mExtent3D->setRotation( rotationZ );
mExtent3D->setShowIn2DView( mMap->showExtentIn2DView() );

connect( mExtent3D, &QgsExtent3DWidget::extentChanged, this, [ = ]
{
updateExtent3D();
} );

connect( mExtent3D, &QgsExtent3DWidget::rotationChanged, this, [ = ]
{
updateExtent3D();
} );

connect( mExtent3D, &QgsExtent3DWidget::showIn2DViewChanged, this, [ = ]
{
mMap->setShowExtentIn2DView( mExtent3D->showIn2DView() );
} );

onTerrainTypeChanged();
}

Expand All @@ -272,19 +288,7 @@ Qgs3DMapConfigWidget::~Qgs3DMapConfigWidget()

void Qgs3DMapConfigWidget::apply()
{
QgsBox3D sceneAABox = QgsBox3D( mExtent3D->extent() );
sceneAABox.setZMinimum( Qgs3DMapSettings::DEFAULT_MIN_DEPTH );
sceneAABox.setZMaximum( Qgs3DMapSettings::DEFAULT_MAX_DEPTH );
QgsOrientedBox3D sceneBox = QgsOrientedBox3D::fromBox3D( sceneAABox );

if ( mExtent3D->rotation() != 0.0 )
{
// rotation is counter-clockwise
sceneBox = Qgs3DUtils::rotateOrientedBoundingBox3D( sceneBox, -mExtent3D->rotation() );
}

mMap->setBox( sceneBox );
updateTerrain();
updateExtent3D();

mMap->setFieldOfView( static_cast<float>( spinCameraFieldOfView->value() ) );
mMap->setProjectionType( cboCameraProjectionType->currentData().value< Qt3DRender::QCameraLens::ProjectionType >() );
Expand Down Expand Up @@ -410,6 +414,18 @@ void Qgs3DMapConfigWidget::updateTerrain()
}
}

void Qgs3DMapConfigWidget::reject()
{
QgsOrientedBox3D currentBox = updateExtent3D( false );
if ( currentBox == mOldSceneBox )
{
return;
}

mMap->setBox( mOldSceneBox );
updateTerrain();
}

void Qgs3DMapConfigWidget::onTerrainTypeChanged()
{
const QgsTerrainGenerator::Type genType = static_cast<QgsTerrainGenerator::Type>( cboTerrainType->currentData().toInt() );
Expand Down Expand Up @@ -555,3 +571,26 @@ void Qgs3DMapConfigWidget::on3DAxisChanged()

mMap->set3DAxisSettings( s );
}

QgsOrientedBox3D Qgs3DMapConfigWidget::updateExtent3D( bool doUpdate )
{
QgsBox3D sceneAABox = QgsBox3D( mExtent3D->extent() );
sceneAABox.setZMinimum( Qgs3DMapSettings::DEFAULT_MIN_DEPTH );
sceneAABox.setZMaximum( Qgs3DMapSettings::DEFAULT_MAX_DEPTH );
QgsOrientedBox3D sceneBox = QgsOrientedBox3D::fromBox3D( sceneAABox );

const double rotationZ = mExtent3D->rotation();
if ( rotationZ != 0 )
{
// rotation is counter-clockwise
sceneBox = Qgs3DUtils::rotateOrientedBoundingBox3D( sceneBox, -rotationZ );
}

if ( doUpdate )
{
mMap->setBox( sceneBox );
updateTerrain();
}

return sceneBox;
}
7 changes: 7 additions & 0 deletions src/app/3d/qgs3dmapconfigwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <ui_map3dconfigwidget.h>

#include "qgsorientedbox3d.h"

class QCheckBox;
class Qgs3DMapSettings;
class QgsMapCanvas;
Expand All @@ -40,6 +42,8 @@ class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget

void apply();

void reject();

signals:

void isValidChanged( bool valid );
Expand All @@ -60,8 +64,11 @@ class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
QgsShadowRenderingSettingsWidget *mShadowSettingsWidget = nullptr;
QCheckBox *mShowExtentIn2DViewCheckbox = nullptr;

QgsOrientedBox3D mOldSceneBox;

void init3DAxisPage();
void updateTerrain();
QgsOrientedBox3D updateExtent3D( bool doUpdate = true );
};

#endif // QGS3DMAPCONFIGWIDGET_H
3 changes: 3 additions & 0 deletions src/app/3d/qgsextent3dwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ QgsExtent3DWidget::QgsExtent3DWidget( QWidget *parent )

connect( mRotationSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ), this, &QgsExtent3DWidget::onRotationChanged );
connect( mRotationSlider, &QSlider::valueChanged, this, &QgsExtent3DWidget::onRotationChanged );
connect( mPreviewExtentCheckBox, &QCheckBox::toggled, this, [ = ] { emit showIn2DViewChanged(); } );
}

void QgsExtent3DWidget::setMapCanvas( QgsMapCanvas *canvas )
Expand Down Expand Up @@ -320,6 +321,7 @@ void QgsExtent3DWidget::setOutputExtent( const QgsRectangle &rectangle, const Qg
}

updateTitle( state );
emit extentChanged();
}

void QgsExtent3DWidget::updateTitle( const QgsExtentWidget::ExtentState &state )
Expand Down Expand Up @@ -359,6 +361,7 @@ QgsRectangle QgsExtent3DWidget::extent() const
void QgsExtent3DWidget::onRotationChanged( int rotation )
{
setRotation( rotation );
emit rotationChanged();
}

void QgsExtent3DWidget::setRotation( double rotation )
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgsextent3dwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class QgsExtent3DWidget : public QgsCollapsibleGroupBox, private Ui::QgsExtent3D
signals:

void toggleDialogVisibility( bool visible );
void extentChanged();
void rotationChanged();
void showIn2DViewChanged();

private slots:

Expand Down

0 comments on commit 93909c8

Please sign in to comment.