Skip to content
Permalink
Browse files

Terrain settings in GUI, react to changes of visible layers

Temporarily disabled 2d canvas preview to better see 3D performance
  • Loading branch information
wonder-sk committed Jul 24, 2017
1 parent 32ad0a7 commit 9e0bf1d69c4509d14056477e150536bc23d38c49
@@ -38,7 +38,8 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
#endif

// Camera
camera->lens()->setPerspectiveProjection( 45.0f, 16.0f / 9.0f, 10.f, 10000.0f );
float aspectRatio = ( float )viewportRect.width() / viewportRect.height();
camera->lens()->setPerspectiveProjection( 45.0f, aspectRatio, 10.f, 10000.0f );

mFrameAction = new Qt3DLogic::QFrameAction();
connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered,
@@ -142,6 +143,9 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
// but then when zoomed in more it would disappear - so let's keep frustum culling disabled
defaultFrameGraph->setFrustumCullingEnabled( false );
}

// force initial update of chunked entities
onCameraChanged();
}

SceneState _sceneState( CameraController *cameraController )
@@ -2,6 +2,7 @@

#include "qgs3dmapcanvas.h"
#include "qgs3dmapconfigwidget.h"
#include "qgsmapcanvas.h"

#include "map3d.h"

@@ -12,12 +13,13 @@

Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
: QgsDockWidget( parent )
, mMainCanvas( nullptr )
{
QWidget *contentsWidget = new QWidget( this );

QToolBar *toolBar = new QToolBar( contentsWidget );
toolBar->addAction( "Reset view", this, &Qgs3DMapCanvasDockWidget::resetView );
toolBar->addAction( "Configure", this, &Qgs3DMapCanvasDockWidget::configure );
toolBar->addAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionZoomFullExtent.svg" ) ), "Reset view", this, &Qgs3DMapCanvasDockWidget::resetView );
toolBar->addAction( QgsApplication::getThemeIcon( QStringLiteral( "mIconProperties.svg" ) ), "Configure", this, &Qgs3DMapCanvasDockWidget::configure );

mCanvas = new Qgs3DMapCanvas( contentsWidget );
mCanvas->setMinimumSize( QSize( 200, 200 ) );
@@ -36,6 +38,13 @@ void Qgs3DMapCanvasDockWidget::setMap( Map3D *map )
mCanvas->setMap( map );
}

void Qgs3DMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas )
{
mMainCanvas = canvas;

connect( mMainCanvas, &QgsMapCanvas::layersChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged );
}

