4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ SET (WITH_GLOBE FALSE CACHE BOOL "Determines whether Globe plugin should be buil
IF (WITH_GLOBE)
SET(QT_USE_QTOPENGL 1)
FIND_PACKAGE(OSGEARTH REQUIRED)
IF (OSGEARTHQT_LIBRARY)
# following variable is used in qgsconfig.h
SET(HAVE_OSGEARTHQT TRUE)
ENDIF (OSGEARTHQT_LIBRARY)
ENDIF (WITH_GLOBE)

# Compile flag. Make it possible to turn it off.
Expand Down
3 changes: 3 additions & 0 deletions cmake/FindOSGEARTH.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY_DEBUG osgEarthFeaturesd )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY_DEBUG osgEarthSymbologyd )

FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY_DEBUG osgEarthQtd )


SET( OSGEARTH_FOUND "NO" )
IF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@

#cmakedefine HAVE_TOUCH

#cmakedefine HAVE_OSGEARTHQT

#endif

24 changes: 19 additions & 5 deletions src/plugins/globe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ SET (globe_plugin_SRCS
globe_plugin.cpp
qgsosgearthtilesource.cpp
globe_plugin_dialog.cpp
osgEarthQt/ViewerWidget.cpp
osgEarthUtil/Controls.cpp
)
IF (NOT HAVE_OSGEARTHQT)
SET(globe_plugin_SRCS
${globe_plugin_SRCS}
osgEarthQt/ViewerWidget.cpp
osgEarthUtil/Controls.cpp
)
ENDIF (NOT HAVE_OSGEARTHQT)

SET (globe_plugin_UIS
globe_plugin_dialog_guibase.ui
Expand Down Expand Up @@ -51,6 +56,17 @@ INCLUDE_DIRECTORIES(
..
)

SET (OSGEARTH_LIBS
${OSGEARTH_LIBRARY}
${OSGEARTHFEATURES_LIBRARY}
${OSGEARTHUTIL_LIBRARY}
)
IF (HAVE_OSGEARTHQT)
SET(OSGEARTH_LIBS
${OSGEARTH_LIBS}
${OSGEARTHQT_LIBRARY}
)
ENDIF (HAVE_OSGEARTHQT)
TARGET_LINK_LIBRARIES(globeplugin
qgis_core
qgis_gui
Expand All @@ -61,9 +77,7 @@ TARGET_LINK_LIBRARIES(globeplugin
${OSG_LIBRARY}
${OSGQT_LIBRARY}
${OSGVIEWER_LIBRARY}
${OSGEARTH_LIBRARY}
${OSGEARTHFEATURES_LIBRARY}
${OSGEARTHUTIL_LIBRARY}
${OSGEARTH_LIBS}
${OPENTHREADS_LIBRARY}
)

Expand Down
72 changes: 60 additions & 12 deletions src/plugins/globe/globe_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#include "globe_plugin.h"
#include "globe_plugin_dialog.h"
#include "qgsosgearthtilesource.h"
#ifdef HAVE_OSGEARTHQT
#include <osgEarthQt/ViewerWidget>
#else
#include "osgEarthQt/ViewerWidget"
#endif

#include <cmath>

Expand Down Expand Up @@ -52,12 +56,13 @@
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/TileSource>
#include <osgEarthUtil/SkyNode>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/tms/TMSOptions>

using namespace osgEarth::Drivers;
using namespace osgEarth::Util::Controls21;
using namespace osgEarth::Util;

#define MOVE_OFFSET 0.05

Expand Down Expand Up @@ -187,18 +192,25 @@ void GlobePlugin::initGui()
// Create the action for tool
mQActionPointer = new QAction( QIcon( ":/globe/globe.png" ), tr( "Launch Globe" ), this );
mQActionSettingsPointer = new QAction( QIcon( ":/globe/globe.png" ), tr( "Globe Settings" ), this );
QAction* actionUnload = new QAction( tr( "Unload Globe" ), this );

// Set the what's this text
mQActionPointer->setWhatsThis( tr( "Overlay data on a 3D globe" ) );
mQActionSettingsPointer->setWhatsThis( tr( "Settings for 3D globe" ) );
// Connect the action to the run
actionUnload->setWhatsThis( tr( "Unload globe" ) );

// Connect actions
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
// Connect to the setting slot
connect( mQActionSettingsPointer, SIGNAL( triggered() ), this, SLOT( settings() ) );
connect( actionUnload, SIGNAL( triggered() ), this, SLOT( reset() ) );

// Add the icon to the toolbar
mQGisIface->addToolBarIcon( mQActionPointer );

//Add menu
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionPointer );
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionSettingsPointer );
mQGisIface->addPluginToMenu( tr( "&Globe" ), actionUnload );

connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) );
Expand Down Expand Up @@ -231,9 +243,9 @@ void GlobePlugin::run()
mIsGlobeRunning = true;
setupProxy();

