home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / propage_pdraw / donsgenies / prodrawgenies.lha / CentreOnPage.pdrx < prev    next >
Encoding:
Text File  |  1995-01-14  |  5.8 KB  |  226 lines

  1. /*
  2. Routine to centre objects. 
  3. Written by Don Cox, Jan 95. Copyright. Not Public Domain.
  4. */
  5. /* $VER: CentreOnPage Jan 95 */
  6.  
  7. /*call open("STDERR","ram:trace","W")
  8. trace r */
  9.  
  10. msg = PDSetup.rexx(2,0) /* load gdarexxsupport.library */
  11. units = getclip(pds_units)
  12. if msg ~= 1 then exit_msg(msg)
  13. call pdm_SetWireFrame(1)
  14. call pdm_SetUnits(2) /* work in cm */
  15.  
  16. numeric digits 7
  17.  
  18. cr = '0a'x
  19.  
  20. call pdm_ShowStatus("  Centring objects...")
  21. cpage = pdm_CurrentPage()
  22. pagewidth = word(pdm_GetPageSize(cpage),1)
  23. pagecenter = pagewidth/2
  24.  
  25. counter=0
  26.  
  27. choice = pdm_Inform(3,"Which objects?","All on page","Click to select","Abort")
  28.  
  29. call pdm_UnselectObj()
  30.  
  31. select
  32. when choice = 1 then do
  33.     do forever
  34.         obj=pdm_ClickOnObj("  Click on objects to be repositioned")
  35.         if obj=0 then break
  36.         counter=counter+1
  37.         objects.counter=obj
  38.         call pdm_Selectobj(obj)
  39.         end
  40.     end
  41.  
  42. when choice = 0 then do
  43.     objects.1 = pdm_PageFirstobj()
  44.     obj = objects.1
  45.     lastobj = pdm_PageLastObj()
  46.     i=1
  47.     do until obj=lastobj
  48.         i=i+1
  49.         obj = pdm_PageNextobj(obj)
  50.         objects.i = obj
  51.         end
  52.     counter = i
  53.     end
  54.  
  55. otherwise exit_msg()
  56. end
  57.  
  58. if counter=0 then exit_msg("No objects selected")
  59.  
  60. call pdm_ShowStatus("  Centring objects...")
  61.  
  62. oldfirst = 0
  63. do i=1 to counter
  64.     moveit = 1
  65.     call pdm_UnselectObj()
  66.     obj=objects.i
  67.     sel = pdm_SelectObj(obj)
  68.     Xpos = word(pdm_GetCenter(obj),1)
  69.     if pdm_IsGrouped(obj) = 1 then do
  70.         firstobj = pdm_GroupFirstObj(obj)
  71.         if firstobj = oldfirst then moveit = 0 /* this group has been moved */
  72.  
  73.         if firstobj~= oldfirst then do /* new group, not yet moved */
  74.             if pdm_IsText(obj)=1 then do /* filter out lone CRs */
  75.                 firstchar = pdm_GroupFirstObj(obj)
  76.                 lastchar = pdm_GroupLastObj(obj)
  77.                 textstring = ""
  78.                 do  char=firstchar to lastchar
  79.                     answer1 = pdm_GetObjText(char)
  80.                     textstring = textstring||answer1
  81.                     if answer1~="0d"x then break
  82.                     end
  83.                 if textstring = "0d"x then iterate i
  84.                 end
  85.             groupobj = pdm_SelectObj(firstobj)
  86.             Xpos = word(pdm_GetCenter(firstobj),1)
  87.             xmin = xpos
  88.             xmax = xpos
  89.             do until groupobj = pdm_GroupLastObj(obj)
  90.                 groupobj = pdm_GroupNextObj(groupobj)
  91.                 sel = pdm_SelectAnother(groupobj)
  92.                 Xpos = word(pdm_GetCenter(groupobj),1)
  93.                 xmax = max(Xpos,xmax)
  94.                 xmin = min(Xpos,xmin)
  95.                 end
  96.             Xpos=(xmin+xmax)/2
  97.             oldfirst = firstobj /* don't do this group again */
  98.             end
  99.         end
  100.  
  101.     if moveit = 1 then do
  102.         deltaX = pagecenter-Xpos
  103.         call pdm_MoveObj(,deltaX,0)
  104.         end
  105.  
  106.     end
  107.  
  108.  
  109. exit_msg()
  110.  
  111. /* +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ */
  112.  
  113. exit_msg()
  114.  
  115. exit_msg: procedure expose units
  116. do
  117.     parse arg message
  118.  
  119.     if message ~= '' then call pdm_Inform(1,message,)
  120.     call pdm_ClearStatus()
  121.     call pdm_SetUnits(units)
  122.     call pdm_AutoUpdate(1)
  123.     exit
  124. end
  125.  
  126.  
  127. /* ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++ */
  128.  
  129. Bezier2:
  130. /* Bezier2.SUB              
  131. From Fundamentals of Interactive Computer Graphics
  132. From article by Steve Enns in Byte, Dec. '86
  133. (2D version only)
  134.  
  135. Calculates cubic parametric freeform Bezier curves
  136.  
  137. XC.,YC. are the coords of the 4 hull points, which are the current and previous points and their inner control points. */
  138.  
  139. XC.1 = oldXcoord
  140. XC.2 = oldControl2X+oldXcoord /* control handle coords are relative */
  141. XC.3 = control1X+Xcoord
  142. XC.4 = Xcoord
  143. YC.1 = oldYcoord
  144. YC.2 = oldControl2Y+oldYcoord
  145. YC.3 = control1Y+Ycoord
  146. YC.4 = Ycoord
  147. curvesize = abs(Xcoord-oldXcoord)+abs(Ycoord-oldYcoord)
  148. curveratio = curvesize/totalsize
  149. increment = 1/(resolution * curveratio)
  150. if increment>0.5 then increment = 0.5 /* just put 1 in the middle */
  151.  
  152. /* Returns CurveXcoord. and CurveYcoord. as the points
  153. Returns XNS as the number of curve points
  154. */
  155.  
  156. IS=1
  157. pointinfo = ""
  158.  
  159. do T=increment to 0.98 by increment /* 0.98 so as not to do a point right at the end of the curve, too close to first poit of next curve */
  160.     T2=T*T
  161.     T3=T2*T
  162.     NC1=1-3*T+3*T2-T3
  163.     NC2=3*T3-6*T2+3*T
  164.     NC3=3*T2-3*T3
  165.     NC4=T3
  166.     CurveXcoord=(NC1*XC.1)+(NC2*XC.2)+(NC3*XC.3)+(NC4*XC.4)
  167.     CurveYcoord=(NC1*YC.1)+(NC2*YC.2)+(NC3*YC.3)+(NC4*YC.4)
  168.     pointinfo = pointinfo||CurveXcoord" "CurveYcoord||cr
  169.     IS=IS+1
  170.     end
  171.  
  172. pointinfo = pointinfo||Xcoord" "Ycoord||cr
  173. XNS = IS-1 /* number of points */
  174.  
  175. RETURN
  176.  
  177. /* +++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ */
  178.  
  179. gridexpand:  /* do the other points of a grid */
  180.  
  181. return
  182.  
  183. /* ++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++ */
  184.  
  185. finalize:  /* Calculate area from file of coordinates. Algorithm from Stolk & Ettershank, Byte Feb. '87, pp.135-6. */
  186.  
  187. call pdm_ShowStatus("  Calculating area...")
  188. call seek("Output",0,"B")
  189. area = 0
  190. totalarea = 0
  191. oldXnumber=0
  192. oldYnumber=0
  193. linecount = 1
  194. firstX = 0
  195. firstY = 0
  196.  
  197. do until eof("Output")
  198.     numbers = readln("Output")
  199.     parse var numbers Xnumber Ynumber
  200.     if datatype(Xnumber,n) & datatype(Ynumber,n) then do
  201.         area = area + (oldXnumber*Ynumber) - (oldYnumber*Xnumber)
  202.         if linecount = 1 then do /* for open/closed check */
  203.             firstX = Xnumber
  204.             firstY = Ynumber
  205.             end
  206.         linecount = linecount+1
  207.         oldXnumber = Xnumber
  208.         oldYnumber = Ynumber
  209.         end
  210.     else do /* blank line between objects */
  211.         if ~(oldXnumber = firstX & oldYnumber = firstY) then area = 0 /* not a closed object */
  212.         linecount = 1
  213.         totalarea = totalarea+area
  214.         area = 0
  215.         oldXnumber=0
  216.         oldYnumber=0
  217.         end
  218.     end
  219. totalarea = abs(totalarea)/2
  220. call close("Output")
  221. address command
  222. 'delete "ram:tempfile" quiet'
  223. return 
  224.  
  225.  
  226.