/* CMD: ½CalcRoll                                                       */
/* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
	MacrosName = "CalcRoll"
/* Macro Type:                                                          */
/* CALCULATES  * MOTIONS   * LOOPS        * REMEMBERS                   */
/* Description:                                                         */

Info1A = "!Calculate Roll ©              Information 1 of 2"
Info1B = ""
Info1C = "@This macro calculates Dist. Rad. and Rotations. "
Info1D = "@Given two of three, the third can and will be   "
Info1E = "@calculated and the menu will return. This macro "
Info1F = "@was meant for calc. the amount of tire spin.    "
Info1G = ""
Info1H = "ş If DISTANCE is wanted, supply a RADIUS in the "
Info1I = "  form of MTRS., FEET, or INCHES; and a ROTATION"
Info1J = "  in the form of DEGREES, ROTATIONS, or RADIANS."
Info1K = "ş If RADIUS is wanted, supply a DISTANCE and    "
Info1L = "  ROTATION.(NOTE: A tire's avg. radius is 1 ft.)"
Info1M = "ş If ROTATION is wanted supply a DISTANCE and   "
Info1N = "  RADIUS.                                       "

Info2A = "!Calculate Roll ©              Information 2 of 2"
Info2B = "@               Plug-Ins and Go! ©               "
Info2C = "                           Hester and associates"
Info2D = "                           13032 Copenhill Road "
Info2E = "                           Dallas, Texas 75240  "
Info2F = "@Special Thanks to:                              "
Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
Info2K = ""
Info2L = "@This macro represents a lot of time & hard work."
Info2M = "@Encourage people to create new ones and not kill"
Info2N = "@that possibility by stealing those that are out."

/* -------------------------------------------------------------------- */
                                     /* Start Error Detection (See End) */
SIGNAL ON ERROR
SIGNAL ON SYNTAX
                                                   /* Address LightWave */
VT3DLib = ADDLIB("LWModelerARexx.port",0)
ADDRESS "LWModelerARexx.port"

/* -------------------------------------------------------------------- */
                                         /* Reading Macro Settings File */
BEHDefaultFilePath = "Sys:"
BEHSettingsSavedTo = "T:"
BEHSpeechAndSound = "1"

IF (EXISTS("S:PlugInPrefs")) THEN DO
	IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
	IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
	BEHDefaultFilePath = READLN(PlugInPrefs)
	BEHSettingsSavedTo = READLN(PlugInPrefs)
	BEHSpeechAndSound = READLN(PlugInPrefs)
	CALL CLOSE PlugInPrefs
END

/* -------------------------------------------------------------------- */
                                                              /* Recall */
ReqDisML = 0 ; ReqDisKM = 0 ; ReqDisFT = 0
ReqDisType = 2
ReqRadMT = 0.3048 ; ReqRadFT = 1 ; ReqRadIN = 12
ReqRadType = 3
ReqRotDG = 0 ; ReqRotRT = 0 ; ReqRotRD = 0
ReqRotType = 1
ReqWanted = 3

PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"

IF (EXISTS(PrefsFileName)) THEN DO
	IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
	IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK

	PARSE VALUE READLN(PrefsFile) WITH ReqDisML ReqDisKM ReqDisFT
	ReqDisType = READLN(PrefsFile)
	PARSE VALUE READLN(PrefsFile) WITH ReqRadMT ReqRadFT ReqRadIN
	ReqRadType = READLN(PrefsFile)
	PARSE VALUE READLN(PrefsFile) WITH ReqRotDG ReqRotRT ReqRotRD
	ReqRotType = READLN(PrefsFile)
	ReqWanted = READLN(PrefsFile)

	CALL CLOSE PrefsFile
END

/* -------------------------------------------------------------------- */
                                                   /* Setting Variables */
PI = 3.141592653589793238462643
DegToRad = PI/180 /* 0.0174... */
RadToDeg = 180/PI /* 57.295... */

/* ******************************************************************** */
                                                   /* Main Body of Code */
DO FOREVER
	CALL MenuRequester
	CALL Calculations
	CALL SaveSettings
END

/* ******************************************************************** */
                                                      /* User Interface */
