From 47c1a0ad60efa42db3d69c7d4f9e4fb45c44b62d Mon Sep 17 00:00:00 2001 From: uclaros Date: Tue, 30 Sep 2025 12:08:09 +0300 Subject: [PATCH 1/2] expose 3d map tools to python --- python/3d/3d_auto.sip | 1 + python/3d/auto_additions/qgs3dmaptool.py | 5 + .../3d/auto_generated/qgs3dmapcanvas.sip.in | 17 ++++ python/3d/auto_generated/qgs3dmaptool.sip.in | 95 +++++++++++++++++++ python/PyQt6/3d/3d_auto.sip | 1 + .../PyQt6/3d/auto_additions/qgs3dmaptool.py | 5 + .../3d/auto_generated/qgs3dmapcanvas.sip.in | 17 ++++ .../3d/auto_generated/qgs3dmaptool.sip.in | 95 +++++++++++++++++++ src/3d/qgs3dmapcanvas.h | 26 ++--- src/3d/qgs3dmaptool.h | 4 +- 10 files changed, 251 insertions(+), 15 deletions(-) create mode 100644 python/3d/auto_additions/qgs3dmaptool.py create mode 100644 python/3d/auto_generated/qgs3dmaptool.sip.in create mode 100644 python/PyQt6/3d/auto_additions/qgs3dmaptool.py create mode 100644 python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in diff --git a/python/3d/3d_auto.sip b/python/3d/3d_auto.sip index 5fb94896794..a470f8ffcd2 100644 --- a/python/3d/3d_auto.sip +++ b/python/3d/3d_auto.sip @@ -3,6 +3,7 @@ %Include auto_generated/qgs3d.sip %Include auto_generated/qgs3dmapscene.sip %Include auto_generated/qgs3dmapsettings.sip +%Include auto_generated/qgs3dmaptool.sip %Include auto_generated/qgs3dtypes.sip %Include auto_generated/qgs3dmapcanvas.sip %Include auto_generated/qgsabstractvectorlayer3drenderer.sip diff --git a/python/3d/auto_additions/qgs3dmaptool.py b/python/3d/auto_additions/qgs3dmaptool.py new file mode 100644 index 00000000000..52623d24c95 --- /dev/null +++ b/python/3d/auto_additions/qgs3dmaptool.py @@ -0,0 +1,5 @@ +# The following has been generated automatically from src/3d/qgs3dmaptool.h +try: + Qgs3DMapTool.__virtual_methods__ = ['mousePressEvent', 'mouseReleaseEvent', 'mouseMoveEvent', 'keyPressEvent', 'keyReleaseEvent', 'mouseWheelEvent', 'activate', 'deactivate', 'cursor'] +except (NameError, AttributeError): + pass diff --git a/python/3d/auto_generated/qgs3dmapcanvas.sip.in b/python/3d/auto_generated/qgs3dmapcanvas.sip.in index 83701d9678f..fb3d4dc2027 100644 --- a/python/3d/auto_generated/qgs3dmapcanvas.sip.in +++ b/python/3d/auto_generated/qgs3dmapcanvas.sip.in @@ -58,6 +58,23 @@ scene has not been initialized yet with :py:func:`~Qgs3DMapCanvas.setMapSettings` %End + void setMapTool( Qgs3DMapTool *tool ); +%Docstring +Sets the active map ``tool`` that will receive events from the 3D +canvas. Does not transfer ownership. If the tool is ``None``, events +will be used for camera manipulation. + +.. versionadded:: 4.0 +%End + + Qgs3DMapTool *mapTool() const; +%Docstring +Returns the active map tool that will receive events from the 3D canvas. +If the tool is ``None``, events will be used for camera manipulation. + +.. versionadded:: 4.0 +%End + protected: virtual void showEvent( QShowEvent *e ); diff --git a/python/3d/auto_generated/qgs3dmaptool.sip.in b/python/3d/auto_generated/qgs3dmaptool.sip.in new file mode 100644 index 00000000000..7e54a681a79 --- /dev/null +++ b/python/3d/auto_generated/qgs3dmaptool.sip.in @@ -0,0 +1,95 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.py again * + ************************************************************************/ + + + + + + +class Qgs3DMapTool : QObject +{ +%Docstring(signature="appended") +Base class for map tools operating on 3D map canvas. + +.. note:: + + Not available in Python bindings + +.. versionadded:: 4.0 +%End + +%TypeHeaderCode +#include "qgs3dmaptool.h" +%End + public: + Qgs3DMapTool( Qgs3DMapCanvas *canvas ); +%Docstring +Base constructor for a Qgs3DMapTool for the specified ``canvas`` +%End + + virtual void mousePressEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseReleaseEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse release ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseMoveEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse move ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void keyPressEvent( QKeyEvent *event ); +%Docstring +Reimplement to handle key press ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void keyReleaseEvent( QKeyEvent *event ); +%Docstring +Reimplement to handle key release ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseWheelEvent( QWheelEvent *event ); +%Docstring +Reimplement to handle mouse wheel ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + + virtual void activate(); +%Docstring +Called when set as currently active map tool +%End + + virtual void deactivate(); +%Docstring +Called when map tool is being deactivated +%End + + virtual QCursor cursor() const; +%Docstring +Mouse cursor to be used when the tool is active +%End + + Qgs3DMapCanvas *canvas(); +%Docstring +Returns the parent Qgs3DMapCanvas +%End + + protected: +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.py again * + ************************************************************************/ diff --git a/python/PyQt6/3d/3d_auto.sip b/python/PyQt6/3d/3d_auto.sip index 5fb94896794..a470f8ffcd2 100644 --- a/python/PyQt6/3d/3d_auto.sip +++ b/python/PyQt6/3d/3d_auto.sip @@ -3,6 +3,7 @@ %Include auto_generated/qgs3d.sip %Include auto_generated/qgs3dmapscene.sip %Include auto_generated/qgs3dmapsettings.sip +%Include auto_generated/qgs3dmaptool.sip %Include auto_generated/qgs3dtypes.sip %Include auto_generated/qgs3dmapcanvas.sip %Include auto_generated/qgsabstractvectorlayer3drenderer.sip diff --git a/python/PyQt6/3d/auto_additions/qgs3dmaptool.py b/python/PyQt6/3d/auto_additions/qgs3dmaptool.py new file mode 100644 index 00000000000..52623d24c95 --- /dev/null +++ b/python/PyQt6/3d/auto_additions/qgs3dmaptool.py @@ -0,0 +1,5 @@ +# The following has been generated automatically from src/3d/qgs3dmaptool.h +try: + Qgs3DMapTool.__virtual_methods__ = ['mousePressEvent', 'mouseReleaseEvent', 'mouseMoveEvent', 'keyPressEvent', 'keyReleaseEvent', 'mouseWheelEvent', 'activate', 'deactivate', 'cursor'] +except (NameError, AttributeError): + pass diff --git a/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in b/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in index 83701d9678f..fb3d4dc2027 100644 --- a/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in +++ b/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in @@ -58,6 +58,23 @@ scene has not been initialized yet with :py:func:`~Qgs3DMapCanvas.setMapSettings` %End + void setMapTool( Qgs3DMapTool *tool ); +%Docstring +Sets the active map ``tool`` that will receive events from the 3D +canvas. Does not transfer ownership. If the tool is ``None``, events +will be used for camera manipulation. + +.. versionadded:: 4.0 +%End + + Qgs3DMapTool *mapTool() const; +%Docstring +Returns the active map tool that will receive events from the 3D canvas. +If the tool is ``None``, events will be used for camera manipulation. + +.. versionadded:: 4.0 +%End + protected: virtual void showEvent( QShowEvent *e ); diff --git a/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in b/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in new file mode 100644 index 00000000000..7e54a681a79 --- /dev/null +++ b/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in @@ -0,0 +1,95 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.py again * + ************************************************************************/ + + + + + + +class Qgs3DMapTool : QObject +{ +%Docstring(signature="appended") +Base class for map tools operating on 3D map canvas. + +.. note:: + + Not available in Python bindings + +.. versionadded:: 4.0 +%End + +%TypeHeaderCode +#include "qgs3dmaptool.h" +%End + public: + Qgs3DMapTool( Qgs3DMapCanvas *canvas ); +%Docstring +Base constructor for a Qgs3DMapTool for the specified ``canvas`` +%End + + virtual void mousePressEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseReleaseEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse release ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseMoveEvent( QMouseEvent *event ); +%Docstring +Reimplement to handle mouse move ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void keyPressEvent( QKeyEvent *event ); +%Docstring +Reimplement to handle key press ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void keyReleaseEvent( QKeyEvent *event ); +%Docstring +Reimplement to handle key release ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + virtual void mouseWheelEvent( QWheelEvent *event ); +%Docstring +Reimplement to handle mouse wheel ``event`` forwarded by the parent +Qgs3DMapCanvas +%End + + virtual void activate(); +%Docstring +Called when set as currently active map tool +%End + + virtual void deactivate(); +%Docstring +Called when map tool is being deactivated +%End + + virtual QCursor cursor() const; +%Docstring +Mouse cursor to be used when the tool is active +%End + + Qgs3DMapCanvas *canvas(); +%Docstring +Returns the parent Qgs3DMapCanvas +%End + + protected: +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.py again * + ************************************************************************/ diff --git a/src/3d/qgs3dmapcanvas.h b/src/3d/qgs3dmapcanvas.h index daeaa0845d5..c1091a45101 100644 --- a/src/3d/qgs3dmapcanvas.h +++ b/src/3d/qgs3dmapcanvas.h @@ -95,6 +95,20 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWindow //! Returns access to the view's camera controller. Returns NULLPTR if the scene has not been initialized yet with setMapSettings() QgsCameraController *cameraController(); + /** + * Sets the active map \a tool that will receive events from the 3D canvas. Does not transfer ownership. + * If the tool is NULLPTR, events will be used for camera manipulation. + * \since QGIS 4.0 + */ + void setMapTool( Qgs3DMapTool *tool ); + + /** + * Returns the active map tool that will receive events from the 3D canvas. + * If the tool is NULLPTR, events will be used for camera manipulation. + * \since QGIS 4.0 + */ + Qgs3DMapTool *mapTool() const { return mMapTool; } + #ifndef SIP_RUN /** @@ -134,18 +148,6 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWindow //! Saves the current scene as an image void saveAsImage( const QString &fileName, const QString &fileFormat ); - /** - * Sets the active map \a tool that will receive events from the 3D canvas. Does not transfer ownership. - * If the tool is NULLPTR, events will be used for camera manipulation. - */ - void setMapTool( Qgs3DMapTool *tool ); - - /** - * Returns the active map tool that will receive events from the 3D canvas. - * If the tool is NULLPTR, events will be used for camera manipulation. - */ - Qgs3DMapTool *mapTool() const { return mMapTool; } - /** * Returns the 3D engine. */ diff --git a/src/3d/qgs3dmaptool.h b/src/3d/qgs3dmaptool.h index 0d03911af9c..b1d7aad5235 100644 --- a/src/3d/qgs3dmaptool.h +++ b/src/3d/qgs3dmaptool.h @@ -25,14 +25,12 @@ class QMouseEvent; class QKeyEvent; class QWheelEvent; -#define SIP_NO_FILE - /** * \ingroup qgis_3d * \brief Base class for map tools operating on 3D map canvas. * \note Not available in Python bindings - * \since QGIS 3.36 (since QGIS 3.4 in QGIS_APP library) + * \since QGIS 4.0 (since QGIS 3.36 in QGIS_3D library, since QGIS 3.4 in QGIS_APP library) */ class _3D_EXPORT Qgs3DMapTool : public QObject { From 5b86bec5e868d825131eab171f9a8040de44a9c2 Mon Sep 17 00:00:00 2001 From: uclaros Date: Tue, 23 Sep 2025 18:13:48 +0300 Subject: [PATCH 2/2] Change 3d sip split parts --- python/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index bff773a3937..95604f2bec6 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -262,7 +262,7 @@ if (WITH_3D) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/3d/project.py.in ${CMAKE_CURRENT_BINARY_DIR}/3d/project.py @ONLY) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/3d/pyproject.toml.temp" "${toml}") execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/3d/pyproject.toml.temp ${CMAKE_CURRENT_BINARY_DIR}/3d/pyproject.toml) - SET(SIP_CONCAT_PARTS 10) # 3D doesn't have enough .sip files to fill 15+ .cpp files + SET(SIP_CONCAT_PARTS 9) # 3D doesn't have enough .sip files to fill 15+ .cpp files GENERATE_SIP_PYTHON_MODULE_CODE(qgis._3d_p 3d/3d.sip "${sip_files_3d}" cpp_files) BUILD_SIP_PYTHON_MODULE(qgis._3d_p 3d/3d.sip ${cpp_files} "" qgis_core qgis_3d) endif()