Standard views (front, top, etc.) work from buttons on SpaceExplorer and SpacePilotPr...
authorMike Erwin <significant.bit@gmail.com>
Thu, 16 Jun 2011 19:45:38 +0000 (19:45 +0000)
committerMike Erwin <significant.bit@gmail.com>
Thu, 16 Jun 2011 19:45:38 +0000 (19:45 +0000)
intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_NDOFManagerX11.cpp
source/blender/editors/space_view3d/view3d_ops.c
source/blender/windowmanager/wm_event_types.h

index 20baa6f725e138e8c35eab1e8a91d1066c3da637..5c2ca658fdb86d48ddd105aabb43041eca7ff9e9 100644 (file)
@@ -97,7 +97,7 @@ static const NDOF_ButtonT SpaceExplorer_HID_map[] =
        NDOF_BUTTON_ROTATE
        };
 
-static const NDOF_ButtonT SpacePilot_HID_map[] =
+static const NDOF_ButtonT SpacePilotPro_HID_map[] =
        {
        NDOF_BUTTON_MENU,
        NDOF_BUTTON_FIT,
@@ -134,7 +134,7 @@ static const NDOF_ButtonT SpacePilot_HID_map[] =
 
 GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
        : m_system(sys)
-       , m_deviceType(SpacePilot) // set it manually, until device detection code is in place
+       , m_deviceType(NDOF_UnknownDevice) // each platform needs its own device detection code
        , m_buttons(0)
        , m_motionTime(1000) // one full second (operators should filter out such large time deltas)
        , m_prevMotionTime(0)
@@ -197,10 +197,10 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64
 
        switch (m_deviceType)
                {
-               case SpaceNavigator:
+               case NDOF_SpaceNavigator:
                        sendButtonEvent(SpaceNavigator_HID_map[button_number], press, time, window);
                        break;
-               case SpaceExplorer:
+               case NDOF_SpaceExplorer:
                        switch (button_number)
                                {
                                case 6: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
@@ -210,16 +210,18 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64
                                default: sendButtonEvent(SpaceExplorer_HID_map[button_number], press, time, window);
                                }
                        break;
-               case SpacePilot:
+               case NDOF_SpacePilotPro:
                        switch (button_number)
                                {
                                case 22: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
                                case 23: sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window); break;
                                case 24: sendKeyEvent(GHOST_kKeyLeftShift, press, time, window); break;
                                case 25: sendKeyEvent(GHOST_kKeyLeftControl, press, time, window); break;
-                               default: sendButtonEvent(SpacePilot_HID_map[button_number], press, time, window);
+                               default: sendButtonEvent(SpacePilotPro_HID_map[button_number], press, time, window);
                                }
                        break;
+               case NDOF_UnknownDevice:
+                       printf("button %d on unknown device (not sent)\n", button_number);
                }
 
        int mask = 1 << button_number;
index ab27fc32f84e9e0a13e06dc880d9de7fb5af46f0..564b0f6f2393af16bc01394bf31079f74e027f35 100644 (file)
@@ -32,7 +32,7 @@
 // #define DEBUG_NDOF_MOTION
 #define DEBUG_NDOF_BUTTONS
 