if ( getenv( "MAPXML" ) )
if ( getenv( "GLOBE_MAPXML" ) )
{
char* mapxml = getenv( "MAPXML" );
char* mapxml = getenv( "GLOBE_MAPXML" );
QgsDebugMsg( mapxml );
osg::Node* node = osgDB::readNodeFile( mapxml );
if ( !node )
Expand All @@ -250,6 +262,15 @@ 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 );
}

// create a surface to house the controls
mControlCanvas = ControlCanvas::get( mOsgViewer );
mRootNode->addChild( mControlCanvas );
Expand Down Expand Up @@ -312,20 +333,21 @@ void GlobePlugin::settings()
void GlobePlugin::setupMap()
{
QSettings settings;
/*
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
TMSCacheOptions cacheOptions;
cacheOptions.setPath( cacheDirectory.toStdString() );
*/

MapOptions mapOptions;
mapOptions.cache() = cacheOptions;
//mapOptions.cache() = cacheOptions;
osgEarth::Map *map = new osgEarth::Map( mapOptions );

//Default image layer
/*
GDALOptions driverOptions;
driverOptions.url() = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/world.tif" ).toStdString();
ImageLayerOptions layerOptions( "world", driverOptions );
layerOptions.cacheEnabled() = false;
map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) );
*/
TMSOptions imagery;
Expand Down Expand Up @@ -633,9 +655,14 @@ void GlobePlugin::setupControls()

//END ZOOM CONTROLS

//EXTRA CONTROLS
//EXTRA CONTROLS
//#define ENABLE_SYNC_BUTTON 1
#if ENABLE_SYNC_BUTTON
//Horizontal container
HBox* extraControls = new HBox();
#else
VBox* extraControls = new VBox();
#endif
extraControls->setFrame( new RoundedFrame() );
extraControls->getFrame()->setBackColor( 1, 1, 1, 0.5 );
extraControls->setMargin( 0 );
Expand All @@ -646,13 +673,19 @@ void GlobePlugin::setupControls()
#endif
extraControls->setVertAlign( Control::ALIGN_CENTER );
extraControls->setHorizAlign( Control::ALIGN_CENTER );
extraControls->setPosition( 5, 220 );
#if ENABLE_SYNC_BUTTON
extraControls->setPosition( 5, 231 );
#else
extraControls->setPosition( 35, 231 );
#endif
extraControls->setPadding( 6 );

//Sync Extent
#if ENABLE_SYNC_BUTTON
osg::Image* extraSyncImg = osgDB::readImageFile( imgDir + "/sync-extent.png" );
ImageControl* extraSync = new NavigationControl( extraSyncImg );
extraSync->addEventHandler( new SyncExtentControlHandler( this ) );
#endif

//Zoom Reset
osg::Image* extraHomeImg = osgDB::readImageFile( imgDir + "/zoom-home.png" );
Expand All @@ -665,7 +698,9 @@ void GlobePlugin::setupControls()
extraRefresh->addEventHandler( new RefreshControlHandler( this ) );

//add controls to extraControls group
#if ENABLE_SYNC_BUTTON
extraControls->addControl( extraSync );
#endif
extraControls->addControl( extraHome );
extraControls->addControl( extraRefresh );

Expand Down Expand Up @@ -735,7 +770,7 @@ void GlobePlugin::imageLayersChanged()
ImageLayerOptions options( "QGIS" );
mQgisMapLayer = new ImageLayer( options, mTileSource );
map->addImageLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
//[layer->setCache is private in 1.3.0] mQgisMapLayer->setCache( 0 ); //disable caching
}
else
{
Expand Down Expand Up @@ -772,7 +807,7 @@ void GlobePlugin::elevationLayersChanged()
for ( int i = 0; i < table->rowCount(); ++i )
{
QString type = table->item( i, 0 )->text();
bool cache = table->item( i, 1 )->checkState();
//bool cache = table->item( i, 1 )->checkState();
QString uri = table->item( i, 2 )->text();
ElevationLayer* layer = 0;

Expand All @@ -790,7 +825,7 @@ void GlobePlugin::elevationLayersChanged()
}
map->addElevationLayer( layer );

if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
//if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
}
}
else
Expand All @@ -800,8 +835,21 @@ void GlobePlugin::elevationLayersChanged()
}
}

void GlobePlugin::reset()
{
if (mViewerWidget) {
delete mViewerWidget;
mViewerWidget = 0;
}
if (mOsgViewer) {
delete mOsgViewer;
mOsgViewer = 0;
}
}

