DIRECTORY GGParseIn, GGViewerOps, Icons, IO, Rope, Vector2, ViewerClasses, ViewerTools; GGViewerOpsImpl: CEDAR PROGRAM IMPORTS GGParseIn, IO, Rope, ViewerTools EXPORTS GGViewerOps = BEGIN Point: TYPE = Vector2.VEC; Viewer: TYPE = ViewerClasses.Viewer; RopeNotOnTop: PUBLIC SIGNAL [position: NAT, wasThere: Rope.ROPE, notThere: Rope.ROPE] = CODE; GetReal: PUBLIC PROC [textViewer: Viewer, default: REAL] RETURNS [r: REAL] = { rRope: Rope.ROPE _ ViewerTools.GetContents[textViewer]; r _ IF Rope.Size[rRope] = 0 THEN default ELSE IO.GetReal[IO.RIS[rRope] ! IO.EndOfStream, IO.Error => {r _ default; CONTINUE}]; }; GetTwoReals: PUBLIC PROC [textViewer: Viewer] RETURNS [x, y: REAL] = { wholeRope: Rope.ROPE _ ViewerTools.GetContents[textViewer]; wholeStream: IO.STREAM _ IO.RIS[wholeRope]; x _ GGParseIn.ReadWReal[wholeStream]; GGParseIn.ReadWRope[wholeStream, ","]; y _ GGParseIn.ReadWReal[wholeStream]; }; GetPositiveReal: 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] ! IO.EndOfStream, IO.Error => {r _ default; CONTINUE}]; RETURN[IF r >0 THEN r ELSE default]; }; }; SetReal: PUBLIC PROC [viewer: Viewer, real: REAL, format: Rope.ROPE _ NIL] = { realRope: Rope.ROPE; format _ IF format = NIL THEN "%g" ELSE format; realRope _ IO.PutFR[format, [real[real]]]; ViewerTools.SetContents[viewer, realRope]; }; GetPoint: PUBLIC PROC [textViewer: Viewer] RETURNS [point: Point, success: BOOL] = { pointRope: Rope.ROPE _ ViewerTools.GetContents[textViewer]; f: IO.STREAM _ IO.RIS[pointRope]; ReadRope[f, "["]; point.x _ ReadBlankAndReal[f]; ReadRope[f, ","]; point.y _ ReadBlankAndReal[f]; ReadRope[f, "]"]; success _ TRUE; }; SetPoint: PUBLIC PROC [viewer: Viewer, point: Point] = { pointRope: Rope.ROPE; pointRope _ IO.PutFR["[%g,%g]", [real[point.x]], [real[point.y]]]; ViewerTools.SetContents[viewer, pointRope]; }; ReadRope: PUBLIC PROC [f: IO.STREAM, rope: Rope.ROPE] = { c: CHAR; endofstream: BOOL _ FALSE; 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; }; ReadBlankAndReal: PROC [f: IO.STREAM] RETURNS [r: REAL] = { ReadBlank[f]; r _ ReadReal[f]; }; ReadBlank: PROC [f: IO.STREAM] = { [] _ IO.SkipWhitespace[f, TRUE]; }; ReadReal: PROC [f: IO.STREAM] RETURNS [r: REAL] = { realRope: Rope.ROPE; end: BOOL _ FALSE; [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.LF =>RETURN [break]; IO.SP => RETURN [break]; ENDCASE => RETURN [other]; }; GetIconSize: PUBLIC PROC [] RETURNS [width, height: INT] = { RETURN[Icons.iconW, Icons.iconH]; }; END. ΜGGViewerOpsImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Last edited by Bier on September 12, 1987 2:24:55 pm PDT Contents: Utility routines to get and set values from buttons, labels, and text viewers. Pier, June 27, 1991 2:49 pm PDT changed from %6.3. KAP. August 18, 1986 changed to format, Bier, September 8, 1987 Assumes a rope of the form "[,]". 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. A convenience function. Equivalent to ReadBlank[f]; r _ ReadReal[f]; Reads, 's, 's, and 's until something else is encountered. Doesn't mind if no white space characters are found. Treats comments as white space. Reads digits up to the next ], , or . Leaves these terminators on the stream. Κή˜code™Kšœ Οmœ1™