Skip to content
Permalink
Browse files

Merge pull request #5128 from manisandro/globe

[Globe] Adapt for QGIS API changes, add Qt5 compatibility, support osgEarth up to current git master
  • Loading branch information
manisandro committed Sep 4, 2017
2 parents c43cd99 + 14f9cd1 commit 916dbce9f7e4b1485d2f65a8e53ac917d6e1d0d3
@@ -48,11 +48,11 @@ FIND_OSGEARTH_INCLUDE( OSGEARTH_ELEVATION_QUERY osgEarth/ElevationQuery )

###### libraries ######

MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY )

FIND_LIBRARY(${MYLIBRARY}
NAMES
${MYLIBRARYNAME}
${ARGN}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_BUILD_DIR}
@@ -93,8 +93,8 @@ FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY_DEBUG osgEarthFeaturesd )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY_DEBUG osgEarthSymbologyd )

FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY_DEBUG osgEarthQtd )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt5 osgEarthQt)
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY_DEBUG osgEarthQtd osgEarthQt5d)

FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY osgEarthAnnotation )
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY_DEBUG osgEarthAnnotationd )
@@ -3,7 +3,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PA

FIND_PACKAGE(OSG REQUIRED)
FIND_PACKAGE(OSGEARTH REQUIRED)
FIND_PACKAGE(Threads)
FIND_PACKAGE(Qt5OpenGL REQUIRED)

########################################################
# Files
@@ -55,18 +55,18 @@ QT5_WRAP_CPP (GLOBE_PLUGIN_MOC_SRCS ${GLOBE_PLUGIN_MOC_HDRS})
QT5_ADD_RESOURCES(GLOBE_PLUGIN_RCC_SRCS ${GLOBE_PLUGIN_RCCS})

ADD_LIBRARY (globeplugin SHARED ${GLOBE_PLUGIN_SRCS} ${GLOBE_PLUGIN_MOC_SRCS} ${GLOBE_PLUGIN_RCC_SRCS} ${GLOBE_PLUGIN_UIS_H} ${GLOBE_PLUGIN_HDRS})

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${Qt5OpenGL_INCLUDE_DIRS}
${OSGEARTH_INCLUDE_DIR}
${OSG_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${SIP_INCLUDE_DIR}
../../core
../../core/expression
../../core/geometry
../../core/metadata
../../core/raster
../../core/symbology
../../gui
..
${CMAKE_BINARY_DIR}/src/core
@@ -76,7 +76,7 @@ INCLUDE_DIRECTORIES(
TARGET_LINK_LIBRARIES(globeplugin
qgis_core
qgis_gui
${QT_QTOPENGL_LIBRARY}
Qt5::OpenGL
${OSGDB_LIBRARY}
${OSGGA_LIBRARY}
${OSGUTIL_LIBRARY}
@@ -106,8 +106,8 @@ FIND_OSG_LIBRARY( OSGVIEWER_LIBRARY_DEBUG osgViewerd )
FIND_OSG_LIBRARY( OSGGA_LIBRARY osgGA )
FIND_OSG_LIBRARY( OSGGA_LIBRARY_DEBUG osgGAd )

FIND_OSG_LIBRARY( OSGQT_LIBRARY osgQt )
FIND_OSG_LIBRARY( OSGQT_LIBRARY_DEBUG osgQtd )
FIND_OSG_LIBRARY( OSGQT_LIBRARY osgQt5 osgQt )
FIND_OSG_LIBRARY( OSGQT_LIBRARY_DEBUG osgQt5d osgQtd )

FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY osgWidget )
FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY_DEBUG osgWidgetd )

This file was deleted.

@@ -74,7 +74,7 @@ class QgsGlobeFeatureOptions : public osgEarth::Features::FeatureSourceOptions /
}

osgEarth::optional<std::string> mLayerId;
QgsVectorLayer *mLayer = nullptr;
QgsVectorLayer *mLayer = nullptr;
};

#endif // QGSGLOBEFEATUREOPTIONS_H
@@ -12,6 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/

#include <osgDB/ReaderWriter>
#include <osgDB/FileNameUtils>

@@ -27,32 +28,48 @@
#include "qgsglobefeaturesource.h"


QgsGlobeFeatureSource::QgsGlobeFeatureSource( const QgsGlobeFeatureOptions &options ) :
mOptions( options ),
mLayer( 0 ),
mProfile( 0 )
QgsGlobeFeatureSource::QgsGlobeFeatureSource( const QgsGlobeFeatureOptions &options )
: mOptions( options )
, mLayer( 0 )
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
, mProfile( 0 )
#endif
{
}

#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
osgEarth::Status QgsGlobeFeatureSource::initialize( const osgDB::Options *dbOptions )
{
#else
void QgsGlobeFeatureSource::initialize( const osgDB::Options *dbOptions )
{
#endif
Q_UNUSED( dbOptions )
mLayer = mOptions.layer();

connect( mLayer, SIGNAL( attributeValueChanged( QgsFeatureId, int, QVariant ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, QVariant ) ) );
connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry ) ) );

// create the profile
osgEarth::SpatialReference *ref = osgEarth::SpatialReference::create( mLayer->crs().toWkt().toStdString() );
if ( 0 == ref )
{
std::cout << "Cannot find the spatial reference" << std::endl;
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
return osgEarth::Status( osgEarth::Status::ConfigurationError );
#else
return;
#endif
}
QgsRectangle ext = mLayer->extent();
osgEarth::GeoExtent geoext( ref, ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum() );
mProfile = new osgEarth::Features::FeatureProfile( geoext );
mSchema = QgsGlobeFeatureUtils::schemaForFields( mLayer->pendingFields() );
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
setFeatureProfile( new osgEarth::Features::FeatureProfile( geoext ) );
return osgEarth::Status( osgEarth::Status::NoError );
#else
mProfile = new osgEarth::Features::FeatureProfile( geoext );
#endif
}

