/* RBB: Router Bit Bevel Script       */
/*      © 1993 by Christian Aubert    */
/* based on:                          */
/* CMD: Test Script By Arnie Cachelin */
/* Skeleton for Modeler ARexx scripts */

/* Set up variables */
sysnam  = 'Router Bit Bevel'
version = 'RBB v1.0ß'
author  = 'by Christian Aubert'
pat=''

/* Set up system */
address "LWModelerARexx.port"
call addlib "LWModelerARexx.port", 0
call addlib "rexxsupport.library", 0, -30, 0
call addlib "rexxmathlib.library", 0, -30, 0
SIGNAL ON ERROR
SIGNAL ON SYNTAX
NUMERIC DIGITS 4

/* Build and call requester */
call req_begin sysnam
id_text  = req_addcontrol(version, 'T', author)
id_axis  = req_addcontrol('Discard Axis', 'CH', 'X Y Z')
id_text  = req_addcontrol('Router Bit Scale', 'T', '')
id_inset = req_addcontrol('Inset %','N')
id_shift = req_addcontrol('Shift %','N')
call req_setval id_axis, 3
call req_setval id_inset, 100
call req_setval id_shift, 100
if (~req_post()) then do
    call req_end
    exit
end
axis = req_getval(id_axis)
inset = req_getval(id_inset)/100
shift = req_getval(id_shift)/100
call req_end()

/* Evaluate router bit, and build */
/* pattern list for bevel         */
t=time('e')
fg = CURLAYER()
bg = CURBLAYER()
call setlayer(bg)
n = xfrm_begin()
call meter_begin n-2, 'Analyzing Router Bit', 'Percentage Completed'
parse value xfrm_getpos(1) with cx cy cz
/* We already have the first value --^ , 
   and the last point is discarded, because
   it is only used to improve 'readability'
   of the router bit */
do i = 2 to n-1
  parse value xfrm_getpos(i) with dx dy dz
  x = (dx - cx)
  y = (dy - cy)
  z = (dz - cz)
  SELECT
     WHEN axis=1 THEN pat = pat y*inset z*shift
     WHEN axis=2 THEN pat = pat x*inset z*shift
     WHEN axis=3 THEN pat = pat x*inset y*shift
  END
  /* a little debugging feature */
  /* i left just in case !      */
  /*  nil = notify(1, x, y, z)  */
  call meter_step
end
call meter_end
call xfrm_end

/* Do the actual bevel */
call setlayer(fg)
call setblayer(bg)
call shapebevel(pat)
t=time('e')-t
nil = notify(1,'!All done beveling','in 't' seconds')
exit

syntax:
error:
  call end_all
     t=Notify(1,'!Rexx Script Error:@'ErrorText(rc), '!On Line 'SIGL, '!Please Notify My Master    ', '!So he can take care of this')
     exit