MenuRequester:

	CALL Req_Begin("Calculate Roll ©    by Brett Hester")
	CALL Req_AddControl("ş",'T',"Distance ----------------------- ş")
	ReqA = Req_AddControl("¤",'V',0)
	ReqB = Req_AddControl("¤",'CH',"  Miles   Kilometer    Feet  ")
	CALL Req_AddControl("ş",'T',"Radius ------------------------- ş")
	ReqC = Req_AddControl("¤",'V',0)
	ReqD = Req_AddControl("¤",'CH'," Meters     Feet     Inches  ")
	CALL Req_AddControl("ş",'T',"Rotations ---------------------- ş")
	ReqE = Req_AddControl("¤",'V','0')
	ReqF = Req_AddControl("¤",'CH'," Degrees  Rotations  Radians ")
	CALL Req_AddControl("ş",'T',"Calculate ---------------------- ş")
	ReqG = Req_AddControl("¤",'CH',"Distance   Radius   Rotations")
	CALL Req_AddControl("¤",'T',"")
	BEHInfo = Req_AddControl("ş",'CH',"Information")

	CALL Req_SetVal(ReqA, ReqDisML ReqDisKM ReqDisFT)
	CALL Req_SetVal(ReqB, ReqDisType)
	CALL Req_SetVal(ReqC, ReqRadMT ReqRadFT ReqRadIN)
	CALL Req_SetVal(ReqD, ReqRadType)
	CALL Req_SetVal(ReqE, ReqRotDG ReqRotRT ReqRotRD)
	CALL Req_SetVal(ReqF, ReqRotType)
	CALL Req_SetVal(ReqG, ReqWanted)
	CALL Req_SetVal(BEHInfo, 0)

	IF Req_Post() = 0 THEN CALL Exiting

	PARSE VALUE Req_GetVal(ReqA) WITH ReqDisML ReqDisKM ReqDisFT
	ReqDisType = Req_GetVal(ReqB)
	PARSE VALUE Req_GetVal(ReqC) WITH ReqRadMT ReqRadFT ReqRadIN
	ReqRadType = Req_GetVal(ReqD)
	PARSE VALUE Req_GetVal(ReqE) WITH ReqRotDG ReqRotRT ReqRotRD
	ReqRotType = Req_GetVal(ReqF)
	ReqWanted = Req_GetVal(ReqG)
	BEHInfo = Req_GetVal(BEHInfo)

	CALL Req_End()

	IF BEHInfo = 1 THEN CALL InformationWindows

RETURN

/* -------------------------------------------------------------------- */

Calculations:
                                                /* Converting Distances */
	IF ReqDisType = 1 THEN DO
		ReqDis = ReqDisML
		ReqDisML = ReqDis
		ReqDisKM = ReqDis * 1.6093445
		ReqDisFT = ReqDis * 5280
	END
	IF ReqDisType = 2 THEN DO
		ReqDis = ReqDisKM
		ReqDisML = ReqDis * 0.621371
		ReqDisKM = ReqDis
		ReqDisFT = ReqDis * 3280.839895
	END
	IF ReqDisType = 3 THEN DO
		ReqDis = ReqDisFT
		ReqDisML = ReqDis * (1 / 5280)
		ReqDisKM = ReqDis * (1 / 3280.839895)
		ReqDisFT = ReqDis
	END
                                                    /* Converting Radii */
	IF ReqRadType = 1 THEN DO
		ReqRad = ReqRadMT
		ReqRadMT = ReqRad
		ReqRadFT = ReqRad * 3.28084
		ReqRadIN = ReqRad * 39.370079
	END
	IF ReqRadType = 2 THEN DO
		ReqRad = ReqRadFT
		ReqRadMT = ReqRad * 0.3048
		ReqRadFT = ReqRad
		ReqRadIN = ReqRad * 12
	END
	IF ReqRadType = 3 THEN DO
		ReqRad = ReqRadIN
		ReqRadMT = ReqRad * 0.0254
		ReqRadFT = ReqRad * (1 / 12)
		ReqRadIN = ReqRad
	END
                                                /* Converting Rotations */
	IF ReqRotType = 1 THEN DO
		ReqRot = ReqRotDG
		ReqRotDG = ReqRot
		ReqRotRT = ReqRot * (1 / 360)
		ReqRotRD = ReqRot * DegToRad
	END
	IF ReqRotType = 2 THEN DO
		ReqRot = ReqRotRT
		ReqRotDG = ReqRot * 360
		ReqRotRT = ReqRot
		ReqRotRD = ReqRot * (2 * PI)
	END
	IF ReqRotType = 3 THEN DO
		ReqRot = ReqRotRD
		ReqRotDG = ReqRot * RadToDeg
		ReqRotRT = ReqRot * (1 / (2 * PI))
		ReqRotRD = ReqRot
	END

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */

	/********************************************/
	/* Note:                                    */
	/*                                          */
	/* Distance = (2 * PI * Radius) * Rotations */
	/*            ^ Circumference ^             */
	/* Radius = Distance / Rotations / 2 / PI   */
	/*                                          */
	/* Rotations = Distance / (2 * PI * Radius) */
	/*                        ^ Circumference ^ */
	/********************************************/

	IF ReqWanted = 1 THEN DO                                 /* Distance */
		ReqDisML = ((2 * PI) * (ReqRadFT * (1 / 5280))) * ReqRotRT
		ReqDisKM = ((2 * PI) * (ReqRadMT * 0.001)) * ReqRotRT
		ReqDisFT = ((2 * PI) * ReqRadFT) * ReqRotRT
	END
	IF ReqWanted = 2 THEN DO                                   /* Radius */
		IF ReqRotRT ~= 0 THEN DO
			ReqRadMT = ((ReqDisKM * 1000) / ReqRotRT) / 2 / PI
			ReqRadFT = (ReqDisFT / ReqRotRT) / 2 / PI
			ReqRadIN = ((ReqDisFT * (12 / 1)) / ReqRotRT) / 2 / PI
		END
		IF ReqRotRT = 0 THEN DO
			ReqRadMT = 0 ; ReqRadFT = 0 ; ReqRadIN = 0
		END
	END
	IF ReqWanted = 3 THEN DO                                /* Rotations */
		IF ReqRadFT ~= 0 THEN DO
			ReqRotRT = ReqDisFT / (2 * PI * ReqRadFT)
			ReqRotDG = ReqRotRT * 360
			ReqRotRD = ReqRotRT * (2 * PI)
		END
		IF ReqRadFT = 0 THEN DO
			ReqRotRT = 0 ; ReqRotDG = 0 ; ReqRotRD = 0
		END
	END

