CSMonitorImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Written by Shand, September 20, 1983 11:40 pm
Last Edited by: Shand, July 28, 1984 7:56:25 pm PDT
DIRECTORY
CD USING [Level, NewLevel, Rect, Design, Technology, RegisterTechnology, lambda],
CornerStitching USING [Tesselation, EnumerateArea, Region, PerTileProc, Area, Value],
CDOps USING [CreateDesign, AddAnObject, Redraw],
CDCommands USING [SelectAll, DeleteSelected],
CDTechnology USING [TeachColor, SetTipTable, Brick4, Brick8],
CDViewer USING [CreateViewer],
CDProperties USING [RegisterProperty, GetProp, PutProp],
CDSequencer USING [ImplementCommand, Command],
CDInline USING [Intersection, SizeOfRect, BaseOfRect],
CDRects USING [CreateBareRect],
TerminalIO USING [WriteRope],
Rope USING [ROPE],
PrintTV USING [Print],
AMTypes USING [TV],
AMBridge USING [TVForATOM, TVForROPE, TVForReferent],
IO USING [STREAM, Put, PutRope, PutF, PutFR, int, rope, char, ROS, RopeFromROS],
CSMonitor
;
CSMonitorImpl: CEDAR PROGRAM
IMPORTS CD, CornerStitching, CDOps, CDCommands, CDProperties, CDInline, CDRects, CDTechnology, CDViewer, CDSequencer, TerminalIO, PrintTV, AMBridge, IO
EXPORTS CSMonitor
~ BEGIN
Monitor:
PUBLIC
PROCEDURE [plane:
REF CornerStitching.Tesselation, name: Rope.
ROPE ←
NIL, paintDark: CSMonitor.PaintPredicate ←
NIL] ~ {
design: CD.Design ← CDOps.CreateDesign[csMonitor];
design.name ← IF name # NIL THEN name ELSE "Tile World";
IF paintDark = NIL THEN paintDark ← DefaultPaintDark;
[] ← CDViewer.CreateViewer[design];
CDProperties.PutProp[onto: design, prop: $Tesselation, val: plane];
CDProperties.PutProp[onto: design, prop: $PaintDark, val: NEW[ CSMonitor.PaintPredicate ← paintDark]];
Display[ design]
};
DefaultPaintDark: CSMonitor.PaintPredicate
--
[tileVal: REF ANY] RETURNS [BOOLEAN] -- ~ {
RETURN [ISTYPE[tileVal, ATOM]]
};
Display:
PROCEDURE [d:
CD.Design] ~ {
ChooseColour:
PROCEDURE [val:
REF
ANY]
RETURNS [
CD.Level] ~ {
IF val =
NIL
THEN
RETURN [space]
ELSE
IF paintDark^[val]
THEN
RETURN [solidDark]
};
windowBound: INT ~ 100000;
displayRegion: CD.Rect ~ [-windowBound,-windowBound, windowBound, windowBound];
r: CD.Rect;
plane: REF CornerStitching.Tesselation ~ NARROW [ CDProperties.GetProp[from: d, prop: $Tesselation] ];
paintDark: REF CSMonitor.PaintPredicate ~ NARROW [ CDProperties.GetProp[from: d, prop: $PaintDark] ];
CDCommands.SelectAll[d];
CDCommands.DeleteSelected[d];
FOR t:
LIST
OF
REF CornerStitching.Region ←
NARROW[ plane.EnumerateArea[rect~displayRegion, backgroundValue~$Nothing] ], t.rest
WHILE t #
NIL
DO
r ← CDInline.Intersection[t.first.rect, displayRegion];
CDOps.AddAnObject[design: d, ob ~ CDRects.CreateBareRect[size ~ CDInline.SizeOfRect[r], l ~ ChooseColour[t.first.value]], location ~ CDInline.BaseOfRect[r], orientation ~ 0]
ENDLOOP;
CDCommands.SelectAll[d];
CDOps.Redraw[d]
};
csMonitor: CD.Technology;
solid: CD.Level;
solidDark: CD.Level;
space: CD.Level;
FindTile:
PROCEDURE [comm: CDSequencer.Command]
RETURNS [
REF CornerStitching.Region] ~ {
NoteTile: CornerStitching.PerTileProc ~ {
tileAtPoint^ ← [tile.Area, tile.Value]
};
plane: REF CornerStitching.Tesselation ~ NARROW [ CDProperties.GetProp[from: comm.design, prop: $Tesselation] ];
tileAtPoint: REF CornerStitching.Region ~ NEW[ CornerStitching.Region];
[] ← plane.EnumerateArea[ rect~[x1~comm.pos.x, y1~comm.pos.y, x2~comm.pos.x, y2~comm.pos.y], perTile~NoteTile, backgroundValue~$Nothing];
RETURN [tileAtPoint]
};
depth: INT ← 4;
width: INT ← 32;
PrintingDepth:
PROCEDURE [comm: CDSequencer.Command] ~ {
SELECT comm.a
FROM
$SuccPrintingDepth => depth ← depth.SUCC;
$PredPrintingDepth => IF depth > 1 THEN depth ← depth.PRED;
ENDCASE;
TerminalIO.WriteRope[ IO.PutFR[ "%g CS Monitor printing depth = %d\n", IO.rope[ comm.design.name], IO.int[ depth]] ];
};
PrintingWidth:
PROCEDURE [comm: CDSequencer.Command] ~ {
SELECT comm.a
FROM
$SuccPrintingWidth => width ← width.SUCC;
$PredPrintingWidth => IF depth > 1 THEN width ← width.PRED;
ENDCASE;
TerminalIO.WriteRope[IO.PutFR["%g CS Monitor printing width = %d\n", IO.rope[ comm.design.name], IO.int[width]]];
};
GetTV:
PROCEDURE [ra:
REF
ANY]
RETURNS [tv: AMTypes.
TV] ~ {
WITH ra
SELECT
FROM
a: ATOM => TRUSTED {tv ← AMBridge.TVForATOM[a]};
r: Rope.ROPE => TRUSTED {tv ← AMBridge.TVForROPE[r]};
ENDCASE => TRUSTED {tv ← AMBridge.TVForReferent[ra]};
};
PrintTileValue:
PROCEDURE [comm: CDSequencer.Command] ~ {
ropeStream: IO.STREAM ← IO.ROS[];
WriteWhere[ropeStream, comm];
IO.PutRope[ropeStream, "Tile Value =\n"];
PrintTV.Print[tv~ GetTV[FindTile[comm].value], put~ ropeStream, depth~ depth, width~ width];
IO.Put[ropeStream, IO.char['\n]];
TerminalIO.WriteRope[IO.RopeFromROS[ropeStream]];
};
PrintTile:
PROCEDURE [comm: CDSequencer.Command] ~ {
ropeStream: IO.STREAM ← IO.ROS[];
WriteWhere[ropeStream, comm];
IO.PutRope[ropeStream, "Tile =\n"];
PrintTV.Print[tv~ GetTV[FindTile[comm]], put~ ropeStream, depth~ depth, width~ width];
IO.Put[ropeStream, IO.char['\n]];
TerminalIO.WriteRope[IO.RopeFromROS[ropeStream]];
};
Redisplay:
PROCEDURE [comm: CDSequencer.Command] ~ {
Display[comm.design]
};
WriteWhere:
PROCEDURE [strm:
IO.
STREAM, comm: CDSequencer.Command] ~ {
IO.PutF[strm, " In %g At (%d,%d) ", IO.rope[ comm.design.name], IO.int[comm.pos.x/CD.lambda], IO.int[comm.pos.y/CD.lambda]];
};
Init:
PROCEDURE ~ {
-- Fix so it keeps trying names until chipndale gives in.
red: CARDINAL ~ 4;
yellow: CARDINAL ~ 14;
blue: CARDINAL ~ 2;
csMonitor ← CD.RegisterTechnology[key~$CSMonitor, name~"Corner Stitching Monitor"];
solid ← CD.NewLevel[technology~csMonitor, uniqueKey~$SOLID];
solidDark ← CD.NewLevel[technology~csMonitor, uniqueKey~$SOLIDATOM];
space ← CD.NewLevel[technology~csMonitor, uniqueKey~$SP];
IF ~ CDProperties.RegisterProperty[$Tesselation] THEN TerminalIO.WriteRope["$Tesselation Redefined\n"];
CDTechnology.SetTipTable[csMonitor, "ChipNDaleCSMonitor.TIP"];
CDTechnology.TeachColor[lev~ solid, bpp~ 1, brick~ [125252B, 0, 52525B, 0]];
CDTechnology.TeachColor[lev~ solidDark, bpp~ 1, brick~ [52525B, 125252B, 52525B, 125252B]];
CDTechnology.TeachColor[lev~ space, bpp~ 1, brick~ [0,0,0,0]];
CDTechnology.TeachColor[lev~ solid, bpp~ 4, brick~ CDTechnology.Brick4[red]];
CDTechnology.TeachColor[lev~ solidDark, bpp~ 4, brick~ CDTechnology.Brick4[blue]];
CDTechnology.TeachColor[lev~ space, bpp~ 4, brick~ CDTechnology.Brick4[yellow]];
CDTechnology.TeachColor[lev~ solid, bpp~ 8, brick~ CDTechnology.Brick8[red]];
CDTechnology.TeachColor[lev~ solidDark, bpp~ 8, brick~ CDTechnology.Brick8[blue]];
CDTechnology.TeachColor[lev~ space, bpp~ 8, brick~ CDTechnology.Brick8[yellow]];
CDSequencer.ImplementCommand[$PrintTileValue, PrintTileValue, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PrintTile, PrintTile, csMonitor, doQueue];
CDSequencer.ImplementCommand[$SuccPrintingDepth, PrintingDepth, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PredPrintingDepth, PrintingDepth, csMonitor, doQueue];
CDSequencer.ImplementCommand[$SuccPrintingWidth, PrintingWidth, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PredPrintingWidth, PrintingWidth, csMonitor, doQueue];
CDSequencer.ImplementCommand[$Redisplay, Redisplay, csMonitor, doQueue];
TerminalIO.WriteRope["Corner Stitching Monitor loaded\n"];
};
Init[];
END.