DIRECTORY GGParseIn, GGViewerOps, Icons, InputFocus, IO, Process, Rope, Vector2, ViewerClasses, ViewerTools; GGViewerOpsImpl: CEDAR PROGRAM IMPORTS GGParseIn, InputFocus, IO, Process, 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.ReadReal[wholeStream]; GGParseIn.ReadChar[wholeStream, ',]; y ¬ GGParseIn.ReadReal[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.PutFR1[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]; GGParseIn.ReadChar[f, '[]; point.x ¬ ReadBlankAndReal[f]; GGParseIn.ReadChar[f, ',]; point.y ¬ ReadBlankAndReal[f]; GGParseIn.ReadChar[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]; }; 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 '], ',, IO.CR, IO.LF, IO.SP =>RETURN [break]; ENDCASE => RETURN [other]; }; GetIconSize: PUBLIC PROC [] RETURNS [width, height: INT] = { RETURN[Icons.iconW, Icons.iconH]; }; pauses: INT ¬ 5; pauseMSec: Process.Milliseconds ¬ 100; -- one-tenth of a second GetSelectionContents: PUBLIC PROC [] RETURNS [Rope.ROPE] = { -- may return NIL THROUGH [0..pauses) DO f: InputFocus.Focus _ InputFocus.GetInputFocus[]; IF f=NIL THEN RETURN [NIL]; -- there really is no input focus IF f.owner=NIL THEN Process.PauseMsec[pauseMSec] -- wait a while until PopUpSelection2 pops InputFocus, then try again ELSE RETURN[ViewerTools.GetSelectionContents[] ]; ENDLOOP; RETURN[NIL]; -- some other process wacked the input focus }; END. ^ GGViewerOpsImpl.mesa Copyright Σ 1985, 1987, 1991, 1992 by Xerox Corporation. All rights reserved. Contents: Utility routines to get and set values from buttons, labels, and text viewers. Last edited by Bier on December 3, 1992 6:30 pm PST Pier, June 30, 1992 2:05 pm PDT Doug Wyatt, April 10, 1992 11:46 am PDT changed from %6.3. KAP. August 18, 1986 changed to format, Bier, September 8, 1987 Assumes a rope of the form "[,]". 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: 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; }; 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. This proc is designed to work around a bug in PopUpSelection2Impl which causes the owner of the input focus on the top of the InputFocus stack to become NIL and the viewer selection contents to become empty momentarily Κe–(cedarcode) style•NewlineDelimiter ™code™Kšœ ΟeœB™NKšΟnœQ™YK™3K™K™'K™—šΟk ˜ Jš œ+Ÿœœ œœ œœ œ˜bK˜—šžœŸœŸ˜KšŸœŸœ˜=KšŸœŸ˜—˜KšœŸœ Ÿœ˜KšœŸœ˜$K˜—Kšž œŸœŸœ ŸœŸœŸœŸœ˜]K˜š žœŸœŸœŸœŸœŸœ˜NKšœ Ÿœ'˜7KšœŸœŸœ ŸœŸœ ŸœŸœ ŸœŸœŸœ˜~Kšœ˜K˜—š ž œŸœŸœŸœŸœ˜FKšœŸœ'˜;Kš œ ŸœŸœŸœŸœ ˜+K˜$K˜$K˜$Kšœ˜K˜—š žœŸœŸœŸœŸœŸœ˜VKšœ Ÿœ'˜7KšŸœŸœ ˜(šŸœ˜Kš œŸœ ŸœŸœ ŸœŸœŸœ˜TKšŸœŸœŸœŸœ ˜$Kšœ˜—Kšœ˜K˜—š žœŸœŸœŸœŸœŸœ˜NKšœŸœ˜Kš œ Ÿœ ŸœŸœŸœ˜/šœ Ÿœ˜+Kšœ'™'Kšœ*™*—Kšœ*˜*Kšœ˜K˜—š žœŸœŸœŸœŸœ˜TKšœ/™/KšœŸœ'˜;Kš œŸœŸœŸœŸœ ˜!K˜K˜K˜K˜K˜Kšœ Ÿœ˜Kšœ˜K˜—šžœŸœŸœ#˜8KšœŸœ˜Kšœ Ÿœ4˜BKšœ+˜+K˜K˜—š žœŸœŸœŸœŸœ Ÿœ™9Kšœ»™»Kšœ2™2KšœŸœ™Kšœ ŸœŸœ™šŸœŸœŸœŸ™&šœŸœ ™KšœΠkrΟr œŸœŸœ™4—šŸœ Ÿœ™KšŸœŸœŸœ™0—šŸœŸœŸœ™%KšŸœŸœ&™=——KšŸœ™Kšœ™K™—š žœŸœŸœŸœŸœŸœ˜;KšœE™EKšœ ˜ K˜Kšœ˜K˜—šž œŸœŸœŸœ˜"KšœŸœŸœ Ÿœ™‘KšœŸœŸœ˜ Kšœ˜K˜—š žœŸœŸœŸœŸœŸœ˜3Kšœ ŸœŸœŸœ+™aKšœŸœ˜KšœŸœŸœ˜šœ ΟcœŸœ˜3KšœŸœŸœŸœ˜+—KšŸœŸœ Ÿœ˜KšŸœŸœŸœ(˜WKšœŸœ ŸœŸœ ˜!Kšœ˜K˜—š ž œŸœŸœŸœŸœ˜;šŸœŸ˜KšœŸœŸœŸœŸœŸœŸœŸœ ˜-KšŸœŸœ ˜—Kšœ˜—K™š ž œŸœŸœŸœŸœ˜