<> <> <> <> <> <> <> <> DIRECTORY AMBridge USING [TVForATOM, TVForReferent, TVForROPE], AMTypes USING [TV], CD USING [Design, Instance, InstanceList, Layer, NewLayer, Number, Position, Rect, RegisterTechnology, Technology], CDBasics USING [BaseOfRect, Intersection, NonEmpty, SizeOfRect], CDCells USING [IncludeOb], CDColors USING [Brick, DefineColor], CDCommandOps USING [LambdaRope], CDMenus USING [CreateEntry, CreateMenu, ImplementCommandToCallMenu], CDOps USING [CreateDesign, DelayedRedraw, DoTheDelayedRedraws, InstList, SetInstList], CDProperties USING [GetProp, PutProp, PutInstanceProp, RegisterProperty], CDRects USING [CreateBareRect], CDSequencer USING [Command, ImplementCommand], CDTipEtc USING [SetTipTable], CDViewer USING [CreateViewer, DesignOf, ShowAndScale, ViewerList, ViewersOf], CStitching USING [Area, BBox, Rect, EnumerateArea, Tesselation, Tile, FindTile], CSMonitor USING [PaintPredicate], IO USING [char, int, Put, PutF, PutFR, PutRope, rope, STREAM], PrintTV USING [Print], Rope USING [ROPE, Equal], TerminalIO USING [TOS, WriteRope, WriteF], UserCredentials USING [Get], ViewerClasses USING [Viewer], ViewerOps USING [SetViewer]; CSMonitorImpl: CEDAR PROGRAM IMPORTS AMBridge, CD, CDBasics, CDCells, CDColors, CDCommandOps, CDMenus, CDOps, CDProperties, CDRects, CDSequencer, CDTipEtc, CDViewer, CStitching, IO, PrintTV, Rope, TerminalIO, UserCredentials, ViewerOps EXPORTS CSMonitor = BEGIN csMonitor: CD.Technology; solidGray: CD.Layer; solidDark: CD.Layer; space: CD.Layer; tessProp: REF ATOM _ NEW[ATOM_$Tesselation]; backgroundValue: REF _ NEW[ATOM_$nothing]; surrround: CD.Number _ 100; isgbb: BOOL ~ IF Rope.Equal[UserCredentials.Get[].name, "Beretta.pa", FALSE] OR Rope.Equal[UserCredentials.Get[].name, "Gunther.pa", FALSE] THEN TRUE ELSE 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.ROPE _ NIL, paintDark: CSMonitor.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[CSMonitor.PaintPredicate _ paintDark]]; ResetFromDesign[design]; viewer _ CDViewer.CreateViewer[design]; IF isgbb THEN BEGIN ViewerOps.SetViewer [viewer: viewer, data: NEW[INT_(csMonitor.lambda/2)], op: $Grid]; ViewerOps.SetViewer [viewer: viewer, data: NEW[INT_csMonitor.lambda], op: $Ticks] END 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: CStitching.Tile, data: REF ANY] = BEGIN 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] ], position: CDBasics.BaseOfRect[r] ].newInst; i.selected _ TRUE; CDProperties.PutInstanceProp[i, $tile, tile]; IF tile.value#NIL THEN CDProperties.PutInstanceProp[i, $SignalName, tile.value]; END; 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.DelayedRedraw[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]; 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.key 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.key FROM $SuccPrintingWidth => width _ width.SUCC; $PredPrintingWidth => IF depth > 1 THEN width _ width.PRED; ENDCASE; TerminalIO.WriteF["%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, "\nIn %g at (%g,%g).\n ", IO.rope[comm.design.name], IO.rope[CDCommandOps.LambdaRope[comm.pos.x, csMonitor.lambda]], IO.rope[CDCommandOps.LambdaRope[comm.pos.y, csMonitor.lambda]] ]; 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 [CStitching.Tile] = BEGIN plane: CStitching.Tesselation = TesselationOff[comm.design]; tile: CStitching.Tile _ CStitching.FindTile[plane, at]; RETURN [tile] END; <<>> <<--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]]; END; RedisplayComm: PROC [comm: CDSequencer.Command] = { ResetFromDesign[comm.design] }; 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: $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]; 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.ImplementCommandToCallMenu[$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["Corner Stitching Monitor loaded\n"]; END; Init[]; END. <<>> <> <> <> <<>>