Skip to content

Commit 88e3e34

Browse files
committedOct 2, 2012
Backported osgEarth::QtGui::ViewerWidget and osgEarth::Util::Controls for compatibilty with news OSG and QT version
1 parent 8a1ad57 commit 88e3e34

File tree

13 files changed

+3351
-292
lines changed

13 files changed

+3351
-292
lines changed
 

‎src/plugins/globe/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ ENDIF(HAVE_OSGEARTH_CHILD_SPACING)
1414

1515
SET (globe_plugin_SRCS
1616
globe_plugin.cpp
17-
qgsosgviewer.cpp
1817
qgsosgearthtilesource.cpp
1918
globe_plugin_dialog.cpp
19+
osgEarthQt/ViewerWidget.cpp
20+
osgEarthUtil/Controls.cpp
2021
)
2122

2223
SET (globe_plugin_UIS
@@ -26,7 +27,9 @@ SET (globe_plugin_UIS
2627
SET (globe_plugin_MOC_HDRS
2728
globe_plugin.h
2829
globe_plugin_dialog.h
29-
qgsosgviewer.h
30+
osgEarthQt/Common
31+
osgEarthQt/ViewerWidget
32+
osgEarthUtil/Controls
3033
)
3134

3235
SET (globe_plugin_RCCS globe_plugin.qrc)
@@ -58,6 +61,7 @@ TARGET_LINK_LIBRARIES(globeplugin
5861
${OSGDB_LIBRARY}
5962
${OSGGA_LIBRARY}
6063
${OSG_LIBRARY}
64+
${OSGQT_LIBRARY}
6165
${OSGVIEWER_LIBRARY}
6266
${OSGEARTH_LIBRARY}
6367
${OSGEARTHFEATURES_LIBRARY}

‎src/plugins/globe/globe_plugin.cpp

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "globe_plugin.h"
2020
#include "globe_plugin_dialog.h"
2121
#include "qgsosgearthtilesource.h"
22+
#include "osgEarthQt/ViewerWidget"
2223

2324
#include <cmath>
2425

@@ -57,7 +58,7 @@
5758
#include <osgEarthDrivers/tms/TMSOptions>
5859

5960
using namespace osgEarth::Drivers;
60-
using namespace osgEarth::Util::Controls;
61+
using namespace osgEarth::Util::Controls21;
6162

6263
#define MOVE_OFFSET 0.05
6364

@@ -74,7 +75,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
7475
, mQGisIface( theQgisInterface )
7576
, mQActionPointer( NULL )
7677
, mQActionSettingsPointer( NULL )
77-
, viewer()
78+
, mOsgViewer( 0 )
7879
, mQgisMapLayer( 0 )
7980
, mTileSource( 0 )
8081
, mElevationManager( NULL )
@@ -94,8 +95,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
9495
#endif
9596
#endif
9697

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

101101
//destructor
@@ -199,7 +199,6 @@ void GlobePlugin::initGui()
199199
//Add menu
200200
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionPointer );
201201
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionSettingsPointer );
202-
mQDockWidget->setWidget( &viewer );
203202

204203
connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
205204
this, SLOT( extentsChanged() ) );
@@ -211,8 +210,6 @@ void GlobePlugin::initGui()
211210
SLOT( projectReady() ) );
212211
connect( mQGisIface, SIGNAL( newProjectCreated() ), this,
213212
SLOT( blankProjectReady() ) );
214-
connect( mQDockWidget, SIGNAL( globeClosed() ), this,
215-
SLOT( setGlobeNotRunning() ) );
216213
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
217214
mQGisIface->mapCanvas(), SIGNAL( xyCoordinates( const QgsPoint & ) ) );
218215
}
@@ -223,54 +220,73 @@ void GlobePlugin::run()
223220
if ( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO );
224221
#endif
225222

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