osgEarth::Features::FeatureCursor *QgsGlobeFeatureSource::createFeatureCursor( const osgEarth::Symbology::Query &query )
@@ -12,10 +12,12 @@
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGLOBEFEATURESOURCE_H
#define QGSGLOBEFEATURESOURCE_H

#include <osgEarthFeatures/FeatureSource>
#include <osgEarth/Version>
#include <QObject>

#include "qgsglobefeatureoptions.h"
@@ -38,18 +40,26 @@ class QgsGlobeFeatureSource : public QObject, public osgEarth::Features::Feature
const char *className() const override { return "QGISFeatureSource"; }
const char *libraryName() const override { return "QGIS"; }

void initialize( const osgDB::Options *dbOptions ) override;
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
osgEarth::Status initialize( const osgDB::Options *dbOptions );
#else
void initialize( const osgDB::Options *dbOptions );
#endif

protected:
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
const osgEarth::Features::FeatureProfile *createFeatureProfile() override { return mProfile; }
#endif
const osgEarth::Features::FeatureSchema &getSchema() const override { return mSchema; }

~QgsGlobeFeatureSource() {}

private:
QgsGlobeFeatureOptions mOptions;
QgsVectorLayer *mLayer = nullptr;
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
osgEarth::Features::FeatureProfile *mProfile = nullptr;
#endif
osgEarth::Features::FeatureSchema mSchema;
typedef std::map<osgEarth::Features::FeatureID, osg::observer_ptr<osgEarth::Features::Feature> > FeatureMap_t;
FeatureMap_t mFeatures;
@@ -36,7 +36,7 @@ class QgsGlobeFeatureUtils
return QgsPoint( QgsWkbTypes::PointZ, pt.x(), pt.y(), pt.z() );
}

static inline osg::Vec3d pointFromQgsPointXY( const QgsPoint &pt )
static inline osg::Vec3d pointFromQgsPoint( const QgsPoint &pt )
{
return osg::Vec3d( pt.x(), pt.y(), pt.z() );
}
@@ -47,7 +47,7 @@ class QgsGlobeFeatureUtils
osgEarth::Features::LineString *retLineString = new osgEarth::Features::LineString();
for ( int iVtx = 0, nVtx = linearString->vertexCount(); iVtx < nVtx; ++iVtx )
{
retLineString->push_back( pointFromQgsPointXY( linearString->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
retLineString->push_back( pointFromQgsPoint( linearString->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
}
delete linearString;
return retLineString;
@@ -63,7 +63,7 @@ class QgsGlobeFeatureUtils
// the outer ring
for ( int iVtx = 0, nVtx = linearPolygon->vertexCount( 0, 0 ); iVtx < nVtx; ++iVtx )
{
retPoly->push_back( pointFromQgsPointXY( linearPolygon->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
retPoly->push_back( pointFromQgsPoint( linearPolygon->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
}
retPoly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );

@@ -72,7 +72,7 @@ class QgsGlobeFeatureUtils
osgEarth::Features::Ring *innerRing = new osgEarth::Features::Ring();
for ( int iVtx = 0, nVtx = linearPolygon->vertexCount( 0, iRing ); iVtx < nVtx; ++iVtx )
{
innerRing->push_back( pointFromQgsPointXY( linearPolygon->vertexAt( QgsVertexId( 0, iRing, iVtx ) ) ) );
innerRing->push_back( pointFromQgsPoint( linearPolygon->vertexAt( QgsVertexId( 0, iRing, iVtx ) ) ) );
}
innerRing->rewind( osgEarth::Symbology::Ring::ORIENTATION_CW );
retPoly->getHoles().push_back( osg::ref_ptr<osgEarth::Features::Ring>( innerRing ) );
@@ -97,7 +97,7 @@ class QgsGlobeFeatureUtils
case QgsWkbTypes::Point:
{
osgEarth::Features::PointSet *pointSet = new osgEarth::Features::PointSet();
pointSet->push_back( pointFromQgsPointXY( *static_cast<QgsPoint *>( geom.geometry() ) ) );
pointSet->push_back( pointFromQgsPoint( *static_cast<QgsPoint *>( geom.geometry() ) ) );
return pointSet;
}

@@ -107,7 +107,7 @@ class QgsGlobeFeatureUtils
QgsMultiPointV2 *multiPoint = static_cast<QgsMultiPointV2 *>( geom.geometry() );
for ( int i = 0, n = multiPoint->numGeometries(); i < n; ++i )
{
pointSet->push_back( pointFromQgsPointXY( *static_cast<QgsPoint *>( multiPoint->geometryN( i ) ) ) );
pointSet->push_back( pointFromQgsPoint( *static_cast<QgsPoint *>( multiPoint->geometryN( i ) ) ) );
}
return pointSet;
}
@@ -156,7 +156,8 @@ class QgsGlobeFeatureUtils
static osgEarth::Features::Feature *featureFromQgsFeature( QgsVectorLayer *layer, QgsFeature &feat )
{
osgEarth::Features::Geometry *nGeom = geometryFromQgsGeometry( feat.geometry() );
osgEarth::Features::Feature *retFeat = new osgEarth::Features::Feature( nGeom, 0, osgEarth::Style(), feat.id() );
osgEarth::SpatialReference *ref = osgEarth::SpatialReference::create( layer->crs().toWkt().toStdString() );
osgEarth::Features::Feature *retFeat = new osgEarth::Features::Feature( nGeom, ref, osgEarth::Style(), feat.id() );

const QgsFields &fields = layer->pendingFields();
const QgsAttributes &attrs = feat.attributes();

0 comments on commit 916dbce

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