Skip to content
Permalink
Browse files

Merge pull request #8893 from wonder-sk/rule-based-3d-renderer

Rule-based 3D renderer
  • Loading branch information
wonder-sk committed Jan 18, 2019
2 parents 008dfee + de5c7cb commit 8709ab61eb5f172571166ed91e0788f3e39e2ead
@@ -1,6 +1,7 @@
// Include auto-generated SIP files
%Include auto_generated/qgs3dtypes.sip
%Include auto_generated/qgsphongmaterialsettings.sip
%Include auto_generated/qgsrulebased3drenderer.sip
%Include auto_generated/qgsvectorlayer3drenderer.sip
%Include auto_generated/symbols/qgsabstract3dsymbol.sip
%Include auto_generated/symbols/qgsline3dsymbol.sip
@@ -0,0 +1,280 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsrulebased3drenderer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsRuleBased3DRendererMetadata : Qgs3DRendererAbstractMetadata
{
%Docstring
Metadata for rule-based 3D renderer to allow creation of its instances from XML

.. warning::

This is not considered stable API, and may change in future QGIS releases. It is
exposed to the Python bindings as a tech preview only.

.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsrulebased3drenderer.h"
%End
public:
QgsRuleBased3DRendererMetadata();

virtual QgsAbstract3DRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) /Factory/;

%Docstring
Creates an instance of a 3D renderer based on a DOM element with renderer configuration
%End
};


class QgsRuleBased3DRenderer : QgsAbstract3DRenderer
{
%Docstring
Rule-based 3D renderer.

Similar to rule-based 2D renderer and rule-based labeling, it allows specification of rules for 3D symbols.

.. warning::

This is not considered stable API, and may change in future QGIS releases. It is
exposed to the Python bindings as a tech preview only.

.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsrulebased3drenderer.h"
%End
public:

typedef QList<QgsRuleBased3DRenderer::Rule *> RuleList;
typedef QMap<const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler *> RuleToHandlerMap;

class Rule
{
%Docstring

.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsrulebased3drenderer.h"
%End
public:
Rule( QgsAbstract3DSymbol *symbol /Transfer/, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
%Docstring
takes ownership of symbol, symbol may be None
%End
~Rule();


enum RegisterResult
{
Filtered,
Inactive,
Registered
};

QgsAbstract3DSymbol *symbol() const;
%Docstring
Gets the labeling settings. May return a null pointer.
%End

QString filterExpression() const;
%Docstring
A filter that will check if this rule applies

:return: An expression
%End

QString description() const;
%Docstring
A human readable description for this rule

:return: Description
%End

bool active() const;
%Docstring
Returns if this rule is active

:return: True if the rule is active
%End

bool isElse() const;
%Docstring
Check if this rule is an ELSE rule

:return: True if this rule is an else rule
%End

QString ruleKey() const;
%Docstring
Unique rule identifier (for identification of rule within labeling, used as provider ID)
%End

void setSymbol( QgsAbstract3DSymbol *symbol /Transfer/ );
%Docstring
Sets new symbol (or NULL). Deletes old symbol if any.
%End

void setFilterExpression( const QString &filterExp );
%Docstring
Set the expression used to check if a given feature shall be rendered with this rule

:param filterExp: An expression
%End

void setDescription( const QString &description );
%Docstring
Set a human readable description for this rule

:param description: Description
%End

void setActive( bool state );
%Docstring
Sets if this rule is active

:param state: Determines if the rule should be activated or deactivated
%End

void setIsElse( bool iselse );
%Docstring
Sets if this rule is an ELSE rule

:param iselse: If true, this rule is an ELSE rule
%End

void setRuleKey( const QString &key );
%Docstring
Override the assigned rule key (should be used just internally by rule-based renderer)
%End


const QgsRuleBased3DRenderer::RuleList &children() const;
%Docstring
Returns all children rules of this rule

:return: A list of rules
%End


QgsRuleBased3DRenderer::RuleList descendants() const;
%Docstring
Returns all children, grand-children, grand-grand-children, grand-gra... you get it

:return: A list of descendant rules
%End


QgsRuleBased3DRenderer::Rule *parent();
%Docstring
The parent rule

:return: Parent rule
%End

void appendChild( QgsRuleBased3DRenderer::Rule *rule /Transfer/ );
%Docstring
add child rule, take ownership, sets this as parent
%End

void insertChild( int i, QgsRuleBased3DRenderer::Rule *rule /Transfer/ );
%Docstring
add child rule, take ownership, sets this as parent
%End

void removeChildAt( int i );
%Docstring
delete child rule
%End

const QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) const;
%Docstring
Try to find a rule given its unique key
%End


QgsRuleBased3DRenderer::Rule *clone() const /Factory/;
%Docstring
clone this rule, return new instance
%End


static QgsRuleBased3DRenderer::Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) /Factory/;
%Docstring
Create a rule from an XML definition

:param ruleElem: The XML rule element
:param context: reading context

:return: A new rule
%End

QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
store labeling info to XML element
%End





private:
Rule( const QgsRuleBased3DRenderer::Rule &rh );
};