228-
viewer.show();
229-
230-
#ifdef GLOBE_OSG_STANDALONE_VIEWER
231-
osgViewer::Viewer viewer;
232-
#endif
225+
// install the programmable manipulator.
226+
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
227+
mOsgViewer->setCameraManipulator( manip );
233228

234229
mIsGlobeRunning = true;
235230
setupProxy();
236231

237-
// install the programmable manipulator.
238-
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
239-
viewer.setCameraManipulator( manip );
232+
if ( getenv( "MAPXML" ) ) {
233+
char* mapxml = getenv( "MAPXML" );
234+
QgsDebugMsg( mapxml );
235+
osg::Node* node = osgDB::readNodeFile(mapxml);
236+
if ( !node ) {
237+
QgsDebugMsg( "Failed to load earth file " );
238+
return;
239+
}
240+
mMapNode = MapNode::findMapNode(node);
241+
mRootNode = new osg::Group();
242+
mRootNode->addChild( node );
243+
} else {
244+
setupMap();
245+
}
246+
247+
// create a surface to house the controls
248+
mControlCanvas = ControlCanvas::get( mOsgViewer );
249+
mRootNode->addChild( mControlCanvas );
250+
251+
mOsgViewer->setSceneData( mRootNode );
252+
253+
mOsgViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
254+
255+
mOsgViewer->addEventHandler(new osgViewer::StatsHandler());
256+
mOsgViewer->addEventHandler(new osgViewer::WindowSizeHandler());
257+
mOsgViewer->addEventHandler(new osgViewer::ThreadingHandler());
258+
mOsgViewer->addEventHandler(new osgViewer::LODScaleHandler());
259+
mOsgViewer->addEventHandler(new osgGA::StateSetManipulator(mOsgViewer->getCamera()->getOrCreateStateSet()));
240260
// add a handler that will automatically calculate good clipping planes
241-
//viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );
261+
//mOsgViewer->addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );
262+
// osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of
263+
// OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
264+
mOsgViewer->getDatabasePager()->setDoPreCompile( true );
242265

243-
setupMap();
266+
mSettingsDialog->setViewer(mOsgViewer);
244267

245-
viewer.setSceneData( mRootNode );
268+
#ifdef GLOBE_OSG_STANDALONE_VIEWER
269+
mOsgViewer->run();
270+
#endif
271+
272+
QWidget* viewerWidget = new osgEarth::QtGui::ViewerWidget( mOsgViewer );
273+
viewerWidget->setGeometry(100, 100, 1024, 800);
274+
viewerWidget->show();
246275

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

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

257283
// add our handlers
258-
viewer.addEventHandler( new FlyToExtentHandler( this ) );
259-
viewer.addEventHandler( new KeyboardControlHandler( manip, mQGisIface ) );
284+
mOsgViewer->addEventHandler( new FlyToExtentHandler( this ) );
285+
mOsgViewer->addEventHandler( new KeyboardControlHandler( manip, mQGisIface ) );
260286

