QGIS API Documentation 3.29.0-Master (ade4f0cf0f)
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)
32template CORE_EXPORT QVector<QVector<int>> SIP_SKIP;
33#endif
34
42class 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
67class 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
94 QgsMeshEditingError initializeWithErrorsFix();
95
101 bool fixError( const QgsMeshEditingError &error );
102
104 void resetTriangularMesh( QgsTriangularMesh *triangularMesh ); SIP_SKIP
105
107 bool faceCanBeAdded( const QgsMeshFace &face );
108
113 bool isFaceGeometricallyCompatible( const QgsMeshFace &face );
114
116 QgsMeshEditingError addFaces( const QVector<QgsMeshFace> &faces ); SIP_SKIP
117
119 QgsMeshEditingError addFace( const QVector<int> &vertexIndexes );
120
122 QgsMeshEditingError removeFaces( const QList<int> &facesToRemove );
123
125 bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
126
128 void flipEdge( int vertexIndex1, int vertexIndex2 );
129
133 bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
134
136 void merge( int vertexIndex1, int vertexIndex2 );
137
141 bool faceCanBeSplit( int faceIndex ) const;
142
147 int splitFaces( const QList<int> &faceIndexes );
148
157 int addVertices( const QVector<QgsMeshVertex> &vertices, double tolerance ); SIP_SKIP
158
167 int addPointsAsVertices( const QVector<QgsPoint> &point, double tolerance );
168
174 QgsMeshEditingError removeVerticesWithoutFillHoles( const QList<int> &verticesToRemoveIndexes );
175
183 QList<int> removeVerticesFillHoles( const QList<int> &verticesToRemoveIndexes );
184
188 void changeZValues( const QList<int> &verticesIndexes, const QList<double> &newValues );
189
201 bool canBeTransformed( const QList<int> &facesToCheck, const std::function<const QgsMeshVertex( int )> &transformFunction ) const; SIP_SKIP
202
208 void changeXYValues( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
209
215 void changeCoordinates( const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
216
220 void advancedEdit( QgsMeshAdvancedEditing *editing );
221
223 void stopEditing();
224
226 QgsRectangle extent() const;
227
229 bool isModified() const;
230
238 bool reindex( bool renumbering );
239
240 //----------- access element methods
241
243 QList<int> freeVerticesIndexes() const;
244
246 bool isVertexOnBoundary( int vertexIndex ) const;
247
249 bool isVertexFree( int vertexIndex ) const;
250
258 QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const; SIP_SKIP
259
261 QgsTopologicalMesh &topologicalMesh(); SIP_SKIP
262
264 QgsTriangularMesh *triangularMesh(); SIP_SKIP
265
267 bool checkConsistency( QgsMeshEditingError &error ) const;
268
273 bool edgeIsClose( QgsPointXY point, double tolerance, int &faceIndex, int &edgePosition );
274
276 int validFacesCount() const;
277
279 int validVerticesCount() const;
280
282 int maximumVerticesPerFace() const;
283
284 signals:
286 void meshEdited();
287
288 private:
289 QgsMesh *mMesh = nullptr;
290 QgsTopologicalMesh mTopologicalMesh;
291 QgsTriangularMesh *mTriangularMesh = nullptr;
292 int mMaximumVerticesPerFace = 0;
293 QgsMeshDatasetGroup *mZValueDatasetGroup = nullptr;
294 int mValidVerticesCount = 0;
295 int mValidFacesCount = 0;
296
297 QVector<QgsMeshFace> prepareFaces( const QVector<QgsMeshFace> &faces, QgsMeshEditingError &error );
298
300 QUndoStack *mUndoStack = nullptr;
301
302 struct Edit
303 {
304 QgsTopologicalMesh::Changes topologicalChanges;
305 QgsTriangularMesh::Changes triangularMeshChanges;
306 };
307 void applyEdit( Edit &edit );
308 void reverseEdit( Edit &edit );
309
310 void applyAddVertex( Edit &edit, const QgsMeshVertex &vertex, double tolerance );
311 bool applyRemoveVertexFillHole( Edit &edit, int vertexIndex );
312 void applyRemoveVerticesWithoutFillHole( QgsMeshEditor::Edit &edit, const QList<int> &verticesIndexes );
313 void applyAddFaces( Edit &edit, const QgsTopologicalMesh::TopologicalFaces &faces );
314 void applyRemoveFaces( Edit &edit, const QList<int> &faceToRemoveIndex );
315 void applyChangeZValue( Edit &edit, const QList<int> &verticesIndexes, const QList<double> &newValues );
316 void applyChangeXYValue( Edit &edit, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
317 void applyFlipEdge( Edit &edit, int vertexIndex1, int vertexIndex2 );
318 void applyMerge( Edit &edit, int vertexIndex1, int vertexIndex2 );
319 void applySplit( QgsMeshEditor::Edit &edit, int faceIndex );
320 void applyAdvancedEdit( Edit &edit, QgsMeshAdvancedEditing *editing );
321
322 void applyEditOnTriangularMesh( Edit &edit, const QgsTopologicalMesh::Changes &topologicChanges );
323
324 void updateElementsCount( const QgsTopologicalMesh::Changes &changes, bool apply = true );
325
326 friend class TestQgsMeshEditor;
333 friend class QgsMeshLayerUndoCommandSetZValue;
340
342};
343
344#ifndef SIP_RUN
345
353class QgsMeshLayerUndoCommandMeshEdit : public QUndoCommand
354{
355 public:
356
357 void undo() override;
358 void redo() override;
359
360 protected:
361
364 QPointer<QgsMeshEditor> mMeshEditor;
365 QList<QgsMeshEditor::Edit> mEdits;
366};
367
376{
377 public:
378
380 QgsMeshLayerUndoCommandAddVertices( QgsMeshEditor *meshEditor, const QVector<QgsMeshVertex> &vertices, double tolerance );
381 void redo() override;
382
383 private:
384 QVector<QgsMeshVertex> mVertices;
385 double mTolerance = 0;
386};
387
396{
397 public:
398
402 QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes );
403 void redo() override;
404
405 private:
406 QList<int> mVerticesToRemoveIndexes;
407};
408
417{
418 public:
419
428 QgsMeshLayerUndoCommandRemoveVerticesFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes, QList<int> *remainingVerticesPointer = nullptr );
429 void redo() override;
430
431 private:
432 QList<int> mVerticesToRemoveIndexes;
433 QList<int> *mRemainingVerticesPointer = nullptr;
434};
435
444{
445 public:
446
449
450 void redo() override;
451 private:
453};
454
463{
464 public:
465
467 QgsMeshLayerUndoCommandRemoveFaces( QgsMeshEditor *meshEditor, const QList<int> &facesToRemoveIndexes );
468
469 void redo() override;
470 private:
471 QList<int> mfacesToRemoveIndexes;
472};
473
482{
483 public:
484
489 QgsMeshLayerUndoCommandChangeZValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<double> &newValues );
490 void redo() override;
491
492 private:
493 QList<int> mVerticesIndexes;
494 QList<double> mNewValues;
495};
496
505{
506 public:
507
512 QgsMeshLayerUndoCommandChangeXYValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
513 void redo() override;
514
515 private:
516 QList<int> mVerticesIndexes;
517 QList<QgsPointXY> mNewValues;
518};
519
528{
529 public:
530
535 QgsMeshLayerUndoCommandChangeCoordinates( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
536 void redo() override;
537
538 private:
539 QList<int> mVerticesIndexes;
540 QList<QgsPoint> mNewCoordinates;
541};
542
551{
552 public:
553
557 QgsMeshLayerUndoCommandFlipEdge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
558 void redo() override;
559
560 private:
561 int mVertexIndex1 = -1;
562 int mVertexIndex2 = -1;
563};
564
573{
574 public:
575
580 QgsMeshLayerUndoCommandMerge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
581 void redo() override;
582
583 private:
584 int mVertexIndex1 = -1;
585 int mVertexIndex2 = -1;
586};
587
596{
597 public:
598
602 QgsMeshLayerUndoCommandSplitFaces( QgsMeshEditor *meshEditor, const QList<int> &faceIndexes );
603 void redo() override;
604
605 private:
606 QList<int> mFaceIndexes;
607};
608
609
617{
618 public:
619
622 void redo() override;
623
624 private:
625 QgsMeshAdvancedEditing *mAdvancedEditing = nullptr;
626};
627
628
629
630
631#endif //SIP_RUN
632
633#endif // QGSMESHEDITOR_H
MeshEditingErrorType
Type of error that can occur during mesh frame editing.
Definition: qgis.h:796
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:100
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.