CDCountCommands.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
by: Ch. Jacobi, February 20, 1985 10:41:19 am PST
Last Edited by: Ch. Jacobi, February 20, 1985 10:41:22 am PST
DIRECTORY
TerminalIO,
CD,
CDSequencer,
CDOps,
CDCommandOps,
CDBasics,
CDMenus USING [CreateEntry],
IO;
CDCountCommands: CEDAR PROGRAM
IMPORTS TerminalIO, CD, CDMenus, CDSequencer, CDOps, CDCommandOps, IO =
BEGIN
--the global variables mare monitored using CDCommandOps.CallWithResource;
--these variables are global so they can be used by MyDrawChild
stopFlag: REF BOOLEAN = NEW[BOOLEAN];
saveCounter: INT;
rectCounter: INT;
childCounter: INT;
MyDrawChild: CD.DrawProc =
--PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: REF CD.DrawInformation]
BEGIN
childCounter ← childCounter+1;
aptr.ob.p.drawMe[aptr: aptr, pos: aptr.location, orient: aptr.orientation, pr: pr];
END;
MyDrawRect: CD.DrawRectProc =
--PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: REF CD.DrawInformation]
BEGIN
rectCounter ← rectCounter+1;
END;
MySaveRect: CD.DrawRectProc =
--PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: REF CD.DrawInformation]
BEGIN
saveCounter ← saveCounter+1;
END;
ProtectedCount: PROCEDURE [comm: CDSequencer.Command] =
BEGIN
myDrawRef: CD.DrawRef ← CD.CreateDrawRef[comm.design];
saveCounter ← rectCounter ← childCounter ← 0;
myDrawRef.interestClip ← CDBasics.universe;
myDrawRef.drawChild ← MyDrawChild;
myDrawRef.drawRect ← MyDrawRect;
myDrawRef.saveRect ← MySaveRect;
CDOps.DrawDesign[design: comm.design, pr: myDrawRef];
myDrawRef ← NIL;
TerminalIO.WriteRope[IO.PutFR["rectangles %g objects %g\n",
IO.int[rectCounter+saveCounter],
IO.int[childCounter]
]];
END;
CountComm: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Count rectangles\n"];
[] ← CDCommandOps.CallWithResource[ProtectedCount, comm, $myDrawRef, stopFlag];
END;
CDMenus.CreateEntry[menu: $ProgramMenu, entry: "count rectangles", key: $CountRects];
CDSequencer.ImplementCommand[$CountRects, CountComm,, dontQueue];
END.