Skip to content

Commit

Permalink
change approach for new face with mesh editing
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and github-actions[bot] committed Jan 21, 2023
1 parent 3787618 commit 2dbb4f2
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 69 deletions.
76 changes: 62 additions & 14 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Expand Up @@ -568,7 +568,8 @@ void QgsMapToolEditMeshFrame::deactivate()
deleteZValueWidget();
qDeleteAll( mFreeVertexMarker );
mFreeVertexMarker.clear();

mNewFaceCandidate.clear();
mNewVerticesForNewFaceCandidate.clear();
}

void QgsMapToolEditMeshFrame::clearAll()
Expand Down Expand Up @@ -818,7 +819,7 @@ void QgsMapToolEditMeshFrame::cadCanvasMoveEvent( QgsMapMouseEvent *e )
case AddingNewFace:
mNewFaceBand->movePoint( mapPoint );
highLight( mapPoint );
if ( testNewVertexInFaceCanditate( mCurrentVertexIndex ) )
if ( testNewVertexInFaceCanditate( true, mCurrentVertexIndex, mapPoint ) )
mNewFaceBand->setColor( mValidFaceColor );
else
mNewFaceBand->setColor( mInvalidFaceColor );
Expand Down Expand Up @@ -946,26 +947,39 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
case AddingNewFace:
if ( e->button() == Qt::LeftButton ) //eventually add a vertex to the face
{
if ( mDoubleClicks )
{
addVertex( mFirstClickPoint, e->mapPointMatch() );
highlightCloseVertex( mFirstClickPoint );
}

if ( mCurrentVertexIndex != -1 )
{
addVertexToFaceCanditate( mCurrentVertexIndex );
const QgsPointXY currentPoint = mapVertexXY( mCurrentVertexIndex );
cadDockWidget()->setPoints( QList<QgsPointXY>() << currentPoint << currentPoint );
}
else
{
bool acceptPoint = true;
if ( ! mNewFaceCandidate.isEmpty() &&
mNewFaceCandidate.last() == -1 &&
!mNewVerticesForNewFaceCandidate.isEmpty() ) //avoid dupplicate new vertex
{
acceptPoint = mapPoint.distance( mNewVerticesForNewFaceCandidate.last() ) > tolerance;
}

if ( acceptPoint )
{
addVertexToFaceCanditate( mapPoint );
const QgsPointXY currentPoint( mapPoint );
cadDockWidget()->setPoints( QList<QgsPointXY>() << currentPoint << currentPoint );
}
}
}
else if ( e->button() == Qt::RightButton ) //if possible validate and add the face to the mesh
{
if ( testNewVertexInFaceCanditate( -1 ) )
if ( testNewVertexInFaceCanditate( false, -1, QgsPointXY() ) )
{
mCurrentEditor->addFace( mNewFaceCandidate.toVector() );
mCurrentEditor->addFaceWithNewVertices( mNewFaceCandidate, mNewVerticesForNewFaceCandidate );
mNewFaceBand->reset( QgsWkbTypes::PolygonGeometry );
mNewFaceCandidate.clear();
mNewVerticesForNewFaceCandidate.clear();
mCurrentState = Digitizing;
}
}
Expand Down Expand Up @@ -1207,16 +1221,22 @@ void QgsMapToolEditMeshFrame::keyPressEvent( QKeyEvent *e )
{
mNewFaceBand->removePoint( -2, true );
if ( !mNewFaceCandidate.isEmpty() )
{
if ( mNewFaceCandidate.last() == -1 && !mNewVerticesForNewFaceCandidate.isEmpty() )
mNewVerticesForNewFaceCandidate.removeLast();
mNewFaceCandidate.removeLast();
}
if ( mNewFaceCandidate.isEmpty() )
mCurrentState = Digitizing;

consumned = true;
}

if ( e->key() == Qt::Key_Escape )
{
mNewFaceBand->reset( QgsWkbTypes::PolygonGeometry );
mNewFaceCandidate.clear();
mNewVerticesForNewFaceCandidate.clear();
mCurrentState = Digitizing;
consumned = true;
}
Expand Down Expand Up @@ -1407,7 +1427,11 @@ void QgsMapToolEditMeshFrame::setCurrentLayer( QgsMapLayer *layer )
QgsMeshLayer *meshLayer = qobject_cast<QgsMeshLayer *>( layer );

