QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
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
111 bool faceCanBeAdded( const QgsMeshFace &face ) const;
112
121 bool faceCanBeAddedWithNewVertices( const QList<int> &verticesIndex, const QList<QgsMeshVertex> &newVertices ) const; SIP_SKIP
122
127 bool isFaceGeometricallyCompatible( const QgsMeshFace &face ) const;
128
130 QgsMeshEditingError addFaces( const QVector<QgsMeshFace> &faces ); SIP_SKIP
131
133 QgsMeshEditingError addFace( const QVector<int> &vertexIndexes );
134
143 QgsMeshEditingError addFaceWithNewVertices( const QList<int> &vertexIndexes, const QList<QgsMeshVertex> &newVertices ); SIP_SKIP
144
146 QgsMeshEditingError removeFaces( const QList<int> &facesToRemove );
147
149 bool edgeCanBeFlipped( int vertexIndex1, int vertexIndex2 ) const;
150
152 void flipEdge( int vertexIndex1, int vertexIndex2 );
153
157 bool canBeMerged( int vertexIndex1, int vertexIndex2 ) const;
158
160 void merge( int vertexIndex1, int vertexIndex2 );
161
165 bool faceCanBeSplit( int faceIndex ) const;
166
171 int splitFaces( const QList<int> &faceIndexes );
172
181 int addVertices( const QVector<QgsMeshVertex> &vertices, double tolerance ); SIP_SKIP
182
191 int addPointsAsVertices( const QVector<QgsPoint> &point, double tolerance );
192
198 QgsMeshEditingError removeVerticesWithoutFillHoles( const QList<int> &verticesToRemoveIndexes );
199
207 QList<int> removeVerticesFillHoles( const QList<int> &verticesToRemoveIndexes );
208
212 void changeZValues( const QList<int> &verticesIndexes, const QList<double> &newValues );
213
225 bool canBeTransformed( const QList<int> &facesToCheck, const std::function<const QgsMeshVertex( int )> &transformFunction ) const; SIP_SKIP
226
232 void changeXYValues( const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
233
239 void changeCoordinates( const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
240
244 void advancedEdit( QgsMeshAdvancedEditing *editing );
245
247 void stopEditing();
248
250 QgsRectangle extent() const;
251
253 bool isModified() const;
254
262 bool reindex( bool renumbering );
263
264 //----------- access element methods
265
267 QList<int> freeVerticesIndexes() const;
268
270 bool isVertexOnBoundary( int vertexIndex ) const;
271
273 bool isVertexFree( int vertexIndex ) const;
274
282 QgsMeshVertexCirculator vertexCirculator( int vertexIndex ) const; SIP_SKIP
283
285 QgsTopologicalMesh &topologicalMesh(); SIP_SKIP
286
288 QgsTriangularMesh *triangularMesh(); SIP_SKIP
289
291 bool checkConsistency( QgsMeshEditingError &error ) const;
292
297 bool edgeIsClose( QgsPointXY point, double tolerance, int &faceIndex, int &edgePosition );
298
300 int validFacesCount() const;
301
303 int validVerticesCount() const;
304
306 int maximumVerticesPerFace() const;
307
308 signals:
310 void meshEdited();
311
312 private:
313 QgsMesh *mMesh = nullptr;
314 QgsTopologicalMesh mTopologicalMesh;
315 QgsTriangularMesh *mTriangularMesh = nullptr;
316 int mMaximumVerticesPerFace = 0;
317 QgsMeshDatasetGroup *mZValueDatasetGroup = nullptr;
318 int mValidVerticesCount = 0;
319 int mValidFacesCount = 0;
320
321 QVector<QgsMeshFace> prepareFaces( const QVector<QgsMeshFace> &faces, QgsMeshEditingError &error ) const;
322 QList<int> prepareFaceWithNewVertices( const QList<int> &vertices, const QList<QgsMeshVertex> &newVertices, QgsMeshEditingError &error ) const;
323 bool isFaceGeometricallyCompatible( const QList<int> &vertexIndex, const QList<QgsMeshVertex> &vertices ) const;
324
326 QUndoStack *mUndoStack = nullptr;
327
328 struct Edit
329 {
330 QgsTopologicalMesh::Changes topologicalChanges;
331 QgsTriangularMesh::Changes triangularMeshChanges;
332 };
333 void applyEdit( Edit &edit );
334 void reverseEdit( Edit &edit );
335
336 void applyAddVertex( Edit &edit, const QgsMeshVertex &vertex, double tolerance );
337 bool applyRemoveVertexFillHole( Edit &edit, int vertexIndex );
338 void applyRemoveVerticesWithoutFillHole( QgsMeshEditor::Edit &edit, const QList<int> &verticesIndexes );
339 void applyAddFaces( Edit &edit, const QgsTopologicalMesh::TopologicalFaces &faces );
340 void applyRemoveFaces( Edit &edit, const QList<int> &faceToRemoveIndex );
341 void applyChangeZValue( Edit &edit, const QList<int> &verticesIndexes, const QList<double> &newValues );
342 void applyChangeXYValue( Edit &edit, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
343 void applyFlipEdge( Edit &edit, int vertexIndex1, int vertexIndex2 );
344 void applyMerge( Edit &edit, int vertexIndex1, int vertexIndex2 );
345 void applySplit( QgsMeshEditor::Edit &edit, int faceIndex );
346 void applyAdvancedEdit( Edit &edit, QgsMeshAdvancedEditing *editing );
347
348 void applyEditOnTriangularMesh( Edit &edit, const QgsTopologicalMesh::Changes &topologicChanges );
349
350 void updateElementsCount( const QgsTopologicalMesh::Changes &changes, bool apply = true );
351
352 friend class TestQgsMeshEditor;
359 friend class QgsMeshLayerUndoCommandSetZValue;
366
368};
369
370#ifndef SIP_RUN
371
379class QgsMeshLayerUndoCommandMeshEdit : public QUndoCommand
380{
381 public:
382
383 void undo() override;
384 void redo() override;
385
386 protected:
387
390 QPointer<QgsMeshEditor> mMeshEditor;
391 QList<QgsMeshEditor::Edit> mEdits;
392};
393
402{
403 public:
404
406 QgsMeshLayerUndoCommandAddVertices( QgsMeshEditor *meshEditor, const QVector<QgsMeshVertex> &vertices, double tolerance );
407 void redo() override;
408
409 private:
410 QVector<QgsMeshVertex> mVertices;
411 double mTolerance = 0;
412};
413
422{
423 public:
424
428 QgsMeshLayerUndoCommandRemoveVerticesWithoutFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes );
429 void redo() override;
430
431 private:
432 QList<int> mVerticesToRemoveIndexes;
433};
434
443{
444 public:
445
454 QgsMeshLayerUndoCommandRemoveVerticesFillHoles( QgsMeshEditor *meshEditor, const QList<int> &verticesToRemoveIndexes, QList<int> *remainingVerticesPointer = nullptr );
455 void redo() override;
456
457 private:
458 QList<int> mVerticesToRemoveIndexes;
459 QList<int> *mRemainingVerticesPointer = nullptr;
460};
461
470{
471 public:
472
475
476 void redo() override;
477 private:
479};
480
489{
490 public:
491
493 QgsMeshLayerUndoCommandRemoveFaces( QgsMeshEditor *meshEditor, const QList<int> &facesToRemoveIndexes );
494
495 void redo() override;
496 private:
497 QList<int> mfacesToRemoveIndexes;
498};
499
508{
509 public:
510
515 QgsMeshLayerUndoCommandChangeZValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<double> &newValues );
516 void redo() override;
517
518 private:
519 QList<int> mVerticesIndexes;
520 QList<double> mNewValues;
521};
522
531{
532 public:
533
538 QgsMeshLayerUndoCommandChangeXYValue( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPointXY> &newValues );
539 void redo() override;
540
541 private:
542 QList<int> mVerticesIndexes;
543 QList<QgsPointXY> mNewValues;
544};
545
554{
555 public:
556
561 QgsMeshLayerUndoCommandChangeCoordinates( QgsMeshEditor *meshEditor, const QList<int> &verticesIndexes, const QList<QgsPoint> &newCoordinates );
562 void redo() override;
563
564 private:
565 QList<int> mVerticesIndexes;
566 QList<QgsPoint> mNewCoordinates;
567};
568
577{
578 public:
579
583 QgsMeshLayerUndoCommandFlipEdge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
584 void redo() override;
585
586 private:
587 int mVertexIndex1 = -1;
588 int mVertexIndex2 = -1;
589};
590
599{
600 public:
601
606 QgsMeshLayerUndoCommandMerge( QgsMeshEditor *meshEditor, int vertexIndex1, int vertexIndex2 );
607 void redo() override;
608
609 private:
610 int mVertexIndex1 = -1;
611 int mVertexIndex2 = -1;
612};
613
622{
623 public:
624
628 QgsMeshLayerUndoCommandSplitFaces( QgsMeshEditor *meshEditor, const QList<int> &faceIndexes );
629 void redo() override;
630
631 private:
632 QList<int> mFaceIndexes;
633};
634
635
643{
644 public:
645
648 void redo() override;
649
650 private:
651 QgsMeshAdvancedEditing *mAdvancedEditing = nullptr;
652};
653
654
655
656
657#endif //SIP_RUN
658
659#endif // QGSMESHEDITOR_H
MeshEditingErrorType
Type of error that can occur during mesh frame editing.
Definition qgis.h:1551
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.
Qgis::MeshEditingErrorType errorType
bool operator==(const QgsMeshEditingError &other) const
bool operator!=(const QgsMeshEditingError &other) const
Class that makes edit operation on a mesh.
Class for undo/redo command for adding faces in mesh.
Class for undo/redo command for adding vertices in mesh.
Class for undo/redo command for applying advanced editing.
Class for undo/redo command for changing coordinate (X,Y,Z) values of vertices.
Class for undo/redo command for changing (X,Y) value of vertices.
Class for undo/redo command for changing Z value of vertices.
Class for undo/redo command for flipping edge.
Class for undo/redo command for merging face.
Base class for undo/redo command for mesh editing.
QList< QgsMeshEditor::Edit > mEdits
QPointer< QgsMeshEditor > mMeshEditor
Class for undo/redo command for removing faces in mesh.
Class for undo/redo command for removing vertices in mesh filling holes created by removed faces.
Class for undo/redo command for removing vertices in mesh without filling holes created by removed fa...
Class for undo/redo command for splitting faces.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Convenient class that turn around a vertex and provide information about faces and vertices.
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A rectangle specified with double values.
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.