GGDescribeImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last edited by Bier on April 9, 1987 11:58:26 am PDT
Contents: Printing out descriptions of gargoyle objects onto text streams, for debugging and feedback.
Pier, May 13, 1987 3:03:07 pm PDT
DIRECTORY
Atom, GGDescribe, GGInterfaceTypes, GGModelTypes, GGSegmentTypes, GGTraj, IO, Rope;
GGDescribeImpl: CEDAR PROGRAM
IMPORTS Atom, GGTraj, IO, Rope
EXPORTS GGDescribe = BEGIN
AlignmentPoint: TYPE = GGInterfaceTypes.AlignmentPoint;
EntityGenerator: TYPE = GGModelTypes.EntityGenerator;
FeatureData: TYPE = GGInterfaceTypes.FeatureData;
GGData: TYPE = GGInterfaceTypes.GGData;
Outline: TYPE = GGModelTypes.Outline;
OutlineDescriptor: TYPE = GGModelTypes.OutlineDescriptor;
Segment: TYPE = GGSegmentTypes.Segment;
Sequence: TYPE = GGModelTypes.Sequence;
SequenceGenerator: TYPE = GGModelTypes.SequenceGenerator;
Slice: TYPE = GGModelTypes.Slice;
SliceDescriptor: TYPE = GGModelTypes.SliceDescriptor;
SliceParts: TYPE = GGModelTypes.SliceParts;
Traj: TYPE = GGModelTypes.Traj;
TrajGenerator: TYPE = GGModelTypes.TrajGenerator;
NotYetImplemented: PUBLIC SIGNAL = CODE;
DescribeFeature: PUBLIC PROC [feature: FeatureData, hitData: REF ANY, ggData: GGData] RETURNS [rope: Rope.ROPE] = {
IF feature = NIL THEN RETURN["nothing"]
ELSE {
SELECT feature.type FROM
outline, slice => {
slice: Slice ← NARROW[feature.shape, SliceDescriptor].slice;
rope ← slice.class.describeHit[slice, hitData];
};
distanceLine => rope ← "distance line";
slopeLine => rope ← "slope line";
angleLine => rope ← "angle line";
symmetryLine => rope ← "symmetry line";
radiiCircle => rope ← "compass circle";
intersectionPoint => {
firstObj, secondObj: Rope.ROPE;
alignPoint: AlignmentPoint ← NARROW[feature.shape];
line1: FeatureData ← alignPoint.curve1;
line2: FeatureData ← alignPoint.curve2;
tangent: BOOL ← alignPoint.tangent;
IF line1 = NIL AND line2 = NIL THEN {
rope ← IO.PutFR["the anchor"];
}
ELSE {
firstObj ← IF line1 # NIL THEN DescribeSourceFeature[line1, ggData]
ELSE "unknown";
secondObj ← IF line2 # NIL THEN DescribeSourceFeature[line2, ggData]
ELSE "unknown";
IF tangent THEN rope ← IO.PutFR["a %g/%g tangency point", [rope[firstObj]], [rope[secondObj]] ]
ELSE rope ← IO.PutFR["a %g/%g intersection point", [rope[firstObj]], [rope[secondObj]] ];
};
};
midpoint => {
seqPart: GGInterfaceTypes.SequencePart ← NARROW[hitData];
segNum: NAT ← seqPart.segNum;
alignPoint: AlignmentPoint ← NARROW[feature.shape];
curveFeature: FeatureData ← alignPoint.curve1;
SELECT curveFeature.type FROM
outline, slice => {
slice: Slice ← NARROW[curveFeature.shape, SliceDescriptor].slice;
rope ← slice.class.describeHit[slice, hitData];
};
ENDCASE => rope ← "unknown";
rope ← IO.PutFR["midpoint of %g", [rope[rope]]];
};
anchor => {
rope ← IO.PutFR["anchor"];
};
ENDCASE => ERROR;
};
};
DescribeSourceFeature: PUBLIC PROC [feature: FeatureData, ggData: GGData] RETURNS [rope: Rope.ROPE] = {
IF feature = NIL THEN RETURN["nothing"]
ELSE {
SELECT feature.type FROM
outline, slice => rope ← Rope.Concat[Atom.GetPName[NARROW[feature.shape, SliceDescriptor].slice.class.type], " slice"];
distanceLine => rope ← "distance line";
slopeLine => rope ← "slope line";
angleLine => rope ← "angle line";
symmetryLine => rope ← "symmetry line";
radiiCircle => rope ← "compass circle";
intersectionPoint => {
firstObj, secondObj: Rope.ROPE;
firstObj ← IF NARROW[feature.shape, AlignmentPoint].curve1 # NIL THEN DescribeSourceFeature[NARROW[feature.shape, AlignmentPoint].curve1, ggData]
ELSE "unknown";
secondObj ← IF NARROW[feature.shape, AlignmentPoint].curve2 # NIL THEN DescribeSourceFeature[NARROW[feature.shape, AlignmentPoint].curve2, ggData]
ELSE "unknown";
rope ← IO.PutFR["a %g/%g intersection point", [rope[firstObj]], [rope[secondObj]] ];
};
midpoint => rope ← IO.PutFR["midpoint of segment ???"];
ENDCASE => ERROR;
};
};
DescribeTraj: PUBLIC PROC [traj: Traj] RETURNS [text: Rope.ROPE] = {
text ←
SELECT traj.role FROM
open => IO.PutFR["a %g-segment open trajectory", [integer[traj.segCount]]],
fence => IO.PutFR["a %g-segment fence", [integer[traj.segCount]]],
hole => IO.PutFR["a %g-segment hole", [integer[traj.segCount]]],
ENDCASE => "";
};
DescribeJoint: PUBLIC PROC [traj: Traj, jointNum: NAT] RETURNS [text: Rope.ROPE] = {
end: BOOL;
end ← GGTraj.IsEndJoint[traj, jointNum];
IF end THEN text ← IO.PutFR["end joint %g on ", [integer[jointNum]] ]
ELSE text ← IO.PutFR["joint %g on ", [integer[jointNum]] ];
text ← Rope.Concat[text, DescribeSegment[traj, IF GGTraj.HiJoint[traj]=jointNum AND traj.role=open THEN jointNum-1 ELSE jointNum]];
Describes one of the possible two segments this joint is on
};
DescribeControlPoint: PUBLIC PROC [traj: Traj, segNum: NAT, cpNum: NAT] RETURNS [text: Rope.ROPE] = {
text ← Rope.Cat[IO.PutFR["control point %g on ", [integer[cpNum]]], DescribeSegment[traj, segNum] ];
};
DescribeSegment: PUBLIC PROC [traj: Traj, segNum: NAT] RETURNS [text: Rope.ROPE] = {
IF segNum=LAST[NAT] THEN text ← Rope.Cat["a segment on ", DescribeTraj[traj]] ELSE {
seg: Segment ← GGTraj.FetchSegment[traj, segNum];
text ← Rope.Cat[seg.class.describe[seg, TRUE, TRUE, TRUE, NIL], IO.PutFR[" segment %g on ", [integer[segNum]]], DescribeTraj[traj]];
text ← Rope.Cat[Atom.GetPName[seg.class.type], IO.PutFR[" segment %g on ", [integer[segNum]]], DescribeTraj[traj]];
};
};
DescribeSequence: PUBLIC PROC [seq: Sequence] RETURNS [text: Rope.ROPE] = {
text ← Rope.Cat[IO.PutFR["One or more parts of "], DescribeTraj[seq.traj]];
};
DescribeItem: PROC [f: IO.STREAM, item: TouchItem] = {
SELECT item.touchingPartType FROM
joint => f.PutF["Item: joint on %g", [rope[DescribeTraj[NARROW[item.traj]]]]];
segment => f.PutF["Item: segment on %g", [rope[DescribeTraj[NARROW[item.traj]]]]];
ENDCASE => ERROR;
};
DescribeTouchGroup: PUBLIC PROC [group: TouchGroup] RETURNS [text: Rope.ROPE] = {
f: IO.STREAM;
touchGen: TouchItemGenerator;
f ← IO.ROS[];
f.PutF["TouchGroup: (%1.2f, %1.2f)\n", [real[group.point.x]], [real[group.point.y]]];
touchGen ← GGTouch.AllTouchItems[group];
FOR item: TouchItem ← GGTouch.NextTouchItem[touchGen], GGTouch.NextTouchItem[touchGen] UNTIL item = NIL DO
f.PutChar[IO.TAB];
DescribeItem[f, item];
f.PutChar[IO.CR];
ENDLOOP;
text ← IO.RopeFromROS[f];
};
END.