if ( mCurrentLayer == meshLayer && mCurrentEditor != nullptr )
{
activate();
updateFreeVertices();
return;
}

if ( mCurrentEditor )
deactivate();
Expand Down Expand Up @@ -1541,12 +1565,35 @@ void QgsMapToolEditMeshFrame::addVertexToFaceCanditate( int vertexIndex )
mNewFaceCandidate.append( vertexIndex );
}

bool QgsMapToolEditMeshFrame::testNewVertexInFaceCanditate( int vertexIndex )
void QgsMapToolEditMeshFrame::addVertexToFaceCanditate( const QgsPointXY &vertexPosition )
{
mNewFaceBand->movePoint( vertexPosition );
mNewFaceBand->addPoint( vertexPosition );
QgsMeshVertex vert = QgsMeshVertex( vertexPosition.x(), vertexPosition.y(), currentZValue() );
mNewVerticesForNewFaceCandidate.append( vert );
mNewFaceCandidate.append( -1 );
}

bool QgsMapToolEditMeshFrame::testNewVertexInFaceCanditate( bool testLast, int vertexIndex, const QgsPointXY &mapPoint ) const
{
QgsMeshFace face = mNewFaceCandidate.toVector();
if ( vertexIndex != -1 && !face.empty() && vertexIndex != mNewFaceCandidate.last() )
face.append( vertexIndex );
return mCurrentEditor->faceCanBeAdded( face );
QList<int> faceToTest = mNewFaceCandidate;
QList<QgsMeshVertex> newVertices = mNewVerticesForNewFaceCandidate;

if ( testLast )
{
if ( vertexIndex != -1 &&
!mNewFaceCandidate.empty() &&
vertexIndex != mNewFaceCandidate.last() &&
vertexIndex != mNewFaceCandidate.first() )
faceToTest.append( vertexIndex );
else if ( vertexIndex == -1 )
{
faceToTest.append( -1 );
newVertices.append( QgsMeshVertex( mapPoint ) );
}
}

return mCurrentEditor->faceCanBeAddedWithNewVertices( faceToTest, newVertices );
}


Expand Down Expand Up @@ -2578,6 +2625,7 @@ void QgsMapToolEditMeshFrame::clearCanvasHelpers()
mFaceRubberBand->reset();
mFaceVerticesBand->reset();
mVertexBand->reset();
mNewFaceBand->reset();

mSnapIndicator->setMatch( QgsPointLocator::Match() );
mSelectFaceMarker->setVisible( false );
Expand Down
6 changes: 4 additions & 2 deletions src/app/mesh/qgsmaptooleditmeshframe.h
Expand Up @@ -219,8 +219,9 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing

QgsPointXY newFaceMarkerPosition( int vertexIndex );

void addVertexToFaceCanditate( int vertexIndex );
bool testNewVertexInFaceCanditate( int vertexIndex );
void addVertexToFaceCanditate( int vertexIndex ); //for existing vertex
void addVertexToFaceCanditate( const QgsPointXY &vertexPosition );
bool testNewVertexInFaceCanditate( bool testLast, int vertexIndex, const QgsPointXY &mapPoint ) const;

// selection methods
void select( const QgsPointXY &mapPoint, Qt::KeyboardModifiers modifiers, double tolerance );
Expand Down Expand Up @@ -265,6 +266,7 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
Edge mCurrentEdge = {-1, -1};
int mCurrentVertexIndex = -1;
QList<int> mNewFaceCandidate;
QList<QgsMeshVertex> mNewVerticesForNewFaceCandidate;
bool mDoubleClicks = false;
QgsPointXY mFirstClickPoint; //the first click point when double clicks, we need it when the point is constraint by the cad tool, second click could not be constraint
double mFirstClickZValue;
Expand Down

0 comments on commit 2dbb4f2

Please sign in to comment.