FigureOps.mesa
Last Edited by: Stone, April 16, 1984 4:29:01 pm PST
Last Edited by: Pier, February 14, 1984 10:11:13 am PST
Last Edited by: Beach, December 3, 1984 5:08:16 pm PST
DIRECTORY
GriffinDefs: FROM "GriffinDefs",
MenuDefs: FROM "MenuDefs",
PointDefs: FROM "PointDefs",
ObjectDefs: FROM "ObjectDefs",
GriffinViewer USING [PaintProc, DoPaint],
GriffinFileDefs: FROM "GriffinFileDefs",
FS USING [EnumerateForNames, ExpandName, NameProc],
RefreshDefs: FROM "RefreshDefs",
ScreenDefs USING [ClearScreen],
GriffinColor USING [LoadColorMap],
GriffinMenusInterface,
Rope USING [Cat, --Fetch, --Substr, Find,Length,ROPE, Match];
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 ← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
ExpungeObjects[];
ObjectDefs.PressAllObjects[name];
END;
Save: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
name: ROPE ← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
IF ~Rope.Match[pattern: "*.griffin", object: name, case: FALSE]
THEN name ← Rope.Cat[name,".griffin"];
ExpungeObjects[];
[] ← GriffinFileDefs.OpenFile[name, TRUE];
[] ← GriffinFileDefs.WriteFigure[];
GriffinFileDefs.CloseFile[];
END;
Restore: PUBLIC MenuDefs.MenuProc =
BEGIN OPEN ObjectDefs;
name: ROPE ← GetName[];
IF Rope.Length[name]=0 THEN RETURN;
IF ~Rope.Match[pattern: "*.griffin", object: name, case: FALSE]
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]=
BEGIN OPEN MenuDefs;
nameItem: MenuItemHandle ← NIL;
FindLastSelected: MenuProc =
BEGIN
IF IsSelected[item] THEN nameItem ← item;
END;
ForAllMenuItems[filesMenu, FindLastSelected];
IF nameItem = fileName THEN nameItem ← AddPortfolioName[MenuString[fileName]];
RETURN[MenuString[nameItem]];
END;
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[]};
EachGriffinFile: FS.NameProc = TRUSTED BEGIN
NameProc: TYPE = PROC [fullFName: ROPE] RETURNS [continue: BOOLEAN];
mark: INT ← Rope.Find[fullFName, "."];
name: ROPE ← Rope.Substr[fullFName, 0, mark];
UNTIL mark<=0 DO
mark ← mark-1;
IF Rope.Fetch[name,mark]='> THEN EXIT;
ENDLOOP;
[]�PortfolioName[Rope.Substr[name,mark+1,Rope.Length[name]]];
nameInWDir: BOOLEAN ← 0 = Rope.Find[s1~fullFName, s2~griffinWDir, case~FALSE];
IF nameInWDir THEN {
name: ROPE ~ Rope.Substr[fullFName, griffinWDirLength, Rope.Find[s1~fullFName, s2~".griffin", case~FALSE]-griffinWDirLength];
[]�PortfolioName[name];
}
ELSE {
name: ROPE ~ Rope.Substr[fullFName, 0, Rope.Find[s1~fullFName, s2~".griffin", case~FALSE]];
[]�PortfolioName[name];
};
RETURN[TRUE];
END;
promptMenu: MenuDefs.MenuHandle←NIL;
displayMenu,filesMenu,viewMenu: PUBLIC MenuDefs.MenuHandle←NIL;
fileName: MenuDefs.MenuItemHandle;
griffinWDir: ROPE;
griffinWDirLength: INT;
StartFigureMenus: PUBLIC PROC = {
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];
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];
griffinWDir ← FS.ExpandName[".Griffin"].fullFName;
griffinWDir ← Rope.Substr[griffinWDir, 0, Rope.Find[griffinWDir, ".Griffin"]];
griffinWDirLength ← Rope.Length[griffinWDir];
FS.EnumerateForNames[pattern: "*.griffin!H", proc: EachGriffinFile, wDir: NIL]; -- enumerate all griffin files in this directory
MenuDefs.SelectOnly[fileName];
};
END.