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

[3D] Point cloud editing line tool #60812

Merged
merged 5 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@
<file>themes/default/mActionScaleFeature.svg</file>
<file>themes/default/mActionScriptOpen.svg</file>
<file>themes/default/mActionSelect.svg</file>
<file>themes/default/mActionSelectAboveLine.svg</file>
<file>themes/default/mActionSelectBelowLine.svg</file>
<file>themes/default/mActionSelectAll.svg</file>
<file>themes/default/mActionSelectedToTop.svg</file>
<file>themes/default/mActionSelectFreehand.svg</file>
Expand Down
59 changes: 59 additions & 0 deletions images/themes/default/mActionSelectAboveLine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions images/themes/default/mActionSelectBelowLine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )
editingToolsButton->setPopupMode( QToolButton::ToolButtonPopupMode::InstantPopup );
QAction *actionPointCloudChangeAttributeTool = mEditingToolsMenu->addAction( QIcon( QgsApplication::iconPath( QStringLiteral( "mActionSelectPolygon.svg" ) ) ), tr( "Select by Polygon" ), this, &Qgs3DMapCanvasWidget::changePointCloudAttributeByPolygon );
QAction *actionPaintbrush = mEditingToolsMenu->addAction( QIcon( QgsApplication::iconPath( QStringLiteral( "propertyicons/rendering.svg" ) ) ), tr( "Select by Paintbrush" ), this, &Qgs3DMapCanvasWidget::changePointCloudAttributeByPaintbrush );
QAction *actionAboveLineTool = mEditingToolsMenu->addAction( QIcon( QgsApplication::iconPath( QStringLiteral( "mActionSelectAboveLine.svg" ) ) ), tr( "Select Above Line" ), this, &Qgs3DMapCanvasWidget::changePointCloudAttributeByAboveLine );
QAction *actionBelowLineTool = mEditingToolsMenu->addAction( QIcon( QgsApplication::iconPath( QStringLiteral( "mActionSelectBelowLine.svg" ) ) ), tr( "Select Below Line" ), this, &Qgs3DMapCanvasWidget::changePointCloudAttributeByBelowLine );

mEditingToolBar->addWidget( mPointCloudEditingToolbar );
mPointCloudEditingToolbar->addWidget( new QLabel( tr( "Attribute" ) ) );
Expand Down Expand Up @@ -165,6 +167,8 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )
actionGroup->addAction( actionMeasurementTool );
actionGroup->addAction( actionPaintbrush );
actionGroup->addAction( actionPointCloudChangeAttributeTool );
actionGroup->addAction( actionAboveLineTool );
actionGroup->addAction( actionBelowLineTool );
actionGroup->setExclusive( true );

mActionAnim = toolBar->addAction( QIcon( QgsApplication::iconPath( "mTaskRunning.svg" ) ), tr( "Animations" ), this, &Qgs3DMapCanvasWidget::toggleAnimations );
Expand Down Expand Up @@ -491,7 +495,33 @@ void Qgs3DMapCanvasWidget::changePointCloudAttributeByPolygon()
return;

mCanvas->setMapTool( nullptr );
mMapToolChangeAttribute.reset( new Qgs3DMapToolPointCloudChangeAttributePolygon( mCanvas ) );
mMapToolChangeAttribute.reset( new Qgs3DMapToolPointCloudChangeAttributePolygon( mCanvas, Qgs3DMapToolPointCloudChangeAttributePolygon::Polygon ) );
onPointCloudChangeAttributeSettingsChanged();
mCanvas->setMapTool( mMapToolChangeAttribute.get() );
mEditingToolsAction->setIcon( action->icon() );
}

void Qgs3DMapCanvasWidget::changePointCloudAttributeByAboveLine()
{
const QAction *action = qobject_cast<QAction *>( sender() );
if ( !action )
return;

mCanvas->setMapTool( nullptr );
mMapToolChangeAttribute.reset( new Qgs3DMapToolPointCloudChangeAttributePolygon( mCanvas, Qgs3DMapToolPointCloudChangeAttributePolygon::AboveLine ) );
onPointCloudChangeAttributeSettingsChanged();
mCanvas->setMapTool( mMapToolChangeAttribute.get() );
mEditingToolsAction->setIcon( action->icon() );
}

