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: BOOL _ FALSE; 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 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"]; scene.coordSysRoot _ newCS; csList _ AppendToCoordSystems[newCS, csList]; }; Rope.Equal[csName,"SCREEN"] => {}; ENDCASE => { wrtCS: CoordSystem _ SVCoordSys.FindCoordSysInList[wrtName, csList]; newCS _ SVCoordSys.CreateCoordSysInTree[csName,mat,wrtCS,scene.coordSysRoot]; csList _ AppendToCoordSystems[newCS, csList]; }; ENDLOOP; }; -- end of FileinCoordSystems AppendToCoordSystems: PROC [cs: CoordSystem, list: CoordSysList] RETURNS [CoordSysList] = { 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] = { 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] = { 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. File: SVFileInImpl.mesa Last edited by Bier on September 16, 1987 1:06:00 pm PDT Copyright c 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. Known Options WORLD must be defined with respect to NIL, and must be the identity matrix. 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. Other coord systems are unrestricted. Create them with the new data. 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. A copy of List.Nconc1 for CoordSysList instead of LIST OF REF ANY A copy of List.Nconc1 for AssemblyListObj instead of LIST OF REF ANY A copy of List.Nconc1 for NameList instead of LIST OF REF ANY. Κl– "cedar" style˜Iheadšœ™Iprocšœ8™8Jšœ Οmœ1™žœ˜Π—L˜šœž ˜Jšžœ%žœ=˜kLšžœ ˜—Lšž˜˜Lšœ žœ˜%Lšœžœ˜/Lšœžœ˜Lšœ žœ˜-Lšœžœ˜/Lšœžœ!˜3Lšœ žœ˜+Lšœ žœ˜-Lšœžœžœžœ ˜,Lšœžœ˜/Lšœžœ!˜7Lšœžœ"˜9Lšœ žœ˜'Lšœ žœ˜#Lšœ žœ˜#Lš œ žœžœžœžœ˜#Lšœžœ˜Lšœ žœ˜Lšœ žœ˜Lšœ žœΟc%˜PLšœžœ˜!Lšœžœ˜!Lšœ žœ˜)Lšœžœ˜Lšœ žœ˜Jšœžœ˜$L˜Lšœ žœžœ˜(Lšœžœ$˜:Lšœžœžœ˜,Lšœžœ&˜>L˜Lšœžœ#˜8Lšœžœ%˜˜>Lšœ,˜,—Lšžœ˜Lšœ˜—š œžœžœžœ˜8Lšœžœ˜ Lšœžœ˜L˜/Lšœ˜Lšœ˜Lšœ˜šžœ žœ˜Lšœ(˜(Lšœ9˜9šžœžœžœ ž˜L˜Lšœ(˜(Lšœ9˜9—Lšžœ˜L˜Lšœ˜—Lšœ˜—š œžœžœžœ/žœžœžœ˜ Lšœ˜Lšœ˜Lšœ˜Lšœžœ˜Lšœ(žœ˜-Lšœ˜Lšœžœžœ˜L˜Lšœ$˜$Lšœ ˜ Lšœ˜Lšœ$˜$Lšœ ˜ Lšœ7˜7Lšœ˜Lšœ$˜$Lšžœžœž˜šœ$žœ˜/Lšœ#˜#Lšœ˜Lšœ ‘œ3˜RLšœ(˜(Lšœ˜Lšžœžœ)˜>Lšœ ˜ Lšœ žœ˜,Lšœ˜Lšœ˜Lšœ˜Lšœ^žœžœ˜jLšœ˜LšœR˜RLšœ;˜;Lšœ˜—šœ$žœ˜/Lšœ žœ˜Lšœžœ˜Lšœ#˜#Lšœ˜Lšœ#˜#Lšœ#˜#Lšœ˜Lšœ ‘œ3˜RLšœ"˜"Lšœ ˜ šœ˜Lšœ^žœžœ˜j—Lšžœžœžœžœ˜9šžœžœžœž˜>Lšœ%˜%Lšœ#˜#Lšžœžœžœž˜ALšžœ˜!L˜—Lšœ˜—Lšžœžœ˜)LšœŸ˜—Lšœžœžœžœ˜*L˜š œžœžœžœ/žœžœžœ žœžœ ˜«Lšœžœ˜ Lšœ ˜ Lšœ žœŸ ˜Lšœ(˜(Lšœ˜Lšœ˜Lšœ;˜;šžœžœžœ ž˜LšœH˜HLšœ-˜-Lšžœ˜—Lšœ˜—Lšœžœžœžœ˜-š œžœžœžœ˜YLšœ˜š žœžœžœžœžœž˜7Lšœ˜Lšœ3˜3—Lšžœ˜Lšœ˜—š œžœžœžœžœžœžœ ˜WLšœD™DLšœžœžœ˜Lš žœžœžœžœžœžœ˜%šžœ žœžœ žœ˜*Lšœ žœžœ˜—Lšžœ˜ Lšœ˜—š œžœ žœžœ˜OLšœ>™>Lšœ˜Lš žœžœžœžœžœžœ˜'šžœ žœžœ žœ˜*Lšœ žœžœ˜—Lšžœ˜ Lšœ˜—š  œžœžœžœžœ˜LLšœžœ˜ Lšœžœ˜Lšœ žœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ˜Lšžœ žœžœ˜9Lšœ"˜"Lšœ0˜0šžœžœžœ ž˜Lšœ˜Lšœ"˜"Lšœ0˜0Lšžœ˜—Lšœ˜Lšœ˜Lšœ˜L˜—š   œžœžœžœ1žœ žœ˜‚Lšœžœ˜ Lšœžœ˜Lšœ˜Lšœžœ˜Lšœ˜L˜Lšœ"˜"Lšœ˜Lšœ˜Lšœ˜Lšœ˜šžœžœžœ ž˜Lšœ)˜)Lšœ ˜ Lšœ˜Lšœ!˜!Lšœ!˜!Lšœ˜LšœD˜DLšžœžœžœžœ˜9LšœT˜TLšœ*˜*LšžœŸ˜—Lšœ˜LšœŸ˜—Lšœžœžœžœ˜/L˜Lšžœ˜—…—2ΐF,