-- COGVorTestImpl.mesa: basic setup for Voronoi testing programs
-- last modified by Stolfi - October 16, 1982 6:42 pm
-- To do: draw vertex and region numbers
-- To do: merge with COGVoronoiImpl?
-- To do: paint region, not point, in DVertexPainter when in dual mode
-- To run: run COGAll; run COGVoronoiImpl; run COGVorTestImpl

DIRECTORY
Rope USING [ROPE],
IO USING [PutF, GetChar],
Process USING [Milliseconds, MsecToTicks, Pause],
COGDebug USING [in, out],
COGVoronoi USING
[MakeVertexObject, MakeEdgeObject, MakeRegionObject, VertexRec],
COGDiagram USING
[DEdge],
COGDrawing USING
[Drawing, Object, MakeDrawing, Add, RemoveLayers, Color, Size, black,
AddPropertyButton, AddMenuAction, MenuProc, PutProp, PaintOrder, RepaintAll],
COGVorTest;
COGVorTestImpl: CEDAR PROGRAM
IMPORTS
IO, Process, COGDrawing, COGDebug,
COGVoronoi
EXPORTS
COGVorTest =
BEGIN
OPEN
Rope, IO,
Draw: COGDrawing,
Vor: COGVoronoi, Bug: COGDebug, Diag: COGDiagram, COGVorTest;
theDrawing: PUBLIC Draw.Drawing ← NIL;
ShowDelay: PUBLIC Process.Milliseconds ← 0;
ShowRegion: PUBLIC PROC
[e: Diag.DEdge, color: Draw.Color ← Draw.black, side: Draw.Size ← 0] = TRUSTED
{Draw.Add [dr: theDrawing, obj: Vor.MakeRegionObject[e, color, side], order: 2];
Process.Pause[Process.MsecToTicks[ShowDelay]]};
ShowEdge: PUBLIC PROC
[e: Diag.DEdge, color: Draw.Color ← Draw.black, width: Draw.Size ← 0] = TRUSTED
{Draw.Add [dr: theDrawing, obj: Vor.MakeEdgeObject[e, color, width], order: 4];
Process.Pause[Process.MsecToTicks[ShowDelay]]};
ShowVertex: PUBLIC PROC
[v: REF Vor.VertexRec, color: Draw.Color ← Draw.black, side: Draw.Size ← 0] = TRUSTED
{Draw.Add [dr: theDrawing, obj: Vor.MakeVertexObject[v, color, side], order: 5];
Process.Pause[Process.MsecToTicks[ShowDelay]]};
CleanTheDrawing: PUBLIC PROC [repaint: BOOLFALSE]=
BEGIN
Draw.RemoveLayers
[dr: theDrawing, minOrder: FIRST[Draw.PaintOrder], maxOrder: 2];
Draw.RemoveLayers
[dr: theDrawing, minOrder: 4, maxOrder: LAST[Draw.PaintOrder]];
IF repaint THEN Draw.RepaintAll [theDrawing]
END;
SlowMode: Draw.MenuProc =
BEGIN
SELECT button FROM
red => {ShowDelay ← (IF ShowDelay = 0 THEN 500 ELSE 2*ShowDelay)};
yellow => {ShowDelay ← 0};
blue => {ShowDelay ← (IF ShowDelay <= 500 THEN 0 ELSE ShowDelay/2)}
ENDCASE => {}
END;
MenuCleanDrawing: Draw.MenuProc =
BEGIN

-- parameters: [parent: REF ANY, clientData: REF ANY, mouseButton]
-- Called by the system when the "Clean" menu entry is activated.

CleanTheDrawing[repaint: TRUE] -- Kludge: assumes the parent is theDrawing
END;

Bug.out.PutF["\nVorTestImpl: Hello! Say something: "];
[] ← Bug.in.GetChar[];
theDrawing ← Draw.MakeDrawing ["VORONOI DIAGRAM", drBox];
Draw.AddPropertyButton [theDrawing, $ENum];
Draw.AddPropertyButton [theDrawing, $VNum];
Draw.AddPropertyButton [theDrawing, $Voronoi];
Draw.AddMenuAction
[dr: theDrawing, name: "Slow", Proc: SlowMode, needs: none, line: 0];
Draw.AddMenuAction
[dr: theDrawing, name: "Clean", Proc: MenuCleanDrawing, needs: write, line: 0];
Draw.PutProp [theDrawing, $ENum, $TRUE];
Bug.out.PutF["\nVorTestImpl: Enjoy yourself. Bye!"]
END.