92 changes: 92 additions & 0 deletions src/plugins/globe/osgEarthQt/Common
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2012 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

#ifndef OSGEARTHQT_COMMON_H
#define OSGEARTHQT_COMMON_H 1

#include <osgEarth/Common>
//#include <osgEarthAnnotation/AnnotationNode>
#include <osgViewer/Viewer>

// define USE_DEPRECATED_API is used to include in API which is being phased out
// if you can compile your apps with this turned off you are
// well placed for compatibility with future versions.
#define USE_DEPRECATED_API

#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4267 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4786 )
#pragma warning( disable : 4305 )
#pragma warning( disable : 4996 )
#endif

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSGEARTHQT_LIBRARY_STATIC )
# define OSGEARTHQT_EXPORT
# elif defined( OSGEARTHQT_LIBRARY )
# define OSGEARTHQT_EXPORT __declspec(dllexport)
# else
# define OSGEARTHQT_EXPORT __declspec(dllimport)
# endif
#else
# define OSGEARTHQT_EXPORT
#endif

// set up define for whether member templates are supported by VisualStudio compilers.
#ifdef _MSC_VER
# if (_MSC_VER >= 1300)
# define __STL_MEMBER_TEMPLATES
# endif
#endif

/* Define NULL pointer value */

#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif

#ifndef OSG_MIN_VERSION_REQUIRED
#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))))
#endif

#ifndef OSG_VERSION_LESS_THAN
#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))))
#endif

/**
\namespace osgEarthQt
*/

namespace osgEarth { namespace QtGui {

//typedef std::vector< osg::ref_ptr<osgEarth::Annotation::AnnotationNode> > AnnotationVector;
typedef std::vector< osg::ref_ptr<osgViewer::View> > ViewVector;

} }

#endif // OSGEARTHQT_COMMON_H

88 changes: 88 additions & 0 deletions src/plugins/globe/osgEarthQt/ViewerWidget
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2012 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTHQT_VIEWERWIDGET_H
#define OSGEARTHQT_VIEWERWIDGET_H 1

//#include <osgEarthQt/Common>
#include "Common"

#include <osgEarth/Map>

#include <osgQt/GraphicsWindowQt>
#include <osgViewer/ViewerBase>

#include <QtCore/QTimer>

namespace osgEarth { namespace QtGui
{
using namespace osgEarth;

/**
* Qt widget that encapsulates an osgViewer::Viewer.
*/
class OSGEARTHQT_EXPORT ViewerWidget : public osgQt::GLWidget
{
public:
/**
* Constructs a new ViewerWidget, creating an underlying viewer.
* @param[in ] scene Scene graph to attach to the viewer (optional)
*/
ViewerWidget(osg::Node* scene=0L);

/**
* Constructs a new ViewerWidget, attaching an existing viewer.
* @param[in ] viewer Viewer to attach to this widget. The widget will install
* a new camera in the viewer. (NOTE: this widget does not take
* ownership of the Viewer. You are still respsonsile for its
* destruction)
*/
ViewerWidget(osgViewer::ViewerBase* viewer);

/**
* Access the underlying viewer.
*/
osgViewer::ViewerBase* getViewer() { return _viewer.get(); }

/**
* Populates the incoming collection with the views comprising this viewer.
*/
template<typename T>
void getViews( T& views ) const {
osgViewer::ViewerBase::Views temp;
_viewer->getViews(temp);
views.insert(views.end(), temp.begin(), temp.end());
}

virtual ~ViewerWidget();

protected:

QTimer _timer;

void createViewer();
void reconfigure( osgViewer::View* );
void installFrameTimer();
void paintEvent( QPaintEvent* );

osg::observer_ptr<osgViewer::ViewerBase> _viewer;
osg::ref_ptr<osg::GraphicsContext> _gc;
};
} }

#endif // OSGEARTHQT_VIEWERWIDGET_H
166 changes: 166 additions & 0 deletions src/plugins/globe/osgEarthQt/ViewerWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2012 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
//#include <osgEarthQt/ViewerWidget>
#include "ViewerWidget"

#include <osgEarthUtil/EarthManipulator>

#include <osgGA/StateSetManipulator>
#include <osgQt/GraphicsWindowQt>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <QtGui>
#include <QtCore/QTimer>
#include <QtGui/QWidget>

