-- File: SVFilesImpl.mesa -- Last edited by Bier on December 18, 1982 1:37 am -- Author: Eric Bier on March 22, 1983 11:16 am -- Contents: Interfaces which make creating scenes look like opening files. DIRECTORY DisplayList3d, FileIO, Filein3d, Fileout3d, IO, MessageWindow, Rope, SVArtwork, SVFiles, TFI3d; SVFilesImpl: PROGRAM IMPORTS DisplayList3d, FileIO, Filein3d, Fileout3d, IO, MessageWindow, Rope, SVArtwork, TFI3d EXPORTS SVFiles = BEGIN Scene: TYPE = DisplayList3d.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] RETURNS [scene: Scene, success: BOOL] = { -- Look for the pic file on the local disk. If there, read in the scene. If not, MessageWindow "file not found" and return success = false. f: IO.STREAM; [f, success] _ OpenFile[picName]; IF NOT success THEN RETURN; -- OpenFile prints any error messages. -- now we must turn the text file into a scene. [scene, success] _ MakeScene[f, picName]; -- MakeScene will print any error messages }; OpenFile: PUBLIC PROC [picName: Rope.ROPE] RETURNS [f: IO.STREAM, success: BOOL] = { success _ TRUE; -- Two possiblilities -- 1) File doesn't exist. Print error message. -- 2) File does exist. File it in. Succeed. f _ FileIO.Open[picName, read, oldOnly !FileIO.OpenFailed => CHECKED {IF why = fileNotFound OR why = illegalFileName THEN {success _ FALSE; CONTINUE} ELSE ERROR}]; IF NOT success THEN { MessageWindow.Append["Picture file: ", TRUE]; MessageWindow.Append[picName]; MessageWindow.Append[" not found."]; RETURN}; }; -- end of OpenFile MakeScene: PRIVATE PROC [f: IO.STREAM, picName: Rope.ROPE] RETURNS [scene: Scene, success: BOOL] = { errorPos: NAT; errorStream: IO.STREAM; errorRope, expected, actual: Rope.ROPE; fileNotFound: BOOL _ FALSE; allMapsFound: BOOL _ TRUE; success _ TRUE; scene _ DisplayList3d.CreateEmptyScene[picName]; MessageWindow.Append["Reading scene: ",TRUE]; MessageWindow.Append[scene.name]; MessageWindow.Append[" from file: "]; MessageWindow.Append[picName]; MessageWindow.Append["..."]; Filein3d.FileinScene [scene, f !TFI3d.RopeNotOnTop => {success _ FALSE; errorPos _ position; expected _ notThere; actual _ wasThere; CONTINUE}; SVArtwork.FileNotFound => {allMapsFound _ FALSE; CONTINUE}]; IF NOT allMapsFound THEN { errorStream _ IO.CreateOutputStreamToRope[]; errorStream.PutF["Some AIS mapping file not found"]; errorRope _ IO.GetOutputStreamRope[errorStream]; MessageWindow.Append[errorRope, TRUE]; success _ FALSE; RETURN }; IF NOT success THEN { errorStream _ IO.CreateOutputStreamToRope[]; errorStream.PutF["At %g in %g expected '%g' not '%g'", [integer[errorPos]], [rope[picName]], [rope[expected]], [rope[actual]]]; errorRope _ IO.GetOutputStreamRope[errorStream]; MessageWindow.Append[errorRope, TRUE]; RETURN } ELSE MessageWindow.Append["Done"]; }; -- end of MakeScene SaveScene: PUBLIC PROC [updatedScene: Scene, picName: Rope.ROPE] RETURNS [success: BOOL] = { -- 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, MessageWindow "File not found. Use Store." and return success = FALSE. f: IO.STREAM; success _ TRUE; f _ FileIO.Open[picName, overwrite, oldOnly !FileIO.OpenFailed => CHECKED {IF why = fileNotFound OR why = illegalFileName THEN {success _ FALSE; CONTINUE} ELSE ERROR}]; IF success THEN SaveFile[updatedScene, f, picName] ELSE {MessageWindow.Append["file has no name. Try Store.", TRUE]; MessageWindow.Blink[]}; }; SaveFile: PRIVATE PROC [scene: Scene, f: IO.STREAM, picName: Rope.ROPE] = { MessageWindow.Append["Writing scene: ",TRUE]; MessageWindow.Append[scene.name]; MessageWindow.Append[" to file: "]; MessageWindow.Append[picName]; MessageWindow.Append["..."]; Fileout3d.FileoutScene [scene, f, picName]; scene.dirty _ FALSE; MessageWindow.Append["Done"]; }; -- end of SaveFile StoreScene: PUBLIC PROC [unNamedScene: Scene, newPicName: Rope.ROPE] RETURNS [success: BOOL] = { -- Check the local disk for this name. Ask for confirmation to store to new (or old) file. Store if confirmed. f: IO.STREAM; fileAlreadyExists: BOOL _ FALSE; confirmation: BOOL _ FALSE; success _ FALSE; f _ FileIO.Open[newPicName, write, newOnly !FileIO.OpenFailed => CHECKED {IF why = fileAlreadyExists OR why = illegalFileName THEN {fileAlreadyExists _ TRUE; CONTINUE} ELSE ERROR}]; IF fileAlreadyExists THEN { confirmation _ MessageWindow.Confirm["Confirm overwrite of existing pic file"]; IF confirmation THEN f _ FileIO.Open[newPicName, overwrite, oldOnly] ELSE RETURN; }; MessageWindow.Append["Writing scene: ",TRUE]; MessageWindow.Append[newPicName]; MessageWindow.Append[" to file: "]; MessageWindow.Append[newPicName]; MessageWindow.Append["..."]; Fileout3d.FileoutScene [unNamedScene, f, newPicName]; MessageWindow.Append["Done"]; success _ TRUE; unNamedScene.dirty _ FALSE; unNamedScene.name _ newPicName; }; -- end of Save FileExists: PUBLIC PROC [fileName: Rope.ROPE] RETURNS [answer: BOOL_TRUE] = { s: IO.STREAM _ FileIO.Open[fileName: fileName, createOptions: oldOnly ! FileIO.OpenFailed => TRUSTED { answer_FALSE; GOTO notThere; }]; IO.Close[s]; EXITS notThere => NULL; }; FilenameMinusExtension: PUBLIC PROC [wholeName: Rope.ROPE] RETURNS [firstPart: Rope.ROPE] = { wholeStream: IO.STREAM _ IO.RIS[wholeName]; firstPart _ IO.GetToken[wholeStream, PeriodBreakProc]; }; PeriodBreakProc: SAFE PROC [char: CHAR] RETURNS [IO.CharClass] = TRUSTED { SELECT char FROM '. => RETURN[sepr]; ENDCASE => RETURN[other]; }; END. Κπ– "Mesa" style˜procšτΟcΚœΟk œ2žœEžœžœ-žœ)žœ žœ žœ$žœžœžœ Οn œžœžœ žœžœžœžœžœ%žœžœžœ žœžœ1žœžœžœ!žœŸœžœžœ#žœ(žœŸ œžœžœžœžœžœŽœžœžœ&žœžœ žœžœ'œ0œ++œŸœžœžœžœžœžœžœ žœžœœ1œ/œBžœžœžœžœ žœžœžœžœžœžœ žœ,žœMžœœŸ œžœžœžœžœžœžœžœžœžœžœ%žœžœžœžœžœ žœ\žœΟžœBžœ0žœžœžœžœžœžœbžœEžœžœžœžœžœ žœžœ°žœEžœžœžœ#œŸ œžœžœ%žœžœ žœ–œSœžœžœ žœGžœžœžœžœžœžœ žœžœžœ žœ%žœ7žœ$Ÿœžœžœžœžœžœ.žœΕžœ%œŸ œžœžœ(žœžœ žœqœžœžœžœžœžœžœ žœHžœžœžœžœžœžœ žœžœžœžœWžœžœ7žœžœ/žœνžœžœ'œŸ œžœžœžœžœ žœžœ˜‘,šœžœžœ9˜EšΟbœžœ˜ Jšœžœ˜ Jšžœ ˜Jšœ˜——Jšœžœ ˜ šœž˜Jšœ žœ˜——Jš/œŸœžœžœžœžœžœžœžœžœžœžœ/Ÿœžœžœžœžœžœžœžœžœžœ žœžœ˜έJšœžœ˜—…—*