Skip to content
Permalink
Browse files
Mesh transform by expression (#44873)
[feature] [mesh] allows the user to make geom transformation of mesh frame by changing the vertices coordinates by expression. Each coordinates (X,Y,Z) of selected vertices can be calculated with an expression allowing transformation of the mesh while the mesh is still valid.

Co-authored-by: Harrissou Sant-anna <delazj@gmail.com>
  • Loading branch information
vcloarec and DelazJ committed Sep 3, 2021
1 parent 8b18399 commit 9ce295ebbd99719e856839a9c2b3c33c921d351f
@@ -925,6 +925,7 @@
<file>themes/default/mActionMeshDigitizing.svg</file>
<file>themes/default/mActionMeshSelectPolygon.svg</file>
<file>themes/default/mActionNewMeshLayer.svg</file>
<file>themes/default/mActionMeshTransformByExpression.svg</file>
<file>themes/default/mIconGeometryCollectionLayer.svg</file>
<file>themes/default/mIconGps.svg</file>
<file>themes/default/mActionNewGpx.svg</file>
@@ -0,0 +1 @@
<svg height="24" width="24" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#5b6775" stroke-linecap="round" stroke-width="1.001834"><path d="m21.881899 5.6699901-9.359749 1.0247509m4.044093-5.1770872 1.271563 9.3294242m-1.329362-9.7534888 5.798899 4.5298213-4.411738 5.6477305-5.798898-4.5298209z"/><path d="m10.499931 14.707888-7.887379 7.548378m0-7.548378 7.887379 7.548378m-8.2458959-7.891486h8.6044139v8.234593h-8.6044139z"/><path d="m9.2712536 2.6065281-6.2013467 6.2974513m0-6.2974513 6.2013467 6.2974513m-6.4832259-6.5836989h6.7651061v6.8699459h-6.7651061z"/></g><g transform="translate(5.318556 -3.59995)"><path d="m-12.901812 19.194933c-1.92383-.683586-2.885744-1.718741-2.885742-3.105469-.000002-1.093739.50781-1.967761 1.523438-2.62207 1.025386-.654284 2.294916-.981432 3.808593-.981445 1.3769451.000013 2.470694.229505 3.2812505.688476.8105357.449232 1.2158087.991223 1.2158203 1.625977-.0000116.332042-.1269646.625011-.3808594.878906-.2539172.244151-.5468856.366221-.8789062.366211-.5468848.00001-.9961031-.380849-1.3476563-1.142578-.4882897-1.054675-1.2207109-1.582019-2.1972659-1.582031-.77149.000012-1.406255.253918-1.904297.761718-.498051.507824-.747074 1.215832-.74707 2.124024-.000004 1.787117.922847 2.680671 2.768555 2.680664.195305.000007.419914-.01952.6738279-.05859.4394451-.05859.7812417-.08788 1.0253906-.08789.595694.000008.8935452.170906.8935547.512696-.0000095.380866-.3027435.571295-.9082031.571289-.2148521.000006-.5371174-.03417-.9667969-.102539-.3222732-.05859-.5712962-.08788-.7470702-.08789-1.95313.000007-2.929692.996099-2.929688 2.988281-.000004.9668.258785 1.748049.776368 2.34375.517572.585939 1.240228.878907 2.167968.878907 1.1621017 0 1.9335853-.600585 2.3144535-1.801758.1953031-.634763.4101466-1.074216.6445312-1.31836.2441306-.244136.5663959-.366207.9667969-.366211.3320201.000004.6298714.122075.8935547.366211.2734255.234379.4101441.537113.4101562.908204-.0000121.888673-.4980585 1.625977-1.4941406 2.211914-.9961034.576171-2.2021568.864257-3.6181639.864257-1.55274 0-2.934575-.371093-4.145508-1.113281-1.201173-.742186-1.801759-1.733396-1.801758-2.973633-.000001-1.552729 1.196287-2.695306 3.588867-3.427734" fill="#5c3566" transform="translate(22.960894 .402232)"/><g fill="#fff"><path d="m8.8453703 15.335963c-1.8135886 1.95573-1.401671-.322256-.3145916-1.106748 1.1264312-.81289 1.7573183-.79349 1.7490763-.54418-.0096.290414-.8636237 1.035325-1.4344847 1.650928z" opacity=".5"/><path d="m8.2348719 21.645433c-1.8135886 1.95573-1.5022297.147018-.4151503-.637474 1.1264312-.81289 1.7573183-.79349 1.7490763-.54418-.0096.290414-.763065.566051-1.333926 1.181654z" opacity=".5"/><path d="m16.204463 23.831019c-1.74795 1.952651-1.613829.09846-.49057-.620714.858053-.549374 1.112902-.0745.49057.620714z" opacity=".5"/></g></g></svg>
@@ -83,6 +83,69 @@ Constructor
};


class QgsMeshTransformVerticesByExpression : QgsMeshAdvancedEditing
{
%Docstring(signature="appended")

Class that can transform vertices of a mesh by expression

Each coordinates are associated with an expression that can be defined with function
returning the current coordinates (see :py:func:`~QgsMeshEditRefineFaces.setExpressions`):

- $vertex_x
- $vertex_y
- $vertex_z

Example:
Transposing a mesh and translate following axe X with a distance of 50 and increase the level of the mesh
with an height of 80 when previous X coordinate is under 100 and de crease the level of 150 when X is under 100:

expressionX: "$vertex_y + 50"
expressionY: "$vertex_x"
expressionZ: "if( $vertex_x <= 100 , $vertex_z + 80 , $vertex_z - 150)"

.. versionadded:: 3.22
%End

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

QgsMeshTransformVerticesByExpression();
%Docstring
Constructor
%End

void setExpressions( const QString &expressionX, const QString &expressionY, const QString &expressionZ );
%Docstring
Sets the expressions for the coordinates transformation.

.. note::

Expressions are optional for each coordinate, the coordinate will not be transformed if the string is void.
%End

bool calculate( QgsMeshLayer *layer );
%Docstring
Calculates the transformed vertices of the mesh ``layer``, returns ``False`` if this leads to topological or geometrical errors.
The mesh layer must be in edit mode.

.. note::

this method not apply new vertices to the mesh layer but only store the calculated transformation
that can be apply later with :py:func:`QgsMeshEditor.advancedEdit()`
%End

QgsMeshVertex transformedVertex( QgsMeshLayer *layer, int vertexIndex ) const;
%Docstring
Returns the transformed vertex from its index ``vertexIndex`` for the mesh ``layer``

If ``layer`` is not the same than the one used to make the calculation, this will create an undefined behavior
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
@@ -171,7 +171,7 @@ Returns whether the mesh has been modified
%End


QList<int> freeVerticesIndexes();
QList<int> freeVerticesIndexes() const;
%Docstring
Returns all the free vertices indexes
%End
@@ -248,6 +248,7 @@ set(QGIS_APP_SRCS
mesh/qgsmeshcalculatordialog.cpp
mesh/qgsnewmeshlayerdialog.cpp
mesh/qgsmaptooleditmeshframe.cpp
mesh/qgsmeshtransformcoordinatesdockwidget.cpp
)

if (WITH_SPATIALITE)

0 comments on commit 9ce295e

Please sign in to comment.