void Qgs3DMapCanvasWidget::changePointCloudAttributeByBelowLine()
{
const QAction *action = qobject_cast<QAction *>( sender() );
if ( !action )
return;

mCanvas->setMapTool( nullptr );
mMapToolChangeAttribute.reset( new Qgs3DMapToolPointCloudChangeAttributePolygon( mCanvas, Qgs3DMapToolPointCloudChangeAttributePolygon::BelowLine ) );
onPointCloudChangeAttributeSettingsChanged();
mCanvas->setMapTool( mMapToolChangeAttribute.get() );
mEditingToolsAction->setIcon( action->icon() );
Expand Down
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dmapcanvaswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget
void measureLine();
void changePointCloudAttributeByPaintbrush();
void changePointCloudAttributeByPolygon();
void changePointCloudAttributeByAboveLine();
void changePointCloudAttributeByBelowLine();
void exportScene();
void toggleNavigationWidget( bool visibility );
void toggleFpsCounter( bool visibility );
Expand Down
111 changes: 81 additions & 30 deletions src/app/3d/qgs3dmaptoolpointcloudchangeattributepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,106 @@
#include <QApplication>
#include <QMouseEvent>


Qgs3DMapToolPointCloudChangeAttributePolygon::Qgs3DMapToolPointCloudChangeAttributePolygon( Qgs3DMapCanvas *canvas )
: Qgs3DMapToolPointCloudChangeAttribute( canvas )
Qgs3DMapToolPointCloudChangeAttributePolygon::Qgs3DMapToolPointCloudChangeAttributePolygon( Qgs3DMapCanvas *canvas, const ToolType type = Polygon )
: Qgs3DMapToolPointCloudChangeAttribute( canvas ), mToolType( type )
{
}

Qgs3DMapToolPointCloudChangeAttributePolygon::~Qgs3DMapToolPointCloudChangeAttributePolygon() = default;

void Qgs3DMapToolPointCloudChangeAttributePolygon::mousePressEvent( QMouseEvent *event )
{
if ( !mIsMoving )
{
mClickPoint = event->pos();
}
mClickPoint = event->pos();
}

void Qgs3DMapToolPointCloudChangeAttributePolygon::mouseMoveEvent( QMouseEvent *event )
{
if ( !mIsMoving )
if ( mToolType != Polygon && mScreenPoints.size() == 2 )
return;
const QgsPoint movedPoint = Qgs3DUtils::screenPointToMapCoordinates( event->pos(), mCanvas->size(), mCanvas->cameraController(), mCanvas->mapSettings() );
if ( mToolType == Polygon )
{
const QgsPoint movedPoint = Qgs3DUtils::screenPointToMapCoordinates( event->pos(), mCanvas->size(), mCanvas->cameraController(), mCanvas->mapSettings() );
mPolygonRubberBand->moveLastPoint( movedPoint );
}
else
{
mLineRubberBand->moveLastPoint( movedPoint );
if ( !mPolygonRubberBand->isEmpty() )
{
mPolygonRubberBand->removeLastPoint();
mPolygonRubberBand->moveLastPoint( Qgs3DUtils::screenPointToMapCoordinates( QPoint( event->x(), mToolType == AboveLine ? 0 : mCanvas->height() ), mCanvas->size(), mCanvas->cameraController(), mCanvas->mapSettings() ) );
mPolygonRubberBand->addPoint( movedPoint );
}
}
}

void Qgs3DMapToolPointCloudChangeAttributePolygon::keyPressEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete )
{
if ( mScreenPoints.isEmpty() )
{
return;
}
else if ( mScreenPoints.size() == 1 )
if ( mScreenPoints.size() == 1 )
{
//removing first point, so restart everything
restart();
}
else
else if ( mScreenPoints.size() > 1 )
{
mScreenPoints.removeLast();
mPolygonRubberBand->removeLastPoint();
if ( mToolType != Polygon )
{
mPolygonRubberBand->removeLastPoint();
mLineRubberBand->removeLastPoint();
}
}
}
else if ( event->key() == Qt::Key_Escape )
{
restart();
}
else if ( event->key() == Qt::Key_Space )
{
const bool newState = !mCanvas->cameraController()->hasInputHandlersEnabled();
mCanvas->cameraController()->setInputHandlersEnabled( newState );
mIsMoving = newState;
}
}

