[comp.sys.sgi] Saving a file with a dialog box

elkins@topaz.rutgers.edu (George Elkins) (02/05/90)

I have written a small program to rotate 3D graphical objects with the
mouse and I would like to save a rotation matrix into a file with a
menu option.  My (possibly naive) question is how do I get the program
to prompt and read the file name from the user?  Should I use a wsh
window for text I/O?  What then happens if the application was not
launched from a wsh window in the first place?

What I would really like to do is the equivalent of the Macintosh
routine SFPutFile, but on a Silicon Graphics Iris 4D/120 GTX.  For
example, in saving a file on the Macintosh, you would do something
like this:

SFPutFile(SFPutPoint, 'Save File as ...', title, NIL, theReply);

where a standard dialog box asking for a file name to save a file into
appears.  The user can type a file name or cancel (e.g. IF
theReply.good THEN ...).  The filename would be returned in
theReply.fname.

How does one create such a dialog box with buttons and a text field in
4Sight using the GL/DGL interface?

George Elkins

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS294 x42854") (02/05/90)

   The way I do things like that is to "winpush" the application back,
open a null window using "noport", then close the window.  The window
you executed the program from will now be ready for input, just do
standard keyboard i/o.  I have to do this on our 3130, I don't know
if all this is necessary on a 4D or not.  We have a 4D/240 for evaluation
and the programs I have ported there use this technique.
--

	Brent L. Bates
	NASA-Langley Research Center
	M.S. 294
	Hampton, Virginia  23665-5225
	(804) 864-2854
	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov

" ratcliffe) (02/05/90)

In article <Feb.4.15.19.22.1990.11760@topaz.rutgers.edu> elkins@topaz.rutgers.edu (George Elkins) writes:

  ...stuff about a Mac dialog box programming call...

>How does one create such a dialog box with buttons and a text field in
>4Sight using the GL/DGL interface?

not sure this will really give you all you want, (no "buttons" in this
implementation--just a carriage return to signal "i'm done") but IF you 
have 3.2, run /usr/sbin/snapshot and check out the way i programmed the 
little "textport" window that comes up when you specify via the mouse 
that you wish to change the filename you want to save yer image out to.  
(see ~4Dgifts/iristools/imgtools/snapshot.c for the source).
a more rudimentary version of this "textport" derives from 
~4Dgifts/examples/grafix/prompt.c which has a main that simply invokes 
the psuedo-textport routine.
--

                                             daveus rattus   

                                   yer friendly neighborhood ratman

                              KOYAANISQATSI

   ko.yan.nis.qatsi (from the Hopi Language)  n.  1. crazy life.  2. life
     in turmoil.  3. life out of balnace.  4. life disintegrating.  
     5. a state of life that calls for another way of living.

gavin@krypton.sgi.com (Gavin A. Bell) (02/06/90)

>In article <Feb.4.15.19.22.1990.11760@topaz.rutgers.edu> elkins@topaz.rutgers.edu (George Elkins) writes:
>>How does one create such a dialog box with buttons and a text field in
>>4Sight using the GL/DGL interface?

Well, I thought up this little hack just two or three weeks ago, so I
can't guarantee that it is perfect yet.

However, it is a very good starting point.  Let me give you the code,
then explain what exactly it is doing:

---------   code follows  --------
/*
 * s      is the string the user's response will be put into
 * len_s  is the length of s (so we won't overflow it)
 * m      is the message prompt
 */
void
GetInputFromUser(char *s, int len_s, const char *m)
{
	char launchline[300];
	FILE *fp;

	sprintf(launchline, "launch -h echo -m \"%s\"", m);
	if ((fp = popen(launchline, "r")) != NULL)
	{
		fgets(s, len_s, fp);
		pclose(fp);
		/* Strip off trailing newline */
		if (s[0] != '\0' && s[strlen(s)-1] == '\n')
		{
			s[strlen(s)-1] = '\0';
		}
	}
	else s[0] = '\0';
}
----------- end of code ----------

This code uses the 'launch' command to do all of the dirty work.  It
launches an 'echo' command, which will just echo back whatever the
user types, which is sent back to the program through the magic of
popen().

Good things about this code:
	It is short and easy.
	The launch command allows you to edit the field in lots of ways,
		including using Copy/Paste and the mouse.

Bad things about this code:
	The program will ignore all events while the prompter is up; if
		the user moves either window, an ugly display is likely to
		result.
	This won't work unless the user is on the graphics console (an OK
		assumption if this is a graphics program that requires
		mouse/keyboard input).
	This won't work with the Distributed Graphics Library.

The 'launch' command is in version 3.2 of the OS; I don't know if it
was around before then.

You might also want to check out the 'confirm' and 'inform'
commands...

--gavin