File: GGFileOutImpl.mesa
Last edited by Bier on January 28, 1987 8:54:58 pm PST
Copyright © 1986 by Xerox Corporation. All rights reserved.
Contents: Facilities for creating text files and writing out a human-readable version of a gargoyle object database
Pier, February 11, 1987 8:19:33 am PST
DIRECTORY
Atom, FileNames, GGBasicTypes, AtomButtons, GGError, GGFileOut, GGInterfaceTypes, GGModelTypes, GGObjects, GGParseOut, GGSegmentTypes, IO, Rope;
GGFileOutImpl: CEDAR PROGRAM
IMPORTS Atom, FileNames, AtomButtons, GGError, GGObjects, GGParseOut, IO
EXPORTS GGFileOut =
BEGIN
EntityGenerator: TYPE = GGModelTypes.EntityGenerator;
FenceHoleOpen: TYPE = GGModelTypes.FenceHoleOpen;
GargoyleData: TYPE = GGInterfaceTypes.GargoyleData;
Outline: TYPE = GGModelTypes.Outline;
Point: TYPE = GGBasicTypes.Point;
ScalarButtonClient: TYPE = AtomButtons.ScalarButtonClient;
Scene: TYPE = GGModelTypes.Scene;
Segment: TYPE = GGSegmentTypes.Segment;
Slice: TYPE = GGModelTypes.Slice;
Traj: TYPE = GGModelTypes.Traj;
TwoState: TYPE = AtomButtons.TwoState;
Problem: PUBLIC SIGNAL [msg: Rope.ROPE] = GGError.Problem;
versionRope: Rope.ROPE;
Init: PROC [] ~ {
versionRope ← "8610.29";
versionRope ← "8612.04";
versionRope ← "8701.13";
versionRope ← "8701.135";
versionRope ← "8701.23";
versionRope ← "8701.26";
versionRope ← "8701.28";
versionRope ← "8701.30";
versionRope ← "8702.11";
};
FileoutSceneAndOptions: PUBLIC PROC [f: IO.STREAM, gargoyleData: GargoyleData, fileName: Rope.ROPE] = {
entityGen: EntityGenerator ← GGObjects.TopLevelEntitiesInScene[gargoyleData.scene];
entityCount: NAT ← GGObjects.EntityCount[entityGen];
fileName ← FileNames.GetShortName[fileName];
f.PutF["Gargoyle file for scene: %g\n", [rope[fileName]]];
f.PutF["Produced by version %g\n\n", [rope[versionRope]]];
FileoutAlignments[f, gargoyleData];
f.PutF["Entities: [%g]:\n\n", [integer[entityCount]]];
FOR entity: REF ANY ← GGObjects.NextEntity[entityGen], GGObjects.NextEntity[entityGen] UNTIL entity = NIL DO
FileoutEntity[f, entity];
ENDLOOP;
};
FileoutSceneOnly: PUBLIC PROC [f: IO.STREAM, scene: Scene, fileName: Rope.ROPE] = {
entityGen: EntityGenerator ← GGObjects.TopLevelEntitiesInScene[scene];
entityCount: NAT ← GGObjects.EntityCount[entityGen];
fileName ← FileNames.GetShortName[fileName];
f.PutF["Gargoyle file for scene: %g\n", [rope[fileName]]];
f.PutF["Produced by version %g\n\n", [rope[versionRope]]];
FileoutAlignments[f, gargoyleData];
f.PutChar[IO.CR];
f.PutChar[IO.CR];
f.PutF["Entities: [%g]:\n\n", [integer[entityCount]]];
FOR entity: REF ANY ← GGObjects.NextEntity[entityGen], GGObjects.NextEntity[entityGen] UNTIL entity = NIL DO
FileoutEntity[f, entity];
ENDLOOP;
};
PrintButtonValues: PROC [f: IO.STREAM, firstButton: ScalarButtonClient] = {
IF firstButton = NIL THEN SIGNAL Problem[msg: "There should always be a dummy first button."];
firstButton ← firstButton.next;
IF firstButton # NIL THEN {
f.PutF["%g", [real[firstButton.value]]];
FOR thisButton: ScalarButtonClient ← firstButton.next, thisButton.next UNTIL thisButton = NIL DO
f.PutF[", %g", [real[thisButton.value]]];
ENDLOOP;
};
};
FileoutAlignments: PROC [f: IO.STREAM, gargoyleData: GargoyleData] = {
firstButton: ScalarButtonClient;
stateInfo: TwoState;
midPointsOn: BOOL;
f.PutF["Slope: "];
firstButton ← gargoyleData.hitTest.slopeHeader.scalarButtons;
PrintButtonValues[f, firstButton];
f.PutChar[IO.CR];
f.PutF["Angle: "];
firstButton ← gargoyleData.hitTest.angleHeader.scalarButtons;
PrintButtonValues[f, firstButton];
f.PutChar[IO.CR];
f.PutF["Radius: "];
firstButton ← gargoyleData.hitTest.radiusHeader.scalarButtons;
PrintButtonValues[f, firstButton];
f.PutChar[IO.CR];
f.PutF["LineDistance: "];
firstButton ← gargoyleData.hitTest.distanceHeader.scalarButtons;
PrintButtonValues[f, firstButton];
f.PutChar[IO.CR];
f.PutF["Midpoints: "];
stateInfo ← gargoyleData.hitTest.midpointButton;
midPointsOn ← AtomButtons.GetButtonState[stateInfo] = on;
GGParseOut.WriteBOOL[f, midPointsOn];
f.PutChar[IO.CR];
f.PutChar[IO.CR];
};
CountEntities: PROC [entities: LIST OF REF ANY] RETURNS [count: NAT] = {
count ← 0;
FOR list: LIST OF REF ANY ← entities, list.rest UNTIL list = NIL DO
count ← count + 1;
ENDLOOP;
};
FileoutEntity: PROC [f: IO.STREAM, entity: REF ANY] = {
WITH entity SELECT FROM
slice: Slice => FileoutSlice[f, slice];
outline: Outline => outline.class.fileout[outline, f];
ENDCASE => ERROR;
};
FileoutSlice: PUBLIC PROC [f: IO.STREAM, slice: Slice] = {
className: Rope.ROPE ← Atom.GetPName[slice.class.type];
f.PutF["Slice (class: %g) [%g]:\n", [rope[className]], [integer[0]]];
f.PutF["Data: "];
slice.class.fileout[slice, f];
f.PutChar[IO.CR];
f.PutChar[IO.CR];
};
Init[];
END.