From 55f860638dde6b7f640341b605fcda02bccf8c75 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 26 Nov 2013 11:10:55 +0100 Subject: [PATCH] [globe] Add vertical scale (Requires osgEarth >= 2.5) --- src/plugins/globe/globe_plugin.cpp | 26 ++- src/plugins/globe/globe_plugin.h | 10 +- src/plugins/globe/globe_plugin_dialog.cpp | 12 ++ .../globe/globe_plugin_dialog_guibase.ui | 164 +++++++++--------- 4 files changed, 131 insertions(+), 81 deletions(-) diff --git a/src/plugins/globe/globe_plugin.cpp b/src/plugins/globe/globe_plugin.cpp index e7c403cdc81b..37b98f00908e 100644 --- a/src/plugins/globe/globe_plugin.cpp +++ b/src/plugins/globe/globe_plugin.cpp @@ -61,10 +61,13 @@ #include #include #include -#include + #if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 2, 0 ) #include #endif +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) +#include +#endif using namespace osgEarth::Drivers; using namespace osgEarth::Util; @@ -87,6 +90,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface ) , mQActionSettingsPointer( NULL ) , mOsgViewer( 0 ) , mViewerWidget( 0 ) + , mMapNode( 0 ) , mBaseLayer( 0 ) , mQgisMapLayer( 0 ) , mTileSource( 0 ) @@ -544,6 +548,22 @@ void GlobePlugin::syncExtent() manip->setViewpoint( viewpoint, 4.0 ); } +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) +void GlobePlugin::setVerticalScale( double value ) +{ + if ( mMapNode ) + { + if ( !mVerticalScale.get() || mVerticalScale->getScale() != value ) + { + mMapNode->getTerrainEngine()->removeEffect( mVerticalScale ); + mVerticalScale = new osgEarth::Util::VerticalScale(); + mVerticalScale->setScale( value ); + mMapNode->getTerrainEngine()->addEffect( mVerticalScale ); + } + } +} +#endif + void GlobePlugin::setupControls() { std::string imgDir = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/gui" ).toStdString(); @@ -810,6 +830,10 @@ void GlobePlugin::elevationLayersChanged() //if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache) } +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) + double scale = QgsProject::instance()->readDoubleEntry( "Globe-Plugin", "/verticalScale", 1 ); + setVerticalScale( scale ); +#endif } else { diff --git a/src/plugins/globe/globe_plugin.h b/src/plugins/globe/globe_plugin.h index 610a4678c235..525b14b7d064 100644 --- a/src/plugins/globe/globe_plugin.h +++ b/src/plugins/globe/globe_plugin.h @@ -45,13 +45,14 @@ using namespace osgEarth::Util::Controls; #include #include #endif +#include class QAction; class QToolBar; class QgisInterface; namespace osgEarth { namespace QtGui { class ViewerWidget; } } -namespace osgEarth { namespace Util { class SkyNode; } } +namespace osgEarth { namespace Util { class SkyNode; class VerticalScale; } } class GlobePlugin : public QObject, public QgisPlugin { @@ -87,6 +88,10 @@ class GlobePlugin : public QObject, public QgisPlugin void extentsChanged(); //! Sync globe extent to mapCanavas void syncExtent(); +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) + //! Set vertical scale + void setVerticalScale( double scale ); +#endif //! called when a project has been read successfully void projectReady(); @@ -148,6 +153,9 @@ class GlobePlugin : public QObject, public QgisPlugin osg::ref_ptr mBaseLayer; //! Sky node osg::ref_ptr mSkyNode; +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) + osg::ref_ptr mVerticalScale; +#endif //! QGIS maplayer osgEarth::ImageLayer* mQgisMapLayer; //! Tile source diff --git a/src/plugins/globe/globe_plugin_dialog.cpp b/src/plugins/globe/globe_plugin_dialog.cpp index 1ec34bb3cbee..af7416d906c6 100644 --- a/src/plugins/globe/globe_plugin_dialog.cpp +++ b/src/plugins/globe/globe_plugin_dialog.cpp @@ -310,6 +310,12 @@ void QgsGlobePluginDialog::readElevationDatasources() elevationDatasourcesWidget->setItem( i, 1, chkBoxItem ); elevationDatasourcesWidget->setItem( i, 2, uri ); } + +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) + double scale = QgsProject::instance()->readDoubleEntry( "Globe-Plugin", "/verticalScale", 1 ); + mTxtVerticalScale->setValue( scale ); + mGlobe->setVerticalScale( scale ); +#endif } void QgsGlobePluginDialog::saveElevationDatasources() @@ -362,6 +368,12 @@ void QgsGlobePluginDialog::saveElevationDatasources() QgsDebugMsg( "emitting elevationDatasourcesChanged" ); emit elevationDatasourcesChanged(); } + +#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) + double scale = mTxtVerticalScale->value(); + mGlobe->setVerticalScale( scale ); + QgsProject::instance()->writeEntry( "Globe-Plugin", "/verticalScale", scale ); +#endif } //END ELEVATION diff --git a/src/plugins/globe/globe_plugin_dialog_guibase.ui b/src/plugins/globe/globe_plugin_dialog_guibase.ui index a3ab40e48332..577b119317c6 100644 --- a/src/plugins/globe/globe_plugin_dialog_guibase.ui +++ b/src/plugins/globe/globe_plugin_dialog_guibase.ui @@ -33,10 +33,17 @@ ../../.designer/backup../../.designer/backup - + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - 0 + 1 @@ -117,42 +124,63 @@ Elevation - - - + + + + + + + + Vertical Scale + + + + + - + - Type + Up - - elevationCombo + + + + + + Down - - - - 0 - 0 - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add + + + + + + + Remove - - - Raster - - - - - TMS - - - + QLayout::SetDefaultConstraint @@ -224,52 +252,7 @@ - - - - - - Up - - - - - - - Down - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add - - - - - - - Remove - - - - - - + true @@ -369,6 +352,36 @@ + + + + Type + + + elevationCombo + + + + + + + + 0 + 0 + + + + + Raster + + + + + TMS + + + + @@ -712,13 +725,6 @@ - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - -