File: SVViewerToolsImpl.mesa
Created December 18, 1982 1:40 am
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Eric Bier on August 1, 1985 5:50:19 pm PDT
Contents: Basic functions for retrieving values from and writing values to text viewers.
DIRECTORY
Imager,
ImagerColor,
ImagerColorPrivate,
IO,
Rope,
SVViewerTools,
TFI3d,
SVError,
ViewerClasses,
ViewerTools;
SVViewerToolsImpl:
PROGRAM
IMPORTS ImagerColor, ImagerColorPrivate, IO, Rope, SVError, TFI3d, ViewerTools
EXPORTS SVViewerTools =
BEGIN
Color: TYPE = Imager.Color;
Viewer: TYPE = ViewerClasses.Viewer;
GetReal:
PUBLIC
PROC [textViewer: Viewer, default:
REAL]
RETURNS [r:
REAL] = {
rRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
IF Rope.Size[rRope] = 0
THEN r ← default
ELSE {
IF Rope.Find[rRope, ".", 0, FALSE] = -1 THEN rRope ← Rope.Concat[rRope, ".0"];
r ← IO.GetReal[IO.RIS[rRope]];
};
};
GetBool:
PUBLIC
PROC [textViewer: Viewer]
RETURNS [b:
BOOL] = {
bRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
b ← IF Rope.Equal[bRope, "TRUE"] THEN TRUE ELSE FALSE;
};
GetColor:
PUBLIC
PROC [textViewer: Viewer]
RETURNS [color: Color, success:
BOOL] = {
r, g, b: REAL;
success ← TRUE;
[r, g, b] ← GetThreeReals[textViewer];
IF r > 1 OR r < 0 THEN {SVError.Append["r value must be between 0 and 1", TRUE, TRUE]; SVError.Blink[]; success ← FALSE};
IF g > 1 OR g < 0 THEN {SVError.Append["g value must be between 0 and 1", TRUE, TRUE]; SVError.Blink[]; success ← FALSE};
IF b > 1 OR b < 0 THEN {SVError.Append["b value must be between 0 and 1", TRUE, TRUE]; SVError.Blink[]; success ← FALSE};
IF success THEN color ← ImagerColor.ColorFromRGB [[r, g, b]];
};
GetThreeReals:
PUBLIC
PROC [textViewer: Viewer]
RETURNS [x, y, z:
REAL] = {
wholeRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
wholeStream: IO.STREAM ← IO.RIS[wholeRope];
threeNumsThere: BOOL ← TRUE;
TFI3d.ReadBlank[wholeStream];
x ← TFI3d.ReadReal[wholeStream];
TFI3d.ReadBlankAndRope[wholeStream, ","
!TFI3d.RopeNotOnTop => {threeNumsThere ← FALSE; CONTINUE}];
IF NOT threeNumsThere THEN y ← x
ELSE {
TFI3d.ReadBlank[wholeStream]; y ← TFI3d.ReadReal[wholeStream]};
TFI3d.ReadBlankAndRope[wholeStream, ","
!TFI3d.RopeNotOnTop => {threeNumsThere ← FALSE; CONTINUE}];
IF NOT threeNumsThere THEN z ← y
ELSE {
TFI3d.ReadBlank[wholeStream]; z ← TFI3d.ReadReal[wholeStream]};
};
GetNat:
PUBLIC
PROC [textViewer: Viewer]
RETURNS [n:
NAT] = {
nRope: Rope.ROPE ← ViewerTools.GetContents[textViewer];
IF Rope.Size[nRope] = 0
THEN n ← 0
ELSE {
n ← IO.GetInt[IO.RIS[nRope]];
};
};
SetReal:
PUBLIC
PROC [viewer: Viewer, real:
REAL] = {
s: IO.STREAM;
realRope: Rope.ROPE;
s ← IO.ROS[];
s.PutF["%g", [real[real]]];
realRope ← IO.RopeFromROS[s];
ViewerTools.SetContents[viewer, realRope];
};
SetBool:
PUBLIC
PROC [viewer: Viewer, bool:
BOOL] = {
s: IO.STREAM;
boolRope: Rope.ROPE;
s ← IO.ROS[];
s.PutF["%g", [boolean[bool]]];
boolRope ← IO.RopeFromROS[s];
ViewerTools.SetContents[viewer, boolRope];
};
SetColor:
PUBLIC
PROC [viewer: Viewer, color: Color] = {
r,g,b: REAL;
r ← ImagerColorPrivate.ComponentFromColor[NARROW[color], $Red];
g ← ImagerColorPrivate.ComponentFromColor[NARROW[color], $Green];
b ← ImagerColorPrivate.ComponentFromColor[NARROW[color], $Blue];
SetThreeReals[viewer, r, g, b];
};
SetThreeReals:
PUBLIC
PROC [viewer: Viewer, a, b, c:
REAL] = {
s: IO.STREAM;
realsRope: Rope.ROPE;
s ← IO.ROS[];
s.PutF["%g, %g, %g", [real[a]], [real[b]], [real[c]]];
realsRope ← IO.RopeFromROS[s];
ViewerTools.SetContents[viewer, realsRope];
};
END.