Using with Tcl/Tk

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
andyc
Posts: 8
Joined: Mon Mar 19, 2007 9:08 am

Using with Tcl/Tk

Post by andyc »

Has anyone got a device going with Tcl/Tk? I've spent many days trying to get it working properly and have come to the conclusion that because Windows Tcl/Tk is also waiting on GetMessage, it's probably impossible to write an event loop that works correctly.

I have tried using the tcl event source system but it's not smooth.

I can make this work on a busy loop but I think our customers would probably complain :)

I'd be pleased to post my code if anyone thinks they could help.

One solution is to modify the event code in Tcl/Tk but this is a pain since we have to support three platforms.

Is it possible to read from a device without using GetMessage? Tcl can wait on sockets and file handles just fine.

thanks for any help!

Andy
ngomes
Moderator
Moderator
Posts: 3321
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

This is interesting. Does Tcl/Tk have support for multiple threading? If yes, try putting all your 3DxInput code on a separate thread and use a thread-safe mechanism to route the data back to the main thread.
Nuno Gomes
andyc
Posts: 8
Joined: Mon Mar 19, 2007 9:08 am

Post by andyc »

Tcl/TK will support multiple threading but it would make the implementation of this very messy. Tcl/TK waits on GetMessage so you need to wedge in there (using the standard Tcl/Tk notification and event sources is useless in this case).

We have solved the problem like this - I hope this is useful to someone. (this is for Windows Tcl/Tk only)

Code: Select all

WNDPROC	oldWndProc; // old WindowProc function

// the new hook function that's wedged into the window event handler
LRESULT CALLBACK HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	check_for_space_mouse_event(msg, wp, lp); // see if it's a space mouse event

	LRESULT lr = CallWindowProc(oldWndProc, hwnd, msg, wp, lp); // call the old event handler
	return(lr);
}

	if (space_mouse_init())
		{
		Tk_Window tkwin = Tk_NameToWindow(interp, ".", Tk_MainWindow(interp));
		Window win = Tk_WindowId(tkwin);
		HWND hwnd = Tk_GetHWND(win);
		
		// set the hook proc and record the old
		oldWndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)HookWndProc);
		}

This will be in our software soon. If you would like to test it before release please contact me - see www.inivis.com for more details on AC3D (3D modelling software)

Andy
ngomes
Moderator
Moderator
Posts: 3321
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

Hi andyc,
From the code, it seems that you're not using 3DxInput but our previous API. Is that correct? Are you the "Si" functions (SiOpen, SiClose, etc)?

It's fully supported, of course. So, the choice is really yours.
andyc
Posts: 8
Joined: Mon Mar 19, 2007 9:08 am

Post by andyc »

Yes - it's using the Si stuff.

space_mouse_init() does all the initialization and check_for_space_mouse_event() uses SiGetEvent etc.
ngomes
Moderator
Moderator
Posts: 3321
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

An alternative to sub-classing the main window -- and since you cannot add an handler for the the registered message "SpaceWareMessage00" -- is to create an hidden window and do all your "Si" processing from there.

It will avoid messing up with the message loop of the main window.
Post Reply