From 540fb7a1b7a06e2bd03616b288a81675ba83cb59 Mon Sep 17 00:00:00 2001 From: Pirmin Kalberer Date: Wed, 13 Jul 2011 01:11:47 +0200 Subject: [PATCH] astyle globe --- src/plugins/globe/globe_plugin.cpp | 391 ++++++++++---------- src/plugins/globe/globe_plugin.h | 67 ++-- src/plugins/globe/globe_plugin_dialog.cpp | 267 ++++++------- src/plugins/globe/globe_plugin_dialog.h | 36 +- src/plugins/globe/qgsosgearthtilesource.cpp | 166 ++++----- src/plugins/globe/qgsosgearthtilesource.h | 39 +- src/plugins/globe/qgsosgviewer.cpp | 88 ++--- src/plugins/globe/qgsosgviewer.h | 88 ++--- 8 files changed, 576 insertions(+), 566 deletions(-) diff --git a/src/plugins/globe/globe_plugin.cpp b/src/plugins/globe/globe_plugin.cpp index 99c04cff8660..d3de0a5e93e3 100644 --- a/src/plugins/globe/globe_plugin.cpp +++ b/src/plugins/globe/globe_plugin.cpp @@ -69,7 +69,7 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI; //constructor GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface ) - : QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ), + : QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ), mQGisIface( theQgisInterface ), mQActionPointer( NULL ), mQActionSettingsPointer( NULL ), @@ -85,8 +85,8 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface ) //needed to be "seen" by other plugins by doing //iface.mainWindow().findChild( QObject, "globePlugin" ) //needed until https://trac.osgeo.org/qgis/changeset/15224 - this->setObjectName("globePlugin"); - this->setParent(theQgisInterface->mainWindow()); + this->setObjectName( "globePlugin" ); + this->setParent( theQgisInterface->mainWindow() ); } //destructor @@ -96,81 +96,81 @@ GlobePlugin::~GlobePlugin() struct PanControlHandler : public NavigationControlHandler { - PanControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } - virtual void onMouseDown( Control* control, int mouseButtonMask ) - { - _manip->pan( _dx, _dy ); - } - private: - osg::observer_ptr _manip; - double _dx; - double _dy; + PanControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } + virtual void onMouseDown( Control* control, int mouseButtonMask ) + { + _manip->pan( _dx, _dy ); + } +private: + osg::observer_ptr _manip; + double _dx; + double _dy; }; struct RotateControlHandler : public NavigationControlHandler { - RotateControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } - virtual void onMouseDown( Control* control, int mouseButtonMask ) + RotateControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } + virtual void onMouseDown( Control* control, int mouseButtonMask ) + { + if ( 0 == _dx && 0 == _dy ) { - if( 0 == _dx && 0 == _dy ) - { - _manip->setRotation( osg::Quat() ); - } - else - { - _manip->rotate( _dx, _dy ); - } + _manip->setRotation( osg::Quat() ); } - private: - osg::observer_ptr _manip; - double _dx; - double _dy; + else + { + _manip->rotate( _dx, _dy ); + } + } +private: + osg::observer_ptr _manip; + double _dx; + double _dy; }; struct ZoomControlHandler : public NavigationControlHandler { - ZoomControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } - virtual void onMouseDown( Control* control, int mouseButtonMask ) - { - _manip->zoom( _dx, _dy ); - } - private: - osg::observer_ptr _manip; - double _dx; - double _dy; + ZoomControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { } + virtual void onMouseDown( Control* control, int mouseButtonMask ) + { + _manip->zoom( _dx, _dy ); + } +private: + osg::observer_ptr _manip; + double _dx; + double _dy; }; struct HomeControlHandler : public NavigationControlHandler { - HomeControlHandler( osgEarth::Util::EarthManipulator* manip ) : _manip( manip ) { } - virtual void onClick( Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) - { - _manip->home( ea, aa ); - } - private: - osg::observer_ptr _manip; + HomeControlHandler( osgEarth::Util::EarthManipulator* manip ) : _manip( manip ) { } + virtual void onClick( Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) + { + _manip->home( ea, aa ); + } +private: + osg::observer_ptr _manip; }; struct RefreshControlHandler : public ControlEventHandler { - RefreshControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { } - virtual void onClick( Control* control, int mouseButtonMask ) - { - mGlobe->layersChanged(); - } - private: - GlobePlugin* mGlobe; + RefreshControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { } + virtual void onClick( Control* control, int mouseButtonMask ) + { + mGlobe->layersChanged(); + } +private: + GlobePlugin* mGlobe; }; struct SyncExtentControlHandler : public ControlEventHandler { - SyncExtentControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { } - virtual void onClick( Control* control, int mouseButtonMask ) - { - mGlobe->syncExtent(); - } - private: - GlobePlugin* mGlobe; + SyncExtentControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { } + virtual void onClick( Control* control, int mouseButtonMask ) + { + mGlobe->syncExtent(); + } +private: + GlobePlugin* mGlobe; }; void GlobePlugin::initGui() @@ -211,7 +211,7 @@ void GlobePlugin::initGui() void GlobePlugin::run() { #ifdef QGISDEBUG - if( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO ); + if ( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO ); #endif mQGisIface->addDockWidget( Qt::RightDockWidgetArea, &mQDockWidget ); @@ -250,8 +250,8 @@ void GlobePlugin::run() viewer.addEventHandler( new KeyboardControlHandler( manip, mQGisIface ) ); viewer.addEventHandler( new QueryCoordinatesHandler( this, mElevationManager, - mMapNode->getMap()->getProfile()->getSRS() ) - ); + mMapNode->getMap()->getProfile()->getSRS() ) + ); // add some stock OSG handlers: viewer.addEventHandler( new osgViewer::StatsHandler() ); @@ -267,7 +267,7 @@ void GlobePlugin::run() void GlobePlugin::settings() { mSettingsDialog.updatePointLayers(); - if( mSettingsDialog.exec() ) + if ( mSettingsDialog.exec() ) { //viewer stereo settings set by mSettingsDialog and stored in QSettings } @@ -278,11 +278,11 @@ void GlobePlugin::setupMap() QSettings settings; QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString(); TMSCacheOptions cacheOptions; - cacheOptions.setPath(cacheDirectory.toStdString()); + cacheOptions.setPath( cacheDirectory.toStdString() ); MapOptions mapOptions; mapOptions.cache() = cacheOptions; - osgEarth::Map *map = new osgEarth::Map(mapOptions); + osgEarth::Map *map = new osgEarth::Map( mapOptions ); //Default image layer GDALOptions driverOptions; @@ -305,7 +305,7 @@ void GlobePlugin::setupMap() mMapNode = new osgEarth::MapNode( map, nodeOptions ); //prefill cache - if( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) ) + if ( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) ) { copyFolder( QgsApplication::pkgDataPath() + "/globe/data/worldwind_srtm", cacheDirectory + "/globe/worldwind_srtm" ); } @@ -352,56 +352,56 @@ void GlobePlugin::projectReady() void GlobePlugin::blankProjectReady() { //needs at least http://trac.osgeo.org/qgis/changeset/14452 mSettingsDialog.elevationDatasources()->clearContents(); - mSettingsDialog.elevationDatasources()->setRowCount(0); + mSettingsDialog.elevationDatasources()->setRowCount( 0 ); } -void GlobePlugin::showCurrentCoordinates(double lon, double lat) +void GlobePlugin::showCurrentCoordinates( double lon, double lat ) { - // show x y on status bar - //OE_NOTICE << "lon: " << lon << " lat: " << lat <extent().height() in meters QgsRectangle extent = mQGisIface->mapCanvas()->extent(); QgsDistanceArea dist; - dist.setProjectionsEnabled(true); - QgsPoint ll = QgsPoint(extent.xMinimum(), extent.yMinimum()); - QgsPoint ul = QgsPoint(extent.xMinimum(), extent.yMaximum()); - double height = dist.measureLine(ll, ul); + dist.setProjectionsEnabled( true ); + QgsPoint ll = QgsPoint( extent.xMinimum(), extent.yMinimum() ); + QgsPoint ul = QgsPoint( extent.xMinimum(), extent.yMaximum() ); + double height = dist.measureLine( ll, ul ); //camera viewing angle double viewAngle = 30; @@ -438,7 +438,7 @@ void GlobePlugin::setupControls() //Horizontal container HBox* moveHControls = new HBox(); moveHControls->setFrame( new RoundedFrame() ); - moveHControls->getFrame()->setBackColor(1,1,1,0.5); + moveHControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); moveHControls->setMargin( 0 ); //moveHControls->setChildSpacing( 47 ); moveHControls->setVertAlign( Control::ALIGN_CENTER ); @@ -460,7 +460,7 @@ void GlobePlugin::setupControls() //Vertical container VBox* moveVControls = new VBox(); moveVControls->setFrame( new RoundedFrame() ); - moveVControls->getFrame()->setBackColor(1,1,1,0.5); + moveVControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); moveVControls->setMargin( 0 ); //moveVControls->setChildSpacing( 36 ); moveVControls->setVertAlign( Control::ALIGN_CENTER ); @@ -490,7 +490,7 @@ void GlobePlugin::setupControls() //Horizontal container HBox* rotateControls = new HBox(); rotateControls->setFrame( new RoundedFrame() ); - rotateControls->getFrame()->setBackColor(1,1,1,0.5); + rotateControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); rotateControls->setMargin( 0 ); //rotateControls->setChildSpacing( 10 ); rotateControls->setVertAlign( Control::ALIGN_CENTER ); @@ -524,7 +524,7 @@ void GlobePlugin::setupControls() //Vertical container VBox* tiltControls = new VBox(); tiltControls->setFrame( new RoundedFrame() ); - tiltControls->getFrame()->setBackColor(1,1,1,0.5); + tiltControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); tiltControls->setMargin( 0 ); //tiltControls->setChildSpacing( 30 ); tiltControls->setVertAlign( Control::ALIGN_CENTER ); @@ -552,7 +552,7 @@ void GlobePlugin::setupControls() //Vertical container VBox* zoomControls = new VBox(); zoomControls->setFrame( new RoundedFrame() ); - zoomControls->getFrame()->setBackColor(1,1,1,0.5); + zoomControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); zoomControls->setMargin( 0 ); //zoomControls->setChildSpacing( 5 ); zoomControls->setVertAlign( Control::ALIGN_CENTER ); @@ -580,7 +580,7 @@ void GlobePlugin::setupControls() //Horizontal container HBox* extraControls = new HBox(); extraControls->setFrame( new RoundedFrame() ); - extraControls->getFrame()->setBackColor(1,1,1,0.5); + extraControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); extraControls->setMargin( 0 ); //extraControls->setChildSpacing( 10 ); extraControls->setVertAlign( Control::ALIGN_CENTER ); @@ -624,11 +624,11 @@ void GlobePlugin::setupProxy() { QSettings settings; settings.beginGroup( "proxy" ); - if( settings.value( "/proxyEnabled" ).toBool() ) + if ( settings.value( "/proxyEnabled" ).toBool() ) { ProxySettings proxySettings( settings.value( "/proxyHost" ).toString().toStdString(), settings.value( "/proxyPort" ).toInt() ); - if( !settings.value( "/proxyUser" ).toString().isEmpty() ) + if ( !settings.value( "/proxyUser" ).toString().isEmpty() ) { QString auth = settings.value( "/proxyUser" ).toString() + ":" + settings.value( "/proxyPassword" ).toString(); #ifdef WIN32 @@ -651,11 +651,12 @@ void GlobePlugin::extentsChanged() void GlobePlugin::layersChanged() { - if ( mIsGlobeRunning ){ + if ( mIsGlobeRunning ) + { QgsDebugMsg( "layersChanged: Globe Running, executing" ); osg::ref_ptr map = mMapNode->getMap(); - if( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1) + if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 ) { viewer.getDatabasePager()->clear(); } @@ -663,7 +664,7 @@ void GlobePlugin::layersChanged() // Remove elevation layers ElevationLayerVector list; map->getElevationLayers( list ); - for( ElevationLayerVector::iterator i = list.begin(); i != list.end(); i++ ) + for ( ElevationLayerVector::iterator i = list.begin(); i != list.end(); i++ ) { map->removeElevationLayer( *i ); } @@ -672,14 +673,14 @@ void GlobePlugin::layersChanged() QSettings settings; QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString(); QTableWidget* table = mSettingsDialog.elevationDatasources(); - for(int i = 0; i < table->rowCount(); ++i) + for ( int i = 0; i < table->rowCount(); ++i ) { - QString type = table->item(i, 0)->text(); - bool cache = table->item(i, 1)->checkState(); - QString uri = table->item(i, 2)->text(); + QString type = table->item( i, 0 )->text(); + bool cache = table->item( i, 1 )->checkState(); + QString uri = table->item( i, 2 )->text(); ElevationLayer* layer = 0; - if( "Raster" == type) + if ( "Raster" == type ) { GDALOptions options; options.url() = uri.toStdString(); @@ -691,8 +692,8 @@ void GlobePlugin::layersChanged() options.elevationCachePath() = cacheDirectory.toStdString() + "/globe/worldwind_srtm"; layer = new osgEarth::ElevationLayer( "WorldWind bil", options ); TerrainEngineNode* terrainEngineNode = mMapNode->getTerrainEngine(); - terrainEngineNode->setVerticalScale(2); - terrainEngineNode->setElevationSamplingRatio(0.25); + terrainEngineNode->setVerticalScale( 2 ); + terrainEngineNode->setElevationSamplingRatio( 0.25 ); } else if ( "TMS" == type ) { @@ -706,7 +707,7 @@ void GlobePlugin::layersChanged() } //remove QGIS layer - if( mQgisMapLayer ) + if ( mQgisMapLayer ) { QgsDebugMsg( "removeMapLayer" ); map->removeImageLayer( mQgisMapLayer ); @@ -759,15 +760,15 @@ void GlobePlugin::placeNode( osg::Node* node, double lat, double lon, double alt void GlobePlugin::copyFolder( QString sourceFolder, QString destFolder ) { QDir sourceDir( sourceFolder ); - if( !sourceDir.exists() ) + if ( !sourceDir.exists() ) return; QDir destDir( destFolder ); - if( !destDir.exists() ) + if ( !destDir.exists() ) { destDir.mkpath( destFolder ); } QStringList files = sourceDir.entryList( QDir::Files ); - for( int i = 0; i < files.count(); i++ ) + for ( int i = 0; i < files.count(); i++ ) { QString srcName = sourceFolder + "/" + files[i]; QString destName = destFolder + "/" + files[i]; @@ -775,7 +776,7 @@ void GlobePlugin::copyFolder( QString sourceFolder, QString destFolder ) } files.clear(); files = sourceDir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot ); - for( int i = 0; i < files.count(); i++ ) + for ( int i = 0; i < files.count(); i++ ) { QString srcName = sourceFolder + "/" + files[i]; QString destName = destFolder + "/" + files[i]; @@ -791,36 +792,36 @@ void GlobePlugin::setGlobeNotRunning() bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx ) { - switch( ea.getEventType() ) + switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::PUSH: _mouse_down_event = &ea; break; case osgGA::GUIEventAdapter::FRAME: - if( _mouse_down_event ) + if ( _mouse_down_event ) { _mouse_down_event = &ea; } break; case osgGA::GUIEventAdapter::RELEASE: - for( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i ) + for ( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i ) { NavigationControlHandler* handler = dynamic_cast( i->get() ); - if( handler ) + if ( handler ) { - handler->onClick( this, ea.getButtonMask(), ea, aa ); + handler->onClick( this, ea.getButtonMask(), ea, aa ); } } _mouse_down_event = NULL; break; } - if( _mouse_down_event ) + if ( _mouse_down_event ) { //OE_NOTICE << "NavigationControl::handle getEventType " << ea.getEventType() << std::endl; - for( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i ) + for ( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i ) { NavigationControlHandler* handler = dynamic_cast( i->get() ); - if( handler ) + if ( handler ) { handler->onMouseDown( this, ea.getButtonMask() ); } @@ -874,56 +875,56 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU */ - switch( ea.getEventType() ) + switch ( ea.getEventType() ) { case( osgGA::GUIEventAdapter::KEYDOWN ) : { //move map - if( ea.getKey() == '4' ) + if ( ea.getKey() == '4' ) { _manip->pan( -MOVE_OFFSET, 0 ); } - if( ea.getKey() == '6' ) + if ( ea.getKey() == '6' ) { _manip->pan( MOVE_OFFSET, 0 ); } - if( ea.getKey() == '2' ) + if ( ea.getKey() == '2' ) { _manip->pan( 0, MOVE_OFFSET ); } - if( ea.getKey() == '8' ) + if ( ea.getKey() == '8' ) { _manip->pan( 0, -MOVE_OFFSET ); } //rotate - if( ea.getKey() == '/' ) + if ( ea.getKey() == '/' ) { _manip->rotate( MOVE_OFFSET, 0 ); } - if( ea.getKey() == '*' ) + if ( ea.getKey() == '*' ) { _manip->rotate( -MOVE_OFFSET, 0 ); } //tilt - if( ea.getKey() == '9' ) + if ( ea.getKey() == '9' ) { _manip->rotate( 0, MOVE_OFFSET ); } - if( ea.getKey() == '3' ) + if ( ea.getKey() == '3' ) { _manip->rotate( 0, -MOVE_OFFSET ); } //zoom - if( ea.getKey() == '-' ) + if ( ea.getKey() == '-' ) { _manip->zoom( 0, MOVE_OFFSET ); } - if( ea.getKey() == '+' ) + if ( ea.getKey() == '+' ) { _manip->zoom( 0, -MOVE_OFFSET ); } //reset - if( ea.getKey() == '5' ) + if ( ea.getKey() == '5' ) { //_manip->zoom( 0, 0 ); } @@ -938,7 +939,7 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { - if( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' ) + if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' ) { mGlobe->syncExtent(); } @@ -947,78 +948,78 @@ bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct bool QueryCoordinatesHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { - if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE) - { - osgViewer::View* view = static_cast(aa.asView()); - osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false ); - mGlobe->showCurrentCoordinates( coords.x(), coords.y() ); - } - if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH - && ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) - { - osgViewer::View* view = static_cast(aa.asView()); - osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false ); + if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE ) + { + osgViewer::View* view = static_cast( aa.asView() ); + osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false ); + mGlobe->showCurrentCoordinates( coords.x(), coords.y() ); + } + if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH + && ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON ) + { + osgViewer::View* view = static_cast( aa.asView() ); + osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false ); - OE_NOTICE << "SelectedCoordinates set to:\nLon: " << coords.x() << " Lat: " << coords.y() - << " Ele: " << coords.z() << std::endl; + OE_NOTICE << "SelectedCoordinates set to:\nLon: " << coords.x() << " Lat: " << coords.y() + << " Ele: " << coords.z() << std::endl; - mGlobe->setSelectedCoordinates( coords ); + mGlobe->setSelectedCoordinates( coords ); - if (ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL) - //ctrl + rightclick pops up a QMessageBox - { - mGlobe->showSelectedCoordinates(); - } + if ( ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL ) + //ctrl + rightclick pops up a QMessageBox + { + mGlobe->showSelectedCoordinates(); } + } - return false; + return false; } -osg::Vec3d QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view, bool getElevation) +osg::Vec3d QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view, bool getElevation ) { - osgUtil::LineSegmentIntersector::Intersections results; - if ( view->computeIntersections( x, y, results, 0x01 ) ) - { - // find the first hit under the mouse: - osgUtil::LineSegmentIntersector::Intersection first = *(results.begin()); - osg::Vec3d point = first.getWorldIntersectPoint(); - - // transform it to map coordinates: - double lat_rad, lon_rad, height; - _mapSRS->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height ); + osgUtil::LineSegmentIntersector::Intersections results; + if ( view->computeIntersections( x, y, results, 0x01 ) ) + { + // find the first hit under the mouse: + osgUtil::LineSegmentIntersector::Intersection first = *( results.begin() ); + osg::Vec3d point = first.getWorldIntersectPoint(); - // query the elevation at the map point: - double lon_deg = osg::RadiansToDegrees( lon_rad ); - double lat_deg = osg::RadiansToDegrees( lat_rad ); - double elevation = -99999; + // transform it to map coordinates: + double lat_rad, lon_rad, height; + _mapSRS->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height ); - if(getElevation) - { - osg::Matrixd out_mat; - double query_resolution = 0.1; // 1/10th of a degree - double out_resolution = 0.0; - - //TODO test elevation calculation - //@see https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_elevation/osgearth_elevation.cpp - if (_elevMan->getPlacementMatrix( - lon_deg, lat_deg, 0, - query_resolution, _mapSRS, - //query_resolution, NULL, - out_mat, elevation, out_resolution ) ) - { - OE_NOTICE << "Elevation at " << lon_deg << ", " << lat_deg - << " is " << elevation << std::endl; - } - else - { - OE_NOTICE << "getElevation FAILED! at (" << lon_deg << ", " - << lat_deg << ")" << std::endl; - } - } + // query the elevation at the map point: + double lon_deg = osg::RadiansToDegrees( lon_rad ); + double lat_deg = osg::RadiansToDegrees( lat_rad ); + double elevation = -99999; - osg::Vec3d coords = osg::Vec3d(lon_deg, lat_deg, elevation); - return coords; + if ( getElevation ) + { + osg::Matrixd out_mat; + double query_resolution = 0.1; // 1/10th of a degree + double out_resolution = 0.0; + + //TODO test elevation calculation + //@see https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_elevation/osgearth_elevation.cpp + if ( _elevMan->getPlacementMatrix( + lon_deg, lat_deg, 0, + query_resolution, _mapSRS, + //query_resolution, NULL, + out_mat, elevation, out_resolution ) ) + { + OE_NOTICE << "Elevation at " << lon_deg << ", " << lat_deg + << " is " << elevation << std::endl; + } + else + { + OE_NOTICE << "getElevation FAILED! at (" << lon_deg << ", " + << lat_deg << ")" << std::endl; + } } + + osg::Vec3d coords = osg::Vec3d( lon_deg, lat_deg, elevation ); + return coords; + } } /** diff --git a/src/plugins/globe/globe_plugin.h b/src/plugins/globe/globe_plugin.h index 08a6ed5e907d..de58c47b3267 100644 --- a/src/plugins/globe/globe_plugin.h +++ b/src/plugins/globe/globe_plugin.h @@ -38,7 +38,7 @@ class QgisInterface; class GlobePlugin : public QObject, public QgisPlugin { - Q_OBJECT + Q_OBJECT public: GlobePlugin( QgisInterface* theQgisInterface ); @@ -76,7 +76,7 @@ class GlobePlugin : public QObject, public QgisPlugin //! prints the ccordinates in a QMessageBox void showSelectedCoordinates(); //! emits signal with current mouse coordinates - void showCurrentCoordinates(double lon, double lat); + void showCurrentCoordinates( double lon, double lat ); //! get longitude of user right click double getSelectedLon(); //! get latitude of user right click @@ -89,7 +89,7 @@ class GlobePlugin : public QObject, public QgisPlugin void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 ); //! Recursive copy folder - static void copyFolder(QString sourceFolder, QString destFolder); + static void copyFolder( QString sourceFolder, QString destFolder ); private: //! Set HTTP proxy settings @@ -132,7 +132,7 @@ class GlobePlugin : public QObject, public QgisPlugin //! coordinates of the right-clicked point on the globe double mSelectedLat, mSelectedLon, mSelectedElevation; -signals: + signals: //! emits current mouse position void xyCoordinates( const QgsPoint & p ); //! emits position of right click on globe @@ -142,27 +142,27 @@ class GlobePlugin : public QObject, public QgisPlugin class FlyToExtentHandler : public osgGA::GUIEventHandler { public: - FlyToExtentHandler( GlobePlugin* globe ) : mGlobe ( globe ) { } + FlyToExtentHandler( GlobePlugin* globe ) : mGlobe( globe ) { } bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); private: - GlobePlugin* mGlobe; + GlobePlugin* mGlobe; }; // An event handler that will print out the coordinates at the clicked point class QueryCoordinatesHandler : public osgGA::GUIEventHandler { -public: + public: QueryCoordinatesHandler( GlobePlugin* globe, osgEarth::Util::ElevationManager* elevMan, const osgEarth::SpatialReference* mapSRS ) - : mGlobe ( globe ), _elevMan(elevMan), _mapSRS( mapSRS ), _mouseDown( false ) { } + : mGlobe( globe ), _elevMan( elevMan ), _mapSRS( mapSRS ), _mouseDown( false ) { } - bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); + bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); - virtual osg::Vec3d getCoords( float x, float y, osgViewer::View* view, bool getElevation = false); + virtual osg::Vec3d getCoords( float x, float y, osgViewer::View* view, bool getElevation = false ); -private: + private: GlobePlugin* mGlobe; osg::ref_ptr _mapSRS; osg::ref_ptr _elevMan; @@ -173,7 +173,7 @@ class QueryCoordinatesHandler : public osgGA::GUIEventHandler class KeyboardControlHandler : public osgGA::GUIEventHandler { public: - KeyboardControlHandler( osgEarth::Util::EarthManipulator* manip, QgisInterface *qGisIface ) : _manip(manip), mQGisIface(qGisIface) { } + KeyboardControlHandler( osgEarth::Util::EarthManipulator* manip, QgisInterface *qGisIface ) : _manip( manip ), mQGisIface( qGisIface ) { } bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); @@ -185,29 +185,32 @@ class KeyboardControlHandler : public osgGA::GUIEventHandler }; -namespace osgEarth { namespace Util +namespace osgEarth { - namespace Controls + namespace Util { - class NavigationControlHandler : public ControlEventHandler + namespace Controls { - public: - virtual void onMouseDown( class Control* control, int mouseButtonMask ) { } - virtual void onClick( class Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { } - }; - - class NavigationControl : public ImageControl - { - public: - NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {} - - protected: - virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx ); - - private: - osg::ref_ptr _mouse_down_event; - }; + class NavigationControlHandler : public ControlEventHandler + { + public: + virtual void onMouseDown( class Control* control, int mouseButtonMask ) { } + virtual void onClick( class Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { } + }; + + class NavigationControl : public ImageControl + { + public: + NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {} + + protected: + virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx ); + + private: + osg::ref_ptr _mouse_down_event; + }; + } } -} } +} #endif // QGS_GLOBE_PLUGIN_H diff --git a/src/plugins/globe/globe_plugin_dialog.cpp b/src/plugins/globe/globe_plugin_dialog.cpp index d32811a189a1..ed4c660dca7d 100644 --- a/src/plugins/globe/globe_plugin_dialog.cpp +++ b/src/plugins/globe/globe_plugin_dialog.cpp @@ -42,7 +42,7 @@ //constructor QgsGlobePluginDialog::QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget* parent, Qt::WFlags fl ) -: mViewer(viewer), QDialog( parent, fl ) + : mViewer( viewer ), QDialog( parent, fl ) { setupUi( this ); loadStereoConfig(); //values from settings, default values from OSG @@ -63,12 +63,12 @@ QString QgsGlobePluginDialog::openRasterFile() const char* filter = "GDAL files (*.dem *.tif *.tiff *.jpg *.jpeg *.asc) \ ;;DEM files (*.dem) \ ;;All files (*.*)"; -QString path = QFileDialog::getOpenFileName( this, - tr( "Open raster file" ), - QDir::homePath (), - tr( filter ) ); + QString path = QFileDialog::getOpenFileName( this, + tr( "Open raster file" ), + QDir::homePath(), + tr( filter ) ); -return path; + return path; } bool QgsGlobePluginDialog::validateResource( QString type, QString uri, QString &error ) @@ -82,34 +82,34 @@ bool QgsGlobePluginDialog::validateResource( QString type, QString uri, QString } else { - error = tr("Invalid Path: The file is either unreadable or does not exist"); + error = tr( "Invalid Path: The file is either unreadable or does not exist" ); return false; } } else { - QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkAccessManager *manager = new QNetworkAccessManager( this ); QNetworkRequest request; - request.setUrl(QUrl(uri)); - QNetworkReply *reply = manager->get(request); + request.setUrl( QUrl( uri ) ); + QNetworkReply *reply = manager->get( request ); //wait for response syncronously QEventLoop eLoop; connect( manager, SIGNAL( finished( QNetworkReply * ) ), - &eLoop, SLOT( quit() ) ); - eLoop.exec(QEventLoop::ExcludeUserInputEvents); + &eLoop, SLOT( quit() ) ); + eLoop.exec( QEventLoop::ExcludeUserInputEvents ); - if (QNetworkReply::HostNotFoundError != reply->error()) + if ( QNetworkReply::HostNotFoundError != reply->error() ) //FIXME:should be the following line but reply->error() always give "unknown error" - //if (QNetworkReply::NoError == reply->error()) + //if (QNetworkReply::NoError == reply->error()) { QByteArray data = reply->readAll(); - QString req(data); + QString req( data ); return true; } else { - error = tr("Invalid URL: ") + reply->errorString(); + error = tr( "Invalid URL: " ) + reply->errorString(); return false; } } @@ -118,7 +118,7 @@ bool QgsGlobePluginDialog::validateResource( QString type, QString uri, QString void QgsGlobePluginDialog::showMessageBox( QString text ) { QMessageBox msgBox; - msgBox.setText(text); + msgBox.setText( text ); msgBox.exec(); } @@ -140,24 +140,24 @@ void QgsGlobePluginDialog::on_buttonBox_rejected() } //ELEVATION -void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged(QString type) +void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged( QString type ) { - elevationPath->setEnabled(true); - if("Raster" == type) + elevationPath->setEnabled( true ); + if ( "Raster" == type ) { - elevationActions->setCurrentIndex(0); + elevationActions->setCurrentIndex( 0 ); elevationPath->setText( QDir::homePath() ); } else if ( "Worldwind" == type ) { - elevationActions->setCurrentIndex(1); - elevationPath->setText("http://tileservice.worldwindcentral.com/getTile?bmng.topo.bathy.200401"); - elevationPath->setEnabled(false); + elevationActions->setCurrentIndex( 1 ); + elevationPath->setText( "http://tileservice.worldwindcentral.com/getTile?bmng.topo.bathy.200401" ); + elevationPath->setEnabled( false ); } else if ( "TMS" == type ) { - elevationActions->setCurrentIndex(1); - elevationPath->setText("http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml"); + elevationActions->setCurrentIndex( 1 ); + elevationPath->setText( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" ); } } @@ -179,21 +179,21 @@ void QgsGlobePluginDialog::on_elevationAdd_clicked() msgBox.setText( errorText ); msgBox.setInformativeText( tr( "Do you want to add the datasource anyway?" ) ); msgBox.setIcon( QMessageBox::Warning ); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); + msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel ); + msgBox.setDefaultButton( QMessageBox::Cancel ); if ( validationResult || msgBox.exec() == QMessageBox::Ok ) { int i = elevationDatasourcesWidget->rowCount(); - QTableWidgetItem *type = new QTableWidgetItem(elevationCombo->currentText()); - QTableWidgetItem *uri = new QTableWidgetItem(elevationPath->text()); + 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 - elevationDatasourcesWidget->setRowCount(1+i); - elevationDatasourcesWidget->setItem(i, 0, type); - elevationDatasourcesWidget->setItem(i, 1, cache); - elevationDatasourcesWidget->setItem(i, 2, uri); - elevationDatasourcesWidget->setCurrentItem(type, QItemSelectionModel::Clear); + 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 ); + elevationDatasourcesWidget->setItem( i, 2, uri ); + elevationDatasourcesWidget->setCurrentItem( type, QItemSelectionModel::Clear ); } } @@ -212,44 +212,44 @@ void QgsGlobePluginDialog::on_elevationDown_clicked() moveRow( elevationDatasourcesWidget, false ); } -void QgsGlobePluginDialog::moveRow(QTableWidget* widget, bool up) +void QgsGlobePluginDialog::moveRow( QTableWidget* widget, bool up ) { //moves QTableWidget row up or down if ( widget->selectedItems().count() > 0 ) { const int sourceRow = widget->currentItem()->row(); - const int destRow = (up ? sourceRow-1 : sourceRow+1); + const int destRow = ( up ? sourceRow - 1 : sourceRow + 1 ); if ( destRow >= 0 && destRow < widget->rowCount() ) { // take whole rows - QList sourceItems = takeRow(widget, sourceRow); - QList destItems = takeRow(widget, destRow); + QList sourceItems = takeRow( widget, sourceRow ); + QList destItems = takeRow( widget, destRow ); // set back in reverse order - setRow(widget, sourceRow, destItems); - setRow(widget, destRow, sourceItems); - widget->selectRow(destRow); + setRow( widget, sourceRow, destItems ); + setRow( widget, destRow, sourceItems ); + widget->selectRow( destRow ); } } } -QList QgsGlobePluginDialog::takeRow(QTableWidget* widget, int row) +QList QgsGlobePluginDialog::takeRow( QTableWidget* widget, int row ) { // takes and returns the whole row QList rowItems; - for (int col = 0; col < widget->columnCount(); ++col) + for ( int col = 0; col < widget->columnCount(); ++col ) { - rowItems << widget->takeItem(row, col); + rowItems << widget->takeItem( row, col ); } return rowItems; } -void QgsGlobePluginDialog::setRow(QTableWidget* widget, int row, const QList& rowItems) +void QgsGlobePluginDialog::setRow( QTableWidget* widget, int row, const QList& rowItems ) { // sets the whole row - for (int col = 0; col < widget->columnCount(); ++col) + for ( int col = 0; col < widget->columnCount(); ++col ) { - widget->setItem(row, col, rowItems.at(col)); + widget->setItem( row, col, rowItems.at( col ) ); } } @@ -258,65 +258,68 @@ void QgsGlobePluginDialog::readElevationDatasources() //showMessageBox("reading"); // clear the widget elevationDatasourcesWidget->clearContents(); - int keysCount = QgsProject::instance()->subkeyList("Globe-Plugin", "/elevationDatasources/").count(); - for (int i = 0; i < keysCount; ++i) { + int keysCount = QgsProject::instance()->subkeyList( "Globe-Plugin", "/elevationDatasources/" ).count(); + for ( int i = 0; i < keysCount; ++i ) + { QString iNum; - iNum.setNum(i); + iNum.setNum( i ); QTableWidgetItem *type = new QTableWidgetItem( - QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type")); + 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"); + QgsProject::instance()->readEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/uri" ) ); + bool cache = QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/cache" ); - elevationDatasourcesWidget->setRowCount(1+i); - elevationDatasourcesWidget->setItem(i, 0, type); + elevationDatasourcesWidget->setRowCount( 1 + i ); + elevationDatasourcesWidget->setItem( i, 0, type ); QTableWidgetItem* chkBoxItem = new QTableWidgetItem(); chkBoxItem->setCheckState( cache ? Qt::Checked : Qt::Unchecked ); - elevationDatasourcesWidget->setItem(i, 1, chkBoxItem); - elevationDatasourcesWidget->setItem(i, 2, uri); + elevationDatasourcesWidget->setItem( i, 1, chkBoxItem ); + elevationDatasourcesWidget->setItem( i, 2, uri ); } } void QgsGlobePluginDialog::saveElevationDatasources() { bool somethingChanged = false; - int keysCount = QgsProject::instance()->subkeyList("Globe-Plugin", "/elevationDatasources/").count(); + int keysCount = QgsProject::instance()->subkeyList( "Globe-Plugin", "/elevationDatasources/" ).count(); int rowsCount = elevationDatasourcesWidget->rowCount(); - for (int i = 0; i < rowsCount; ++i) { + for ( int i = 0; i < rowsCount; ++i ) + { QString iNum; - iNum.setNum(i); - QString typeKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type"); - QString uriKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri"); - bool cacheKey = QgsProject::instance()->readBoolEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache"); + iNum.setNum( i ); + QString typeKey = QgsProject::instance()->readEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/type" ); + QString uriKey = QgsProject::instance()->readEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/uri" ); + bool cacheKey = QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/cache" ); - QString type = elevationDatasourcesWidget->item(i, 0)->text(); - QString uri = elevationDatasourcesWidget->item(i, 2)->text(); - bool cache = elevationDatasourcesWidget->item(i, 1)->checkState(); + QString type = elevationDatasourcesWidget->item( i, 0 )->text(); + QString uri = elevationDatasourcesWidget->item( i, 2 )->text(); + bool cache = elevationDatasourcesWidget->item( i, 1 )->checkState(); if ( typeKey != type || uriKey != uri || cacheKey != cache ) { somethingChanged = true; - QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type", type); - QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri); - QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache); - QgsDebugMsg( "editing at "+iNum ); + QgsProject::instance()->writeEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/type", type ); + QgsProject::instance()->writeEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/uri", uri ); + QgsProject::instance()->writeEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/cache", cache ); + QgsDebugMsg( "editing at " + iNum ); } else { - QgsDebugMsg( "nothing to do at "+iNum ); + QgsDebugMsg( "nothing to do at " + iNum ); } } - if (keysCount > rowsCount ) + if ( keysCount > rowsCount ) { //elminate superfluous keys somethingChanged = true; - for (int i = rowsCount; i < keysCount; ++i) { + for ( int i = rowsCount; i < keysCount; ++i ) + { QString iNum; - iNum.setNum(i); - QgsDebugMsg( "deleting "+iNum ); - QgsProject::instance()->removeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/"); + iNum.setNum( i ); + QgsDebugMsg( "deleting " + iNum ); + QgsProject::instance()->removeEntry( "Globe-Plugin", "/elevationDatasources/L" + iNum + "/" ); } } @@ -333,19 +336,19 @@ QList QgsGlobePluginDialog::pointLayers() { QList list; QMap< QString, QgsMapLayer *> layers = QgsMapLayerRegistry::instance()->mapLayers(); - QMapIterator it(layers); - while (it.hasNext()) + QMapIterator it( layers ); + while ( it.hasNext() ) { - it.next(); - QgsMapLayer* layer = it.value(); - if (layer->type() == QgsMapLayer::VectorLayer) - { - QgsVectorLayer* vectorLayer = static_cast(layer); - if ( vectorLayer->geometryType() == QGis::Point ) - { - list.append( vectorLayer ); - } - } + it.next(); + QgsMapLayer* layer = it.value(); + if ( layer->type() == QgsMapLayer::VectorLayer ) + { + QgsVectorLayer* vectorLayer = static_cast( layer ); + if ( vectorLayer->geometryType() == QGis::Point ) + { + list.append( vectorLayer ); + } + } } return list; } @@ -354,11 +357,11 @@ void QgsGlobePluginDialog::updatePointLayers() { modelLayerCombo->clear(); QList layers = pointLayers(); - QListIterator it(layers); - while (it.hasNext()) + QListIterator it( layers ); + while ( it.hasNext() ) { - QgsVectorLayer* layer = it.next(); - modelLayerCombo->addItem( layer->name() ); + QgsVectorLayer* layer = it.next(); + modelLayerCombo->addItem( layer->name() ); } } @@ -374,9 +377,9 @@ void QgsGlobePluginDialog::on_modelBrowse_clicked() const char* filter = "Model files (*.3dc *.asc *.3ds *.ac *.bsp *.dae *.dw *.dxf *.fbx *.gem *.geo *.iv *.wrl *.ive *.logo *.lwo *.lw *.geo *.lws *.md2 *.obj *.ogr *.flt *.osg *.shp *.stl *.sta *.wrl *.x) \ ;;All files (*.*)"; QString path = QFileDialog::getOpenFileName( this, - tr( "Open 3D model file" ), - QDir::homePath (), - tr( filter ) ); + tr( "Open 3D model file" ), + QDir::homePath(), + tr( filter ) ); if ( ! path.isEmpty() ) { @@ -389,85 +392,85 @@ void QgsGlobePluginDialog::on_modelBrowse_clicked() void QgsGlobePluginDialog::on_resetStereoDefaults_clicked() { //http://www.openscenegraph.org/projects/osg/wiki/Support/UserGuides/StereoSettings - comboStereoMode->setCurrentIndex( comboStereoMode->findText("OFF") ); + comboStereoMode->setCurrentIndex( comboStereoMode->findText( "OFF" ) ); screenDistance->setValue( 0.5 ); screenHeight->setValue( 0.26 ); screenWidth->setValue( 0.325 ); - eyeSeparation->setValue( 0.06); + eyeSeparation->setValue( 0.06 ); splitStereoHorizontalSeparation->setValue( 42 ); splitStereoVerticalSeparation->setValue( 42 ); splitStereoHorizontalEyeMapping->setCurrentIndex( 0 ); splitStereoVerticalEyeMapping->setCurrentIndex( 0 ); } -void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged(QString value) +void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged( QString value ) { setStereoMode(); updateStereoDialog(); } -void QgsGlobePluginDialog::on_eyeSeparation_valueChanged(double value) +void QgsGlobePluginDialog::on_eyeSeparation_valueChanged( double value ) { osg::DisplaySettings::instance()->setEyeSeparation( value ); } -void QgsGlobePluginDialog::on_screenDistance_valueChanged(double value) +void QgsGlobePluginDialog::on_screenDistance_valueChanged( double value ) { osg::DisplaySettings::instance()->setScreenDistance( value ); } -void QgsGlobePluginDialog::on_screenWidth_valueChanged(double value) +void QgsGlobePluginDialog::on_screenWidth_valueChanged( double value ) { osg::DisplaySettings::instance()->setScreenWidth( value ); } -void QgsGlobePluginDialog::on_screenHeight_valueChanged(double value) +void QgsGlobePluginDialog::on_screenHeight_valueChanged( double value ) { osg::DisplaySettings::instance()->setScreenHeight( value ); } -void QgsGlobePluginDialog::on_splitStereoHorizontalSeparation_valueChanged(int value) +void QgsGlobePluginDialog::on_splitStereoHorizontalSeparation_valueChanged( int value ) { osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( value ); } -void QgsGlobePluginDialog::on_splitStereoVerticalSeparation_valueChanged(int value) +void QgsGlobePluginDialog::on_splitStereoVerticalSeparation_valueChanged( int value ) { osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( value ); } -void QgsGlobePluginDialog::on_splitStereoHorizontalEyeMapping_currentIndexChanged(int value) +void QgsGlobePluginDialog::on_splitStereoHorizontalEyeMapping_currentIndexChanged( int value ) { osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping( - (osg::DisplaySettings::SplitStereoHorizontalEyeMapping) value ); + ( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) value ); } -void QgsGlobePluginDialog::on_splitStereoVerticalEyeMapping_currentIndexChanged(int value) +void QgsGlobePluginDialog::on_splitStereoVerticalEyeMapping_currentIndexChanged( int value ) { osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping( - (osg::DisplaySettings::SplitStereoVerticalEyeMapping) value ); + ( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) value ); } void QgsGlobePluginDialog::loadStereoConfig() { comboStereoMode->setCurrentIndex( comboStereoMode->findText( settings.value( "/Plugin-Globe/stereoMode", - "OFF" ).toString() ) ); + "OFF" ).toString() ) ); screenDistance->setValue( settings.value( "/Plugin-Globe/screenDistance", - osg::DisplaySettings::instance()->getScreenDistance() ).toDouble() ); + osg::DisplaySettings::instance()->getScreenDistance() ).toDouble() ); screenWidth->setValue( settings.value( "/Plugin-Globe/screenWidth", - osg::DisplaySettings::instance()->getScreenWidth() ).toDouble() ); + osg::DisplaySettings::instance()->getScreenWidth() ).toDouble() ); screenHeight->setValue( settings.value( "/Plugin-Globe/screenHeight", osg::DisplaySettings::instance()->getScreenHeight() ).toDouble() ); eyeSeparation->setValue( settings.value( "/Plugin-Globe/eyeSeparation", - osg::DisplaySettings::instance()->getEyeSeparation() ).toDouble() ); + osg::DisplaySettings::instance()->getEyeSeparation() ).toDouble() ); splitStereoHorizontalSeparation->setValue( settings.value( "/Plugin-Globe/splitStereoHorizontalSeparation", - osg::DisplaySettings::instance()->getSplitStereoHorizontalSeparation() ).toInt() ); + osg::DisplaySettings::instance()->getSplitStereoHorizontalSeparation() ).toInt() ); splitStereoVerticalSeparation->setValue( settings.value( "/Plugin-Globe/splitStereoVerticalSeparation", - osg::DisplaySettings::instance()->getSplitStereoVerticalSeparation() ).toInt() ); + osg::DisplaySettings::instance()->getSplitStereoVerticalSeparation() ).toInt() ); splitStereoHorizontalEyeMapping->setCurrentIndex( settings.value( "/Plugin-Globe/splitStereoHorizontalEyeMapping", - osg::DisplaySettings::instance()->getSplitStereoHorizontalEyeMapping() ).toInt() ); + osg::DisplaySettings::instance()->getSplitStereoHorizontalEyeMapping() ).toInt() ); splitStereoVerticalEyeMapping->setCurrentIndex( settings.value( "/Plugin-Globe/splitStereoVerticalEyeMapping", - osg::DisplaySettings::instance()->getSplitStereoVerticalEyeMapping() ).toInt() ); + osg::DisplaySettings::instance()->getSplitStereoVerticalEyeMapping() ).toInt() ); } void QgsGlobePluginDialog::setStereoMode() @@ -476,7 +479,7 @@ void QgsGlobePluginDialog::setStereoMode() //http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00181.html QString stereoMode = comboStereoMode->currentText() ; - if("OFF" == stereoMode) + if ( "OFF" == stereoMode ) { osg::DisplaySettings::instance()->setStereo( false ); } @@ -484,19 +487,19 @@ void QgsGlobePluginDialog::setStereoMode() { osg::DisplaySettings::instance()->setStereo( true ); - if("ANAGLYPHIC" == stereoMode) + if ( "ANAGLYPHIC" == stereoMode ) { osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC ); } - else if("VERTICAL_SPLIT" == stereoMode) + else if ( "VERTICAL_SPLIT" == stereoMode ) { osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::VERTICAL_SPLIT ); } - else if("HORIZONTAL_SPLIT" == stereoMode) + else if ( "HORIZONTAL_SPLIT" == stereoMode ) { osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::HORIZONTAL_SPLIT ); } - else if("QUAD_BUFFER" == stereoMode) + else if ( "QUAD_BUFFER" == stereoMode ) { osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::QUAD_BUFFER ); } @@ -504,7 +507,7 @@ void QgsGlobePluginDialog::setStereoMode() { //should never get here QMessageBox msgBox; - msgBox.setText("This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC"); + msgBox.setText( "This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC" ); msgBox.exec(); } } @@ -522,9 +525,9 @@ void QgsGlobePluginDialog::setStereoConfig() osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( splitStereoHorizontalSeparation->value() ); osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( splitStereoVerticalSeparation->value() ); osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping( - (osg::DisplaySettings::SplitStereoHorizontalEyeMapping) splitStereoHorizontalEyeMapping->currentIndex() ); + ( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) splitStereoHorizontalEyeMapping->currentIndex() ); osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping( - (osg::DisplaySettings::SplitStereoVerticalEyeMapping) splitStereoVerticalEyeMapping->currentIndex() ); + ( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) splitStereoVerticalEyeMapping->currentIndex() ); } @@ -553,28 +556,28 @@ void QgsGlobePluginDialog::updateStereoDialog() splitStereoHorizontalEyeMapping->setEnabled( false ); splitStereoVerticalEyeMapping->setEnabled( false ); - if("OFF" == stereoMode) + if ( "OFF" == stereoMode ) { screenDistance->setEnabled( false ); screenHeight->setEnabled( false ); screenWidth->setEnabled( false ); eyeSeparation->setEnabled( false ); } - else if("ANAGLYPHIC" == stereoMode) + else if ( "ANAGLYPHIC" == stereoMode ) { //nothing to do } - else if("VERTICAL_SPLIT" == stereoMode) + else if ( "VERTICAL_SPLIT" == stereoMode ) { splitStereoVerticalSeparation->setEnabled( true ); splitStereoVerticalEyeMapping->setEnabled( true ); } - else if("HORIZONTAL_SPLIT" == stereoMode) + else if ( "HORIZONTAL_SPLIT" == stereoMode ) { splitStereoHorizontalSeparation->setEnabled( true ); splitStereoHorizontalEyeMapping->setEnabled( true ); } - else if("QUAD_BUFFER" == stereoMode) + else if ( "QUAD_BUFFER" == stereoMode ) { //nothing to do } @@ -582,7 +585,7 @@ void QgsGlobePluginDialog::updateStereoDialog() { //should never get here QMessageBox msgBox; - msgBox.setText("This stereo mode has not been implemented yet."); + msgBox.setText( "This stereo mode has not been implemented yet." ); msgBox.exec(); } } diff --git a/src/plugins/globe/globe_plugin_dialog.h b/src/plugins/globe/globe_plugin_dialog.h index a010ae8379ec..6284a18a51ce 100644 --- a/src/plugins/globe/globe_plugin_dialog.h +++ b/src/plugins/globe/globe_plugin_dialog.h @@ -27,9 +27,9 @@ #include #include -class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBase +class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiBase { - Q_OBJECT + Q_OBJECT public: QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget * parent = 0, Qt::WFlags fl = 0 ); @@ -45,12 +45,12 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa private: QString openRasterFile(); void updateStereoDialog(); - bool validateResource( QString type, QString uri, QString& error); + bool validateResource( QString type, QString uri, QString& error ); void saveElevationDatasources(); - void moveRow( QTableWidget* widget, bool up); - QList takeRow( QTableWidget* widget, int row); - void setRow( QTableWidget* widget, int row, const QList< QTableWidgetItem* >& rowItems); - void showMessageBox( QString text); + void moveRow( QTableWidget* widget, bool up ); + QList takeRow( QTableWidget* widget, int row ); + void setRow( QTableWidget* widget, int row, const QList< QTableWidgetItem* >& rowItems ); + void showMessageBox( QString text ); QList pointLayers(); //! Set osg/DisplaySettings void setStereoConfig(); @@ -66,22 +66,22 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa void on_buttonBox_rejected(); //STEREO - void on_comboStereoMode_currentIndexChanged(QString value); - void on_eyeSeparation_valueChanged(double value); - void on_screenDistance_valueChanged(double value); - void on_screenWidth_valueChanged(double value); - void on_screenHeight_valueChanged(double value); - void on_splitStereoHorizontalSeparation_valueChanged(int value); - void on_splitStereoVerticalSeparation_valueChanged(int value); - void on_splitStereoHorizontalEyeMapping_currentIndexChanged(int value); - void on_splitStereoVerticalEyeMapping_currentIndexChanged(int value); + void on_comboStereoMode_currentIndexChanged( QString value ); + void on_eyeSeparation_valueChanged( double value ); + void on_screenDistance_valueChanged( double value ); + void on_screenWidth_valueChanged( double value ); + void on_screenHeight_valueChanged( double value ); + void on_splitStereoHorizontalSeparation_valueChanged( int value ); + void on_splitStereoVerticalSeparation_valueChanged( int value ); + void on_splitStereoHorizontalEyeMapping_currentIndexChanged( int value ); + void on_splitStereoVerticalEyeMapping_currentIndexChanged( int value ); void on_resetStereoDefaults_clicked(); //MODEL void on_modelBrowse_clicked(); //ELEVATION - void on_elevationCombo_currentIndexChanged(QString type); + void on_elevationCombo_currentIndexChanged( QString type ); void on_elevationBrowse_clicked(); void on_elevationAdd_clicked(); void on_elevationRemove_clicked(); @@ -92,4 +92,4 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa void elevationDatasourcesChanged(); }; -#endif // QGIS_GLOBE_PLUGIN_DIALOG_H +#endif // QGIS_GLOBE_PLUGIN_DIALOG_H diff --git a/src/plugins/globe/qgsosgearthtilesource.cpp b/src/plugins/globe/qgsosgearthtilesource.cpp index 48c8066bfe72..33bf6c5cbff9 100644 --- a/src/plugins/globe/qgsosgearthtilesource.cpp +++ b/src/plugins/globe/qgsosgearthtilesource.cpp @@ -30,96 +30,96 @@ using namespace osgEarth; using namespace osgEarth::Drivers; -QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options ) : TileSource(options), mQGisIface(theQgisInterface), mCoordTranform(0) +QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options ) : TileSource( options ), mQGisIface( theQgisInterface ), mCoordTranform( 0 ) { } void QgsOsgEarthTileSource::initialize( const std::string& referenceURI, const Profile* overrideProfile ) { - setProfile( osgEarth::Registry::instance()->getGlobalGeodeticProfile() ); - QgsMapRenderer* mainRenderer = mQGisIface->mapCanvas()->mapRenderer(); - mMapRenderer = new QgsMapRenderer(); + setProfile( osgEarth::Registry::instance()->getGlobalGeodeticProfile() ); + QgsMapRenderer* mainRenderer = mQGisIface->mapCanvas()->mapRenderer(); + mMapRenderer = new QgsMapRenderer(); - long epsgGlobe = 4326; - if (mainRenderer->destinationSrs().epsg() != epsgGlobe) - { - QgsCoordinateReferenceSystem srcCRS; - srcCRS.createFromEpsg(mainRenderer->destinationSrs().epsg()); //FIXME: crs from canvas or first layer? - QgsCoordinateReferenceSystem destCRS; - destCRS.createFromEpsg(epsgGlobe); - //QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectionsEnabled",1); - mMapRenderer->setDestinationSrs(destCRS); - mMapRenderer->setProjectionsEnabled(true); - mCoordTranform = new QgsCoordinateTransform( srcCRS, destCRS ); - } - mMapRenderer->setOutputUnits(mainRenderer->outputUnits()); - mMapRenderer->setMapUnits( QGis::Degrees ); + long epsgGlobe = 4326; + if ( mainRenderer->destinationSrs().epsg() != epsgGlobe ) + { + QgsCoordinateReferenceSystem srcCRS; + srcCRS.createFromEpsg( mainRenderer->destinationSrs().epsg() ); //FIXME: crs from canvas or first layer? + QgsCoordinateReferenceSystem destCRS; + destCRS.createFromEpsg( epsgGlobe ); + //QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectionsEnabled",1); + mMapRenderer->setDestinationSrs( destCRS ); + mMapRenderer->setProjectionsEnabled( true ); + mCoordTranform = new QgsCoordinateTransform( srcCRS, destCRS ); + } + mMapRenderer->setOutputUnits( mainRenderer->outputUnits() ); + mMapRenderer->setMapUnits( QGis::Degrees ); - mMapRenderer->setLabelingEngine( new QgsPalLabeling() ); + mMapRenderer->setLabelingEngine( new QgsPalLabeling() ); } osg::Image* QgsOsgEarthTileSource::createImage( const TileKey& key, ProgressCallback* progress ) { - osg::ref_ptr image; - if (intersects(&key)) + osg::ref_ptr image; + if ( intersects( &key ) ) + { + //Get the extents of the tile + double xmin, ymin, xmax, ymax; + key.getExtent().getBounds( xmin, ymin, xmax, ymax ); + + int tileSize = getPixelsPerTile(); + int target_width = tileSize; + int target_height = tileSize; + + QgsDebugMsg( "QGIS: xmin:" + QString::number( xmin ) + " ymin:" + QString::number( ymin ) + " ymax:" + QString::number( ymax ) + " ymax " + QString::number( ymax ) ); + + //Return if parameters are out of range. + if ( target_width <= 0 || target_height <= 0 ) { - //Get the extents of the tile - double xmin, ymin, xmax, ymax; - key.getExtent().getBounds(xmin, ymin, xmax, ymax); - - int tileSize = getPixelsPerTile(); - int target_width = tileSize; - int target_height = tileSize; - - QgsDebugMsg("QGIS: xmin:" + QString::number(xmin) + " ymin:" + QString::number(ymin) + " ymax:" + QString::number(ymax) + " ymax " + QString::number(ymax)); - - //Return if parameters are out of range. - if (target_width <= 0 || target_height <= 0) - { - return 0; - } - - QImage* qImage = createImage(target_width, target_height); - if(!qImage) - { - return 0; - } - - QgsMapRenderer* mainRenderer = mQGisIface->mapCanvas()->mapRenderer(); - mMapRenderer->setLayerSet(mainRenderer->layerSet()); - - mMapRenderer->setOutputSize(QSize(qImage->width(), qImage->height()), qImage->logicalDpiX()); - - QgsRectangle mapExtent(xmin, ymin, xmax, ymax); - mMapRenderer->setExtent(mapExtent); - - QPainter thePainter(qImage); - //thePainter.setRenderHint(QPainter::Antialiasing); //make it look nicer - mMapRenderer->render(&thePainter); - - unsigned char* data = qImage->bits(); - - image = new osg::Image; - //The pixel format is always RGBA to support transparency - image->setImage(qImage->width(), qImage->height(), 1, - 4, - GL_BGRA,GL_UNSIGNED_BYTE, //Why not GL_RGBA - QGIS bug? - data, - osg::Image::NO_DELETE, 1); - image->flipVertical(); + return 0; } - //Create a transparent image if we don't have an image - if (!image.valid()) + QImage* qImage = createImage( target_width, target_height ); + if ( !qImage ) { - return ImageUtils::createEmptyImage(); + return 0; } - return image.release(); + + QgsMapRenderer* mainRenderer = mQGisIface->mapCanvas()->mapRenderer(); + mMapRenderer->setLayerSet( mainRenderer->layerSet() ); + + mMapRenderer->setOutputSize( QSize( qImage->width(), qImage->height() ), qImage->logicalDpiX() ); + + QgsRectangle mapExtent( xmin, ymin, xmax, ymax ); + mMapRenderer->setExtent( mapExtent ); + + QPainter thePainter( qImage ); + //thePainter.setRenderHint(QPainter::Antialiasing); //make it look nicer + mMapRenderer->render( &thePainter ); + + unsigned char* data = qImage->bits(); + + image = new osg::Image; + //The pixel format is always RGBA to support transparency + image->setImage( qImage->width(), qImage->height(), 1, + 4, + GL_BGRA, GL_UNSIGNED_BYTE, //Why not GL_RGBA - QGIS bug? + data, + osg::Image::NO_DELETE, 1 ); + image->flipVertical(); + } + + //Create a transparent image if we don't have an image + if ( !image.valid() ) + { + return ImageUtils::createEmptyImage(); + } + return image.release(); } QImage* QgsOsgEarthTileSource::createImage( int width, int height ) const { - if( width < 0 || height < 0 ) + if ( width < 0 || height < 0 ) { return 0; } @@ -132,7 +132,7 @@ QImage* QgsOsgEarthTileSource::createImage( int width, int height ) const bool transparent = true; //use alpha channel only if necessary because it slows down performance - if( transparent && !jpeg ) + if ( transparent && !jpeg ) { qImage = new QImage( width, height, QImage::Format_ARGB32_Premultiplied ); qImage->fill( 0 ); @@ -140,13 +140,13 @@ QImage* QgsOsgEarthTileSource::createImage( int width, int height ) const else { qImage = new QImage( width, height, QImage::Format_RGB32 ); - qImage->fill( qRgb(255, 255, 255) ); + qImage->fill( qRgb( 255, 255, 255 ) ); } - if(!qImage) - { - return 0; - } + if ( !qImage ) + { + return 0; + } //apply DPI parameter if present. /* @@ -157,12 +157,12 @@ QImage* QgsOsgEarthTileSource::createImage( int width, int height ) const return qImage; } -bool QgsOsgEarthTileSource::intersects(const TileKey* key) +bool QgsOsgEarthTileSource::intersects( const TileKey* key ) { - //Get the native extents of the tile - double xmin, ymin, xmax, ymax; - key->getExtent().getBounds(xmin, ymin, xmax, ymax); - QgsRectangle extent = mQGisIface->mapCanvas()->fullExtent(); - if (mCoordTranform) extent = mCoordTranform->transformBoundingBox(extent); - return ! ( xmin >= extent.xMaximum() || xmax <= extent.xMinimum() || ymin >= extent.yMaximum() || ymax <= extent.yMinimum() ); + //Get the native extents of the tile + double xmin, ymin, xmax, ymax; + key->getExtent().getBounds( xmin, ymin, xmax, ymax ); + QgsRectangle extent = mQGisIface->mapCanvas()->fullExtent(); + if ( mCoordTranform ) extent = mCoordTranform->transformBoundingBox( extent ); + return !( xmin >= extent.xMaximum() || xmax <= extent.xMinimum() || ymin >= extent.yMaximum() || ymax <= extent.yMinimum() ); } diff --git a/src/plugins/globe/qgsosgearthtilesource.h b/src/plugins/globe/qgsosgearthtilesource.h index 56ee2742a2fe..685e386c31c4 100644 --- a/src/plugins/globe/qgsosgearthtilesource.h +++ b/src/plugins/globe/qgsosgearthtilesource.h @@ -12,48 +12,51 @@ class QgisInterface; using namespace osgEarth; -namespace osgEarth { namespace Drivers +namespace osgEarth { + namespace Drivers + { class QgsOsgEarthTileSource : public TileSource { - public: - QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options =TileSourceOptions() ); + public: + QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options = TileSourceOptions() ); void initialize( const std::string& referenceURI, const Profile* overrideProfile = NULL ); osg::Image* createImage( const TileKey& key, ProgressCallback* progress ); osg::HeightField* createHeightField( const TileKey* key, - ProgressCallback* progress) + ProgressCallback* progress ) { - //NI - OE_WARN << "[QGIS] Driver does not support heightfields" << std::endl; - return NULL; + //NI + OE_WARN << "[QGIS] Driver does not support heightfields" << std::endl; + return NULL; } virtual std::string getExtension() const { - //All QGIS tiles are in JPEG format - return "jpg"; + //All QGIS tiles are in JPEG format + return "jpg"; } virtual bool supportsPersistentCaching() const { - return false; + return false; } -private: + private: - QImage* createImage( int width, int height ) const; - bool intersects(const TileKey* key); + QImage* createImage( int width, int height ) const; + bool intersects( const TileKey* key ); - //! Pointer to the QGIS interface object - QgisInterface *mQGisIface; - QgsCoordinateTransform *mCoordTranform; - QgsMapRenderer* mMapRenderer; + //! Pointer to the QGIS interface object + QgisInterface *mQGisIface; + QgsCoordinateTransform *mCoordTranform; + QgsMapRenderer* mMapRenderer; }; -} } // namespace osgEarth::Drivers + } +} // namespace osgEarth::Drivers #endif // OSGEARTH_DRIVER_QGIS_DRIVEROPTIONS diff --git a/src/plugins/globe/qgsosgviewer.cpp b/src/plugins/globe/qgsosgviewer.cpp index 7293d8e4f4e6..7757e2ed0b59 100644 --- a/src/plugins/globe/qgsosgviewer.cpp +++ b/src/plugins/globe/qgsosgviewer.cpp @@ -23,94 +23,94 @@ #include #include -QDockWidgetGlobe::QDockWidgetGlobe(const QString &title, QWidget *parent, Qt::WindowFlags flags): - QDockWidget(title, parent, flags) +QDockWidgetGlobe::QDockWidgetGlobe( const QString &title, QWidget *parent, Qt::WindowFlags flags ): + QDockWidget( title, parent, flags ) { }; -QDockWidgetGlobe::QDockWidgetGlobe(QWidget *parent, Qt::WindowFlags flags): - QDockWidget(parent, flags) +QDockWidgetGlobe::QDockWidgetGlobe( QWidget *parent, Qt::WindowFlags flags ): + QDockWidget( parent, flags ) { }; //reimplement the close event to emit a signal -void QDockWidgetGlobe::closeEvent(QCloseEvent* event) +void QDockWidgetGlobe::closeEvent( QCloseEvent* event ) { emit globeClosed(); event->accept(); } -QgsGLWidgetAdapter::QgsGLWidgetAdapter( QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f): - QGLWidget(parent, shareWidget, f) +QgsGLWidgetAdapter::QgsGLWidgetAdapter( QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f ): + QGLWidget( parent, shareWidget, f ) { - _gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height()); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking ( true ); + _gw = new osgViewer::GraphicsWindowEmbedded( 0, 0, width(), height() ); + setFocusPolicy( Qt::ClickFocus ); + setMouseTracking( true ); } void QgsGLWidgetAdapter::resizeGL( int width, int height ) { - _gw->getEventQueue()->windowResize(0, 0, width, height ); - _gw->resized(0,0,width,height); + _gw->getEventQueue()->windowResize( 0, 0, width, height ); + _gw->resized( 0, 0, width, height ); } void QgsGLWidgetAdapter::keyPressEvent( QKeyEvent* event ) { - _gw->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) ); + _gw->getEventQueue()->keyPress(( osgGA::GUIEventAdapter::KeySymbol ) *( event->text().toAscii().data() ) ); } void QgsGLWidgetAdapter::keyReleaseEvent( QKeyEvent* event ) { - _gw->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) ); + _gw->getEventQueue()->keyRelease(( osgGA::GUIEventAdapter::KeySymbol ) *( event->text().toAscii().data() ) ); } void QgsGLWidgetAdapter::mousePressEvent( QMouseEvent* event ) { - adaptModifiers( event ); - int button = 0; - switch(event->button()) - { - case(Qt::LeftButton): button = 1; break; - case(Qt::MidButton): button = 2; break; - case(Qt::RightButton): button = 3; break; - case(Qt::NoButton): button = 0; break; - default: button = 0; break; - } - _gw->getEventQueue()->mouseButtonPress(event->x(), event->y(), button); + adaptModifiers( event ); + int button = 0; + switch ( event->button() ) + { + case( Qt::LeftButton ): button = 1; break; + case( Qt::MidButton ): button = 2; break; + case( Qt::RightButton ): button = 3; break; + case( Qt::NoButton ): button = 0; break; + default: button = 0; break; + } + _gw->getEventQueue()->mouseButtonPress( event->x(), event->y(), button ); } void QgsGLWidgetAdapter::adaptModifiers( QInputEvent* event ) { - int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier); + int modkey = event->modifiers() & ( Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier ); - unsigned int modkeyosg = 0; - if (modkey & Qt::ShiftModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_SHIFT; - if (modkey & Qt::ControlModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_CTRL; - if (modkey & Qt::AltModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_ALT; + unsigned int modkeyosg = 0; + if ( modkey & Qt::ShiftModifier ) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_SHIFT; + if ( modkey & Qt::ControlModifier ) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_CTRL; + if ( modkey & Qt::AltModifier ) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_ALT; - _gw->getEventQueue()->getCurrentEventState()->setModKeyMask( modkeyosg ); + _gw->getEventQueue()->getCurrentEventState()->setModKeyMask( modkeyosg ); } void QgsGLWidgetAdapter::mouseReleaseEvent( QMouseEvent* event ) { - int button = 0; - switch(event->button()) - { - case(Qt::LeftButton): button = 1; break; - case(Qt::MidButton): button = 2; break; - case(Qt::RightButton): button = 3; break; - case(Qt::NoButton): button = 0; break; - default: button = 0; break; - } - _gw->getEventQueue()->mouseButtonRelease(event->x(), event->y(), button); + int button = 0; + switch ( event->button() ) + { + case( Qt::LeftButton ): button = 1; break; + case( Qt::MidButton ): button = 2; break; + case( Qt::RightButton ): button = 3; break; + case( Qt::NoButton ): button = 0; break; + default: button = 0; break; + } + _gw->getEventQueue()->mouseButtonRelease( event->x(), event->y(), button ); } void QgsGLWidgetAdapter::mouseMoveEvent( QMouseEvent* event ) { - _gw->getEventQueue()->mouseMotion(event->x(), event->y()); + _gw->getEventQueue()->mouseMotion( event->x(), event->y() ); } -void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event) +void QgsGLWidgetAdapter::wheelEvent( QWheelEvent *event ) { - _gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP); + _gw->getEventQueue()->mouseScroll(( event->delta() > 0 ) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP ); } diff --git a/src/plugins/globe/qgsosgviewer.h b/src/plugins/globe/qgsosgviewer.h index 47ea97f88958..1a875a7afd37 100644 --- a/src/plugins/globe/qgsosgviewer.h +++ b/src/plugins/globe/qgsosgviewer.h @@ -30,48 +30,48 @@ using Qt::WindowFlags; class QDockWidgetGlobe : public QDockWidget { - Q_OBJECT + Q_OBJECT - public: - QDockWidgetGlobe(const QString& title, QWidget* parent = 0, WindowFlags flags = 0); - QDockWidgetGlobe(QWidget *parent = 0, Qt::WindowFlags flags = 0); + public: + QDockWidgetGlobe( const QString& title, QWidget* parent = 0, WindowFlags flags = 0 ); + QDockWidgetGlobe( QWidget *parent = 0, Qt::WindowFlags flags = 0 ); - virtual ~QDockWidgetGlobe() {} + virtual ~QDockWidgetGlobe() {} - protected: - virtual void closeEvent(QCloseEvent *event); + protected: + virtual void closeEvent( QCloseEvent *event ); - signals: - void globeClosed(); + signals: + void globeClosed(); }; class QgsGLWidgetAdapter : public QGLWidget { - Q_OBJECT - public: + Q_OBJECT + public: - QgsGLWidgetAdapter( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WindowFlags f = 0 ); + QgsGLWidgetAdapter( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WindowFlags f = 0 ); - virtual ~QgsGLWidgetAdapter() {} + virtual ~QgsGLWidgetAdapter() {} - osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); } - const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); } + osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); } + const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); } - protected: + protected: - void init(); - virtual void resizeGL( int width, int height ); - virtual void keyPressEvent( QKeyEvent* event ); - virtual void keyReleaseEvent( QKeyEvent* event ); - //! converts QT modifiers key to OSG modifiers key - virtual void adaptModifiers( QInputEvent* event ); - virtual void mousePressEvent( QMouseEvent* event ); - virtual void mouseReleaseEvent( QMouseEvent* event ); - virtual void mouseMoveEvent( QMouseEvent* event ); - virtual void wheelEvent( QWheelEvent * event ); + void init(); + virtual void resizeGL( int width, int height ); + virtual void keyPressEvent( QKeyEvent* event ); + virtual void keyReleaseEvent( QKeyEvent* event ); + //! converts QT modifiers key to OSG modifiers key + virtual void adaptModifiers( QInputEvent* event ); + virtual void mousePressEvent( QMouseEvent* event ); + virtual void mouseReleaseEvent( QMouseEvent* event ); + virtual void mouseMoveEvent( QMouseEvent* event ); + virtual void wheelEvent( QWheelEvent * event ); - osg::ref_ptr _gw; + osg::ref_ptr _gw; }; @@ -79,29 +79,29 @@ class QgsGLWidgetAdapter : public QGLWidget class QgsOsgViewer : public osgViewer::Viewer, public QgsGLWidgetAdapter { - public: + public: - QgsOsgViewer(QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WindowFlags f = 0): - QgsGLWidgetAdapter( parent, name, shareWidget, f ) - { - getCamera()->setViewport(new osg::Viewport(0,0,width(),height())); - getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast(width())/static_cast(height()), 1.0f, 10000.0f); - getCamera()->setGraphicsContext(getGraphicsWindow()); + QgsOsgViewer( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WindowFlags f = 0 ): + QgsGLWidgetAdapter( parent, name, shareWidget, f ) + { + getCamera()->setViewport( new osg::Viewport( 0, 0, width(), height() ) ); + getCamera()->setProjectionMatrixAsPerspective( 30.0f, static_cast( width() ) / static_cast( height() ), 1.0f, 10000.0f ); + getCamera()->setGraphicsContext( getGraphicsWindow() ); - setThreadingModel(osgViewer::Viewer::SingleThreaded); + setThreadingModel( osgViewer::Viewer::SingleThreaded ); - connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL())); - _timer.start(10); - } + connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) ); + _timer.start( 10 ); + } - virtual void paintGL() - { - frame(); - } + virtual void paintGL() + { + frame(); + } - protected: + protected: - QTimer _timer; + QTimer _timer; }; #endif // QGS_OSG_VIEWER_H