Skip to content

Commit

Permalink
Merge pull request #7105 from PeterPetrik/quick-3-identity
Browse files Browse the repository at this point in the history
[qgsquick] [feature] Identify and highlight
  • Loading branch information
m-kuhn committed Jun 22, 2018
2 parents 638fc0c + 26c13d4 commit c780d60
Show file tree
Hide file tree
Showing 24 changed files with 1,461 additions and 17 deletions.
66 changes: 66 additions & 0 deletions python/core/auto_generated/qgstessellator.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstessellator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsTessellator
{
%Docstring
Class that takes care of tessellation of polygons into triangles.

It is expected that client code will create the tessellator object, then repeatedly call
addPolygon() method that will generate triangles, and finally call data() to get final vertex data.

Optionally provides extrusion by adding triangles that serve as walls when extrusion height is non-zero.

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgstessellator.h"
%End
public:
QgsTessellator( double originX, double originY, bool addNormals, bool invertNormals = false, bool addBackFaces = false );
%Docstring
Creates tessellator with a specified origin point of the world (in map coordinates)
%End

void addPolygon( const QgsPolygon &polygon, float extrusionHeight );
%Docstring
Tessellates a triangle and adds its vertex entries to the output data array
%End

QVector<float> data() const;
%Docstring
Returns array of triangle vertex data

Vertice coordinates are stored as (x, z, -y)
%End

int dataVerticesCount() const;
%Docstring
Returns the number of vertices stored in the output data array
%End

int stride() const;
%Docstring
Returns size of one vertex entry in bytes
%End


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstessellator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
%Include auto_generated/expression/qgsexpressionnode.sip
%Include auto_generated/expression/qgsexpressionnodeimpl.sip
%Include auto_generated/expression/qgsexpressionfunction.sip
%Include auto_generated/qgstessellator.sip
%Include auto_generated/qgis.sip
%Include auto_generated/qgsaction.sip
%Include auto_generated/qgsactionscope.sip
Expand Down
9 changes: 0 additions & 9 deletions src/3d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SET(QGIS_3D_SRCS
qgscameracontroller.cpp
qgsphongmaterialsettings.cpp
qgstessellatedpolygongeometry.cpp
qgstessellator.cpp
qgstilingscheme.cpp
qgsvectorlayer3drenderer.cpp

Expand Down Expand Up @@ -41,12 +40,6 @@ SET(QGIS_3D_SRCS
terrain/qgsterraintileloader_p.cpp
#terrain/quantizedmeshgeometry.cpp
#terrain/quantizedmeshterraingenerator.cpp

${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc
)

SET(QGIS_3D_MOC_HDRS
Expand Down Expand Up @@ -82,7 +75,6 @@ SET(QGIS_3D_HDRS
qgscameracontroller.h
qgsphongmaterialsettings.h
qgstessellatedpolygongeometry.h
qgstessellator.h
qgstilingscheme.h
qgsvectorlayer3drenderer.h

Expand Down Expand Up @@ -127,7 +119,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/3d
${CMAKE_SOURCE_DIR}/external/poly2tri
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/3d
)
Expand Down
10 changes: 10 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ SET(QGIS_CORE_SRCS
${CMAKE_SOURCE_DIR}/external/nmea/time.c
${CMAKE_SOURCE_DIR}/external/nmea/tok.c

${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc

gps/qgsgpsconnection.cpp
gps/qgsgpsconnectionregistry.cpp
gps/qgsgpsdconnection.cpp
Expand Down Expand Up @@ -291,6 +297,7 @@ SET(QGIS_CORE_SRCS
qgsstringstatisticalsummary.cpp
qgsstringutils.cpp
qgstaskmanager.cpp
qgstessellator.cpp
qgstextlabelfeature.cpp
qgstextrenderer.cpp
qgstolerance.cpp
Expand Down Expand Up @@ -811,6 +818,8 @@ SET(QGIS_CORE_HDRS
expression/qgsexpressionnodeimpl.h
expression/qgsexpressionfunction.h

qgstessellator.h

qgis.h
qgis_sip.h
qgsaction.h
Expand Down Expand Up @@ -1204,6 +1213,7 @@ INCLUDE_DIRECTORIES(
metadata
mesh
${CMAKE_SOURCE_DIR}/external/nmea
${CMAKE_SOURCE_DIR}/external/poly2tri
)
IF (WITH_INTERNAL_QEXTSERIALPORT)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/external/qextserialport)
Expand Down
5 changes: 5 additions & 0 deletions src/3d/qgstessellator.cpp → src/core/qgstessellator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ QgsPoint getPointFromData( QVector< float >::const_iterator &it )
return QgsPoint( x, y, z );
}

int QgsTessellator::dataVerticesCount() const
{
return mData.size() / 3;
}

std::unique_ptr<QgsMultiPolygon> QgsTessellator::asMultiPolygon() const
{
std::unique_ptr< QgsMultiPolygon > mp = qgis::make_unique< QgsMultiPolygon >();
Expand Down
22 changes: 16 additions & 6 deletions src/3d/qgstessellator.h → src/core/qgstessellator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@
#ifndef QGSTESSELLATOR_H
#define QGSTESSELLATOR_H

#include "qgis_3d.h"
#include "qgis_core.h"
#include "qgis.h"

class QgsPolygon;
class QgsMultiPolygon;

#include <QVector>
#include <memory>
#include "qgspoint.h"

/**
* \ingroup 3d
* \ingroup core
* Class that takes care of tessellation of polygons into triangles.
*
* It is expected that client code will create the tessellator object, then repeatedly call
* addPolygon() method that will generate triangles, and finally call data() to get final vertex data.
*
* Optionally provides extrusion by adding triangles that serve as walls when extrusion height is non-zero.
*
* \since QGIS 3.0
* \since QGIS 3.4 (since QGIS 3.0 in QGIS_3D library)
*/
class _3D_EXPORT QgsTessellator
class CORE_EXPORT QgsTessellator
{
public:
//! Creates tessellator with a specified origin point of the world (in map coordinates)
Expand All @@ -44,15 +46,23 @@ class _3D_EXPORT QgsTessellator
//! Tessellates a triangle and adds its vertex entries to the output data array
void addPolygon( const QgsPolygon &polygon, float extrusionHeight );

//! Returns array of triangle vertex data
/**
* Returns array of triangle vertex data
*
* Vertice coordinates are stored as (x, z, -y)
*/
QVector<float> data() const { return mData; }

//! Returns the number of vertices stored in the output data array
int dataVerticesCount() const;

//! Returns size of one vertex entry in bytes
int stride() const { return mStride; }

/**
* Returns the triangulation as a multipolygon geometry.
*/
std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const;
std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const SIP_SKIP;

private:
double mOriginX = 0, mOriginY = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
############################################################
# sources
SET(QGIS_QUICK_GUI_MOC_HDRS
qgsquickfeaturelayerpair.h
qgsquickfeaturehighlight.h
qgsquickidentifykit.h
qgsquickmapcanvasmap.h
qgsquickmapsettings.h
qgsquickmaptransform.h
qgsquickmessagelogmodel.h
qgsquickscalebarkit.h
qgsquickutils.h
)

SET(QGIS_QUICK_GUI_HDRS
qgsquickhighlightsgnode.h
)

SET(QGIS_QUICK_GUI_SRC
qgsquickfeaturelayerpair.cpp
qgsquickfeaturehighlight.cpp
qgsquickhighlightsgnode.cpp
qgsquickidentifykit.cpp
qgsquickmapcanvasmap.cpp
qgsquickmapsettings.cpp
qgsquickmaptransform.cpp
qgsquickmessagelogmodel.cpp
qgsquickscalebarkit.cpp
qgsquickutils.cpp
Expand Down
8 changes: 8 additions & 0 deletions src/quickgui/plugin/qgsquickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
#include "qgscoordinatetransformcontext.h"
#include "qgsvectorlayer.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickidentifykit.h"
#include "qgsquickfeaturelayerpair.h"
#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "qgsquickmaptransform.h"
#include "qgsquickmessagelogmodel.h"
#include "qgsquickplugin.h"
#include "qgsquickscalebarkit.h"
Expand All @@ -53,10 +57,14 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsFeatureId > ( "QgsFeatureId" );
qRegisterMetaType< QgsPoint >( "QgsPoint" );
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
Expand Down
84 changes: 84 additions & 0 deletions src/quickgui/qgsquickfeaturehighlight.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/***************************************************************************
qgsqguickfeaturehighlight.cpp
--------------------------------------
Date : May 2018
Copyright : (C) 2018 by Peter Petrik
Email : zilolv at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <memory>

#include "qgsvectorlayer.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickmapsettings.h"
#include "qgsquickhighlightsgnode.h"


QgsQuickFeatureHighlight::QgsQuickFeatureHighlight( QQuickItem *parent )
: QQuickItem( parent )
{
setFlags( QQuickItem::ItemHasContents );
setAntialiasing( true );

// transform to device coords
mTransform.appendToItem( this );

connect( this, &QgsQuickFeatureHighlight::mapSettingsChanged, this, &QgsQuickFeatureHighlight::onMapSettingsChanged );
connect( this, &QgsQuickFeatureHighlight::featureLayerPairChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::colorChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::widthChanged, this, &QgsQuickFeatureHighlight::markDirty );
}

void QgsQuickFeatureHighlight::markDirty()
{
mDirty = true;
update();
}

void QgsQuickFeatureHighlight::onMapSettingsChanged()
{
mTransform.setMapSettings( mMapSettings );
markDirty();
}

QSGNode *QgsQuickFeatureHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeData * )
{
if ( !mDirty || !mMapSettings || !mFeatureLayerPair.isValid() )
return n;

delete n;
n = new QSGNode;

QgsVectorLayer *layer = mFeatureLayerPair.layer();
Q_ASSERT( layer ); // we checked the validity of feature-layer pair
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() );

QgsFeature feature = mFeatureLayerPair.feature();
if ( feature.hasGeometry() )
{
QgsGeometry geom( feature.geometry() );
try
{
geom.transform( transf );
std::unique_ptr<QgsQuickHighlightSGNode> rb( new QgsQuickHighlightSGNode( geom, mColor, mWidth ) );
rb->setFlag( QSGNode::OwnedByParent );
n->appendChildNode( rb.release() );
}
catch ( QgsCsException &e )
{
Q_UNUSED( e );
// Caught an error in transform
}
}
mDirty = false;

return n;
}

0 comments on commit c780d60

Please sign in to comment.