<> <> <> <> DIRECTORY AIS, Buttons, CastRays, CGDevice, ColorMap, Containers, CoordSys, CSG, CSGGraphics, DisplayList3d, DitherAIS, Draw3d, FileIO, Graphics, GraphicsBasic, GraphicsColor, GraphicsToPress, IO, Labels, Map, Matrix3d, Menus, MessageWindow, Preprocess3d, Real, Rope, SV2d, SVBoundBox, SVEditUser, SVFiles, SVImage, SVTransforms, SVVector3d, SVViewerTool, SVViewerTools, SVViewerUser, System, TFO3d, Time, ViewerClasses, ViewerTools; SVViewerUserImplB: CEDAR PROGRAM IMPORTS AIS, Buttons, CastRays, ColorMap, CoordSys, CSGGraphics, DisplayList3d, DitherAIS, Draw3d, FileIO, Graphics, GraphicsToPress, IO, Labels, Map, Matrix3d, MessageWindow, Preprocess3d, Real, Rope, SVBoundBox, SVEditUser, SVFiles, SVImage, SVTransforms, SVViewerUser, SVViewerTools, TFO3d, Time, ViewerTools EXPORTS GraphicsBasic, SVViewerUser = BEGIN Assembly: TYPE = DisplayList3d.Assembly; BoundBox: TYPE = SVBoundBox.BoundBox; Camera: TYPE = CSGGraphics.Camera; Color: TYPE = GraphicsColor.Color; CoordSysGenerator: TYPE = DisplayList3d.CoordSysGenerator; CSGTree: TYPE = DisplayList3d.CSGTree; DeviceObject: PUBLIC TYPE = CGDevice.Rep; DrawStyle: TYPE = CSGGraphics.DrawStyle; EditToolData: TYPE = SVEditUser.EditToolData; FrameBox: TYPE = CSGGraphics.FrameBox; MasterObject: TYPE = DisplayList3d.MasterObject; Matrix4by4: TYPE = Matrix3d.Matrix4by4; MouseButton: TYPE = Menus.MouseButton; Point2d: TYPE = SV2d.Point2d; Primitive: TYPE = CSG.Primitive; Scene: TYPE = DisplayList3d.Scene; Selection: TYPE = SVEditUser.Selection; Vector: TYPE = SVVector3d.Vector; Viewer: TYPE = ViewerClasses.Viewer; ViewerToolData: TYPE = REF ViewerToolDataObj; ViewerToolDataObj: TYPE = SVViewerTool.ViewerToolDataObj; ViewerTextData: TYPE = SVViewerTool.ViewerTextData; ViewerPictureData: TYPE = REF ViewerPictureDataObj; ViewerPictureDataObj: TYPE = SVViewerUser.ViewerPictureDataObj; InteractionMode: TYPE = SVViewerUser.InteractionMode;-- {select, cast}; DCProc: TYPE = SVViewerUser.DCProc; <> globalTable: Map.ColorTable; globalSceneStyleCount: NAT = 3; globalSceneStyleArray: ARRAY[1..globalSceneStyleCount] OF Rope.ROPE _ ["WireFrame", "Shaded", "Normals"]; globalBandsDeviceCount: NAT = 3; globalBandsDeviceArray: ARRAY[1..globalBandsDeviceCount] OF Rope.ROPE _ ["Hornet", "Screen", "Platemaker"]; Press: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; camera: Camera _ viewerPictureData.camera; <> startTime: System.GreenwichMeanTime; endTime: System.GreenwichMeanTime; totalTime: LONG CARDINAL; timeStream: IO.STREAM; outStream: IO.STREAM _ SVEditUser.GetOutHandle[]; timeRope: Rope.ROPE; <> pressName: Rope.ROPE; pressStream: IO.STREAM; pressContext: Graphics.Context; <> startTime _ Time.Current[]; <> pressName _ ViewerTools.GetContents[viewerToolData.textSection.ais]; pressName _ Rope.Concat[SVFiles.FilenameMinusExtension[pressName], ".press"]; pressStream _ FileIO.Open[pressName, overwrite, none]; pressContext _ GraphicsToPress.NewContextFromStream[ outputStream: pressStream, fileNameForHeaderPage: pressName, resolution: 384]; CSGGraphics.SetQualityCamera[camera, quality];-- make a high quality image CSGGraphics.ColorFilmCamera[camera, FALSE];-- but only black and white SVViewerUser.DrawSceneEtc[pressContext, viewerToolData]; CSGGraphics.ColorFilmCamera[camera, TRUE];-- restore to color mode CSGGraphics.SetQualityCamera[camera, fast];-- restore to fast mode for interactive editting GraphicsToPress.Close[pressContext]; endTime _ Time.Current[]; totalTime _ endTime - startTime; timeStream _ IO.CreateOutputStreamToRope[]; timeStream.PutF[" Done. Pressing took (%r)",[cardinal[totalTime]]]; outStream.PutF[" Done. Pressing took (%r)",[cardinal[totalTime]]]; timeRope _ timeStream.GetOutputStreamRope[]; MessageWindow.Append[timeRope, TRUE]; }; PressAIS: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; scene: Scene _ viewerPictureData.scene; camera: Camera _ viewerPictureData.camera; minX, minY, maxX, maxY: REAL; tree: CSGTree; aisRope: Rope.ROPE _ ViewerTools.GetContents[viewerToolData.textSection.ais]; <> startTime: System.GreenwichMeanTime; endTime: System.GreenwichMeanTime; totalTime: LONG CARDINAL; timeStream: IO.STREAM; timeRope: Rope.ROPE; <> pressName: Rope.ROPE; pressStream: IO.STREAM; outStream: IO.STREAM _ SVEditUser.GetOutHandle[]; pressContext: Graphics.Context; <> startTime _ Time.Current[]; <> pressName _ ViewerTools.GetContents[viewerToolData.textSection.ais]; pressName _ Rope.Concat[SVFiles.FilenameMinusExtension[pressName], ".press"]; pressStream _ FileIO.Open[pressName, overwrite, none]; pressContext _ GraphicsToPress.NewContextFromStream[ outputStream: pressStream, fileNameForHeaderPage: pressName, resolution: 384]; tree _ DisplayList3d.SceneToTree[scene, camera]; [minX, minY, maxX, maxY] _ MinAndMaxFromCameraAndTree[camera, tree]; SVImage.DrawAndScaleColorImage[pressContext, aisRope, [camera.screenCS.mat[1][4], camera.screenCS.mat[2][4]], minX, minY, maxX, maxY]; GraphicsToPress.Close[pressContext]; endTime _ Time.Current[]; totalTime _ endTime - startTime; timeStream _ IO.CreateOutputStreamToRope[]; timeStream.PutF[" Done. Pressing AIS took (%r)",[cardinal[totalTime]]]; outStream.PutF[" Done. Pressing AIS took (%r)",[cardinal[totalTime]]]; timeRope _ timeStream.GetOutputStreamRope[]; MessageWindow.Append[timeRope, TRUE]; }; PressBWAIS: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; editToolData: EditToolData _ NARROW[viewerToolData.editToolData]; scene: Scene _ viewerPictureData.scene; camera: Camera _ viewerPictureData.camera; minX, minY, maxX, maxY: REAL; tree: CSGTree; aisRope: Rope.ROPE _ ViewerTools.GetContents[viewerToolData.textSection.ais]; <> startTime: System.GreenwichMeanTime; endTime: System.GreenwichMeanTime; totalTime: LONG CARDINAL; timeStream: IO.STREAM; timeRope: Rope.ROPE; <> pressName: Rope.ROPE; pressStream: IO.STREAM; outStream: IO.STREAM _ SVEditUser.GetOutHandle[]; pressContext: Graphics.Context; <> startTime _ Time.Current[]; <> pressName _ ViewerTools.GetContents[viewerToolData.textSection.ais]; pressName _ Rope.Concat[SVFiles.FilenameMinusExtension[pressName], ".press"]; pressStream _ FileIO.Open[pressName, overwrite, none]; pressContext _ GraphicsToPress.NewContextFromStream[ outputStream: pressStream, fileNameForHeaderPage: pressName, resolution: 384]; tree _ DisplayList3d.SceneToTree[scene, camera]; [minX, minY, maxX, maxY] _ MinAndMaxFromCameraAndTree[camera, tree]; SVImage.DrawAndScaleBlackAndWhiteImage[pressContext, aisRope, [camera.screenCS.mat[1][4], camera.screenCS.mat[2][4]], minX, minY, maxX, maxY]; GraphicsToPress.Close[pressContext]; endTime _ Time.Current[]; totalTime _ endTime - startTime; timeStream _ IO.CreateOutputStreamToRope[]; timeStream.PutF[" Done. Pressing AIS took (%r)",[cardinal[totalTime]]]; outStream.PutF[" Done. Pressing AIS took (%r)",[cardinal[totalTime]]]; timeRope _ timeStream.GetOutputStreamRope[]; MessageWindow.Append[timeRope, TRUE]; }; CrossHairs: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { <> viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; camera: Camera _ viewerPictureData.camera; DoCrossHairs: PROC [dc: Graphics.Context] = TRUSTED { Draw3d.Draw2dCoordSys[dc, [0,0], camera]; }; SVViewerUser.Painter[DoCrossHairs, viewerToolData]; }; -- end of CrossHairs Dither: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; baseName, redName, greenName, blueName, FSFilename: Rope.ROPE; baseName _ ViewerTools.GetContents[viewerToolData.textSection.ais]; baseName _ SVFiles.FilenameMinusExtension[baseName]; redName _ Rope.Concat[baseName, "-red.ais"]; greenName _ Rope.Concat[baseName, "-green.ais"]; blueName _ Rope.Concat[baseName, "-blue.ais"]; FSFilename _ Rope.Concat[baseName, "-std.ais"]; BEGIN globalTable _ Preprocess3d.GetGlobalTable[]; DitherAIS.Squash[redName, greenName, blueName, FSFilename, MyMap ! AIS.Error => { outStream: IO.STREAM _ SVEditUser.GetOutHandle[]; outStream.PutF["%g -*.ais - Bad file names", [rope[baseName]]]; MessageWindow.Append[Rope.Concat[baseName, "-*.ais - Bad file names"], TRUE]; GOTO giveUp}]; <> DrawDither[parent, clientData, mouseButton, shift, control]; EXITS giveUp => NULL; END; }; MyMap: DitherAIS.UserMapProc = TRUSTED { rb, gb, bb: Map.ColorMapSize; palix _ Map.GetIndex[r, g, b, globalTable]; [rb, gb, bb] _ ColorMap.GetColor[palix]; -- ought to use the table re _ r - rb; ge _ g - gb; be _ b - bb; }; Extend: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { <> SVEditUser.ExtendSecondary[]; }; Move: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { newMat: Matrix4by4; primary, secondary: Selection; primary _ SVEditUser.GetPrimarySelection[]; secondary _ SVEditUser.GetSecondarySelection[]; IF primary = NIL THEN RETURN[]; IF primary.assembly = NIL THEN RETURN; IF secondary = NIL THEN RETURN[]; IF secondary.assembly = NIL THEN RETURN; <> IF primary.viewerToolData # secondary.viewerToolData THEN { primaryPicture: ViewerPictureData _ NARROW[primary.viewerToolData.viewerPicture.data]; secondaryPicture: ViewerPictureData _ NARROW[secondary.viewerToolData.viewerPicture.data]; IF primaryPicture.scene # secondaryPicture.scene THEN { copyAssembly: Assembly _ DisplayList3d.MergeAssemblyIntoScene[secondary.assembly, secondaryPicture.scene, primaryPicture.scene.assembly, primaryPicture.scene]; <> SVViewerUser.SceneNewVersion[primary.viewerToolData]; SVViewerUser.DrawSceneInternal[NIL, primary.viewerToolData, red, FALSE, FALSE]; SVViewerUser.DrawSceneInternal[NIL, secondary.viewerToolData, red, FALSE, FALSE]; RETURN; }; }; newMat _ Matrix3d.MakeRotateYMat[180]; SVTransforms.PlaceIndirect[secondary.assembly, secondary.coordSys, primary.coordSys, newMat]; <> SVViewerUser.SceneNewVersion[primary.viewerToolData]; SVViewerUser.DrawSceneInternal[NIL, primary.viewerToolData, red, FALSE, FALSE]; }; DrawPt: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; camera: Camera _ viewerPictureData.camera; <> x, y: REAL; DoDrawPt: PROC [dc: Graphics.Context] = TRUSTED { Draw3d.DrawX[dc, [x, y], camera]; }; [x, y] _ SVViewerUser.ReadTwoReals[viewerToolData.textSection.xyz]; SVViewerUser.Painter[DoDrawPt, viewerToolData]; }; MinAndMaxFromCameraAndTree: PRIVATE PROC [camera: Camera, tree: CSGTree] RETURNS [minX, minY, maxX, maxY: REAL] = TRUSTED { frame: FrameBox _ camera.frame; boundBox: BoundBox; IF frame.fullScreen THEN { boundBox _ Preprocess3d.Preprocess[tree, camera]; minX _ boundBox.minVert[1]; minY _ boundBox.minVert[2]; maxX _ boundBox.maxVert[1]; maxY _ boundBox.maxVert[2]; } ELSE { minX _ frame.downLeft[1]; minY _ frame.downLeft[2]; maxX _ frame.upRight[1]; maxY _ frame.upRight[2]; }; }; DrawColor: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { <> viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; scene: Scene _ viewerPictureData.scene; resolution: REAL; boundBox: BoundBox; minX, minY, maxX, maxY: REAL; camera: Camera _ viewerPictureData.camera; tree: CSGTree; aisRope: Rope.ROPE _ ViewerTools.GetContents[viewerToolData.textSection.ais]; DoDrawColor: PROC [dc: Graphics.Context] = TRUSTED { SVImage.DrawAlignedColorImage[dc, aisRope, resolution, [camera.screenCS.mat[1][4], camera.screenCS.mat[2][4]], boundBox]; }; resolution _ camera.resolution; tree _ DisplayList3d.SceneToTree[scene, camera]; [minX, minY, maxX, maxY] _ MinAndMaxFromCameraAndTree[camera, tree]; boundBox _ SVBoundBox.BoundBoxFromValues[minX, minY, maxX, maxY]; SVViewerUser.Painter[DoDrawColor, viewerToolData]; }; -- end of DrawColor DrawBlackAndWhite: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { <> viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; resolution: REAL; scene: Scene _ viewerPictureData.scene; boundBox: BoundBox; minX, minY, maxX, maxY: REAL; camera: Camera _ viewerPictureData.camera; tree: CSGTree; aisRope: Rope.ROPE _ ViewerTools.GetContents[viewerToolData.textSection.ais]; DoDrawBlackAndWhite: PROC [dc: Graphics.Context] = TRUSTED { SVImage.DrawAlignedBlackAndWhiteImage[dc, aisRope, resolution, [camera.screenCS.mat[1][4], camera.screenCS.mat[2][4]], boundBox, FALSE]; }; resolution _ camera.resolution; tree _ DisplayList3d.SceneToTree[scene, camera]; [minX, minY, maxX, maxY] _ MinAndMaxFromCameraAndTree[camera, tree]; boundBox _ SVBoundBox.BoundBoxFromValues[minX, minY, maxX, maxY]; SVViewerUser.Painter[DoDrawBlackAndWhite, viewerToolData]; }; -- end of DrawBlackAndWhite DrawDither: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { <> viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; resolution: REAL; scene: Scene _ viewerPictureData.scene; boundBox: BoundBox; minX, minY, maxX, maxY: REAL; camera: Camera _ viewerPictureData.camera; tree: CSGTree; aisRope: Rope.ROPE _ ViewerTools.GetContents[viewerToolData.textSection.ais]; DoDrawBlackAndWhite: PROC [dc: Graphics.Context] = TRUSTED { SVImage.DrawAlignedBlackAndWhiteImage[dc, aisRope, resolution, [camera.screenCS.mat[1][4], camera.screenCS.mat[2][4]], boundBox, TRUE]; }; resolution _ camera.resolution; aisRope _ Rope.Concat[SVFiles.FilenameMinusExtension[aisRope], "-std.ais"]; tree _ DisplayList3d.SceneToTree[scene, camera]; [minX, minY, maxX, maxY] _ MinAndMaxFromCameraAndTree[camera, tree]; boundBox _ SVBoundBox.BoundBoxFromValues[minX, minY, maxX, maxY]; SVViewerUser.Painter[DoDrawBlackAndWhite, viewerToolData]; }; -- end of DrawDither SetFocalLength: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; viewerPictureData.camera.focalLength _ SVViewerTools.GetReal[viewerToolData.textSection.focalLength, 1800]; }; -- end of SetFocalLength <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> SingleRay: PUBLIC PROC [viewerToolData: ViewerToolData, cameraPoint: Point2d] = TRUSTED { viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; f: IO.STREAM _ SVEditUser.GetOutHandle[]; color: Color; xInt, yInt: INTEGER; tree: CSGTree; scene: Scene _ viewerPictureData.scene; camera: Camera _ viewerPictureData.camera; xInt _ Real.FixI[cameraPoint[1]]; yInt _ Real.FixI[cameraPoint[2]]; tree _ DisplayList3d.SceneToTree[scene, camera]; color _ CastRays.SingleRay[xInt, yInt, tree, scene.lightSources, camera, TRUE, f]; f.PutF["[%g,%g]: ",[real[cameraPoint[1]]], [real[cameraPoint[2]]]]; TFO3d.FileoutColor[f, color]; }; PointAt: PUBLIC PROC [viewerToolData: ViewerToolData, cameraPoint: Point2d] = TRUSTED { <> viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; f: IO.STREAM _ SVEditUser.GetOutHandle[]; tree: CSGTree; normal: Vector; prim: Primitive; scene: Scene _ viewerPictureData.scene; camera: Camera _ viewerPictureData.camera; class: CSG.Classification; tree _ DisplayList3d.SceneToTree[scene, camera]; class _ CastRays.SingleRay2[cameraPoint, tree, scene.lightSources, camera, TRUE, f]; IF class.count = 0 THEN RETURN; prim _ class.primitives[1]; normal _ class.normals[1]; }; RayCastProgress: PUBLIC CastRays.NotifyOfProgressProc = TRUSTED { <> <> viewerToolData: ViewerToolData _ NARROW[clientData]; viewerPictureData: ViewerPictureData _ NARROW[viewerToolData.viewerPicture.data]; camera: Camera _ viewerPictureData.camera; width: REAL _ 10; box: Graphics.Box; lowLeft, upRight: Point2d; DoRayCastProgress: PROC [dc: Graphics.Context] = TRUSTED { Graphics.SetColor[dc, GraphicsColor.black]; Graphics.DrawBox[dc, box]; }; lowLeft _ CoordSys.CameraToScreen[[minX, minY], camera.screenCS]; upRight _ CoordSys.CameraToScreen[[maxX, currentY], camera.screenCS]; box _ [lowLeft[1], lowLeft[2], upRight[1], upRight[2]]; SVViewerUser.Painter[DoRayCastProgress, viewerToolData]; }; END.