AISShowImpl.mesa
Copyright (C) 1985, Xerox Corporation. All rights reserved.
Last Edited by: Diebert, April 29, 1985 4:05:45 pm PDT
DIRECTORY
AIS USING [FRef, Raster, OpenFile, CloseFile, ReadRaster],
AISViewer USING [CreateAISViewer, DisplayAIS],
Commander USING [CommandProc, Register],
CommandTool USING [CurrentWorkingDirectory],
Containers USING [Create, ChildXBound, ChildYBound],
FS USING [Error, ExpandName, FileInfo, ComponentPositions],
IO USING [card, EndOfStream, GetTokenRope, IDProc, PutFR, PutRope, RIS, rope, STREAM],
Menus USING [Menu, MenuProc, CreateMenu, CreateEntry, AppendMenuEntry],
MessageWindow USING [Append],
Rope USING [Equal, Find, IsEmpty, ROPE, Substr],
ViewerClasses USING [Viewer],
ViewerOps USING [PaintViewer],
ViewerTools USING [GetSelectionContents];
AISShowImpl: CEDAR MONITOR
IMPORTS AIS, AISViewer, Commander, CommandTool, Containers, FS, IO, Menus, MessageWindow, Rope, ViewerOps, ViewerTools
= BEGIN
ROPE: TYPE ~ Rope.ROPE;
Tool: TYPE ~ REF ToolRecord;
ToolRecord: TYPE ~ RECORD [
outer: ViewerClasses.Viewer,
aisViewer: ViewerClasses.Viewer,
wDir: ROPENIL,
fileName: ROPENIL,
scans, pixels: CARDINAL ← 0
];
BuildTool: Commander.CommandProc ~ {
tool: Tool ← NEW [ToolRecord ← [wDir: "///"]];
menu: Menus.Menu ← Menus.CreateMenu[];
stream: IO.STREAM;
fileName: ROPE;
Ok: BOOLFALSE;
nwd: ROPE;
cp: FS.ComponentPositions;
Menus.AppendMenuEntry[menu, Menus.CreateEntry["Display", DisplayProc, tool]];
tool.outer ← Containers.Create[
info: [
name: "AIS Show", iconic: FALSE, column: left, scrollable: FALSE, icon: tool, menu: menu
],
paint: TRUE
];
tool.aisViewer ← AISViewer.CreateAISViewer[info: [ww: 9999, wh: 9999, parent: tool.outer, name: "AIS Show", border: FALSE]];
Containers.ChildXBound[container: tool.outer, child: tool.aisViewer];
Containers.ChildYBound[container: tool.outer, child: tool.aisViewer];
tool.wDir ← CommandTool.CurrentWorkingDirectory[];
tool.outer.name ← IO.PutFR["AIS Show: WD = %g", IO.rope [tool.wDir]];
ViewerOps.PaintViewer[tool.outer, all];
IF cmd.commandLine.IsEmpty THEN RETURN;
stream ← IO.RIS[cmd.commandLine];
fileName ← stream.GetTokenRope[IO.IDProc ! IO.EndOfStream => GOTO BailOut].token;
cp ← FS.ExpandName[fileName, tool.wDir].cp;
IF fileName.Find["/"] >= 0 THEN
nwd ← fileName.Substr[0, cp.base.start - 1] ELSE nwd ← tool.wDir;
IF NOT tool.wDir.Equal[nwd, FALSE] THEN tool.wDir ← nwd;
tool.fileName ← FS.ExpandName[fileName, tool.wDir].fullFName;
IF NOT FileCheck[fileName].exists THEN {cmd.out.PutRope["Can't find file.\n"]; RETURN; };
[tool.scans, tool.pixels] ← GetDims[fileName];
tool.outer.name ← IO.PutFR["%g s: %g p: %g",
IO.rope [tool.fileName], IO.card[tool.scans], IO.card[tool.pixels]];
ViewerOps.PaintViewer[tool.outer, caption];
[] ← AISViewer.DisplayAIS[tool.aisViewer, fileName];
cmd.out.PutRope["\n"];
EXITS BailOut => RETURN;
};
FileCheck: PROC
[fileName: ROPE, wDir: ROPENIL] RETURNS [exists: BOOL, fullFName: ROPE] = BEGIN
-- Returns exists: TRUE iff file exists. If exists then fullFName is filled in to make later lookup faster.
[fullFName: fullFName] ← FS.FileInfo[name: fileName, wDir: wDir
! FS.Error => IF error.group = $user THEN GOTO doesNotExist];
RETURN [exists: TRUE, fullFName: fullFName]
EXITS doesNotExist => RETURN [exists: FALSE, fullFName: NIL];
END;
DisplayProc: Menus.MenuProc = BEGIN
PROC [parent: REF ANY, clientData: REF ANYNIL,
mouseButton: MouseButton ← red, shift, control: BOOLFALSE];
nwd: ROPE;
r: ROPE ← ViewerTools.GetSelectionContents[];
tool: Tool ← NARROW [clientData];
cp: FS.ComponentPositions ← FS.ExpandName[r, "///"].cp;
IF r.Find["/"] >= 0 THEN nwd ← r.Substr[0, cp.base.start - 1] ELSE nwd ← tool.wDir;
IF NOT tool.wDir.Equal[nwd, FALSE] THEN tool.wDir ← nwd;
r ← FS.ExpandName[r, tool.wDir].fullFName;
IF NOT FileCheck[r].exists THEN {MessageWindow.Append["Can't find file."]; RETURN; };
[tool.scans, tool.pixels] ← GetDims[(tool.fileName ← r)];
tool.outer.name ← IO.PutFR["%g s: %g p: %g",
IO.rope [tool.fileName], IO.card[tool.scans], IO.card[tool.pixels]];
ViewerOps.PaintViewer[tool.outer, caption];
[] ← AISViewer.DisplayAIS[tool.aisViewer, (tool.fileName ← r)];
END;
GetDims: PROC [fileName: ROPE] RETURNS [scans, pixels: CARDINAL] = BEGIN
f: AIS.FRef = AIS.OpenFile[fileName ! FS.Error => GOTO Out];
r: AIS.Raster = AIS.ReadRaster[f];
scans ← r.scanCount; pixels ← r.scanLength;
AIS.CloseFile[f];
EXITS Out => RETURN [0, 0];
END;
Commander.Register[key: "AISShow", proc: BuildTool, doc: "AISShow"];
END.