<> <> <> DIRECTORY CD USING [Rect], Commander USING [CommandProc, Register], IO USING [BreakProc, CharClass, EndOf, EndOfStream, Error, GetChar, GetInt, GetLineRope, GetTokenRope, int, Put, PutF, PutFR, Reset, RIS, rope, STREAM], Process USING [Detach], Rope USING [Cat, Length, ROPE, SkipOver, Substr], RopeList USING [Compare, Cons, Sort], SXQuadTree USING [Store, QuadTreeRoot, Rectangle], ViewerIO USING [CreateViewerStreams], ViewerTools USING [FindExistingViewer, InhibitUserEdits, Viewer]; SXTest: CEDAR MONITOR IMPORTS Commander, IO, Process, Rope, RopeList, SXQuadTree, ViewerIO, ViewerTools = BEGIN ROPE: TYPE = Rope.ROPE; windowCount: INT _ 0; -- a count of the number of test windows created. counter: INT _ 0; -- general purpose; quadTree: SXQuadTree.QuadTreeRoot; MakeTestWindow: ENTRY Commander.CommandProc = BEGIN <> title: ROPE; windowCount _ windowCount+1; title _ IO.PutFR ["Spinifex maintenance test window # %g", IO.int[windowCount]]; TRUSTED {Process.Detach[FORK Test [title]];} END; MakeQTTestWindow: ENTRY Commander.CommandProc = BEGIN <> title: ROPE; windowCount _ windowCount+1; title _ IO.PutFR ["Spinifex Quad Tree test window # %g", IO.int[windowCount]]; TRUSTED {Process.Detach[FORK QTTest [title]];} END; MakeCoreTestWindow: ENTRY Commander.CommandProc = BEGIN <> title: ROPE; windowCount _ windowCount+1; title _ IO.PutFR ["SX Core test %g", IO.int[windowCount]]; TRUSTED {Process.Detach[FORK CoreTest [title]];} END; Test: PROC[title: ROPE] = BEGIN <> parList: ROPE; parameters, sortedPar: LIST OF ROPE; in, out: IO.STREAM; nothingToDo: BOOL; [in: in, out: out] _ ViewerIO.CreateViewerStreams[title]; DO -- Read a parameter list, terminated by a CR: ENABLE IO.Error => IF ec = SyntaxError THEN { IO.Reset [in]; out.PutF ["\nIncorrect input. Please retype.\n\n"]; LOOP} ELSE EXIT; IO.PutF [stream: out, format: "%lType a parameter list and terminate with CR to sort it:\n%l", v1: IO.rope["e"], v2: IO.rope["E"]]; parList _ IO.GetLineRope[in]; [parameters, nothingToDo] _ PiecifyParameters [parList]; IF nothingToDo THEN {out.Put [IO.rope["Par list empty\n"]]; LOOP}; sortedPar _ SortParameters [parameters]; parList _ RebuildParList [sortedPar]; IO.PutF [stream: out, format: "%l\nThe sorted parameter list is:%l\n%g\n\n", v1: IO.rope["b"], v2: IO.rope["B"], v3: IO.rope[parList]]; ENDLOOP; END; -- Test CoreTest: PROC[title: ROPE] = BEGIN <> in, out: IO.STREAM; viewer: ViewerTools.Viewer; [in: in, out: out] _ ViewerIO.CreateViewerStreams [title]; viewer _ ViewerTools.FindExistingViewer [title]; ViewerTools.InhibitUserEdits [viewer] END; -- CoreTest QTTest: PROC[title: ROPE] = BEGIN <> nr: REF INT; r: CD.Rect; rect: REF SXQuadTree.Rectangle; in, out: IO.STREAM; [in: in, out: out] _ ViewerIO.CreateViewerStreams [title]; DO -- Read a parameter list, terminated by a CR: ENABLE IO.Error => IF ec = SyntaxError THEN { IO.Reset [in]; out.PutF ["\nIncorrect input. Please retype.\n\n"]; LOOP} ELSE EXIT; IO.PutF [stream: out, format: "%lType lower left and upper right coordinates and terminate with CR to insert the rectangle:\n%l", v1: IO.rope["e"], v2: IO.rope["E"]]; r.x1 _ IO.GetInt [in]; r.y1 _ IO.GetInt [in]; r.x2 _ IO.GetInt [in]; r.y2 _ IO.GetInt [in]; counter _ SUCC [counter]; nr _ NEW [INT]; nr^ _ counter; rect _ NEW [SXQuadTree.Rectangle]; rect.interestBound _ r; rect.dimDecr _ [0, 0, 0, 0]; rect.nodeInformation _ nr; quadTree _ SXQuadTree.Store [quadTree, rect]; IO.PutF [stream: out, format: "\nRectangle %g inserted in quadtree, size: %g, %g; %g, %g.\n\n", v1: IO.int [counter], v2: IO.int [quadTree.size.x1], v3: IO.int [quadTree.size.y1], v4: IO.int [quadTree.size.x2], v5: IO.int [quadTree.size.y2]]; ENDLOOP; END; -- QTTest PiecifyParameters: PROCEDURE [r: ROPE] RETURNS [rList: LIST OF ROPE, empty: BOOL] = <> BEGIN ParProc: IO.BreakProc = {RETURN [IF char = ', THEN sepr ELSE other]}; buffer: IO.STREAM ~ IO.RIS [rope: r]; -- reconvert rope into stream rope: ROPE; length, nonSpace: INT; -- Skip leading parenthesis IF IO.GetChar [buffer] # '{ THEN ERROR; empty _ IO.EndOf [buffer]; DO -- rip off subrope until next comma and add to list of ropes BEGIN rope _ IO.GetTokenRope[stream: buffer, breakProc: ParProc ! IO.EndOfStream => GOTO eos].token; nonSpace _ Rope.SkipOver [s: rope, pos: 0, skip: " "]; length _ Rope.Length [base: rope]; IF (nonSpace < length) AND (nonSpace > 0) THEN rope _ Rope.Substr[base: rope, start: nonSpace, len: length-nonSpace]; rList _ RopeList.Cons [list: rList, r: rope]; EXITS eos => RETURN [rList, empty] END ENDLOOP; END; -- PiecifyParameters SortParameters: PROCEDURE [unsorted: LIST OF ROPE] RETURNS [sorted: LIST OF ROPE] = <> BEGIN sorted _ RopeList.Sort[list: unsorted, compareProc: RopeList.Compare] END; -- SortParameters RebuildParList: PROCEDURE [list: LIST OF ROPE] RETURNS [rope: ROPE] = <> BEGIN rope _ "{"; rope _ Rope.Cat [r1: "{", r2: list.first]; FOR l: LIST OF ROPE _ list.rest, l.rest WHILE l # NIL DO rope _ Rope.Cat [r1: rope, r2: ", ", r3: l.first] ENDLOOP; END; -- RebuildParList Commander.Register [key: "Test", proc: MakeTestWindow, doc: "A simple Spinifex test program"]; Commander.Register [key: "QTTest", proc: MakeQTTestWindow, doc: "Spinifex quad tree test program"]; Commander.Register [key: "CoreTest", proc: MakeCoreTestWindow, doc: "Prints the contents of the current core sesign created by Spinifex"]; END.