-typedef enum { SpaceNavigator, SpaceExplorer, SpacePilot } NDOF_DeviceT;
+typedef enum { NDOF_UnknownDevice, NDOF_SpaceNavigator, NDOF_SpaceExplorer, NDOF_SpacePilotPro } NDOF_DeviceT;
 
 // NDOF device button event types
 typedef enum {
index 99ee29d8a174c0af817b0f3f2b9e9f9699484202..49372e8502d9ff5a6e2853251f89d07412d1e68a 100644 (file)
@@ -33,6 +33,34 @@ GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
        if (spnav_open() != -1)
                {
                m_available = true;
+
+               // determine exactly which device is plugged in
+
+               #define MAX_LINE_LENGTH 100
+
+               // look for USB devices with Logitech's vendor ID
+               FILE* command_output = popen("lsusb -d 046d:","r");
+               if (command_output)
+                       {
+                       char line[MAX_LINE_LENGTH] = {0};
+                       while (fgets(line, MAX_LINE_LENGTH, command_output))
+                               {
+                               unsigned short vendor_id = 0, product_id = 0;
+                               if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2)
+                                       {
+                                       // the following code will live in the base class
+                                       // once all platforms have device detection
+                                       switch (product_id)
+                                               {
+                                               case 0xc626: m_deviceType = NDOF_SpaceNavigator; break;
+                                               case 0xc627: m_deviceType = NDOF_SpaceExplorer; break;
+                                               case 0xc629: m_deviceType = NDOF_SpacePilotPro; break;
+                                               default: printf("unknown product ID: %04x\n", product_id);
+                                               }
+                                       }
+                               }
+                       pclose(command_output);
+                       }
                }
        else
                {
index 3e99c6992d1e1e6c38a5108f940e2cf7cef7ac73..2dd560a6408297300babd5a033d7be0da182001c 100644 (file)
@@ -163,8 +163,14 @@ void view3d_keymap(wmKeyConfig *keyconf)
        RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1);
 
        /* 3D mouse */
-       WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON1, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW3D_OT_ndof", NDOF_MOTION, 0, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_LEFT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_LEFT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BOTTOM, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
 
        /* numpad view hotkeys*/
        RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
index 748f5018e1aad2c99da17806f1752872e4370c5d..ed500ccd5c5a7b598d8ac10edf83dc338d612ab2 100644 (file)
 #define INBETWEEN_MOUSEMOVE    17
 
 /* NDOF (from SpaceNavigator & friends) */
-#define NDOF_MOTION 0x12
+#define NDOF_MOTION 0x12 // keep in sync with GHOST_NDOFManager.h
 enum {
-       NDOF_BUTTON_NONE = NDOF_MOTION, /* never sent, used internally */
-       NDOF_BUTTON1,
-       NDOF_BUTTON2/*, the following buttons will be supported soon...
-       NDOF_BUTTON3,   and possibly get meaningful names
-       NDOF_BUTTON4,
-       NDOF_BUTTON5,
-       NDOF_BUTTON6,
-       NDOF_BUTTON7,
-       NDOF_BUTTON8,
-       NDOF_BUTTON9,
-       NDOF_BUTTON10,
-       NDOF_BUTTON11,
-       NDOF_BUTTON12,
-       NDOF_BUTTON13,
-       NDOF_BUTTON14,
-       NDOF_BUTTON15,
-       NDOF_BUTTON16*/
+       // used internally, never sent
+       NDOF_BUTTON_NONE = NDOF_MOTION,
+       // these two are available from any 3Dconnexion device
+       NDOF_BUTTON_MENU,
+       NDOF_BUTTON_FIT,
+       // standard views
+       NDOF_BUTTON_TOP,
+       NDOF_BUTTON_BOTTOM,
+       NDOF_BUTTON_LEFT,
+       NDOF_BUTTON_RIGHT,
+       NDOF_BUTTON_FRONT,
+       NDOF_BUTTON_BACK,
+       // more views
+       NDOF_BUTTON_ISO1,
+       NDOF_BUTTON_ISO2,
+       // 90 degree rotations
+       NDOF_BUTTON_ROLL_CW,
+       NDOF_BUTTON_ROLL_CCW,
+       NDOF_BUTTON_SPIN_CW,
+       NDOF_BUTTON_SPIN_CCW,
+       NDOF_BUTTON_TILT_CW,
+       NDOF_BUTTON_TILT_CCW,
+       // device control
+       NDOF_BUTTON_ROTATE,
+       NDOF_BUTTON_PANZOOM,
+       NDOF_BUTTON_DOMINANT,
+       NDOF_BUTTON_PLUS,
+       NDOF_BUTTON_MINUS,
+       // general-purpose buttons
+       NDOF_BUTTON_1,
+       NDOF_BUTTON_2,
+       NDOF_BUTTON_3,
+       NDOF_BUTTON_4,
+       NDOF_BUTTON_5,
+       NDOF_BUTTON_6,
+       NDOF_BUTTON_7,
+       NDOF_BUTTON_8,
+       NDOF_BUTTON_9,
+       NDOF_BUTTON_10,
        };