Compare commits

...

3 Commits

8 changed files with 78 additions and 19 deletions

View File

@ -90,6 +90,24 @@ scene's clipping planes
.. versionadded:: 4.0
%End
bool crossSectionEnabled() const;
%Docstring
Returns ``True`` if the cross section mode is enabled or the 3d scene
has other clipping planes applied
.. seealso:: :py:func:`enableCrossSection`
.. versionadded:: 4.0
%End
void crossSectionEnabledChanged( bool enabled );
%Docstring
Emitted when the cross section mode is enabled or disabled
.. seealso:: :py:func:`enableCrossSection`
.. versionadded:: 4.0
%End
protected:
virtual void showEvent( QShowEvent *e );

View File

@ -90,6 +90,24 @@ scene's clipping planes
.. versionadded:: 4.0
%End
bool crossSectionEnabled() const;
%Docstring
Returns ``True`` if the cross section mode is enabled or the 3d scene
has other clipping planes applied
.. seealso:: :py:func:`enableCrossSection`
.. versionadded:: 4.0
%End
void crossSectionEnabledChanged( bool enabled );
%Docstring
Emitted when the cross section mode is enabled or disabled
.. seealso:: :py:func:`enableCrossSection`
.. versionadded:: 4.0
%End
protected:
virtual void showEvent( QShowEvent *e );

View File

