GraphConvertImpl.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, October 19, 1985 8:13:39 pm PDT
DIRECTORY
Convert USING [RopeFromInt, RopeFromReal],
Imager USING [VEC],
ImagerFont USING [Extents, Font, RopeBoundingBox],
IO USING [EndOfStream, Error, GetIndex, GetReal, PutFR, real, RIS, STREAM],
Graph USING [CaretIndex, Entity, EntityList, JustifX, JustifY, Mark, NullVec, ROPE, SegmentDataList, ValueList],
GraphConvert,
GraphPrivate USING [Angle, Operand],
GraphUtil USING [BlinkMsg, ReverseValueList],
Real USING [RealException],
Rope USING [Cat, Equal];
GraphConvertImpl: CEDAR PROGRAM
IMPORTS Convert, GraphUtil, ImagerFont, IO, Real, Rope
EXPORTS GraphConvert = { OPEN Graph, GraphPrivate;
RopeOfPlace: PUBLIC PROC[p: Imager.VEC ← NullVec] RETURNS [s: ROPENIL] = {
RETURN[IO.PutFR["(%g, %g)", IO.real[p.x], IO.real[p.y]]];
}; -- RopeOfPlace
RopeSize: PUBLIC PROC[rope: ROPENIL, 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: ROPENIL] = {
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 => "Ë", square => "¡", diamond => ".", cross => " ", 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 x => "x", y => "y", ENDCASE => "allY"];
}; -- 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: ROPENIL] = {
RETURN[SELECT index FROM primary => "primary", secondary => "secondary", ENDCASE => "text caret"]}; -- RopeFromCaretIndex
RopeFromValueList: PUBLIC PROC[vector: ValueList ← NIL] RETURNS [r: ROPENIL] = {
rope: ROPE;
FOR v: ValueList ← vector, v.rest UNTIL v = NIL DO
rope ← Convert.RopeFromReal[v.first];
r ← IF r = NIL THEN rope ELSE r.Cat[" ", rope];
ENDLOOP;
}; -- RopeFromValueList
RopeFromSDL: PUBLIC PROC[segmentDataList: SegmentDataList ← NIL] RETURNS [r: ROPENIL] = {
rope: ROPE;
FOR sdl: SegmentDataList ← segmentDataList, sdl.rest UNTIL sdl = NIL DO
rope ← Convert.RopeFromReal[sdl.first.end];
r ← IF r = NIL THEN rope ELSE r.Cat[" ", rope];
ENDLOOP;
}; -- RopeFromValueList
ValueListFromRope: PUBLIC PROC [r: ROPENIL] RETURNS [vector: ValueList ← NIL, length, pos: INT ← 0] = {
s: IO.STREAM;
real: REAL;
IF r = NIL THEN RETURN[];
s ← IO.RIS[r];
DO
ENABLE {
IO.EndOfStream => GOTO done;
IO.Error => {pos ← s.GetIndex[]; GOTO error};
};
real ← IO.GetReal[s];
vector ← CONS[real, vector];
length ← length + 1;
REPEAT
error => {vector ← NIL; length ← 0};
done => NULL;
ENDLOOP;
IF pos # 0 THEN GraphUtil.BlinkMsg[Rope.Cat["Syntax error at [", Convert.RopeFromInt[pos], "] in the value field."]];
vector ← GraphUtil.ReverseValueList[vector];
}; -- ValueListFromRope
RopeOfEntityListIds: PUBLIC PROC[entityList: EntityList ← NIL, exclude: Entity ← NIL] RETURNS [r: ROPENIL] = {
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
}.
LOG.
SChen, created October 9, 1985 6:29:44 pm PDT