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, May 29, 1985 6:50:31 pm PDT
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];
rectCounter: INT;
childCounter: INT;
MyDrawChild:
CD.DrawProc =
--PROC [inst: CD.Instance, pos: CD.Position, orient: CD.Orientation, pr: REF CD.DrawInformation]
BEGIN
childCounter ← childCounter+1;
inst.ob.class.drawMe[inst: inst, pos: inst.location, orient: inst.orientation, pr: pr];
END;
MyDrawRect:
CD.DrawRectProc =
--PROC [inst: CD.Instance, pos: CD.Position, orient: CD.Orientation, pr: REF CD.DrawInformation]
BEGIN
rectCounter ← rectCounter+1;
END;
ProtectedCount:
PROCEDURE [comm: CDSequencer.Command] =
BEGIN
myDrawRef: CD.DrawRef ← CD.CreateDrawRef[comm.design];
rectCounter ← childCounter ← 0;
myDrawRef.interestClip ← CDBasics.universe;
myDrawRef.drawChild ← MyDrawChild;
myDrawRef.drawRect ← MyDrawRect;
CDOps.DrawDesign[design: comm.design, pr: myDrawRef];
myDrawRef ← NIL;
TerminalIO.WriteRope[
IO.PutFR["rectangles %g objects %g\n",
IO.int[rectCounter],
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.