261-
viewer.addEventHandler( new QueryCoordinatesHandler( this, mElevationManager,
287+
mOsgViewer->addEventHandler( new QueryCoordinatesHandler( this, mElevationManager,
262288
mMapNode->getMap()->getProfile()->getSRS() )
263289
);
264-
265-
// add some stock OSG handlers:
266-
viewer.addEventHandler( new osgViewer::StatsHandler() );
267-
viewer.addEventHandler( new osgViewer::WindowSizeHandler() );
268-
viewer.addEventHandler( new osgGA::StateSetManipulator( viewer.getCamera()->getOrCreateStateSet() ) );
269-
270-
#ifdef GLOBE_OSG_STANDALONE_VIEWER
271-
viewer.run();
272-
#endif
273-
274290
}
275291

276292
void GlobePlugin::settings()
@@ -294,11 +310,23 @@ void GlobePlugin::setupMap()
294310
osgEarth::Map *map = new osgEarth::Map( mapOptions );
295311

296312
//Default image layer
313+
/*
297314
GDALOptions driverOptions;
298315
driverOptions.url() = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/world.tif" ).toStdString();
299316
ImageLayerOptions layerOptions( "world", driverOptions );
300317
layerOptions.cacheEnabled() = false;
301318
map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) );
319+
*/
320+
TMSOptions imagery;
321+
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
322+
map->addImageLayer( new ImageLayer("Imagery", imagery) );
323+
324+
// add a TMS elevation layer:
325+
/*
326+
TMSOptions elevation;
327+
elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/9/";
328+
map->addElevationLayer( new ElevationLayer("Elevation", elevation) );
329+
*/
302330

303331
MapNodeOptions nodeOptions;
304332
//nodeOptions.proxySettings() =
@@ -415,14 +443,15 @@ double GlobePlugin::getSelectedElevation()
415443

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

422450
//get mapCanvas->extent().height() in meters
423451
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
424452
QgsDistanceArea dist;
425453
dist.setEllipsoidalMode( true );
454+
//dist.setProjectionsEnabled( true );
426455
QgsPoint ll = QgsPoint( extent.xMinimum(), extent.yMinimum() );
427456
QgsPoint ul = QgsPoint( extent.xMinimum(), extent.yMaximum() );
428457
double height = dist.measureLine( ll, ul );
@@ -459,7 +488,7 @@ void GlobePlugin::setupControls()
459488
moveHControls->setPosition( 5, 30 );
460489
moveHControls->setPadding( 6 );
461490

462-
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() );
491+
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( mOsgViewer->getCameraManipulator() );
463492
//Move Left
464493
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
465494
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
@@ -650,7 +679,6 @@ void GlobePlugin::setupControls()
650679
mControlCanvas->addControl( rotateControls );
651680
mControlCanvas->addControl( zoomControls );
652681
mControlCanvas->addControl( extraControls );
653-
654682
}
655683

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

692720
if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 )
693721
{
694-
viewer.getDatabasePager()->clear();
722+
mOsgViewer->getDatabasePager()->clear();
695723
}
696724

697725
// Remove elevation layers

‎src/plugins/globe/globe_plugin.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
#define QGS_GLOBE_PLUGIN_H
2121

2222
#include "../qgisplugin.h"
23-
#include "qgsosgviewer.h"
2423
#include "qgsosgearthtilesource.h"
2524
#include "globe_plugin_dialog.h"
2625
#include <QObject>
26+
#include <osgViewer/Viewer>
2727
#include <osgEarth/MapNode>
2828
#include <osgEarth/ImageLayer>
2929
#include <osgEarthUtil/EarthManipulator>
30-
#include <osgEarthUtil/Controls>
30+
//#include <osgEarthUtil/Controls>
31+
#include "osgEarthUtil/Controls"
3132
#include <osgEarthUtil/ElevationManager>
3233
#include <osgEarthUtil/ObjectPlacer>
3334

