File: SVFileInImpl.mesa
Last edited by Bier on September 16, 1987 1:06:00 pm PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Contents: Recreates a 3d database from a 3d text file of the sort produced by Fileout3d.mesa.
Note: When you change this file, you may wish to update versionRope in SVSceneImplA.
DIRECTORY
AtomButtonsTypes, SVCoordSys, GGParseIn, Imager, ImagerColor, IO, Rope, SV2d, SV3d, SVAssembly, SVFileIn, SVMasterObject, SVModelTypes, SVRay, SVScene, SVSceneTypes, SVSweepGeometry, SVParseIn, ViewerClasses;
SVFileInImpl: CEDAR PROGRAM
IMPORTS SVCoordSys, GGParseIn, ImagerColor, IO, Rope, SVAssembly, SVMasterObject, SVRay, SVScene, SVParseIn
EXPORTS SVFileIn =
BEGIN
Artwork: TYPE = SVModelTypes.Artwork;
ArtworkClass: TYPE = SVModelTypes.ArtworkClass;
Color: TYPE = Imager.Color;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CoordSysList: TYPE = SVModelTypes.CoordSysList;
FeedbackData: TYPE = AtomButtonsTypes.FeedbackData;
FileCamera: TYPE = SVSceneTypes.FileCamera;
LightSource: TYPE = SVModelTypes.LightSource;
LightSourceList: TYPE = LIST OF LightSource;
MasterObject: TYPE = SVSceneTypes.MasterObject;
MasterObjectList: TYPE = SVSceneTypes.MasterObjectList;
MasterObjectClass: TYPE = SVSceneTypes.MasterObjectClass;
Material: TYPE = SVModelTypes.Material;
Matrix3by3: TYPE = SV2d.Matrix3by3;
Matrix4by4: TYPE = SV3d.Matrix4by4;
NameList: TYPE = LIST OF Rope.ROPE;
OMap: TYPE = SVModelTypes.OMap;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = SV3d.Point3d;
PointSetOp: TYPE = SVSceneTypes.PointSetOp; -- {union, intersection, difference}
Scene: TYPE = SVSceneTypes.Scene;
Slice: TYPE = SVSceneTypes.Slice;
SliceList: TYPE = SVSceneTypes.SliceList;
SMap: TYPE = SVModelTypes.SMap;
Vector3d: TYPE = SV3d.Vector3d;
Viewer: TYPE = ViewerClasses.Viewer;
LinearMesh: TYPE = REF LinearMeshRecord;
LinearMeshRecord: TYPE = SVSweepGeometry.LinearMeshRecord;
RevoluteMesh: TYPE = REF RevoluteMeshRecord;
RevoluteMeshRecord: TYPE = SVSweepGeometry.RevoluteMeshRecord;
LinearMeshArray: TYPE = SVSweepGeometry.LinearMeshArray;
RevoluteMeshArray: TYPE = SVSweepGeometry.RevoluteMeshArray;
FileinScene: PUBLIC PROC [scene: Scene, f: IO.STREAM, wdirForAIS: Rope.ROPE, feedback: FeedbackData] = {
csList: CoordSysList;
worldCS: CoordSystem;
sceneName: Rope.ROPE;
version: REAL;
restOfVersionRope: Rope.ROPE;
GGParseIn.ReadWRope[f, "File:"];
[] ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWhiteSpace[f];
GGParseIn.ReadWRope[f, "3D file for scene:"];
sceneName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWhiteSpace[f];
GGParseIn.ReadWRope[f, "Produced by Solidviews Version"];
version ← GGParseIn.ReadWReal[f];
restOfVersionRope ← GGParseIn.ReadLine[f];
IF version >= 2.0 THEN ReadOptions[f, scene, version];
IF scene.lightSources = NIL THEN {
ambientLight: LightSource ← SVScene.CreateAmbientLightSource["Ambient", ImagerColor.ColorFromRGB[[0.2,0.2,0.2]]];
scene.lightSources ← CONS[ambientLight, NIL];
};
GGParseIn.ReadBlank[f];
csList ← FileinCoordSystems[f, scene];
FileinLightSources[f, scene];
worldCS ← SVCoordSys.FindCoordSysInList["WORLD", csList];
FileinObjects[f, scene, csList, wdirForAIS, version, feedback];
scene.assembly ← FileinAssembly[f, scene, csList, version, wdirForAIS, feedback];
IF version >= 3.0 THEN FileinCameras[f, scene, csList, version]
ELSE scene.cameras ← SVScene.InitialCameraList[];
IF version >= 3.0 THEN FileinCameraOrder[f, scene]
ELSE scene.cameraOrder ← LIST["Front"];
GGParseIn.ReadBlank[f];
GGParseIn.ReadWRope[f, "END"];
f.Close[];
};
ReadOptions: PROCEDURE [f: IO.STREAM, scene: Scene, version: REAL] = {
keyWord, option: Rope.ROPE;
good: BOOL;
nextChar: CHAR;
twoCRsFound: BOOLFALSE;
GGParseIn.ReadBlank[f];
UNTIL twoCRsFound DO
[keyWord, good] ← SVParseIn.ReadKeyWord[f];
IF NOT good THEN {
nextChar ← IO.PeekChar[f];
IF nextChar = IO.CR THEN {
[] ← IO.GetChar[f];
twoCRsFound ← TRUE;
};
LOOP};
good ← GGParseIn.ReadHorizontalBlank[f];
IF NOT good THEN {
nextChar ← IO.PeekChar[f];
IF nextChar = IO.CR THEN {
[] ← IO.GetChar[f];
twoCRsFound ← TRUE;
};
LOOP};
option ← GGParseIn.ReadLine[f];
ProcessOption[keyWord, option, scene, version];
nextChar ← IO.PeekChar[f];
IF nextChar = IO.CR THEN {
[] ← IO.GetChar[f];
twoCRsFound ← TRUE;
};
ENDLOOP;
};
ProcessOption: PROC [keyWord: Rope.ROPE, option: Rope.ROPE, scene: Scene, version: REAL] = {
SELECT TRUE FROM
Known Options
Rope.Equal[keyWord, "background color", FALSE] => {
scene.backgroundColor ← SVParseIn.ReadColor[IO.RIS[option]];
};
Rope.Equal[keyWord, "shadows", FALSE] => {
good, truth: BOOL;
[truth, good] ← GGParseIn.ReadBool[IO.RIS[option], version];
IF NOT good THEN RETURN;
scene.shadows ← truth;
};
Rope.Equal[keyWord, "ambient", FALSE] => {
color: Color;
ls: LightSource;
color ← SVParseIn.ReadColor[IO.RIS[option]];
ls ← SVScene.CreateAmbientLightSource["Ambient", color];
SVScene.AddLightSourceToScene[ls, scene];
};
ENDCASE;
}; -- end of ProcessOption
FileinCoordSystems: PROC [f: IO.STREAM, scene: Scene] RETURNS [csList: CoordSysList] = {
count: NAT;
mat: Matrix4by4;
newCS: CoordSystem;
csName, wrtName: Rope.ROPE;
csList ← NIL;
GGParseIn.ReadWRope[f, "CoordSystems"];
GGParseIn.ReadWhiteSpace[f];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"]; GGParseIn.ReadWhiteSpace[f];
FOR i: NAT IN[1..count] DO
GGParseIn.ReadWRope[f, "CoordSys:"];
csName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWhiteSpace[f];
GGParseIn.ReadWRope[f, "mat:"];
GGParseIn.ReadBlank[f];
mat ← SVParseIn.FileinMatrix[f];
GGParseIn.ReadWRope[f, "withRespectTo:"];
wrtName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWhiteSpace[f];
SELECT TRUE FROM
Rope.Equal[csName,"WORLD"] => {
newCS ← SVCoordSys.CreateRoot["WORLD"];
WORLD must be defined with respect to NIL, and must be the identity matrix.
scene.coordSysRoot ← newCS;
csList ← AppendToCoordSystems[newCS, csList];
};
Rope.Equal[csName,"SCREEN"] => {};
SCREEN must be in terms of NIL.
The matrix between them must be a translation
SCREEN is ignored since it depends on viewer size and shouldn't be in these files anyway.
ENDCASE => {
Other coord systems are unrestricted. Create them with the new data.
wrtCS: CoordSystem ← SVCoordSys.FindCoordSysInList[wrtName, csList];
newCS ← SVCoordSys.CreateCoordSysInTree[csName,mat,wrtCS,scene.coordSysRoot];
csList ← AppendToCoordSystems[newCS, csList];
};
All coordinate systems other than screen and world will be added to the scene's coord sys list (not the same as csList!) when assemblies (see FileinAssemblies) are added.
ENDLOOP;
}; -- end of FileinCoordSystems
AppendToCoordSystems: PROC [cs: CoordSystem, list: CoordSysList] RETURNS [CoordSysList] = {
A copy of List.Nconc1 for CoordSysList instead of LIST OF REF ANY
z: CoordSysList ← list;
IF z = NIL THEN RETURN[CONS[cs,NIL]];
UNTIL z.rest = NIL DO z ← z.rest; ENDLOOP;
z.rest ← CONS[cs,NIL];
RETURN[list];
};
FileinLightSources: PROC [f: IO.STREAM, scene: Scene] = {
count: NAT;
thisLS: LightSource;
lsName: Rope.ROPE;
point3d: Point3d;
color: Color;
GGParseIn.ReadWRope[f, "LightSources"];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"]; GGParseIn.ReadWhiteSpace[f];
FOR i: NAT IN[1..count] DO
GGParseIn.ReadWRope[f, "LightSource:"];
lsName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWRope[f, "position:"];
GGParseIn.ReadBlank[f];
point3d ← SVParseIn.ReadPoint3d[f];
GGParseIn.ReadWRope[f, "color:"];
GGParseIn.ReadBlank[f];
color ← SVParseIn.ReadColor[f];
GGParseIn.ReadWhiteSpace[f];
thisLS ← SVScene.CreateLightSource[lsName, point3d, color];
SVScene.AddLightSourceToScene[thisLS, scene];
ENDLOOP;
};
FileinCameras: PROC [f: IO.STREAM, scene: Scene, csList: CoordSysList, version: REAL] = {
worldCS: CoordSystem ← SVCoordSys.FindCoordSysInList["WORLD", csList];
count: NAT;
fileCamera: FileCamera;
GGParseIn.ReadWRope[f, "Cameras"];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"]; GGParseIn.ReadWhiteSpace[f];
FOR i: NAT IN[1..count] DO
fileCamera ← SVParseIn.ReadCamera[f, worldCS, scene, version];
SVScene.AddCameraToScene[fileCamera, scene];
ENDLOOP;
};
FileinCameraOrder: PROC [f: IO.STREAM, scene: Scene] = {
count: NAT;
fileCameraName: Rope.ROPE;
GGParseIn.ReadWRope[f, "Initial Camera Order"];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"];
IF count > 0 THEN {
fileCameraName ← GGParseIn.ReadWWord[f];
SVScene.AddCameraOrderNameToScene[fileCameraName, scene];
FOR i: NAT IN[2..count] DO
GGParseIn.ReadWRope[f, ","];
fileCameraName ← GGParseIn.ReadWWord[f];
SVScene.AddCameraOrderNameToScene[fileCameraName, scene];
ENDLOOP;
};
GGParseIn.ReadBlank[f];
};
FileinAssembly: PROC [f: IO.STREAM, scene: Scene, csList: CoordSysList, version: REAL, wdirForAIS: Rope.ROPE, feedback: FeedbackData] RETURNS [thisA: Slice] = {
thisCS: CoordSystem;
artwork: Artwork;
scalars: Vector3d;
primOrComp: Rope.ROPE;
asName, csName, opRope, chairName: Rope.ROPE;
pointSetOp: PointSetOp;
subAssemblies: LIST OF Slice;
GGParseIn.ReadWRope[f, "Assembly:"];
asName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWRope[f, ","];
GGParseIn.ReadWRope[f, "coordSys:"];
csName ← GGParseIn.ReadWWord[f];
thisCS ← SVCoordSys.FindCoordSysInList[csName, csList];
GGParseIn.ReadWRope[f, ","];
primOrComp ← GGParseIn.ReadWWord[f];
SELECT TRUE FROM
Rope.Equal[primOrComp, "Composite", FALSE] => {
GGParseIn.ReadWRope[f, "artwork:"];
GGParseIn.ReadBlank[f];
artwork ← SVParseIn.ReadArtwork[f, csList, thisCS, wdirForAIS, version, feedback];
GGParseIn.ReadWRope[f, "subassemblies"];
GGParseIn.ReadWRope[f, "["];
IF version < 5.2 THEN GGParseIn.ReadWRope[f, "point set op:"];
opRope ← GGParseIn.ReadWWord[f];
pointSetOp ← SVRay.RopeToPointSetOp[opRope];
GGParseIn.ReadWRope[f, "]"];
GGParseIn.ReadWhiteSpace[f];
[] ← FileinSubassemblyNames[f];
thisA ← SVAssembly.CreateClusterAssemblyAtExistingCoordSys[asName, pointSetOp, scene, thisCS, FALSE, NIL];
thisA.artwork ← artwork;
subAssemblies ← FileinAssemblies[f, scene, csList, version, wdirForAIS, feedback];
WireUpAssemblyToSubassemblies[thisA, subAssemblies, scene];
};
Rope.Equal[primOrComp, "Primitive", FALSE] => {
obName: Rope.ROPE;
masterObjectFound: BOOL;
GGParseIn.ReadWRope[f, "scalars:"];
GGParseIn.ReadBlank[f];
scalars ← SVParseIn.ReadPoint3d[f];
GGParseIn.ReadWRope[f, "artwork:"];
GGParseIn.ReadBlank[f];
artwork ← SVParseIn.ReadArtwork[f, csList, thisCS, wdirForAIS, version, feedback];
GGParseIn.ReadWRope[f, "object:"];
obName ← GGParseIn.ReadWWord[f];
[thisA, masterObjectFound] ←
SVAssembly.CreatePrimitiveAtExistingCoordSys[asName, obName, scalars, scene, thisCS, artwork, FALSE, NIL];
IF NOT masterObjectFound THEN ERROR MasterObjectNotFound;
IF version >= 5.3 AND Rope.Equal[obName, "jack", FALSE] THEN {
GGParseIn.ReadWRope[f, "sittingOn:"];
chairName ← GGParseIn.ReadWWord[f];
IF Rope.Equal[chairName, "NIL", FALSE] THEN thisA.sittingOn ← NIL
ELSE thisA.sittingOn ← chairName;
};
};
ENDCASE => SIGNAL ErrorInAssemblyFileout;
}; -- end of FileinAssembly
MasterObjectNotFound: PUBLIC ERROR = CODE;
FileinAssemblies: PROC [f: IO.STREAM, scene: Scene, csList: CoordSysList, version: REAL, wdirForAIS: Rope.ROPE, feedback: FeedbackData] RETURNS [asList: LIST OF Slice] = {
count: NAT;
thisA: Slice;
asList ← NIL;-- initially
GGParseIn.ReadWRope[f, "Subassemblies"];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"]; GGParseIn.ReadWhiteSpace[f];
FOR i: NAT IN[1..count] DO
thisA ← FileinAssembly[f, scene, csList, version, wdirForAIS, feedback];
asList ← AppendToAssemblyList[thisA, asList];
ENDLOOP;
};
ErrorInAssemblyFileout: PUBLIC SIGNAL = CODE;
WireUpAssemblyToSubassemblies: PROC [assem: Slice, subA: LIST OF Slice, scene: Scene] = {
thisSub: Slice;
FOR al: LIST OF Slice ← subA, al.rest UNTIL al = NIL DO
thisSub ← al.first;
SVAssembly.ConnectAssemblyToParent[thisSub, assem];
ENDLOOP;
};
AppendToAssemblyList: PROC [as: Slice, list: LIST OF Slice] RETURNS [LIST OF Slice] = {
A copy of List.Nconc1 for AssemblyListObj instead of LIST OF REF ANY
z: LIST OF Slice ← list;
IF z = NIL THEN RETURN[CONS[as,NIL]];
UNTIL z.rest = NIL DO z ← z.rest; ENDLOOP;
z.rest ← CONS[as,NIL];
RETURN[list];
};
AppendToNameList: PROC [name: Rope.ROPE, list: NameList] RETURNS [NameList] = {
A copy of List.Nconc1 for NameList instead of LIST OF REF ANY.
z: NameList ← list;
IF z = NIL THEN RETURN[CONS[name,NIL]];
UNTIL z.rest = NIL DO z ← z.rest; ENDLOOP;
z.rest ← CONS[name,NIL];
RETURN[list];
};
FileinSubassemblyNames: PROC [f: IO.STREAM] RETURNS [nameList: NameList] = {
count: NAT;
thisName: Rope.ROPE;
nameList ← NIL;
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"];
GGParseIn.ReadWRope[f, "("];
IF count = 0 THEN {GGParseIn.ReadWRope[f, ")"]; RETURN;};
thisName ← GGParseIn.ReadWWord[f];
nameList ← AppendToNameList[thisName, nameList];
FOR i: NAT IN[2..count] DO
GGParseIn.ReadWRope[f, ", "];
thisName ← GGParseIn.ReadWWord[f];
nameList ← AppendToNameList[thisName, nameList];
ENDLOOP;
GGParseIn.ReadWRope[f, ")"];
GGParseIn.ReadWhiteSpace[f];
};
FileinObjects: PROC [f: IO.STREAM, scene: Scene, csList: CoordSysList, wdir: Rope.ROPE, version: REAL, feedback: FeedbackData] = {
count: NAT;
obName, obClass: Rope.ROPE;
moClass: MasterObjectClass;
moClassFound: BOOL;
mo: MasterObject;
GGParseIn.ReadWRope[f, "Objects"];
GGParseIn.ReadWRope[f, "["];
count ← GGParseIn.ReadWNAT[f];
GGParseIn.ReadWRope[f, "]:"];
GGParseIn.ReadWhiteSpace[f];
FOR i: NAT IN[1..count] DO
GGParseIn.ReadWRope[f, "Master Object:"];
obName ← GGParseIn.ReadWWord[f];
GGParseIn.ReadWhiteSpace[f];
GGParseIn.ReadWRope[f, "class:"];
obClass ← GGParseIn.ReadWWord[f];
GGParseIn.ReadBlank[f];
[moClass, moClassFound] ← SVMasterObject.FindClassFromName[obClass];
IF NOT moClassFound THEN ERROR MasterObjectClassNotFound;
mo ← moClass.filein[f, obName, csList, scene.coordSysRoot, wdir, version, feedback];
SVScene.AddMasterObjectToScene[mo, scene];
ENDLOOP;-- next master object
GGParseIn.ReadBlank[f];
}; -- end of FileinObjects
MasterObjectClassNotFound: PUBLIC ERROR = CODE;
END.