FigureOps.mesa
Last Edited by: Stone, June 19, 1984 2:22:47 pm PDT
Last Edited by: Pier, February 14, 1984 10:11:13 am PST
DIRECTORY
GriffinDefs: FROM "GriffinDefs",
MenuDefs: FROM "MenuDefs",
PointDefs: FROM "PointDefs",
ObjectDefs: FROM "ObjectDefs",
GriffinViewer USING [PaintProc, DoPaint],
GriffinFileDefs: FROM "GriffinFileDefs",
FS USING [EnumerateForNames, NameProc, ExpandName, ComponentPositions],
RefreshDefs: FROM "RefreshDefs",
ScreenDefs USING [ClearScreen],
GriffinColor USING [LoadColorMap],
GriffinMenusInterface,
Rope USING [Cat, Substr, Length,ROPE, Equal];
FigureOps: PROGRAM
IMPORTS GriffinDefs, MenuDefs, ScreenDefs, ObjectDefs,
GriffinFileDefs, FS, RefreshDefs, Rope, GriffinViewer, GriffinColor
EXPORTS GriffinDefs, GriffinMenusInterface =
BEGIN
gridX: INTEGER ← 8; gridY: INTEGER ← 8;
gridOn: BOOLEANFALSE;
X: CARDINAL = PointDefs.X;
Y: CARDINAL = PointDefs.Y;
ROPE: TYPE = Rope.ROPE;
Refresh: PUBLIC MenuDefs.MenuProc =
BEGIN
paintProc: GriffinViewer.PaintProc = {
ScreenDefs.ClearScreen[dc];
ObjectDefs.ReplotAllObjects[dc];
};
GriffinViewer.DoPaint[paintProc];
END;
Press: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
name: ROPE;
readOnly: BOOLEAN;
[name, readOnly]← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
IF readOnly THEN GriffinDefs.UserMessage["File is read-only."];
ExpungeObjects[];
ObjectDefs.PressAllObjects[name];
END;
Save: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
name: ROPE;
readOnly: BOOLEAN;
[name, readOnly]← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
IF readOnly THEN GriffinDefs.UserMessage["File is read-only."];
name ← Rope.Cat[name,".griffin"];
ExpungeObjects[];
[] ← GriffinFileDefs.OpenFile[name, TRUE];
[] ← GriffinFileDefs.WriteFigure[];
GriffinFileDefs.CloseFile[];
END;
Restore: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
name: ROPE;
readOnly: BOOLEAN;
[name, readOnly]← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
IF ~readOnly THEN name ← Rope.Cat[name,".griffin"];
ExpungeObjects[];
IF GriffinFileDefs.OpenFile[name, FALSE] THEN
BEGIN
GriffinFileDefs.ReadFigure[];
GriffinFileDefs.CloseFile[];
ObjectDefs.ReplotAllObjects[NIL];
END;
END;
TypeIntoFileName: PUBLIC MenuDefs.MenuProc =
BEGIN
MenuDefs.SelectOnly[item];
GriffinDefs.TypeIntoMenuItem[item];
END;
GetName: PROCEDURE RETURNS[string: ROPE, readOnly: BOOLEAN]=
BEGIN OPEN MenuDefs;
nameItem: MenuItemHandle ← NIL;
FindLastSelected: MenuProc =
BEGIN
IF IsSelected[item] THEN nameItem ← item;
END;
ForAllMenuItems[filesMenu, FindLastSelected];
[menuName: string, readOnly: readOnly] ← ParseName[MenuDefs.MenuString[nameItem]];
IF nameItem = fileName THEN [] ← AddPortfolioName[string]; --name is in type-in menu
RETURN[string, readOnly];
END;
MakeDirInfo: PROC[fName: ROPE, cp: FS.ComponentPositions] RETURNS [dirInfo: ROPE] = {
dirInfo ← Rope.Cat[Rope.Substr[fName,cp.dir.start, cp.dir.length],
">",Rope.Substr[fName,cp.subDirs.start, cp.subDirs.length]];
};
ParseName: PROC[name: ROPE] RETURNS [readOnly: BOOLEAN, menuName: ROPE] = {
IF readOnly THEN menuName is a complete GName
Otherwise, the menuName is approximately the LName for the file
Exceptions:
if the file is on the default subdirectory then no subdirectory is included
The LName never contains an extension
cp: FS.ComponentPositions;
dirInfo, extension, fName: ROPE;
[fullFName: fName, cp: cp] ← FS.ExpandName[name];
dirInfo ← MakeDirInfo[fName,cp];
extension ← Rope.Substr[fName, cp.ext.start, cp.ext.length];
isSimple ← cp.server.length=0 AND Rope.Equal[dirInfo, localDirInfo, FALSE] AND cp.ver.length=0 AND (cp.ext.length=0 OR Rope.Equal[extension, "griffin", FALSE] OR Rope.Equal[extension, "press", FALSE]);
readOnly ← cp.server.length#0 OR cp.ver.length#0 OR
~(Rope.Equal[extension, "griffin", FALSE] OR Rope.Equal[extension, "press", FALSE]);
menuName ←IF readOnly THEN fName
ELSE IF Rope.Equal[dirInfo, localDirInfo, FALSE]
THEN Rope.Substr[fName, cp.base.start, cp.base.length]
ELSE Rope.Cat[dirInfo, Rope.Substr[fName, cp.base.start, cp.base.length]];
};
AddPortfolioName: PROCEDURE[string: ROPE]
RETURNS [item: MenuDefs.MenuItemHandle] =
BEGIN OPEN MenuDefs, GriffinDefs;
IF Rope.Length[string] = 0
THEN UserMessage["First select or type a file name."];
item ← AddMenuItem[filesMenu, string, SelectOnly];
SetMenuString[fileName, ""];
SelectOnly[item];
RefreshDefs.RestoreScreen[];
END;
GridMenuProc: PUBLIC MenuDefs.MenuProc =
BEGIN
gridOn ← ~gridOn;
IF ~gridOn THEN BEGIN
MenuDefs.Deselect[item];
ObjectDefs.GridOff[];
END
ELSE BEGIN
MenuDefs.Select[item];
ObjectDefs.GridOn[];
END;
END;
Grid: PUBLIC PROCEDURE[pt: PointDefs.ScrPt] RETURNS[PointDefs.ScrPt]=
BEGIN
dx,dy: INTEGER;
IF NOT gridOn THEN RETURN[pt];
will be unconvincing if grid < 2;
dx ← pt[X] MOD gridX;
pt[X] ← pt[X]-dx;
IF dx > gridX/2 THEN pt[X] ← pt[X] +gridX;
dy ← pt[Y] MOD gridY;
pt[Y] ← pt[Y]-dy;
IF dy > gridY/2 THEN pt[Y] ← pt[Y] +gridY;
RETURN[pt];
END;
Merge: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
view: View ← viewMenu.view;
Mark: ObjectProc = BEGIN
IF obj.view=view THEN RETURN;
obj.view ← view;
RefreshDefs.MarkBox[obj.tl,obj.br,obj];
END;
ForAllObjects[Mark];
RefreshDefs.RestoreScreen[];
END;
Switch: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
newView: View ← IF viewMenu.view=main THEN alternate ELSE main;
Mark: ObjectProc = BEGIN
WITH foo: obj SELECT FROM
menu => obj.view ← newView;
token => IF foo.tokenType#selected AND foo.tokenType#open THEN obj.view ← newView;
ENDCASE;
END;
paintProc: GriffinViewer.PaintProc = {
ScreenDefs.ClearScreen[dc];
ObjectDefs.ReplotAllObjects[dc];
};
ForAllObjects[Mark];
SetCurrentView[newView];
GriffinViewer.DoPaint[paintProc];
END;
ColorMap: PUBLIC MenuDefs.MenuProc = {GriffinColor.LoadColorMap[]};
promptMenu: MenuDefs.MenuHandle←NIL;
displayMenu,filesMenu,viewMenu: PUBLIC MenuDefs.MenuHandle←NIL;
fileName: MenuDefs.MenuItemHandle;
localDirInfo: ROPENIL;
EachGriffinFile: FS.NameProc = TRUSTED BEGIN
NameProc: TYPE = PROC [fullFName: ROPE] RETURNS [continue: BOOLEAN];
cp: FS.ComponentPositions ← FS.ExpandName[fullFName].cp;
[]�PortfolioName[Rope.Substr[fullFName,cp.base.start,cp.base.length]];
localDirInfo ← MakeDirInfo[fullFName, cp];
RETURN[TRUE];
END;
StartFigureMenus: PUBLIC PROC = {
IF filesMenu=NIL THEN { --first call
promptMenu ← MenuDefs.CreateMenu[horizontal, [60,70], "Type File Name >"];
viewMenu ← MenuDefs.CreateMenu[horizontal, [100,50], NIL];
[]←MenuDefs.AddMenuItem[viewMenu,"Refresh",Refresh];
[]←MenuDefs.AddMenuItem[viewMenu,"Grid",GridMenuProc];
[]←MenuDefs.AddMenuItem[viewMenu,"Merge",Merge];
[]←MenuDefs.AddMenuItem[viewMenu,"Switch",Switch];
[]←MenuDefs.AddMenuItem[viewMenu,"ColorMap",ColorMap];
}
ELSE [] ← ObjectDefs.DeleteObject[filesMenu]; --we're being called with a new viewer and wd
filesMenu ← MenuDefs.CreateMenu[vertical, [100,75], NIL];
[]←MenuDefs.AddMenuItem[filesMenu,"Save", Save];
[]←MenuDefs.AddMenuItem[filesMenu,"Restore", Restore];
[]←MenuDefs.AddMenuItem[filesMenu,"Press", Press];
fileName ← MenuDefs.AddMenuItem[filesMenu, "", TypeIntoFileName];
FS.EnumerateForNames[pattern: "*.griffin!H", proc: EachGriffinFile, wDir: NIL];
MenuDefs.SelectOnly[fileName];
};
END.