using namespace osgEarth;
using namespace osgEarth::QtGui;


ViewerWidget::ViewerWidget(osg::Node* scene)
{
// create a new viewer (a simple osgViewer::Viewer)
createViewer();

// attach the scene graph provided by the user
if (scene)
{
dynamic_cast<osgViewer::Viewer*>(_viewer.get())->setSceneData( scene );
}

// start up the paint event timer.
installFrameTimer();
}

ViewerWidget::ViewerWidget(osgViewer::ViewerBase* viewer) :
_viewer( viewer )
{
if ( !_viewer.valid() )
{
// create a viewer if the user passed in NULL
createViewer();
}

else
{
// reconfigure all the viewer's views to use a Qt graphics context.
osgViewer::ViewerBase::Views views;
getViews( views );
for( osgViewer::ViewerBase::Views::iterator v = views.begin(); v != views.end(); ++v )
{
reconfigure( *v );
}

// disable event setting on the viewer.
viewer->setKeyEventSetsDone(0);
viewer->setQuitEventSetsDone(false);
}

// start up the paint event timer.
installFrameTimer();
}

ViewerWidget::~ViewerWidget()
{
_timer.stop();
if ( _viewer.valid() )
{
_viewer->stopThreading();
_viewer = 0L;
}

OE_DEBUG << "ViewerWidget::DTOR" << std::endl;
}


void ViewerWidget::installFrameTimer()
{
// start the frame timer.
connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
_timer.start(15);
}


void ViewerWidget::createViewer()
{
// creates a simple basic viewer.
osgViewer::Viewer* viewer = new osgViewer::Viewer();

viewer->setThreadingModel(osgViewer::Viewer::DrawThreadPerContext);
viewer->setCameraManipulator(new osgEarth::Util::EarthManipulator());

viewer->addEventHandler(new osgViewer::StatsHandler());
viewer->addEventHandler(new osgGA::StateSetManipulator());
viewer->addEventHandler(new osgViewer::ThreadingHandler());

viewer->setKeyEventSetsDone(0);
viewer->setQuitEventSetsDone(false);

reconfigure( viewer );

_viewer = viewer;
}

void ViewerWidget::reconfigure( osgViewer::View* view )
{
if ( !_gc.valid() )
{
// create the Qt graphics context if necessary; it will be shared across all views.
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);

traits->readDISPLAY();
if (traits->displayNum<0) traits->displayNum = 0;

traits->windowName = "osgEarthViewerQt";
traits->windowDecoration = false;
traits->x = x();
traits->y = y();
traits->width = width();
traits->height = height();
traits->doubleBuffer = true;
traits->inheritedWindowData = new osgQt::GraphicsWindowQt::WindowData(this);

_gc = new osgQt::GraphicsWindowQt( traits.get() );
}

// reconfigure this view's camera to use the Qt GC if necessary.
osg::Camera* camera = view->getCamera();
if ( camera->getGraphicsContext() != _gc.get() )
{
camera->setGraphicsContext( _gc.get() );
if ( !camera->getViewport() )
{
camera->setViewport(new osg::Viewport(0, 0, _gc->getTraits()->width, _gc->getTraits()->height));
}
camera->setProjectionMatrixAsPerspective(
30.0f, camera->getViewport()->width()/camera->getViewport()->height(), 1.0f, 10000.0f );
}
}


void ViewerWidget::paintEvent(QPaintEvent* e)
{
if (_viewer->getRunFrameScheme() == osgViewer::ViewerBase::CONTINUOUS ||
_viewer->checkNeedToDoFrame() )
{
_viewer->frame();
}
}
690 changes: 690 additions & 0 deletions src/plugins/globe/osgEarthUtil/Controls

Large diffs are not rendered by default.

2,214 changes: 2,214 additions & 0 deletions src/plugins/globe/osgEarthUtil/Controls.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/plugins/globe/qgsosgearthtilesource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void QgsOsgEarthTileSource::initialize( const std::string& referenceURI, const P
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 )
Expand Down
117 changes: 0 additions & 117 deletions src/plugins/globe/qgsosgviewer.cpp

This file was deleted.

107 changes: 0 additions & 107 deletions src/plugins/globe/qgsosgviewer.h

This file was deleted.