Skip to content
Permalink
Browse files

Start of 3D map configuration widget

  • Loading branch information
wonder-sk committed Jul 23, 2017
1 parent c8b5e63 commit 32ad0a7eb06c1c63648604463126416a1444e3d2
@@ -86,6 +86,28 @@ Map3D::Map3D()
{
}

Map3D::Map3D( const Map3D &other )
: originX( other.originX )
, originY( other.originY )
, originZ( other.originZ )
, crs( other.crs )
, backgroundColor( other.backgroundColor )
, zExaggeration( other.zExaggeration )
, tileTextureSize( other.tileTextureSize )
, maxTerrainError( other.maxTerrainError )
, terrainGenerator( other.terrainGenerator ? other.terrainGenerator->clone() : nullptr )
, polygonRenderers( other.polygonRenderers )
, pointRenderers( other.pointRenderers )
, lineRenderers( other.lineRenderers )
, skybox( other.skybox )
, skyboxFileBase( other.skyboxFileBase )
, skyboxFileExtension( other.skyboxFileExtension )
, showBoundingBoxes( other.showBoundingBoxes )
, drawTerrainTileInfo( other.drawTerrainTileInfo )
, mLayers( other.mLayers )
{
}

Map3D::~Map3D()
{
}
@@ -151,6 +151,7 @@ class _3D_EXPORT Map3D
{
public:
Map3D();
Map3D( const Map3D &other );
~Map3D();

void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
@@ -28,6 +28,10 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
{
defaultFrameGraph->setClearColor( map.backgroundColor );

// TODO: strange - setting OnDemand render policy still keeps QGIS busy (Qt 5.9.0)
// actually it is more busy than with the default "Always" policy although there are no changes in the scene.
//renderSettings->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );

#if QT_VERSION >= 0x050900
// we want precise picking of terrain (also bounding volume picking does not seem to work - not sure why)
renderSettings->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking );
@@ -129,6 +129,15 @@ QgsRasterLayer *DemTerrainGenerator::layer() const
return qobject_cast<QgsRasterLayer *>( mLayer.layer.data() );
}

TerrainGenerator *DemTerrainGenerator::clone() const
{
DemTerrainGenerator *cloned = new DemTerrainGenerator;
cloned->mLayer = mLayer;
cloned->mResolution = mResolution;
cloned->updateGenerator();
return cloned;
}

TerrainGenerator::Type DemTerrainGenerator::type() const
{
return TerrainGenerator::Dem;
@@ -30,6 +30,7 @@ class _3D_EXPORT DemTerrainGenerator : public TerrainGenerator

DemHeightMapGenerator *heightMapGenerator() { return mHeightMapGenerator.get(); }

virtual TerrainGenerator *clone() const override;
Type type() const override;
QgsRectangle extent() const override;
float heightAt( double x, double y, const Map3D &map ) const override;
@@ -86,6 +86,15 @@ ChunkLoader *FlatTerrainGenerator::createChunkLoader( ChunkNode *node ) const
return new FlatTerrainChunkLoader( mTerrain, tileGeometry, node );
}

TerrainGenerator *FlatTerrainGenerator::clone() const
{
FlatTerrainGenerator *cloned = new FlatTerrainGenerator;
cloned->mCrs = mCrs;
cloned->mExtent = mExtent;
cloned->updateTilingScheme();
return cloned;
}

TerrainGenerator::Type FlatTerrainGenerator::type() const
{
return TerrainGenerator::Flat;
@@ -21,6 +21,7 @@ class _3D_EXPORT FlatTerrainGenerator : public TerrainGenerator

virtual ChunkLoader *createChunkLoader( ChunkNode *node ) const override;

virtual TerrainGenerator *clone() const override;
Type type() const override;
QgsRectangle extent() const override;
virtual void rootChunkHeightRange( float &hMin, float &hMax ) const override;
@@ -35,6 +35,9 @@ class TerrainGenerator : public ChunkLoaderFactory

void setTerrain( Terrain *t ) { mTerrain = t; }

//! Makes a copy of the current instance
virtual TerrainGenerator *clone() const = 0;

//! What texture generator implementation is this
virtual Type type() const = 0;

@@ -22,6 +22,8 @@ class Qgs3DMapCanvas : public QWidget
//! Configure map scene being displayed. Takes ownership.
void setMap( Map3D *map );

const Map3D *map() const { return mMap; }

//! Resets camera position to the default: looking down at the origin of world coordinates
void resetView();

@@ -1,8 +1,13 @@
#include "qgs3dmapcanvasdockwidget.h"

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

#include "map3d.h"

#include <QBoxLayout>
#include <QDialog>
#include <QDialogButtonBox>
#include <QToolBar>

Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
@@ -12,6 +17,7 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )

QToolBar *toolBar = new QToolBar( contentsWidget );
toolBar->addAction( "Reset view", this, &Qgs3DMapCanvasDockWidget::resetView );
toolBar->addAction( "Configure", this, &Qgs3DMapCanvasDockWidget::configure );

mCanvas = new Qgs3DMapCanvas( contentsWidget );
mCanvas->setMinimumSize( QSize( 200, 200 ) );
@@ -34,3 +40,21 @@ void Qgs3DMapCanvasDockWidget::resetView()
{
mCanvas->resetView();
}

