DIRECTORY AtomButtonsTypes, Feedback, FileNames, FS, IO, MessageWindow, Rope, SVArtwork, SVFileIn, SVFileOut, SVFiles, SVScene, SVSceneTypes, SVTransforms, TFI3d, ViewerClasses; SVFilesImpl: CEDAR PROGRAM IMPORTS SVScene, SVFileIn, SVFileOut, FileNames, FS, IO, MessageWindow, Rope, SVArtwork, Feedback, SVTransforms, TFI3d EXPORTS SVFiles = BEGIN FeedbackData: TYPE = AtomButtonsTypes.FeedbackData; Scene: TYPE = SVSceneTypes.Scene; SceneTable: TYPE = LIST OF Scene; Viewer: TYPE = ViewerClasses.Viewer; 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, feedback: FeedbackData] RETURNS [scene: Scene, success: BOOL] = { f: IO.STREAM; [f, success] _ OpenFile[picName, feedback]; IF NOT success THEN RETURN; -- OpenFile prints any error messages. [scene, success] _ MakeScene[f, picName, wdirForAIS, feedback]; -- MakeScene will print any error messages }; OpenFile: PUBLIC PROC [picName: Rope.ROPE, feedback: FeedbackData] RETURNS [f: IO.STREAM, success: BOOL] = { success _ TRUE; f _ FS.StreamOpen[picName ! FS.Error => { IF error.group = user THEN { success _ FALSE; Feedback.PutF[feedback, oneLiner, "Picture file problem: %g", [rope[error.explanation]]]; } ELSE ERROR; CONTINUE}]; }; -- end of OpenFile MakeScene: PRIVATE PROC [f: IO.STREAM, picName: Rope.ROPE, wdirForAIS: Rope.ROPE, feedback: FeedbackData] RETURNS [scene: Scene, success: BOOL] = { errorPos: NAT; errorRope, expected, actual: Rope.ROPE; fileNotFound: BOOL _ FALSE; allMapsFound: BOOL _ TRUE; success _ TRUE; scene _ SVScene.CreateEmptyScene[picName]; Feedback.PutF[feedback, begin, "Reading file: %g...", [rope[picName]]]; SVFileIn.FileinScene [scene, f, wdirForAIS, feedback !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"]; Feedback.Append[feedback, errorRope, oneLiner]; 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]]]; Feedback.Append[feedback, errorRope, oneLiner]; RETURN } ELSE Feedback.Append[feedback, "Done", end]; }; -- end of MakeScene SaveScene: PUBLIC PROC [updatedScene: Scene, picName: Rope.ROPE, feedback: FeedbackData] RETURNS [success: BOOL] = { f: IO.STREAM; success _ TRUE; IF FileExists[picName] THEN { f _ FS.StreamOpen[picName, $create ! FS.Error => { IF error.group = user THEN { success _ FALSE; Feedback.PutF[feedback, oneLiner, "Pic file problem: %g", [rope[error.explanation]]]; Feedback.Blink[feedback]; CONTINUE} ELSE ERROR}]; IF success THEN { SVTransforms.TidyUpCoordSysTree[updatedScene.coordSysRoot]; SaveFile[updatedScene, f, picName, feedback]; }; } ELSE { Feedback.Append[feedback, "File not found. Use Store.", oneLiner]; Feedback.Blink[feedback]; }; }; SaveFile: PROC [scene: Scene, f: IO.STREAM, picName: Rope.ROPE, feedback: FeedbackData] = { Feedback.PutF[feedback, begin, "Writing file: %g...", [rope[picName]]]; SVFileOut.FileoutScene [scene, f, picName]; scene.dirty _ FALSE; Feedback.Append[feedback, "Done", end]; }; -- end of SaveFile StoreScene: PUBLIC PROC [unNamedScene: Scene, newPicName: Rope.ROPE, feedback: FeedbackData] 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]; Feedback.PutF[feedback, begin, "Writing file: %g...", [rope[newPicName]]]; SVTransforms.TidyUpCoordSysTree[unNamedScene.coordSysRoot]; SVFileOut.FileoutScene [unNamedScene, f, newPicName]; Feedback.Append[feedback, "Done", end]; 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] = { SELECT char FROM '.=> RETURN[sepr]; ENDCASE => RETURN[other]; }; END. LFile: SVFilesImpl.mesa Last edited by: Eric Bier on May 6, 1987 4:18:16 pm PDT 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, Feedback "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. Κc– "cedar" style˜Ihead1šœ™Iprocšœ7™7Jšœ Οmœ1™