@@ -108,9 +109,7 @@ class GlobePlugin : public QObject, public QgisPlugin
108109
//!pointer to the qaction for this plugin
109110
QAction * mQActionSettingsPointer;
110111
//! OSG Viewer
111-
QgsOsgViewer viewer;
112-
//! Dock widget for viewer
113-
QDockWidgetGlobe *mQDockWidget;
112+
osgViewer::Viewer* mOsgViewer;
114113
//! Settings Dialog
115114
QgsGlobePluginDialog *mSettingsDialog;
116115
//! OSG root node
@@ -122,7 +121,7 @@ class GlobePlugin : public QObject, public QgisPlugin
122121
//! Tile source
123122
osgEarth::Drivers::QgsOsgEarthTileSource* mTileSource;
124123
//! Control Canvas
125-
osgEarth::Util::Controls::ControlCanvas* mControlCanvas;
124+
osgEarth::Util::Controls21::ControlCanvas* mControlCanvas;
126125
//! Elevation manager
127126
osgEarth::Util::ElevationManager* mElevationManager;
128127
//! Object placer
@@ -189,7 +188,7 @@ namespace osgEarth
189188
{
190189
namespace Util
191190
{
192-
namespace Controls
191+
namespace Controls21
193192
{
194193
class NavigationControlHandler : public ControlEventHandler
195194
{

‎src/plugins/globe/globe_plugin_dialog.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
#include <osg/DisplaySettings>
3939

4040
//constructor
41-
QgsGlobePluginDialog::QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget* parent, Qt::WFlags fl )
41+
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
4242
: QDialog( parent, fl )
43-
, mViewer( viewer )
43+
, mViewer( 0 )
4444
{
4545
setupUi( this );
4646
loadStereoConfig(); //values from settings, default values from OSG
@@ -514,20 +514,21 @@ void QgsGlobePluginDialog::setStereoMode()
514514

515515
void QgsGlobePluginDialog::setStereoConfig()
516516
{
517-
mViewer->getDatabasePager()->clear();
518-
//SETTING THE VALUES IN THE OEGearth instance
519-
setStereoMode();
520-
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
521-
osg::DisplaySettings::instance()->setScreenWidth( screenWidth->value() );
522-
osg::DisplaySettings::instance()->setScreenHeight( screenHeight->value() );
523-
osg::DisplaySettings::instance()->setEyeSeparation( eyeSeparation->value() );
524-
osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( splitStereoHorizontalSeparation->value() );
525-
osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( splitStereoVerticalSeparation->value() );
526-
osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping(
527-
( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) splitStereoHorizontalEyeMapping->currentIndex() );
528-
osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping(
529-
( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) splitStereoVerticalEyeMapping->currentIndex() );
530-
517+
if (mViewer) {
518+
mViewer->getDatabasePager()->clear();
519+
//SETTING THE VALUES IN THE OEGearth instance
520+
setStereoMode();
521+
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
522+
osg::DisplaySettings::instance()->setScreenWidth( screenWidth->value() );
523+
osg::DisplaySettings::instance()->setScreenHeight( screenHeight->value() );
524+
osg::DisplaySettings::instance()->setEyeSeparation( eyeSeparation->value() );
525+
osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( splitStereoHorizontalSeparation->value() );
526+
osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( splitStereoVerticalSeparation->value() );
527+
osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping(
528+
( osg::DisplaySettings::SplitStereoHorizontalEyeMapping ) splitStereoHorizontalEyeMapping->currentIndex() );
529+
osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping(
530+
( osg::DisplaySettings::SplitStereoVerticalEyeMapping ) splitStereoVerticalEyeMapping->currentIndex() );
531+
}
531532
}
532533

533534
void QgsGlobePluginDialog::saveStereoConfig()

‎src/plugins/globe/globe_plugin_dialog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <QDialog>
2020
#include <QSettings>
2121
#include <QCheckBox>
22-
#include "qgsosgviewer.h"
22+
#include <osgViewer/Viewer>
2323
#include "qgscontexthelp.h"
2424
#include <qgsproject.h>
2525
#include <qgsvectorlayer.h>
@@ -29,15 +29,16 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
2929
Q_OBJECT
3030

3131
public:
32-
QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget * parent = 0, Qt::WFlags fl = 0 );
32+
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
3333
~QgsGlobePluginDialog();
34+
void setViewer( osgViewer::Viewer* viewer ) { mViewer = viewer; }
3435
void readElevationDatasources();
3536
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
3637
void updatePointLayers();
3738
QgsVectorLayer* modelLayer();
3839
QString modelPath() { return modelPathLineEdit->text(); }
3940
private:
40-
QgsOsgViewer* mViewer;
41+
osgViewer::Viewer* mViewer;
4142
QSettings settings;
4243
private:
4344
QString openRasterFile();

‎src/plugins/globe/osgEarthQt/Common

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* -*-c++-*- */
2+
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3+
* Copyright 2008-2012 Pelican Mapping
4+
* http://osgearth.org
5+
*
6+
* osgEarth is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*/
19+
20+
#ifndef OSGEARTHQT_COMMON_H
21+
#define OSGEARTHQT_COMMON_H 1
22+
23+
#include <osgEarth/Common>
24+
//#include <osgEarthAnnotation/AnnotationNode>
25+
#include <osgViewer/Viewer>
26+
27+
// define USE_DEPRECATED_API is used to include in API which is being phased out
28+
// if you can compile your apps with this turned off you are
29+
// well placed for compatibility with future versions.
30+
#define USE_DEPRECATED_API
31+
32+
#if defined(_MSC_VER)
33+
#pragma warning( disable : 4244 )
34+
#pragma warning( disable : 4251 )
35+
#pragma warning( disable : 4267 )
36+
#pragma warning( disable : 4275 )
37+
#pragma warning( disable : 4290 )
38+
#pragma warning( disable : 4786 )
39+
#pragma warning( disable : 4305 )
40+
#pragma warning( disable : 4996 )
41+
#endif
42+
43+
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
44+
# if defined( OSGEARTHQT_LIBRARY_STATIC )
45+
# define OSGEARTHQT_EXPORT
46+
# elif defined( OSGEARTHQT_LIBRARY )
47+
# define OSGEARTHQT_EXPORT __declspec(dllexport)
48+
# else
49+
# define OSGEARTHQT_EXPORT __declspec(dllimport)
50+
# endif
51+
#else
52+
# define OSGEARTHQT_EXPORT
53+
#endif
54+
55+
// set up define for whether member templates are supported by VisualStudio compilers.
56+
#ifdef _MSC_VER
57+
# if (_MSC_VER >= 1300)
58+
# define __STL_MEMBER_TEMPLATES
59+
# endif
60+
#endif
61+
62+
/* Define NULL pointer value */
63+
64+
#ifndef NULL
65+
#ifdef __cplusplus
66+
#define NULL 0
67+
#else
68+
#define NULL ((void *)0)
69+
#endif
70+
#endif
71+
72+
#ifndef OSG_MIN_VERSION_REQUIRED
73+
#define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH))))
74+
#endif
75+
76+
#ifndef OSG_VERSION_LESS_THAN
77+
#define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION<MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION<MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION<PATCH))))
78+
#endif
79+
80+
/**
81+
\namespace osgEarthQt
82+
*/
83+
84+
namespace osgEarth { namespace QtGui {
85+
86+
//typedef std::vector< osg::ref_ptr<osgEarth::Annotation::AnnotationNode> > AnnotationVector;
87+
typedef std::vector< osg::ref_ptr<osgViewer::View> > ViewVector;
88+
89+
} }
90+
91+
#endif // OSGEARTHQT_COMMON_H
92+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* -*-c++-*- */
2+
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3+
* Copyright 2008-2012 Pelican Mapping
4+
* http://osgearth.org
5+
*
6+
* osgEarth is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*/
19+
#ifndef OSGEARTHQT_VIEWERWIDGET_H
20+
#define OSGEARTHQT_VIEWERWIDGET_H 1
21+
22+
//#include <osgEarthQt/Common>
23+
#include "Common"
24+
25+
#include <osgEarth/Map>
26+
27+
#include <osgQt/GraphicsWindowQt>
28+
#include <osgViewer/ViewerBase>
29+
30+
#include <QtCore/QTimer>
31+
32+
namespace osgEarth { namespace QtGui
33+
{
34+
using namespace osgEarth;
35+
36+
/**
37+
* Qt widget that encapsulates an osgViewer::Viewer.
38+
*/
39+
class OSGEARTHQT_EXPORT ViewerWidget : public osgQt::GLWidget
40+
{
41+
public:
42+
/**
43+
* Constructs a new ViewerWidget, creating an underlying viewer.
44+
* @param[in ] scene Scene graph to attach to the viewer (optional)
45+
*/
46+
ViewerWidget(osg::Node* scene=0L);
47+
48+
/**
49+
* Constructs a new ViewerWidget, attaching an existing viewer.
50+
* @param[in ] viewer Viewer to attach to this widget. The widget will install
51+
* a new camera in the viewer. (NOTE: this widget does not take
52+
* ownership of the Viewer. You are still respsonsile for its
53+
* destruction)
54+
*/
55+
ViewerWidget(osgViewer::ViewerBase* viewer);
56+
57+
/**
58+
* Access the underlying viewer.
59+
*/
60+
osgViewer::ViewerBase* getViewer() { return _viewer.get(); }
61+
62+
/**
63+
* Populates the incoming collection with the views comprising this viewer.
64+
*/
65+
template<typename T>
66+
void getViews( T& views ) const {
67+
osgViewer::ViewerBase::Views temp;
68+
_viewer->getViews(temp);
69+
views.insert(views.end(), temp.begin(), temp.end());
70+
}
71+
72+
virtual ~ViewerWidget();
73+
74+
protected:
75+
76+
QTimer _timer;
77+
78+
void createViewer();
79+
void reconfigure( osgViewer::View* );
80+
void installFrameTimer();
81+
void paintEvent( QPaintEvent* );
82+
83+
osg::observer_ptr<osgViewer::ViewerBase> _viewer;
84+
osg::ref_ptr<osg::GraphicsContext> _gc;
85+
};
86+
} }
87+
88+
#endif // OSGEARTHQT_VIEWERWIDGET_H
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/* -*-c++-*- */
2+
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3+
* Copyright 2008-2012 Pelican Mapping
4+
* http://osgearth.org
5+
*
6+
* osgEarth is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*/
19+
//#include <osgEarthQt/ViewerWidget>
20+
#include "ViewerWidget"
21+
22+
#include <osgEarthUtil/EarthManipulator>
23+
24+
#include <osgGA/StateSetManipulator>
25+
#include <osgQt/GraphicsWindowQt>
26+
#include <osgViewer/Viewer>
27+
#include <osgViewer/ViewerEventHandlers>
28+
29+
#include <QtGui>
30+
#include <QtCore/QTimer>
31+
#include <QtGui/QWidget>
32+
33+
using namespace osgEarth;
34+
using namespace osgEarth::QtGui;
35+
36+
37+
ViewerWidget::ViewerWidget(osg::Node* scene)
38+
{
39+
// create a new viewer (a simple osgViewer::Viewer)
40+
createViewer();
41+
42+
// attach the scene graph provided by the user
43+
if (scene)
44+
{
45+
dynamic_cast<osgViewer::Viewer*>(_viewer.get())->setSceneData( scene );
46+
}
47+
48+
// start up the paint event timer.
49+
installFrameTimer();
50+
}
51+
52+
ViewerWidget::ViewerWidget(osgViewer::ViewerBase* viewer) :
53+
_viewer( viewer )
54+
{
55+
if ( !_viewer.valid() )
56+
{
57+
// create a viewer if the user passed in NULL
58+
createViewer();
59+
}
60+
61+
else
62+
{
63+
// reconfigure all the viewer's views to use a Qt graphics context.
64+
osgViewer::ViewerBase::Views views;
65+
getViews( views );
66+
for( osgViewer::ViewerBase::Views::iterator v = views.begin(); v != views.end(); ++v )
67+
{
68+
reconfigure( *v );
69+
}
70+
71+
// disable event setting on the viewer.
72+
viewer->setKeyEventSetsDone(0);
73+
viewer->setQuitEventSetsDone(false);
74+
}
75+
76+
// start up the paint event timer.
77+
installFrameTimer();
78+
}
79+
80+
ViewerWidget::~ViewerWidget()
81+
{
82+
_timer.stop();
83+
if ( _viewer.valid() )
84+
{
85+
_viewer->stopThreading();
86+
_viewer = 0L;
87+
}
88+
89+
OE_DEBUG << "ViewerWidget::DTOR" << std::endl;
90+
}
91+
92+
93+
void ViewerWidget::installFrameTimer()
94+
{
95+
// start the frame timer.
96+
connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
97+
_timer.start(15);
98+
}
99+
100+
101+
void ViewerWidget::createViewer()
102+
{
103+
// creates a simple basic viewer.
104+
osgViewer::Viewer* viewer = new osgViewer::Viewer();
105+
106+
viewer->setThreadingModel(osgViewer::Viewer::DrawThreadPerContext);
107+
viewer->setCameraManipulator(new osgEarth::Util::EarthManipulator());
108+
109+
viewer->addEventHandler(new osgViewer::StatsHandler());
110+
viewer->addEventHandler(new osgGA::StateSetManipulator());
111+
viewer->addEventHandler(new osgViewer::ThreadingHandler());
112+
113+
viewer->setKeyEventSetsDone(0);
114+
viewer->setQuitEventSetsDone(false);
115+
116+
reconfigure( viewer );
117+
118+
_viewer = viewer;
119+
}
120+
121+
void ViewerWidget::reconfigure( osgViewer::View* view )
122+
{
123+
if ( !_gc.valid() )
124+
{
125+
// create the Qt graphics context if necessary; it will be shared across all views.
126+
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
127+
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
128+
129+
traits->readDISPLAY();
130+
if (traits->displayNum<0) traits->displayNum = 0;
131+
132+
traits->windowName = "osgEarthViewerQt";
133+
traits->windowDecoration = false;
134+
traits->x = x();
135+
traits->y = y();
136+
traits->width = width();
137+
traits->height = height();
138+
traits->doubleBuffer = true;
139+
traits->inheritedWindowData = new osgQt::GraphicsWindowQt::WindowData(this);
140+
141+
_gc = new osgQt::GraphicsWindowQt( traits.get() );
142+
}
143+
144+
// reconfigure this view's camera to use the Qt GC if necessary.
145+
osg::Camera* camera = view->getCamera();
146+
if ( camera->getGraphicsContext() != _gc.get() )
147+
{
148+
camera->setGraphicsContext( _gc.get() );
149+
if ( !camera->getViewport() )
150+
{
151+
camera->setViewport(new osg::Viewport(0, 0, _gc->getTraits()->width, _gc->getTraits()->height));
152+
}
153+
camera->setProjectionMatrixAsPerspective(
154+
30.0f, camera->getViewport()->width()/camera->getViewport()->height(), 1.0f, 10000.0f );
155+
}
156+
}
157+
158+
159+
void ViewerWidget::paintEvent(QPaintEvent* e)
160+
{
161+
if (_viewer->getRunFrameScheme() == osgViewer::ViewerBase::CONTINUOUS ||
162+
_viewer->checkNeedToDoFrame() )
163+
{
164+
_viewer->frame();
165+
}
166+
}

‎src/plugins/globe/osgEarthUtil/Controls

Lines changed: 690 additions & 0 deletions
Large diffs are not rendered by default.

‎src/plugins/globe/osgEarthUtil/Controls.cpp

Lines changed: 2214 additions & 0 deletions
Large diffs are not rendered by default.

‎src/plugins/globe/qgsosgearthtilesource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void QgsOsgEarthTileSource::initialize( const std::string& referenceURI, const P
7171
mMapRenderer->setOutputUnits( mainRenderer->outputUnits() );
7272
mMapRenderer->setMapUnits( QGis::Degrees );
7373

74-
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
74+
//mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
7575
}
7676

7777
osg::Image* QgsOsgEarthTileSource::createImage( const TileKey& key, ProgressCallback* progress )

‎src/plugins/globe/qgsosgviewer.cpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

‎src/plugins/globe/qgsosgviewer.h

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.