CSMonitorImpl.mesa
Copyright © 1984, 1986 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: Christian Jacobi, March 25, 1986 6:00:16 pm PST
Last Edited by: Neil Gunther May 2, 1986 11:53:15 am PDT
Last edited by: Christian Jacobi, November 5, 1986 11:17:18 am PST
gbb October 17, 1986 4:26:53 pm PDT
DIRECTORY
AMBridge USING [TVForATOM, TVForReferent, TVForROPE],
AMTypes USING [TV],
CD USING [Design, FetchTechnology, Instance, InstanceList, Layer, NewLayer, Number, Position, Rect, RegisterTechnology, Technology],
CDBasics USING [BaseOfRect, Intersection, NonEmpty, SizeOfRect],
CDCells USING [IncludeOb],
CDColors,
CDCommandOps,
CDEnvironment USING [GetTipTable, SetTipTable],
CDOps,
CDPopUpMenus,
CDProperties USING [GetProp, PutProp, PutInstanceProp, RegisterProperty],
CDRects USING [CreateBareRect],
CDSequencer USING [Command, ImplementCommand],
CDViewer USING [CreateViewer, DesignOf, ShowAndScale, ViewerList, ViewersOf],
CStitching,
CSMonitor,
ImagerColor,
IO,
PrintTV USING [Print],
Rope USING [ROPE, Equal],
TerminalIO,
UserCredentials USING [Get],
ViewerClasses USING [Viewer],
ViewerOps USING [SetViewer];
CSMonitorImpl: CEDAR PROGRAM
IMPORTS AMBridge, CD, CDBasics, CDCells, CDColors, CDCommandOps, CDEnvironment, CDOps, CDPopUpMenus, CDProperties, CDRects, CDSequencer, CDViewer, CStitching, ImagerColor, IO, PrintTV, Rope, TerminalIO, UserCredentials, ViewerOps
EXPORTS CSMonitor
SHARES CDPopUpMenus =
BEGIN
csMonitor: CD.Technology;
solidGray, solidDark, space: CD.Layer;
tessProp: REF ATOMNEW[ATOM←$Tesselation];
backgroundValue: REFNEW[ATOM←$nothing];
surrround: CD.Number ← 100;
isgbb: BOOL ~ Rope.Equal[UserCredentials.Get[].name, "Beretta.pa", FALSE] OR Rope.Equal[UserCredentials.Get[].name, "Gunther.pa", FALSE];
depth: INT ← 4;
width: INT ← 32;
TesselationOff: PROC [d: CD.Design] RETURNS [plane: CStitching.Tesselation] = {
plane ← NARROW[CDProperties.GetProp[from: d, prop: tessProp]]
};
DefaultPaintDark: CSMonitor.PaintPredicate = {
RETURN [ISTYPE[val, ATOM]]
};
Monitor: PUBLIC PROC [plane: CStitching.Tesselation, name: Rope.ROPENIL, paintDark: CSMonitor.PaintPredicate ← NIL] RETURNS [viewer: ViewerClasses.Viewer] = {
design: CD.Design = CDOps.CreateDesign[csMonitor];
design.name ← IF name#NIL THEN name ELSE "Tile World";
IF paintDark = NIL THEN paintDark ← DefaultPaintDark;
CDProperties.PutProp[design, tessProp, plane];
CDProperties.PutProp[design, $PaintDark, NEW[CSMonitor.PaintPredicate ← paintDark]];
ResetFromDesign[design];
viewer ← CDViewer.CreateViewer[design, TRUE, FALSE];
IF isgbb THEN {
ViewerOps.SetViewer[viewer: viewer, data: NEW[INT←(csMonitor.lambda/2)], op: $Grid];
ViewerOps.SetViewer[viewer: viewer, data: NEW[INT𡤌sMonitor.lambda], op: $Ticks]
}
};
Reset: PUBLIC PROC [ref: REF] = {
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];
};
ResetFromDesign: PROC [d: CD.Design] = {
ChooseColor: PROC [val: REF ANY] RETURNS [CD.Layer] = {
IF val=NIL THEN RETURN [space]
ELSE IF paintDark^[val] THEN RETURN [solidDark]
ELSE RETURN [solidGray];
};
IncludeTile: PROC [tile: CStitching.Tile, data: REF ANY] = {
r: CStitching.Rect = CDBasics.Intersection[CStitching.Area[tile], displayRegion];
i: CD.Instance ← CDCells.IncludeOb[
design: d,
ob: CDRects.CreateBareRect[
size: CDBasics.SizeOfRect[r],
l: ChooseColor[tile.value]
],
trans: [CDBasics.BaseOfRect[r]]
].newInst;
i.selected ← TRUE;
CDProperties.PutInstanceProp[i, $tile, tile];
IF tile.value#NIL THEN CDProperties.PutInstanceProp[i, $SignalName, tile.value];
};
old: CD.InstanceList←NIL;
displayRegion: CD.Rect;
plane: CStitching.Tesselation = TesselationOff[d];
paintDark: REF CSMonitor.PaintPredicate = NARROW[CDProperties.GetProp[from: d, prop: $PaintDark] ];
usedRect: CD.Rect;
IF plane=NIL THEN ERROR;
usedRect ← CStitching.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.Redraw[d]; --causes later redrawing of small areas to be clipped
CStitching.EnumerateArea[
plane: plane,
rect: displayRegion,
skip: backgroundValue,
eachTile: IncludeTile
];
CDOps.DoTheDelayedRedraws[d];
DisposeOf[old];
};
DisposeOf: PROC [il: CD.InstanceList] = {
--helps garbage collection, but only a little bit to avoid zct grow
n: INT ← 1000;
FOR il2: CD.InstanceList ← il, il2.rest WHILE il2#NIL DO
IF (n ← n-1)<0 THEN {il2.rest←NIL; RETURN};
il.first.ob ← NIL;
il.first.properties ← NIL;
ENDLOOP
};
SetPrintingDepthComm: PROC [comm: CDSequencer.Command] = {
SELECT comm.key FROM
$SuccPrintingDepth => depth ← depth.SUCC;
$PredPrintingDepth => IF depth > 1 THEN depth ← depth.PRED;
ENDCASE => NULL;
TerminalIO.PutF["%g CS Monitor printing depth = %d\n", IO.rope[ comm.design.name], IO.int[ depth]];
};
SetPrintingWidthComm: PROC [comm: CDSequencer.Command] = {
SELECT comm.key FROM
$SuccPrintingWidth => width ← width.SUCC;
$PredPrintingWidth => IF depth > 1 THEN width ← width.PRED;
ENDCASE => NULL;
TerminalIO.PutF["%g CS Monitor printing width = %d\n", IO.rope[ comm.design.name], IO.int[width]];
};
PrintTileComm: PROC [comm: CDSequencer.Command] = {
WriteWhere: PROC [strm: IO.STREAM, comm: CDSequencer.Command] = {
IO.PutF[strm, "\nIn %g at (%g,%g).\n ",
IO.rope[comm.design.name],
IO.rope[CDOps.LambdaRope[comm.pos.x, csMonitor.lambda]],
IO.rope[CDOps.LambdaRope[comm.pos.y, csMonitor.lambda]]
];
};
GetTV: PROC [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]};
};
GetTile: PROC [d: CD.Design, at: CD.Position] RETURNS [CStitching.Tile] = {
plane: CStitching.Tesselation = TesselationOff[comm.design];
tile: CStitching.Tile ← CStitching.FindTile[plane, at];
RETURN [tile]
};
--PrintTileComm
ropeStream: IO.STREAM ← TerminalIO.TOS[];
tile: CStitching.Tile;
WriteWhere[ropeStream, comm];
IO.PutRope[ropeStream, "Tile "];
IF comm.key=$PrintTileValue THEN IO.PutRope[ropeStream, "value"];
IO.PutRope[ropeStream, " = "];
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.key=$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]];
};
RedisplayComm: PROC [comm: CDSequencer.Command] = {
ResetFromDesign[comm.design]
};
CenterComm: PROC [comm: CDSequencer.Command] = {
--shows a constant rectangle; just in case your lost...
showRect: CD.Rect ← CD.Rect[x1: -10, y1: -10, x2: 100, y2: 100];
vl: CDViewer.ViewerList ← CDViewer.ViewersOf[comm.design];
IF vl#NIL THEN
CDViewer.ShowAndScale[vl.first, showRect]
};
Init: PROC = {
Checker8: PROC[col1, col2: CARDINAL] RETURNS [REF CDColors.Brick] = {
RETURN[NEW[CDColors.Brick ← [col1*256+col2, col2*256+col1, col1*256+col2, col2*256+col1]]]
};
csMonitor ← CD.FetchTechnology [$CSMonitor0];
IF (csMonitor = NIL) THEN csMonitor ← CD.RegisterTechnology[key: $CSMonitor0, name: "CSMonitor", lambda: IF isgbb THEN 8 ELSE 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];
IF CDEnvironment.GetTipTable[csMonitor]=NIL THEN
CDEnvironment.SetTipTable[csMonitor, "Standard"];
CDColors.DefineColor[solidGray, NEW[CDColors.Brick ← [125252B, 0, 52525B, 0]], bw];
CDColors.DefineColor[solidGray, Checker8[8, 8], bit8];
CDColors.DefineIColor[solidGray, ImagerColor.ColorFromRGB[[0.5, 0.5, 0.5]], bit8];
CDColors.DefineColor[solidDark, NEW[CDColors.Brick ← [52525B, 125252B, 52525B, 125252B]], bw];
CDColors.DefineColor[solidDark, Checker8[4, 4], bit8];
CDColors.DefineIColor[solidGray, ImagerColor.ColorFromRGB[[0.1, 0.1, 0.1]], bit8];
CDColors.DefineColor[space, NEW[CDColors.Brick ← [0, 0, 0, 0]], bw];
CDColors.DefineColor[space, NEW[CDColors.Brick ← [0, 0, 0, 0]], bit8];
CDColors.DefineIColor[space, ImagerColor.ColorFromRGB[[1, 1, 1]], bit8];
CDSequencer.ImplementCommand[$PrintTileValue, PrintTileComm, csMonitor, doQueue];
CDSequencer.ImplementCommand[$PrintTile, 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];
[] ← CDPopUpMenus.MakeMenu[$csMonitorComm, "CS Monitor commands", "debugging cornerstitched tessselations", csMonitor];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "update from tesselation", "resets plane and redisplay", $Redisplay];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "depth + 1", "of information", $SuccPrintingDepth];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "depth - 1", "of information", $PredPrintingDepth];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "width + 1", "of information", $SuccPrintingWidth];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "width - 1", "of information", $PredPrintingWidth];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "print value", "", $PrintTileValue];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "print tile", "", $PrintTileComm];
CDCommandOps.RegisterWithMenu[$csMonitorComm, "standard and positionscale", "", $Center];
TerminalIO.PutRope["Corner Stitching monitor loaded.\n"];
};
Init[];
END.
gbb February 17, 1986 3:34:09 pm PST
Fixed printing of cursor position.
changes to: PrintTileComm: added division by  in WriteWhere
gbb October 17, 1986 4:26:24 pm PDT
The command for PrintTile had the wrong key.
changes to: Init