Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mesh] mesh frame editing part 3 - Edit mesh map tool (#44037)
[mesh] [feature] add mesh map tool to CRUD/digitize actions for mesh frame (vertices, faces)
  • Loading branch information
vcloarec committed Jul 14, 2021
1 parent 5762fe3 commit c09443a
Show file tree
Hide file tree
Showing 34 changed files with 4,801 additions and 397 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -921,6 +921,7 @@
<file>themes/default/mIconFolderLinkParams.svg</file>
<file>themes/default/mIconFolderHomeParams.svg</file>
<file>themes/default/mActionMeasureBearing.svg</file>
<file>themes/default/mActionMeshDigitizing.svg</file>
<file>themes/default/mActionNewMeshLayer.svg</file>
</qresource>
<qresource prefix="/images/tips">
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionMeshDigitizing.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion python/core/auto_additions/qgis.py
Expand Up @@ -402,10 +402,11 @@
# monkey patching scoped based enum
Qgis.MeshEditingErrorType.NoError.__doc__ = "No type"
Qgis.MeshEditingErrorType.InvalidFace.__doc__ = "An error occurs due to an invalid face (for example, vertex indexes are unordered)"
Qgis.MeshEditingErrorType.TooManyVerticesInFace.__doc__ = "A face has more vertices than the maximum number supported per face"
Qgis.MeshEditingErrorType.FlatFace.__doc__ = "A flat face is present"
Qgis.MeshEditingErrorType.UniqueSharedVertex.__doc__ = "A least two faces share only one vertices"
Qgis.MeshEditingErrorType.InvalidVertex.__doc__ = "An error occurs due to an invalid vertex (for example, vertex index is out of range the available vertex)"
Qgis.MeshEditingErrorType.__doc__ = 'Type of error that can occur during mesh frame editing.\n\n.. versionadded:: 3.22\n\n' + '* ``NoError``: ' + Qgis.MeshEditingErrorType.NoError.__doc__ + '\n' + '* ``InvalidFace``: ' + Qgis.MeshEditingErrorType.InvalidFace.__doc__ + '\n' + '* ``FlatFace``: ' + Qgis.MeshEditingErrorType.FlatFace.__doc__ + '\n' + '* ``UniqueSharedVertex``: ' + Qgis.MeshEditingErrorType.UniqueSharedVertex.__doc__ + '\n' + '* ``InvalidVertex``: ' + Qgis.MeshEditingErrorType.InvalidVertex.__doc__
Qgis.MeshEditingErrorType.__doc__ = 'Type of error that can occur during mesh frame editing.\n\n.. versionadded:: 3.22\n\n' + '* ``NoError``: ' + Qgis.MeshEditingErrorType.NoError.__doc__ + '\n' + '* ``InvalidFace``: ' + Qgis.MeshEditingErrorType.InvalidFace.__doc__ + '\n' + '* ``TooManyVerticesInFace``: ' + Qgis.MeshEditingErrorType.TooManyVerticesInFace.__doc__ + '\n' + '* ``FlatFace``: ' + Qgis.MeshEditingErrorType.FlatFace.__doc__ + '\n' + '* ``UniqueSharedVertex``: ' + Qgis.MeshEditingErrorType.UniqueSharedVertex.__doc__ + '\n' + '* ``InvalidVertex``: ' + Qgis.MeshEditingErrorType.InvalidVertex.__doc__
# --
Qgis.MeshEditingErrorType.baseClass = Qgis
# monkey patching scoped based enum
Expand Down
9 changes: 9 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Expand Up @@ -142,6 +142,15 @@ Returns number of edges in the native mesh
.. versionadded:: 3.14
%End

virtual int maximumVerticesCountPerFace() const;
%Docstring
Returns the maximum number of vertices per face supported by the current mesh,
if returns 0, the number of vertices is unlimited

:return: Maximum number of vertices per face

.. versionadded:: 3.22
%End
virtual void populateMesh( QgsMesh *mesh ) const = 0;
%Docstring
Populates the mesh vertices, edges and faces
Expand Down
63 changes: 63 additions & 0 deletions python/core/auto_generated/mesh/qgsmesheditor.sip.in
Expand Up @@ -63,6 +63,11 @@ Constructor with a specified layer ``meshLayer``
QgsMeshEditingError initialize();
%Docstring
Initialize the mesh editor and return errors if the internal native mesh have topologic errors
%End

bool faceCanBeAdded( const QgsMeshFace &face );
%Docstring
Returns ``True`` if a ``face`` can be added to the mesh
%End

QgsMeshEditingError addFace( const QVector<int> &vertexIndexes );
Expand All @@ -73,6 +78,37 @@ Adds a face ``face`` to the mesh with vertex indexes ``vertexIndexes``, returns
QgsMeshEditingError removeFaces( const QList<int> &facesToRemove );
%Docstring
Removes faces ``faces`` to the mesh, returns topological errors if this operation fails (operation is not realized)
%End

bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
%Docstring
Returns ``True`` if the edge can be flipped (only available for edge shared by two faces with 3 vertices)
%End

void flipEdge( int vertexIndex1, int vertexIndex2 );
%Docstring
Flips edge (``vertexIndex1``, ``vertexIndex2``)
%End

bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
%Docstring
Returns ``True`` if faces separated by vertices with indexes ``vertexIndex1`` and ``vertexIndex2`` can be merged
%End

void merge( int vertexIndex1, int vertexIndex2 );
%Docstring
Merges faces separated by vertices with indexes ``vertexIndex1`` and ``vertexIndex2``
%End

bool faceCanBeSplit( int faceIndex ) const;
%Docstring
Returns ``True`` if face with index ``faceIndex`` can be split
%End

int splitFaces( const QList<int> &faceIndexes );
%Docstring
Splits faces with index ``faceIndexes``. Only faces that can be split are split.
Returns the count of faces effictively split
%End

int addPointsAsVertices( const QVector<QgsPoint> &point, double tolerance );
Expand All @@ -93,6 +129,17 @@ Removes vertices with indexes in the list ``verticesToRemoveIndexes`` in the mes
if ``fillHoles`` is set to ``True``, this operation will fill holes created in the mesh, if not remove the surrounding faces

If removing these vertices leads to a topological errors, the method will return the corresponding error and the operatio is canceled
%End

void changeZValues( const QList<int> &verticesIndexes, const QList<double> &newValues );
%Docstring
Changes the Z values of the vertices with indexes in ``vertices`` indexes with the values in ``newValues``
%End

void changeXYValues( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
%Docstring
Changes the (X,Y) coordinates values of the vertices with indexes in ``vertices`` indexes with the values in ``newValues``.
The caller has the responsibility to check if changing the vertices coordinates does not lead to topological errors
%End

void stopEditing();
Expand All @@ -110,6 +157,22 @@ Returns the extent of the edited mesh
Returns whether the mesh has been modified
%End


QList<int> freeVerticesIndexes();
%Docstring
Returns all the free vertices indexes
%End

bool isVertexOnBoundary( int vertexIndex ) const;
%Docstring
Returns whether the vertex with index ``vertexIndex`` is on a boundary
%End

bool isVertexFree( int vertexIndex ) const;
%Docstring
Returns whether the vertex with index ``vertexIndex`` is a free vertex
%End

signals:
void meshEdited();
%Docstring
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -299,6 +299,7 @@ The development version
{
NoError,
InvalidFace,
TooManyVerticesInFace,
FlatFace,
UniqueSharedVertex,
InvalidVertex,
Expand Down
2 changes: 1 addition & 1 deletion src/3d/mesh/qgsmeshterraingenerator.cpp
Expand Up @@ -168,7 +168,7 @@ void QgsMeshTerrainGenerator::readXml( const QDomElement &elem )
float QgsMeshTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings & ) const
{
QgsPointXY point( x, y );
int faceIndex = mTriangularMesh.faceIndexForPoint( point );
int faceIndex = mTriangularMesh.faceIndexForPoint_v2( point );
if ( faceIndex < 0 || faceIndex >= mTriangularMesh.triangles().count() )
return std::numeric_limits<float>::quiet_NaN();

Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -246,6 +246,7 @@ set(QGIS_APP_SRCS

mesh/qgsmeshcalculatordialog.cpp
mesh/qgsnewmeshlayerdialog.cpp
mesh/qgsmaptooleditmeshframe.cpp
)

if (WITH_SPATIALITE)
Expand Down
2 changes: 2 additions & 0 deletions src/app/maptools/qgsappmaptools.cpp
Expand Up @@ -69,6 +69,7 @@
#include "qgsmaptoolchangelabelproperties.h"
#include "qgsmaptoolpinlabels.h"
#include "qgsmaptooloffsetpointsymbol.h"
#include "qgsmaptooleditmeshframe.h"
#include "qgsspinbox.h"
#include "qgssettingsregistrycore.h"

Expand Down Expand Up @@ -176,6 +177,7 @@ QgsAppMapTools::QgsAppMapTools( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockW
mTools.insert( Tool::MoveLabel, new QgsMapToolMoveLabel( canvas, cadDock ) );
mTools.insert( Tool::RotateLabel, new QgsMapToolRotateLabel( canvas, cadDock ) );
mTools.insert( Tool::ChangeLabelProperties, new QgsMapToolChangeLabelProperties( canvas, cadDock ) );
mTools.insert( Tool::EditMeshFrame, new QgsMapToolEditMeshFrame( canvas ) );

mStreamDigitizingSettingsAction = new QgsStreamDigitizingSettingsAction();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/maptools/qgsappmaptools.h
Expand Up @@ -113,6 +113,7 @@ class QgsAppMapTools
ChangeLabelProperties,
ReverseLine,
TrimExtendFeature,
EditMeshFrame
};

QgsAppMapTools( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock );
Expand Down

0 comments on commit c09443a

Please sign in to comment.