<<>> <> <> <> DIRECTORY Commander, Controls, ControlsPrivate, FS, G2dBasic, G2dContour, G2dTool, Imager, IO, Rope, TIPUser, ViewerClasses, ViewerOps; G2dContourCmdsImpl: CEDAR PROGRAM IMPORTS Controls, ControlsPrivate, FS, G2dContour, G2dTool, Imager, IO, TIPUser, ViewerOps ~ BEGIN <> Control: TYPE ~ Controls.Control; IntegerPair: TYPE ~ G2dBasic.IntegerPair; IntegerPairSequence: TYPE ~ G2dBasic.IntegerPairSequence; Pair: TYPE ~ G2dBasic.Pair; Contour: TYPE ~ G2dContour.Contour; ROPE: TYPE ~ Rope.ROPE; ProgramData: TYPE ~ REF ProgramDataRec; ProgramDataRec: TYPE ~ RECORD [ outerData: Controls.OuterData ¬ NIL, -- some good stuff here alpha: Control ¬ NIL, -- contour interpolator scaler: Control ¬ NIL, -- contour scaler contour: Control ¬ NIL, -- the contour control contour0: Control ¬ NIL, -- key contour one contour1: Control ¬ NIL, -- key contour two save: IntegerPairSequence ¬ NIL, -- permit undo center: Pair ¬ [0, 0], -- of contour normals: BOOL ¬ FALSE -- show contour normals? ]; <> ContoursTest: Commander.CommandProc ~ { p: ProgramData ¬ NEW[ProgramDataRec]; p.contour ¬ Controls.NewControl[ name: "Contour and Normals", type: contour, clientData: p, w: 180, flavor: $Normals]; p.scaler ¬ Controls.NewControl["Scale", vSlider, p, 0.0, 5.0, 1.0, Scale,,,,,,, 138]; p.outerData ¬ Controls.OuterViewer[ name: "Contours Test", column: left, controls: LIST[p.contour, p.scaler], buttons: LIST[ Controls.ClickButton["Normals-Off", ToggleNormals, p, 0], Controls.ClickButton["Read", Read, p, 0], Controls.ClickButton["Write", Write, p, 0], Controls.ClickButton["Undo", Undo, p, 1], Controls.ClickButton["Center", Center, p, 1], Controls.ClickButton["Thin", Thin, p, 1], Controls.ClickButton["Smooth", Smooth, p, 1]], typescriptHeight: 18, clientData: p]; }; Scale: Controls.ControlProc ~ { p: ProgramData ¬ NARROW[control.clientData]; IF control.mouse.state = down THEN { ips: IntegerPairSequence ¬ Controls.GetContour[p.contour]; IF ips # NIL AND (p.save = NIL OR p.save.length # ips.length) THEN { p.save ¬ Controls.GetContour[p.contour]; p.center ¬ G2dContour.Centroid[G2dContour.FromIntegerPairs[p.save, TRUE]]; }; }; IF p.save # NIL THEN { c: Contour ¬ G2dContour.FromIntegerPairs[p.save, TRUE]; c ¬ G2dContour.Offset[c, [-p.center.x, -p.center.y]]; c ¬ G2dContour.Scale[c, [p.scaler.value, p.scaler.value]]; c ¬ G2dContour.Offset[c, p.center]; ToControl[p.contour, c]; }; }; Center: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; p.center ¬ [p.contour.w/2, p.contour.h/2]; ToControl[p.contour,G2dContour.Offset[G2dContour.Center[FromControl[p.contour]],p.center]]; p.save ¬ Controls.GetContour[p.contour]; }; Thin: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; p.save ¬ Controls.GetContour[p.contour]; ToControl[p.contour, G2dContour.Thin[FromControl[p.contour]]]; }; Smooth: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; p.save ¬ Controls.GetContour[p.contour]; ToControl[p.contour, G2dContour.Smooth[FromControl[p.contour]]]; }; Undo: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; Controls.SetContour[p.contour, p.save, TRUE]; p.center ¬ G2dContour.Centroid[FromControl[p.contour]]; }; ToggleNormals: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; Controls.ButtonToggle[p.outerData, p.normals ¬ NOT p.normals, "Normals-On", "Normals-Off"]; ViewerOps.PaintViewer[p.contour.viewer, client, FALSE, NIL]; }; PaintNormals: ViewerClasses.PaintProc ~ { control: Control ¬ NARROW[self.data]; p: ProgramData ¬ NARROW[control.clientData]; IF p.normals THEN { contour: Contour ¬ FromControl[p.contour]; IF contour = NIL THEN RETURN; contour.normals ¬ G2dContour.Normals[contour]; G2dContour.Paint[contour, context, TRUE]; } ELSE [] ¬ ControlsPrivate.PaintContour[self, context, whatChanged, clear]; }; Read: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; ts: Controls.Typescript ¬ p.outerData.typescript; name: ROPE ¬ Controls.TypescriptReadFileName[ts]; IF name # NIL THEN { stream: IO.STREAM ¬ FS.StreamOpen[name ! FS.Error => GOTO Bad]; ToControl[p.contour, G2dContour.Read[stream]]; EXITS Bad => Controls.TypescriptWrite[ts, IO.PutFR1["Can't open %g\n", IO.rope[name]]]; }; }; Write: Controls.ClickProc ~ { p: ProgramData ¬ NARROW[clientData]; r: ROPE ¬ Controls.TypescriptReadFileName[p.outerData.typescript]; IF r # NIL THEN G2dContour.Write[FS.StreamOpen[r, $create], FromControl[p.contour]]; }; FromControl: PROC [control: Control, t: REAL ¬ 0.0] RETURNS [contour: Contour] ~ { ips: IntegerPairSequence ¬ Controls.GetContour[control]; IF ips # NIL THEN contour ¬ G2dContour.FromIntegerPairs[ips, TRUE, t]; }; ToControl: PROC [control: Control, contour: Contour, repaint: BOOL ¬ TRUE] ~ { IF contour = NIL THEN Controls.Reset[control] ELSE Controls.SetContour[ control, G2dContour.IntegerPairsFromPairs[contour.pairs], TRUE, repaint]; }; <> ContoursInterpolate: Commander.CommandProc ~ { p: ProgramData ¬ NEW[ProgramDataRec]; p.alpha ¬ Controls.NewControl["Alpha", vSlider, p, 0.0, 1.0, 0.5, Interpolate,,,,,,, 120]; p.contour0 ¬ Controls.NewControl[type: contour, w: 160, proc: Interpolate, clientData: p]; p.contour1 ¬ Controls.NewControl[type: contour, w: 160, proc: Interpolate, clientData: p]; p.contour ¬ Controls.NewControl[type: contour, w: 160, clientData: p]; p.outerData ¬ Controls.OuterViewer[ name: "Contours Interpolate", controls: LIST[p.contour0, p.contour1, p.contour, p.alpha], clientData: p ]; }; Interpolate: Controls.ControlProc ~ { IF control.mouse.state # up THEN { p: ProgramData ¬ NARROW[control.clientData]; contour0: Contour ¬ FromControl[p.contour0]; contour1: Contour ¬ FromControl[p.contour1]; ToControl[p.contour, G2dContour.Interpolate[contour0, contour1, p.alpha.value]]; }; }; <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<];>> <<>> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <<};>> <<>> <> <> <> <> <<}>> <> <> <> <<};>> <<>> <> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <> <> <> <> <> <> < Controls3d.SetCamera[d.cam];>> < NULL;>> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <<};>> <> <<};>> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <> <> <> <> <> <<};>> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <> <> <> <> <> <<};>> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <<};>> <<};>> <> <> <<>> <> <> <> <<>> <> <> <> <<>> <> <> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<];>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<["Recurse", Recurse], ["Randomize", Randomize],>> <<["PickToggle", PickToggle], ["Reset", Reset], ["PrintC", PrintC]],>> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <> <> <> <> <<};>> <> <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <> < 0 THEN Draw3d.PP[p, q, context, d.view];>> <

> <> <<}>> <> <> <> <> <> <<};>> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<>> <> <<>> <> <> <> <> <> <> <> <<>> <> <> <<>> <> <<>> <> <> <<>> <> <> <> <<>> <> <> <> <> <> <<>> <> <<};>> <<>> <> <> <> <> <> <> <<};>> <> <> <> < 0 AND roots.r1 IN [0.0..1.0] THEN CheckI[roots.r1];>> < 1 AND roots.r2 IN [0.0..1.0] THEN CheckI[roots.r2];>> <<};>> <<>> <> <> <<};>> <<>>