Skip to content

Commit

Permalink
Backported osgEarth::QtGui::ViewerWidget and osgEarth::Util::Controls…
Browse files Browse the repository at this point in the history
… for compatibilty with news OSG and QT version
  • Loading branch information
pka committed Oct 2, 2012
1 parent 8a1ad57 commit 88e3e34
Show file tree
Hide file tree
Showing 13 changed files with 3,351 additions and 292 deletions.
8 changes: 6 additions & 2 deletions src/plugins/globe/CMakeLists.txt
Expand Up @@ -14,9 +14,10 @@ ENDIF(HAVE_OSGEARTH_CHILD_SPACING)

SET (globe_plugin_SRCS
globe_plugin.cpp
qgsosgviewer.cpp
qgsosgearthtilesource.cpp
globe_plugin_dialog.cpp
osgEarthQt/ViewerWidget.cpp
osgEarthUtil/Controls.cpp
)

SET (globe_plugin_UIS
Expand All @@ -26,7 +27,9 @@ SET (globe_plugin_UIS
SET (globe_plugin_MOC_HDRS
globe_plugin.h
globe_plugin_dialog.h
qgsosgviewer.h
osgEarthQt/Common
osgEarthQt/ViewerWidget
osgEarthUtil/Controls
)

SET (globe_plugin_RCCS globe_plugin.qrc)
Expand Down Expand Up @@ -58,6 +61,7 @@ TARGET_LINK_LIBRARIES(globeplugin
${OSGDB_LIBRARY}
${OSGGA_LIBRARY}
${OSG_LIBRARY}
${OSGQT_LIBRARY}
${OSGVIEWER_LIBRARY}
${OSGEARTH_LIBRARY}
${OSGEARTHFEATURES_LIBRARY}
Expand Down
106 changes: 67 additions & 39 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -19,6 +19,7 @@
#include "globe_plugin.h"
#include "globe_plugin_dialog.h"
#include "qgsosgearthtilesource.h"
#include "osgEarthQt/ViewerWidget"

#include <cmath>

Expand Down Expand Up @@ -57,7 +58,7 @@
#include <osgEarthDrivers/tms/TMSOptions>

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

#define MOVE_OFFSET 0.05

Expand All @@ -74,7 +75,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
, mQGisIface( theQgisInterface )
, mQActionPointer( NULL )
, mQActionSettingsPointer( NULL )
, viewer()
, mOsgViewer( 0 )
, mQgisMapLayer( 0 )
, mTileSource( 0 )
, mElevationManager( NULL )
Expand All @@ -94,8 +95,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
#endif
#endif

mSettingsDialog = new QgsGlobePluginDialog( &viewer, theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags );
mQDockWidget = new QDockWidgetGlobe( tr( "Globe" ), theQgisInterface->mainWindow() );
mSettingsDialog = new QgsGlobePluginDialog( theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags );
}

//destructor
Expand Down Expand Up @@ -199,7 +199,6 @@ void GlobePlugin::initGui()
//Add menu
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionPointer );
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionSettingsPointer );
mQDockWidget->setWidget( &viewer );

connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) );
Expand All @@ -211,8 +210,6 @@ void GlobePlugin::initGui()
SLOT( projectReady() ) );
connect( mQGisIface, SIGNAL( newProjectCreated() ), this,
SLOT( blankProjectReady() ) );
connect( mQDockWidget, SIGNAL( globeClosed() ), this,
SLOT( setGlobeNotRunning() ) );
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
mQGisIface->mapCanvas(), SIGNAL( xyCoordinates( const QgsPoint & ) ) );
}
Expand All @@ -223,54 +220,73 @@ void GlobePlugin::run()
if ( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO );
#endif

mQGisIface->addDockWidget( Qt::RightDockWidgetArea, mQDockWidget );
if (mOsgViewer == 0) mOsgViewer = new osgViewer::Viewer();

viewer.show();

#ifdef GLOBE_OSG_STANDALONE_VIEWER
osgViewer::Viewer viewer;
#endif
// install the programmable manipulator.
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
mOsgViewer->setCameraManipulator( manip );

mIsGlobeRunning = true;
setupProxy();

// install the programmable manipulator.
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
viewer.setCameraManipulator( manip );
if ( getenv( "MAPXML" ) ) {
char* mapxml = getenv( "MAPXML" );
QgsDebugMsg( mapxml );
osg::Node* node = osgDB::readNodeFile(mapxml);
if ( !node ) {
QgsDebugMsg( "Failed to load earth file " );
return;
}
mMapNode = MapNode::findMapNode(node);
mRootNode = new osg::Group();
mRootNode->addChild( node );
} else {
setupMap();
}

