Skip to content
Permalink
Browse files

Backported osgEarth::QtGui::ViewerWidget and osgEarth::Util::Controls…

… for compatibilty with news OSG and QT version
  • Loading branch information
pka committed Oct 2, 2012
1 parent 8a1ad57 commit 88e3e348df95ab19c944709cb7f45bfaba1977f3
@@ -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
@@ -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)
@@ -58,6 +61,7 @@ TARGET_LINK_LIBRARIES(globeplugin
${OSGDB_LIBRARY}
${OSGGA_LIBRARY}
${OSG_LIBRARY}
${OSGQT_LIBRARY}
${OSGVIEWER_LIBRARY}
${OSGEARTH_LIBRARY}
${OSGEARTHFEATURES_LIBRARY}
@@ -19,6 +19,7 @@
#include "globe_plugin.h"
#include "globe_plugin_dialog.h"
#include "qgsosgearthtilesource.h"
#include "osgEarthQt/ViewerWidget"

#include <cmath>

@@ -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

@@ -74,7 +75,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
, mQGisIface( theQgisInterface )
, mQActionPointer( NULL )
, mQActionSettingsPointer( NULL )
, viewer()
, mOsgViewer( 0 )
, mQgisMapLayer( 0 )
, mTileSource( 0 )
, mElevationManager( NULL )
@@ -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
@@ -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() ) );
@@ -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 & ) ) );
}
@@ -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()
@@ -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() =
@@ -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 );
@@ -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 );
@@ -650,7 +679,6 @@ void GlobePlugin::setupControls()
mControlCanvas->addControl( rotateControls );
mControlCanvas->addControl( zoomControls );
mControlCanvas->addControl( extraControls );

}

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

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

// Remove elevation layers
@@ -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>

@@ -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
@@ -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
@@ -189,7 +188,7 @@ namespace osgEarth
{
namespace Util
{
namespace Controls
namespace Controls21
{
class NavigationControlHandler : public ControlEventHandler
{
@@ -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
@@ -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()
@@ -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>
@@ -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();

0 comments on commit 88e3e34

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