DIRECTORY Convert USING [RopeFromInt, RopeFromReal], Imager USING [VEC], ImagerFont USING [Extents, Font, RopeBoundingBox], IO USING [EndOfStream, Error, GetChar, GetIndex, GetReal, int, PeekChar, PutFR, real, RIS, rope, STREAM], Graph USING [Angle, CaretIndex, Entity, EntityList, GraphHandle, JustifX, JustifY, Mark, NullVec, NtNan, Operand, ROPE, SegmentDataList, ValueList], GraphCleanUp USING [CleanUpVL], GraphConvert, GraphUtil USING [BlinkMsg, LengthOfSDL, LengthOfVL, NotANumber, RaiseError, ReverseValueList], Real USING [RealException], Rope USING [Cat, Concat, Equal, IsEmpty], ViewerTools USING [GetContents]; GraphConvertImpl: CEDAR PROGRAM IMPORTS Convert, GraphCleanUp, GraphUtil, ImagerFont, IO, Real, Rope, ViewerTools EXPORTS GraphConvert = { OPEN Graph; RopeOfPlace: PUBLIC PROC[p: Imager.VEC _ NullVec] RETURNS [s: ROPE _ NIL] = { RETURN[IO.PutFR["(%g, %g)", IO.real[p.x], IO.real[p.y]]]; }; -- RopeOfPlace RopeSize: PUBLIC PROC[rope: ROPE _ NIL, font: ImagerFont.Font _ NIL] RETURNS[w, h: REAL _ 0.0] = { IF rope # NIL AND font # NIL THEN { extents: ImagerFont.Extents _ ImagerFont.RopeBoundingBox[font, rope]; w _ extents.rightExtent - extents.leftExtent; h _ extents.descent + extents.ascent; }; }; -- RopeSize RopeOfSlope: PUBLIC PROC[p1, p2: Imager.VEC _ NullVec] RETURNS [s: ROPE _ NIL] = { dx, dy: REAL; IF p2.x < p1.x THEN {t: Imager.VEC _ p1; p1 _ p2; p2 _ t; dx _ -dx; dy _ -dy}; dx _ p2.x - p1.x; dy _ p2.y - p1.y; IF dx = 0.0 THEN RETURN[IF dy = 0.0 THEN "Undefined." ELSE IF dy > 0.0 THEN "+ Infinity." ELSE "- Infinity."] ELSE IF dy = 0.0 THEN RETURN ["0.0"] ELSE { ENABLE Real.RealException => { s _ SELECT TRUE FROM flags[overflow] => "overflow", flags[underflow] => "underflow", flags[invalidOperation] => "invalid operation", ENDCASE => "can't get it."; CONTINUE}; s _ Convert.RopeFromReal[dy/dx]; }; }; -- RopeOfSlope RopeFromJustifX: PUBLIC PROC[justifX: JustifX] RETURNS [ROPE] = { RETURN[SELECT justifX FROM left => "left", center => "center", ENDCASE => "right"] }; -- RopeFromJustifX JustifXFromRope: PUBLIC PROC[jRope: ROPE] RETURNS [JustifX] = { FOR jx: JustifX IN JustifX DO IF RopeFromJustifX[jx].Equal[jRope] THEN RETURN[jx]; ENDLOOP; ERROR; }; -- JustifXFromRope RopeFromJustifY: PUBLIC PROC[justifY: JustifY] RETURNS [ROPE] = { RETURN[SELECT justifY FROM top => "top", center => "center", ENDCASE => "bottom"] }; -- RopeFromJustifX JustifYFromRope: PUBLIC PROC[jRope: ROPE] RETURNS [JustifY] = { FOR jy: JustifY IN JustifY DO IF RopeFromJustifY[jy].Equal[jRope] THEN RETURN[jy]; ENDLOOP; ERROR; }; -- JustifXFromRope RopeFromMark: PUBLIC PROC[mark: Mark] RETURNS [ROPE] = { RETURN[SELECT mark FROM none => "none", round => "round", square => "square", diamond => "diamond", cross => "cross", dollar => "dollar", ENDCASE => "percent"]; }; -- RopeFromMark CharRopeFromMark: PUBLIC PROC [mark: Mark] RETURNS [ROPE] = { RETURN[SELECT mark FROM round => "0", square => "1", diamond => "3", cross => "X", dollar => "$", percent => "%", ENDCASE => " "]; -- error ! }; -- CharRopeFromMark MarkFromRope: PUBLIC PROC [mRope: ROPE] RETURNS [Mark] = { FOR m: Mark IN Mark DO IF RopeFromMark[m].Equal[mRope] THEN RETURN[m]; ENDLOOP; ERROR; }; -- MarkFromRope RopeFromOperand: PUBLIC PROC[op: Operand] RETURNS [ROPE] = { RETURN[SELECT op FROM y => "selected y", plottedYs => "plotted y's", ENDCASE => "x"]; }; -- RopeFromOperand OperandFromRope: PUBLIC PROC[rOp: ROPE] RETURNS [Operand] = { FOR iOp: Operand IN Operand DO IF RopeFromOperand[iOp].Equal[rOp] THEN RETURN[iOp]; ENDLOOP; ERROR; }; -- OperandFromRope RopeFromAngle: PUBLIC PROC[angle: Angle] RETURNS [ROPE] = { RETURN[IF angle = degrees THEN "degrees" ELSE "radians"]; }; -- RopeFromAngle AngleFromRope: PUBLIC PROC[rA: ROPE] RETURNS [Angle] = { IF rA.Equal["radians"] THEN RETURN[radians]; IF rA.Equal["degrees"] THEN RETURN[degrees]; ERROR; }; -- AngleFromRope RopeFromCaretIndex: PUBLIC PROC[index: CaretIndex _ primary] RETURNS [r: ROPE _ NIL] = { RETURN[SELECT index FROM primary => "primary", secondary => "secondary", ENDCASE => "text caret"]}; -- RopeFromCaretIndex RopeFromValueList: PUBLIC PROC[vector: ValueList _ NIL] RETURNS [r: ROPE _ NIL] = { rope: ROPE; FOR v: ValueList _ vector, v.rest UNTIL v = NIL DO rope _ IF GraphUtil.NotANumber[v.first] THEN "*" ELSE Convert.RopeFromReal[v.first]; r _ IF r = NIL THEN rope ELSE r.Cat[" ", rope]; ENDLOOP; }; -- RopeFromValueList RopeFromSDL: PUBLIC PROC[segmentDataList: SegmentDataList _ NIL] RETURNS [r: ROPE _ NIL] = { rope: ROPE; FOR sdl: SegmentDataList _ segmentDataList, sdl.rest UNTIL sdl = NIL DO rope _ IF GraphUtil.NotANumber[sdl.first.end] THEN "*" ELSE Convert.RopeFromReal[sdl.first.end]; r _ IF r = NIL THEN rope ELSE r.Cat[" ", rope]; ENDLOOP; }; -- RopeFromValueList VLFromSDL: PUBLIC PROC [segmentDataList: SegmentDataList] RETURNS [valueList: ValueList _ NIL] = { lastVL: ValueList _ NIL; FOR sdl: SegmentDataList _ segmentDataList, sdl.rest UNTIL sdl = NIL DO vl: ValueList _ CONS[sdl.first.end, NIL]; IF lastVL = NIL THEN lastVL _ valueList _ vl ELSE {lastVL.rest _ vl; lastVL _ vl}; ENDLOOP; }; -- ValueListFromSDL ValueListFromRope: PUBLIC PROC [r: ROPE] RETURNS [vl, last: ValueList _ NIL, length, pos: INT _ 0] = { s: IO.STREAM; real: REAL; IF r.IsEmpty[] THEN RETURN[]; s _ IO.RIS[r]; DO ENABLE { IO.EndOfStream => GOTO done; IO.Error => {pos _ s.GetIndex[]; GOTO error}; }; real _ IO.GetReal[s]; vl _ CONS[real, vl]; length _ length + 1; REPEAT error => {vl _ NIL; length _ 0}; done => NULL; ENDLOOP; IF pos # 0 THEN GraphUtil.BlinkMsg[Rope.Cat["Syntax error at [", Convert.RopeFromInt[pos], "] in the value field."]]; [vl, last] _ GraphUtil.ReverseValueList[vl]; }; -- ValueListFromRope RopeOfEntityListIds: PUBLIC PROC[entityList: EntityList _ NIL, exclude: Entity _ NIL] RETURNS [r: ROPE _ NIL] = { rope: ROPE; FOR el: EntityList _ entityList, el.rest UNTIL el = NIL DO IF el.first = exclude THEN LOOP; rope _ Convert.RopeFromInt[el.first.id]; r _ IF r = NIL THEN rope ELSE r.Cat[" ", rope]; ENDLOOP; }; -- RopeOfEntityListIds RopeOfXYValues: PUBLIC PROC [entity: Entity _ NIL] RETURNS [rope: ROPE _ NIL] = { IF entity # NIL THEN { count: INT _ 0; IF entity.segments # NIL THEN { -- plotted. xseg: SegmentDataList _ entity.group.x.segments; yseg: SegmentDataList _ entity.segments; IF GraphUtil.LengthOfSDL[xseg] # GraphUtil.LengthOfSDL[yseg] THEN GraphUtil.RaiseError[$Other, "different lengths of x and y segments"]; UNTIL xseg = NIL DO pair: ROPE _ IO.PutFR["(%g, %g) ", IF GraphUtil.NotANumber[xseg.first.end] THEN IO.rope["*"] ELSE IO.real[xseg.first.end], IF GraphUtil.NotANumber[yseg.first.end] THEN IO.rope["*"] ELSE IO.real[yseg.first.end]]; IF (count _ count + 1) MOD 4 = 0 THEN pair _ pair.Cat[ IO.PutFR[" -- %g\n", IO.int[count]]]; rope _ rope.Concat[pair]; xseg _ xseg.rest; yseg _ yseg.rest; ENDLOOP; } ELSE { xvl: ValueList _ entity.group.x.oldValues; yvl: ValueList _ entity.oldValues; IF GraphUtil.LengthOfVL[xvl] # GraphUtil.LengthOfVL[yvl] THEN GraphUtil.RaiseError[$Other, "different lengths of x and y values"]; UNTIL xvl = NIL DO pair: ROPE _ IO.PutFR["(%g, %g) ", IF GraphUtil.NotANumber[xvl.first] THEN IO.rope["*"] ELSE IO.real[xvl.first], IF GraphUtil.NotANumber[yvl.first] THEN IO.rope["*"] ELSE IO.real[yvl.first]]; IF (count _ count + 1) MOD 4 = 0 THEN pair _ pair.Cat[ IO.PutFR[" -- %g\n", IO.int[count]]]; rope _ rope.Concat[pair]; xvl _ xvl.rest; yvl _ yvl.rest; ENDLOOP; }; }; }; -- RopeOfXYValues VLsFromValues: PUBLIC PROC [handle: GraphHandle] RETURNS [vlx, vly, lastX, lastY: ValueList _ NIL, msg: ROPE _ NIL] = { s: IO.STREAM _ IO.RIS[ViewerTools.GetContents[handle.controller.values]]; DO ENABLE { IO.EndOfStream => EXIT; IO.Error => { msg _ SELECT ec FROM SyntaxError => "Syntax error", Overflow => "Overflow", ENDCASE => "Error"; EXIT; }; }; rx, ry: REAL; tvl: ValueList; char: CHAR _ ' ; UNTIL char = '( DO char _ s.GetChar[] ENDLOOP; IF s.PeekChar[] = '* THEN {rx _ NtNan; [] _ s.GetChar} ELSE rx _ s.GetReal[]; char _ s.PeekChar[]; UNTIL (char = '* OR char = '- OR char = '+) OR (char IN ['0..'9]) DO [] _ s.GetChar[]; char _ s.PeekChar[]; ENDLOOP; IF char = '* THEN {ry _ NtNan; [] _ s.GetChar} ELSE ry _ s.GetReal[]; UNTIL char = ') DO char _ s.GetChar[] ENDLOOP; tvl _ CONS[rx, NIL]; IF lastX = NIL THEN lastX _ vlx _ tvl ELSE {lastX.rest _ tvl; lastX _ tvl}; tvl _ CONS[ry, NIL]; IF lastY = NIL THEN lastY _ vly _ tvl ELSE {lastY.rest _ tvl; lastY _ tvl}; ENDLOOP; IF msg # NIL THEN { msg _ msg.Concat[IO.PutFR[" at [%g] parsing the value list.", IO.int[s.GetIndex[]]]]; lastX _ vlx _ GraphCleanUp.CleanUpVL[vlx]; lastY _ vly _ GraphCleanUp.CleanUpVL[vly]; }; }; -- VLsFromValues }. LOG. SChen, created October 9, 1985 6:29:44 pm PDT ÒGraphConvertImpl.mesa, Copyright c 1985 by Xerox Corporation. All rights reserved. Last Edited by: Sweetsun Chen, November 15, 1985 5:47:59 pm PST converts contents in the values viewer to xvl and yvl. Ê F˜Jšœ!Ïmœ1™Sšœ™Icode™/—J™šÏk ˜ Jšœžœ˜*Jšœžœžœ˜Jšœ žœ"˜2JšžœžœNžœžœ˜iJšœžœgžœ˜”Jšœ žœ ˜Jšœ ˜ Jšœ žœO˜^Jšœžœ˜Jšœžœ˜)Jšœ žœ˜ —J˜šœžœž˜Jšžœ/žœ˜QJšžœžœ˜$—J˜šÏn œžœžœ žœ žœžœžœ˜MJšžœžœžœ žœ ˜9JšœÏc˜—J˜šŸœžœžœžœžœžœžœžœ ˜bš žœžœžœžœžœ˜#JšœE˜EJšœ-˜-Jšœ%˜%J˜—Jšœ  ˜—J˜šŸ œžœžœžœ žœžœžœ˜RJšœžœ˜ Jšžœ žœ žœ,˜NJšœ˜Jšœ˜š žœ žœžœžœ žœ ˜5Jšžœžœ žœ˜#Jšžœ˜—Jšžœžœ žœžœ˜$šžœ˜šžœ˜šœžœžœž˜J˜J˜ J˜/Jšžœ˜—Jšžœ˜ —J˜ J˜—Jšœ ˜—J˜š Ÿœžœžœžœžœ˜AJšžœžœ žœ%žœ ˜RJšœ ˜—J˜š Ÿœžœžœžœžœ˜?Jšžœ žœ žœžœ"žœžœžœ˜[Jšžœ˜Jšœ ˜—J˜š Ÿœžœžœžœžœ˜AJšžœžœ žœ#žœ ˜QJšœ ˜—J˜š Ÿœžœžœžœžœ˜?Jšžœ žœ žœžœ"žœžœžœ˜[Jšžœ˜Jšœ ˜—J˜š Ÿ œžœžœ žœžœ˜8šžœžœž˜Jšœržœ˜ˆ—Jšœ ˜—J˜š Ÿœžœžœžœžœ˜=šžœžœž˜Jš œ œœœ œ!˜YJšžœ  œ˜—Jšœ ˜—J˜š Ÿ œžœžœ žœžœ ˜:Jšžœ žœžœžœžœžœžœ˜OJšžœ˜Jšœ ˜—J˜š Ÿœžœžœžœžœ˜