QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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
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
MeshEditingErrorType
Type of error that can occur during mesh frame editing.
Definition: qgis.h:502
Abstract class that can be derived to implement advanced editing on mesh.
Abstract class that represents a dataset group.
Class that represents an error during mesh editing.
Definition: qgsmesheditor.h:43
Qgis::MeshEditingErrorType errorType
Definition: qgsmesheditor.h:52
bool operator==(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:56
bool operator!=(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:57
Class that makes edit operation on a mesh.
Definition: qgsmesheditor.h:68
Class for undo/redo command for adding faces in mesh.
QgsMeshLayerUndoCommandAddFaces(QgsMeshEditor *meshEditor, QgsTopologicalMesh::TopologicalFaces &faces)
Constructor with the associated meshEditor and faces that will be added.
Class for undo/redo command for adding vertices in mesh.
QgsMeshLayerUndoCommandAddVertices(QgsMeshEditor *meshEditor, const QVector< QgsMeshVertex > &vertices, double tolerance)
Constructor with the associated meshEditor and vertices that will be added.
Class for undo/redo command for applying advanced editing.
QgsMeshLayerUndoCommandAdvancedEditing(QgsMeshEditor *meshEditor, QgsMeshAdvancedEditing *advancdEdit)
Constructor with the associated meshEditor.
Class for undo/redo command for changing coordinate (X,Y,Z) values of vertices.
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...
Class for undo/redo command for changing (X,Y) value of vertices.
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...
Class for undo/redo command for changing Z value of vertices.
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...
Class for undo/redo command for flipping edge.
QgsMeshLayerUndoCommandFlipEdge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
Class for undo/redo command for merging face.
QgsMeshLayerUndoCommandMerge(QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2)
Constructor with the associated meshEditor and the vertex indexes of the edge (vertexIndex1,...
Base class for undo/redo command for mesh editing.
QList< QgsMeshEditor::Edit > mEdits
QgsMeshLayerUndoCommandMeshEdit(QgsMeshEditor *meshEditor)
Constructor for the base class.
QPointer< QgsMeshEditor > mMeshEditor
Class for undo/redo command for removing faces in mesh.
QgsMeshLayerUndoCommandRemoveFaces(QgsMeshEditor *meshEditor, const QList< int > &facesToRemoveIndexes)
Constructor with the associated meshEditor and indexes facesToRemoveIndexes of the faces that will be...
Class for undo/redo command for removing vertices in mesh filling holes created by removed faces.
QgsMeshLayerUndoCommandRemoveVerticesFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes, QList< int > *remainingVerticesPointer=nullptr)
Constructor with the associated meshEditor and vertices that will be removed.
Class for undo/redo command for removing vertices in mesh without filling holes created by removed fa...
QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes)
Constructor with the associated meshEditor and vertices that will be removed.
Class for undo/redo command for splitting faces.
QgsMeshLayerUndoCommandSplitFaces(QgsMeshEditor *meshEditor, const QList< int > &faceIndexes)
Constructor with the associated meshEditor and indexes faceIndexes of the faces to split.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:97
Convenient class that turn around a vertex and provide information about faces and vertices.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Class that contains topological differences between two states of a topological mesh,...
Class that contains independent faces an topological information about this faces.
Class that wraps a QgsMesh to ensure the consistency of the mesh during editing and help to access to...
The Changes class is used to make changes of the triangular and to keep traces of this changes If a C...
Triangular/Derived Mesh is mesh with vertices in map coordinates.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QVector< int > QgsMeshFace
List of vertex indexes.
Mesh - vertices, edges and faces.