void Qgs3DMapCanvasDockWidget::configure()
{
QDialog dlg;
Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( mCanvas->map(), &dlg );
QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dlg );
connect( buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
connect( buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );

QVBoxLayout *layout = new QVBoxLayout( &dlg );
layout->addWidget( w, 1 );
layout->addWidget( buttons );
if ( !dlg.exec() )
return;

// update map
setMap( new Map3D( *w->map() ) );
}
@@ -19,6 +19,7 @@ class Qgs3DMapCanvasDockWidget : public QgsDockWidget

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

private:
Qgs3DMapCanvas *mCanvas;
@@ -0,0 +1,56 @@
#include "qgs3dmapconfigwidget.h"

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

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

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

mMap = new Map3D( *map );

cboTerrainLayer->setAllowEmptyLayer( true );
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );

TerrainGenerator *terrainGen = mMap->terrainGenerator.get();
if ( terrainGen && terrainGen->type() == TerrainGenerator::Dem )
{
DemTerrainGenerator *demTerrainGen = static_cast<DemTerrainGenerator *>( terrainGen );
spinTerrainResolution->setValue( demTerrainGen->resolution() );
cboTerrainLayer->setLayer( demTerrainGen->layer() );
}
else
{
cboTerrainLayer->setLayer( nullptr );
spinTerrainResolution->setEnabled( false );
}

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

Qgs3DMapConfigWidget::~Qgs3DMapConfigWidget()
{
delete mMap;
}

Map3D *Qgs3DMapConfigWidget::map()
{
// TODO: update terrain settings

mMap->zExaggeration = spinTerrainScale->value();
mMap->tileTextureSize = spinMapResolution->value();
mMap->maxTerrainError = spinScreenError->value();
mMap->drawTerrainTileInfo = chkShowTileInfo->isChecked();
mMap->showBoundingBoxes = chkShowBoundingBoxes->isChecked();

return mMap;
}
@@ -0,0 +1,28 @@
#ifndef QGS3DMAPCONFIGWIDGET_H
#define QGS3DMAPCONFIGWIDGET_H

#include <QWidget>

#include <ui_map3dconfigwidget.h>

class Map3D;

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 );
~Qgs3DMapConfigWidget();

Map3D *map();

signals:

public slots:

private:
Map3D *mMap;
};

#endif // QGS3DMAPCONFIGWIDGET_H
@@ -369,12 +369,14 @@ IF (WITH_3D)
${QGIS_APP_SRCS}
3d/qgs3dmapcanvas.cpp
3d/qgs3dmapcanvasdockwidget.cpp
3d/qgs3dmapconfigwidget.cpp
)

SET (QGIS_APP_MOC_HDRS
${QGIS_APP_MOC_HDRS}
3d/qgs3dmapcanvas.h
3d/qgs3dmapcanvasdockwidget.h
3d/qgs3dmapconfigwidget.h
)
ENDIF (WITH_3D)

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<class>Map3DConfigWidget</class>
<widget class="QWidget" name="Map3DConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
@@ -28,7 +28,7 @@
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="cboTerrainLayer"/>
<widget class="QgsMapLayerComboBox" name="cboTerrainLayer"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
@@ -56,6 +56,9 @@
<property name="suffix">
<string> px</string>
</property>
<property name="maximum">
<number>4096</number>
</property>
</widget>
</item>
</layout>
@@ -75,6 +78,9 @@
<property name="suffix">
<string> px</string>
</property>
<property name="maximum">
<number>4096</number>
</property>
</widget>
</item>
<item row="1" column="0">
@@ -85,7 +91,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinScreenError">
<widget class="QSpinBox" name="spinScreenError">
<property name="suffix">
<string> px</string>
</property>
@@ -122,6 +128,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgsmaplayercombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -8,7 +8,19 @@ FILE(GLOB LAYOUT_UIS "${CMAKE_CURRENT_SOURCE_DIR}/layout/*.ui")
FILE(GLOB AUTH_UIS "${CMAKE_CURRENT_SOURCE_DIR}/auth/*.ui")
FILE(GLOB RASTER_UIS "${CMAKE_CURRENT_SOURCE_DIR}/raster/*.ui")
FILE(GLOB STYLEDOCK_UIS "${CMAKE_CURRENT_SOURCE_DIR}/styledock/*.ui")
FILE(GLOB _3D_UIS "${CMAKE_CURRENT_SOURCE_DIR}/3d/*.ui")

QT5_WRAP_UI(QGIS_UIS_H ${QGIS_UIS} ${SYMBOLLAYER_UIS} ${EDITORWIDGET_UIS} ${PAINTEFFECT_UIS} ${COMPOSER_UIS} ${AUTH_UIS} ${RASTER_UIS} ${STYLEDOCK_UIS} ${LAYOUT_UIS})
QT5_WRAP_UI(QGIS_UIS_H
${QGIS_UIS}
${SYMBOLLAYER_UIS}
${EDITORWIDGET_UIS}
${PAINTEFFECT_UIS}
${COMPOSER_UIS}
${AUTH_UIS}
${RASTER_UIS}
${STYLEDOCK_UIS}
${LAYOUT_UIS}
${_3D_UIS}
)

ADD_CUSTOM_TARGET(ui ALL DEPENDS ${QGIS_UIS_H})

0 comments on commit 32ad0a7

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