Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh point add elevation #58877

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 86 additions & 4 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "qgsmaptooleditmeshframe.h"

#include <QMessageBox>
#include <QVBoxLayout>
#include <QPushButton>
#include <QCheckBox>

#include "qgis.h"
#include "qgisapp.h"
Expand Down Expand Up @@ -45,7 +48,9 @@
#include "qgsmeshselectbyexpressiondialog.h"
#include "qgsmaptoolidentify.h"
#include "qgsidentifymenu.h"

#include "qgsprojectelevationproperties.h"
#include "qgscoordinatetransform.h"
#include "qgsterrainprovider.h"

//
// QgsZValueWidget
Expand All @@ -54,9 +59,12 @@

QgsZValueWidget::QgsZValueWidget( const QString &label, QWidget *parent ): QWidget( parent )
{
QHBoxLayout *layout = new QHBoxLayout( this );
QVBoxLayout *mainLayout = new QVBoxLayout( this );
mainLayout->setContentsMargins( 0, 0, 0, 0 );
setLayout( mainLayout );

QHBoxLayout *layout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
setLayout( layout );

if ( !label.isEmpty() )
{
Expand All @@ -76,6 +84,27 @@ QgsZValueWidget::QgsZValueWidget( const QString &label, QWidget *parent ): QWidg
mZValueSpinBox->clear();

mZValueSpinBox->setFocusPolicy( Qt::NoFocus );

mGetZValuesButton = new QPushButton( this );
mGetZValuesButton->setText( "Get Z value from project terrain" );

mGetZValuesFromProjectElevationByDefaultCheckBox = new QCheckBox( "Set Z value from project terrain for new points", this );
JanCaha marked this conversation as resolved.
Show resolved Hide resolved

mainLayout->addLayout( layout );
mainLayout->addWidget( mGetZValuesButton );
mainLayout->addWidget( mGetZValuesFromProjectElevationByDefaultCheckBox );

connect( mGetZValuesButton, &QPushButton::pressed, this, &QgsZValueWidget::getZValuesFromProjectElevation_pressed );
JanCaha marked this conversation as resolved.
Show resolved Hide resolved
}

void QgsZValueWidget::getZValuesFromProjectElevation_pressed()
{
emit applyZValuesFromProjectElevation();
}

bool QgsZValueWidget::getZFromProjectElevation()
{
return mGetZValuesFromProjectElevationByDefaultCheckBox->isChecked();
}

double QgsZValueWidget::zValue() const
Expand Down Expand Up @@ -893,6 +922,10 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
addVertex( mFirstClickPoint, e->mapPointMatch() );
mCadDockWidget->setPoints( QList<QgsPointXY>() << mFirstClickPoint << mFirstClickPoint );

// after addition select the vertex for easier editing of Z value
mCurrentVertexIndex = closeVertex( mapPoint );
select( mapPoint, e->modifiers(), tolerance );
}
else if ( mNewFaceMarker->isVisible() &&
mapPoint.distance( mNewFaceMarker->center() ) < tolerance
Expand Down Expand Up @@ -2047,6 +2080,40 @@ void QgsMapToolEditMeshFrame::selectContainedByGeometry( const QgsGeometry &geom
setSelectedVertices( selectedVertices.values(), behavior );
}

void QgsMapToolEditMeshFrame::applyZValueFromProjectTerrainOnSelectedVertices()
{
if ( !mZValueWidget )
return;

if ( mSelectedVertices.isEmpty() )
return;

const QgsAbstractTerrainProvider *terrainProvider = QgsProject::instance()->elevationProperties()->terrainProvider();
const QgsCoordinateTransform transformation = QgsCoordinateTransform( mCurrentLayer->crs(), terrainProvider->crs(), QgsProject::instance() );

QList<double> zValues;
zValues.reserve( mSelectedVertices.count() );

for ( QMap<int, SelectedVertexData>::iterator it = mSelectedVertices.begin(); it != mSelectedVertices.end(); ++it )
{
const QgsPoint vertex = mapVertex( it.key() );
QgsPointXY point;

try
{
point = transformation.transform( vertex.x(), vertex.y() );
}
catch ( const QgsCsException & )
{
point = QgsPointXY( vertex.x(), vertex.y() );
JanCaha marked this conversation as resolved.
Show resolved Hide resolved
}

zValues.append( terrainProvider->heightAt( point.x(), point.y() ) );
}

mCurrentEditor->changeZValues( mSelectedVertices.keys(), zValues );
}

void QgsMapToolEditMeshFrame::applyZValueOnSelectedVertices()
{
if ( !mZValueWidget )
Expand Down Expand Up @@ -2631,6 +2698,8 @@ void QgsMapToolEditMeshFrame::createZValueWidget()
mZValueWidget->setDefaultValue( defaultZValue() );
mZValueWidget->setZValue( mUserZValue );
QgisApp::instance()->addUserInputWidget( mZValueWidget );

connect( mZValueWidget, &QgsZValueWidget::applyZValuesFromProjectElevation, this, &QgsMapToolEditMeshFrame::applyZValueFromProjectTerrainOnSelectedVertices );
}

void QgsMapToolEditMeshFrame::deleteZValueWidget()
Expand Down Expand Up @@ -2717,7 +2786,20 @@ void QgsMapToolEditMeshFrame::addVertex(
zValue = QgsMeshLayerUtils::interpolateFromVerticesData( v1, v2, v3, v1.z(), v2.z(), v3.z(), mapPoint );
}
else
zValue = currentZValue();
{
if ( mZValueWidget->getZFromProjectElevation() )
{
const QgsAbstractTerrainProvider *terrainProvider = QgsProject::instance()->elevationProperties()->terrainProvider();
const QgsCoordinateTransform transformation = QgsCoordinateTransform( mCurrentLayer->crs(), terrainProvider->crs(), QgsProject::instance() );
const QgsPointXY point = transformation.transform( effectivePoint.x(), effectivePoint.y() );

zValue = terrainProvider->heightAt( point.x(), point.y() );
}
else
{
zValue = currentZValue();
}
}
JanCaha marked this conversation as resolved.
Show resolved Hide resolved

const QVector<QgsMeshVertex> points( 1, QgsMeshVertex( effectivePoint.x(), effectivePoint.y(), zValue ) );
if ( mCurrentEditor )
Expand Down
13 changes: 13 additions & 0 deletions src/app/mesh/qgsmaptooleditmeshframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class QgsSnapIndicator;
class QgsMeshTransformCoordinatesDockWidget;
class QComboBox;
class QCheckBox;
class QPushButton;
class QCheckBox;
class QgsUnitSelectionWidget;
class QgsMapToolSelectionHandler;

Expand All @@ -58,6 +60,9 @@ class APP_EXPORT QgsZValueWidget : public QWidget
//! Sets the current value \a z of the widget
void setZValue( double z );

//! Should \a z value be extract from project elevation setting
bool getZFromProjectElevation();
JanCaha marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets the current value of the widget and set it as the default one,
* that is the value that is retrieve if the z value spin box is cleared
Expand All @@ -66,8 +71,15 @@ class APP_EXPORT QgsZValueWidget : public QWidget

QWidget *keyboardEntryWidget() const;

signals:
void applyZValuesFromProjectElevation();
JanCaha marked this conversation as resolved.
Show resolved Hide resolved

private:
void getZValuesFromProjectElevation_pressed();

QgsDoubleSpinBox *mZValueSpinBox = nullptr;
QPushButton *mGetZValuesButton = nullptr;
QCheckBox *mGetZValuesFromProjectElevationByDefaultCheckBox = nullptr;
};

class QgsMeshEditForceByLineAction : public QWidgetAction
Expand Down Expand Up @@ -235,6 +247,7 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
void selectTouchedByGeometry( const QgsGeometry &geometry, Qgis::SelectBehavior behavior );
void selectContainedByGeometry( const QgsGeometry &geometry, Qgis::SelectBehavior behavior );
void applyZValueOnSelectedVertices();
void applyZValueFromProjectTerrainOnSelectedVertices();
void prepareSelection();
void updateSelectecVerticesMarker();
void moveSelection( const QgsPointXY &destinationPoint );
Expand Down