home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LW5VT09.LHA / Toaster / Arexx_examples / PlugIns / Calculator.lwm < prev    next >
Encoding:
Text File  |  1996-06-10  |  12.3 KB  |  335 lines

  1. /* CMD: ½Calculator                                                     */
  2. /* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
  3.     MacrosName = "Calculator"
  4. /* Macro Type:                                                          */
  5. /* CALCULATES                                                           */
  6. /* Description:                                                         */
  7.  
  8. Info1A = "!Calculator ©                  Information 1 of 5"
  9. Info1B = ""
  10. Info1C = "@This macro allows for performing calculations,  "
  11. Info1D = "@even those that involve variables, constants,   "
  12. Info1E = "@and commands.                                   "
  13. Info1F = ""
  14. Info1G = "þ Variables X, Y and Z default to the coords. of"
  15. Info1H = "  selected pnt. or previous calculator settings."
  16. Info1I = ""
  17. Info1J = "þ The output from the last formula is sent to a "
  18. Info1K = '  variable labeled "RESULT".                    '
  19. Info1L = ""
  20. Info1M = "@Information on constants, commands, and usage  "
  21. Info1N = "@are on the following information windows.      "
  22.  
  23. Info2A = "!Calculator ©                  Information 2 of 5"
  24. Info2B = ""
  25. Info2C = "@þ Constants:                                    "
  26. Info2D = '  Type "PI" to get 3.141592653589793238462643   '
  27. Info2E = '  Type "Eunit" for 2.718281828459045235360287   '
  28. Info2F = ""
  29. Info2G = "@¤ Constants for conversion purposes:            "
  30. Info2H = "þ 8 length constants are included, multiply by -"
  31. Info2I = "  MtToFt, MtToIn, KmToMl, KmToFt, & the reverse "
  32. Info2J = "þ 6 speed constants are included, multiply by - "
  33. Info2K = "  KPHToMPH, KPHToFPS, MPHToFPS, and the reverse "
  34. Info2L = "þ 2 angle constants are included, multiply by - "
  35. Info2M = "  DegToRad or RadToDeg                          "
  36. Info2N = "@Information on commands and usage to follow... "
  37.  
  38. Info3A = "!Calculator ©                  Information 3 of 5"
  39. Info3B = ""
  40. Info3C = "@þ Commands:                                     "
  41. Info3D = "  SQRT(x) = Square Root  ABS(x)  = Absolute     "
  42. Info3E = "  FACT(x) = Factorial    NINT(x) = Rounds off   "
  43. Info3F = ""
  44. Info3G = "@¤ Commands involving angle calculations:        "
  45. Info3H = "  SIN(x°)    ASIN(x°)    SINH(x°)    ASINH(x°)  "
  46. Info3I = "  COS(x°)    ACOS(x°)    COSH(x°)    ACOSH(x°)  "
  47. Info3J = "  TAN(x°)    ATAN(x°)    TANH(x°)    ATANH(x°)  "
  48. Info3K = ""
  49. Info3L = "@NOTE: The computer calculates angles in radians."
  50. Info3M = "@If you are suppling the angles in degrees, type "
  51. Info3N = "@ALT-W (°) after the angle. This equals DegToRad."
  52.  
  53. Info4A = "!Calculator ©                  Information 4 of 5"
  54. Info4B = ""
  55. Info4C = "@þ Arithmetic operations and their priority:     "
  56. Info4D = "@Operator           Priority  Example      Result"
  57. Info4E = "+  (prefix conversion) 8     '3.12'       3.12  "
  58. Info4F = '-  (prefix negation)   8     -"3.12"      -3.12 '
  59. Info4G = "** (exponentiation)    7     0.5 ** 3     0.125 "
  60. Info4H = "*  (multiplication)    6     1.5 * 1.50   2.250 "
  61. Info4I = "/  (division)          6     6 / 3        2     "
  62. Info4J = "%  (integer division)  6     -8 % 3       -2    "
  63. Info4K = "// (remainder)         6     5.1 // 0.2   0.1   "
  64. Info4L = "+  (addition)          5     3.1 + 4.05   7.15  "
  65. Info4M = "-  (subtraction)       5     5.55 - 1     4.55  "
  66. Info4N = "@((((( Use Parentheses When Ever Necessary. )))))"
  67.  
  68. Info5A = "!Calculator ©                  Information 5 of 5"
  69. Info5B = "@               Plug-Ins and Go! ©               "
  70. Info5C = "                           Hester and associates"
  71. Info5D = "                           13032 Copenhill Road "
  72. Info5E = "                           Dallas, Texas 75240  "
  73. Info5F = "@Special Thanks to:                              "
  74. Info5G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
  75. Info5H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
  76. Info5I = "Kevin DeRita    Greg Glaser     William S. Hawes"
  77. Info5J = "NewTek ©        Commodore ©     INOVAtronics ©  "
  78. Info5K = ""
  79. Info5L = "@This macro represents a lot of time & hard work."
  80. Info5M = "@Encourage people to create new ones and not kill"
  81. Info5N = "@that possibility by stealing those that are out."
  82.  
  83. /* -------------------------------------------------------------------- */
  84.                                      /* Start Error Detection (See End) */
  85. SIGNAL ON ERROR
  86. SIGNAL ON SYNTAX
  87.                                                    /* Address LightWave */
  88. VT3DLib = ADDLIB("LWModelerARexx.port",0)
  89. ADDRESS "LWModelerARexx.port"
  90.                                                /* Add Support Functions */
  91. SupportLib = "rexxsupport.library"
  92. IF POS(SupportLib , SHOW('L')) = 0 THEN
  93.     IF ~ADDLIB(SupportLib , 0 , -30 , 0) THEN DO
  94.         CALL Notify(1,"!Can't find "SupportLib)
  95.         CALL Exiting
  96.     END
  97.                                                   /* Add Math Functions */
  98. MATHLIB= "rexxmathlib.library"
  99. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  100.     IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  101.         CALL Notify(1,"!Can't find "MATHLIB)
  102.         IF VT3DLib THEN CALL REMLIB("LWModelerARexx.port")
  103.         EXIT
  104.     END
  105.  
  106. /* -------------------------------------------------------------------- */
  107.                                     /* Reading Global Macro Preferences */
  108. BEHDefaultFilePath = "Sys:"
  109. BEHSettingsSavedTo = "T:"
  110. BEHSpeechAndSound = "1"
  111.  
  112. IF (EXISTS("S:PlugInPrefs")) THEN DO
  113.     IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
  114.     IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
  115.     BEHDefaultFilePath = READLN(PlugInPrefs)
  116.     BEHSettingsSavedTo = READLN(PlugInPrefs)
  117.     BEHSpeechAndSound = READLN(PlugInPrefs)
  118.     CALL CLOSE PlugInPrefs
  119. END
  120.  
  121. /* -------------------------------------------------------------------- */
  122.                                             /* Recalling Macro Settings */
  123. ReqFormula = "1 + 2"
  124. ReqResults = "3"
  125. ReqX = "0"
  126. ReqY = "0"
  127. ReqZ = "0"
  128.  
  129. PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
  130.  
  131. IF (EXISTS(PrefsFileName)) THEN DO
  132.     IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
  133.     IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
  134.  
  135.     ReqFormula = READLN(PrefsFile)
  136.     ReqResults = READLN(PrefsFile)
  137.     ReqX = READLN(PrefsFile)
  138.     ReqY = READLN(PrefsFile)
  139.     ReqZ = READLN(PrefsFile)
  140.  
  141.     CALL CLOSE PrefsFile
  142. END
  143.  
  144. /* -------------------------------------------------------------------- */
  145.                                             /* If One Point is selected */
  146. CALL Sel_Mode(USER)
  147.  
  148. NumberOfPnts = XFrm_Begin()
  149.  
  150. IF NumberOfPnts = 1 THEN DO
  151.     PARSE VALUE Xfrm_GetPos(1) WITH ReqX ReqY ReqZ
  152. END
  153.  
  154. CALL End_All()
  155.  
  156. /* -------------------------------------------------------------------- */
  157.                                              /* Setting Fixed Variables */
  158. PI = 3.141592653589793238462643
  159. Eunit = 2.718281828459045235360287
  160.                                                     /* Angle Conversion */
  161. RadToDeg = 180 / PI  ; DegToRad = PI / 180
  162.                                                  /* Distance Conversion */
  163. MtToFt = 3.28084     ; FtToMt = 0.3048
  164. MtToIn = 39.370079   ; InToMt = 0.0254
  165. KmToMl = 0.621371    ; MlToKm = 1.609344
  166. KmToFt = 3280.839895 ; FtToKm = 0.000305
  167.                                                     /* Speed Conversion */
  168. KPHToMPH = 0.621371  ; MPHToKPH = 1.609344
  169. KPHToFPS = 0.911344  ; FPSToKPH = 1.09728
  170. MPHToFPS = 1.466667  ; FPSToMPH = 0.681818
  171.  
  172. /* ******************************************************************** */
  173.                                                    /* Main Body Of Code */
  174. MainBodyOfCode:
  175.  
  176.     DO FOREVER
  177.         CALL MenuRequester
  178.         CALL Calculations
  179.         CALL SaveSettings
  180.     END
  181.  
  182. RETURN
  183.  
  184. /* ******************************************************************** */
  185.                                                       /* User Interface */
  186. MenuRequester:
  187.  
  188.     CALL Req_Begin("Calculator ©                                   by Brett Hester")
  189.  
  190.     ReqA = Req_AddControl("þ Formula:",'S',52)
  191.     CALL Req_AddControl("¤ Result =",'T',ReqResults)
  192.     CALL Req_AddControl("",'T',"")
  193.     ReqC = Req_AddControl("Variable X",'S',20)
  194.     ReqD = Req_AddControl("Variable Y",'S',20)
  195.     ReqE = Req_AddControl("Variable Z",'S',20)
  196.     CALL Req_AddControl("",'T',"")
  197.     ReqF = Req_AddControl("",'CH', "Information")
  198.  
  199.     CALL Req_SetVal(ReqA, ReqFormula)
  200.     CALL Req_SetVal(ReqC, ReqX)
  201.     CALL Req_SetVal(ReqD, ReqY)
  202.     CALL Req_SetVal(ReqE, ReqZ)
  203.     CALL Req_SetVal(ReqF, 0)
  204.  
  205.     IF Req_Post() = 0 THEN CALL Exiting
  206.  
  207.     ReqFormula = Req_GetVal(ReqA)
  208.     ReqX = Req_GetVal(ReqC)
  209.     ReqY = Req_GetVal(ReqD)
  210.     ReqZ = Req_GetVal(ReqE)
  211.     BEHInfo = Req_GetVal(ReqF)
  212.  
  213.     CALL Req_End()
  214.  
  215.     IF BEHInfo = 1 THEN CALL InformationWindows
  216.  
  217. RETURN
  218.  
  219. /* -------------------------------------------------------------------- */
  220.                                                         /* Calculations */
  221. Calculations:
  222.                                               /* User Defined Variables */
  223.     INTERPRET "X = "||ReqX
  224.     INTERPRET "Y = "||ReqY
  225.     INTERPRET "Z = "||ReqZ
  226.                                                 /* Adding NEW Variables */
  227.     Result = ReqResults
  228.     Formula = ReqFormula
  229.                            /* Structuring Formulas with Degree symbols  */
  230.     QAAngle = 1
  231.     DO UNTIL QAAngle = 0
  232.         QAAngle = 0
  233.  
  234.         FormulaLength = LENGTH(Formula)
  235.  
  236.         QAAngle = POS("°", Formula)
  237.         IF QAAngle ~= 0 THEN DO
  238.             PartA = LEFT(Formula, QAAngle - 1)
  239.             PartB = RIGHT(Formula, FormulaLength - QAAngle)
  240.  
  241.             Formula = PartA||" * "||DegToRad||PartB
  242.         END
  243.     END
  244.                                                           /* The RESULT */
  245.     INTERPRET "ReqResults = "||Formula
  246.                                       /* If Formula is in Yes/No Format */
  247.     IF POS("=", Formula) ~= 0 THEN DO
  248.         IF ReqResults = 1 THEN ReqResults = "Correct"
  249.         IF ReqResults = 0 THEN ReqResults = "Incorrect"
  250.     END
  251.                              /* If the Formula is actually an operation */
  252.     IF ReqResults = "CALL 1" THEN ReqResults = "The above operation returned a positive response."
  253.     IF ReqResults = "CALL 0" THEN ReqResults = "The above operation returned a negative response."
  254.  
  255. RETURN
  256.  
  257. /* -------------------------------------------------------------------- */
  258.                                             /* Recording Macro Settings */
  259. SaveSettings:
  260.  
  261.     IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
  262.         CALL WRITELN(PrefsFile, MacrosName)
  263.  
  264.         CALL WRITELN(PrefsFile, ReqFormula)
  265.         CALL WRITELN(PrefsFile, ReqResults)
  266.         CALL WRITELN(PrefsFile, ReqX)
  267.         CALL WRITELN(PrefsFile, ReqY)
  268.         CALL WRITELN(PrefsFile, ReqZ)
  269.  
  270.         CALL CLOSE PrefsFile
  271.     END
  272.  
  273. RETURN
  274.  
  275. /* -------------------------------------------------------------------- */
  276.                                                               /* Ending */
  277. Exiting:
  278.  
  279.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  280.     EXIT
  281.  
  282. RETURN
  283.  
  284. /* -------------------------------------------------------------------- */
  285.                                                  /* Information Windows */
  286. InformationWindows:
  287.  
  288.     OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
  289.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
  290.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info3A, Info3B, Info3C, Info3D, Info3E, Info3F, Info3G, Info3H, Info3I, Info3J, Info3K, Info3L, Info3M, Info3N)
  291.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info4A, Info4B, Info4C, Info4D, Info4E, Info4F, Info4G, Info4H, Info4I, Info4J, Info4K, Info4L, Info4M, Info4N)
  292.     IF OKorCancel = 1 THEN OKorCancel = Notify(1, Info5A, Info5B, Info5C, Info5D, Info5E, Info5F, Info5G, Info5H, Info5I, Info5J, Info5K, Info5L, Info5M, Info5N)
  293.     CALL MenuRequester
  294.  
  295. RETURN
  296.  
  297. /* -------------------------------------------------------------------- */
  298.                                                       /* Error Handling */
  299. SYNTAX:
  300. ERROR:
  301.  
  302.     ErrCode = RC
  303.     ErrLine = SIGL
  304.     ErrInfo = ERRORTEXT(ErrCode)
  305.  
  306.     Err1 = "!Sorry!"
  307.     Err2 = "An Error has been detected"
  308.     Err3 = "@þ Macro -            "
  309.     Err4 = "@þ Line Number -      "
  310.     Err5 = "@þ Error Code -       "
  311.     Err6 = "@þ Error Description -"
  312.     Err7 = "@¤ Please Inform -    "
  313.     Err8 = '  "Error Notice"     '
  314.     Err9 = "  13032 Copenhill Rd."
  315.     Err10 = "  Dallas, TX. 75240  "
  316.  
  317.     Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
  318.  
  319. /* -------------------------------------------------------------------- */
  320.                                              /* Advanced Error Handling */
  321.     CALL SETCLIP("ErrorMacro",MacrosName)
  322.     CALL SETCLIP("ErrorLine",ErrLine)
  323.     CALL SETCLIP("ErrorCode",ErrCode)
  324.     CALL SETCLIP("ErrorDesc",ErrInfo)
  325.  
  326.     PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
  327.  
  328.     CALL SETCLIP("ErrorFile",ErrFile)
  329.  
  330. /* -------------------------------------------------------------------- */
  331.  
  332.     SIGNAL ON ERROR
  333.     SIGNAL ON SYNTAX
  334.     SIGNAL MainBodyOfCode
  335.