@ -190,6 +190,9 @@ QgsCameraController *Qgs3DMapCanvas::cameraController()
void Qgs3DMapCanvas::enableCrossSection( const QgsPointXY &startPoint, const QgsPointXY &endPoint, double width, bool setSideView )
{
if ( !mScene )
return;
const QgsVector3D startVec { startPoint.x(), startPoint.y(), 0 };
const QgsVector3D endVec { endPoint.x(), endPoint.y(), 0 };
const QList<QVector4D> clippingPlanes = Qgs3DUtils::lineSegmentToClippingPlanes(
@ -225,10 +228,18 @@ void Qgs3DMapCanvas::enableCrossSection( const QgsPointXY &startPoint, const Qgs
void Qgs3DMapCanvas::disableCrossSection()
{
if ( !mScene )
return;
mScene->disableClipping();
emit crossSectionEnabledChanged( false );
}
bool Qgs3DMapCanvas::crossSectionEnabled() const
{
return mScene ? !mScene->clipPlaneEquations().isEmpty() : false;
}
void Qgs3DMapCanvas::resetView()
{
if ( !mScene )

View File

@ -116,6 +116,14 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWindow
*/
void disableCrossSection();
/**
* Returns TRUE if the cross section mode is enabled or the 3d scene has other clipping planes applied
*
* \see enableCrossSection()
* \since QGIS 4.0
*/
bool crossSectionEnabled() const;
#ifndef SIP_RUN
/**
@ -217,9 +225,13 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWindow
//! Emitted when the camera navigation \a speed is changed.
void cameraNavigationSpeedChanged( double speed );
//! Emitted when the cross section mode is enabled or disabled
void crossSectionEnabledChanged( bool enabled );
#endif
/**
* Emitted when the cross section mode is enabled or disabled
* \see enableCrossSection()
* \since QGIS 4.0
*/
void crossSectionEnabledChanged( bool enabled );
private slots:
void captureDepthBuffer();

View File

@ -708,6 +708,7 @@ void Qgs3DMapCanvasWidget::setMapSettings( Qgs3DMapSettings *map )
mMapToolClippingPlanes = std::make_unique<QgsMapToolClippingPlanes>( mMainCanvas, this );
mMapToolClippingPlanes->setAction( mActionSetClippingPlanes );
connect( mMapToolClippingPlanes.get(), &QgsMapToolClippingPlanes::finishedSuccessfully, this, &Qgs3DMapCanvasWidget::onCrossSectionToolFinished );
// none of the actions in the Camera menu are supported by globe yet, so just hide it completely
mActionCamera->setVisible( map->sceneMode() == Qgis::SceneMode::Local );
@ -1207,7 +1208,7 @@ void Qgs3DMapCanvasWidget::setClippingPlanesOn2DCanvas()
mMessageBar->pushInfo( QString(), tr( "Select a rectangle using 3 points on the main 2D map view to define the cross-section of this 3D scene" ) );
}
void Qgs3DMapCanvasWidget::crossSectionToolFinished()
void Qgs3DMapCanvasWidget::onCrossSectionToolFinished()
{
this->activateWindow();
this->raise();

View File

@ -96,8 +96,6 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget
bool eventFilter( QObject *watched, QEvent *event ) override;
void crossSectionToolFinished();
private slots:
void resetView();
void configure();
@ -138,7 +136,8 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget
void onGpuMemoryLimitReached();
void onPointCloudChangeAttributeSettingsChanged();
// void onPointCloudChangeAttributePointFilterChanged();
void onCrossSectionToolFinished();
private:
void updateCheckedActionsFromMapSettings( const Qgs3DMapSettings *mapSettings ) const;

View File

@ -23,7 +23,6 @@
#include "qgspolygon.h"
#include "qgs3dmapcanvaswidget.h"
#include "qgs3dmapscene.h"
#include "qgsmessagebar.h"
#include "qgisapp.h"
#include "qgscoordinatetransform.h"
#include "qgsrubberband.h"
@ -32,7 +31,7 @@
QgsMapToolClippingPlanes::QgsMapToolClippingPlanes( QgsMapCanvas *canvas, Qgs3DMapCanvasWidget *mapCanvas )
: QgsMapTool( canvas ), m3DCanvas( mapCanvas )
: QgsMapTool( canvas ), m3DCanvasWidget( mapCanvas )
{
mRubberBandPolygon.reset( new QgsRubberBand( canvas, Qgis::GeometryType::Polygon ) );
mRubberBandLines.reset( new QgsRubberBand( canvas, Qgis::GeometryType::Line ) );
@ -54,7 +53,7 @@ void QgsMapToolClippingPlanes::activate()
mRubberBandPolygon->show();
mCt = std::make_unique<QgsCoordinateTransform>(
mCanvas->mapSettings().destinationCrs(),
m3DCanvas->mapCanvas3D()->mapSettings()->crs(),
m3DCanvasWidget->mapCanvas3D()->mapSettings()->crs(),
mCanvas->mapSettings().transformContext()
);
}
@ -142,14 +141,13 @@ void QgsMapToolClippingPlanes::canvasReleaseEvent( QgsMapMouseEvent *e )
QgsDebugError( QStringLiteral( "Could not reproject cross-section extent to 3d map canvas crs." ) );
}
if ( !crossSectionPolygon.intersects( m3DCanvas->mapCanvas3D()->scene()->sceneExtent() ) )
if ( !crossSectionPolygon.intersects( m3DCanvasWidget->mapCanvas3D()->scene()->sceneExtent() ) )
{
clear();
QgsMessageBar *msgBar = QgisApp::instance()->messageBar();
if ( crossSectionPolygon.isNull() )
msgBar->pushWarning( QString(), tr( "Could not reproject the cross-section extent to 3D map coordinates." ) );
emit messageEmitted( tr( "Could not reproject the cross-section extent to 3D map coordinates." ), Qgis::MessageLevel::Warning );
else
msgBar->pushInfo( QString(), tr( "The cross section is outside of the scene extent, please select a new one!" ) );
emit messageEmitted( tr( "The cross section is outside of the scene extent, please select a new one!" ), Qgis::MessageLevel::Info );
}
else
{
@ -162,23 +160,22 @@ void QgsMapToolClippingPlanes::canvasReleaseEvent( QgsMapMouseEvent *e )
}
catch ( const QgsCsException & )
{
QgsMessageBar *msgBar = QgisApp::instance()->messageBar();
msgBar->pushWarning( QString(), tr( "Could not reproject the cross-section extent to 3D map coordinates." ) );
emit messageEmitted( tr( "Could not reproject the cross-section extent to 3D map coordinates." ), Qgis::MessageLevel::Warning );
}
m3DCanvas->mapCanvas3D()->enableCrossSection(
m3DCanvasWidget->mapCanvas3D()->enableCrossSection(
pt0,
pt1,
mRectangleWidth,
true
);
m3DCanvas->crossSectionToolFinished();
const QgsSettings settings;
QColor highlightColor = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
highlightColor.setAlphaF( 0.5 );
mRubberBandPolygon->setColor( highlightColor );
emit finishedSuccessfully();
}
}
else

View File

@ -52,6 +52,9 @@ class QgsMapToolClippingPlanes : public QgsMapTool
//! Returns the Geometry of clipped area
QgsGeometry clippedPolygon() const;
signals:
void finishedSuccessfully();
private:
void clearRubberBand() const;
@ -59,7 +62,7 @@ class QgsMapToolClippingPlanes : public QgsMapTool
QObjectUniquePtr<QgsRubberBand> mRubberBandLines;
QObjectUniquePtr<QgsRubberBand> mRubberBandPoints;
std::unique_ptr<QgsCoordinateTransform> mCt;
Qgs3DMapCanvasWidget *m3DCanvas = nullptr;
Qgs3DMapCanvasWidget *m3DCanvasWidget = nullptr;
double mRectangleWidth = 0;
};