File: SVArtworkUserImpl.mesa
Created December 18, 1982 1:42 am
Copyright © 1984 by Xerox Corporation. All rights reserved.
Contents: Viewer for Two dimensional artwork for mappings
Last edited by Bier on August 9, 1984 3:31:09 pm PDT
DIRECTORY
AIS,
Containers,
FS,
Graphics,
GraphicsColor,
IO,
Matrix3d,
Menus,
ReadAIS,
Real,
Rope,
SV2d,
SV3d,
SVArtwork,
SVArtworkUser,
SVCoordSys2d,
SVDraw,
SVError,
SVFiles,
SVInterfaceTypes,
SVMappings,
SVModelTypes,
SVRayTypes,
SVSceneTypes,
SVMatrix2d,
SVSelections,
SVViewerTools,
ViewerClasses,
ViewerTools,
ViewerOps;
SVArtworkUserImpl: CEDAR PROGRAM
IMPORTS AIS, FS, GraphicsColor, IO, Matrix3d, ReadAIS, Real, Rope, SVArtwork, SVCoordSys2d, SVDraw, SVError, SVFiles, SVMappings, SVMatrix2d, SVSelections, SVViewerTools, ViewerOps, ViewerTools
EXPORTS SVArtworkUser =
BEGIN
Artwork: TYPE = SVModelTypes.Artwork;
Assembly: TYPE = SVSceneTypes.Assembly;
AssemblyList: TYPE = SVSceneTypes.AssemblyList;
Box: TYPE = SVModelTypes.Box;
EditToolData: TYPE = SVInterfaceTypes.EditToolData;
Matrix4by4: TYPE = SV3d.Matrix4by4;
MouseButton: TYPE = Menus.MouseButton;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = SV3d.Point3d;
Primitive: TYPE = SVRayTypes.Primitive;
Shape: TYPE = SVSceneTypes.Shape;
Tube: TYPE = SVModelTypes.Tube;
Vector: TYPE = SV3d.Vector;
Viewer: TYPE = ViewerClasses.Viewer;
ViewerToolData: TYPE = SVInterfaceTypes.ViewerToolData;
ArtworkToolData: TYPE = SVInterfaceTypes.ArtworkToolData;
UpdateHeader: PUBLIC PROC [assemblyName: Rope.ROPE, sceneName: Rope.ROPE, artworkToolData: ArtworkToolData] = {
headerRope: Rope.ROPE;
headerStream: IO.STREAM;
headerStream ← IO.ROS[];
IF artworkToolData.artwork.source = NIL THEN { -- pure color artwork
r,g,b: REAL;
[r,g,b] ← GraphicsColor.ColorToRGB[artworkToolData.artwork.color];
headerStream.PutF["Artwork: (pure color) [%g, %g, %g]", [real[r]], [real[g]], [real[b]]];
}
ELSE {
r,g,b: REAL;
[r,g,b] ← GraphicsColor.ColorToRGB[artworkToolData.artwork.color];
headerStream.PutF["Artwork: %g %g backColor: [%g, %g, %g]", [rope[sceneName]], [rope[assemblyName]], [real[r]], [real[g]], [real[b]]];
};
headerRope ← IO.RopeFromROS[headerStream];
artworkToolData.outer.name ← headerRope;
ViewerOps.PaintViewer[artworkToolData.outer, caption, FALSE, NIL];
};
Painter: PUBLIC PROC [proc: PROC [dc: Graphics.Context], artworkToolData: ArtworkToolData] = TRUSTED {
artworkToolData.proc ← proc;
ViewerOps.PaintViewer[viewer: artworkToolData.picture,
hint: client,
whatChanged: artworkToolData,
clearClient: FALSE];
}; -- end of Painter
SVEditTool / ArtworkTool communication
SetArtwork: PUBLIC PROC [artworkTool: Viewer, artwork: Artwork, sceneName: Rope.ROPE, assemblyName: Rope.ROPE] = {
artworkToolData: ArtworkToolData ← NARROW[artworkTool.data];
artworkToolData.artwork ← artwork;
UpdateHeader[assemblyName, sceneName, artworkToolData];
DrawArtwork[NIL, artworkToolData, red, FALSE, FALSE];
};
RotateArtwork: PUBLIC PROC [artworkTool: Viewer, degrees: REAL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[artworkTool.data];
artwork: Artwork ← artworkToolData.artwork;
SVCoordSys2d.RotateCCWAwrtB[artwork.artWRTPad, artwork.artWRTPad, degrees];
DrawArtwork[NIL, artworkToolData, red, FALSE, FALSE];
};
NormalizeArtwork: PUBLIC PROC [artworkTool: Viewer] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[artworkTool.data];
artwork: Artwork ← artworkToolData.artwork;
SVCoordSys2d.PlaceAwrtB[artwork.artWRTPad, NIL, SVMatrix2d.Identity[]];
};
Button procs
ScalarSetPrompt: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
scalar: REAL ← SVViewerTools.GetReal[artworkToolData.textSection.scalar, 1];
artworkToolData.scalar ← scalar;
DrawArtwork[NIL, artworkToolData, red, FALSE, FALSE];
};
ScalarPrompt: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
ViewerTools.SetSelection[artworkToolData.textSection.scalar];
};
Tentfilter: PROC [x,y: REAL] RETURNS [val: REAL] = TRUSTED {
RETURN [1.0-ABS[x]];
};
DrawArtwork: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
artwork: Artwork ← artworkToolData.artwork;
scalar: REAL ← artworkToolData.scalar;
DoDrawArtwork: PROC [dc: Graphics.Context] = TRUSTED {
SVArtwork.DrawArtwork[dc, artwork, artworkToolData.origin, scalar];
};
Painter[DoDrawArtwork, artworkToolData];
CrossHairs[parent, clientData, mouseButton, shift, control];
};
PlaceOrigin: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control: BOOL] = TRUSTED {
parent is the picture
find the center of the picture in picture coordinates
picture: Viewer ← NARROW[parent];
originX, originY: INTEGER;
artworkToolData: ArtworkToolData ← NARROW[clientData];
originX ← picture.cw;-- convert window width to real
originY ← picture.ch;-- convert window height to real
originX ← originX/2;-- find the midpoint in window coords
originY ← originY/2;
artworkToolData.origin ← [originX, originY];
};
CrossHairs: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
DoCrossHairs: PROC [dc: Graphics.Context] = TRUSTED {
SVDraw.CrossHairs[dc, artworkToolData.origin];
};
artworkToolData: ArtworkToolData ← NARROW[clientData];
Painter[DoCrossHairs, artworkToolData];
};
Position: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
Get the current skitter position. Make sure that the skitter assembly is the same as the current artwork assembly. Inverse map the skitter surface point. Use this as the center of the AIS file.
artworkToolData: ArtworkToolData ← NARROW[clientData];
artwork: Artwork ← artworkToolData.artwork;
assembly: Assembly;
viewerToolData: ViewerToolData;
skitterWORLD, moWORLD, skitterMO: Matrix4by4;
imagePoint: Point2d;
origin: Point3d;
normal: Vector;
[assembly, ----, viewerToolData] ← SVSelections.GetSkitterData[];
[----, skitterWORLD] ← SVSelections.GetPositionSkitter[];
WITH assembly.shape SELECT FROM
shape: Shape => moWORLD ← shape.coordSys.wrtWorld;
alist: AssemblyList => {
SVError.Append["Can't position with skitter on a Composite assembly", TRUE, TRUE];
SVError.Blink[];
RETURN;
};
ENDCASE => ERROR;
skitterMO ← Matrix3d.WorldToLocal[moWORLD, skitterWORLD];
origin ← Matrix3d.OriginOfMatrix[skitterMO];
normal ← Matrix3d.ZAxisOfMatrix[skitterMO];
imagePoint ← GetImagePointFromSurfacePoint[artwork, origin, normal];
SVCoordSys2d.PlaceTranslationAwrtB[artwork.artWRTPad, NIL, imagePoint];
DrawArtwork[NIL, artworkToolData, red, FALSE, FALSE];
};
GetImagePointFromSurfacePoint: PUBLIC PROC [artwork: Artwork, surfacePt: Point3d, normal: Vector] RETURNS [imagePoint: Point2d] = TRUSTED {
surfacePt should be in assembly coordinates.
onSurf: BOOL;
WITH artwork.surface SELECT FROM
tube: Tube => {
tubePoint: Point2d;
tubePoint ← SVMappings.Point3dToTubePoint[surfacePt];
[imagePoint, onSurf] ← SVMappings.TubeToImage[tubePoint, tube];
IF NOT onSurf THEN {
SVError.Append["Point not on tube mapping surface.", TRUE, TRUE];
SVError.Blink[];
RETURN;
};
};
box: Box => {
boxPoint: Point2d;
SELECT artwork.oMap FROM
radial => [boxPoint, onSurf] ← SVMappings.BoxRadialOInverse[surfacePt, normal, box];
orthogonal => [boxPoint, onSurf] ← SVMappings.BoxOrthogonalOInverse[surfacePt, normal, box];
ENDCASE => ERROR;
IF NOT onSurf THEN {
SVError.Append["Point not on box mapping surface.", TRUE, TRUE];
SVError.Blink[];
RETURN;
};
[imagePoint, onSurf] ← SVMappings.BoxToImage[boxPoint, box];
IF NOT onSurf THEN {
SVError.Append["Point not on box mapping surface.", TRUE, TRUE];
SVError.Blink[];
RETURN;
};
};
ENDCASE => ERROR SVError.NotYetImplemented;
};
SetColor: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
success: BOOL;
[artworkToolData.paintColor, success] ← SVViewerTools.GetColor[artworkToolData.textSection.color];
IF NOT success THEN {
SVError.Append["Color not understood. Using red.", TRUE, TRUE];
SVError.Blink[];
artworkToolData.paintColor ← GraphicsColor.RGBToColor[0.9,0.5,0.5];
RETURN;
};
};
OpenFileButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
OpenFile[artworkToolData];
};
OpenFile: PUBLIC PROC [artworkToolData: ArtworkToolData] = TRUSTED {
artwork: Artwork ← artworkToolData.artwork;
editToolData: EditToolData ← artworkToolData.editToolData;
fileName: Rope.ROPE ← ViewerTools.GetSelectionContents[];
fullName, wdir: Rope.ROPE;
success: BOOL;
numberOfSamplesX, numberOfSamplesY: NAT;
raster: AIS.Raster;
redRope: Rope.ROPE;
greenRope: Rope.ROPE;
blueRope: Rope.ROPE;
bwRope: Rope.ROPE;
realRed, realGreen, realBlue, realBlack: REAL;
redValue, greenValue, blueValue, blackValue: NAT;
wdir ← editToolData.originalWorkingDirectory;
success ← TRUE;
[fullName,,] ← FS.ExpandName[fileName, wdir
! FS.Error => IF error.group = user THEN {
success ← FALSE;
SVError.Append[error.explanation];
SVError.Blink[];
CONTINUE;
}
];
IF NOT success THEN RETURN;
artwork.source ← fullName;
artwork.open ← TRUE;
numberOfSamplesX ← numberOfSamplesY ← 300;
raster ← NEW[AIS.RasterPart ← [numberOfSamplesY, numberOfSamplesX, rd, 8, -1, 65535]];
redRope ← Rope.Concat[SVFiles.FilenameMinusExtension[fullName], "-red.ais"];
greenRope ← Rope.Concat[SVFiles.FilenameMinusExtension[fullName], "-grn.ais"];
blueRope ← Rope.Concat[SVFiles.FilenameMinusExtension[fullName], "-blu.ais"];
bwRope ← fullName;
artwork.isColorFile ← TRUE;
artwork.redfile ← ReadAIS.CreateFile[redRope, raster, NIL, TRUE, 0, 72];
artwork.redWindow ← AIS.OpenWindow[artwork.redfile];
artwork.greenfile ← ReadAIS.CreateFile[greenRope, raster, NIL, TRUE, 0, 72];
artwork.greenWindow ← AIS.OpenWindow[artwork.greenfile];
artwork.bluefile ← ReadAIS.CreateFile[blueRope, raster, NIL, TRUE, 0, 72];
artwork.blueWindow ← AIS.OpenWindow[artwork.bluefile];
artwork.blackfile ← ReadAIS.CreateFile[bwRope, raster, NIL, TRUE, 0, 72];
artwork.blackWindow ← AIS.OpenWindow[artwork.blackfile];
FOR i: NAT IN [0..numberOfSamplesX) DO
FOR j: NAT IN [0..numberOfSamplesY) DO
[realRed, realGreen, realBlue] ← GraphicsColor.ColorToRGB[artwork.color];
realBlack ← GraphicsColor.ColorToIntensity[artwork.color];
redValue ← Real.Fix[realRed*255.0];
greenValue ← Real.Fix[realGreen*255.0];
blueValue ← Real.Fix[realBlue*255.0];
blackValue ← Real.Fix[realBlack*255.0];
AIS.WriteSample[artwork.redWindow, redValue, i, j];
AIS.WriteSample[artwork.greenWindow, greenValue, i, j];
AIS.WriteSample[artwork.blueWindow, blueValue, i, j];
AIS.WriteSample[artwork.blackWindow, blackValue, i, j];
ENDLOOP;
ENDLOOP;
SVError.Append[" New color "];
SVError.Append[bwRope];
SVError.Append["'s created.", FALSE, TRUE];
};
CloseFileButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
artworkToolData: ArtworkToolData ← NARROW[clientData];
CloseFile[artworkToolData];
};
CloseFile: PUBLIC PROC [artworkToolData: ArtworkToolData] = TRUSTED {
SVArtwork.CloseArtwork[artworkToolData.artwork];
};
END.