Skip to content

Commit

Permalink
Mesh transform by expression (#44873)
Browse files Browse the repository at this point in the history
[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 9ce295e
Show file tree
Hide file tree
Showing 19 changed files with 1,232 additions and 158 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionMeshTransformByExpression.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshadvancedediting.sip.in
Expand Up @@ -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 *
* *
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/mesh/qgsmesheditor.sip.in
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -248,6 +248,7 @@ set(QGIS_APP_SRCS
mesh/qgsmeshcalculatordialog.cpp
mesh/qgsnewmeshlayerdialog.cpp
mesh/qgsmaptooleditmeshframe.cpp
mesh/qgsmeshtransformcoordinatesdockwidget.cpp
)

if (WITH_SPATIALITE)
Expand Down

0 comments on commit 9ce295e

Please sign in to comment.