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 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[]]; }; 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 { 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 { 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 { 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. dFile: SVArtworkUserImpl.mesa Created December 18, 1982 1:42 am Copyright c 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 SVEditTool / ArtworkTool communication Button procs parent is the picture find the center of the picture in picture coordinates 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. surfacePt should be in assembly coordinates. Κ o˜Ihead1šœ™Jšœ!™!Jšœ Οmœ1™žœ˜gJšœ˜Jšœ6˜6Jšœ ˜ Jšœ˜Jšœ žœ˜JšœŸ˜—J˜Jšœ&™&J˜š   œžœžœ9žœžœ˜rJšœ#žœ˜