Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by ian.rees »

Yes, I bought a basic SpaceNavigator a couple years ago (using some of that money from Aleph Objects - thanks again!).

When I was starting the recent work, I made a couple test programs with the sockets API and with the X11 one - both seem to work fine with the gear I have (USB SpaceNavigator, Ubuntu 18.04, Qt5.11). The main difference is that the socket API is polled, where the X one is event driven. So, I didn't have a good reason to prefer one over the other, and it sounds like the socket API might not support some older devices.

I'd be glad to implement the sockets API if there's a reason to, however the code around there is already getting a bit unwieldy with precompiler options. Would it be OK, to only do the SpaceNavigator sockets API for Qt5?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by wmayer »

When I was starting the recent work, I made a couple test programs with the sockets API and with the X11 one - both seem to work fine with the gear I have (USB SpaceNavigator, Ubuntu 18.04, Qt5.11). The main difference is that the socket API is polled, where the X one is event driven.
There was the request by @freecad-heini-1 (https://forum.freecadweb.org/viewtopic. ... 90#p256492) to do it the same as Blender as this seems to work flawlessly. After logging in and starting Blender you can simply use the device while for FreeCAD you still have to run these steps every time:

Code: Select all

sudo /etc/init.d/spacenavd stop
sudo xhost +
sudo /etc/init.d/spacenavd start
Then, I am not sure what will happen after Wayland more and more replaces the X-server. I wonder whether there will be a way that X stuff still can be used or do we then have to use the polling approach.
So, I didn't have a good reason to prefer one over the other, and it sounds like the socket API might not support some older devices.
Yes, tanderson69 mentioned this above that it can happen that his serial device won't work this way any more. But therefore it would be good to keep the X-server approach and add e.g. a cmake option for it.
I'd be glad to implement the sockets API if there's a reason to, however the code around there is already getting a bit unwieldy with precompiler options. Would it be OK, to only do the SpaceNavigator sockets API for Qt5?
Only supporting Qt5 shouldn't be a problem as this is the default for most recent releases of the major distributions. Also, feel free to put the code into its own source files as currently it looks a bit messy due to the heavy use of #ifdef's.

Thanks in advance!

P.S.: As a reference here is the link to the Blender code that uses the polling API of spacenav:
https://github.com/UPBGE/blender/blob/m ... erUnix.cpp
tsadowski
Posts: 36
Joined: Tue Jan 20, 2015 10:50 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tsadowski »

Hi,

I put together a solution for the socket interface. It can be found here:
https://github.com/tsadowski/FreeCAD/tree/LinuxSpacenav

It works for my on Arch Linux under Gnome/Wayland with XWayland. I don't want to make a pull request yet because I would like to find a solution for serial devices as well using the inputattach method as described here:
https://wiki.archlinux.org/index.php/Se ... rnel_input
and here:
https://www.kernel.org/doc/Documentatio ... ystick.txt

Unluckily even though the inputattach works, jstest remains silent. It might just be the crappy pl2303 usb to serial adapter which possibly does not support RTS/CTS. Maybe a FTDI chip could work.

Cheers,
Torsten
Last edited by tsadowski on Wed Oct 17, 2018 10:03 pm, edited 1 time in total.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by ian.rees »

Thanks Torsten, and sorry it's taken me so long to (still not) do anything about this. For what it's worth, in general, it's a good idea to communicate about work that you're thinking about doing, when there's a chance someone else will already be doing that work. Otherwise, there is a real risk of duplicating (read: wasting) effort, which is our most precious resource.

From your commit message, I'm assuming that the X11 input stuff is incompatible with Wayland, is that right? If so, it would seem that's a good reason to look at switching to the new polling API from the event-based one, like you've done here.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by wmayer »

IMO, the old X11-event based code should not be removed but a CMake option should be provided so that people who build their own FreeCAD still can switch back to the X11 method in case the polling method doesn't work.
And to avoid an ifdef/else/endif mess and thus to keep maintenance low I suggest to have one class the uses the X11 API of spacenav and in another class (it can be the same class name if guarded by an ifdef/else/endif) using the polling API.
tsadowski
Posts: 36
Joined: Tue Jan 20, 2015 10:50 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tsadowski »

@ian You are of course right about communicating but I had some time and because it simply worked, I posted the result.

The drivers under Wayland cannot use X because XWayland is just a layer for the running programs. We have to switch as Wayland will become more common.

@wmayer I will try to cleanup the #ifdef tangle and add the X11 API back afterwards with an SPNAV_USE_X11 option for cmake.

Does anyone know, why SpaceNavigatorDevice.cpp does also open the spacenav driver?

Cheers,Torsten
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by wmayer »

Does anyone know, why SpaceNavigatorDevice.cpp does also open the spacenav driver?
You can ignore this class. It's the implementation of the Coin3d developers who also implemented the original Quarter library but inside FreeCAD we don't use it. Instead we handle the space mouse support in our own class (GUIApplicationNativeEventAware).
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by PrzemoF »

tsadowski wrote: Thu Oct 18, 2018 5:17 pm[..]
Does anyone know, why SpaceNavigatorDevice.cpp does also open the spacenav driver?
[..]
You mean this [1]?

Code: Select all

  PRIVATE(this)->hasdevice =
spnav_x11_open(QX11Info::display(), PRIVATE(this)->windowid) == -1 ? false : true;
From the docs ([2], page 7): it might be because of some magellan X11 protocol [3] that was probably used long time ago.
spnav.spnav_x11_open(display,window)
Opens a connection to the daemon, using the original magellan X11 protocol. Any application using this protocol should be compatible with the proprietary 3D connexion driver too.
[1] https://github.com/FreeCAD/FreeCAD/blob ... ce.cpp#L94
[2] https://media.readthedocs.org/pdf/spnav ... /spnav.pdf
[3] http://spacemice.org/pdf/Magellan_Protocol.pdf

P.S. I'm just guessing....
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by ian.rees »

tsadowski wrote: Thu Oct 18, 2018 5:17 pm @ian You are of course right about communicating but I had some time and because it simply worked, I posted the result.
No worries - was more suggesting that it would've been fine to drop me an email/pm. I had already done much of the same work, so could've shared that directly.
tsadowski wrote: Thu Oct 18, 2018 5:17 pm @wmayer I will try to cleanup the #ifdef tangle and add the X11 API back afterwards with an SPNAV_USE_X11 option for cmake.
It might be good to make the new cmake option less SPNAV-specific, as there could be other Wayland/X11 differences around. Hopefully not, since we're pretty good about sticking to Qt for GUI interaction, but there's not much penalty for making the variable USE_WAYLAND instead, even if it only applies to Space Navigator for now.
tsadowski
Posts: 36
Joined: Tue Jan 20, 2015 10:50 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tsadowski »

Hi,

I just pushed a first version to my Github repository. The Linux build works with Qt5. I will also try to build on Linux with Qt4 and on Mac OSX. I would appreciate, if someone could work on the Windows build.

I kept the option name SPNAV_USE_X11. The option has nothing to do with Wayland directly and the polling driver works under both window systems.

Cheers,
Torsten
Post Reply