git: 46d3b8f4a284 - main - cad/freecad: optionize SpaceMouse support

From: Christoph Moench-Tegeder <cmt_at_FreeBSD.org>
Date: Mon, 24 Mar 2025 22:13:58 UTC
The branch main has been updated by cmt:

URL: https://cgit.FreeBSD.org/ports/commit/?id=46d3b8f4a28431fbacb8029f905d1175ba3ae61e

commit 46d3b8f4a28431fbacb8029f905d1175ba3ae61e
Author:     Christoph Moench-Tegeder <cmt@FreeBSD.org>
AuthorDate: 2025-03-24 22:04:24 +0000
Commit:     Christoph Moench-Tegeder <cmt@FreeBSD.org>
CommitDate: 2025-03-24 22:04:24 +0000

    cad/freecad: optionize SpaceMouse support
    
    Originially, FreeCAD picked up libspnav (SpaceMouse) support
    when the library was present in the system during build. That
    alone would be a minor problem, but people still insist on
    building in unclean systems.
    Additionally, libspnav support in FreeCAD was broken and resulted
    in build failure when accidentially building with libspnav (see
    above).
    Upstream fixed this in a series of changes touching many places
    and sometimes even depending on otherwise unrelated changes:
    importing all that would be close to updating to a snapshot.
    Instead, adopt the relevant fix for building with libspnav from
    upstream, and put the whole libspnav detection behind a cmake
    option (made accessible as a port option).
    
    PR:             285542
    Reported by:    Chad Jacob Milios
---
 cad/freecad/Makefile                  |  7 ++-
 cad/freecad/files/patch-spnav-support | 94 +++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/cad/freecad/Makefile b/cad/freecad/Makefile
index 4f8d87554a63..b10760856548 100644
--- a/cad/freecad/Makefile
+++ b/cad/freecad/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	FreeCAD
 DISTVERSION=	1.0.0
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	cad
 
 MAINTAINER=	cmt@FreeBSD.org
@@ -102,10 +102,13 @@ CMAKE_ARGS+=	-DOCC_INCLUDE_DIR="${LOCALBASE}/include/OpenCASCADE" \
 
 CMAKE_INSTALL_PREFIX=	${PREFIX}/${PORTNAME}
 
-OPTIONS_DEFINE=	COLLADA
+OPTIONS_DEFINE=	COLLADA SPNAV
 
 COLLADA_DESC=		Install pycollada for Collada files import
 COLLADA_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}pycollada>0:graphics/py-pycollada@${PY_FLAVOR}
+SPNAV_DESC=		Enable libspnav (SpaceMouse) support
+SPNAV_CMAKE_BOOL=	FREECAD_SPNAV_SUPPORT
+SPNAV_LIB_DEPENDS=	libspnav.so:misc/libspnav
 
 .include <bsd.port.options.mk>
 