RETURN

/* -------------------------------------------------------------------- */
                                                 /* Information Windows */
InformationWindows:

	OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
	IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
	CALL MenuRequester

RETURN   /* RETURN Not actually required because calling menu requester */

/* -------------------------------------------------------------------- */
                                                              /* Record */
SaveSettings:

	IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
		CALL WRITELN(PrefsFile, MacrosName)

		CALL WRITELN(PrefsFile, ReqDisML ReqDisKM ReqDisFT)
		CALL WRITELN(PrefsFile, ReqDisType)
		CALL WRITELN(PrefsFile, ReqRadMT ReqRadFT ReqRadIN)
		CALL WRITELN(PrefsFile, ReqRadType)
		CALL WRITELN(PrefsFile, ReqRotDG ReqRotRT ReqRotRD)
		CALL WRITELN(PrefsFile, ReqRotType)
		CALL WRITELN(PrefsFile, ReqWanted)

		CALL CLOSE PrefsFile
	END

RETURN

/* -------------------------------------------------------------------- */
                                                              /* Ending */
Exiting:

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT

RETURN

/* -------------------------------------------------------------------- */
                                                      /* Error Handling */
SYNTAX:
ERROR:

	ErrCode = RC
	ErrLine = SIGL
	ErrInfo = ERRORTEXT(ErrCode)

	Err1 = "!Sorry!"
	Err2 = "An Error has been detected"
	Err3 = "@ş Macro -            "
	Err4 = "@ş Line Number -      "
	Err5 = "@ş Error Code -       "
	Err6 = "@ş Error Description -"
	Err7 = "@¤ Please Inform -    "
	Err8 = '  "Error Notice"     '
	Err9 = "  13032 Copenhill Rd."
	Err10 = "  Dallas, TX. 75240  "

	Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)

/* -------------------------------------------------------------------- */
                                             /* Advanced Error Handling */
	CALL SETCLIP("ErrorMacro",MacrosName)
	CALL SETCLIP("ErrorLine",ErrLine)
	CALL SETCLIP("ErrorCode",ErrCode)
	CALL SETCLIP("ErrorDesc",ErrInfo)

	PARSE SOURCE TempA TempB ErrFile TempC TempD TempE

	CALL SETCLIP("ErrorFile",ErrFile)

/* -------------------------------------------------------------------- */

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT
