QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
29 
31 
39 class CORE_EXPORT QgsMeshEditingError
40 {
41  public:
42 
45 
47  QgsMeshEditingError( Qgis::MeshEditingErrorType type, int elementIndex );
48 
50 
52 
53  bool operator==( const QgsMeshEditingError &other ) const {return ( other.errorType == errorType && other.elementIndex == elementIndex );}
54  bool operator!=( const QgsMeshEditingError &other ) const {return !operator==( other );}
55 };
56 
64 class CORE_EXPORT QgsMeshEditor : public QObject
65 {
66  Q_OBJECT
67  public:
68 
70  QgsMeshEditor( QgsMeshLayer *meshLayer );
71 
73  QgsMeshEditor( QgsMesh *nativeMesh, QgsTriangularMesh *triangularMesh, QObject *parent = nullptr ); SIP_SKIP
75 
80  QgsMeshDatasetGroup *createZValueDatasetGroup() SIP_TRANSFERBACK;
81 
83  QgsMeshEditingError initialize();
84 
86  void resetTriangularMesh( QgsTriangularMesh *triangularMesh ); SIP_SKIP
87 
89  bool faceCanBeAdded( const QgsMeshFace &face );
90 
95  bool isFaceGeometricallyCompatible( const QgsMeshFace &face );
96 
98  QgsMeshEditingError addFaces( const QVector<QgsMeshFace> &faces ); SIP_SKIP
99 
101  QgsMeshEditingError addFace( const QVector<int> &vertexIndexes );
102 
104  QgsMeshEditingError removeFaces( const QList<int> &facesToRemove );
105 
107  bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
108 
110  void flipEdge( int vertexIndex1, int vertexIndex2 );
111 
115  bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
116 
118  void merge( int vertexIndex1, int vertexIndex2 );
119 
123  bool faceCanBeSplit( int faceIndex ) const;
124 
129  int splitFaces( const QList<int> &faceIndexes );
130 
139  int addVertices( const QVector<QgsMeshVertex> &vertices, double tolerance ); SIP_SKIP
140 
149  int addPointsAsVertices( const QVector<QgsPoint> &point, double tolerance );
150 
157  QgsMeshEditingError removeVertices( const QList<int> &verticesToRemoveIndexes, bool fillHoles = false );
158 
162  void changeZValues( const QList<int> &verticesIndexes, const QList<double> &newValues );
163 
175  bool canBeTransformed( const QList<int> &facesToCheck, const std::function<const QgsMeshVertex( int )> &transformFunction ) const; SIP_SKIP
176 
182  void changeXYValues( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
183 
189  void changeCoordinates( const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
190 
194  void advancedEdit( QgsMeshAdvancedEditing *editing );
195 
197  void stopEditing();
198 
200  QgsRectangle extent() const;
201 
203  bool isModified() const;
204 
212  bool reindex( bool renumbering );
213 
214  //----------- access element methods
215 
217  QList<int> freeVerticesIndexes() const;
218 
220  bool isVertexOnBoundary( int vertexIndex ) const;
221 
223  bool isVertexFree( int vertexIndex ) const;
224 
232  QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const; SIP_SKIP
233 
235  QgsTopologicalMesh &topologicalMesh(); SIP_SKIP
236 
238  QgsTriangularMesh *triangularMesh(); SIP_SKIP
239 
241  bool checkConsistency() const;
242 
247  bool edgeIsClose( QgsPointXY point, double tolerance, int &faceIndex, int &edgePosition );
248 
250  int validFacesCount() const;
251 
253  int validVerticesCount() const;
254 
255  signals:
257  void meshEdited();
258 
259  private:
260  QgsMesh *mMesh = nullptr;
261  QgsTopologicalMesh mTopologicalMesh;
262  QgsTriangularMesh *mTriangularMesh = nullptr;
263  int mMaximumVerticesPerFace = 0;
264  QgsMeshDatasetGroup *mZValueDatasetGroup = nullptr;
265  int mValidVerticesCount = 0;
266  int mValidFacesCount = 0;
267 
268  QVector<QgsMeshFace> prepareFaces( const QVector<QgsMeshFace> &faces, QgsMeshEditingError &error );
269 
271  QUndoStack *mUndoStack = nullptr;
272 
273  struct Edit
274  {
275  QgsTopologicalMesh::Changes topologicalChanges;
276  QgsTriangularMesh::Changes triangularMeshChanges;
277  };
278  void applyEdit( Edit &edit );
279  void reverseEdit( Edit &edit );
280 
281  void applyAddVertex( Edit &edit, const QgsMeshVertex &vertex, double tolerance );
282  void applyRemoveVertexFillHole( Edit &edit, int vertexIndex );
283  void applyRemoveVerticesWithoutFillHole( QgsMeshEditor::Edit &edit, const QList<int> &verticesIndexes );
284  void applyAddFaces( Edit &edit, const QgsTopologicalMesh::TopologicalFaces &faces );
285  void applyRemoveFaces( Edit &edit, const QList<int> &faceToRemoveIndex );
286  void applyChangeZValue( Edit &edit, const QList<int> &verticesIndexes, const QList<double> &newValues );
287  void applyChangeXYValue( Edit &edit, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
288  void applyFlipEdge( Edit &edit, int vertexIndex1, int vertexIndex2 );
289  void applyMerge( Edit &edit, int vertexIndex1, int vertexIndex2 );
290  void applySplit( QgsMeshEditor::Edit &edit, int faceIndex );
291  void applyAdvancedEdit( Edit &edit, QgsMeshAdvancedEditing *editing );
292 
293  void applyEditOnTriangularMesh( Edit &edit, const QgsTopologicalMesh::Changes &topologicChanges );
294 
295  void updateElementsCount( const QgsTopologicalMesh::Changes &changes, bool apply = true );
296 
297  friend class TestQgsMeshEditor;
303  friend class QgsMeshLayerUndoCommandSetZValue;
310 
312 };
313 
314 #ifndef SIP_RUN
315 
323 class QgsMeshLayerUndoCommandMeshEdit : public QUndoCommand
324 {
325  public:
326 
327  void undo() override;
328  void redo() override;
329 
330  protected:
331 
334  QPointer<QgsMeshEditor> mMeshEditor;
335  QList<QgsMeshEditor::Edit> mEdits;
336 };
337 
346 {
347  public:
348 
350  QgsMeshLayerUndoCommandAddVertices( QgsMeshEditor *meshEditor, const QVector<QgsMeshVertex> &vertices, double tolerance );
351  void redo() override;
352 
353  private:
354  QVector<QgsMeshVertex> mVertices;
355  double mTolerance = 0;
356 };
357 
366 {
367  public:
369  QgsMeshLayerUndoCommandRemoveVertices( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes, bool fillHole );
370  void redo() override;
371 
372  private:
373  QList<int> mVerticesToRemoveIndexes;
374  bool mFillHole = false;
375 };
376 
385 {
386  public:
387 
390 
391  void redo() override;
392  private:
394 };
395 
404 {
405  public:
406 
408  QgsMeshLayerUndoCommandRemoveFaces( QgsMeshEditor *meshEditor, const QList<int> &facesToRemoveIndexes );
409 
410  void redo() override;
411  private:
412  QList<int> mfacesToRemoveIndexes;
413 };
414 
423 {
424  public:
425 
430  QgsMeshLayerUndoCommandChangeZValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<double> &newValues );
431  void redo() override;
432 
433  private:
434  QList<int> mVerticesIndexes;
435  QList<double> mNewValues;
436 };
437 
446 {
447  public:
448 
453  QgsMeshLayerUndoCommandChangeXYValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
454  void redo() override;
455 
456  private:
457  QList<int> mVerticesIndexes;
458  QList<QgsPointXY> mNewValues;
459 };
460 
469 {
470  public:
471 
476  QgsMeshLayerUndoCommandChangeCoordinates( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
477  void redo() override;
478 
479  private:
480  QList<int> mVerticesIndexes;
481  QList<QgsPoint> mNewCoordinates;
482 };
483 
492 {
493  public:
494 
498  QgsMeshLayerUndoCommandFlipEdge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
499  void redo() override;
500 
501  private:
502  int mVertexIndex1 = -1;
503  int mVertexIndex2 = -1;
504 };
505 
514 {
515  public:
516 
521  QgsMeshLayerUndoCommandMerge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
522  void redo() override;
523 
524  private:
525  int mVertexIndex1 = -1;
526  int mVertexIndex2 = -1;
527 };
528 
537 {
538  public:
539 
543  QgsMeshLayerUndoCommandSplitFaces( QgsMeshEditor *meshEditor, const QList<int> &faceIndexes );
544  void redo() override;
545 
546  private:
547  QList<int> mFaceIndexes;
548 };
549 
550 
558 {
559  public:
560 
563  void redo() override;
564 
565  private:
566  QgsMeshAdvancedEditing *mAdvancedEditing = nullptr;
567 };
568 
569 
570 
571 
572 #endif //SIP_RUN
573 
574 #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:40
Qgis::MeshEditingErrorType errorType
Definition: qgsmesheditor.h:49
bool operator==(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:53
bool operator!=(const QgsMeshEditingError &other) const
Definition: qgsmesheditor.h:54
Class that makes edit operation on a mesh.
Definition: qgsmesheditor.h:65
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.
QgsMeshLayerUndoCommandRemoveVertices(QgsMeshEditor *meshEditor, const QList< int > &verticesToRemoveIndexes, bool fillHole)
Constructor with the associated meshEditor and vertices that will be removed and the flag fillHole.
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.