diff --git a/cad/freecad/files/patch-spnav-support b/cad/freecad/files/patch-spnav-support
new file mode 100644
index 000000000000..e9b364d61f60
--- /dev/null
+++ b/cad/freecad/files/patch-spnav-support
@@ -0,0 +1,94 @@
+commit f2b872ba4dc509622bda2d86ce42e2464d40832b
+Author: Christoph Moench-Tegeder <cmt@burggraben.net>
+Date:   Mon Mar 24 01:03:53 2025 +0100
+
+    attempt to fix building with libspnav
+
+diff --git cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake
+index e9aa47fd6e..826c510ef0 100644
+--- cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake
++++ cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake
+@@ -142,6 +142,7 @@ macro(InitializeFreeCADBuildOptions)
+     option(BUILD_CLOUD "Build the FreeCAD cloud module" OFF)
+     option(ENABLE_DEVELOPER_TESTS "Build the FreeCAD unit tests suit" ON)
+ 
++    option(FREECAD_SPNAV_SUPPORT "Enable libspnav support" OFF)
+     if(MSVC)
+         set(FREECAD_3DCONNEXION_SUPPORT "NavLib" CACHE STRING "Select version of the 3Dconnexion device integration")
+         set_property(CACHE FREECAD_3DCONNEXION_SUPPORT PROPERTY STRINGS "NavLib" "Raw input")
+diff --git src/Gui/CMakeLists.txt src/Gui/CMakeLists.txt
+index 642f58568f..52cc393875 100644
+--- src/Gui/CMakeLists.txt
++++ src/Gui/CMakeLists.txt
+@@ -133,7 +133,8 @@ if(${Qt5WinExtras_FOUND})
+     )
+ endif()
+ 
+-IF(SPNAV_FOUND)
++IF(FREECAD_SPNAV_SUPPORT AND SPNAV_FOUND)
++    add_definitions(-D_USE_3DCONNEXION_SDK)
+     if(SPNAV_USE_X11)
+         add_definitions(-DSPNAV_USE_X11)
+         if (FREECAD_QT_MAJOR_VERSION EQUAL 5 AND UNIX AND NOT APPLE)
+@@ -175,7 +176,11 @@ IF(SPNAV_FOUND)
+     list(APPEND FreeCADGui_LIBS
+         ${SPNAV_LIBRARIES}
+     )
+-ENDIF(SPNAV_FOUND)
++ENDIF(FREECAD_SPNAV_SUPPORT AND SPNAV_FOUND)
++
++IF(FREECAD_SPNAV_SUPPORT AND NOT SPNAV_FOUND)
++    MESSAGE(FATAL_ERROR "libspnav support requested but libspnav not found")
++ENDIF(FREECAD_SPNAV_SUPPORT AND NOT SPNAV_FOUND)
+ 
+ IF(OCULUS_FOUND)
+     add_definitions(-DOCULUS_FOUND)
+diff --git src/Gui/GuiApplicationNativeEventAware.cpp src/Gui/GuiApplicationNativeEventAware.cpp
+index ba41901472..c0cf3c7666 100644
+--- src/Gui/GuiApplicationNativeEventAware.cpp
++++ src/Gui/GuiApplicationNativeEventAware.cpp
+@@ -33,7 +33,7 @@
+ 
+ 
+ #if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND)
+-#if defined(Q_OS_LINUX)
++#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
+   #if defined(SPNAV_USE_X11)
+     #include "3Dconnexion/GuiNativeEventLinuxX11.h"
+   #else
+@@ -59,7 +59,15 @@ Gui::GUIApplicationNativeEventAware::~GUIApplicationNativeEventAware() = default
+ void Gui::GUIApplicationNativeEventAware::initSpaceball(QMainWindow *window)
+ {
+ #if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND)
++# if defined(USE_3DCONNEXION_NAVLIB)
++    ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath(
++        "User parameter:BaseApp/Preferences/View");
++    if (nativeEvent && hViewGrp->GetBool("LegacySpaceMouseDevices", false)) {
++        nativeEvent->initSpaceball(window);
++    }
++# else
+     nativeEvent->initSpaceball(window);
++# endif
+ #else
+     Q_UNUSED(window);
+ #endif
+diff --git src/Gui/View3DInventorViewer.cpp src/Gui/View3DInventorViewer.cpp
+index 694f834583..d32c2486b5 100644
+--- src/Gui/View3DInventorViewer.cpp
++++ src/Gui/View3DInventorViewer.cpp
+@@ -555,7 +555,15 @@ void View3DInventorViewer::init()
+     //filter a few qt events
+     viewerEventFilter = new ViewerEventFilter;
+     installEventFilter(viewerEventFilter);
++#if defined(USE_3DCONNEXION_NAVLIB)
++    ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath(
++        "User parameter:BaseApp/Preferences/View");
++    if (hViewGrp->GetBool("LegacySpaceMouseDevices", false)) {
++        getEventFilter()->registerInputDevice(new SpaceNavigatorDevice);
++    }
++#else
+     getEventFilter()->registerInputDevice(new SpaceNavigatorDevice);
++#endif
+     getEventFilter()->registerInputDevice(new GesturesDevice(this));
+ 
+     try{