Skip to content
Permalink
Browse files

[globe] Add SkyNode configuration options

  • Loading branch information
m-kuhn committed Nov 14, 2013
1 parent bc8f7af commit a5de83b0ae90903750ee5da497bc91796c215334
@@ -283,14 +283,10 @@ void GlobePlugin::run()
setupMap();
}

if ( getenv( "GLOBE_SKY" ) )
{
SkyNode* sky = new SkyNode( mMapNode->getMap() );
sky->setDateTime( 2011, 1, 6, 17.0 );
//sky->setSunPosition( osg::Vec3(0,-1,0) );
sky->attach( mOsgViewer );
mRootNode->addChild( sky );
}
// Initialize the sky node if required
setSkyParameters( settings.value( "/Plugin-Globe/skyEnabled", false ).toBool()
, settings.value( "/Plugin-Globe/skyDateTime", QDateTime() ).toDateTime()
, settings.value( "/Plugin-Globe/skyAutoAmbient", false ).toBool() );

// create a surface to house the controls
mControlCanvas = ControlCanvas::get( mOsgViewer );
@@ -811,17 +807,48 @@ void GlobePlugin::elevationLayersChanged()

void GlobePlugin::setBaseMap( QString url )
{
mMapNode->getMap()->removeImageLayer( mBaseLayer );
if ( url.isNull() )
if ( mMapNode )
{
mBaseLayer = 0;
mMapNode->getMap()->removeImageLayer( mBaseLayer );
if ( url.isNull() )
{
mBaseLayer = 0;
}
else
{
TMSOptions imagery;
imagery.url() = url.toStdString();
mBaseLayer = new ImageLayer( "Imagery", imagery );
mMapNode->getMap()->insertImageLayer( mBaseLayer, 0 );
}
}
else
}

void GlobePlugin::setSkyParameters( bool enabled, const QDateTime& dateTime, bool autoAmbience )
{
if ( mRootNode )
{
TMSOptions imagery;
imagery.url() = url.toStdString();
mBaseLayer = new ImageLayer( "Imagery", imagery );
mMapNode->getMap()->insertImageLayer( mBaseLayer, 0 );
if ( enabled )
{
// Create if not yet done
if ( !mSkyNode.get() )
mSkyNode = new SkyNode( mMapNode->getMap() );

#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 4, 0 )
mSkyNode->setAutoAmbience( autoAmbience );
#endif
mSkyNode->setDateTime( dateTime.date().year()
, dateTime.date().month()
, dateTime.date().day()
, dateTime.time().hour() + dateTime.time().minute() / 60.0 );
//sky->setSunPosition( osg::Vec3(0,-1,0) );
mSkyNode->attach( mOsgViewer );
mRootNode->addChild( mSkyNode );
}
else
{
mRootNode->removeChild( mSkyNode );
}
}
}

@@ -51,6 +51,7 @@ class QToolBar;
class QgisInterface;

namespace osgEarth { namespace QtGui { class ViewerWidget; } }
namespace osgEarth { namespace Util { class SkyNode; } }

class GlobePlugin : public QObject, public QgisPlugin
{
@@ -81,6 +82,8 @@ class GlobePlugin : public QObject, public QgisPlugin
//! Set a different base map (QString::NULL will disable the base map)
void setBaseMap( QString url );
//! Called when the extents of the map change
void setSkyParameters( bool enabled, const QDateTime& dateTime, bool autoAmbience );
//! Called when the extents of the map change
void extentsChanged();
//! Sync globe extent to mapCanavas
void syncExtent();
@@ -143,6 +146,8 @@ class GlobePlugin : public QObject, public QgisPlugin
osgEarth::MapNode* mMapNode;
//! Base layer
osg::ref_ptr<osgEarth::ImageLayer> mBaseLayer;
//! Sky node
osg::ref_ptr<osgEarth::Util::SkyNode> mSkyNode;
//! QGIS maplayer
osgEarth::ImageLayer* mQgisMapLayer;
//! Tile source
@@ -577,25 +577,33 @@ void QgsGlobePluginDialog::loadMapSettings()
}

mBaseLayerURL->setText( mapUrl );

mSkyGroupBox->setChecked( settings.value( "/Plugin-Globe/skyEnabled", false ).toBool() );
mSkyAutoAmbient->setChecked( settings.value( "/Plugin-Globe/skyAutoAmbient", false ).toBool() );
mSkyDateTime->setDateTime( settings.value( "/Plugin-Globe/skyDateTime", QDateTime() ).toDateTime() );
}

void QgsGlobePluginDialog::saveMapSettings()
{
settings.setValue( "/Plugin-Globe/baseLayerEnabled", mBaseLayerGroupBox->isChecked() );
settings.setValue( "/Plugin-Globe/baseLayerURL", mBaseLayerURL->text() );

// If there is a viewer instance already, apply it on this instance
if ( mGlobe->osgViewer() )
// Let globe update the current view
if ( mBaseLayerGroupBox->isChecked() )
{
if ( mBaseLayerGroupBox->isChecked() )
{
mGlobe->setBaseMap( mBaseLayerURL->text() );
}
else
{
mGlobe->setBaseMap( QString::null );
}
mGlobe->setBaseMap( mBaseLayerURL->text() );
}
else
{
mGlobe->setBaseMap( QString::null );
}

settings.setValue( "/Plugin-Globe/skyEnabled", mSkyGroupBox->isChecked() );
settings.setValue( "/Plugin-Globe/skyAutoAmbient", mSkyAutoAmbient->isChecked() );
settings.setValue( "/Plugin-Globe/skyDateTime", mSkyDateTime->dateTime() );

// Adjust sky of a running globe viewer
mGlobe->setSkyParameters( mSkyGroupBox->isChecked(), mSkyDateTime->dateTime(), mSkyAutoAmbient->isChecked() );
}

void QgsGlobePluginDialog::setStereoConfig()
@@ -42,8 +42,8 @@
<attribute name="title">
<string>Map</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="mBaseLayerGroupBox">
<property name="title">
<string>Base Layer</string>
@@ -78,6 +78,35 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mSkyGroupBox">
<property name="title">
<string>Sky</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Date / Time (UTC)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDateTimeEdit" name="mSkyDateTime"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mSkyAutoAmbient">
<property name="text">
<string>Auto ambient</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="elevation">

0 comments on commit a5de83b

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