discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Need help to support 3Dconnexion SpaceNavigator

JK
Jochen Kunz
Tue, Jun 30, 2015 9:06 PM

Hi.

Recently I bought a 3Dconnexion SpaceNavigator to use with OpenSCAD. I
know that this gadget is currently not supported by OpenSCAD. But being
a hacker fluent in C and C++, I thought it would be a nice project to
add support for it myself.

3Dconnexion offers a SDK for there devices, but the SDK is poisoned by a
ridiculous restrictive license. The SDK is impossible to use with Open
Source Software.

Fortunately the SpaceNavigator enumerates as an ordinary USB HID. I had
a look into libusb and the documentation here:
http://libusb.org/wiki/APIs#libusb-1.0currentAPIandimplementation
redirected me to HIDAPI:
http://www.signal11.us/oss/hidapi/
This is a small library with support for Mac OS X, Linux, Windows and
FreeBSD. It is a single .h file and a single .c file per platform.

With the help of HIDAPI I got reasonable output from the SpaceNavigator
using a small self written test program. See attachment. So now I can
get proper values for X/Y/Z translation and rotation as well as button
events. All on MacOS X. Fine. Now get this into OpenSCAD!

I tried to hack class QGLView as it handles mouse events. But getting
data from the SpaceNavigator requires a separate thread and Qt complained:
Cannot make QOpenGLContext current in a different thread

I have no clue about the OpenSCAD source code layout, its dependency
management, (3D) computer graphics nor Qt. So I need a bit of help to
get started with hacking OpenSCAD. As said, I am fluent in C++. So the
basics are covered. Mostly I need to know where to start digging, what
source code files to read, what classes to investigate, where are
similar things done as an example and the like.

Things that need to be done / I need help with:

  • Integrate HIDAPI into OpenSCAD.
  • At process startup of OpenSCAD I need to hook into a periodic timer
    for polling the USB HID or (preferably) I need to spawn a separate
    std::thread to read USB HID reports.
  • If there is a USB HID report determine if OpenSCAD is in focus and
    which window is topmost. Send translate / rotate message to window.
  • Handle translate / rotate message from USB HID thread in the window.

Any help appreciated and thanks for your patience.

tschüß,
Jochen

Hi. Recently I bought a 3Dconnexion SpaceNavigator to use with OpenSCAD. I know that this gadget is currently not supported by OpenSCAD. But being a hacker fluent in C and C++, I thought it would be a nice project to add support for it myself. 3Dconnexion offers a SDK for there devices, but the SDK is poisoned by a ridiculous restrictive license. The SDK is impossible to use with Open Source Software. Fortunately the SpaceNavigator enumerates as an ordinary USB HID. I had a look into libusb and the documentation here: http://libusb.org/wiki/APIs#libusb-1.0currentAPIandimplementation redirected me to HIDAPI: http://www.signal11.us/oss/hidapi/ This is a small library with support for Mac OS X, Linux, Windows and FreeBSD. It is a single .h file and a single .c file per platform. With the help of HIDAPI I got reasonable output from the SpaceNavigator using a small self written test program. See attachment. So now I can get proper values for X/Y/Z translation and rotation as well as button events. All on MacOS X. Fine. Now get this into OpenSCAD! I tried to hack class QGLView as it handles mouse events. But getting data from the SpaceNavigator requires a separate thread and Qt complained: Cannot make QOpenGLContext current in a different thread I have no clue about the OpenSCAD source code layout, its dependency management, (3D) computer graphics nor Qt. So I need a bit of help to get started with hacking OpenSCAD. As said, I am fluent in C++. So the basics are covered. Mostly I need to know where to start digging, what source code files to read, what classes to investigate, where are similar things done as an example and the like. Things that need to be done / I need help with: - Integrate HIDAPI into OpenSCAD. - At process startup of OpenSCAD I need to hook into a periodic timer for polling the USB HID or (preferably) I need to spawn a separate std::thread to read USB HID reports. - If there is a USB HID report determine if OpenSCAD is in focus and which window is topmost. Send translate / rotate message to window. - Handle translate / rotate message from USB HID thread in the window. Any help appreciated and thanks for your patience. -- tschüß, Jochen
RK
Roland Koebler
Tue, Jun 30, 2015 10:36 PM

Hi,

I've used libusb myself and also wrote a (user-space) mouse driver (for
a touchscreen) for Linux.

