[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37568] branches/merwin-spacenav: Standard views (front, top, etc.) work from buttons on SpaceExplorer and SpacePilotPro.

Mike Erwin significant.bit at gmail.com
Thu Jun 16 21:45:39 CEST 2011


Revision: 37568
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37568
Author:   merwin
Date:     2011-06-16 19:45:38 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
Standard views (front, top, etc.) work from buttons on SpaceExplorer and SpacePilotPro. Linux can now determine which NDOF device is plugged in.

Modified Paths:
--------------
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp
    branches/merwin-spacenav/source/blender/editors/space_view3d/view3d_ops.c
    branches/merwin-spacenav/source/blender/windowmanager/wm_event_types.h

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-16 19:25:21 UTC (rev 37567)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-16 19:45:38 UTC (rev 37568)
@@ -97,7 +97,7 @@
 	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 @@
 
 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 @@
 
 	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 @@
 				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;

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-16 19:25:21 UTC (rev 37567)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-16 19:45:38 UTC (rev 37568)
@@ -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 {

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp	2011-06-16 19:25:21 UTC (rev 37567)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp	2011-06-16 19:45:38 UTC (rev 37568)
@@ -33,6 +33,34 @@
 	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
 		{

Modified: branches/merwin-spacenav/source/blender/editors/space_view3d/view3d_ops.c
===================================================================
--- branches/merwin-spacenav/source/blender/editors/space_view3d/view3d_ops.c	2011-06-16 19:25:21 UTC (rev 37567)
+++ branches/merwin-spacenav/source/blender/editors/space_view3d/view3d_ops.c	2011-06-16 19:45:38 UTC (rev 37568)
@@ -163,8 +163,14 @@
 	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);

Modified: branches/merwin-spacenav/source/blender/windowmanager/wm_event_types.h
===================================================================
--- branches/merwin-spacenav/source/blender/windowmanager/wm_event_types.h	2011-06-16 19:25:21 UTC (rev 37567)
+++ branches/merwin-spacenav/source/blender/windowmanager/wm_event_types.h	2011-06-16 19:45:38 UTC (rev 37568)
@@ -79,25 +79,47 @@
 #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,
 	};
 
 




More information about the Bf-blender-cvs mailing list