// create a surface to house the controls
mControlCanvas = ControlCanvas::get( mOsgViewer );
mRootNode->addChild( mControlCanvas );

mOsgViewer->setSceneData( mRootNode );

mOsgViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);

mOsgViewer->addEventHandler(new osgViewer::StatsHandler());
mOsgViewer->addEventHandler(new osgViewer::WindowSizeHandler());
mOsgViewer->addEventHandler(new osgViewer::ThreadingHandler());
mOsgViewer->addEventHandler(new osgViewer::LODScaleHandler());
mOsgViewer->addEventHandler(new osgGA::StateSetManipulator(mOsgViewer->getCamera()->getOrCreateStateSet()));
// add a handler that will automatically calculate good clipping planes
//viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );
//mOsgViewer->addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );
// osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of
// OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
mOsgViewer->getDatabasePager()->setDoPreCompile( true );

setupMap();
mSettingsDialog->setViewer(mOsgViewer);

viewer.setSceneData( mRootNode );
#ifdef GLOBE_OSG_STANDALONE_VIEWER
mOsgViewer->run();
#endif

QWidget* viewerWidget = new osgEarth::QtGui::ViewerWidget( mOsgViewer );
viewerWidget->setGeometry(100, 100, 1024, 800);
viewerWidget->show();

// Set a home viewpoint
manip->setHomeViewpoint(
osgEarth::Util::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 4e7 ),
1.0 );

// create a surface to house the controls
mControlCanvas = new ControlCanvas( &viewer );
mRootNode->addChild( mControlCanvas );
setupControls();

// add our handlers
viewer.addEventHandler( new FlyToExtentHandler( this ) );
viewer.addEventHandler( new KeyboardControlHandler( manip, mQGisIface ) );
mOsgViewer->addEventHandler( new FlyToExtentHandler( this ) );
mOsgViewer->addEventHandler( new KeyboardControlHandler( manip, mQGisIface ) );

viewer.addEventHandler( new QueryCoordinatesHandler( this, mElevationManager,
mOsgViewer->addEventHandler( new QueryCoordinatesHandler( this, mElevationManager,
mMapNode->getMap()->getProfile()->getSRS() )
);

// add some stock OSG handlers:
viewer.addEventHandler( new osgViewer::StatsHandler() );
viewer.addEventHandler( new osgViewer::WindowSizeHandler() );
viewer.addEventHandler( new osgGA::StateSetManipulator( viewer.getCamera()->getOrCreateStateSet() ) );

#ifdef GLOBE_OSG_STANDALONE_VIEWER
viewer.run();
#endif

}

void GlobePlugin::settings()
Expand All @@ -294,11 +310,23 @@ void GlobePlugin::setupMap()
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;
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
map->addImageLayer( new ImageLayer("Imagery", imagery) );

// add a TMS elevation layer:
/*
TMSOptions elevation;
elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/9/";
map->addElevationLayer( new ElevationLayer("Elevation", elevation) );
*/

MapNodeOptions nodeOptions;
//nodeOptions.proxySettings() =
Expand Down Expand Up @@ -415,14 +443,15 @@ double GlobePlugin::getSelectedElevation()

void GlobePlugin::syncExtent()
{
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() );
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( mOsgViewer->getCameraManipulator() );
//rotate earth to north and perpendicular to camera
manip->setRotation( osg::Quat() );

//get mapCanvas->extent().height() in meters
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
QgsDistanceArea dist;
dist.setEllipsoidalMode( true );
//dist.setProjectionsEnabled( true );
QgsPoint ll = QgsPoint( extent.xMinimum(), extent.yMinimum() );
QgsPoint ul = QgsPoint( extent.xMinimum(), extent.yMaximum() );
double height = dist.measureLine( ll, ul );
Expand Down Expand Up @@ -459,7 +488,7 @@ void GlobePlugin::setupControls()
moveHControls->setPosition( 5, 30 );
moveHControls->setPadding( 6 );

osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() );
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( mOsgViewer->getCameraManipulator() );
//Move Left
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
Expand Down Expand Up @@ -650,7 +679,6 @@ void GlobePlugin::setupControls()
mControlCanvas->addControl( rotateControls );
mControlCanvas->addControl( zoomControls );
mControlCanvas->addControl( extraControls );

}

void GlobePlugin::setupProxy()
Expand Down Expand Up @@ -691,7 +719,7 @@ void GlobePlugin::layersChanged()

