QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsmesheditor.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmesheditor.h - QgsMeshEditor
3 
4  ---------------------
5  begin : 8.6.2021
6  copyright : (C) 2021 by Vincent Cloarec
7  email : vcloarec at gmail dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSMESHEDITOR_H
17 #define QGSMESHEDITOR_H
18 
19 #include <QObject>
20 #include <QUndoCommand>
21 #include <QPointer>
22 
23 #include "qgis.h"
24 #include "qgsmeshdataset.h"
25 #include "qgsmeshdataprovider.h"
26 #include "qgstriangularmesh.h"
27 #include "qgstopologicalmesh.h"
28 
30 
31 #if defined(_MSC_VER)
32 template CORE_EXPORT QVector<QVector<int>> SIP_SKIP;
33 #endif
34 
42 class CORE_EXPORT QgsMeshEditingError
43 {
44  public:
45 
48 
50  QgsMeshEditingError( Qgis::MeshEditingErrorType type, int elementIndex );
51 
53 
54  int elementIndex = -1;
55 
56  bool operator==( const QgsMeshEditingError &other ) const {return ( other.errorType == errorType && other.elementIndex == elementIndex );}
57  bool operator!=( const QgsMeshEditingError &other ) const {return !operator==( other );}
58 };
59 
67 class CORE_EXPORT QgsMeshEditor : public QObject
68 {
69  Q_OBJECT
70  public:
71 
73  QgsMeshEditor( QgsMeshLayer *meshLayer );
74 
76  QgsMeshEditor( QgsMesh *nativeMesh, QgsTriangularMesh *triangularMesh, QObject *parent = nullptr ); SIP_SKIP
77  ~QgsMeshEditor();
78 
83  QgsMeshDatasetGroup *createZValueDatasetGroup() SIP_TRANSFERBACK;
84 
86  QgsMeshEditingError initialize();
87 
89  void resetTriangularMesh( QgsTriangularMesh *triangularMesh ); SIP_SKIP
90 
92  bool faceCanBeAdded( const QgsMeshFace &face );
93 
98  bool isFaceGeometricallyCompatible( const QgsMeshFace &face );
99 
101  QgsMeshEditingError addFaces( const QVector<QgsMeshFace> &faces ); SIP_SKIP
102 
104  QgsMeshEditingError addFace( const QVector<int> &vertexIndexes );
105 
107  QgsMeshEditingError removeFaces( const QList<int> &facesToRemove );
108 
110  bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
111 
113  void flipEdge( int vertexIndex1, int vertexIndex2 );
114 
118  bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
119 
121  void merge( int vertexIndex1, int vertexIndex2 );
122 
126  bool faceCanBeSplit( int faceIndex ) const;
127 
132  int splitFaces( const QList<int> &faceIndexes );
133 
142  int addVertices( const QVector<QgsMeshVertex> &vertices, double tolerance ); SIP_SKIP
143 
152  int addPointsAsVertices( const QVector<QgsPoint> &point, double tolerance );
153 
159  QgsMeshEditingError removeVerticesWithoutFillHoles( const QList<int> &verticesToRemoveIndexes );
160 
168  QList<int> removeVerticesFillHoles( const QList<int> &verticesToRemoveIndexes );
169 
173  void changeZValues( const QList<int> &verticesIndexes, const QList<double> &newValues );
174 
186  bool canBeTransformed( const QList<int> &facesToCheck, const std::function<const QgsMeshVertex( int )> &transformFunction ) const; SIP_SKIP
187 
193  void changeXYValues( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
194 
200  void changeCoordinates( const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
201 
205  void advancedEdit( QgsMeshAdvancedEditing *editing );
206 
208  void stopEditing();
209 
211  QgsRectangle extent() const;
212 
214  bool isModified() const;
215 
223  bool reindex( bool renumbering );
224 
225  //----------- access element methods
226 
228  QList<int> freeVerticesIndexes() const;
229 
231  bool isVertexOnBoundary( int vertexIndex ) const;
232 
234  bool isVertexFree( int vertexIndex ) const;
235 
243  QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const; SIP_SKIP
244 
246  QgsTopologicalMesh &topologicalMesh(); SIP_SKIP
247 
249  QgsTriangularMesh *triangularMesh(); SIP_SKIP
250 
252  bool checkConsistency( QgsMeshEditingError &error ) const;
253 
258  bool edgeIsClose( QgsPointXY point, double tolerance, int &faceIndex, int &edgePosition );
259 
261  int validFacesCount() const;
262 
264  int validVerticesCount() const;
265 
267  int maximumVerticesPerFace() const;
268 
269  signals:
271  void meshEdited();
272 
273  private:
274  QgsMesh *mMesh = nullptr;
275  QgsTopologicalMesh mTopologicalMesh;
276  QgsTriangularMesh *mTriangularMesh = nullptr;
277  int mMaximumVerticesPerFace = 0;
278  QgsMeshDatasetGroup *mZValueDatasetGroup = nullptr;
279  int mValidVerticesCount = 0;
280  int mValidFacesCount = 0;
281 
282  QVector<QgsMeshFace> prepareFaces( const QVector<QgsMeshFace> &faces, QgsMeshEditingError &error );
283 
285  QUndoStack *mUndoStack = nullptr;
286 
287  struct Edit
288  {
289  QgsTopologicalMesh::Changes topologicalChanges;
290  QgsTriangularMesh::Changes triangularMeshChanges;
291  };
292  void applyEdit( Edit &edit );
293  void reverseEdit( Edit &edit );
294 
295  void applyAddVertex( Edit &edit, const QgsMeshVertex &vertex, double tolerance );
296  bool applyRemoveVertexFillHole( Edit &edit, int vertexIndex );
297  void applyRemoveVerticesWithoutFillHole( QgsMeshEditor::Edit &edit, const QList<int> &verticesIndexes );
298  void applyAddFaces( Edit &edit, const QgsTopologicalMesh::TopologicalFaces &faces );
299  void applyRemoveFaces( Edit &edit, const QList<int> &faceToRemoveIndex );
300  void applyChangeZValue( Edit &edit, const QList<int> &verticesIndexes, const QList<double> &newValues );
301  void applyChangeXYValue( Edit &edit, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
302  void applyFlipEdge( Edit &edit, int vertexIndex1, int vertexIndex2 );
303  void applyMerge( Edit &edit, int vertexIndex1, int vertexIndex2 );
304  void applySplit( QgsMeshEditor::Edit &edit, int faceIndex );
305  void applyAdvancedEdit( Edit &edit, QgsMeshAdvancedEditing *editing );
306 
307  void applyEditOnTriangularMesh( Edit &edit, const QgsTopologicalMesh::Changes &topologicChanges );
308 
309  void updateElementsCount( const QgsTopologicalMesh::Changes &changes, bool apply = true );
310 
311  friend class TestQgsMeshEditor;
318  friend class QgsMeshLayerUndoCommandSetZValue;
325 
327 };
328 
329 #ifndef SIP_RUN
330 
338 class QgsMeshLayerUndoCommandMeshEdit : public QUndoCommand
339 {
340  public:
341 
342  void undo() override;
343  void redo() override;
344 
345  protected:
346 
349  QPointer<QgsMeshEditor> mMeshEditor;
350  QList<QgsMeshEditor::Edit> mEdits;
351 };
352 
361 {
362  public:
363 
365  QgsMeshLayerUndoCommandAddVertices( QgsMeshEditor *meshEditor, const QVector<QgsMeshVertex> &vertices, double tolerance );
366  void redo() override;
367 
368  private:
369  QVector<QgsMeshVertex> mVertices;
370  double mTolerance = 0;
371 };
372 
381 {
382  public:
383 
387  QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes );
388  void redo() override;
389 
390  private:
391  QList<int> mVerticesToRemoveIndexes;
392 };
393 
402 {
403  public:
404 
413  QgsMeshLayerUndoCommandRemoveVerticesFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes, QList<int> *remainingVerticesPointer = nullptr );
414  void redo() override;
415 
416  private:
417  QList<int> mVerticesToRemoveIndexes;
418  QList<int> *mRemainingVerticesPointer = nullptr;
419 };
420 
429 {
430  public:
431 
434 
435  void redo() override;
436  private:
438 };
439 
448 {
449  public:
450 
452  QgsMeshLayerUndoCommandRemoveFaces( QgsMeshEditor *meshEditor, const QList<int> &facesToRemoveIndexes );
453 
454  void redo() override;
455  private:
456  QList<int> mfacesToRemoveIndexes;
457 };
458 
467 {
468  public:
469 
474  QgsMeshLayerUndoCommandChangeZValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<double> &newValues );
475  void redo() override;
476 
477  private:
478  QList<int> mVerticesIndexes;
479  QList<double> mNewValues;
480 };
481 
490 {
491  public:
492 
497  QgsMeshLayerUndoCommandChangeXYValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
498  void redo() override;
499 
500  private:
501  QList<int> mVerticesIndexes;
502  QList<QgsPointXY> mNewValues;
503 };
504 
513 {
514  public:
515 
520  QgsMeshLayerUndoCommandChangeCoordinates( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
521  void redo() override;
522 
523  private:
524  QList<int> mVerticesIndexes;
525  QList<QgsPoint> mNewCoordinates;
526 };
527 
536 {
537  public:
538 
542  QgsMeshLayerUndoCommandFlipEdge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
543  void redo() override;
544 
545  private:
546  int mVertexIndex1 = -1;
547  int mVertexIndex2 = -1;
548 };
549 
558 {
559  public:
560 
565  QgsMeshLayerUndoCommandMerge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
566  void redo() override;
567 
568  private:
569  int mVertexIndex1 = -1;
570  int mVertexIndex2 = -1;
571 };
572 
581 {
582  public:
583 
587  QgsMeshLayerUndoCommandSplitFaces( QgsMeshEditor *meshEditor, const QList<int> &faceIndexes );
588  void redo() override;
589 
590  private:
591  QList<int> mFaceIndexes;
592 };
593 
594 
602 {
603  public:
604 
607  void redo() override;
608 
609  private:
610  QgsMeshAdvancedEditing *mAdvancedEditing = nullptr;
611 };
612 
613 
614 
615 
616 #endif //SIP_RUN
617 
618 #endif // QGSMESHEDITOR_H
QgsMeshAdvancedEditing
Abstract class that can be derived to implement advanced editing on mesh.
Definition: qgsmeshadvancedediting.h:38
QgsMeshLayerUndoCommandFlipEdge::QgsMeshLayerUndoCommandFlipEdge
QgsMeshLayerUndoCommandFlipEdge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
Definition: qgsmesheditor.cpp:1116
QgsMeshLayerUndoCommandAddVertices::QgsMeshLayerUndoCommandAddVertices
QgsMeshLayerUndoCommandAddVertices(QgsMeshEditor *meshEditor, const QVector< QgsMeshVertex > &vertices, double tolerance)
Constructor with the associated meshEditor and vertices that will be added.
Definition: qgsmesheditor.cpp:795
QgsMeshLayerUndoCommandFlipEdge::redo
void redo() override
Definition: qgsmesheditor.cpp:1124
QgsTopologicalMesh::TopologicalFaces
Class that contains independent faces an topological information about this faces.
Definition: qgstopologicalmesh.h:62
QgsTopologicalMesh::Changes
Class that contains topological differences between two states of a topological mesh,...
Definition: qgstopologicalmesh.h:96
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsMeshLayerUndoCommandMerge
Class for undo/redo command for merging face.
Definition: qgsmesheditor.h:557
QgsMeshVertex
QgsPoint QgsMeshVertex
xyz coords of vertex
Definition: qgsmeshdataprovider.h:36
QgsMeshLayerUndoCommandRemoveVerticesFillHoles::QgsMeshLayerUndoCommandRemoveVerticesFillHoles
QgsMeshLayerUndoCommandRemoveVerticesFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes, QList< int > *remainingVerticesPointer=nullptr)
Constructor with the associated meshEditor and vertices that will be removed.
Definition: qgsmesheditor.cpp:825
Qgis::MeshEditingErrorType
MeshEditingErrorType
Type of error that can occur during mesh frame editing.
Definition: qgis.h:734
QgsMeshLayerUndoCommandChangeXYValue
Class for undo/redo command for changing (X,Y) value of vertices.
Definition: qgsmesheditor.h:489
QgsMeshLayerUndoCommandRemoveFaces
Class for undo/redo command for removing faces in mesh.
Definition: qgsmesheditor.h:447
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles
Class for undo/redo command for removing vertices in mesh without filling holes created by removed fa...
Definition: qgsmesheditor.h:380
QgsMeshLayerUndoCommandFlipEdge
Class for undo/redo command for flipping edge.
Definition: qgsmesheditor.h:535
qgis.h
QgsMeshLayerUndoCommandMeshEdit::QgsMeshLayerUndoCommandMeshEdit
QgsMeshLayerUndoCommandMeshEdit(QgsMeshEditor *meshEditor)
Constructor for the base class.
Definition: qgsmesheditor.cpp:772
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsMeshLayerUndoCommandChangeZValue
Class for undo/redo command for changing Z value of vertices.
Definition: qgsmesheditor.h:466
QgsMeshLayerUndoCommandMeshEdit::mMeshEditor
QPointer< QgsMeshEditor > mMeshEditor
Definition: qgsmesheditor.h:349
QgsMeshVertexCirculator
Convenient class that turn around a vertex and provide information about faces and vertices.
Definition: qgstopologicalmesh.h:379
QgsMeshLayerUndoCommandSplitFaces::QgsMeshLayerUndoCommandSplitFaces
QgsMeshLayerUndoCommandSplitFaces(QgsMeshEditor *meshEditor, const QList< int > &faceIndexes)
Constructor with the associated meshEditor and indexes faceIndexes of the faces to split.
Definition: qgsmesheditor.cpp:1166
QgsMeshLayerUndoCommandSplitFaces
Class for undo/redo command for splitting faces.
Definition: qgsmesheditor.h:580
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsMeshLayerUndoCommandRemoveVerticesFillHoles::redo
void redo() override
Definition: qgsmesheditor.cpp:836
SIP_TRANSFERBACK
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
QgsMeshLayerUndoCommandChangeZValue::QgsMeshLayerUndoCommandChangeZValue
QgsMeshLayerUndoCommandChangeZValue(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< double > &newValues)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
Definition: qgsmesheditor.cpp:1024
QgsMeshLayerUndoCommandAddFaces::redo
void redo() override
Definition: qgsmesheditor.cpp:912
QgsMeshEditor
Class that makes edit operation on a mesh.
Definition: qgsmesheditor.h:67
QgsTopologicalMesh
Class that wraps a QgsMesh to ensure the consistency of the mesh during editing and help to access to...
Definition: qgstopologicalmesh.h:47
qgstopologicalmesh.h
QgsMeshLayerUndoCommandChangeCoordinates::QgsMeshLayerUndoCommandChangeCoordinates
QgsMeshLayerUndoCommandChangeCoordinates(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< QgsPoint > &newCoordinates)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
Definition: qgsmesheditor.cpp:1075
qgstriangularmesh.h
QgsMeshLayerUndoCommandMerge::redo
void redo() override
Definition: qgsmesheditor.cpp:1149
QgsMeshLayerUndoCommandAddFaces
Class for undo/redo command for adding faces in mesh.
Definition: qgsmesheditor.h:428
QgsMeshLayerUndoCommandRemoveFaces::QgsMeshLayerUndoCommandRemoveFaces
QgsMeshLayerUndoCommandRemoveFaces(QgsMeshEditor *meshEditor, const QList< int > &facesToRemoveIndexes)
Constructor with the associated meshEditor and indexes facesToRemoveIndexes of the faces that will be...
Definition: qgsmesheditor.cpp:929
QgsMeshLayerUndoCommandChangeXYValue::redo
void redo() override
Definition: qgsmesheditor.cpp:1057
QgsMeshLayerUndoCommandMeshEdit::undo
void undo() override
Definition: qgsmesheditor.cpp:777
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsMeshLayerUndoCommandSplitFaces::redo
void redo() override
Definition: qgsmesheditor.cpp:1173
QgsMeshEditingError
Class that represents an error during mesh editing.
Definition: qgsmesheditor.h:42
QgsMeshLayerUndoCommandRemoveVerticesFillHoles
Class for undo/redo command for removing vertices in mesh filling holes created by removed faces.
Definition: qgsmesheditor.h:401
QgsMeshLayerUndoCommandChangeCoordinates::redo
void redo() override
Definition: qgsmesheditor.cpp:1083
QgsMeshLayerUndoCommandRemoveFaces::redo
void redo() override
Definition: qgsmesheditor.cpp:936
QgsMeshFace
QVector< int > QgsMeshFace
List of vertex indexes.
Definition: qgsmeshdataprovider.h:42
QgsMeshDatasetGroup
Abstract class that represents a dataset group.
Definition: qgsmeshdataset.h:578
QgsMeshEditingError::operator!=
bool operator!=(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:57
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsMeshEditingError::elementIndex
int elementIndex
Definition: qgsmesheditor.h:54
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles::QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes)
Constructor with the associated meshEditor and vertices that will be removed.
Definition: qgsmesheditor.cpp:878
QgsMeshLayerUndoCommandAdvancedEditing::redo
void redo() override
Definition: qgsmesheditor.cpp:1199
QgsMeshLayerUndoCommandAdvancedEditing
Class for undo/redo command for applying advanced editing.
Definition: qgsmesheditor.h:601
qgsmeshdataset.h
QgsMeshLayerUndoCommandMeshEdit
Base class for undo/redo command for mesh editing.
Definition: qgsmesheditor.h:338
QgsMeshLayerUndoCommandMerge::QgsMeshLayerUndoCommandMerge
QgsMeshLayerUndoCommandMerge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
Definition: qgsmesheditor.cpp:1141
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles::redo
void redo() override
Definition: qgsmesheditor.cpp:887
QgsMeshLayerUndoCommandChangeXYValue::QgsMeshLayerUndoCommandChangeXYValue
QgsMeshLayerUndoCommandChangeXYValue(QgsMeshEditor *meshEditor, const QList< int > &verticesIndexes, const QList< QgsPointXY > &newValues)
Constructor with the associated meshEditor and indexes verticesIndexes of the vertices that will have...
Definition: qgsmesheditor.cpp:1049
QgsMeshLayerUndoCommandChangeCoordinates
Class for undo/redo command for changing coordinate (X,Y,Z) values of vertices.
Definition: qgsmesheditor.h:512
QgsMeshLayerUndoCommandAddFaces::QgsMeshLayerUndoCommandAddFaces
QgsMeshLayerUndoCommandAddFaces(QgsMeshEditor *meshEditor, QgsTopologicalMesh::TopologicalFaces &faces)
Constructor with the associated meshEditor and faces that will be added.
Definition: qgsmesheditor.cpp:905
QgsMeshLayerUndoCommandMeshEdit::mEdits
QList< QgsMeshEditor::Edit > mEdits
Definition: qgsmesheditor.h:350
QgsTriangularMesh::Changes
The Changes class is used to make changes of the triangular and to keep traces of this changes If a C...
Definition: qgstriangularmesh.h:251
QgsMeshEditingError::errorType
Qgis::MeshEditingErrorType errorType
Definition: qgsmesheditor.h:52
QgsMeshLayerUndoCommandAddVertices
Class for undo/redo command for adding vertices in mesh.
Definition: qgsmesheditor.h:360
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:51
Qgis::MeshEditingErrorType::NoError
@ NoError
No type.
QgsMeshLayerUndoCommandAdvancedEditing::QgsMeshLayerUndoCommandAdvancedEditing
QgsMeshLayerUndoCommandAdvancedEditing(QgsMeshEditor *meshEditor, QgsMeshAdvancedEditing *advancdEdit)
Constructor with the associated meshEditor.
Definition: qgsmesheditor.cpp:1192
QgsMeshLayerUndoCommandChangeZValue::redo
void redo() override
Definition: qgsmesheditor.cpp:1032
qgsmeshdataprovider.h
QgsMeshLayerUndoCommandMeshEdit::redo
void redo() override
Definition: qgsmesheditor.cpp:786
QgsMeshEditingError::operator==
bool operator==(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:56
QgsMeshLayerUndoCommandAddVertices::redo
void redo() override
Definition: qgsmesheditor.cpp:803