Skip to content
Permalink
Browse files

[BUG][MESH][3D] fix enable/disable mesh 3D rendering (#34999)

fixes #34985 and fixes #34986 (mesh 3d gui)
  • Loading branch information
vcloarec committed Mar 13, 2020
1 parent b133b81 commit e6fa6c8cb5334e8afb8197f20603cff9cb522f64
@@ -77,7 +77,8 @@ Qt3DCore::QEntity *QgsMeshLayer3DRenderer::createEntity( const Qgs3DMapSettings
if ( !meshLayer || !meshLayer->dataProvider() )
return nullptr;

if ( meshLayer->dataProvider()->contains( QgsMesh::ElementType::Edge ) )
if ( meshLayer->dataProvider()->contains( QgsMesh::ElementType::Edge ) ||
!mSymbol->isEnabled() )
{
// 3D not implemented for 1D meshes
return nullptr;
@@ -41,6 +41,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co

//Advanced symbol
QDomElement elemAdvancedSettings = doc.createElement( QStringLiteral( "advanced-settings" ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "renderer-3d-enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
@@ -78,6 +79,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex

//Advanced symbol
QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
mEnabled = elemAdvancedSettings.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();
mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
@@ -237,3 +239,13 @@ void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
{
mArrowsFixedSize = arrowsFixeSize;
}

bool QgsMesh3DSymbol::isEnabled() const
{
return mEnabled;
}

void QgsMesh3DSymbol::setEnabled( bool enabled )
{
mEnabled = enabled;
}
@@ -76,6 +76,20 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

/**
* Returns if the 3d rendering is enabled
*
* \since QGIS 3.14
*/
bool isEnabled() const;

/**
* Sets if the 3d rendering is enabled
*
* \since QGIS 3.14
*/
void setEnabled( bool enabled );

//! Returns method that determines altitude (whether to clamp to feature to terrain)
Qgs3DTypes::AltitudeClamping altitudeClamping() const { return mAltClamping; }
//! Sets method that determines altitude (whether to clamp to feature to terrain)
@@ -309,6 +323,8 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
QgsPhongMaterialSettings mMaterial; //!< Defines appearance of objects
bool mAddBackFaces = false;

bool mEnabled = true;

//! Triangles settings
bool mSmoothedTriangles = false;
bool mWireframeEnabled = false;
@@ -71,7 +71,7 @@ QgsMesh3dSymbolWidget::QgsMesh3dSymbolWidget( QgsMeshLayer *meshLayer, QWidget *

void QgsMesh3dSymbolWidget::setSymbol( const QgsMesh3DSymbol &symbol )
{
// Advanced symbology
mSymbol = symbol;
mChkSmoothTriangles->setChecked( symbol.smoothedTriangles() );
mChkWireframe->setChecked( symbol.wireframeEnabled() );
mColorButtonWireframe->setColor( symbol.wireframeLineColor() );
@@ -143,7 +143,7 @@ double QgsMesh3dSymbolWidget::lineEditValue( const QLineEdit *lineEdit ) const

QgsMesh3DSymbol QgsMesh3dSymbolWidget::symbol() const
{
QgsMesh3DSymbol sym;
QgsMesh3DSymbol sym = mSymbol;

sym.setSmoothedTriangles( mChkSmoothTriangles->isChecked() );
sym.setWireframeEnabled( mChkWireframe->isChecked() );
@@ -18,6 +18,7 @@

#include <QWidget>

#include "qgsmesh3dsymbol.h"
#include "ui_qgsmesh3dpropswidget.h"

class QgsMeshDatasetGroupListModel;
@@ -57,6 +58,7 @@ class QgsMesh3dSymbolWidget : public QWidget, private Ui::QgsMesh3dPropsWidget
void setColorRampMinMax( double min, double max );
QgsMeshLayer *mLayer = nullptr;
QgsMeshDatasetGroupListModel *mDatasetGroupListModel = nullptr;
QgsMesh3DSymbol mSymbol;

};

@@ -31,14 +31,14 @@ QgsMeshLayer3DRendererWidget::QgsMeshLayer3DRendererWidget( QgsMeshLayer *layer,

QVBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
chkEnabled = new QCheckBox( tr( "Enable 3D Renderer" ), this );
layout->addWidget( chkEnabled );
mChkEnabled = new QCheckBox( tr( "Enable 3D Renderer" ), this );
layout->addWidget( mChkEnabled );

mWidgetMesh = new QgsMesh3dSymbolWidget( layer, this );
mWidgetMesh->configureForDataset();
layout->addWidget( mWidgetMesh );

connect( chkEnabled, &QCheckBox::clicked, this, &QgsMeshLayer3DRendererWidget::onEnabledClicked );
connect( mChkEnabled, &QCheckBox::clicked, this, &QgsMeshLayer3DRendererWidget::onEnabledClicked );
connect( mWidgetMesh, &QgsMesh3dSymbolWidget::changed, this, &QgsMeshLayer3DRendererWidget::widgetChanged );
}

@@ -52,6 +52,7 @@ void QgsMeshLayer3DRendererWidget::setLayer( QgsMeshLayer *layer )
{
QgsMeshLayer3DRenderer *meshRenderer = static_cast<QgsMeshLayer3DRenderer *>( r );
setRenderer( meshRenderer );
mWidgetMesh->setEnabled( meshRenderer->symbol()->isEnabled() );
}
else
{
@@ -62,23 +63,15 @@ void QgsMeshLayer3DRendererWidget::setLayer( QgsMeshLayer *layer )
void QgsMeshLayer3DRendererWidget::setRenderer( const QgsMeshLayer3DRenderer *renderer )
{
mRenderer.reset( renderer ? renderer->clone() : nullptr );
whileBlocking( chkEnabled )->setChecked( ( bool )mRenderer );
whileBlocking( mChkEnabled )->setChecked( renderer ? renderer->symbol()->isEnabled() : false );
}

QgsMeshLayer3DRenderer *QgsMeshLayer3DRendererWidget::renderer()
{
if ( chkEnabled->isChecked() )
{
QgsMesh3DSymbol *sym = new QgsMesh3DSymbol( mWidgetMesh->symbol() );
QgsMeshLayer3DRenderer *r = new QgsMeshLayer3DRenderer( sym );
r->setLayer( qobject_cast<QgsMeshLayer *>( mLayer ) );
mRenderer.reset( r );
}
else
{
mRenderer.reset();
}

QgsMesh3DSymbol *sym = new QgsMesh3DSymbol( mWidgetMesh->symbol() );
sym->setEnabled( mChkEnabled->isChecked() );
mRenderer.reset( new QgsMeshLayer3DRenderer( sym ) );
mRenderer->setLayer( qobject_cast<QgsMeshLayer *>( mLayer ) );
return mRenderer.get();
}

@@ -90,6 +83,6 @@ void QgsMeshLayer3DRendererWidget::apply()

void QgsMeshLayer3DRendererWidget::onEnabledClicked()
{
mWidgetMesh->setEnabled( chkEnabled->isChecked() );
mWidgetMesh->setEnabled( mChkEnabled->isChecked() );
emit widgetChanged();
}
@@ -49,7 +49,7 @@ class QgsMeshLayer3DRendererWidget : public QgsMapLayerConfigWidget
void onEnabledClicked();

private:
QCheckBox *chkEnabled = nullptr;
QCheckBox *mChkEnabled = nullptr;
QgsMesh3dSymbolWidget *mWidgetMesh = nullptr;
std::unique_ptr<QgsMeshLayer3DRenderer> mRenderer;
};

0 comments on commit e6fa6c8

Please sign in to comment.
You can’t perform that action at this time.