if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 )
{
viewer.getDatabasePager()->clear();
mOsgViewer->getDatabasePager()->clear();
}

// Remove elevation layers
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -20,14 +20,15 @@
#define QGS_GLOBE_PLUGIN_H

#include "../qgisplugin.h"
#include "qgsosgviewer.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>
//#include <osgEarthUtil/Controls>
#include "osgEarthUtil/Controls"
#include <osgEarthUtil/ElevationManager>
#include <osgEarthUtil/ObjectPlacer>

Expand Down Expand Up @@ -108,9 +109,7 @@ class GlobePlugin : public QObject, public QgisPlugin
//!pointer to the qaction for this plugin
QAction * mQActionSettingsPointer;
//! OSG Viewer
QgsOsgViewer viewer;
//! Dock widget for viewer
QDockWidgetGlobe *mQDockWidget;
osgViewer::Viewer* mOsgViewer;
//! Settings Dialog
QgsGlobePluginDialog *mSettingsDialog;
//! OSG root node
Expand All @@ -122,7 +121,7 @@ class GlobePlugin : public QObject, public QgisPlugin
//! Tile source
osgEarth::Drivers::QgsOsgEarthTileSource* mTileSource;
//! Control Canvas
osgEarth::Util::Controls::ControlCanvas* mControlCanvas;
osgEarth::Util::Controls21::ControlCanvas* mControlCanvas;
//! Elevation manager
osgEarth::Util::ElevationManager* mElevationManager;
//! Object placer
Expand Down Expand Up @@ -189,7 +188,7 @@ namespace osgEarth
{
namespace Util
{
namespace Controls
namespace Controls21
{
class NavigationControlHandler : public ControlEventHandler
{
Expand Down
33 changes: 17 additions & 16 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -38,9 +38,9 @@
#include <osg/DisplaySettings>

//constructor
QgsGlobePluginDialog::QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget* parent, Qt::WFlags fl )
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mViewer( viewer )
, mViewer( 0 )
{
setupUi( this );
loadStereoConfig(); //values from settings, default values from OSG
Expand Down Expand Up @@ -514,20 +514,21 @@ void QgsGlobePluginDialog::setStereoMode()

void QgsGlobePluginDialog::setStereoConfig()
{
mViewer->getDatabasePager()->clear();
//SETTING THE VALUES IN THE OEGearth instance
setStereoMode();
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
osg::DisplaySettings::instance()->setScreenWidth( screenWidth->value() );
osg::DisplaySettings::instance()->setScreenHeight( screenHeight->value() );
osg::DisplaySettings::instance()->setEyeSeparation( eyeSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( splitStereoHorizontalSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( splitStereoVerticalSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping(
( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) splitStereoHorizontalEyeMapping->currentIndex() );
osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping(
( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) splitStereoVerticalEyeMapping->currentIndex() );

if (mViewer) {
mViewer->getDatabasePager()->clear();
//SETTING THE VALUES IN THE OEGearth instance
setStereoMode();
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
osg::DisplaySettings::instance()->setScreenWidth( screenWidth->value() );
osg::DisplaySettings::instance()->setScreenHeight( screenHeight->value() );
osg::DisplaySettings::instance()->setEyeSeparation( eyeSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( splitStereoHorizontalSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( splitStereoVerticalSeparation->value() );
osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping(
( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) splitStereoHorizontalEyeMapping->currentIndex() );
osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping(
( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) splitStereoVerticalEyeMapping->currentIndex() );
}
}

void QgsGlobePluginDialog::saveStereoConfig()
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -19,7 +19,7 @@
#include <QDialog>
#include <QSettings>
#include <QCheckBox>
#include "qgsosgviewer.h"
#include <osgViewer/Viewer>
#include "qgscontexthelp.h"
#include <qgsproject.h>
#include <qgsvectorlayer.h>
Expand All @@ -29,15 +29,16 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
Q_OBJECT

public:
QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget * parent = 0, Qt::WFlags fl = 0 );
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
~QgsGlobePluginDialog();
void setViewer( osgViewer::Viewer* viewer ) { mViewer = viewer; }
void readElevationDatasources();
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
void updatePointLayers();
QgsVectorLayer* modelLayer();
QString modelPath() { return modelPathLineEdit->text(); }
private:
QgsOsgViewer* mViewer;
osgViewer::Viewer* mViewer;
QSettings settings;
private:
QString openRasterFile();
Expand Down

0 comments on commit 88e3e34

Please sign in to comment.