DIRECTORY BasicTime, Containers, DisplayList3d, DisplayListToTree, Imager, ImagerPD, IO, Menus, PadGraphics, Rope, Scratchpad2dUser, SV2d, SVError, SVFiles, SVInterfaceTypes, SVModelTypes, SVRayTypes, SVSceneTypes, SVSelections, SVPolygon2d, SVSlices, SVViewerTool, SVViewerUser, SVLines2d, SVVector2d, ViewerClasses, ViewerOps, ViewerTools; Scratchpad2dUserImpl: CEDAR PROGRAM IMPORTS BasicTime, DisplayList3d, DisplayListToTree, Imager, ImagerPD, IO, PadGraphics, Rope, SVError, SVFiles, SVLines2d, SVPolygon2d, SVSelections, SVSlices, SVVector2d, SVViewerUser, ViewerOps, ViewerTools EXPORTS Scratchpad2dUser = BEGIN Assembly: TYPE = SVSceneTypes.Assembly; Camera: TYPE = SVModelTypes.Camera; CoordSystem: TYPE = SVModelTypes.CoordSystem; CSGTree: TYPE = SVRayTypes.CSGTree; EditToolData: TYPE = SVInterfaceTypes.EditToolData; FrameBlock: TYPE = REF FrameBlockObj; FrameBlockObj: TYPE = SVSceneTypes.FrameBlockObj; MouseButton: TYPE = Menus.MouseButton; Path: TYPE = SV2d.Path; Point2d: TYPE = SV2d.Point2d; Polygon: TYPE = SV2d.Polygon; Scene: TYPE = SVSceneTypes.Scene; Slice: TYPE = SVSlices.Slice; ToolData: TYPE = SVSceneTypes.ToolData; TrigLineSeg: TYPE = SV2d.TrigLineSeg; Vector2d: TYPE = SV2d.Vector2d; Viewer: TYPE = ViewerClasses.Viewer; ViewerToolData: TYPE = SVInterfaceTypes.ViewerToolData; ScratchViewerData: TYPE = SVInterfaceTypes.ScratchViewerData; ScratchpadData: TYPE = SVInterfaceTypes.ScratchpadData; squareSide: REAL = 6; Painter: PUBLIC PROC [proc: PROC [Imager.Context], scratchViewerData: ScratchViewerData _ NIL] = TRUSTED { scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; scratchpadData.proc _ proc; ViewerOps.PaintViewer[ viewer: scratchViewerData.scratchpad, hint: client, whatChanged: scratchViewerData, clearClient: FALSE]; }; -- end of Painter PaintRevo: PUBLIC PROC [dc: Imager.Context, scratchpadData: ScratchpadData] = TRUSTED { IF scratchpadData.path.len = 0 THEN RETURN; Imager.SetColor[dc, Imager.black]; PadGraphics.MoveTo[dc, [0, scratchpadData.path[0][2]], scratchpadData.origin]; PadGraphics.DrawSquare[dc, squareSide, [0, scratchpadData.path[0][2]], scratchpadData.origin]; FOR i: NAT IN[0..scratchpadData.path.len) DO PadGraphics.DrawTo[dc, scratchpadData.path[i], scratchpadData.origin]; PadGraphics.DrawSquare[dc, squareSide, scratchpadData.path[i], scratchpadData.origin]; ENDLOOP; PadGraphics.DrawTo[dc, [0, scratchpadData.path[scratchpadData.path.len-1][2]], scratchpadData.origin]; PadGraphics.DrawSquare[dc, squareSide, [0, scratchpadData.path[scratchpadData.path.len-1][2]], scratchpadData.origin]; PadGraphics.MirrorMoveTo[dc, [0, scratchpadData.path[0][2]], scratchpadData.origin]; FOR i: NAT IN[0..scratchpadData.path.len) DO PadGraphics.MirrorDrawTo[dc, scratchpadData.path[i], scratchpadData.origin]; PadGraphics.MirrorDrawSquare[dc, squareSide, scratchpadData.path[i], scratchpadData.origin]; ENDLOOP; PadGraphics.MirrorDrawTo[dc, [0, scratchpadData.path[scratchpadData.path.len-1][2]], scratchpadData.origin]; }; -- end of PaintPoly PaintLin: PUBLIC PROC [dc: Imager.Context, scratchpadData: ScratchpadData] = TRUSTED { IF scratchpadData.path.len = 0 THEN RETURN; Imager.SetColor[dc, Imager.black]; PadGraphics.MoveTo[dc, scratchpadData.path[0], scratchpadData.origin]; PadGraphics.DrawSquare[dc, squareSide, scratchpadData.path[0], scratchpadData.origin]; FOR i: NAT IN[1..scratchpadData.path.len) DO PadGraphics.DrawTo[dc, scratchpadData.path[i], scratchpadData.origin]; PadGraphics.DrawSquare[dc, squareSide, scratchpadData.path[i], scratchpadData.origin]; ENDLOOP; PadGraphics.DrawTo[dc, scratchpadData.path[0], scratchpadData.origin]; }; -- end of PaintLin EraseButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; DoEraseButton: PROC [dc: Imager.Context] = TRUSTED { Erase[dc]; }; Painter[DoEraseButton, scratchViewerData]; }; Erase: PUBLIC PROC [dc: Imager.Context] = TRUSTED { ir: Imager.IntRectangle; Imager.SetColor[dc, Imager.white]; ir _ Imager.GetViewBox[dc]; Imager.IntegerMaskRectangle[dc, ir.x, ir.y, ir.w, ir.h]; }; NormalsButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; path: Path _ scratchpadData.path; iPlusOne: NAT; p1, p2: Point2d; seg: TrigLineSeg; normal: Vector2d; midpoint: Point2d; DoDrawNormals: PROC [dc: Imager.Context] = TRUSTED { Imager.SetColor[dc, Imager.black]; FOR i: NAT IN [0..path.len) DO iPlusOne _ IF i = path.len -1 THEN 0 ELSE i + 1; p1 _ path[i]; p2 _ path[iPlusOne]; seg _ SVLines2d.CreateTrigLineSeg[p1, p2]; normal _ SVVector2d.LeftNormalOfTrigLineSeg[seg]; midpoint[1] _ (p1[1]+p2[1])/2; midpoint[2] _ (p1[2] + p2[2])/2; PadGraphics.Draw2dVector[dc: dc, vec: normal, at: midpoint, origin: scratchpadData.origin]; ENDLOOP; Imager.SetColor[dc, Imager.black]; }; Painter[DoDrawNormals, scratchViewerData]; }; PlaceOrigin: PUBLIC PROC [viewer: Viewer] = TRUSTED { originX, originY: INTEGER; scratchpadData: ScratchpadData _ NARROW[viewer.data]; originX _ viewer.cw;-- convert window width to real originY _ viewer.ch;-- convert window height to real originX _ originX/2;-- find the midpoint in window coords originY _ originY/2; scratchpadData.origin _ [originX, originY]; }; CrossHairsButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; DoCrossHairsButton: PROC [dc: Imager.Context] = TRUSTED { CrossHairs[dc, scratchpadData]; }; Painter[DoCrossHairsButton, scratchViewerData]; }; CrossHairs: PUBLIC PROC [dc: Imager.Context, scratchpadData: ScratchpadData] = TRUSTED { Imager.SetColor[dc, Imager.black]; PadGraphics.CrossHairs[dc, scratchpadData.origin]; }; DrawSceneButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { DoDrawSceneButton: PROC [dc: Imager.Context] = TRUSTED { Erase[dc]; CrossHairs[dc, scratchpadData]; DrawScene[dc, scratchpadData]; }; scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; Painter[DoDrawSceneButton, scratchViewerData]; }; DrawScene: PUBLIC PROC [dc: Imager.Context, scratchpadData: ScratchpadData] = TRUSTED { SELECT scratchpadData.mode FROM drawLin => PaintLin[dc, scratchpadData]; drawRevo => PaintRevo[dc, scratchpadData]; drawSlice => PaintSlice[dc, scratchpadData]; ENDCASE; }; NewLinButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { currentState: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[currentState.scratchpad.data]; scratchpadData.mode _ drawLin; SVPolygon2d.ClearPath[scratchpadData.path]; DrawSceneButton[parent, clientData, mouseButton, shift, control]; }; -- end of NewLine NewRevoButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { currentState: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[currentState.scratchpad.data]; scratchpadData.mode _ drawRevo; SVPolygon2d.ClearPath[scratchpadData.path]; DrawSceneButton[parent, clientData, mouseButton, shift, control]; }; -- end of NewRevo TestPointsButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { currentState: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[currentState.scratchpad.data]; scratchpadData.mode _ pointAt; }; -- end of TestPoints CircleButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; DoDrawCircle: PROC [dc: Imager.Context] = TRUSTED { Imager.SetColor[dc, Imager.black]; PadGraphics.Circle[dc, scratchpadData.origin[1], scratchpadData.origin[2], 100]; }; Painter[DoDrawCircle, scratchViewerData]; }; -- end of Circle DrawSliceButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; editToolData: EditToolData _ NARROW[scratchViewerData.editToolData]; viewerToolData: ViewerToolData _ editToolData.currentViewerToolData; planeAssembly: Assembly; block: FrameBlock; toolData: ToolData; camera: Camera _ viewerToolData.camera; scene: Scene _ editToolData.sceneSection.currentScene; slice: Slice; plane: NAT; tree: CSGTree; xSize, ySize, width, height, scalar, padRatio, sliceRatio: REAL; DoDrawSliceAux: PROC [dc: Imager.Context] = TRUSTED { body: PROC = TRUSTED { Erase[dc]; Imager.TranslateT[dc, scratchpadData.origin[1], scratchpadData.origin[2]]; Imager.ScaleT[dc, scalar]; Imager.TranslateT[dc, -scratchpadData.origin[1], -scratchpadData.origin[2]]; PaintSlice[dc, scratchpadData]; }; Imager.DoSaveAll[dc, body]; }; planeAssembly _ SVSelections.TopPlaneCoincident[]; IF planeAssembly = NIL THEN RETURN; -- no slice plane. IF planeAssembly.toolMasterObject = NIL THEN DisplayList3d.AddOrResizeToolToAssembly[planeAssembly, scene]; toolData _ NARROW[planeAssembly.toolMasterObject.mainBody]; block _ CopyFrameBlock[toolData.block]; plane _ toolData.plane; IF scratchpadData.slice = NIL THEN { slice _ SVSlices.CreateSlice[100, planeAssembly.coordSys, block, plane]; scratchpadData.slice _ slice; } ELSE { slice _ scratchpadData.slice; SVSlices.UpdateSlice[slice, planeAssembly.coordSys, CopyFrameBlock[block], plane]; }; tree _ DisplayListToTree.AssemblyToTree[scene.assembly, scene, camera]; viewerToolData.tree _ tree; SVSlices.RayTraceTheSlice [slice, tree, camera]; xSize _ scratchpadData.origin[1]*2.0; ySize _ scratchpadData.origin[2]*2.0; padRatio _ xSize/ySize; [width, height] _ SVSlices.WidthAndHeight[slice]; sliceRatio _ width/height; IF sliceRatio > padRatio THEN scalar _ 0.6*xSize/width ELSE scalar _ 0.6*ySize/height; Painter[DoDrawSliceAux, scratchViewerData]; SVViewerUser.DrawSlice[viewerToolData, slice]; }; -- end of DrawSliceButton CopyFrameBlock: PRIVATE PROC [block: FrameBlock] RETURNS [copy: FrameBlock] = { copy _ NEW[FrameBlockObj]; copy.loX _ block.loX; copy.hiX _ block.hiX; copy.loY _ block.loY; copy.hiY _ block.hiY; copy.loZ _ block.loZ; copy.hiZ _ block.hiZ; }; SliceRepeatButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; editToolData: EditToolData _ NARROW[scratchViewerData.editToolData]; viewerToolData: ViewerToolData _ editToolData.currentViewerToolData; planeAssembly: Assembly; camera: Camera _ viewerToolData.camera; scene: Scene _ editToolData.sceneSection.currentScene; slice: Slice; tree: CSGTree; xSize, ySize, width, height, scalar, padRatio, sliceRatio: REAL; DoSliceRepeatButton: PROC [dc: Imager.Context] = TRUSTED { body: PROC = TRUSTED { Erase[dc]; Imager.TranslateT[dc, scratchpadData.origin[1], scratchpadData.origin[2]]; Imager.ScaleT[dc, scalar]; Imager.TranslateT[dc, -scratchpadData.origin[1], -scratchpadData.origin[2]]; PaintSlice[dc, scratchpadData]; }; Imager.DoSaveAll[dc, body]; }; planeAssembly _ SVSelections.TopTargetCoincident[]; IF planeAssembly = NIL THEN RETURN; slice _ scratchpadData.slice; slice.coordSys _ planeAssembly.coordSys; tree _ viewerToolData.tree; SVSlices.RayTraceTheSlice [slice, tree, camera]; xSize _ scratchpadData.origin[1]*2.0; ySize _ scratchpadData.origin[2]*2.0; padRatio _ xSize/ySize; [width, height] _ SVSlices.WidthAndHeight[slice]; sliceRatio _ width/height; IF sliceRatio > padRatio THEN scalar _ 0.6*xSize/width ELSE scalar _ 0.6*ySize/height; Painter[DoSliceRepeatButton, scratchViewerData]; SVViewerUser.DrawSlice[viewerToolData, slice]; }; -- end of SliceRepeatButton HardcopyButton: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED { scratchViewerData: ScratchViewerData _ NARROW[clientData]; scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; editToolData: EditToolData _ NARROW[scratchViewerData.editToolData]; viewerToolData: ViewerToolData _ editToolData.currentViewerToolData; startTime: BasicTime.GMT; endTime: BasicTime.GMT; totalTime: INT; timeRope: Rope.ROPE; ipressName: Rope.ROPE; pdDes: ImagerPD.PDFileDescription; ipressContext: Imager.Context; startTime _ BasicTime.Now[]; ipressName _ ViewerTools.GetContents[viewerToolData.textSection.ais]; ipressName _ Rope.Concat[SVFiles.FilenameMinusExtension[ipressName], ".pd"]; SVError.Append[Rope.Cat["Interpressing file ", ipressName, " ..."], TRUE, TRUE]; pdDes _ ImagerPD.Hornet[ipressName]; ipressContext _ Imager.Create[$PD, pdDes]; Imager.ScaleT[ipressContext, 3.527778e-4]; -- units in screen dots DrawScene[ipressContext, scratchpadData]; [] _ Imager.SpecialOp[ipressContext, $Close, NIL]; endTime _ BasicTime.Now[]; totalTime _ BasicTime.Period[startTime, endTime]; timeRope _ IO.PutFR[" Done in (%r)", [integer[totalTime]]]; SVError.Append[timeRope, TRUE, TRUE]; }; EditMode: TYPE = Scratchpad2dUser.EditMode;-- {lin, revo}; SetSlice: PUBLIC PROC [scratchViewerData: ScratchViewerData, slice: Slice] = { scratchpadData: ScratchpadData _ NARROW[scratchViewerData.scratchpad.data]; scratchpadData.slice _ slice; }; Edit: PUBLIC PROC [path: Path, mode: EditMode, scratchViewerData: ScratchViewerData] = TRUSTED { scratchpad: ViewerClasses.Viewer _ scratchViewerData.scratchpad; scratchpadData: ScratchpadData _ NARROW[scratchpad.data]; scratchpadData.path _ path; SELECT mode FROM lin => {scratchpadData.mode _ drawLin; DrawSceneButton [scratchpad, scratchpadData.scratchViewerData, red, FALSE, FALSE]; }; revo => {scratchpadData.mode _ drawRevo; DrawSceneButton [scratchpad, scratchpadData.scratchViewerData, red, FALSE, FALSE]; }; ENDCASE => ERROR; }; -- end of Edit PaintSlice: PROC [dc: Imager.Context, scratchpadData: ScratchpadData] ~ { slice: Slice; origin: Point2d; Erase[dc]; CrossHairs[dc, scratchpadData]; scratchpadData.mode _ drawSlice; slice _ scratchpadData.slice; origin _ scratchpadData.origin; Imager.SetColor[dc, Imager.black]; SVSlices.DrawSlice[dc, slice, origin]; }; END. ˆFile: Scratchpad2dUserImpl.mesa Last edited by: Eric Bier on August 20, 1984 0:59:09 am PDT Copyright c 1984 by Xerox Corporation. All rights reserved. Contents: Functions called by the buttons on a Scratchpad2d viewer. Begin at y axis to show user how the final effect will look Paint right side End at y axis to show user how the final sweep will look Now paint left side End at y axis to show user how the final sweep will look Paint right side Go through each segment of the current picture. Find its outward pointing normal and draw it. mark: Graphics.Mark _ Graphics.Save[dc]; Graphics.Restore[dc,mark]; viewer is the scratchpad window find the center of the scratchpad window in scratchpad window coordinates Find the current target object and use its current plane as the slicing plane. To keep from allocating a new slice record, we reuse the old one when possible. There has been no previous slice. Use the planeAssembly to make one. Now we must make a ray-tracing tree. Now, we must ray-trace the current scene along this plane. This is view-point independent, but we need a camera anyway to specify the bounding spheres. Finally, we must tell the Scratchpad to draw it. Also, draw the slice on the appropriate solid viewer. Like DrawSliceButton but doesn't recompute the ray tracing tree. Now, we must ray-trace the current scene along this plane. This is view-point independent, but we need a camera anyway to specify the bounding spheres. Finally, we must tell the Scratchpad to draw it. Also, draw the slice on the appropriate solid viewer. Timing Varables Interpress Variables Start Timing Start Pressing GraphicsToPress.Close[pressContext]; Κ– "cedar" style˜Iheadšœ™Iprocšœ;™;Jšœ Οmœ1™—Lšœ žœ*˜;JšŸœ"˜'JšŸœ˜šžœžœžœ˜%J™EJ•StartOfExpansion[]šœŸ œ,˜HJšœ˜J˜—šžœ˜Jšœ˜Jšœ Ÿ œ?˜SJ˜J™$—JšœŸœ ˜Gšœ˜J™˜—šœ Ÿœ˜0J™0—Jšœ%˜%Jšœ%˜%Jšœ˜Jšœ1˜1Jšœ˜Jšžœžœ˜6Jšžœ˜šœŸœ˜+J™5—Jšœ Ÿ œ˜.Lšœ‘˜L™—š œž œžœ˜OLšœžœ˜L˜L˜L˜L˜L˜L˜L˜L˜—š œž œ žœžœžœžœ,žœ˜yL™@Lšœ'žœ ˜:Lšœ!žœ$˜KLšœžœ!˜DJšœD˜DLšœ˜Jšœ'˜'Jšœ6˜6J˜ Jšœ˜Jšœ;žœ˜@š œžœžœ˜:šœžœžœ˜J˜ JšœJ˜JJ˜JšœL˜LJšœ˜J˜—Jšœ˜J˜J˜—Jšœ3˜3Jšžœžœžœžœ˜#J˜J–[]šœ˜Jšœ(˜(šœ˜J™˜—šœ0˜0J™0—Jšœ%˜%Jšœ%˜%Jšœ˜Jšœ1˜1Jšœ˜Jšžœžœ˜6Jšžœ˜šœ0˜0J™5—Jšœ.˜.Lšœ‘˜L˜—š œžœžœ žœžœžœžœ,žœ ˜~Jšœ'žœ ˜:Jšœ!žœ$˜KLšœžœ!˜DšœD˜DJšœ™—Jšœžœ˜Jšœžœ˜Jšœ žœ˜šœžœ˜Jšœ™—Jšœžœ˜Jšœ"˜"šœ˜Jšœ ™ —šœ˜Jšœ™—JšœE˜EJšœL˜LJšœDžœžœ˜PJšœ$˜$Jšœ*˜*JšœC˜CJšœ)˜)Jšœ2˜2Jšœ$™$Jšœ˜Jšœ1˜1Jšœ žœ.˜;Jšœžœžœ˜%Jšœ˜—L˜Lšœ žœ‘˜:L˜š œžœžœ9˜NLšœ!žœ$˜KLšœ˜L˜—L˜š œžœžœFžœ˜`Lšœ@˜@Lšœ!žœ˜9Lšœ˜Lšžœž˜šœ&˜&LšœDžœžœ˜RLšœ˜—Lšœ(˜(LšœGžœžœ˜ULšœ˜Lšžœžœ˜Lšœ‘˜—L˜š  œžœ9˜ILšœ ˜ Lšœ˜L˜L˜ Lšœ˜Lšœ ˜ Lšœ˜Lšœ˜L˜"Lšœ&˜&˜L˜——Lšžœ˜—…—9ΰO€