Skip to content
Permalink
Browse files

Merge pull request #9472 from wonder-sk/backport-34-fixes-3d

Backport 3D fixes to 3.4
  • Loading branch information
wonder-sk committed Mar 11, 2019
2 parents 6bccc8e + 06c9401 commit 6da978d5fd26486c62475acc699fc97ef92af5be
@@ -365,6 +365,8 @@ void Qgs3DMapScene::createTerrain()

mTerrain->deleteLater();
mTerrain = nullptr;

emit terrainEntityChanged();
}

if ( !mTerrainUpdateScheduled )
@@ -59,7 +59,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity

//! Returns camera controller
QgsCameraController *cameraController() { return mCameraController; }
//! Returns terrain entity
//! Returns terrain entity (may be temporarily null)
QgsTerrainEntity *terrainEntity() { return mTerrain; }

//! Resets camera view to show the whole scene (top view)
@@ -209,6 +209,21 @@ Qt3DRender::QGeometryRenderer *QgsPolygon3DSymbolEntityNode::renderer( const Qgs
extrusionHeightPerPolygon.append( extrusionHeight );
}
}
else if ( const QgsGeometryCollection *gc = qgsgeometry_cast< const QgsGeometryCollection *>( g ) )
{
for ( int i = 0; i < gc->numGeometries(); ++i )
{
const QgsAbstractGeometry *g2 = gc->geometryN( i );
if ( QgsWkbTypes::flatType( g2->wkbType() ) != QgsWkbTypes::Polygon )
continue;
QgsPolygon *polyClone = static_cast< const QgsPolygon *>( g2 )->clone();
Qgs3DUtils::clampAltitudes( polyClone, symbol.altitudeClamping(), symbol.altitudeBinding(), height, map );
polygons.append( polyClone );
fids.append( f.id() );
if ( hasDDExtrusion )
extrusionHeightPerPolygon.append( extrusionHeight );
}
}
else
qDebug() << "not a polygon";
}
@@ -77,16 +77,20 @@ void Qgs3DMapToolIdentify::mousePressEvent( QMouseEvent *event )

void Qgs3DMapToolIdentify::activate()
{
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
connect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
{
connect( terrainEntity->terrainPicker(), &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
}

mCanvas->scene()->registerPickHandler( mPickHandler.get() );
}

void Qgs3DMapToolIdentify::deactivate()
{
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
disconnect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
{
disconnect( terrainEntity->terrainPicker(), &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
}

mCanvas->scene()->unregisterPickHandler( mPickHandler.get() );
}
@@ -137,6 +141,8 @@ void Qgs3DMapToolIdentify::onTerrainEntityChanged()
{
// no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
connect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
{
connect( terrainEntity->terrainPicker(), &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
}
}
@@ -423,6 +423,11 @@ void QgsTessellator::addPolygon( const QgsPolygon &polygon, float extrusionHeigh
// Assuming that the coordinates should be in a projected CRS, we should be able
// to simplify geometries that may cause problems and avoid possible crashes
QgsGeometry polygonSimplified = QgsGeometry( polygonNew->clone() ).simplify( 0.001 );
if ( polygonSimplified.isNull() )
{
QgsMessageLog::logMessage( QObject::tr( "geometry simplification failed - skipping" ), QObject::tr( "3D" ) );
return;
}
const QgsPolygon *polygonSimplifiedData = qgsgeometry_cast<const QgsPolygon *>( polygonSimplified.constGet() );
if ( _minimum_distance_between_coordinates( *polygonSimplifiedData ) < 0.001 )
{
@@ -506,7 +506,7 @@ QString QgsPGLayerItem::createUri()
QgsDataSourceUri uri( QgsPostgresConn::connUri( connItem->name() ).connectionInfo( false ) );
uri.setDataSource( mLayerProperty.schemaName, mLayerProperty.tableName, mLayerProperty.geometryColName, mLayerProperty.sql, pkColName );
uri.setWkbType( mLayerProperty.types.at( 0 ) );
if ( uri.wkbType() != QgsWkbTypes::NoGeometry )
if ( uri.wkbType() != QgsWkbTypes::NoGeometry && mLayerProperty.srids.at( 0 ) != std::numeric_limits<int>::min() )
uri.setSrid( QString::number( mLayerProperty.srids.at( 0 ) ) );
QgsDebugMsg( QStringLiteral( "layer uri: %1" ).arg( uri.uri( false ) ) );
return uri.uri( false );
@@ -740,7 +740,12 @@ QgsPGLayerItem *QgsPGSchemaItem::createLayer( QgsPostgresLayerProperty layerProp
tip = tr( "Table" );
}
QgsWkbTypes::Type wkbType = layerProperty.types.at( 0 );
tip += tr( "\n%1 as %2 in %3" ).arg( layerProperty.geometryColName, QgsPostgresConn::displayStringForWkbType( wkbType ) ).arg( layerProperty.srids.at( 0 ) );
tip += tr( "\n%1 as %2" ).arg( layerProperty.geometryColName, QgsPostgresConn::displayStringForWkbType( wkbType ) );
if ( layerProperty.srids.at( 0 ) != std::numeric_limits<int>::min() )
tip += tr( " (srid %1)" ).arg( layerProperty.srids.at( 0 ) );
else
tip += tr( " (unknown srid)" );

if ( !layerProperty.tableComment.isEmpty() )
{
tip = layerProperty.tableComment + '\n' + tip;
@@ -134,6 +134,7 @@ class TestQgsTessellator : public QObject
void testBadCoordinates();
void testIssue17745();
void testCrashSelfIntersection();
void testCrashEmptyPolygon();

private:
};
@@ -335,6 +336,18 @@ void TestQgsTessellator::testCrashSelfIntersection()
t.addPolygon( p, 0 ); // must not crash - that's all we test here
}

void TestQgsTessellator::testCrashEmptyPolygon()
{
// this is a polygon that goes through GEOS simplification which throws an exception (and produces null geometry)

QgsTessellator t( 0, 0, true );
QgsPolygon p;
bool resWktRead = p.fromWkt( "PolygonZ ((0 0 0, 0 0 0, 0 0 0))" );
QVERIFY( resWktRead );

t.addPolygon( p, 0 ); // must not crash - that's all we test here
}


QGSTEST_MAIN( TestQgsTessellator )
#include "testqgstessellator.moc"

0 comments on commit 6da978d

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