DIRECTORY DisplayList3d, Filein3d, Fileout3d, FileNames, FS, IO, MessageWindow, Rope, SVArtwork, SVError, SVFiles, SVTransforms, SVSceneTypes, TFI3d; SVFilesImpl: PROGRAM IMPORTS DisplayList3d, Filein3d, Fileout3d, FileNames, FS, IO, MessageWindow, Rope, SVArtwork, SVError, SVTransforms, TFI3d EXPORTS SVFiles = BEGIN Scene: TYPE = SVSceneTypes.Scene; SceneTable: TYPE = LIST OF Scene; FindScene: PRIVATE PROC [name: Rope.ROPE, table: SceneTable] RETURNS [scene: Scene, success: BOOL] = { success _ FALSE; FOR list: SceneTable _ table, list.rest UNTIL list = NIL OR success DO IF Rope.Equal[s1: name, s2: list.first.name, case: TRUE] THEN { success _ TRUE; scene _ list.first; }; ENDLOOP; }; AddSceneToTable: PRIVATE PROC [scene: Scene, table: SceneTable] RETURNS [newtable: SceneTable] = { newtable _ CONS[scene, table]; }; OpenScene: PUBLIC PROC [picName: Rope.ROPE, wdirForAIS: Rope.ROPE] RETURNS [scene: Scene, success: BOOL] = { f: IO.STREAM; [f, success] _ OpenFile[picName]; IF NOT success THEN RETURN; -- OpenFile prints any error messages. [scene, success] _ MakeScene[f, picName, wdirForAIS]; -- MakeScene will print any error messages }; OpenFile: PUBLIC PROC [picName: Rope.ROPE] RETURNS [f: IO.STREAM, success: BOOL] = { success _ TRUE; f _ FS.StreamOpen[picName ! FS.Error => CHECKED { IF error.group = user THEN { success _ FALSE; SVError.Append["Picture file problem: ", TRUE]; SVError.Append[error.explanation]; } ELSE ERROR; CONTINUE}]; }; -- end of OpenFile MakeScene: PRIVATE PROC [f: IO.STREAM, picName: Rope.ROPE, wdirForAIS: Rope.ROPE] RETURNS [scene: Scene, success: BOOL] = { errorPos: NAT; errorRope, expected, actual: Rope.ROPE; fileNotFound: BOOL _ FALSE; allMapsFound: BOOL _ TRUE; success _ TRUE; scene _ DisplayList3d.CreateEmptyScene[picName]; SVError.Append["Reading scene: ",TRUE]; SVError.Append[scene.name]; SVError.Append[" from file: "]; SVError.Append[picName]; SVError.Append["..."]; Filein3d.FileinScene [scene, f, wdirForAIS !TFI3d.RopeNotOnTop => { success _ FALSE; errorPos _ position; expected _ notThere; actual _ wasThere; CONTINUE}; SVArtwork.FileNotFound => {allMapsFound _ FALSE; CONTINUE} ]; IF NOT allMapsFound THEN { errorRope _ IO.PutFR["Some AIS mapping file not found"]; SVError.Append[errorRope, TRUE, TRUE]; success _ FALSE; RETURN }; IF NOT success THEN { errorRope _ IO.PutFR["At %g in %g expected '%g' not '%g'", [integer[errorPos]], [rope[picName]], [rope[expected]], [rope[actual]]]; SVError.Append[errorRope, TRUE, TRUE]; RETURN } ELSE SVError.Append["Done", FALSE, TRUE]; }; -- end of MakeScene SaveScene: PUBLIC PROC [updatedScene: Scene, picName: Rope.ROPE] RETURNS [success: BOOL] = { f: IO.STREAM; success _ TRUE; IF FileExists[picName] THEN { f _ FS.StreamOpen[picName, $create ! FS.Error => CHECKED { IF error.group = user THEN { success _ FALSE; SVError.Append["Pic file problem: ", TRUE]; SVError.Append[error.explanation]; SVError.Blink[]; CONTINUE} ELSE ERROR}]; IF success THEN { SVTransforms.TidyUpCoordSysTree[updatedScene.coordSysRoot]; SaveFile[updatedScene, f, picName]; }; } ELSE { SVError.Append["File not found. Use Store.", TRUE]; SVError.Blink[]; }; }; SaveFile: PRIVATE PROC [scene: Scene, f: IO.STREAM, picName: Rope.ROPE] = { SVError.Append["Writing scene: ",TRUE]; SVError.Append[scene.name]; SVError.Append[" to file: "]; SVError.Append[picName]; SVError.Append["..."]; Fileout3d.FileoutScene [scene, f, picName]; scene.dirty _ FALSE; SVError.Append["Done",FALSE,TRUE]; }; -- end of SaveFile StoreScene: PUBLIC PROC [unNamedScene: Scene, newPicName: Rope.ROPE] RETURNS [success: BOOL] = { f: IO.STREAM; fileAlreadyExists: BOOL _ FALSE; confirmation: BOOL _ FALSE; success _ FALSE; IF FileExists[newPicName] THEN { confirmation _ MessageWindow.Confirm["Confirm overwrite of existing pic file"]; IF confirmation THEN f _ FS.StreamOpen[newPicName, $create] ELSE RETURN; } ELSE f _ FS.StreamOpen[newPicName, $create]; SVError.Append["Writing scene: ",TRUE]; SVError.Append[newPicName]; SVError.Append[" to file: "]; SVError.Append[newPicName]; SVError.Append["..."]; SVTransforms.TidyUpCoordSysTree[unNamedScene.coordSysRoot]; Fileout3d.FileoutScene [unNamedScene, f, newPicName]; SVError.Append["Done", FALSE, TRUE]; success _ TRUE; unNamedScene.dirty _ FALSE; unNamedScene.name _ newPicName; }; -- end of StoreScene FileExists: PUBLIC PROC [fileName: Rope.ROPE] RETURNS [answer: BOOL] = { answer _ TRUE; [----, ----, ----, ----] _ FS.FileInfo[fileName ! FS.Error => {IF error.code = $unknownFile THEN {answer _ FALSE; CONTINUE} ELSE ERROR}]; }; FilenameMinusExtension: PUBLIC PROC [wholeName: Rope.ROPE] RETURNS [firstPart: Rope.ROPE] = { directory, shortName, shortNameMinusExtension: Rope.ROPE; shortNameStream: IO.STREAM; directory _ FileNames.Directory[wholeName]; shortName _ FileNames.GetShortName[wholeName, TRUE]; shortNameStream _ IO.RIS[shortName]; [shortNameMinusExtension, ----] _ IO.GetTokenRope[shortNameStream, PeriodBreakProc]; firstPart _ Rope.Concat[directory, shortNameMinusExtension]; }; PeriodBreakProc: SAFE PROC [char: CHAR] RETURNS [IO.CharClass] = TRUSTED { SELECT char FROM '.=> RETURN[sepr]; ENDCASE => RETURN[other]; }; END. PFile: SVFilesImpl.mesa Last edited by: Eric Bier on January 2, 1985 5:22:31 pm PST Copyright c 1984 by Xerox Corporation. All rights reserved. Contents: Interfaces which make creating scenes look like opening files. Look for the pic file on the local disk. If there, read in the scene. If not, Tell the user "file not found" and return success = false. Now we must turn the text file into a scene. Two possiblilities 1) File doesn't exist. Print error message. 2) File does exist. File it in. Succeed. Check local disk to see that we have a scene with this name. If so, save it as a file on the local disk after confirmation. scene.dirty _ FALSE. If not, SVError "File not found. Use Store." and return success = FALSE. Check the local disk for this name. Ask for confirmation to store to new (or old) file. Store if confirmed. ΚG– "cedar" style˜Ihead1šœ™Iprocšœ;™;Jšœ Οmœ1™˜{Lšžœ ˜—L˜Lšž˜˜Lšœžœ˜!Lšœ žœžœžœ˜!L˜—š Οn œžœžœ žœžœžœ˜fLšœ žœ˜š žœ%žœžœžœ ž˜Fšžœ1žœžœ˜?Lšœ žœ˜Lšœ˜Lšœ˜—Lšžœ˜—Lšœ˜—L˜šŸœžœžœ#žœ˜bLšœ žœ˜Lšœ˜—L˜šŸ œžœžœžœžœžœžœ˜lLšœŠ™ŠLšœžœžœ˜ Lšœ!˜!Lš žœžœ žœžœΟc&˜BLšœ,™,Lšœ6 *˜`Lšœ˜—L˜L˜šŸœžœžœžœžœžœžœ žœ˜TLšœ žœ˜L˜šœ™Lšœ-™-Lšœ+™+—L˜šœžœ˜šœžœ žœ˜šžœžœ˜Lšœ žœ˜Lšœ)žœ˜/Lšœ"˜"Lšœ˜—Lšžœžœ˜ Lšžœ˜ ——Lšœ ˜—L˜šŸ œžœžœžœžœžœžœžœžœ˜{Lšœ žœ˜Lšœ"žœ˜'Lšœžœžœ˜Lšœžœžœ˜Lšœ žœ˜Lšœ0˜0L˜Lšœ!žœ˜'Lšœ˜Lšœ˜Lšœ˜Lšœ˜šœ*˜*šœ˜Lšœ žœ+˜:Lšœžœ˜—Lšœ+žœžœ˜;Lšœ˜—šžœžœžœ˜Lšœ žœ*˜8Lšœžœžœ˜&Lšœ žœ˜Lšž˜Lšœ˜—šžœžœ žœ˜Lšœ žœu˜ƒLšœžœžœ˜&Lšž˜Lšœ˜—Lšžœžœžœ˜)Lšœ ˜—L˜š Ÿ œžœžœ%žœžœ žœ˜\Lšœ’™’LšœI™ILšœžœžœ˜ Lšœ žœ˜šžœžœ˜Lšœžœ˜"šœžœ žœ˜šžœžœ˜Lšœ žœ˜Lšœ%žœ˜+Lšœ"˜"Lšœ˜Lšžœ˜ —Lšœžœžœ˜—šžœ žœ˜Lšœ;˜;Lšœ#˜#L˜—L˜—šžœ˜Lšœ-žœ˜3Lšœ˜Lšœ˜—Lšœ˜—L˜š Ÿœžœžœžœžœžœ˜KLšœ!žœ˜'Lšœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ+˜+Lšœžœ˜Lšœžœžœ˜"Lšœ ˜—L˜š Ÿ œžœžœ(žœžœ žœ˜`Lšœm™mLšœžœžœ˜ Lšœžœžœ˜ Lšœžœžœ˜Lšœ žœ˜L˜šžœžœ˜ LšœO˜Ošžœžœ˜Lšœžœ ˜&—Lšžœžœ˜ Lšœ˜—Lšžœžœ!˜,Lšœ!žœ˜'Lšœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ;˜;Lšœ5˜5Lšœžœžœ˜$Lšœ žœ˜Lšœžœ˜Lšœ˜Lšœ ˜—L˜L˜š Ÿ œžœžœžœžœ žœ˜HLšœ žœ˜š œ œ œ œ œžœ˜/Lš œžœ žœžœ žœžœ˜LLšœžœžœ˜—Jšœ˜—J˜š Ÿœžœžœžœžœžœ˜]Jšœ4žœ˜9Jšœžœžœ˜Jšœ+˜+Jšœ.žœ˜4Jšœžœžœ ˜$Jšœ œžœ0˜TJšœ<˜