void Qgs3DMapToolPointCloudChangeAttributePolygon::mouseReleaseEvent( QMouseEvent *event )
{
if ( ( event->pos() - mClickPoint ).manhattanLength() > QApplication::startDragDistance() || mIsMoving )
if ( ( event->pos() - mClickPoint ).manhattanLength() > QApplication::startDragDistance() )
return;

const QgsPoint newPoint = Qgs3DUtils::screenPointToMapCoordinates( event->pos(), mCanvas->size(), mCanvas->cameraController(), mCanvas->mapSettings() );

if ( event->button() == Qt::LeftButton )
{
if ( mPolygonRubberBand->isEmpty() )
if ( mToolType != Polygon && mScreenPoints.size() > 2 )
return;

mScreenPoints.append( QgsPointXY( event->x(), event->y() ) );

if ( mToolType == Polygon )
{
if ( mPolygonRubberBand->isEmpty() )
{
mPolygonRubberBand->addPoint( newPoint );
mCanvas->cameraController()->setInputHandlersEnabled( false );
}
mPolygonRubberBand->addPoint( newPoint );
mCanvas->cameraController()->setInputHandlersEnabled( false );
}
mPolygonRubberBand->addPoint( newPoint );
mScreenPoints.append( QgsPointXY( event->x(), event->y() ) );
else
{
const QgsPoint screenEdgePoint = Qgs3DUtils::screenPointToMapCoordinates( QPoint( event->x(), mToolType == AboveLine ? 0 : mCanvas->height() ), mCanvas->size(), mCanvas->cameraController(), mCanvas->mapSettings() );
if ( mLineRubberBand->isEmpty() )
{
mLineRubberBand->addPoint( newPoint );

mPolygonRubberBand->addPoint( newPoint );
mPolygonRubberBand->addPoint( screenEdgePoint );
mCanvas->cameraController()->setInputHandlersEnabled( false );
}
mLineRubberBand->addPoint( newPoint );
if ( mScreenPoints.size() < 2 )
{
mPolygonRubberBand->addPoint( screenEdgePoint );
mPolygonRubberBand->addPoint( newPoint );
}
}
}
else if ( event->button() == Qt::RightButton )
{
Expand All @@ -112,8 +140,21 @@ void Qgs3DMapToolPointCloudChangeAttributePolygon::activate()
// cannot move this to the constructor as there are no mapSettings available yet when the tool is created
if ( !mPolygonRubberBand )
{
mPolygonRubberBand = new QgsRubberBand3D( *mCanvas->mapSettings(), mCanvas->engine(), mCanvas->engine()->frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
mPolygonRubberBand->setHideLastMarker( true );
mPolygonRubberBand = std::make_unique<QgsRubberBand3D>( *mCanvas->mapSettings(), mCanvas->engine(), mCanvas->engine()->frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Polygon );
if ( mToolType == Polygon )
{
mPolygonRubberBand->setHideLastMarker( true );
}
else
{
mPolygonRubberBand->setEdgesEnabled( false );
mPolygonRubberBand->setMarkersEnabled( false );
}
}
if ( !mLineRubberBand && mToolType != Polygon )
{
mLineRubberBand = std::make_unique<QgsRubberBand3D>( *mCanvas->mapSettings(), mCanvas->engine(), mCanvas->engine()->frameGraph()->rubberBandsRootEntity(), Qgis::GeometryType::Line );
mLineRubberBand->setHideLastMarker( true );
}
}

Expand All @@ -124,11 +165,17 @@ void Qgs3DMapToolPointCloudChangeAttributePolygon::deactivate()

void Qgs3DMapToolPointCloudChangeAttributePolygon::run()
{
QgsTemporaryCursorOverride busyCursor( Qt::WaitCursor );

if ( mToolType == AboveLine || mToolType == BelowLine )
{
const double y = mToolType == AboveLine ? 0 : mCanvas->height();
mScreenPoints.append( { QgsPointXY( mScreenPoints[1].x(), y ), QgsPointXY( mScreenPoints[0].x(), y ) } );
}

if ( mScreenPoints.size() < 3 )
return;

QgsTemporaryCursorOverride busyCursor( Qt::WaitCursor );

const QgsGeometry searchPolygon = QgsGeometry( new QgsPolygon( new QgsLineString( mScreenPoints ) ) );
changeAttributeValue( searchPolygon, mAttributeName, mNewValue, *mCanvas, QgisApp::instance()->activeLayer() );
}
Expand All @@ -138,4 +185,8 @@ void Qgs3DMapToolPointCloudChangeAttributePolygon::restart()
mCanvas->cameraController()->setInputHandlersEnabled( true );
mScreenPoints.clear();
mPolygonRubberBand->reset();
if ( mToolType != Polygon )
{
mLineRubberBand->reset();
}
}
Loading
Loading