home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 58 / af058b.adf / PV21.lha / REXX / Shear.pvrx < prev    next >
Text File  |  1991-08-13  |  3KB  |  110 lines

  1. /* This is a ProVector AREXX macro */
  2.  
  3.     /***************************************************************\
  4.     *                                *
  5.     *    Macro to 'shear' the selected objects by a given    *
  6.     *    angle.  Works on groups, polygons, and polylines,    *
  7.     *    but not text.  Needs rexxmathlib.library to work.    *
  8.     *                                *
  9.     *                Ross Cunniff, 10/30/89        *
  10.     *                                *
  11.     \***************************************************************/
  12.  
  13. /* Get the rexxmathlib.library */
  14. if ~exists("LIBS:rexxmathlib.library") then do
  15.     'GetBool "Can not find REXXMATHLIB.LIBRARY" "Cancel" "Cancel"' 
  16.     exit
  17.     end
  18. else call addlib "rexxmathlib.library",0,-30,0
  19.  
  20. /* Address the application and ask that results be returned */
  21. Address 'ProVector'
  22. options results
  23.  
  24. /* Try to obtain exclusive access to ProVector; quit if not possible */
  25. 'Lock'
  26. if rc ~= 0 then exit
  27.  
  28. /* Get the shear angle from the user; quit if they cancel */
  29. 'GetStr "Shear angle:" "OK" "Cancel"'; Angle=Result
  30. if rc ~= 0 then do
  31.     'UnLock'
  32.     exit
  33. end
  34.  
  35. /* Check the angle: values outside of -75 degrees to 75 degrees won't work */
  36. if (Angle < -75) | (Angle > 75) then do
  37.     'UnLock'
  38.     exit
  39. end
  40.  
  41. /* Find the Sin and Cos of the angle */
  42. Rads = Angle*3.141593653589/180.0
  43. CosA = cos(Rads);        SinA = sin(Rads)
  44.  
  45. /* Get the baseline for shearing */
  46. 'SelExtent Ext';    Base = Ext.Y2
  47.  
  48. 'PushUndo'
  49.  
  50. /* Shear each object in the list of selected objects */
  51. 'SelectList Sel';    N = Result
  52. do I = 0 to N-1
  53.     call ShearOne(Sel.I,SinA,CosA,Base,1)
  54. end
  55.  
  56. /* Repair the visual damage done by doing that */
  57. 'Repair'
  58.  
  59. /* All done!  Return to normal operations */
  60. 'UnLock'
  61. exit
  62.  
  63.  
  64.  
  65.     /***************************************************************\
  66.     *                                *
  67.     *    ShearOne( Obj, SinA, CosA, Base ) - Shears object Obj    *
  68.     *    by the angle whose sine and cosine are SinA and CosA.    *
  69.     *    Shearing is done relative to line through Y==Base.    *
  70.     *    Recursively calls itself in the case of groups.        *
  71.     *                                *
  72.     \***************************************************************/
  73.  
  74. ShearOne: procedure
  75.     arg Obj,SinA,CosA,Base,Top
  76.  
  77.     /* Find out what we're dealing with */
  78.     'TypeOf Obj';        T = Result
  79.     if T = 'Group' then do
  80.         /* This is a group.  Shear each object in the group. */
  81.         'GroupObj Obj';    GObj = Result
  82.         do while GObj ~= 0
  83.             call ShearOne( GObj, SinA, CosA, Base, 0 )
  84.             'NextObj GObj'; GObj = Result
  85.         end
  86.         /* Kludge to fix up bounding box information */
  87.         'Rotate Obj 0 0 0'
  88.     end
  89.     else if (T = 'Polygon') | (T = 'Polyline') then do
  90.         /* This is a normal object.  Shear each point. */
  91.         'GetPoints Obj Pts';        n = Result
  92.         i = 0
  93.         do while i < n
  94.             PX = Pts.i.X;    PY = Pts.i.Y
  95.             if PX ~= 'INDICATOR' then do
  96.                 r = (Base - PY) / CosA
  97.                 PX = PX + r*SinA
  98.                 Pts.i.X = PX;    Pts.i.Y = PY
  99.             end
  100.             i = i + 1
  101.         end
  102.         if Top = 1 then do
  103.             'SaveUndo Obj'
  104.         end
  105.         'ChangePoints Obj n Pts'
  106.     end
  107.     return
  108.  
  109. /*** EOF shear.pvrx ***/
  110.