void GlobePlugin::unload()
{
reset();
// remove the GUI
mQGisIface->removePluginMenu( "&Globe", mQActionPointer );
mQGisIface->removeToolBarIcon( mQActionPointer );
Expand Down
24 changes: 19 additions & 5 deletions src/plugins/globe/globe_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@
#ifndef QGS_GLOBE_PLUGIN_H
#define QGS_GLOBE_PLUGIN_H

#include "../qgisplugin.h"
#include "qgsconfig.h"
#include "qgisplugin.h"
#include "qgsosgearthtilesource.h"
#include "globe_plugin_dialog.h"
#include <QObject>
#include <osgViewer/Viewer>
#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarthUtil/EarthManipulator>
//#include <osgEarthUtil/Controls>
#ifndef HAVE_OSGEARTHQT //use backported controls if osgEarth <= 2.1
#define USE_BACKPORTED_CONTROLS
#endif
#ifdef USE_BACKPORTED_CONTROLS
#include "osgEarthUtil/Controls"
using namespace osgEarth::Util::Controls21;
#else
#include <osgEarthUtil/Controls>
using namespace osgEarth::Util::Controls;
#endif
#include <osgEarthUtil/ElevationManager>
#include <osgEarthUtil/ObjectPlacer>

Expand All @@ -52,6 +61,8 @@ class GlobePlugin : public QObject, public QgisPlugin
void run();
//! Show the settings dialog box
void settings();
//! Reset globe
void reset();
//! unload the plugin
void unload();
//! show the help document
Expand Down Expand Up @@ -87,7 +98,6 @@ class GlobePlugin : public QObject, public QgisPlugin
//! get elevation of user right click
double getSelectedElevation();


//! Place an OSG model on the globe
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );

Expand Down Expand Up @@ -125,7 +135,7 @@ class GlobePlugin : public QObject, public QgisPlugin
//! Tile source
osgEarth::Drivers::QgsOsgEarthTileSource* mTileSource;
//! Control Canvas
osgEarth::Util::Controls21::ControlCanvas* mControlCanvas;
ControlCanvas* mControlCanvas;
//! Elevation manager
osgEarth::Util::ElevationManager* mElevationManager;
//! Object placer
Expand Down Expand Up @@ -192,7 +202,11 @@ namespace osgEarth
{
namespace Util
{
namespace Controls21
#ifdef USE_BACKPORTED_CONTROLS
namespace Controls21
#else
namespace Controls
#endif
{
class NavigationControlHandler : public ControlEventHandler
{
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/globe/globe_plugin_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void QgsGlobePluginDialog::on_elevationAdd_clicked()
QTableWidgetItem *type = new QTableWidgetItem( elevationCombo->currentText() );
QTableWidgetItem *uri = new QTableWidgetItem( elevationPath->text() );
QTableWidgetItem* cache = new QTableWidgetItem();
cache->setCheckState(( elevationCombo->currentText() == "Worldwind" ) ? Qt::Checked : Qt::Unchecked ); //worldwind_cache will be active
//cache->setCheckState(( elevationCombo->currentText() == "Worldwind" ) ? Qt::Checked : Qt::Unchecked ); //worldwind_cache will be active
elevationDatasourcesWidget->setRowCount( 1 + i );
elevationDatasourcesWidget->setItem( i, 0, type );
elevationDatasourcesWidget->setItem( i, 1, cache );
Expand Down Expand Up @@ -257,13 +257,12 @@ void QgsGlobePluginDialog::resetElevationDatasources()
elevationDatasourcesWidget->setRowCount( 1 );
elevationDatasourcesWidget->setItem( 0, 0, new QTableWidgetItem("TMS") );
elevationDatasourcesWidget->setItem( 0, 1, new QTableWidgetItem() );
elevationDatasourcesWidget->item( 0, 1 )->setCheckState( Qt::Unchecked );
//elevationDatasourcesWidget->item( 0, 1 )->setCheckState( Qt::Unchecked );
elevationDatasourcesWidget->setItem( 0, 2, new QTableWidgetItem("http://readymap.org/readymap/tiles/1.0.0/9/") );
}

void QgsGlobePluginDialog::readElevationDatasources()
{
//showMessageBox("reading");
// clear the widget
elevationDatasourcesWidget->clearContents();
elevationDatasourcesWidget->setRowCount( 0 );
Expand All @@ -276,12 +275,12 @@ void QgsGlobePluginDialog::readElevationDatasources()
QgsProject::instance()->readEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/type" ) );
QTableWidgetItem *uri = new QTableWidgetItem(
QgsProject::instance()->readEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/uri" ) );
bool cache = QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/cache" );
//bool cache = QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/cache" );

elevationDatasourcesWidget->setRowCount( 1 + i );
elevationDatasourcesWidget->setItem( i, 0, type );
QTableWidgetItem* chkBoxItem = new QTableWidgetItem();
chkBoxItem->setCheckState( cache ? Qt::Checked : Qt::Unchecked );
//chkBoxItem->setCheckState( cache ? Qt::Checked : Qt::Unchecked );
elevationDatasourcesWidget->setItem( i, 1, chkBoxItem );
elevationDatasourcesWidget->setItem( i, 2, uri );
}
Expand Down
Binary file modified src/plugins/globe/images/gui/zoom-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.