home *** CD-ROM | disk | FTP | other *** search
- /*
- Routine to centre objects.
- Written by Don Cox, Jan 95. Copyright. Not Public Domain.
- */
- /* $VER: CentreOnPage Jan 95 */
-
- /*call open("STDERR","ram:trace","W")
- trace r */
-
- msg = PDSetup.rexx(2,0) /* load gdarexxsupport.library */
- units = getclip(pds_units)
- if msg ~= 1 then exit_msg(msg)
- call pdm_SetWireFrame(1)
- call pdm_SetUnits(2) /* work in cm */
-
- numeric digits 7
-
- cr = '0a'x
-
- call pdm_ShowStatus(" Centring objects...")
- cpage = pdm_CurrentPage()
- pagewidth = word(pdm_GetPageSize(cpage),1)
- pagecenter = pagewidth/2
-
- counter=0
-
- choice = pdm_Inform(3,"Which objects?","All on page","Click to select","Abort")
-
- call pdm_UnselectObj()
-
- select
- when choice = 1 then do
- do forever
- obj=pdm_ClickOnObj(" Click on objects to be repositioned")
- if obj=0 then break
- counter=counter+1
- objects.counter=obj
- call pdm_Selectobj(obj)
- end
- end
-
- when choice = 0 then do
- objects.1 = pdm_PageFirstobj()
- obj = objects.1
- lastobj = pdm_PageLastObj()
- i=1
- do until obj=lastobj
- i=i+1
- obj = pdm_PageNextobj(obj)
- objects.i = obj
- end
- counter = i
- end
-
- otherwise exit_msg()
- end
-
- if counter=0 then exit_msg("No objects selected")
-
- call pdm_ShowStatus(" Centring objects...")
-
- oldfirst = 0
- do i=1 to counter
- moveit = 1
- call pdm_UnselectObj()
- obj=objects.i
- sel = pdm_SelectObj(obj)
- Xpos = word(pdm_GetCenter(obj),1)
- if pdm_IsGrouped(obj) = 1 then do
- firstobj = pdm_GroupFirstObj(obj)
- if firstobj = oldfirst then moveit = 0 /* this group has been moved */
-
- if firstobj~= oldfirst then do /* new group, not yet moved */
- if pdm_IsText(obj)=1 then do /* filter out lone CRs */
- firstchar = pdm_GroupFirstObj(obj)
- lastchar = pdm_GroupLastObj(obj)
- textstring = ""
- do char=firstchar to lastchar
- answer1 = pdm_GetObjText(char)
- textstring = textstring||answer1
- if answer1~="0d"x then break
- end
- if textstring = "0d"x then iterate i
- end
- groupobj = pdm_SelectObj(firstobj)
- Xpos = word(pdm_GetCenter(firstobj),1)
- xmin = xpos
- xmax = xpos
- do until groupobj = pdm_GroupLastObj(obj)
- groupobj = pdm_GroupNextObj(groupobj)
- sel = pdm_SelectAnother(groupobj)
- Xpos = word(pdm_GetCenter(groupobj),1)
- xmax = max(Xpos,xmax)
- xmin = min(Xpos,xmin)
- end
- Xpos=(xmin+xmax)/2
- oldfirst = firstobj /* don't do this group again */
- end
- end
-
- if moveit = 1 then do
- deltaX = pagecenter-Xpos
- call pdm_MoveObj(,deltaX,0)
- end
-
- end
-
-
- exit_msg()
-
- /* +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ */
-
- exit_msg()
-
- exit_msg: procedure expose units
- do
- parse arg message
-
- if message ~= '' then call pdm_Inform(1,message,)
- call pdm_ClearStatus()
- call pdm_SetUnits(units)
- call pdm_AutoUpdate(1)
- exit
- end
-
-
- /* ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++ */
-
- Bezier2:
- /* Bezier2.SUB
- From Fundamentals of Interactive Computer Graphics
- From article by Steve Enns in Byte, Dec. '86
- (2D version only)
-
- Calculates cubic parametric freeform Bezier curves
-
- XC.,YC. are the coords of the 4 hull points, which are the current and previous points and their inner control points. */
-
- XC.1 = oldXcoord
- XC.2 = oldControl2X+oldXcoord /* control handle coords are relative */
- XC.3 = control1X+Xcoord
- XC.4 = Xcoord
- YC.1 = oldYcoord
- YC.2 = oldControl2Y+oldYcoord
- YC.3 = control1Y+Ycoord
- YC.4 = Ycoord
- curvesize = abs(Xcoord-oldXcoord)+abs(Ycoord-oldYcoord)
- curveratio = curvesize/totalsize
- increment = 1/(resolution * curveratio)
- if increment>0.5 then increment = 0.5 /* just put 1 in the middle */
-
- /* Returns CurveXcoord. and CurveYcoord. as the points
- Returns XNS as the number of curve points
- */
-
- IS=1
- pointinfo = ""
-
- 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 */
- T2=T*T
- T3=T2*T
- NC1=1-3*T+3*T2-T3
- NC2=3*T3-6*T2+3*T
- NC3=3*T2-3*T3
- NC4=T3
- CurveXcoord=(NC1*XC.1)+(NC2*XC.2)+(NC3*XC.3)+(NC4*XC.4)
- CurveYcoord=(NC1*YC.1)+(NC2*YC.2)+(NC3*YC.3)+(NC4*YC.4)
- pointinfo = pointinfo||CurveXcoord" "CurveYcoord||cr
- IS=IS+1
- end
-
- pointinfo = pointinfo||Xcoord" "Ycoord||cr
- XNS = IS-1 /* number of points */
-
- RETURN
-
- /* +++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ */
-
- gridexpand: /* do the other points of a grid */
-
- return
-
- /* ++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++ */
-
- finalize: /* Calculate area from file of coordinates. Algorithm from Stolk & Ettershank, Byte Feb. '87, pp.135-6. */
-
- call pdm_ShowStatus(" Calculating area...")
- call seek("Output",0,"B")
- area = 0
- totalarea = 0
- oldXnumber=0
- oldYnumber=0
- linecount = 1
- firstX = 0
- firstY = 0
-
- do until eof("Output")
- numbers = readln("Output")
- parse var numbers Xnumber Ynumber
- if datatype(Xnumber,n) & datatype(Ynumber,n) then do
- area = area + (oldXnumber*Ynumber) - (oldYnumber*Xnumber)
- if linecount = 1 then do /* for open/closed check */
- firstX = Xnumber
- firstY = Ynumber
- end
- linecount = linecount+1
- oldXnumber = Xnumber
- oldYnumber = Ynumber
- end
- else do /* blank line between objects */
- if ~(oldXnumber = firstX & oldYnumber = firstY) then area = 0 /* not a closed object */
- linecount = 1
- totalarea = totalarea+area
- area = 0
- oldXnumber=0
- oldYnumber=0
- end
- end
- totalarea = abs(totalarea)/2
- call close("Output")
- address command
- 'delete "ram:tempfile" quiet'
- return
-
-
-