Skip to content

Commit

Permalink
[globe] Add vertical scale (Requires osgEarth >= 2.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 26, 2013
1 parent 1eda09d commit 55f8606
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 81 deletions.
26 changes: 25 additions & 1 deletion src/plugins/globe/globe_plugin.cpp
Expand Up @@ -61,10 +61,13 @@
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarth/Version>

#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 2, 0 )
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#endif
#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 )
#include <osgEarthUtil/VerticalScale>
#endif
using namespace osgEarth::Drivers;
using namespace osgEarth::Util;

Expand All @@ -87,6 +90,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
, mQActionSettingsPointer( NULL )
, mOsgViewer( 0 )
, mViewerWidget( 0 )
, mMapNode( 0 )
, mBaseLayer( 0 )
, mQgisMapLayer( 0 )
, mTileSource( 0 )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/globe/globe_plugin.h
Expand Up @@ -45,13 +45,14 @@ using namespace osgEarth::Util::Controls;
#include <osgEarthUtil/ElevationManager>
#include <osgEarthUtil/ObjectPlacer>
#endif
#include <osgEarth/Version>

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
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -148,6 +153,9 @@ class GlobePlugin : public QObject, public QgisPlugin
osg::ref_ptr<osgEarth::ImageLayer> mBaseLayer;
//! Sky node
osg::ref_ptr<osgEarth::Util::SkyNode> mSkyNode;
#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 )
osg::ref_ptr<osgEarth::Util::VerticalScale> mVerticalScale;
#endif
//! QGIS maplayer
osgEarth::ImageLayer* mQgisMapLayer;
//! Tile source
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
164 changes: 85 additions & 79 deletions src/plugins/globe/globe_plugin_dialog_guibase.ui
Expand Up @@ -33,10 +33,17 @@
<normaloff>../../.designer/backup</normaloff>../../.designer/backup</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Expand Down Expand Up @@ -117,42 +124,63 @@
<attribute name="title">
<string>Elevation</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QGridLayout" name="gridLayout_7">
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="mTxtVerticalScale"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Vertical Scale</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_10">
<widget class="QPushButton" name="elevationUp">
<property name="text">
<string>Type</string>
<string>Up</string>
</property>
<property name="buddy">
<cstring>elevationCombo</cstring>
</widget>
</item>
<item>
<widget class="QPushButton" name="elevationDown">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="elevationCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="elevationAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="elevationRemove">
<property name="text">
<string>Remove</string>
</property>
<item>
<property name="text">
<string>Raster</string>
</property>
</item>
<item>
<property name="text">
<string>TMS</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
Expand Down Expand Up @@ -224,52 +252,7 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="elevationUp">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="elevationDown">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="elevationAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="elevationRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<item row="5" column="0" colspan="2">
<widget class="QTableWidget" name="elevationDatasourcesWidget">
<property name="acceptDrops">
<bool>true</bool>
Expand Down Expand Up @@ -369,6 +352,36 @@
</column>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Type</string>
</property>
<property name="buddy">
<cstring>elevationCombo</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="elevationCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Raster</string>
</property>
</item>
<item>
<property name="text">
<string>TMS</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="video">
Expand Down Expand Up @@ -712,13 +725,6 @@
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand Down

0 comments on commit 55f8606

Please sign in to comment.