I think you don't need to write a SpaceNavigator libusb-hid-driver.
At least for Linux, several usb-hid-drivers for the SpaceNavigator
exist (e.g.: http://janoc.rd-h.com/archives/74). I think there
should also be some for Mac OS X.

And I don't think that OpenSCAD should include hardware-specific
code. Instead, the SpaceNavigator should behave like a normal (extended)
mouse or joystick. The operating-system and window-manager should
handle the USB-polling, determine the current window and send
mouse-events to this window. At least that's how I think it should
be done.

You can also google for SpaceNavigator and FreeCAD -- it looks like
someone has already done something similar to implement SpaceNavigator-
support in FreeCAD (which also uses Qt AFAIK).

just my 2 ct,
Roland

Hi, I've used libusb myself and also wrote a (user-space) mouse driver (for a touchscreen) for Linux. I think you don't need to write a SpaceNavigator libusb-hid-driver. At least for Linux, several usb-hid-drivers for the SpaceNavigator exist (e.g.: http://janoc.rd-h.com/archives/74). I think there should also be some for Mac OS X. And I don't think that OpenSCAD should include hardware-specific code. Instead, the SpaceNavigator should behave like a normal (extended) mouse or joystick. The operating-system and window-manager should handle the USB-polling, determine the current window and send mouse-events to this window. At least that's how I think it should be done. You can also google for SpaceNavigator and FreeCAD -- it looks like someone has already done something similar to implement SpaceNavigator- support in FreeCAD (which also uses Qt AFAIK). just my 2 ct, Roland
JK
Jochen Kunz
Mon, Jul 6, 2015 9:52 PM

Am 1.07.15 um 23:06 schrieb Roland:

I think you don't need to write a SpaceNavigator libusb-hid-driver.
At least for Linux, several usb-hid-drivers for the SpaceNavigator
exist (e.g.: http://janoc.rd-h.com/archives/74). I think there
should also be some for Mac OS X.

I had a look into this before I started. Unfortunately none of this is
really usable. Linux only, X11 only, outdated, can not coexist with the
3Dconnexion drivers, unacceptable license, ...

A direct USB interface with HIDAPI can coexist with the 3Dconnexion
drivers and is platform independent. But it probably has to deal with
differences among devices. Also note that the code to interpret the HID
reports from the SpaceNavigator is trivial. (See my demo code.)

And I don't think that OpenSCAD should include hardware-specific
code. Instead, the SpaceNavigator should behave like a normal
(extended) mouse or joystick. The operating-system and
window-manager should handle the USB-polling, determine the
current window and send mouse-events to this window. At least
that's how I think it should be done.

Agreed. Unfortunately Qt doesn't know anything about 6dof devices. There
is no generic support infrastructure like for 2D rodents.
http://www.codegardening.com/2011/02/using-3dconnexion-mouse-with-qt.html
"Qt has no corresponding Qt events for the 3D mouse"

As far as I read X11 has some generic multi-axis support, but not
Windows nor MacOS.

You can also google for SpaceNavigator and FreeCAD -- it looks like
someone has already done something similar to implement
SpaceNavigator-support in FreeCAD (which also uses Qt AFAIK).

I know. According to my research FreeCAD does it "by hand" too. It uses
different interfaces depending on platform:
http://lists.qt-project.org/pipermail/interest/2015-April/016309.html
says: "Freecad can use either proprietary SDK (Windows and Mac) or
libspnav (X11)"
and does its own event processing.

tschüß,
Jochen

Am 1.07.15 um 23:06 schrieb Roland: > I think you don't need to write a SpaceNavigator libusb-hid-driver. > At least for Linux, several usb-hid-drivers for the SpaceNavigator > exist (e.g.: http://janoc.rd-h.com/archives/74). I think there > should also be some for Mac OS X. I had a look into this before I started. Unfortunately none of this is really usable. Linux only, X11 only, outdated, can not coexist with the 3Dconnexion drivers, unacceptable license, ... A direct USB interface with HIDAPI can coexist with the 3Dconnexion drivers and is platform independent. But it probably has to deal with differences among devices. Also note that the code to interpret the HID reports from the SpaceNavigator is trivial. (See my demo code.) > And I don't think that OpenSCAD should include hardware-specific > code. Instead, the SpaceNavigator should behave like a normal > (extended) mouse or joystick. The operating-system and > window-manager should handle the USB-polling, determine the > current window and send mouse-events to this window. At least > that's how I think it should be done. Agreed. Unfortunately Qt doesn't know anything about 6dof devices. There is no generic support infrastructure like for 2D rodents. http://www.codegardening.com/2011/02/using-3dconnexion-mouse-with-qt.html "Qt has no corresponding Qt events for the 3D mouse" As far as I read X11 has some generic multi-axis support, but not Windows nor MacOS. > You can also google for SpaceNavigator and FreeCAD -- it looks like > someone has already done something similar to implement > SpaceNavigator-support in FreeCAD (which also uses Qt AFAIK). I know. According to my research FreeCAD does it "by hand" too. It uses different interfaces depending on platform: http://lists.qt-project.org/pipermail/interest/2015-April/016309.html says: "Freecad can use either proprietary SDK (Windows and Mac) or libspnav (X11)" and does its own event processing. -- tschüß, Jochen