home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LW5VT09.LHA / Toaster / Arexx_examples / Lwe / Explload.lwm < prev    next >
Encoding:
Text File  |  1996-06-10  |  32.8 KB  |  1,124 lines

  1.  /*************************************************************\
  2. /                                                               \                              
  3.            ExplodeLoad V1.0, by Reinhard Grams © 1994
  4. \                                                               / 
  5.  \*************************************************************/
  6.  
  7. macro_name="ExplodeLoad V1.0"
  8. macro_path="/EXPL"
  9.  
  10. /**************************************************************/
  11. call InitVariables()
  12. /**************************************************************/
  13.  
  14. help.GERMAN.1="Dieses Makro lädt ein Lightwave Objekt und läßt es explodieren."
  15. help.GERMAN.2="Jede Fläche wird dabei mit unabhängigen Punkten versehen, so daß"
  16. help.GERMAN.3="die Flächen einzeln animiert werden können. Die Stärke der Ex-"
  17. help.GERMAN.4="plosion bestimmt der Explosion Factor. Die Richtung der Explosi-"
  18. help.GERMAN.5="on bestimmen Sie durch die Angabe des Zentrums der Explosion und"
  19. help.GERMAN.6="der Achsen, entlang denen die Explosion wirkt. Die Flächen ro-"
  20. help.GERMAN.7="tieren während der Explosion, die Stärke der Rotation bestimmen"
  21. help.GERMAN.8="Sie durch die Eingabe des minimalen und maximalen Rotationswin-"
  22. help.GERMAN.9="kels. Zusätzlich können die Flächen im Verlauf der Explosion"
  23. help.GERMAN.10="skaliert werden, eine Eingabe von 0 beim Parameter Scale Factor"
  24. help.GERMAN.11="bewirkt bspw. ein Verschwinden der Teile nach Ablauf der Explo-"
  25. help.GERMAN.12="sion."
  26. help.GERMAN.13="[PAGE]"
  27. help.GERMAN.14="Der Schalter Explode to Sphere bewirkt, daß die Flächen am Ende"
  28. help.GERMAN.15="der Explosion eine Kugelschale bilden. Den einzelnen Flächen"
  29. help.GERMAN.16="kann noch durch einen Random Factor eine für jede Fläche leicht"
  30. help.GERMAN.17="verschiedene Explosionswirkung verliehen werden. Den Verlauf der"
  31. help.GERMAN.18="Explosion bestimmen Sie in einem weiteren Requester, der die"
  32. help.GERMAN.19="""Hüllkurve"" der Explosion festlegt. Eine ""echte"" Explosion"
  33. help.GERMAN.20="entspricht der Wahl von SquareRoot. Beachten Sie, daß die Flä-"
  34. help.GERMAN.21="chen möglichst gleich weit vom Explode Center enfernt sind, um"
  35. help.GERMAN.22="eine gleichmäßige Wirkung zu erzielen."
  36. help.GERMAN.23="[PAGE]"
  37. help.GERMAN.24="Die Anzahl der zu berechnenden Objekte geben Sie beim Parameter"
  38. help.GERMAN.25="Frames an. Die Objekte werden durch Morphing animiert. Dazu ru-"
  39. help.GERMAN.26="fen Sie anschließend das Makro Morph2Scene auf, welches aus ei-"
  40. help.GERMAN.27="ner Reihe von Objekten eine LW-Scene generiert (siehe dort). Die"
  41. help.GERMAN.28="Scene können Sie einfach mit Load Scene als solche in den Lay-"
  42. help.GERMAN.29="outer einladen. Mächtiger ist jedoch die Möglichkeit, nur die"
  43. help.GERMAN.30="Morphsequenz mit Objects/Load from Scene in eine bestehende Sce-"
  44. help.GERMAN.31="ne einzubauen."
  45. help.GERMAN.32="[PAGE]"
  46. help.GERMAN.33="Beachten Sie bitte, daß die Anzahl der Objekte im direkten Zu-"
  47. help.GERMAN.34="sammenhang mit der Art der Explosion steht. Je nichtlinearer die"
  48. help.GERMAN.35="Explosion ist, desto mehr Objekte sollten Sie verwenden (d.h"
  49. help.GERMAN.36="möglichst wenig Interpolation durch LW). Die besten Ergebnisse"
  50. help.GERMAN.37="erzielen Sie mit einem Objekt pro Frame der Animation, aber in"
  51. help.GERMAN.38="den meisten Fällen reichen 3 bis 5 Interpolationsframes für ei-"
  52. help.GERMAN.39="nen ausreichend weichen Ablauf aus. D.h für 3 Sekunden Animation"
  53. help.GERMAN.40="(75 Frames) sollten Sie ca. 25 Objekte verwenden."
  54. help.GERMAN.41="[END]"
  55.  
  56. help.ENGLISH.1="This macro loads a Lightwave object and simply explodes it. Each"
  57. help.ENGLISH.2="surface is made with independent points, so the single surface"
  58. help.ENGLISH.3="can become animated. The power of explosion is determined by the"
  59. help.ENGLISH.4="""Explosion Factor"". The direction of the explosion is selected"
  60. help.ENGLISH.5="by setting the center and the axes along the explosion operates."
  61. help.ENGLISH.6="The surfaces are rotating during the explosion, the intensity of"
  62. help.ENGLISH.7="rotation is selected with the input of minimal and maximal rota-"
  63. help.ENGLISH.8="tion-angle. Additionally the surfaces can be scaled during the"
  64. help.ENGLISH.9="explosion, if 0 is entered at ""ScaleFactor"", the parts will"
  65. help.ENGLISH.10="fade away when the explosion ends."
  66. help.ENGLISH.11="[PAGE]"
  67. help.ENGLISH.12="The ""Explode to Sphere"" switch makes the surfaces forming into"
  68. help.ENGLISH.13="a sphere socket in the end of the explosion. Each surface can"
  69. help.ENGLISH.14="get an own explosion-effect by setting a ""Random Factor"". You"
  70. help.ENGLISH.15="can determine the course of the explosion in another requester,"
  71. help.ENGLISH.16="which sets the ""covercurve"" of the explosion. A ""real"" ex-"
  72. help.ENGLISH.17="plosion is eqivalent to ""SquareRoot"". Have attention that all"
  73. help.ENGLISH.18="the surfaces have nearly the same distance to the explode center"
  74. help.ENGLISH.19="to get a symmetrical result."
  75. help.ENGLISH.20="[PAGE]"
  76. help.ENGLISH.21="You specify the number of the objects to calculate with the"
  77. help.ENGLISH.22="""Frames"" parameter. The objects are animated by morphing."
  78. help.ENGLISH.23="Therefor you run the macro Morph2Scene as next, which generates"
  79. help.ENGLISH.24="a LW-scene out of a row of objects (see there). Load the scene"
  80. help.ENGLISH.25="with ""Load Scene"" into the layouter as it is. The option to"
  81. help.ENGLISH.26="load only the morphing sequence with ""Objects/Load from Scene"""
  82. help.ENGLISH.27="into an existing scene is more powerful."
  83. help.ENGLISH.28="[PAGE]"
  84. help.ENGLISH.29="Remember that the number of objects influences the way of explo-"
  85. help.ENGLISH.30="sion directly. You should use more objects if the explosion is"
  86. help.ENGLISH.31="non-linear (means as less interpolation by LW as possible). You"
  87. help.ENGLISH.32="will get the best results with one object per frame for the"
  88. help.ENGLISH.33="whole animation, but in most cases 3 to 5 interpolation frames"
  89. help.ENGLISH.34="are enough for a smooth running. For 3 seconds of animation (75"
  90. help.ENGLISH.35="frames) You should use around 25 objects."
  91. help.ENGLISH.36="[END]"
  92.  
  93. /**************************************************************/
  94.  
  95.     form0.1="influence=influence"
  96.     form0.2="influence=sin(frame*(90/frames)*pi180)"
  97.     form0.3="influence=1-cos(frame*(90/frames)*pi180)"
  98.     form0.4="influence=influence*influence"
  99.     form0.5="influence=influence*influence*influence"
  100.     form0.6="influence=sqrt(influence)"
  101.     form0.7="influence=tanh(influence*PI)"
  102.  
  103.     form1.1="influence=influence"
  104.     form1.2="influence=sin((frame-1)*(90/(frames-1))*pi180)"
  105.     form1.3="influence=1-cos((frame-1)*(90/(frames-1))*pi180)"
  106.     form1.4="influence=influence*influence"
  107.     form1.5="influence=influence*influence*influence"
  108.     form1.6="influence=sqrt(influence)"
  109.     form1.7="influence=tanh(influence*PI)"
  110.  
  111.     EX_LINEAR=1
  112.     EX_SINUS=2
  113.     EX_COSINUS=3
  114.     EX_EXP2=4
  115.     EX_EXP3=5
  116.     EX_SQR=6
  117.     EX_TANH=7
  118.  
  119. /**************************************************************/
  120.  
  121.     explosion_type=EX_LINEAR
  122.     object_name=""
  123.     frames=11
  124.     explode_factor=3
  125.     explode_dist=3
  126.     explode_random=0.33
  127.     add_surfaces=1
  128.     make_sphere=1
  129.     random_seed=4713
  130.     explode_type=6
  131.     sphere_factor=1
  132.     rotate_min=0.25
  133.     rotate_max=0.5
  134.     scale_factor=1
  135.     start_object=1
  136.     end_object=1
  137.     start_exploded=0
  138.     do_x=1
  139.     do_y=1
  140.     do_z=1
  141.  
  142. /**************************************************************/
  143.  
  144.     call OpenLibs()
  145.     call GlobalsRequester(macro_name)
  146.     call HelpRequester(macro_name,"help",language)
  147.  
  148.     call LoadConfig()
  149.     call Requester()
  150.     explosion_type=ExTypeRequester()
  151.     if (explosion_type=0) then call CleanExit()
  152.     call SaveConfig()
  153.  
  154.     file_name=SelectFile(messages.language.OBJECT_MESS,"3D:Objects","",selection1)
  155.     if (file_name="") then call CleanExit()
  156.  
  157.     object_name=SelectFile(messages.language.OUTPUT_MESS,"3D:Objects","",selection2)
  158.     if (object_name="") then call CleanExit()
  159.  
  160.     call ExplodeSequence()
  161.  
  162.     call CloseLibs()
  163.     exit 0
  164.  
  165. /**************************************************************/
  166.  
  167. Requester:
  168.  
  169.     call req_begin(macro_name)
  170.  
  171.     id_frames=req_addcontrol("Frames", 'n')
  172.     id_type=req_addcontrol("Explosion Axis",'ch',"X Y Z XY XZ XYZ")
  173.     id_surf=req_addcontrol("Add Surfaces", 'b')
  174.     id_sphere=req_addcontrol("Explode to Sphere", 'b')
  175.     id_start=req_addcontrol("Start Exploded", 'b')
  176.     id_exp=req_addcontrol("Explosion Factor",'n')
  177.     id_expr=req_addcontrol("Explosion Random",'n')
  178.     id_sphfac=req_addcontrol("Sphere Factor", 'n')
  179.     id_rotmm=req_addcontrol("Rotate Min, Max °", 'v')
  180.     id_expc=req_addcontrol("Explode Center XYZ", 'v',1)
  181.     id_scafac=req_addcontrol("Scale Factor", 'n')
  182.     id_seed=req_addcontrol("Random Seed", 'n')
  183.  
  184.     call req_setval(id_frames, frames)
  185.     call req_setval(id_type, explode_type)
  186.     call req_setval(id_exp, explode_factor)
  187.     call req_setval(id_expr, explode_random)
  188.     call req_setval(id_seed, random_seed)
  189.     call req_setval(id_surf, add_surfaces)
  190.     call req_setval(id_sphere, make_sphere)
  191.     call req_setval(id_sphfac, sphere_factor)
  192.     call req_setval(id_rotmm, rotate_min*360 rotate_max*360 0)
  193.     call req_setval(id_expc, offset_x offset_y offset_z)
  194.     call req_setval(id_scafac, scale_factor)
  195.     call req_setval(id_start, start_exploded)
  196.  
  197.     if (~req_post()) then call CleanExit()
  198.     
  199.     frames=req_getval(id_frames)
  200.     explode_type=req_getval(id_type)
  201.     explode_factor=req_getval(id_exp)
  202.     explode_random=req_getval(id_expr)
  203.     random_seed=req_getval(id_seed)
  204.     add_surfaces=req_getval(id_surf)
  205.     make_sphere=req_getval(id_sphere)
  206.     sphere_factor=req_getval(id_sphfac)
  207.     rmm=req_getval(id_rotmm)
  208.     parse value rmm with rotate_min rotate_max .
  209.     rotate_min=rotate_min/360; rotate_max=rotate_max/360
  210.     of=req_getval(id_expc)
  211.     parse value of with offset_x offset_y offset_z .
  212.     scale_factor=req_getval(id_scafac)
  213.     start_exploded=req_getval(id_start)
  214.  
  215.     call req_end()
  216.  
  217.     select
  218.         when (explode_type=1) then do; do_x=1; do_y=0; do_z=0; end
  219.         when (explode_type=2) then do; do_x=0; do_y=1; do_z=0; end
  220.         when (explode_type=3) then do; do_x=0; do_y=0; do_z=1; end
  221.         when (explode_type=4) then do; do_x=1; do_y=1; do_z=0; end
  222.         when (explode_type=5) then do; do_x=1; do_y=0; do_z=1; end
  223.         when (explode_type=6) then do; do_x=1; do_y=1; do_z=1; end
  224.     end
  225.  
  226.     if (random_seed=0) then random_seed=time('s')
  227.     if (frames<1) then frames=1
  228.  
  229.     return 1
  230.  
  231. /**************************************************************/
  232.  
  233. ExTypeRequester:
  234.  
  235.     mes.ENGLISH.1="Select Explosion Type"
  236.     mes.GERMAN.1="Typ der Explosion"
  237.  
  238.     extypes="Linear Sin Cos Exp2 Exp3 SquareRoot Tanh"
  239.     return VariableChoice(mes.language.1,"TYPE",,
  240.         extypes,7,explosion_type)
  241.  
  242. /**************************************************************/
  243.  
  244. SaveConfig:
  245.  
  246.     if (open(state, config, 'W')) then do
  247.         call writeln(state, "CONF")
  248.         call writeln(state, explode_type add_surfaces make_sphere,
  249.             sphere_factor scale_factor explode_factor explode_random,
  250.             random_seed rotate_min rotate_max frames start_exploded,
  251.             explosion_type offset_x offset_y offset_z)
  252.         call close state
  253.     end
  254.     return
  255.  
  256. /**************************************************************/
  257.  
  258. LoadConfig:
  259.  
  260.     if (exists(config)) then do
  261.         if (open(state, config, 'R')) then do
  262.             if (readln(state)="CONF") then do
  263.                 parse value readln(state) with explode_type,
  264.                     add_surfaces make_sphere sphere_factor scale_factor,
  265.                     explode_factor explode_random random_seed rotate_min,
  266.                     rotate_max frames start_exploded explosion_type,
  267.                     offset_x offset_y offset_z .
  268.             end
  269.         end
  270.         call close state
  271.     end
  272.     return
  273.  
  274. /**************************************************************/
  275. /**************************************************************/
  276.  
  277. ExplodeSequence:
  278.  
  279.     call randu(random_seed)
  280.  
  281.     frames=trunc(frames)
  282.  
  283.     call cut(); call cut()
  284.     if (add_surfaces) then call load(file_name)
  285.  
  286.     call LoadLightwaveObject(file_name)
  287.     call InitExplode()
  288.     do frame=1 to frames
  289.         call cut()
  290.         call ExplodeFaces()
  291.         if (frames>1) then do
  292.             name=object_name||MakeExtension(frame,extension_digits)
  293.         end
  294.         else name=object_name
  295.         call save(name)
  296.     end
  297.  
  298.     if (verbose) then do
  299.         call notify(1,! vmes.language.1 trunc(frames) vmes.language.2) 
  300.     end
  301.  
  302.     return
  303.  
  304. /**************************************************************/
  305.  
  306. LoadLightwaveObject: parse arg file_name
  307.  
  308.     points=0; faces=0; surfaces=0
  309.  
  310. /* OPEN FILE */
  311.  
  312.     file=LW_OpenObject(file_name)
  313.     if (file=0) then call CleanExit(OBJECT_ERR,file_name)
  314.  
  315. /* DO SURFACES */
  316.  
  317.     if (add_surfaces) then do
  318.         surfaces=LW_SetObject(file,"SURFACES","COUNT")
  319.         if (surfaces>0) then do
  320.             call meter_begin(surfaces,macro_name":" surfaces "SURFACES")
  321.              do surface=1 to trunc(surfaces)
  322.                 surface_names.surface=LW_GetObject(file)
  323.                 call meter_step();
  324.             end
  325.             call meter_end()
  326.         end
  327.     end
  328.  
  329. /* DO POINTS */
  330.  
  331.     points=LW_SetObject(file,"POINTS","COUNT")
  332.     if (points=0) then call CleanExit(OBJECT_ERR,file_name)
  333.  
  334.     call meter_begin(points,macro_name":" points "POINTS")
  335.     pointlist=""
  336.     do point=1 to trunc(points)
  337.         coords=LW_GetObject(file)
  338.         parse value coords with x.point y.point z.point .
  339.         pointlist=pointlist coords
  340.         call meter_step();
  341.     end    
  342.     call meter_end()
  343.         
  344. /* DO POLYGONS */
  345.     
  346.     faces=LW_SetObject(file,"POLYGONS","COUNT")
  347.     if (faces=0) then call CleanExit(OBJECT_ERR,file_name)
  348.  
  349.     call meter_begin(faces,macro_name":" faces "FACES")
  350.     do face=1 to faces
  351.         face_list.face=LW_GetObject(file)
  352.         face_count.face=words(face_list.face)-1
  353.         call meter_step();
  354.     end
  355.     call meter_end()
  356.  
  357. /* CLOSE FILE */
  358.  
  359.     file=LW_CloseObject(file)
  360.  
  361.     return
  362.  
  363. /**************************************************************/
  364.  
  365. ExplodeFaces:
  366.  
  367.     call SetExplode()
  368.     call add_begin() 
  369.     call meter_begin(faces,macro_name||mmes.language.1 frame mmes.language.2 frames)
  370.  
  371.     do face=1 to trunc(faces)
  372.         call ExplodeFace(face,face_count.face)
  373.         pointlist=""
  374.         do p=1 to face_count.face
  375.             pointlist=pointlist add_point(px.p py.p pz.p)
  376.         end
  377.         if (add_surfaces && surfaces>0) then do
  378.             surface=word(face_list.face,face_count.face+1)
  379.             call surface(surface_names.surface)
  380.         end 
  381.         call add_polygon(pointlist)
  382.         call meter_step();
  383.     end
  384.  
  385.     call meter_end()
  386.     call add_end()
  387.  
  388.     return 
  389.  
  390. /**************************************************************/
  391.  
  392. ExplodeFace: parse arg face, face_points
  393.  
  394.     pointlist=""
  395.     do p=1 to face_points
  396.         offset=word(face_list.face,p)
  397.         px.p=x.offset
  398.         py.p=y.offset
  399.         pz.p=z.offset
  400.         pointlist=pointlist px.p py.p pz.p
  401.     end
  402.     parse value LW_PointsCenter(pointlist,"CENTER") with cx cy cz .
  403.  
  404.     cx=cx-center_x; cy=cy-center_y; cz=cz-center_z
  405.     rotate=LW_InitRotate(rotate_x.face,rotate_y.face,rotate_z.face)
  406.     do p=1 to face_points
  407.         dx=((px.p-center_x)-cx)*scal
  408.         dy=((py.p-center_y)-cy)*scal
  409.         dz=((pz.p-center_z)-cz)*scal
  410.         parse value LW_PointsRotate(rotate,dx,dy,dz) with dx dy dz .                
  411.  
  412.         if (do_x) then px.p=explode_x*random.face*cx+dx+center_x
  413.         if (do_y) then py.p=explode_y*random.face*cy+dy+center_y
  414.         if (do_z) then pz.p=explode_z*random.face*cz+dz+center_z
  415.  
  416.     end
  417.     rotate=LW_RemoveRotate(rotate)
  418.  
  419.     return
  420.  
  421. /**************************************************************/
  422.  
  423. InitExplode:
  424.  
  425.     center=LW_PointsCenter(pointlist,"CENTER")
  426.     parse value center with center_xo center_yo center_zo .
  427.     center_x=center_xo+offset_x
  428.     center_y=center_yo+offset_y
  429.     center_z=center_zo+offset_z
  430.     center=LW_PointsCenter(pointlist,"RATIO")
  431.     parse value center with ratio_x ratio_y ratio_z .
  432.     ratio_xo=(ratio_x-1.0)*sphere_factor
  433.     ratio_yo=(ratio_y-1.0)*sphere_factor
  434.     ratio_zo=(ratio_z-1.0)*sphere_factor
  435.  
  436.     fac=360*PI180*(rotate_max-rotate_min)
  437.     min=360*PI180*rotate_min
  438.     do r=1 to faces
  439.         v=2*randu()-1; rotate_xo.r=v*fac+(min*sign(v))
  440.         v=2*randu()-1; rotate_yo.r=v*fac+(min*sign(v))
  441.         v=2*randu()-1; rotate_zo.r=v*fac+(min*sign(v))
  442.         random_o.r=(2*randu()-1.0)*explode_random
  443.     end
  444.  
  445.     return
  446.  
  447. /**************************************************************/
  448.  
  449. SetExplode:
  450.  
  451.     influence=1
  452.     if (frames>1) then do
  453.         if (start_exploded) then do
  454.             influence=frame/frames
  455.             interpret(form0.explosion_type)
  456.         end
  457.         else do
  458.             influence=(frame-1)/(frames-1)
  459.             interpret(form1.explosion_type)
  460.         end
  461.     end
  462.     
  463.     expl=(explode_factor-1)*influence+1
  464.     scal=(scale_factor-1)*influence+1
  465.     ratio_x=ratio_xo*influence+1
  466.     ratio_y=ratio_yo*influence+1
  467.     ratio_z=ratio_zo*influence+1
  468.  
  469.     if (make_sphere) then do
  470.         explode_x=expl*ratio_x
  471.         explode_y=expl*ratio_y
  472.         explode_z=expl*ratio_z
  473.     end
  474.     else do
  475.         explode_x=expl
  476.         explode_y=expl
  477.         explode_z=expl
  478.     end
  479.     do r=1 to faces
  480.         rotate_x.r=rotate_xo.r*influence
  481.         rotate_y.r=rotate_yo.r*influence
  482.         rotate_z.r=rotate_zo.r*influence
  483.         random.r=random_o.r*influence+1
  484.     end
  485.  
  486.     return
  487.  
  488. /**************************************************************/
  489. /**************************************************************/
  490.  
  491. ErrorMessage: parse arg status, add_string, user_cancel
  492.  
  493.     continue=0
  494.     if (status~="") then do
  495.         if (user_cancel~="") then user_sel=2; else user_sel=1
  496.         if (verify(status,"0123456789")=0) then do
  497.             if (status>0 & status<INTERNAL_ERR) then do
  498.                 if (add_string~="") then do
  499.                     continue=notify(user_sel,! errors.language.status"!",add_string)
  500.                 end
  501.                 else do
  502.                     continue=notify(user_sel,! errors.language.status"!")
  503.                 end
  504.             end
  505.             else do
  506.                 continue=notify(1,! errors.language.INTERNAL_ERR"!")
  507.             end
  508.         end
  509.         else do
  510.             if (add_string~="") then continue=notify(user_sel,! status,add_string)
  511.             else continue=notify(user_sel,! status)
  512.         end            
  513.     end
  514.     return continue
  515.  
  516. /**************************************************************/
  517.  
  518. CleanExit: parse arg status, add_string, user_cancel
  519.  
  520.     call end_all()
  521.     call ErrorMessage(status, add_string, user_cancel)
  522.     call CloseLibs()
  523.     exit 0
  524.  
  525. /**************************************************************/
  526.  
  527. OpenLibs:
  528.  
  529.     if (~show('L',rexxlib)) then do
  530.         if ~addlib(rexxlib,0,-30,0) then do
  531.             call ErrorMessage(OPEN_LIB_ERR,rexxlib)
  532.             exit 10
  533.         end
  534.         if (~show('L',rexxlib)) then do
  535.             call ErrorMessage(OPEN_LIB_ERR,rexxlib)
  536.             exit 10
  537.         end
  538.     end
  539.     if (~show('L',mathlib)) then do
  540.         if ~addlib(mathlib,0,-30,0) then do
  541.             call ErrorMessage(OPEN_LIB_ERR,mathlib)
  542.             exit 10
  543.         end
  544.         if (~show('L',mathlib)) then do
  545.             call ErrorMessage(OPEN_LIB_ERR,mathlib)
  546.             exit 10
  547.         end
  548.     end
  549.     if (~show('L',supplib)) then do
  550.         if ~addlib(supplib,0,-30,0) then do
  551.             call ErrorMessage(OPEN_LIB_ERR,supplib)
  552.             exit 10
  553.         end
  554.         if (~show('L',supplib)) then do
  555.             call ErrorMessage(OPEN_LIB_ERR,mathlib)
  556.             exit 10
  557.         end
  558.     end
  559.     port=addlib("LWModelerARexx.port",0)
  560.     return 
  561.  
  562. /**************************************************************/
  563.  
  564. CloseLibs:
  565.  
  566.     if (port~="") then call remlib("LWModelerARexx.port")
  567.     return
  568.  
  569. /**************************************************************/
  570.  
  571. SelectFile: PROCEDURE EXPOSE selected_file selected_drawer
  572.     parse arg title, drawer_name, file_name, config_file, mode
  573.  
  574.     if (exists(config_file)) then do
  575.         if (open(state,config_file,'R')) then do
  576.             if (readln(state)="FSEL") then do
  577.                 drawer_name=readln(state)
  578.                 file_name=readln(state)
  579.             end
  580.             call close state
  581.         end
  582.     end
  583.     if (mode=DRAWER) then choice=getfilename(title,drawer_name,"")
  584.     else choice=getfilename(title,drawer_name,file_name)
  585.     if (choice="(none)") then return ""
  586.     selected_drawer=LW_Drawer(choice)
  587.     selected_file=LW_File(choice)
  588.     if (mode~="DRAWER") then do
  589.         if (selected_file="") then return ""
  590.     end        
  591.     if (open(state,config_file,'W')) then do
  592.         call writeln(state, "FSEL")
  593.         call writeln(state, selected_drawer)
  594.         call writeln(state, selected_file)
  595.         call close(state)
  596.     end
  597.     select 
  598.         when (mode="DRAWER") then choice=selected_drawer
  599.         when (mode="FILE") then choice=selected_file
  600.         otherwise nop
  601.     end
  602.  
  603.     return choice
  604.  
  605. /**************************************************************/
  606.  
  607. HelpRequester: parse arg title, text_array, language
  608.  
  609.     select 
  610.         when (help_type=HELP_NEVER) then return
  611.         when (help_type=HELP_FIRST) then do    
  612.             if (exists(config)) then return
  613.         end
  614.         otherwise nop
  615.     end    
  616.     if (~TextRequester(title,text_array,language)) then do
  617.         call GlobalsRequester(title,1)
  618.     end
  619.     return 
  620.  
  621. /**************************************************************/
  622.  
  623. TextRequester: parse arg title, text_array, language
  624.  
  625.     hpages=1
  626.     hline=1
  627.     do until (str="[END]")
  628.         interpret("str="text_array"."language"."hline)
  629.         if (str="[PAGE]") then hpages=hpages+1
  630.         hline=hline+1
  631.     end
  632.     call req_begin(title||pmes.language.1 "1" pmes.language.2 hpages) 
  633.     hline=1; continue=1; hpage=1
  634.     do while (continue)
  635.         interpret("htext="text_array"."language"."hline)
  636.         select
  637.             when (htext="[PAGE]") then do
  638.                 go_on=req_post()
  639.                 call req_end()
  640.                 if (go_on) then do
  641.                     hpage=hpage+1
  642.                     call req_begin(title||pmes.language.1 hpage pmes.language.2 hpages) 
  643.                 end
  644.                 else continue=0
  645.             end
  646.             when (htext="[END]") then do
  647.                 go_on=req_post()
  648.                 call req_end()
  649.                 continue=0
  650.             end
  651.             otherwise do
  652.                 id.hline=req_addcontrol("",'t',htext)
  653.             end    
  654.         end
  655.         hline=hline+1
  656.     end
  657.     return go_on
  658.  
  659. /**************************************************************/
  660.  
  661. SaveSettings: PROCEDURE EXPOSE ENV_ERR envpath globals language,
  662.     help_type verbose extension_digits
  663.  
  664.     if (~exists(envpath)) then do
  665.         address command "makedir" envpath
  666.         if (~exists(envpath)) then call CleanExit(ENV_ERR)
  667.     end
  668.     ok=0
  669.     if (open(state, globals, 'W')) then do
  670.         call writeln(state, "GLBS")
  671.         call writeln(state, language help_type verbose extension_digits)
  672.         call close(state)
  673.         ok=1
  674.     end
  675.     return ok
  676.  
  677. /**************************************************************/
  678.  
  679. LoadSettings: PROCEDURE EXPOSE ENV_ERR envpath globals language,
  680.     help_type verbose extension_digits
  681.  
  682.     if (~exists(envpath)) then do
  683.         address command "makedir" envpath
  684.         if (~exists(envpath)) then call CleanExit(ENV_ERR)
  685.     end
  686.     ok=0
  687.     if (exists(globals)) then do
  688.         if (open(state, globals, 'R')) then do
  689.             if (readln(state)="GLBS") then do
  690.                    parse value readln(state) with language help_type,
  691.                     verbose extension_digits .
  692.                 ok=1
  693.             end
  694.             call close(state)
  695.         end
  696.     end
  697.     return ok
  698.  
  699. /**************************************************************/
  700.  
  701. GlobalsRequester: PROCEDURE EXPOSE ENV_ERR envpath globals language,
  702.     help_type verbose extension_digits
  703.     parse arg title, force
  704.  
  705.     loaded=LoadSettings()
  706.     if (force="") then do
  707.         if (loaded) then return
  708.     end
  709.     call req_begin(title": Globals")
  710.     id_la=req_addcontrol("Language", 'ch',"English German")
  711.     id_he=req_addcontrol("Help", 'ch',"First Always Never")
  712.     id_ve=req_addcontrol("Verbose", 'b')
  713.     id_ex=req_addcontrol("Ext. Digits", 'n')
  714.     call req_setval(id_la, language)
  715.     call req_setval(id_he, help_type)
  716.     call req_setval(id_ve, verbose)
  717.     call req_setval(id_ex, extension_digits)
  718.     if (~req_post()) then do; call req_end(); return 0; end
  719.     language=req_getval(id_la)
  720.     help_type=req_getval(id_he)
  721.     verbose=req_getval(id_ve)
  722.     extension_digits=req_getval(id_ex)
  723.     call req_end()
  724.     if (extension_digits<2) then extension_digits=2
  725.     call SaveSettings()
  726.     return 
  727.  
  728. /**************************************************************/
  729.  
  730. GetExtension: PROCEDURE; parse arg exname
  731.  
  732.     l=length(exname)
  733.     s=verify(reverse(exname),"0123456789")
  734.     if (s>l) then return exname
  735.     if (s<2) then return ""
  736.     return substr(exname,length(exname)+2-s)
  737.     
  738. /**************************************************************/
  739.  
  740. GetBaseName: PROCEDURE; parse arg exname
  741.  
  742.     b=length(exname)-length(GetExtension(exname))
  743.     return substr(exname,1,b)
  744.     
  745. /**************************************************************/
  746.  
  747. GetExtensionDigits: PROCEDURE; parse arg exname
  748.  
  749.     return length(GetExtension(exname))
  750.  
  751. /**************************************************************/
  752.  
  753. MakeExtension: PROCEDURE; parse arg exname, ext_digits
  754.  
  755.     return right(exname,ext_digits,'0')
  756.  
  757. /**************************************************************/
  758.  
  759. SaveSelection: PROCEDURE EXPOSE sequence_name.
  760.     parse arg selected, select_file, select_type
  761.  
  762.     ok=0
  763.     if (open(state, select_file, 'W')) then do
  764.         call writeln(state, "SSEL")
  765.         call writeln(state, select_type)
  766.         call writeln(state, selected)
  767.         c=1
  768.         do while (c<=selected)
  769.             call writeln(state, sequence_name.c); c=c+1
  770.         end
  771.         call close(state)
  772.         ok=1
  773.     end
  774.     return ok
  775.  
  776. /**************************************************************/
  777.  
  778. LoadSelection: PROCEDURE EXPOSE select_type sequence_name.
  779.     parse arg select_file
  780.  
  781.     selected=0
  782.     if (exists(select_file)) then do
  783.         if (open(state, select_file, 'R')) then do
  784.             if (readln(state)="SSEL") then do
  785.                    select_type=readln(state)
  786.                    selected=readln(state)
  787.                 c=1
  788.                 do while (c<=selected)
  789.                     sequence_name.c=readln(state); c=c+1
  790.                 end    
  791.             end
  792.             call close(state)
  793.         end
  794.     end
  795.     return selected
  796.  
  797. /**************************************************************/
  798.  
  799. SelectSequence: PROCEDURE EXPOSE language sequence_name.,
  800.     EXTENSION_ERR SEQUENCE_ERR FILE_ERR READ_ERR GERMAN ENGLISH errors.,        
  801.     ST_SEQUENCE ST_SPECIFY ST_LIST ST_DIRECTORY ST_READ ST_REPEAT
  802.     parse arg title, default_drawer, minimum_files, maximum_files,,
  803.     selection1, selection2, select_file, select_type
  804.  
  805.     mes.ENGLISH.1="Select First"    
  806.     mes.ENGLISH.2="Select Last"
  807.     mes.ENGLISH.3="Select Next (or CANCEL)"
  808.     mes.ENGLISH.4="Select List"
  809.     mes.ENGLISH.5="Select Directory"
  810.     mes.ENGLISH.6="Need at least"
  811.     mes.ENGLISH.7="File(s)"
  812.     mes.ENGLISH.8="Maximum of"
  813.     mes.ENGLISH.9="Files selected"
  814.  
  815.     mes.GERMAN.1="Wählen Sie die erste Datei"    
  816.     mes.GERMAN.2="Wählen Sie die letzte Datei"    
  817.     mes.GERMAN.3="Nächste Datei (oder CANCEL)"    
  818.     mes.GERMAN.4="Wählen Sie die Liste"
  819.     mes.GERMAN.5="Wählen Sie das Verzeichnis"
  820.     mes.GERMAN.6="Wählen Sie bitte mindestens"
  821.     mes.GERMAN.7="Datei(en)"
  822.     mes.GERMAN.8="Bitte nur maximal"
  823.     mes.GERMAN.9="Datei(en) ausgewählt"
  824.  
  825.     old_selected=LoadSelection(select_file)
  826.     select_type=TypeRequester(title,select_type,old_selected)
  827.     if (select_type=0) then return 0
  828.     if (title~="") then title=title": "
  829.     seq_files=0
  830.  
  831.     select
  832.         when (select_type=ST_SEQUENCE) then do
  833.             name1=SelectFile(title||mes.language.1,default_drawer,"",selection1)
  834.             if (name1="") then return 0            
  835.             name2=SelectFile(title||mes.language.2,selected_drawer,"",selection2)
  836.             if (name2="") then return 0
  837.  
  838.             start_sequence=GetExtension(name1)
  839.             end_sequence=GetExtension(name2)
  840.             if (start_sequence="" | end_sequence="") then do
  841.                 call CleanExit(EXTENSION_ERR)
  842.             end
  843.             if (start_sequence>end_sequence) then do
  844.                 temp=start_sequence
  845.                 start_sequence=end_sequence
  846.                 end_sequence=temp
  847.             end
  848.             base_name=GetBaseName(name1)            
  849.             extension_digits=GetExtensionDigits(name1)
  850.             if (upper(base_name)~=upper(GetBaseName(name2))) then do
  851.                 call CleanExit(SEQUENCE_ERR)
  852.             end
  853.             if (extension_digits~=GetExtensionDigits(name2)) then do
  854.                 extension_digits=0
  855.             end
  856.             do o=start_sequence to end_sequence
  857.                 seq_files=seq_files+1
  858.                 sequence_name.seq_files=base_name||MakeExtension(o,extension_digits)
  859.             end
  860.         end
  861.  
  862.         when (select_type=ST_SPECIFY) then do
  863.  
  864.             done=0
  865.             do until (done)
  866.                 name=SelectFile(title||mes.language.3,default_drawer,"",selection1)
  867.                 if (name="") then do
  868.                     if (seq_files=0) then return 0
  869.                     else done=1
  870.                 end
  871.                 if (~done) then do    
  872.                     seq_files=seq_files+1
  873.                     sequence_name.seq_files=name
  874.                 end
  875.             end
  876.         end
  877.  
  878.         when (select_type=ST_LIST) then do
  879.  
  880.             name=SelectFile(title||mes.language.4,"RAM:","",selection1)
  881.             if (name="") then return 0
  882.             if (~exists(name)) then call CleanExit(FILE_ERR)
  883.             if (~open(state,name,'R')) then call CleanExit(READ_ERR)
  884.             do until (name="")
  885.                 name=readln(state)
  886.                 if (name~="") then do
  887.                     seq_files=seq_files+1
  888.                     sequence_name.seq_files=name
  889.                 end
  890.             end
  891.             call close(state)
  892.         end
  893.  
  894.         when (select_type=ST_DIRECTORY) then do
  895.  
  896.             drawer=SelectFile(title||mes.language.5,default_drawer,"",selection1,"DRAWER")
  897.             if (drawer="") then return 0
  898.             list=DeleteInfo(showdir(drawer,'F'))
  899.             seq_files=words(list)
  900.             do sequence=1 to seq_files
  901.                 name=LW_AddFile(drawer,word(list,sequence))
  902.                 sequence_name.sequence=name
  903.             end
  904.         end
  905.  
  906.         when (select_type=ST_READ) then do
  907.  
  908.             name1=SelectFile(title||mes.language.1,default_drawer,"",selection1)
  909.             if (name1="") then return 0            
  910.             name2=SelectFile(title||mes.language.2,selected_drawer,"",selection2)
  911.             if (name2="") then return 0
  912.  
  913.             drawer=LW_DRAWER(name1)
  914.             list=DeleteInfo(showdir(drawer,'F'))
  915.             list=LW_SortList(list,words(list))
  916.             files=words(list)
  917.             do_add=0
  918.             do sequence=1 to files
  919.                 name=LW_AddFile(drawer,word(list,sequence)) 
  920.                 if (name=name1) then do_add=1
  921.                 if (do_add) then do
  922.                     seq_files=seq_files+1
  923.                     sequence_name.seq_files=name
  924.                 end
  925.                 if (name=name2) then leave
  926.             end
  927.         end
  928.  
  929.         when (select_type=ST_REPEAT) then do
  930.             seq_files=old_selected
  931.         end
  932.     end
  933.  
  934.     if (seq_files<minimum_files) then do
  935.         call notify(1,! mes.language.6 minimum_files mes.language.7); return 0
  936.     end
  937.     if (seq_files>maximum_files) then do
  938.         call notify(1,! mes.language.8 maximum_files mes.language.7); return 0
  939.     end
  940.     if (~notify(2,! seq_files mes.language.9)) then return 0
  941.  
  942.     SaveSelection(seq_files,select_file,select_type)
  943.     return seq_files
  944.  
  945. /**************************************************************/
  946.  
  947. DeleteInfo: parse arg flist
  948.  
  949.     elist=""
  950.     if (flist~="") then do
  951.         do i=1 to words(flist)
  952.             w=word(flist,i)
  953.             if (pos(".info",w,length(w)-5)=0) then elist=elist w
  954.         end
  955.     end
  956.     return elist
  957.  
  958. /**************************************************************/
  959.  
  960. TypeRequester: PROCEDURE EXPOSE language ENGLISH GERMAN
  961.     parse arg title, select_type, old_selected
  962.  
  963.     mes.ENGLISH.1=": Selection Type"
  964.     mes.ENGLISH.2="Type of File Selection"
  965.     mes.GERMAN.1=": Art der Auswahl"
  966.     mes.GERMAN.2="Art der Dateiauswahl"
  967.  
  968.     if (title~="") then tstring=title||mes.language.1
  969.     else tstring=mes.language.2
  970.     cstring="Sequence Specify List Directory AlphaSort"
  971.     if (old_selected>0) then cstring=cstring "Repeat"
  972.     return VariableChoice(tstring,"TYPE",cstring,words(cstring),select_type)
  973.  
  974. /**************************************************************/
  975.  
  976. VariableChoice: PROCEDURE EXPOSE language ENGLISH GERMAN pmes.
  977.     parse arg title, descriptor, array, visible, selected 
  978.  
  979.     vchoice=0
  980.     to_show=words(array); coffset=1; cpage=1; cpages=to_show/visible; 
  981.     if ((to_show//visible)>0) then cpages=cpages+1; cpages=trunc(cpages)
  982.     do while (to_show>0)
  983.         if (to_show>visible) then citems=visible; else citems=to_show
  984.         vc=""; do i=coffset to citems+coffset-1; vc=vc word(array,i); end
  985.         if (cpages>1) then call req_begin(title||pmes.language.1 cpage pmes.language.2 cpages)
  986.         else call req_begin(title)
  987.         vci=req_addcontrol(descriptor,'cv',vc)
  988.         call req_setval(vci,selected)
  989.         if (~req_post()) then do; call req_end(); return 0; end
  990.         vchoice=req_getval(vci)
  991.         call req_end()
  992.         to_show=to_show-citems; coffset=coffset+citems
  993.     end
  994.     return vchoice
  995.  
  996. /**************************************************************/
  997.  
  998. error:
  999. syntax:
  1000.  
  1001.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  1002.     call CleanExit()
  1003.  
  1004. /**************************************************************/
  1005. /**************************************************************/
  1006.  
  1007. InitVariables:
  1008.  
  1009. mathlib="rexxmathlib.library"
  1010. rexxlib="rexxsupport.library"
  1011. supplib="LWE.library"
  1012. port=""
  1013.  
  1014. envpath="ENV:LWEnhancer"
  1015. globals=envpath"/LWEN.GLB"
  1016. envname=envpath||macro_path
  1017. config=envname".CNF"
  1018.  
  1019. selection1=envname".1"
  1020. selection2=envname".2"
  1021. selection3=envname".3"
  1022. selectionl=envname".L"
  1023.  
  1024. /**************************************************************/
  1025.  
  1026. ENGLISH=1
  1027. GERMAN=2
  1028.  
  1029. HELP_FIRST=1
  1030. HELP_ALWAYS=2
  1031. HELP_NEVER=3
  1032.  
  1033. help_type=HELP_FIRST
  1034. language=ENGLISH
  1035. verbose=1
  1036.  
  1037. /**************************************************************/
  1038.  
  1039. ST_SEQUENCE=1
  1040. ST_SPECIFY=2
  1041. ST_LIST=3
  1042. ST_DIRECTORY=4
  1043. ST_READ=5
  1044. ST_REPEAT=6
  1045.  
  1046. extension_digits=3
  1047.  
  1048. /**************************************************************/
  1049.  
  1050. vmes.ENGLISH.1="Object exploded,"
  1051. vmes.ENGLISH.2="Object(s) generated."
  1052. vmes.GERMAN.1="Objekt wurde explodiert,"
  1053. vmes.GERMAN.2="Objekt(e) erzeugt."
  1054.  
  1055. mmes.ENGLISH.1=": Object"
  1056. mmes.ENGLISH.2="of"
  1057. mmes.GERMAN.1=": Objekt"
  1058. mmes.GERMAN.2="von"
  1059.  
  1060. pmes.ENGLISH.1=": Page"
  1061. pmes.ENGLISH.2="from"
  1062. pmes.GERMAN.1=": Seite"
  1063. pmes.GERMAN.2="von"
  1064.  
  1065. NO_ERROR=0
  1066. FILE_ERR=1
  1067. OPEN_LIB_ERR=2
  1068. READ_ERR=3
  1069. WRITE_ERR=4
  1070. EXTENSION_ERR=5
  1071. SEQUENCE_ERR=6
  1072. ENV_ERR=7
  1073. OBJECT_ERR=8
  1074. INTERNAL_ERR=9
  1075.  
  1076. errors.ENGLISH.FILE_ERR="File not found"
  1077. errors.ENGLISH.OPEN_LIB_ERR="Can't open Library"
  1078. errors.ENGLISH.READ_ERR="Read Error"
  1079. errors.ENGLISH.WRITE_ERR="Write Error"
  1080. errors.ENGLISH.EXTENSION_ERR="Numeric Extension Error"
  1081. errors.ENGLISH.SEQUENCE_ERR="Base Names are different"
  1082. errors.ENGLISH.ENV_ERR="Can't create"
  1083. errors.ENGLISH.OBJECT_ERR="Not a valid object file"
  1084. errors.ENGLISH.INTERNAL_ERR="Internal Error"
  1085.  
  1086. errors.GERMAN.FILE_ERR="Datei nicht gefunden"
  1087. errors.GERMAN.OPEN_LIB_ERR="Kann Library nicht öffnen"
  1088. errors.GERMAN.READ_ERR="Fehler beim Lesen der Datei"
  1089. errors.GERMAN.WRITE_ERR="Fehler beim Schreiben der Datei"
  1090. errors.GERMAN.EXTENSION_ERR="Keine gültige numerische Extension"
  1091. errors.GERMAN.SEQUENCE_ERR="Sequenz mit unterschiedlichen Basisnamen"
  1092. errors.GERMAN.ENV_ERR="Kann Verzeichnis nicht anlegen"
  1093. errors.GERMAN.OBJECT_ERR="Fehler beim Lesen der Objektdatei"
  1094. errors.GERMAN.INTERNAL_ERR="Interner Fehler"
  1095.  
  1096. /**************************************************************/
  1097.  
  1098. SELECT_MESS=1
  1099. MOTION_MESS=2
  1100. OBJECT_MESS=3
  1101. OUTPUT_MESS=4
  1102. SEQUENCE_MESS=5
  1103.  
  1104. messages.ENGLISH.SELECT_MESS="Please select File"
  1105. messages.ENGLISH.MOTION_MESS="Please select Motion File"
  1106. messages.ENGLISH.OBJECT_MESS="Please select Object File"
  1107. messages.ENGLISH.OUTPUT_MESS="Please select Output File"
  1108. messages.ENGLISH.SEQUENCE_MESS="Please select File Sequence"
  1109.  
  1110. messages.GERMAN.SELECT_MESS="Bitte wählen Sie eine Datei"
  1111. messages.GERMAN.MOTION_MESS="Bitte wählen Sie eine Motion-Datei"
  1112. messages.GERMAN.OBJECT_MESS="Bitte wählen Sie eine Objekt-Datei"
  1113. messages.GERMAN.OUTPUT_MESS="Bitte wählen Sie die Zieldatei"
  1114. messages.GERMAN.SEQUENCE_MESS="Wählen Sie eine Sequenz von Dateien"
  1115.  
  1116. /**************************************************************/
  1117.  
  1118. PI=3.14159265358; PI180=pi/180; PI2=pi/2; DegrPerRad=180/pi
  1119.  
  1120. /**************************************************************/
  1121.  
  1122. return
  1123.  
  1124.