QgsRuleBased3DRenderer( QgsRuleBased3DRenderer::Rule *root /Transfer/ );
%Docstring
Construct renderer with the given root rule (takes ownership)
%End
~QgsRuleBased3DRenderer();

void setLayer( QgsVectorLayer *layer );
%Docstring
Sets vector layer associated with the renderer
%End
QgsVectorLayer *layer() const;
%Docstring
Returns vector layer associated with the renderer
%End

QgsRuleBased3DRenderer::Rule *rootRule();
%Docstring
Returns pointer to the root rule
%End

virtual QString type() const;
virtual QgsRuleBased3DRenderer *clone() const /Factory/;


virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;

virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );

virtual void resolveReferences( const QgsProject &project );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsrulebased3drenderer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -9,11 +9,13 @@ SET(QGIS_3D_SRCS
qgs3dutils.cpp
qgscameracontroller.cpp
qgscamerapose.cpp
qgsfeature3dhandler_p.cpp
qgslayoutitem3dmap.cpp
qgsoffscreen3dengine.cpp
qgsphongmaterialsettings.cpp
qgspointlightsettings.cpp
qgsraycastingutils_p.cpp
qgsrulebased3drenderer.cpp
qgstessellatedpolygongeometry.cpp
qgstilingscheme.cpp
qgsvectorlayer3drenderer.cpp
@@ -94,11 +96,13 @@ SET(QGIS_3D_HDRS
qgs3dutils.h
qgscameracontroller.h
qgscamerapose.h
qgsfeature3dhandler_p.h
qgslayoutitem3dmap.h
qgsoffscreen3dengine.h
qgsphongmaterialsettings.h
qgspointlightsettings.h
qgsraycastingutils_p.h
qgsrulebased3drenderer.h
qgstessellatedpolygongeometry.h
qgstilingscheme.h
qgsvectorlayer3drenderer.h
@@ -43,6 +43,7 @@
#include "qgschunknode_p.h"
#include "qgsmeshlayer.h"
#include "qgsmeshlayer3drenderer.h"
#include "qgsrulebased3drenderer.h"
#include "qgsterrainentity_p.h"
#include "qgsterraingenerator.h"
#include "qgstessellatedpolygongeometry.h"
@@ -539,6 +540,10 @@ void Qgs3DMapScene::addLayerEntity( QgsMapLayer *layer )
{
static_cast<QgsVectorLayer3DRenderer *>( renderer )->setLayer( static_cast<QgsVectorLayer *>( layer ) );
}
else if ( layer->type() == QgsMapLayer::VectorLayer && renderer->type() == QLatin1String( "rulebased" ) )
{
static_cast<QgsRuleBased3DRenderer *>( renderer )->setLayer( static_cast<QgsVectorLayer *>( layer ) );
}
else if ( layer->type() == QgsMapLayer::MeshLayer && renderer->type() == QLatin1String( "mesh" ) )
{
static_cast<QgsMeshLayer3DRenderer *>( renderer )->setLayer( static_cast<QgsMeshLayer *>( layer ) );
@@ -27,6 +27,10 @@
#include "qgsabstract3dengine.h"
#include "qgsterraingenerator.h"

#include "qgsline3dsymbol.h"
#include "qgspoint3dsymbol.h"
#include "qgspolygon3dsymbol.h"


QImage Qgs3DUtils::captureSceneImage( QgsAbstract3DEngine &engine, Qgs3DMapScene *scene )
{
@@ -374,3 +378,26 @@ QgsVector3D Qgs3DUtils::transformWorldCoordinates( const QgsVector3D &worldPoint
return mapToWorldCoordinates( mapPoint2, origin2 );
}

std::unique_ptr<QgsAbstract3DSymbol> Qgs3DUtils::symbolForGeometryType( QgsWkbTypes::GeometryType geomType )
{
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPoint3DSymbol );
case QgsWkbTypes::LineGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsLine3DSymbol );
case QgsWkbTypes::PolygonGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPolygon3DSymbol );
default:
return nullptr;
}
}

QgsExpressionContext Qgs3DUtils::globalProjectLayerExpressionContext( QgsVectorLayer *layer )
{
QgsExpressionContext exprContext;
exprContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() )
<< QgsExpressionContextUtils::layerScope( layer );
return exprContext;
}

0 comments on commit 8709ab6

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