GGViewerOpsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last edited by Bier on August 9, 1985 0:02:25 am PDT
Contents: Utility routines to get and set values from buttons, labels, and text viewers.
DIRECTORY
GGModelTypes,
GGViewerOps,
IO,
Rope,
ViewerClasses,
ViewerTools;
GGViewerOpsImpl: CEDAR PROGRAM
IMPORTS IO, Rope, ViewerTools
EXPORTS GGViewerOps =
BEGIN
Point: TYPE = GGModelTypes.Point;
Viewer: TYPE = ViewerClasses.Viewer;
GetReal: PUBLIC PROC [textViewer: Viewer, default: REAL] RETURNS [r: REAL] = {
rRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
IF Rope.Size[rRope] = 0 THEN r ← default ELSE {
r ← IO.GetReal[IO.RIS[rRope]];
};
};
SetReal: PUBLIC PROC [viewer: Viewer, real: REAL] = {
realRope: Rope.ROPE;
realRope ← IO.PutFR["%6.2f", [real[real]]];
ViewerTools.SetContents[viewer, realRope];
};
GetPoint: PUBLIC PROC [textViewer: Viewer] RETURNS [point: Point, success: BOOL] = {
Assumes a rope of the form "[<real1>,<real2>]".
pointRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
f: IO.STREAMIO.RIS[pointRope];
ReadRope[f, "["];
point[1] ← ReadBlankAndReal[f];
ReadRope[f, ","];
point[2] ← ReadBlankAndReal[f];
ReadRope[f, "]"];
success ← TRUE;
};
SetPoint: PUBLIC PROC [viewer: Viewer, point: Point] = {
pointRope: Rope.ROPE;
pointRope ← IO.PutFR["[%6.2f,%6.2f]", [real[point[1]]], [real[point[2]]]];
ViewerTools.SetContents[viewer, pointRope];
};
ReadRope: PUBLIC PROC [f: IO.STREAM, rope: Rope.ROPE] = {
Removes the given rope from the top of the stream. Used to remove formatting words and phrases from 3d files. We are not interested in these strings but only in the data in between them.
Signals RopeNotOnTop if some other rope is on top.
c: CHAR;
endofstream: BOOLFALSE;
FOR i: INT IN[1..Rope.Length[rope]] DO
c ← IO.GetChar[f
! IO.EndOfStream => {endofstream ← TRUE; CONTINUE}];
IF endofstream THEN
SIGNAL RopeNotOnTop [IO.GetIndex[f], NIL, rope];
IF NOT c = Rope.Fetch[rope,i-1] THEN
SIGNAL RopeNotOnTop [IO.GetIndex[f], Rope.FromChar[c], rope];
ENDLOOP;
};
RopeNotOnTop: PUBLIC SIGNAL [position: NAT, wasThere: Rope.ROPE, notThere: Rope.ROPE] = CODE;
ReadBlankAndReal: PROC [f: IO.STREAM] RETURNS [r: REAL] = {
A convenience function. Equivalent to ReadBlank[f]; r ← ReadReal[f];
ReadBlank[f];
r ← ReadReal[f];
};
ReadBlank: PROC [f: IO.STREAM] = {
Reads, <SPACE>'s, <CR>'s, and <TAB>'s until something else is encountered. Doesn't mind if no white space characters are found. Treats comments as white space.
[] ← IO.SkipWhitespace[f, TRUE];
};
ReadReal: PROC [f: IO.STREAM] RETURNS [r: REAL] = {
Reads digits up to the next ], <CR>, <SPACE> or <COMMA>. Leaves these terminators on the stream.
realRope: Rope.ROPE;
end: BOOLFALSE;
[realRope, ----] ← IO.GetTokenRope[f, RealBreakProc
!IO.EndOfStream => {end ← TRUE; CONTINUE}];
IF end THEN {r ← 0.0; RETURN};
IF Rope.Find[realRope, ".", 0, FALSE] = -1 THEN realRope ← Rope.Concat[realRope, ".0"];
r ← IO.GetReal[IO.RIS[realRope]];
};
RealBreakProc: PROC [char: CHAR] RETURNS [IO.CharClass] = {
SELECT char FROM
'], ', => RETURN [break];
IO.CR =>RETURN [break];
IO.SP => RETURN [break];
ENDCASE => RETURN [other];
};
END.