-- LoomSetup.mesa Edited by Sweet on June 13, 1979 10:14 AM DIRECTORY DisplayDefs: FROM "displaydefs" USING [Dimension], ImageDefs: FROM "imagedefs" USING [StopMesa], IODefs: FROM "IODefs" USING [BS, ControlA, ControlW, DEL, SP], LoomDefs: FROM "loomdefs", MenuDefs: FROM "MenuDefs" USING [InstantiateMenuWithSubwindow, MenuHandle, MenuItemObject, CreateMenu, UninstantiateMenuFromSubwindow, DestroyMenu, MenuItemIndex], ParameterDefs: FROM "ParameterDefs" USING [ CreateParameterSubwindow, defaultBoxWidth, DisplayParameterItem, EnumeratedRecord, line0, line1, line2, line3, line4, line5, line6, line7, line8, ParameterItemDescriptor, ParameterItemHandle, ParameterItemObject, ParameterProcType, ParameterStringEditProcType, VanillaEditStringProc, VanillaFeedbackStringProc, VanillaMenuProc, VanillaNotifyProc], SelectionDefs: FROM "SelectionDefs" USING [SelectionTargetType], StringDefs: FROM "StringDefs" USING [AppendChar, AppendDecimal, AppendString], SystemDefs: FROM "SystemDefs" USING [ AllocateHeapNode, AllocateHeapString, FreeHeapNode, FreeHeapString], ToolsDefs: FROM "ToolsDefs" USING [ MakeHeapString], WindowDefs: FROM "WindowDefs" USING [ CreateSubwindow, MakeWindowSizeTiny, DestroyWindowEtc, PaintWindow, SubwindowHandle, SubwindowPlace, WindowHandle]; LoomSetup: PROGRAM IMPORTS ImageDefs, LoomDefs, MenuDefs, ParameterDefs, StringDefs, SystemDefs, ToolsDefs, WindowDefs EXPORTS LoomDefs = BEGIN OPEN DisplayDefs, MenuDefs, ParameterDefs, WindowDefs, LoomDefs; Quit: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor _ NULL, index: CARDINAL _ NULL] = BEGIN ImageDefs.StopMesa[]; END; DestroyThisTool: PUBLIC PROCEDURE = -- This procedure will be called just prior to this Tools destruction. BEGIN IF msgSW # NIL THEN MakeToolInactive[]; DestroyWindowEtc[controlWindow]; END; menu: ARRAY PaintAction OF MenuDefs.MenuHandle; mi: ARRAY PaintAction OF DESCRIPTOR FOR ARRAY OF MenuDefs.MenuItemObject; currentMenu: PaintAction _ stop; MakeMyMenu: PUBLIC PROCEDURE = BEGIN OPEN MenuDefs, ToolsDefs; a: PaintAction; mi[stop] _ DESCRIPTOR[SystemDefs.AllocateHeapNode[3*SIZE[MenuItemObject]], 3]; mi[run] _ DESCRIPTOR[SystemDefs.AllocateHeapNode[3*SIZE[MenuItemObject]], 3]; mi[pause] _ DESCRIPTOR[SystemDefs.AllocateHeapNode[4*SIZE[MenuItemObject]], 4]; mi[stop][0] _ mi[run][0] _ mi[pause][0] _ [MakeHeapString["Press"L], MenuProc]; mi[stop][1] _ [MakeHeapString["Repaint"L], MenuProc]; mi[stop][2] _ mi[run][2] _ mi[pause][3] _ [MakeHeapString["Quit"L], MenuProc]; mi[run][1] _ [MakeHeapString["Pause"L], MenuProc]; mi[pause][1] _ [MakeHeapString["Resume"L], MenuProc]; mi[pause][2] _ [MakeHeapString["Cancel"L], MenuProc]; FOR a IN PaintAction DO menu[a] _ CreateMenu[mi[a], "LoomTool"L]; ENDLOOP; MenuDefs.InstantiateMenuWithSubwindow[menu[stop], weaveWindow.subwindowChain]; currentMenu _ stop; END; FreeMyMenu: PUBLIC PROCEDURE = BEGIN OPEN SystemDefs, MenuDefs; i: CARDINAL; a: PaintAction; UninstantiateMenuFromSubwindow[menu[currentMenu], weaveWindow.subwindowChain]; FOR a IN PaintAction DO DestroyMenu[menu[a]]; FOR i IN [0..LENGTH[mi[a]]) DO FreeHeapString[mi[a][i].keyword]; ENDLOOP; FreeHeapNode[BASE[mi[a]]]; ENDLOOP; END; MenuProc: PROCEDURE [sw: SubwindowHandle, menu: MenuDefs.MenuHandle, index: MenuDefs.MenuItemIndex] = BEGIN SELECT currentMenu FROM stop => SELECT index FROM 0 => Press[sw]; 1 => Repaint[sw]; 2 => Quit[sw]; ENDCASE; run => SELECT index FROM 0 => Press[sw]; 1 => PausePainting[sw]; 2 => Quit[sw]; ENDCASE; pause => SELECT index FROM 0 => Press[sw]; 1 => ResumePainting[sw]; 2 => CancelPainting[sw]; 3 => Quit[sw]; ENDCASE; ENDCASE; END; PaintCommands: PUBLIC PROCEDURE [action: PaintAction] = BEGIN parameterItems[flex1parm] _ fp1[action]; parameterItems[flex2parm] _ fp2[action]; [] _ DisplayParameterItem[parameterSW, flex1parm]; [] _ DisplayParameterItem[parameterSW, flex2parm]; IF action # currentMenu THEN BEGIN UninstantiateMenuFromSubwindow[menu[currentMenu], weaveWindow.subwindowChain]; InstantiateMenuWithSubwindow[menu[action], weaveWindow.subwindowChain]; currentMenu _ action; END; END; flex1parm, flex2parm: CARDINAL; fp1, fp2: ARRAY PaintAction OF ParameterItemHandle; maxParams: CARDINAL = 50; parameterItems: PUBLIC DESCRIPTOR FOR ARRAY OF ParameterItemHandle; MakeMeAParameterSubwindow: PUBLIC PROCEDURE = BEGIN OPEN SystemDefs; piBase: POINTER; np: INTEGER _ -1; parameterSW _ CreateSubwindow[controlWindow, [[0,0], [10, 10]], NIL]; input _ AllocateHeapString[20]; output _ AllocateHeapString[20]; titleString _ AllocateHeapString[40]; woString _ AllocateHeapString[100]; poString _ AllocateHeapString[100]; warpSizeString _ AllocateHeapString[4]; weftSizeString _ AllocateHeapString[4]; warpColorString _ AllocateHeapString[30]; weftColorString _ AllocateHeapString[30]; overlapString _ AllocateHeapString[30]; StringDefs.AppendDecimal[warpSizeString, warpSize]; StringDefs.AppendDecimal[weftSizeString, weftSize]; BEGIN p: Pedal; FOR p IN Pedal DO tieup[p] _ AllocateHeapString[8]; ENDLOOP; END; piBase _ AllocateHeapNode[maxParams]; parameterItems _ DESCRIPTOR[piBase, maxParams]; parameterItems[np_np+1] _ MakeStringItem["Warp order"L, [1*7, line0], @woString, D1to8dash]; parameterItems[np_np+1] _ MakeStringItem["P1"L, [0, line1], @tieup[0], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P2"L, [13*7, line1], @tieup[1], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P3"L, [26*7, line1], @tieup[2], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P4"L, [39*7, line1], @tieup[3], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P5"L, [0, line2], @tieup[4], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P6"L, [13*7, line2], @tieup[5], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P7"L, [26*7, line2], @tieup[6], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["P8"L, [39*7, line2], @tieup[7], D1to8, 8*7]; parameterItems[np_np+1] _ MakeStringItem["Warp"L, [0, line3], @warpSizeString, D0to9]; parameterItems[np_np+1] _ MakeStringItem[",color"L, [9*7, line3], @warpColorString, EditColors, 20*7]; parameterItems[np_np+1] _ MakeStringItem["Overlap"L, [38*7, line3], @overlapString, EditOverlap]; parameterItems[np_np+1] _ MakeStringItem["Weft"L, [0, line4], @weftSizeString, D0to9]; parameterItems[np_np+1] _ MakeStringItem[",color"L, [9*7, line4], @weftColorString, EditColors, 20*7]; parameterItems[np_np+1] _ MakeStringItem["Title"L, [0,line5], @titleString]; parameterItems[np_np+1] _ MakeCommandItem["Load"L, [0, line6], Load]; parameterItems[np_np+1] _ MakeStringItem["from"L, [6*7,line6], @input]; parameterItems[np_np+1] _ MakeCommandItem["Dump"L, [31*7, line6], Dump]; parameterItems[np_np+1] _ MakeCommandItem["Press"L, [37*7, line6], Press]; parameterItems[np_np+1] _ MakeStringItem["to"L, [44*7,line6], @output]; parameterItems[np_np+1] _ MakeBoolItem["AUTO"L, [1*7, line7], @autoRepaint]; parameterItems[flex1parm _ (np_np+1)] _ fp1[stop] _ MakeCommandItem["Repaint"L, [6*7, line7], Repaint]; parameterItems[flex2parm _ (np_np+1)] _ fp2[stop] _ fp2[run] _ MakeTagItem[""L, [15*7, line7]]; fp1[run] _ MakeCommandItem["Pause"L, [6*7, line7], PausePainting]; fp1[pause] _ MakeCommandItem["Resume"L, [6*7, line7], ResumePainting]; fp2[pause] _ MakeCommandItem["Cancel"L, [15*7, line7], CancelPainting]; parameterItems[np_np+1] _ MakeCommandItem["StdPedal"L, [23*7, line7], StdPedal]; parameterItems[np_np+1] _ MakeCommandItem["Up&Down"L, [33*7, line7], UpDown]; parameterItems[np_np+1] _ MakeCommandItem["Quit"L, [42*7, line7], Quit]; parameterItems[poParmNum _ (np_np+1)] _ MakeStringItem["Pedal order"L, [0,line8], @poString, D1to8dash]; nParams _ np+1; parameterItems _ DESCRIPTOR[piBase, nParams]; CreateParameterSubwindow[parameterItems, parameterSW, [fixed, TRUE, TRUE, TRUE], ConvertSelection]; END; D1to8: PROCEDURE [item: POINTER TO string ParameterItemObject, edits: STRING] RETURNS [pos: CARDINAL] = BEGIN OPEN IODefs; filtered: STRING _ SystemDefs.AllocateHeapString[edits.length]; i: CARDINAL; c: CHARACTER; FOR i IN [0..edits.length) DO SELECT (c _ edits[i]) FROM IN ['1..'8], BS, ControlA, ControlW, DEL => StringDefs.AppendChar[filtered, c]; ENDCASE; ENDLOOP; pos _ VanillaEditStringProc[item, filtered]; SystemDefs.FreeHeapString[filtered]; RETURN END; D1to8dash: PROCEDURE [item: POINTER TO string ParameterItemObject, edits: STRING] RETURNS [pos: CARDINAL] = BEGIN OPEN IODefs; filtered: STRING _ SystemDefs.AllocateHeapString[edits.length]; i: CARDINAL; c: CHARACTER; FOR i IN [0..edits.length) DO SELECT (c _ edits[i]) FROM IN ['1..'8], '-, BS, ControlA, ControlW, DEL, SP => StringDefs.AppendChar[filtered, c]; ENDCASE; ENDLOOP; pos _ VanillaEditStringProc[item, filtered]; SystemDefs.FreeHeapString[filtered]; RETURN END; D0to9: PROCEDURE [item: POINTER TO string ParameterItemObject, edits: STRING] RETURNS [pos: CARDINAL] = BEGIN OPEN IODefs; filtered: STRING _ SystemDefs.AllocateHeapString[edits.length]; i: CARDINAL; c: CHARACTER; FOR i IN [0..edits.length) DO SELECT (c _ edits[i]) FROM IN ['0..'9], BS, ControlA, ControlW, DEL => StringDefs.AppendChar[filtered, c]; ENDCASE; ENDLOOP; pos _ VanillaEditStringProc[item, filtered]; SystemDefs.FreeHeapString[filtered]; RETURN END; EditColors: PROCEDURE [item: POINTER TO string ParameterItemObject, edits: STRING] RETURNS [pos: CARDINAL] = BEGIN OPEN IODefs; filtered: STRING _ SystemDefs.AllocateHeapString[edits.length]; i: CARDINAL; c: CHARACTER; FOR i IN [0..edits.length) DO SELECT (c _ edits[i]) FROM IN ['0..'9], BS, ControlA, ControlW, DEL, SP, IN ColorName, 'r => StringDefs.AppendChar[filtered, c]; ENDCASE; ENDLOOP; pos _ VanillaEditStringProc[item, filtered]; SystemDefs.FreeHeapString[filtered]; RETURN END; EditOverlap: PROCEDURE [item: POINTER TO string ParameterItemObject, edits: STRING] RETURNS [pos: CARDINAL] = BEGIN OPEN IODefs; filtered: STRING _ SystemDefs.AllocateHeapString[edits.length]; i: CARDINAL; c: CHARACTER; FOR i IN [0..edits.length) DO SELECT (c _ edits[i]) FROM IN ['0..'9], BS, ControlA, ControlW, DEL, SP, IN ColorName, '/, '= => StringDefs.AppendChar[filtered, c]; ENDCASE; ENDLOOP; pos _ VanillaEditStringProc[item, filtered]; SystemDefs.FreeHeapString[filtered]; RETURN END; -- Make Standard Tools Facilities Utilities ConvertSelection: PROCEDURE [ data: POINTER, targetType: SelectionDefs.SelectionTargetType] RETURNS [POINTER] = BEGIN RETURN [NIL]; END; MakeCommandItem: PROCEDURE [ tag: STRING, place: SubwindowPlace, proc: ParameterProcType] RETURNS [p: POINTER TO command ParameterItemObject] = BEGIN s: STRING _ SystemDefs.AllocateHeapString[tag.length]; StringDefs.AppendString[s, tag]; p _ SystemDefs.AllocateHeapNode[SIZE[ParameterItemObject]]; p^ _ ParameterItemObject [s, place, command[proc: proc]]; END; MakeTagItem: PROCEDURE [ tag: STRING, place: SubwindowPlace, other: POINTER _ NIL] RETURNS [p: POINTER TO tagOnly ParameterItemObject] = BEGIN s: STRING _ SystemDefs.AllocateHeapString[tag.length]; StringDefs.AppendString[s, tag]; p _ SystemDefs.AllocateHeapNode[SIZE[ParameterItemObject]]; p^ _ ParameterItemObject [s, place, tagOnly[otherItem: other]]; END; MakeStringItem: PROCEDURE [ tag: STRING, place: SubwindowPlace, sp: POINTER TO STRING, eproc: ParameterStringEditProcType _ VanillaEditStringProc, bw: Dimension _ defaultBoxWidth] RETURNS [p: POINTER TO string ParameterItemObject] = BEGIN OPEN SystemDefs; s: STRING _ AllocateHeapString[tag.length]; StringDefs.AppendString[s, tag]; p _ AllocateHeapNode[SIZE[ParameterItemObject]]; p^ _ ParameterItemObject [s, place, string[ boxWidth: bw, string: sp, editProc: eproc, feedbackProc: VanillaFeedbackStringProc, menuProc: VanillaMenuProc]]; END; MakeBoolItem: PROCEDURE [ tag: STRING, place: SubwindowPlace, bp: POINTER TO BOOLEAN] RETURNS [p: POINTER TO boolean ParameterItemObject] = BEGIN OPEN SystemDefs; s: STRING _ AllocateHeapString[tag.length]; StringDefs.AppendString[s, tag]; p _ AllocateHeapNode[SIZE[ParameterItemObject]]; p^ _ ParameterItemObject [s, place, boolean[ feedback: video, switch: bp, proc: VanillaNotifyProc]]; END; MakeEnumItem: PROCEDURE [ tag: STRING, place: SubwindowPlace, ep: POINTER, ea: DESCRIPTOR FOR ARRAY OF EnumeratedRecord] RETURNS [p: POINTER TO enumerated ParameterItemObject] = BEGIN OPEN SystemDefs; s: STRING _ AllocateHeapString[tag.length]; StringDefs.AppendString[s, tag]; p _ AllocateHeapNode[SIZE[ParameterItemObject]]; p^ _ ParameterItemObject [s, place, enumerated[ feedback: all, value: ep, proc: VanillaNotifyProc, enumeratedRecords: ea]]; END; -- Mainline code MenuDefs.InstantiateMenuWithSubwindow[NIL, controlWindow.subwindowChain]; MakeWindowSizeTiny[controlWindow]; PaintWindow[controlWindow]; END. -- of LoomSetup