void Qgs3DMapCanvasDockWidget::resetView()
{
mCanvas->resetView();
@@ -44,7 +53,7 @@ void Qgs3DMapCanvasDockWidget::resetView()
void Qgs3DMapCanvasDockWidget::configure()
{
QDialog dlg;
Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( mCanvas->map(), &dlg );
Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( mCanvas->map(), mMainCanvas, &dlg );
QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dlg );
connect( buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
connect( buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
@@ -58,3 +67,10 @@ void Qgs3DMapCanvasDockWidget::configure()
// update map
setMap( new Map3D( *w->map() ) );
}

void Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged()
{
Map3D *newMap = new Map3D( *mCanvas->map() );
newMap->setLayers( mMainCanvas->layers() );
setMap( newMap );
}
@@ -4,6 +4,7 @@
#include "qgsdockwidget.h"

class Qgs3DMapCanvas;
class QgsMapCanvas;

class Map3D;

@@ -17,12 +18,17 @@ class Qgs3DMapCanvasDockWidget : public QgsDockWidget
//! takes ownership
void setMap( Map3D *map );

void setMainCanvas( QgsMapCanvas *canvas );

private slots:
void resetView();
void configure();

void onMainCanvasLayersChanged();

private:
Qgs3DMapCanvas *mCanvas;
QgsMapCanvas *mMainCanvas;
};

#endif // QGS3DMAPCANVASDOCKWIDGET_H
@@ -2,16 +2,22 @@

#include "map3d.h"
#include "demterraingenerator.h"
#include "flatterraingenerator.h"

#include "qgsmapcanvas.h"
#include "qgsrasterlayer.h"
//#include "qgsproject.h"

Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( const Map3D *map, QWidget *parent )
Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( const Map3D *map, QgsMapCanvas *mainCanvas, QWidget *parent )
: QWidget( parent )
, mMap( nullptr )
, mMainCanvas( mainCanvas )
{
setupUi( this );

Q_ASSERT( map );
Q_ASSERT( mainCanvas );

mMap = new Map3D( *map );

cboTerrainLayer->setAllowEmptyLayer( true );
@@ -28,13 +34,16 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( const Map3D *map, QWidget *parent )
{
cboTerrainLayer->setLayer( nullptr );
spinTerrainResolution->setEnabled( false );
spinTerrainResolution->setValue( 16 );
}

spinTerrainScale->setValue( mMap->zExaggeration );
spinMapResolution->setValue( mMap->tileTextureSize );
spinScreenError->setValue( mMap->maxTerrainError );
chkShowTileInfo->setChecked( mMap->drawTerrainTileInfo );
chkShowBoundingBoxes->setChecked( mMap->showBoundingBoxes );

connect( cboTerrainLayer, static_cast<void ( QComboBox::* )( int )>( &QgsMapLayerComboBox::currentIndexChanged ), this, &Qgs3DMapConfigWidget::onTerrainLayerChanged );
}

Qgs3DMapConfigWidget::~Qgs3DMapConfigWidget()
@@ -44,7 +53,21 @@ Qgs3DMapConfigWidget::~Qgs3DMapConfigWidget()

Map3D *Qgs3DMapConfigWidget::map()
{
// TODO: update terrain settings
// update terrain settings
if ( QgsRasterLayer *demLayer = qobject_cast<QgsRasterLayer *>( cboTerrainLayer->currentLayer() ) )
{
DemTerrainGenerator *demTerrainGen = new DemTerrainGenerator;
demTerrainGen->setLayer( demLayer );
demTerrainGen->setResolution( spinTerrainResolution->value() );
mMap->terrainGenerator.reset( demTerrainGen );
}
else
{
FlatTerrainGenerator *flatTerrainGen = new FlatTerrainGenerator;
flatTerrainGen->setCrs( mMap->crs );
flatTerrainGen->setExtent( mMainCanvas->fullExtent() );
mMap->terrainGenerator.reset( flatTerrainGen );
}

mMap->zExaggeration = spinTerrainScale->value();
mMap->tileTextureSize = spinMapResolution->value();
@@ -54,3 +77,8 @@ Map3D *Qgs3DMapConfigWidget::map()

return mMap;
}

void Qgs3DMapConfigWidget::onTerrainLayerChanged()
{
spinTerrainResolution->setEnabled( cboTerrainLayer->currentLayer() );
}
@@ -7,22 +7,27 @@

class Map3D;

class QgsMapCanvas;


class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
{
Q_OBJECT
public:
//! construct widget. does not take ownership of the passed map.
explicit Qgs3DMapConfigWidget( const Map3D *map, QWidget *parent = nullptr );
explicit Qgs3DMapConfigWidget( const Map3D *map, QgsMapCanvas *mainCanvas, QWidget *parent = nullptr );
~Qgs3DMapConfigWidget();

Map3D *map();

signals:

public slots:
private slots:
void onTerrainLayerChanged();

private:
Map3D *mMap;
QgsMapCanvas *mMainCanvas;
};

#endif // QGS3DMAPCONFIGWIDGET_H
@@ -9909,6 +9909,7 @@ void QgisApp::new3DMapCanvas()
map3DWidget->setAllowedAreas( Qt::AllDockWidgetAreas );
map3DWidget->setGeometry( QRect( rect().width() * 0.75, rect().height() * 0.5, 400, 400 ) );
map3DWidget->setMap( map );
map3DWidget->setMainCanvas( mMapCanvas );
addDockWidget( Qt::RightDockWidgetArea, map3DWidget );
}

0 comments on commit 9e0bf1d

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