Skip to content
Permalink
Browse files
transform only one vertex (#44981)
[mesh] [feature] change coordinates of a single vertex
  • Loading branch information
vcloarec committed Sep 9, 2021
1 parent 45e07dd commit c917e02aca38b29693402f250fea8355c9c51d2a
@@ -927,6 +927,7 @@
<file>themes/default/mActionMeshSelectExpression.svg</file>
<file>themes/default/mActionNewMeshLayer.svg</file>
<file>themes/default/mActionMeshTransformByExpression.svg</file>
<file>themes/default/mIconVertexCoordinates.svg</file>
<file>themes/default/mIconGeometryCollectionLayer.svg</file>
<file>themes/default/mIconGps.svg</file>
<file>themes/default/mActionNewGpx.svg</file>
@@ -0,0 +1 @@
<svg enable-background="new 4 4 24 24" height="24" viewBox="4 4 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><ellipse cx="16.057125" cy="11.025824" fill="none" rx="4.00118" ry="4.087982" stroke="#00f" stroke-linecap="round" stroke-linejoin="bevel" stroke-width="2"/><text style="font-weight:700;font-size:8.62;font-family:DejaVu Sans Mono;letter-spacing:0;word-spacing:0;fill:#555;stroke:#555;stroke-width:.395" x="8.27794" y="24.400002"><tspan stroke-width=".395" x="8.27794" y="24.400002">XYZ</tspan></text></svg>
@@ -1297,21 +1297,19 @@ void QgsMapToolEditMeshFrame::triggerTransformCoordinatesDockWidget( bool checke
{
if ( !checked && mTransformDockWidget )
{
mTransformDockWidget->deleteLater();
mTransformDockWidget = nullptr;
mTransformDockWidget->close();
return;
}
else if ( mTransformDockWidget )
{
mTransformDockWidget->show();
return;
}

onEditingStarted();

mTransformDockWidget = new QgsMeshTransformCoordinatesDockWidget( QgisApp::instance() );
mTransformDockWidget->setWindowTitle( tr( "Transform Mesh Vertices" ) );
mTransformDockWidget->setObjectName( QStringLiteral( "TransformMeshVerticesDockWidget" ) );
mTransformDockWidget->setAttribute( Qt::WA_DeleteOnClose );
mTransformDockWidget->setInput( mCurrentLayer, mSelectedVertices.keys() );

if ( !QgisApp::instance()->restoreDockWidget( mTransformDockWidget ) )
@@ -1420,9 +1418,8 @@ void QgsMapToolEditMeshFrame::triggerTransformCoordinatesDockWidget( bool checke
prepareSelection();
} );

connect( mTransformDockWidget, &QgsMeshTransformCoordinatesDockWidget::destroyed, this, [this]
connect( mTransformDockWidget, &QgsDockWidget::closed, this, [this]
{
mTransformDockWidget = nullptr;
mActionTransformCoordinates->setChecked( false );
if ( !mIsInitialized )
return;
@@ -24,6 +24,8 @@
#include "qgsproject.h"
#include "qgsguiutils.h"
#include "qgshelp.h"
#include "qgscoordinateutils.h"
#include "qgsapplication.h"

QgsMeshTransformCoordinatesDockWidget::QgsMeshTransformCoordinatesDockWidget( QWidget *parent ):
QgsDockWidget( parent )
@@ -33,7 +35,6 @@ QgsMeshTransformCoordinatesDockWidget::QgsMeshTransformCoordinatesDockWidget( QW
QgsGui::enableAutoGeometryRestore( this );

setWindowTitle( tr( "Transform Mesh Vertices by Expression" ) );

mExpressionLineEdits << mExpressionEditX << mExpressionEditY << mExpressionEditZ;
mCheckBoxes << mCheckBoxX << mCheckBoxY << mCheckBoxZ;

@@ -51,6 +52,7 @@ QgsMeshTransformCoordinatesDockWidget::QgsMeshTransformCoordinatesDockWidget( QW

connect( mButtonPreview, &QToolButton::clicked, this, &QgsMeshTransformCoordinatesDockWidget::calculate );
connect( mButtonApply, &QPushButton::clicked, this, &QgsMeshTransformCoordinatesDockWidget::apply );
connect( mButtonImport, &QToolButton::toggled, this, &QgsMeshTransformCoordinatesDockWidget::onImportVertexClicked );
}

QgsExpressionContext QgsMeshTransformCoordinatesDockWidget::createExpressionContext() const
@@ -99,6 +101,7 @@ void QgsMeshTransformCoordinatesDockWidget::setInput( QgsMeshLayer *layer, const
arg( QString::number( mInputVertices.count() ), mInputLayer->name() ) );
}
}
importVertexCoordinates();
updateButton();
emit calculationUpdated();
}
@@ -157,3 +160,40 @@ void QgsMeshTransformCoordinatesDockWidget::apply()
emit applied();
}

void QgsMeshTransformCoordinatesDockWidget::onImportVertexClicked( bool checked )
{
if ( checked )
importVertexCoordinates();
else
{
mExpressionEditX->setExpression( QString() );
mExpressionEditY->setExpression( QString() );
mExpressionEditZ->setExpression( QString() );
}
}


QString QgsMeshTransformCoordinatesDockWidget::displayCoordinateText( const QgsCoordinateReferenceSystem &crs, double value )
{
return QString::number( value, 'f', QgsCoordinateUtils::calculateCoordinatePrecisionForCrs( crs, QgsProject::instance() ) );
}

void QgsMeshTransformCoordinatesDockWidget::importVertexCoordinates()
{
if ( mButtonImport->isChecked() && mInputLayer )
{
if ( mInputVertices.count() == 1 )
{
mExpressionEditX->setExpression( displayCoordinateText( mInputLayer->crs(), mInputLayer->nativeMesh()->vertex( mInputVertices.first() ).x() ) );
mExpressionEditY->setExpression( displayCoordinateText( mInputLayer->crs(), mInputLayer->nativeMesh()->vertex( mInputVertices.first() ).y() ) );
mExpressionEditZ->setExpression( displayCoordinateText( mInputLayer->crs(), mInputLayer->nativeMesh()->vertex( mInputVertices.first() ).z() ) );
}
else
{
mExpressionEditX->setExpression( QString() );
mExpressionEditY->setExpression( QString() );
mExpressionEditZ->setExpression( QString() );
}
}
}

@@ -67,6 +67,7 @@ class APP_EXPORT QgsMeshTransformCoordinatesDockWidget: public QgsDockWidget, pu
void calculate();
void updateButton();
void apply();
void onImportVertexClicked( bool checked );

private:
QgsMeshTransformVerticesByExpression mTransformVertices;
@@ -77,6 +78,9 @@ class APP_EXPORT QgsMeshTransformCoordinatesDockWidget: public QgsDockWidget, pu
QList<QgsExpressionLineEdit *> mExpressionLineEdits;
QList<QCheckBox *> mCheckBoxes;

QString displayCoordinateText( const QgsCoordinateReferenceSystem &crs, double value );
void importVertexCoordinates();

};

#endif // QGSMESHTRANSFORMCOORDINATESDOCKWIDGET_H
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>256</width>
<height>174</height>
<width>297</width>
<height>182</height>
</rect>
</property>
<property name="floating">
@@ -18,37 +18,24 @@
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<item row="4" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionEditZ" native="true"/>
</item>
<item row="2" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionEditY" native="true"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mCheckBoxY">
<property name="text">
<string>Y coordinate</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mCheckBoxX">
<property name="text">
<string>X coordinate</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionEditX" native="true"/>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mCheckBoxZ">
<widget class="QCheckBox" name="mCheckBoxY">
<property name="text">
<string>Z value</string>
<string>Y coordinate</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
@@ -69,24 +56,86 @@
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="mLabelInformation">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="2" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionEditX" native="true"/>
</item>
<item row="3" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionEditY" native="true"/>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="mCheckBoxZ">
<property name="text">
<string>TextLabel</string>
<string>Z value</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0,0">
<property name="spacing">
<number>6</number>
</property>
<property name="wordWrap">
<bool>true</bool>
<property name="topMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QLabel" name="mLabelInformation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="mButtonImport">
<property name="toolTip">
<string>Import coordinates of the selected vertex</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconVertexCoordinates.svg</normaloff>:/images/themes/default/mIconVertexCoordinates.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@@ -105,6 +154,16 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<tabstops>
<tabstop>mCheckBoxX</tabstop>
<tabstop>mCheckBoxY</tabstop>
<tabstop>mCheckBoxZ</tabstop>
<tabstop>mButtonPreview</tabstop>
<tabstop>mButtonApply</tabstop>
<tabstop>mButtonImport</tabstop>
</tabstops>
<resources>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit c917e02

Please sign in to comment.