/* This script is supplied with the Mand2000 demo and release */
/* versions and may be freely distributed. */
/* Copyright 1993 Cygnus Software. */

/* An ARexx programming for rendering a series of pictures. */

portname = address()	/* Retrieve the current port name. */
/* If the portname does not start with MAND2000 then this script must */
/* have been run with rx, rather than from Mand2000.  Therefore we */
/* need to set the port name.  We do not always set the port name */
/* because it is better to let Mand2000 set it for us, so that */
/* this script can be used with windows other than the one with */
/* port name MAND2000.1. */
if (left(portname, 8) ~= "MAND2000") THEN
	address 'MAND2000.1'

options results

/* Set up these variables with the number of pictures that you want */
/* calculated and the names of all of the file names.  They will be */
/* loaded in one at a time and saved when they are finished calculating. */
/* This is typically used if you have a series of pictures which will */
/* all take a long time to calculate. */
frames.count = 10
frames.0 = '"ram:frame1"'
frames.1 = '"ram:frame2"'
frames.2 = '"ram:frame3"'
frames.3 = '"ram:frame4"'
frames.4 = '"ram:frame5"'
frames.5 = '"ram:frame6"'
frames.6 = '"ram:frame7"'
frames.7 = '"ram:frame8"'
frames.8 = '"ram:frame9"'
frames.9 = '"ram:frame10"'

/* Parse out the command option.  This script is called when the */
/* user wants a sequence started, when the user wants a sequence */
/* finished and whenever one of the pictures in the sequence is done.  */

parse arg command

command = upper(command)	/* Make sure the command is in upper case. */

if (command = START) then
	CALL StartCalcSequence()
else if (command = STOP) then
	CALL StopCalcSequence()
else
	CALL ContinueCalcSequence(SAVE)

Exit



/* Load the first picture and set up everything so that the script */
/* will continue. */

StartCalcSequence:
	CALL SETCLIP("Mand2000SequenceNum", 0)

	/* Put a command in the user menu for stopping the sequence creation. */
	menu '"------------------------"'
	menu '"Stop Sequence"' calcsequence stop

	/* Tell Mand2000 to reinvoke this script whenever a picture */
	/* finishes calculating. */
	EVENTACTION PICTUREDONE calcsequence
	OPEN filename frames.0
	if (RC ~= 0) THEN DO
		CALL StopCalcSequence()
		REQUESTNOTIFY "Couldn't load first file.  This|script must be modified to render|your pictures by putting their|names in the script, or else save|the frames to be rendered as|ram:frame1, ram:frame2, etc."
		EXIT
		END
	GETATTR application stem PROJ
	if (PROJ.DONE = 1) THEN
		CALL ContinueCalcSequence(NOSAVE)
	RETURN 0



StopCalcSequence:
	CALL SETCLIP("Mand2000SequenceNum")
	/* Tell Mand2000 to stop invoking this script whenever a picture */
	/* finishes calculating. */
	EVENTACTION PICTUREDONE
	/* Remove the `Stop Sequence' menu. */
	CLEARNMENUS 2
	RETURN 0



/*
	This portion of the script saves the current picture if necessary
and then loads the next one if there is one.
	*/

ContinueCalcSequence:
	parse arg savemode
	if (savemode = save) THEN DO
		SAVE
		if (RC ~= 0) THEN DO
			REQUESTNOTIFY "Error in saving file.|Aborting sequence."
			CALL StopCalcSequence()
			EXIT
			END
		END
	SequenceNum = GETCLIP("Mand2000SequenceNum")
	SequenceNum = SequenceNum + 1
	CALL SETCLIP("Mand2000SequenceNum", SequenceNum)
	if (SequenceNum >= frames.count) THEN DO
		CALL StopCalcSequence()
		EXIT
		END
	OPEN filename frames.SequenceNum
	GETATTR application stem PROJ
	if (PROJ.DONE = 1) THEN
		CALL ContinueCalcSequence(NOSAVE)
	RETURN 0
