CSMImpl.mesa
Copyright © 1984, 1985 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
Last Edited by: Beretta, October 30, 1984 10:31:53 am PST
Last Edited by: Jacobi, January 23, 1986 1:51:55 pm PST
DIRECTORY
AMBridge USING [TVForATOM, TVForROPE, TVForReferent],
AMTypes USING [TV],
CD,
CDBasics USING [Intersection, SizeOfRect, BaseOfRect, NonEmpty],
CDCells,
CDColors,
CDLayers,
CDMenus,
CDOps,
CDProperties,
CDRects USING [CreateBareRect],
CDSequencer USING [ImplementCommand, Command],
CDTipEtc,
CDViewer,
CS,
CSM,
IO,
PrintTV USING [Print],
Rope USING [ROPE],
TerminalIO,
ViewerClasses USING [Viewer];
CSMImpl: CEDAR PROGRAM
IMPORTS AMBridge, CD, CDBasics, CDCells, CDColors, CDLayers, CDMenus, CDOps, CDProperties, CDRects, CDSequencer, CDTipEtc, CDViewer, CS, IO, PrintTV, TerminalIO
EXPORTS CSM =
BEGIN
csMonitor: CD.Technology;
solidGray: CD.Layer;
solidDark: CD.Layer;
space: CD.Layer;
tessProp: REF ATOMNEW[ATOM←$Tesselation];
backgroundValue: REFNEW[ATOM←$nothing];
surrround: CD.Number ← 100;
depth: INT ← 4;
width: INT ← 32;
TesselationOff: PROC [d: CD.Design] RETURNS [plane: CS.Tesselation] =
BEGIN
plane ← NARROW[CDProperties.GetProp[from: d, prop: tessProp]]
END;
DefaultPaintDark: CSM.PaintPredicate =
BEGIN
RETURN [ISTYPE[val, ATOM]]
END;
Monitor: PUBLIC PROC [plane: CS.Tesselation, name: Rope.ROPENIL, paintDark: CSM.PaintPredicate ← NIL] RETURNS [viewer: ViewerClasses.Viewer] =
BEGIN
design: CD.Design = CDOps.CreateDesign[csMonitor];
design.name ← IF name#NIL THEN name ELSE "Tile World";
IF paintDark = NIL THEN paintDark ← DefaultPaintDark;
CDProperties.PutProp[onto: design, prop: tessProp, val: plane];
CDProperties.PutProp[onto: design, prop: $PaintDark, val: NEW[CSM.PaintPredicate ← paintDark]];
ResetFromDesign[design];
CDLayers.SetCurrentLayer[design, CD.highLightShade];
CDLayers.SetLayerWidth[design, CD.highLightShade, 0];
viewer ← CDViewer.CreateViewer[design];
END;
Reset: PUBLIC PROC [ref: REF] =
BEGIN
design: CD.Design ← NIL;
WITH ref SELECT FROM
d: CD.Design => design ← d;
v: ViewerClasses.Viewer => design ← CDViewer.DesignOf[v];
ENDCASE => NULL;
IF design#NIL THEN ResetFromDesign[design];
END;
ResetFromDesign: PROC [d: CD.Design] =
BEGIN
ChooseColor: PROC [val: REF ANY] RETURNS [CD.Layer] =
BEGIN
IF val=NIL THEN RETURN [space]
ELSE IF paintDark^[val] THEN RETURN [solidDark]
ELSE RETURN [solidGray];
END;
IncludeTile: PROC [tile: CS.Tile, data: REF ANY] =
BEGIN
r: CS.Rect = CDBasics.Intersection[CS.Area[tile], displayRegion];
i: CD.Instance ← CDCells.IncludeOb[
design: d,
ob: CDRects.CreateBareRect[
size: CDBasics.SizeOfRect[r],
l: ChooseColor[tile.value]
],
position: CDBasics.BaseOfRect[r]
].newInst;
i.selected ← TRUE;
CDProperties.PutPropOnInstance[i, $tile, tile];
IF tile.value#NIL THEN CDProperties.PutPropOnInstance[i, $SignalName, tile.value];
END;
old: CD.InstanceList←NIL;
displayRegion: CD.Rect;
plane: CS.Tesselation = TesselationOff[d];
paintDark: REF CSM.PaintPredicate = NARROW[CDProperties.GetProp[from: d, prop: $PaintDark] ];
usedRect: CD.Rect;
IF plane=NIL THEN ERROR;
usedRect ← CS.BBox[plane];
IF ~CDBasics.NonEmpty[usedRect] THEN usedRect ← [0, 0, 0, 0];
displayRegion.x1 ← MAX[usedRect.x1, -(LAST[INT]-surrround-4)]-surrround;
displayRegion.y1 ← MAX[usedRect.y1, -(LAST[INT]-surrround-4)]-surrround;
displayRegion.x2 ← MIN[usedRect.x2, (LAST[INT]-surrround-4)]+surrround;
displayRegion.y2 ← MIN[usedRect.y2, (LAST[INT]-surrround-4)]+surrround;
old ← CDOps.InstList[d];
CDOps.SetInstList[d, NIL];
CDOps.DelayedRedraw[d]; --causes later redrawing of small areas to be clipped
CS.EnumerateArea[
plane: plane,
rect: displayRegion,
skip: backgroundValue,
eachTile: IncludeTile
];
CDOps.DoTheDelayedRedraws[d];
DisposeOf[old];
END;
DisposeOf: PROC [il: CD.InstanceList] =
BEGIN
il2: CD.InstanceList;
WHILE il#NIL DO
il2 ← il.rest;
il.first.properties ← NIL;
il.first.ob ← NIL;
il.rest ← NIL;
il ← il2
ENDLOOP
END;
SetPrintingDepthComm: PROC [comm: CDSequencer.Command] =
BEGIN
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]]];
END;
SetPrintingWidthComm: PROC [comm: CDSequencer.Command] =
BEGIN
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]]];
END;
PrintTileComm: PROC [comm: CDSequencer.Command] =
BEGIN
WriteWhere: PROC [strm: IO.STREAM, comm: CDSequencer.Command] =
BEGIN
IO.PutF[strm, "In %g at (%d,%d) ",
IO.rope[comm.design.name],
IO.int[comm.pos.x],
IO.int[comm.pos.y]];
END;
GetTV: PROC [ra: REF ANY] RETURNS [tv: AMTypes.TV] =
BEGIN
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]};
END;
GetTile: PROC [d: CD.Design, at: CD.Position] RETURNS [CS.Tile] =
BEGIN
plane: CS.Tesselation = TesselationOff[comm.design];
tile: CS.Tile ← CS.FindTile[plane, at];
RETURN [tile]
END;
--PrintTileComm
ropeStream: IO.STREAM ← TerminalIO.TOS[];
tile: CS.Tile;
WriteWhere[ropeStream, comm];
IO.PutRope[ropeStream, "Tile "];
IF comm.a=$PrintTileValue THEN IO.PutRope[ropeStream, "value"];
IO.PutRope[ropeStream, " =\n "];
tile ← GetTile[comm.design, comm.pos];
IF tile=NIL THEN IO.PutRope[ropeStream, " no tile"]
ELSE IF tile.value=backgroundValue THEN IO.PutRope[ropeStream, " background"]
ELSE {
tv: AMTypes.TV;
IF comm.a=$PrintTileValue THEN
tv ← GetTV[tile.value]
ELSE
tv ← GetTV[tile];
PrintTV.Print[tv: tv, put: ropeStream, depth: depth, width: width];
};
IO.Put[ropeStream, IO.char['\n]];
END;
RedisplayComm: PROC [comm: CDSequencer.Command] =
BEGIN
ResetFromDesign[comm.design]
END;
showRect: CD.Rect ← CD.Rect[x1: -10, y1: -10, x2: 100, y2: 100];
CenterComm: PROC [comm: CDSequencer.Command] =
BEGIN
vl: CDViewer.ViewerList ← CDViewer.ViewersOf[comm.design];
IF vl#NIL THEN {
CDViewer.ShowAndScale[vl.first, showRect]
};
END;
Init: PROC =
BEGIN
Checker8: PROC[col1, col2: CARDINAL] RETURNS[REF CDColors.Brick] =
BEGIN
RETURN[NEW[CDColors.Brick ← [col1*256+col2, col2*256+col1, col1*256+col2, col2*256+col1]]]
END;
csMonitor ← CD.RegisterTechnology[key: $CSMonitorx1, name: "CSM", lambda: 1];
solidGray ← CD.NewLayer[technology: csMonitor, uniqueKey: $SOLID];
solidDark ← CD.NewLayer[technology: csMonitor, uniqueKey: $SOLIDATOM];
space ← CD.NewLayer[technology: csMonitor, uniqueKey: $SP];
[] ← CDProperties.RegisterProperty[tessProp, $IDontCare];
CDTipEtc.SetTipTable[csMonitor, "Standard"];
CDColors.DefineColor[solidGray, NEW[CDColors.Brick ← [125252B, 0, 52525B, 0]], bw];
CDColors.DefineColor[solidGray, NEW[CDColors.Brick ← [125252B, 0, 52525B, 0]], bit4];
CDColors.DefineColor[solidGray, Checker8[8, 8], bit8];
CDColors.DefineColor[solidDark, NEW[CDColors.Brick ← [52525B, 125252B, 52525B, 125252B]], bw];
CDColors.DefineColor[solidDark, NEW[CDColors.Brick ← [52525B, 125252B, 52525B, 125252B]], bit4];
CDColors.DefineColor[solidDark, Checker8[4, 4], bit8];
CDColors.DefineColor[space, NEW[CDColors.Brick ← [0, 0, 0, 0]], bw];
CDColors.DefineColor[space, NEW[CDColors.Brick ← [0, 0, 0, 0]], bit4];
CDColors.DefineColor[space, NEW[CDColors.Brick ← [0, 0, 0, 0]], bit8];
CDSequencer.ImplementCommand[$PrintTileValue, PrintTileComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PrintTileComm, PrintTileComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$SuccPrintingDepth, SetPrintingDepthComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PredPrintingDepth, SetPrintingDepthComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$SuccPrintingWidth, SetPrintingWidthComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PredPrintingWidth, SetPrintingWidthComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$Redisplay, RedisplayComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$Center, CenterComm, csMonitor, dontQueue];
[] ← CDMenus.CreateMenu["CS Monitor commands", $csMonitorComm];
CDMenus.ImplementMenuCommand[$csMonitorComm, $csMonitorComm, csMonitor];
CDMenus.CreateEntry[$csMonitorComm, "update from tesselation", $Redisplay];
CDMenus.CreateEntry[$csMonitorComm, "depth + 1", $SuccPrintingDepth];
CDMenus.CreateEntry[$csMonitorComm, "depth - 1", $PredPrintingDepth];
CDMenus.CreateEntry[$csMonitorComm, "width + 1", $SuccPrintingWidth];
CDMenus.CreateEntry[$csMonitorComm, "width - 1", $PredPrintingWidth];
CDMenus.CreateEntry[$csMonitorComm, "print value", $PrintTileValue];
CDMenus.CreateEntry[$csMonitorComm, "print tile", $PrintTileComm];
CDMenus.CreateEntry[$csMonitorComm, "standard scale", $Center];
TerminalIO.WriteRope["CS monitor loaded\n"];
END;
Init[];
END.