home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 58 / af058b.adf / PV21.lha / REXX / Dimension.pvrx < prev    next >
Text File  |  1991-07-18  |  3KB  |  109 lines

  1. /* Dimension.pvrx
  2.    Copyright © 1990 by Taliesin, Inc.
  3.    Author - Ross Cunniff
  4. */
  5.  
  6. /* Get the argument list to see whether this is a MENU, an OK, or a SIZE */
  7. address 'ProVector'
  8.  
  9. arg arglist
  10. Cmd = word(arglist,1)
  11.  
  12. /* Get the rexxmathlib.library */
  13. if ~exists("LIBS:rexxmathlib.library") then do
  14.     'GetBool "Can not find REXXMATHLIB.LIBRARY" "Cancel" "Cancel"' 
  15.     exit
  16.     end
  17. else call addlib "rexxmathlib.library",0,-30,0
  18.  
  19. /* Always do this for a ProVector AREXX function */
  20. Options Results
  21.  
  22. 'Lock Wait'
  23.  
  24. if Cmd = 'MENU' then do
  25.     /* This was called directly from the menu */
  26.     /* Call setdimension after getting a line segment */
  27.     'Prompt "Drag dimension line:"'
  28.     'GetUserData 1 2 2 "Dimension OK" ""'
  29. end
  30. else if Cmd = 'OK' then do
  31.     /* This was called from GetUseData */
  32.     'EndPrompt'
  33.     'GetInputPoints Pts'
  34.  
  35.     /* First, create the line segment */
  36.     'PolyLine 2 Pts';    Obj = Result
  37.  
  38.     X0 = Pts.0.X;    Y0 = Pts.0.Y
  39.     X1 = Pts.1.X;    Y1 = Pts.1.Y
  40.  
  41.     /* Next, calculate the parameters for the text string */
  42.     DX = X1 - X0;        DY = Y1 - Y0
  43.     Dist = sqrt( DX*DX + DY*DY )
  44.     DStr = trunc(Dist,2)
  45.     NChars = Length(DStr)
  46.     ChWidth = (Dist/3)/NChars
  47.     ChHeight = 2*ChWidth
  48.     ChXPos = 0.66666666 * X0 + 0.33333333 * X1
  49.     ChYPos = 0.66666666 * Y0 + 0.33333333 * Y1
  50.     ChAngle = 180 * atan2(Y1 - Y0, X1 - X0) / 3.141592653589
  51.  
  52.     /* Make a new undo level */
  53.     'PushUndo'
  54.  
  55.     /* Now, create the text string */
  56.     'Text DStr ChXPos ChYPos ChWidth ChHeight ChAngle';    TObj = Result
  57.  
  58.     /* Group the line and the text string together */
  59.     GList.0 = Obj;    GList.1 = TObj
  60.     'Group 2 GList';    GObj = Result
  61.  
  62.     /* Attach the redimension call to the object */
  63.     'Rexx GObj Dimension SIZE';    RObj = Result
  64.  
  65.     /* Select it */
  66.     'SelectObj RObj'
  67. end
  68. else if Cmd = 'SIZE' then do
  69.     RObj = word(arglist,2)
  70.  
  71.     CX = word(arglist,3);        CY = word(arglist,4)
  72.     SX = word(arglist,5);        SY = word(arglist,6)
  73.  
  74.     'GroupObj RObj';    GObj = Result
  75.     'GroupObj GObj';    Obj = Result
  76.     'NextObj Obj';        TObj = Result
  77.  
  78.     'Size RObj CX CY SX SY'
  79.  
  80.     'GetText TObj';        SStr=Result
  81.  
  82.     'GetPoints Obj Points';    NumPoints = Result - 1
  83.     X0 = Points.0.X;        Y0 = Points.0.Y
  84.     XN = Points.NumPoints.X;    YN = Points.NumPoints.Y
  85.     Drop Points
  86.  
  87.     DX = XN - X0;        DY = YN - Y0
  88.     Dist = sqrt( DX*DX + DY*DY ); DStr = trunc(Dist,2)
  89.     NChars = Length(DStr)
  90.  
  91.     'ChangeText TObj DStr'
  92.  
  93.     Angle = 180.0*atan2( YN - Y0, XN - X0 )/3.141592653589
  94.     'Rotate TObj CX CY Angle'
  95.     'ObjExtent TObj Ext'
  96.     X = 0.5*Ext.X1 + 0.5*Ext.X2;    Y = 0.25*Ext.Y1 + 0.75*Ext.Y2
  97.     NW = (Ext.X2 - Ext.X1) / NChars;        NH = Ext.Y2 - Ext.Y1
  98.     XScale = Length(SStr)/NChars
  99.     YScale = (2 * NW * XScale) / NH /* YScale = XScale * SY / SX */
  100.     'Size TObj X Y XScale YScale'
  101.     Angle = 0 - Angle;    'Rotate TObj CX CY Angle'
  102.  
  103.     'Rotate RObj 0 0 0'
  104.     'Repair'
  105. end
  106.  
  107. /* All done!  Unlock ProVector */
  108. 'UnLock'
  109.