ThymeViewers.mesa -- Some parts stolen from PseudoCursorsImpl.mesa
Last Edited by: SChen, September 17, 1984 6:21:43 pm PDT
DIRECTORY
Buttons USING [Button, ButtonProc, Create, SetDisplayStyle],
Commander USING [CommandProc, Register],
Containers USING [ChildXBound, ChildYBound, Create],
Cursors USING [CursorArray],
FileNames USING [CurrentWorkingDirectory],
Graphics USING [Context, Mark, Restore, Save, SetCP, SetPaintMode],
GraphicsOps USING [BitmapRef, BitmapRep, DrawBitmap],
IO USING [Close, Flush, PutF, time],
Labels USING [Create, Label],
Menus USING [AppendMenuEntry, ChangeNumberOfLines, CreateMenu, CreateEntry,
GetLine, SetLine, MenuEntry
GetNumberOfLines, Menu, MenuLine, MenuProc],
MessageWindow USING [Append, Blink],
Process USING [Detach, InitializeCondition, MsecToTicks, Ticks],
Rope USING [ROPE],
Rules USING [Create, Rule],
spGlobals USING[ConRec, DumpIt, Handle, FuncTablePtr, Level2Model, ModelTablePtr, NodeRec, RefConRec, RefNodeRec, RefR, RefUnReal, ResistorBody, ShowDetails, SimulateIt, spFunctions, spModels, Stages, StopIt, ThymeToolRec, ToggleShowDetails, UnReal],
TiogaOps USING [FindDef, FindText, FindWord, SearchDir],
TypeScript USING [Create, TS],
VFonts USING[CharWidth, StringWidth],
ViewerBLT USING[ChangeNumberOfLines],
ViewerClasses USING [PaintProc, Viewer, ViewerClass, ViewerClassRec],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [AddProp, CreateViewer, FetchProp, PaintViewer, RegisterViewerClass, RestoreViewer, SaveViewer, --SetMenu, --SetOpenHeight],
ViewerTools USING [GetContents, MakeNewTextViewer, SetSelection];
ThymeViewers: CEDAR MONITOR
IMPORTS Buttons, Commander, Containers, FileNames, Graphics, GraphicsOps, IO, Labels, Menus, MessageWindow, Rules, spGlobals, TiogaOps, TypeScript, ViewerEvents, ViewerIO, ViewerOps, VFonts, ViewerBLT, ViewerTools
EXPORTS spGlobals = {
entryHeight: CARDINAL = 12;
entryVSpace: CARDINAL = 6;
entryHSpace: CARDINAL = 10;
msgViewerH: CARDINAL = 100;
destroyEvent: ViewerEvents.EventRegistration ← NIL;
MakeThyme: Commander.CommandProc = {
MakeThymeViewers[FileNames.CurrentWorkingDirectory[]];
}; -- MakeThyme
MakeThymeViewers: PROC[wDir: Rope.ROPENIL] = {
handle: spGlobals.Handle ← NEW[spGlobals.ThymeToolRec ← []];
thymeMenus: Menus.Menu ← MakeThymeMenus[handle];
handle.outer ← Containers.Create[
info: [
name: version,
data: handle,
iconic: TRUE,
menu: thymeMenus,
column: left,
scrollable: FALSE],
paint: FALSE];
Menus.ChangeNumberOfLines[thymeMenus, 1];
MakeMainViewer[handle, wDir];
MakeMsgViewer[handle];
ViewerOps.SetOpenHeight[handle.outer, handle.height + msgViewerH];
ViewerOps.PaintViewer[handle.outer, all];
}; -- MakeThymeViewers
menus
MakeThymeMenus: PROC[handle: spGlobals.Handle] RETURNS[menu: Menus.Menu] = {
requestConfirmMsg: Rope.ROPE = "Please confirm by clicking at it again.";
menu ← Menus.CreateMenu[];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[
name: "Stop",
proc: Stop,
clientData: handle,
guarded: TRUE,
documentation: requestConfirmMsg]
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[
name: "Dump",
proc: Dump,
clientData: handle,
guarded: TRUE,
documentation: requestConfirmMsg]
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "Run", proc: Run, clientData: handle]
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "New", proc: New, clientData: handle]
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "TypeScriptMenus", proc: TypeScriptMenus,
clientData: handle]
];
typescript menus
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[
name: "Save",
proc: Save,
clientData: handle,
guarded: TRUE,
documentation: requestConfirmMsg],
line: 1
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[
name: "Reset",
proc: Reset,
clientData: handle,
guarded: TRUE,
documentation: requestConfirmMsg],
line: 1
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "Find", proc: Find, clientData: handle],
line: 1
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "Word", proc: Word, clientData: handle],
line: 1
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "Def", proc: Def, clientData: handle],
line: 1
];
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: "FindError", proc: FindError, clientData: handle],
line: 1
];
}; -- MakeThymeMenus
Stop: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
spGlobals.StopIt[handle];
}; -- Stop
Run: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
spGlobals.SimulateIt[handle];
}; -- Run
Dump: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
spGlobals.DumpIt[handle];
}; -- Dump
New: Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
[]← MakeThymeViewers[ViewerTools.GetContents[handle.wDir]];
};
TypeScriptMenus: ENTRY Menus.MenuProc = {
viewer: ViewerClasses.Viewer ← NARROW[parent];
menu: Menus.Menu ← viewer.menu;
numLines: Menus.MenuLine ← Menus.GetNumberOfLines[menu];
SELECT numLines FROM
1 => {
Menus.SetLine[menu, 1, tsMenuEntry];
numLines ← numLines + 1;
};
2 => numLines ← numLines - 1;
ENDCASE => ERROR;
ViewerBLT.ChangeNumberOfLines[viewer, numLines];
}; -- TypeScriptMenus
Save: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.simulation # NIL THEN MessageWindow.Append["Thyme.log could NOT be saved when a circuit is being simulated.", TRUE]
ELSE IF handle.msgStream # NIL THEN {
handle.msgStream.PutF["\nSaved: %g\n", IO.time[]];
handle.msgStream.Flush[];
ViewerOps.SaveViewer[handle.message];
};
};
}; -- Save
Reset: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.simulation # NIL THEN MessageWindow.Append["Thyme.log could NOT be reset when a circuit is being simulated.", TRUE]
ELSE IF handle.msgStream # NIL THEN {
ViewerOps.RestoreViewer[handle.message];
handle.msgStream.PutF["File: Thyme.log\nCreated: %g\n", IO.time[]];
};
};
}; -- Reset
Find: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.msgStream # NIL AND handle.message # NIL THEN {
dir: TiogaOps.SearchDir = SELECT mouseButton FROM
red => forwards, yellow => anywhere, ENDCASE => backwards;
case: BOOL = NOT shift;
found: BOOL ← TiogaOps.FindText[
viewer: handle.message,
rope: NIL, -- automatically uses contents of primary selection
whichDir: dir,
which: primary,
case: case];
IF NOT found THEN BlinkMsg["Text not found."];
};
};
}; -- Find
Word: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.msgStream # NIL AND handle.message # NIL THEN {
dir: TiogaOps.SearchDir = SELECT mouseButton FROM
red => forwards, yellow => anywhere, ENDCASE => backwards;
case: BOOL = NOT shift;
found: BOOL ← TiogaOps.FindWord[
viewer: handle.message,
rope: NIL, -- automatically uses contents of primary selection
whichDir: dir,
which: primary,
case: case];
IF NOT found THEN BlinkMsg["Text not found."];
};
};
}; -- Word
Def: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.msgStream # NIL AND handle.message # NIL THEN {
dir: TiogaOps.SearchDir = SELECT mouseButton FROM
red => forwards, yellow => anywhere, ENDCASE => backwards;
case: BOOL = NOT shift;
found: BOOL ← TiogaOps.FindDef[
viewer: handle.message,
rope: NIL, -- automatically uses contents of primary selection
whichDir: dir,
which: primary,
case: case];
IF NOT found THEN BlinkMsg["Text not found."];
};
};
}; -- Def
FindError: ENTRY Menus.MenuProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
IF handle.msgStream # NIL AND handle.message # NIL THEN {
dir: TiogaOps.SearchDir = SELECT mouseButton FROM
red => forwards, yellow => anywhere, ENDCASE => backwards;
case: BOOL = NOT shift;
found: BOOL ← TiogaOps.FindText[
viewer: handle.message,
rope: "g Error ",
whichDir: dir,
which: primary,
case: case];
IF NOT found THEN BlinkMsg["Text not found."];
};
};
}; -- FindError
BlinkMsg: PROC[msg: Rope.ROPE] = {
MessageWindow.Blink[];
MessageWindow.Append[msg, TRUE];
}; -- BlinkMsg
main sub viewer
initialOutputName: Rope.ROPE = "<Output file name(s) will be set automatically.>";
MakeMainViewer: PROC [handle: spGlobals.Handle, workingDir: Rope.ROPE ← NIL] = {
progressLabel, timeLabel, stepLabel: Labels.Label;
inputButton: Buttons.Button;
openInput: Buttons.Button;
initialInputName: Rope.ROPE = "<Specify input file name here.>";
handle.height ← handle.height + entryVSpace;
working directory
inputButton ← Buttons.Create[
info: [
name: "Working Directory:",
parent: handle.outer,
wy: handle.height + 2,
wh: entryHeight, -- default the width so that it will be computed for us
border: FALSE ],
clientData: handle,
proc: DirPrompt,
paint: FALSE];
handle.wDir ← ViewerTools.MakeNewTextViewer[
info: [
parent: handle.outer,
wx: inputButton.wx + inputButton.ww + entryHSpace,
wy: handle.height,
ww: 80*VFonts.CharWidth['M],
wh: entryHeight + 2,
data: workingDir,
scrollable: FALSE,
border: FALSE],
paint: FALSE];
handle.height ← handle.height + entryHeight + entryVSpace;
input file
inputButton ← Buttons.Create[
info: [
name: "Input File:",
parent: handle.outer,
wy: handle.height + 2,
wh: entryHeight,
border: FALSE ],
clientData: handle,
proc: InputPrompt,
paint: FALSE];
handle.input ← ViewerTools.MakeNewTextViewer[
info: [
parent: handle.outer,
wx: inputButton.wx + inputButton.ww + entryHSpace,
wy: handle.height,
ww: 80*VFonts.CharWidth['M],
wh: entryHeight + 2,
data: initialInputName,
scrollable: FALSE,
border: FALSE],
paint: FALSE];
handle.height ← handle.height + entryHeight + entryVSpace;
output file
[] ← Labels.Create[
info: [
name: "Output File:",
parent: handle.outer,
wy: handle.height,
border: FALSE ],
paint: FALSE];
handle.output ← Labels.Create[
info: [
name: initialOutputName,
parent: handle.outer,
wx: VFonts.StringWidth["Output File:"] + entryHSpace,
wy: handle.height + 2,
ww: 80*VFonts.CharWidth['W],
wh: entryHeight,
border: FALSE],
paint: FALSE];
handle.height ← handle.height + entryHeight + entryVSpace;
progress cursor
progressLabel ← Labels.Create[
info: [name: "Progress:", parent: handle.outer,
wy: handle.height, border: FALSE ],
paint: FALSE];
handle.progress ← CreateCursor[
parent: handle.outer,
x: progressLabel.wx + progressLabel.ww + entryHSpace,
y: handle.height];
handle.showDetailsButton ← Buttons.Create[
info: [
name: "details:",
parent: handle.outer,
wx: handle.progress.wx + handle.progress.ww + entryHSpace + entryHSpace,
wy: handle.height,
wh: entryHeight + 3,
border: TRUE ],
clientData: handle,
proc: ShowDetailsProc,
paint: FALSE];
Buttons.SetDisplayStyle[handle.showDetailsButton,
IF spGlobals.ShowDetails[handle] THEN $WhiteOnBlack ELSE $BlackOnWhite];
timeLabel ← Labels.Create[
info: [
name: "time:",
parent: handle.outer,
wx: handle.showDetailsButton.wx + handle.showDetailsButton.ww + entryHSpace,
wy: handle.height + 2,
wh: entryHeight,
border: FALSE ],
paint: FALSE];
handle.time ← Labels.Create[
info: [
parent: handle.outer,
wx: timeLabel.wx + timeLabel.ww + entryHSpace,
wy: handle.height + 2,
ww: 10*VFonts.StringWidth["M"],
wh: entryHeight,
border: FALSE],
paint: FALSE];
stepLabel ← Labels.Create[
info: [
name: "step:",
parent: handle.outer,
wx: handle.time.wx + handle.time.ww + entryHSpace,
wy: handle.height + 2,
wh: entryHeight,
border: FALSE ],
paint: FALSE];
handle.step ← Labels.Create[
info: [
parent: handle.outer,
wx: stepLabel.wx + stepLabel.ww + entryHSpace,
wy: handle.height + 2,
ww: 15*VFonts.StringWidth["M"],
wh: entryHeight,
border: FALSE],
paint: FALSE];
handle.height ← handle.height + entryHeight + entryVSpace;
}; -- MakeMainViewer
DirPrompt: Buttons.ButtonProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN ViewerTools.SetSelection[handle.wDir];
}; -- InputPrompt
InputPrompt: Buttons.ButtonProc = {
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN ViewerTools.SetSelection[handle.input];
}; -- InputPrompt
ShowDetailsProc: Buttons.ButtonProc = {
force the selection into the user input field
handle: spGlobals.Handle ← NARROW[clientData];
IF handle # NIL THEN {
spGlobals.ToggleShowDetails[handle];
Buttons.SetDisplayStyle[handle.showDetailsButton,
IF spGlobals.ShowDetails[handle] THEN $WhiteOnBlack ELSE $BlackOnWhite];
};
}; -- InputPrompt
message viewer
MakeMsgViewer: PROC [handle: spGlobals.Handle] = {
divider
rule: Rules.Rule ← Rules.Create[
info: [
parent: handle.outer,
wy: handle.height,
ww: handle.outer.cw,
wh: 1],
paint: FALSE];
Containers.ChildXBound[handle.outer, rule];
handle.height← handle.height + 2;
the msg sub window
handle.message← TypeScript.Create[
info: [
parent: handle.outer,
wy: handle.height,
ww: handle.outer.cw,
wh: 800,
border: FALSE,
file: "Thyme.log"],
paint: FALSE
];
IF ViewerOps.FetchProp[handle.message, $ThymeToolData] = NIL
THEN ViewerOps.AddProp[handle.message, $ThymeToolData, handle];
[in: , out: handle.msgStream] ← ViewerIO.CreateViewerStreams[
name: "Thyme.log", viewer: handle.message, backingFile: "Thyme.log"];
IO.PutF[handle.msgStream, "File: Thyme.log\nCreated: %g\n", IO.time[]];
Containers.ChildXBound[handle.outer, handle.message];
Containers.ChildYBound[handle.outer, handle.message];
}; -- MakeMsgViewer
MyDestroy: ViewerEvents.EventProc = {
h: spGlobals.Handle ← NARROW[ViewerOps.FetchProp[viewer, $ThymeToolData]];
IF h=NIL THEN RETURN;
IF event=destroy AND before THEN h.msgStream.Close[];
ViewerEvents.UnRegisterEventProc[proc: destroyEvent, event: destroy];
}; -- MyDestroy
cursors
CursorBits: TYPE= REF Cursors.CursorArray;
CursorArray: TYPE= Cursors.CursorArray;
CursorData: TYPE= RECORD[
bits: REF CursorArray ← NIL,
bitMap: GraphicsOps.BitmapRef ← NIL,
newData: BOOL ← FALSE,
paint: PROCESS ← NIL,
timeout: CONDITION,
invert: BOOLFALSE];
idleCursor: CursorBits= NEW[CursorArray ← ALL[0]];
inputCursor: CursorBits= NEW[CursorArray ←
[177740B, 102040B, 2400B, 2400B,
2751B, 2451B, 2451B, 2447B,
2001B, 2007B, 2000B, 2242B,
2525B, 2527B, 2524B, 7523B] ];
bombCursor: CursorBits= NEW[CursorArray ←
[ 30B, 140B, 200B, 700B,
600B, 700B, 3060B, 4010B,
4010B, 10004B, 10004B, 10004B,
4010B, 4010B, 3060B, 700B] ];
topoCursor: CursorBits= NEW[CursorArray ←
[ 0B, 400B, 0B, 20410B,
10020B, 4440B, 2100B, 0B,
124052B, 0B, 2100B, 4440B,
10020B, 20410B, 0B, 400B] ];
runCursor: ARRAY [0..4) OF CursorBits= [
NEW[CursorArray ←
[ 3700B, 14060B, 20410B, 41604B,
40404B, 100402B, 100402B, 100402B,
100002B, 100002B, 40004B, 40004B,
20010B, 14060B, 3700B, 0B] ],
NEW[CursorArray ←
[ 3700B, 14060B, 20010B, 40004B,
40004B, 100002B, 100022B, 100772B,
100022B, 100002B, 40004B, 40004B,
20010B, 14060B, 3700B, 0B] ],
NEW[CursorArray ←
[ 3700B, 14060B, 20010B, 40004B,
40004B, 100002B, 100002B, 100402B,
100402B, 100402B, 40404B, 41604B,
20410B, 14060B, 3700B, 0B] ],
NEW[CursorArray ←
[ 3700B, 14060B, 20010B, 40004B,
40004B, 100002B, 110002B, 137402B,
110002B, 100002B, 40004B, 40004B,
20010B, 14060B, 3700B, 0B] ] ];
CreateCursor: PROC [parent: ViewerClasses.Viewer, x, y: INTEGER ← 0]
RETURNS [cursor: ViewerClasses.Viewer] = TRUSTED {
cursorData: REF CursorData ← NEW[CursorData];
cursorData.bits ← NEW[CursorArray];
cursorData.bitMap ←
NEW[GraphicsOps.BitmapRep ←
[base: cursorData.bits, raster: 1, width: 16, height: 16]];
cursorData.newData ← TRUE;
Process.InitializeCondition[@cursorData.timeout, waitTime];
cursor ← ViewerOps.CreateViewer[
flavor: $ThymeCursor,
info: [
parent: parent,
wx: x, wy: y, ww: 16, wh: 16,
data: cursorData,
border: FALSE],
paint: FALSE];
}; -- CreateCursor
SetCursor: PUBLIC PROC [handle: spGlobals.Handle,
invert: BOOLFALSE] = {
ENABLE UNWIND => {};
d: REF CursorData;
IF handle = NIL THEN RETURN;
IF handle.progress = NIL THEN RETURN;
d← NARROW[handle.progress.data];
IF d = NIL THEN RETURN;
SELECT handle.stage FROM
idle => d.bits^ ← idleCursor^;
input => d.bits^ ← inputCursor^;
bomb => d.bits^ ← bombCursor^;
topo => d.bits^ ← topoCursor^;
run => d.bits^ ←
IF handle.vars = NIL THEN runCursor[0]^ ELSE
runCursor[handle.vars.runState]^;
ENDCASE =>
BlinkMsg["* Weird situation at SetCursor detected. Please inform Thyme implementor."];
d.invert ← invert;
IF d.paint=NIL THEN TRUSTED{
Process.Detach[d.paint ← FORK PaintProcess[handle.progress]]};
PaintProcess[handle.progress];
}; -- SetCursor
waitTime: Process.Ticks ← Process.MsecToTicks[100];
PaintProcess: -- ENTRY -- PROC[viewer: ViewerClasses.Viewer] = {
ENABLE UNWIND=> {};
d: REF CursorData ← NARROW[viewer.data];
d.newData ← TRUE;
WHILE d.newData DO
d.newData ← FALSE;
TRUSTED{ViewerOps.PaintViewer[viewer, client, FALSE, $Update]};
WAIT d.timeout;
ENDLOOP;
d.paint ← NIL;
TRUSTED{ViewerOps.PaintViewer[viewer, client, FALSE, $Update]};
}; -- PaintProcess
ThymeCursorPaint: ViewerClasses.PaintProc = {
ctx: Graphics.Context ← context;
cursorData: REF CursorData ← NARROW[self.data];
mark: Graphics.Mark ← Graphics.Save[ctx];
Graphics.SetCP[ctx, 0, 16];
IF cursorData.invert THEN [] ← Graphics.SetPaintMode[ctx, invert]
ELSE [] ← Graphics.SetPaintMode[ctx, opaque];
GraphicsOps.DrawBitmap[ctx, cursorData.bitMap, 16, 16];
Graphics.Restore[ctx, mark];
}; -- ThymeCursorPaint
Main Program starts here
global variables
version: PUBLIC Rope.ROPE← "Thyme - Cedar5.2 - Aug. 1984";
refNodeRec: PUBLIC spGlobals.RefNodeRec= NEW[spGlobals.NodeRec];
refConRec: PUBLIC spGlobals.RefConRec= NEW[spGlobals.ConRec];
refR: PUBLIC spGlobals.RefR= NEW[spGlobals.ResistorBody];
refUnReal: PUBLIC spGlobals.RefUnReal= NEW[spGlobals.UnReal];
modelTable: PUBLIC spGlobals.ModelTablePtr← NIL;
functionTable: PUBLIC spGlobals.FuncTablePtr← NIL;
-- progress cursor
thymeCursor: ViewerClasses.ViewerClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: ThymeCursorPaint,
tipTable: NIL]
];
Thyme menus
thymeMenus: Menus.Menu ← MakeThymeMenus[];
tsMenuEntry: Menus.MenuEntry ← Menus.GetLine[thymeMenus, 1];
Menus.SetLine[thymeMenus, 1, NIL];
Menus.ChangeNumberOfLines[thymeMenus, 1];
registrations:
ViewerOps.RegisterViewerClass[$ThymeCursor, thymeCursor];
Commander.Register[
key: "Thyme",
proc: MakeThyme,
doc: "Start an instance of the circuit simulator Thyme." ];
destroyEvent --
[] ← ViewerEvents.RegisterEventProc[proc: MyDestroy, event: destroy];
build the library functions and models
START spGlobals.spModels;
START spGlobals.Level2Model;
START spGlobals.spFunctions;
}.
CHANGE LOG
Chen, June 12, 1984 11:21:28 am PDT, created.