DIRECTORY AtomButtonsTypes, CoordSys, SVGraphics, Feedback, GList, Imager, ImagerColor, ImagerColorPrivate, ImagerTransformation, IO, Rope, SV2d, SV3d, SVArtwork, SVAssembly, SVBasicTypes, SVBoundBox, SVMasterObject, SVModelTypes, SVScene, SVScenePrivate, SVSceneTypes, SVSelect, SVUtility, ViewerClasses; SVSceneImplB: CEDAR PROGRAM IMPORTS CoordSys, SVGraphics, Feedback, GList, Imager, ImagerColor, ImagerColorPrivate, IO, Rope, SVArtwork, SVAssembly, SVBoundBox, SVMasterObject, SVScene, SVScenePrivate, SVSelect, SVUtility EXPORTS SVScene, SVScenePrivate = BEGIN BoundBox: TYPE = SVBasicTypes.BoundBox; Camera: TYPE = SVModelTypes.Camera; Classification: TYPE = SVSceneTypes.Classification; Color: TYPE = Imager.Color; CoordSysList: TYPE = SVModelTypes.CoordSysList; CoordSystem: TYPE = SVModelTypes.CoordSystem; CSGTree: TYPE = SVSceneTypes.CSGTree; DrawStyle: TYPE = SVModelTypes.DrawStyle; FeedbackData: TYPE = AtomButtonsTypes.FeedbackData; FileCamera: TYPE = REF FileCameraObj; FileCameraObj: TYPE = SVSceneTypes.FileCameraObj; FileCameraList: TYPE = SVSceneTypes.FileCameraList; FrameBox: TYPE = SVSceneTypes.FrameBox; Matrix4by4: TYPE = SV3d.Matrix4by4; Plane: TYPE = SV3d.Plane; Point2d: TYPE = SV2d.Point2d; Point3d: TYPE = SV3d.Point3d; PointSetOp: TYPE = SVSceneTypes.PointSetOp; -- {union, intersection, difference} Poly3d: TYPE = SV3d.Poly3d; Primitive: TYPE = SVSceneTypes.Primitive; Ray: TYPE = SVSceneTypes.Ray; Shape: TYPE = SVSceneTypes.Shape; SliceDescriptor: TYPE = SVSceneTypes.SliceDescriptor; SliceDescriptorGenerator: TYPE = SVSceneTypes.SliceDescriptorGenerator; Vector3d: TYPE = SV3d.Vector3d; Viewer: TYPE = ViewerClasses.Viewer; Database: TYPE = REF DatabaseObj; DatabaseObj: TYPE = SVSceneTypes.DatabaseObj; Scene: TYPE = REF SceneObj; SceneObj: TYPE = SVSceneTypes.SceneObj; Artwork: TYPE = SVModelTypes.Artwork; Slice: TYPE = REF SliceObj; SliceObj: TYPE = SVSceneTypes.SliceObj; ToolData: TYPE = REF ToolDataObj; ToolDataObj: TYPE = SVSceneTypes.ToolDataObj; SliceList: TYPE = REF SliceListObj; SliceListObj: TYPE = SVSceneTypes.SliceListObj; LightSource: TYPE = REF LightSourceObj; LightSourceObj: TYPE = SVModelTypes.LightSourceObj; LightSourceList: TYPE = SVModelTypes.LightSourceList; MasterObjectClass: TYPE = REF MasterObjectClassObj; MasterObjectClassObj: TYPE = SVSceneTypes.MasterObjectClassObj; MasterObjectClassList: TYPE = SVSceneTypes.MasterObjectClassList; FileoutProc: TYPE = SVSceneTypes.FileoutProc; FileinProc: TYPE = SVSceneTypes.FileinProc; MasterObject: TYPE = REF MasterObjectRec; MasterObjectRec: TYPE = SVSceneTypes.MasterObjectRec; MasterObjectList: TYPE = SVSceneTypes.MasterObjectList; FileoutPolyProc: TYPE = SVSceneTypes.FileoutPolyProc; RayCastProc: TYPE = SVSceneTypes.RayCastProc; RayCastNoBBoxesProc: TYPE = SVSceneTypes.RayCastNoBBoxesProc; RayCastBoundingSpheresProc: TYPE = SVSceneTypes.RayCastBoundingSpheresProc; GetHedronProc: TYPE = SVSceneTypes.GetHedronProc; PreprocessProc: TYPE = SVSceneTypes.PreprocessProc; LineDrawProc: TYPE = SVSceneTypes.LineDrawProc; NormalsDrawProc: TYPE = SVSceneTypes.NormalsDrawProc; CountSurfProc: TYPE = SVSceneTypes.CountSurfProc; GetSurfProc: TYPE = SVSceneTypes.GetSurfProc; PlanarSurface: TYPE = REF PlanarSurfaceObj; PlanarSurfaceObj: TYPE = SVSceneTypes.PlanarSurfaceObj; PlanarSurfaceList: TYPE = SVSceneTypes.PlanarSurfaceList; DrawPlanarSurfaceProc: TYPE = SVSceneTypes.DrawPlanarSurfaceProc; DrawSubBoxesProc: TYPE = SVSceneTypes.DrawSubBoxesProc; DrawSubSpheresProc: TYPE = SVSceneTypes.DrawSubSpheresProc; DeleteMasterObjectNamed: PUBLIC PROC [moName: Rope.ROPE, scene: Scene] RETURNS [found: BOOL] = { mo, beforeMo, afterMo: MasterObjectList; [beforeMo, mo, afterMo, found] _ SVScenePrivate.FindMasterObjectAndNeighborsFromName[moName, scene.masterObjects]; IF NOT found THEN RETURN; IF beforeMo = NIL THEN scene.masterObjects _ afterMo ELSE beforeMo.rest _ afterMo; }; -- end of DeleteMasterObjectNamed MasterObjectIsUsed: PUBLIC PROC [mo: MasterObject, scene: Scene] RETURNS [used: BOOL] = { shape: Shape; IF Rope.Equal[mo.class.name, "sphere"] OR Rope.Equal[mo.class.name, "cylinder"] OR Rope.Equal[mo.class.name, "cone"] OR Rope.Equal[mo.class.name, "halfSpace"] THEN RETURN[TRUE]; FOR primitiveAssemblies: LIST OF Slice _ SVScene.ListOfPrimAssemblies[scene.assembly, scene], primitiveAssemblies.rest UNTIL primitiveAssemblies = NIL DO shape _ NARROW[primitiveAssemblies.first.shape]; IF shape.mo = mo THEN RETURN[TRUE]; ENDLOOP; RETURN[FALSE]; }; DeleteMasterObjectIfUnused: PUBLIC PROC [mo: MasterObject, scene: Scene] RETURNS [found: BOOL] = { shape: Shape; IF Rope.Equal[mo.class.name, "sphere"] OR Rope.Equal[mo.class.name, "block"] OR Rope.Equal[mo.class.name, "cylinder"] OR Rope.Equal[mo.class.name, "cone"] OR Rope.Equal[mo.class.name, "halfSpace"] THEN RETURN[TRUE]; FOR primitiveAssemblies: LIST OF Slice _ SVScene.ListOfPrimAssemblies[scene.assembly, scene], primitiveAssemblies.rest UNTIL primitiveAssemblies = NIL DO shape _ NARROW[primitiveAssemblies.first.shape]; IF shape.mo = mo THEN RETURN[TRUE]; ENDLOOP; found _ DeleteMasterObjectNamed[mo.name, scene]; }; -- end of DeleteMasterObjectIfUnused DeleteCoordSysAndChildren: PUBLIC PROC [cs: CoordSystem, scene: Scene] = { CoordSys.DeleteCoordSysAndChildren[cs, scene.coordSysRoot]; }; -- end of DeleteCoordSysNamed DeleteLightSourceNamed: PUBLIC PROC [lsName: Rope.ROPE, scene: Scene] = { ls, beforeLS, afterLS: LightSourceList; notFound: BOOL _ FALSE; [beforeLS, ls, afterLS] _ SVScenePrivate.FindLightSourceAndNeighborsFromName[lsName, scene.lightSources !SVScenePrivate.LightSourceNotFound => {notFound _ TRUE; CONTINUE}]; IF notFound THEN RETURN; IF beforeLS = NIL THEN scene.lightSources _ afterLS ELSE beforeLS.rest _ afterLS; }; -- end of DeleteLightSourceNamed ClearScene: PUBLIC PROC [scene: Scene] = { scene.assembly.shape _ NEW[SliceListObj _ [NIL, union] ]; ClearCoordSystems[scene]; ClearMasterObjects[scene]; }; ClearCoordSystems: PUBLIC PROC [scene: Scene] = { world: CoordSystem _ scene.coordSysRoot; DeleteCoordSysAndChildren[CoordSys.GetSceneAssembly[world], scene]; }; ClearMasterObjects: PUBLIC PROC [scene: Scene] = { z: MasterObjectList _ scene.masterObjects; -- "sphere" z _ z.rest;-- "block" z _ z.rest;-- "cone" z _ z.rest;-- "cylinder" z.rest _ NIL;-- cut off the rest }; DeleteSubassemblyFromAssembly: PUBLIC PROC [subassembly: Slice, assembly: Slice, scene: Scene] RETURNS [success: BOOL] = { IF ISTYPE[assembly.shape, SliceList] THEN [assembly.shape, success] _ RemoveFromAssemblyList[subassembly, NARROW[assembly.shape, SliceList], scene] ELSE ERROR; }; RemoveFromAssemblyList: PROC [a: Slice, al: SliceList, scene: Scene] RETURNS [newAl: SliceList, success: BOOL] = { lastAssemblyList: LIST OF Slice _ al.list; DeleteAllAssembliesSittingOn[a, scene]; IF lastAssemblyList.first = a THEN {-- first item on the list DeleteAssemblyAndSons[a, scene]; al.list _ lastAssemblyList.rest; RETURN[al, TRUE]; }; FOR l: LIST OF Slice _ lastAssemblyList.rest, l.rest UNTIL l = NIL DO IF l.first = a THEN { DeleteAssemblyAndSons[a, scene]; success _ TRUE; lastAssemblyList.rest _ l.rest; -- splice out a newAl _ al; RETURN; } ELSE lastAssemblyList _ lastAssemblyList.rest; ENDLOOP; success _ FALSE; }; TemporaryRemoveFromAssemblyList: PUBLIC PROC [a: Slice, al: SliceList, scene: Scene] RETURNS [newAl: SliceList, success: BOOL] = { lastAssemblyList: LIST OF Slice _ al.list; IF lastAssemblyList.first = a THEN {-- first item on the list al.list _ lastAssemblyList.rest; RETURN[al, TRUE] }; FOR l: LIST OF Slice _ lastAssemblyList.rest, l.rest UNTIL l = NIL DO IF l.first = a THEN { success _ TRUE; lastAssemblyList.rest _ l.rest; -- splice out a newAl _ al; RETURN; } ELSE lastAssemblyList _ lastAssemblyList.rest; ENDLOOP; success _ FALSE; }; DeleteAssemblyAndSons: PROC [a: Slice, scene: Scene] = { DeleteCoordSysAndChildren[a.coordSys, scene]; }; DeleteAllPrimitivesOfClass: PUBLIC PROC [className: Rope.ROPE, scene: Scene, feedback: FeedbackData] = { moClass: MasterObjectClass; success: BOOL; [moClass, success] _ SVMasterObject.FindClassFromName[className]; IF NOT success THEN { Feedback.Append[feedback, Rope.Cat["DeleteAllPrimitivesOfClass: Couldn't find class ", className, "."], oneLiner]; Feedback.Blink[feedback]; }; DeleteAllOfClassAux[moClass, scene.assembly, scene]; }; DeleteAllOfClassAux: PROC [moClass: MasterObjectClass, root: Slice, scene: Scene] = { WITH root.shape SELECT FROM shape: Shape => { child, parent: Slice; success: BOOL; IF shape.mo.class = moClass THEN { [child, parent] _ SVScene.FindAssemblyFromName[root.name, scene]; IF child # root THEN ERROR; success _ SVScene.DeleteSubassemblyFromAssembly[child, parent, scene]; IF NOT success THEN ERROR; }; }; alist: SliceList => { FOR list: LIST OF Slice _ alist.list, list.rest UNTIL list = NIL DO DeleteAllOfClassAux[moClass, list.first, scene]; ENDLOOP; }; ENDCASE => ERROR; }; DeleteAllAssembliesSittingOn: PUBLIC PROC [chair: Slice, scene: Scene] = { DeleteAllSittingOnAux[chair.name, scene.assembly, scene]; }; DeleteAllSittingOnAux: PROC [chairName: Rope.ROPE, root: Slice, scene: Scene] = { child, parent: Slice; success: BOOL; IF Rope.Equal[root.sittingOn, chairName, TRUE] THEN { [child, parent] _ SVScene.FindAssemblyFromName[root.name, scene]; IF child # root THEN ERROR; success _ SVScene.DeleteSubassemblyFromAssembly[child, parent, scene]; IF NOT success THEN ERROR; RETURN; }; WITH root.shape SELECT FROM shape: Shape => {}; alist: SliceList => { FOR list: LIST OF Slice _ alist.list, list.rest UNTIL list = NIL DO DeleteAllSittingOnAux[chairName, list.first, scene]; ENDLOOP; }; ENDCASE => ERROR; }; DeleteAllSelected: PUBLIC PROC [scene: Scene, camera: Camera] RETURNS [bBox: BoundBox] = { sliceDescGen: SliceDescriptorGenerator; assembly, superAssembly: Slice; success: BOOL _ TRUE; bBox _ SVBoundBox.BoundBoxOfSelected[scene, camera, normal]; sliceDescGen _ SVSelect.SelectedSlices[scene, normal]; FOR coin: Slice _ SVSelect.NextSlice[sliceDescGen], SVSelect.NextSlice[sliceDescGen] UNTIL coin = NIL DO [assembly, superAssembly, success] _ SVScene.FindAssemblyFromName[coin.name, scene]; IF NOT success THEN LOOP; SVSelect.DeselectEntireSlice[assembly, scene, hot]; success _ SVScene.DeleteSubassemblyFromAssembly[assembly, superAssembly, scene]; IF NOT success THEN ERROR; ENDLOOP; SVSelect.DeselectAll[scene, normal]; }; CopyAssemblyAndSonsRename: PUBLIC PROC [assembly: Slice, scene: Scene, prefix: Rope.ROPE, parent: Slice, feedback: FeedbackData] RETURNS [copy: Slice] = { moFound: BOOL; IF NewNamesAlreadyPresent[assembly, scene, prefix] THEN SIGNAL SVScene.NameAlreadyPresent; WITH assembly.shape SELECT FROM alist: SliceList => {-- assembly is a composite assembly. copyCS: CoordSystem _ CoordSys.CreateCoordSysInTree[name: Rope.Concat[prefix, assembly.name], mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: scene.coordSysRoot]; copy _ SVAssembly.CreateClusterAssemblyAtExistingCoordSys[Rope.Concat[prefix, assembly.name], alist.pointSetOp, scene, copyCS]; FOR list: LIST OF Slice _ alist.list, list.rest UNTIL list = NIL DO [] _ CopyAssemblyAndSonsRename[list.first, scene, prefix, copy, feedback]; ENDLOOP; }; shape: Shape => { -- assembly is a primitive assembly artworkCopy: Artwork _ SVArtwork.Copy[assembly.artwork]; copyCS: CoordSystem _ CoordSys.CreateCoordSysInTree[name: Rope.Concat[prefix, assembly.name], mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: scene.coordSysRoot]; [copy, moFound] _ SVAssembly.CreatePrimitiveAtExistingCoordSys[Rope.Concat[prefix, assembly.name], shape.mo.name, CoordSys.GetScalars[shape.coordSys], scene, copyCS, artworkCopy, assembly.isTool]; IF NOT moFound THEN ERROR; -- for some reason the master object which assembly refers to is not registered in the scene (report this to SolidviewsSupport). }; ENDCASE => ERROR; SVAssembly.ConnectAssemblyToParent[copy, parent]; }; -- end of CopyAssemblyAndSons CopyAssemblyAndSonsNoRename: PUBLIC PROC [assembly: Slice, newScene: Scene, parent: Slice, feedback: FeedbackData] RETURNS [copy: Slice] = { moFound: BOOL; IF SVScene.AnyNamesAlreadyPresent[assembly, newScene] THEN SIGNAL SVScene.NameAlreadyPresent; WITH assembly.shape SELECT FROM alist: SliceList => {-- assembly is a composite assembly. copyCS: CoordSystem _ CoordSys.CreateCoordSysInTree[name: assembly.name, mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: newScene.coordSysRoot]; copy _ SVAssembly.CreateClusterAssemblyAtExistingCoordSys[assembly.name, alist.pointSetOp, newScene, copyCS]; FOR list: LIST OF Slice _ alist.list, list.rest UNTIL list = NIL DO [] _ CopyAssemblyAndSonsNoRename[list.first, newScene, copy, feedback]; ENDLOOP; }; shape: Shape => { -- assembly is a primitive assembly artworkCopy: Artwork _ SVArtwork.Copy[assembly.artwork]; copyCS: CoordSystem _ CoordSys.CreateCoordSysInTree[name: assembly.name, mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: newScene.coordSysRoot]; [copy, moFound] _ SVAssembly.CreatePrimitiveAtExistingCoordSys[assembly.name, shape.mo.name, CoordSys.GetScalars[shape.coordSys], newScene, copyCS, artworkCopy, assembly.isTool]; IF NOT moFound THEN ERROR; -- for some reason the master object which assembly refers to is not registered in the scene (report this to SolidviewsSupport). }; ENDCASE => ERROR; SVAssembly.ConnectAssemblyToParent[assembly, parent]; }; -- end of CopyAssemblyAndSonsNoRename ReadAlpha: PROC [s: IO.STREAM] RETURNS [base: Rope.ROPE] = { skip: INT; [base, skip] _ IO.GetTokenRope[s, AlphaBreakProc]; }; AlphaBreakProc: SAFE PROC [char: CHAR] RETURNS [IO.CharClass] = { RETURN[IF char = '. THEN break ELSE other] }; FindUniqueAssemblyNum: PROC [scene: Scene] RETURNS [num: NAT] = { num _ FindUniqueAssemblyNumAux[scene.assembly]; num _ num + 1; }; FindUniqueAssemblyNumAux: PROC [assembly: Slice] RETURNS [num: NAT] = { thisNum: NAT; WITH assembly.shape SELECT FROM alist: SliceList => {-- assembly is a composite assembly. [----, num] _ CoordSys.BaseAndNumber[assembly.name]; FOR l: LIST OF Slice _ alist.list, l.rest UNTIL l = NIL DO thisNum _ FindUniqueAssemblyNumAux[l.first]; num _ MAX[num, thisNum]; ENDLOOP; }; shape: Shape => { -- assembly is a primitive assembly [----, num] _ CoordSys.BaseAndNumber[assembly.name]; }; ENDCASE => ERROR; }; CopyAssemblyAndSonsUniqueNames: PUBLIC PROC [assembly: Slice, oldScene: Scene, newScene: Scene, parent: Slice, feedback: FeedbackData] RETURNS [copy: Slice] = { num: NAT; success: BOOL; num _ FindUniqueAssemblyNum[newScene]; IF oldScene = newScene THEN copy _ CopyAssemblyAndSonsUniqueNamesAux[assembly, newScene, parent, num, feedback] ELSE { success _ CopyNeededMasterObjects[assembly, oldScene, newScene]; IF NOT success THEN { Feedback.Append[feedback, Rope.Cat["Masterobject name conflict scenes: ", oldScene.name, "/", newScene.name], oneLiner]; Feedback.Blink[feedback]; RETURN; }; copy _ CopyAssemblyAndSonsUniqueNamesAux[assembly, newScene, parent, num, feedback]; }; }; CopyAssemblyAndSonsUniqueNamesAux: PUBLIC PROC [assembly: Slice, newScene: Scene, parent: Slice, num: NAT, feedback: FeedbackData] RETURNS [copy: Slice] = { thisBase, unique: Rope.ROPE; thisNum: NAT; moFound: BOOL; WITH assembly.shape SELECT FROM alist: SliceList => {-- assembly is a composite assembly. copyCS: CoordSystem; [thisBase, thisNum] _ CoordSys.BaseAndNumber[assembly.name]; unique _ IO.PutFR["%g.%g", [rope[thisBase]], [integer[num]]]; copyCS _ CoordSys.CreateCoordSysInTree[name: unique, mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: newScene.coordSysRoot]; copy _ SVAssembly.CreateClusterAssemblyAtExistingCoordSys[unique, alist.pointSetOp, newScene, copyCS]; FOR list: LIST OF Slice _ alist.list, list.rest UNTIL list = NIL DO [] _ CopyAssemblyAndSonsUniqueNamesAux[list.first, newScene, copy, num, feedback]; ENDLOOP; }; shape: Shape => { -- assembly is a primitive assembly artworkCopy: Artwork _ SVArtwork.Copy[assembly.artwork]; copyCS: CoordSystem; oldMO, newMO: MasterObject; [thisBase, thisNum] _ CoordSys.BaseAndNumber[assembly.name]; unique _ IO.PutFR["%g.%g",[rope[thisBase]], [integer[num]]]; copyCS _ CoordSys.CreateCoordSysInTree[ name: unique, mat: CoordSys.GetMat[assembly.coordSys], parent: parent.coordSys, root: newScene.coordSysRoot]; oldMO _ shape.mo; newMO _ oldMO.class.copy[oldMO, unique]; SVScene.AddMasterObjectToScene[newMO, newScene]; [copy, moFound] _ SVAssembly.CreatePrimitiveAtExistingCoordSys[unique, newMO.name, CoordSys.GetScalars[shape.coordSys], newScene, copyCS, artworkCopy, assembly.isTool]; IF NOT moFound THEN ERROR; }; ENDCASE => ERROR; SVAssembly.ConnectAssemblyToParent[copy, parent]; }; AddMOsToScene: PROC [moList: MasterObjectList, scene: Scene] = { FOR list: MasterObjectList _ moList, list.rest UNTIL list = NIL DO scene.masterObjects _ SVUtility.AppendToMasterObjects[list.first, scene.masterObjects]; ENDLOOP; }; CopyMOList: PROC [moList: MasterObjectList] RETURNS [copyList: MasterObjectList] = { copyList _ NIL; FOR list: MasterObjectList _ moList, list.rest UNTIL list = NIL DO copyList _ SVUtility.AppendToMasterObjects[SVScene.CopyMasterObject[list.first], copyList]; ENDLOOP; }; CopyNeededMasterObjects: PUBLIC PROC [assembly: Slice, fromScene, toScene: Scene] RETURNS [success: BOOL] = { moList: MasterObjectList; toMoList: MasterObjectList; neededList: MasterObjectList; success _ TRUE; moList _ SVScene.MasterObjectsOfAssembly[assembly, fromScene]; toMoList _ SVScene.MasterObjectsOfScene[toScene]; neededList _ SVScenePrivate.MoListMinusMoList[moList, toMoList]; neededList _ CopyMOList[neededList]; AddMOsToScene[neededList, toScene]; }; RemoveDuplicateMOs: PUBLIC PROC [moList: MasterObjectList] RETURNS [uniqueList: MasterObjectList] = { thisMO: MasterObject; uniqueList _ NIL; FOR list: MasterObjectList _ moList, list.rest UNTIL list = NIL DO thisMO _ list.first; IF NOT ObjectNameInList[thisMO.name, uniqueList] THEN uniqueList _ CONS[thisMO, uniqueList]; ENDLOOP; }; ObjectNameInList: PROC [moName: Rope.ROPE, moList: MasterObjectList] RETURNS [BOOL]= { FOR list: MasterObjectList _ moList, list.rest UNTIL list = NIL DO IF Rope.Equal[list.first.name, moName, TRUE] THEN RETURN[TRUE]; ENDLOOP; RETURN[FALSE]; }; MoListMinusMoList: PUBLIC PROC [moList1, moList2: MasterObjectList] RETURNS [moList1MinusmoList2: MasterObjectList] = { moList1MinusmoList2 _ NIL; FOR list: MasterObjectList _ moList1, list.rest UNTIL list = NIL DO IF NOT ObjectNameInList[list.first.name, moList2] THEN moList1MinusmoList2 _ CONS[list.first, moList1MinusmoList2]; ENDLOOP; }; CopyMasterObjectList: PUBLIC PROC [moList: MasterObjectList] RETURNS [copy: MasterObjectList] = { copy _ NIL; FOR list: MasterObjectList _ moList, list.rest UNTIL list = NIL DO copy _ SVUtility.AppendToMasterObjects[list.first, copy]; ENDLOOP; }; NewNamesAlreadyPresent: PUBLIC PROC [assembly: Slice, scene: Scene, prefix: Rope.ROPE] RETURNS [BOOL] = { newName: Rope.ROPE _ Rope.Concat[prefix, assembly.name]; IF SVScene.AssemblyNameIsPresent[newName, scene] THEN RETURN [TRUE]; WITH assembly.shape SELECT FROM shape: Shape => RETURN[FALSE]; aList: SliceList => RETURN[NewNamesAlreadyPresentInList[aList, scene, prefix]]; ENDCASE => RETURN[FALSE]; }; NewNamesAlreadyPresentInList: PROC [assemblyList: SliceList, scene: Scene, prefix: Rope.ROPE] RETURNS [BOOL] = { FOR list: LIST OF Slice _ assemblyList.list, list.rest UNTIL list = NIL DO IF NewNamesAlreadyPresent[list.first, scene, prefix] THEN RETURN [TRUE]; ENDLOOP; RETURN [FALSE]; }; DrawScene: PUBLIC PROC [dc: Imager.Context, scene: Scene, camera: Camera, except: Slice _ NIL] = { DrawSceneAux: SAFE PROC = { SELECT camera.style FROM wire => DrawWireAssemblies[dc, scene, camera]; shaded => DrawShadedAssemblies[dc, scene, camera, clippedBy, except]; normals => DrawNormalsAssemblies[dc, scene, camera]; ENDCASE => SIGNAL NotYetImplemented; IF NOT camera.frame.fullScreen THEN { SetColor[dc, camera, Imager.black]; SVGraphics.DrawFrame[dc, camera]; }; }; clippedBy: Imager.Rectangle _ [0.0, 0.0, 8.5*72.0, 11.0*72.0]; Imager.DoSaveAll[dc, DrawSceneAux]; }; NotYetImplemented: PUBLIC SIGNAL = CODE; DrawWireAssemblies: PROC [dc: Imager.Context, scene: Scene, camera: Camera] = { assemblyName: Rope.ROPE; found: BOOL; assembly: Slice; FOR list: LIST OF Rope.ROPE _ camera.visibleAssemblies, list.rest UNTIL list = NIL DO assemblyName _ list.first; found _ TRUE; [assembly, ----] _ SVScene.FindAssemblyFromName[assemblyName, scene !SVScene.AssemblyNotFound => {found _ FALSE; CONTINUE}]; IF found THEN { SVAssembly.Draw[assembly, dc, scene, camera]; }; ENDLOOP; }; DrawShadedAssemblies: PROC [dc: Imager.Context, scene: Scene, camera: Camera, clippedBy: Imager.Rectangle, except: Slice _ NIL] = { assemblyName: Rope.ROPE; assembly: Slice; found: BOOL; SetColor[dc, camera, scene.backgroundColor]; Imager.MaskRectangle[dc, clippedBy]; FOR list: LIST OF Rope.ROPE _ camera.visibleAssemblies, list.rest UNTIL list = NIL DO assemblyName _ list.first; found _ TRUE; [assembly, ----] _ SVScene.FindAssemblyFromName[assemblyName, scene !SVScene.AssemblyNotFound => {found _ FALSE; CONTINUE}]; IF found THEN { SVAssembly.Draw[assembly, dc, scene, camera]; }; ENDLOOP; }; DrawNormalsAssemblies: PROC [dc: Imager.Context, scene: Scene, camera: Camera] = { assemblyName: Rope.ROPE; assembly: Slice; found: BOOL; FOR list: LIST OF Rope.ROPE _ camera.visibleAssemblies, list.rest UNTIL list = NIL DO assemblyName _ list.first; found _ TRUE; [assembly, ----] _ SVScene.FindAssemblyFromName[assemblyName, scene !SVScene.AssemblyNotFound => {found _ FALSE; CONTINUE}]; IF found THEN { SVAssembly.Draw[assembly, dc, scene, camera]; }; ENDLOOP; }; SetColor: PROC [dc: Imager.Context, camera: Camera, color: Color] = { IF camera.colorFilm THEN Imager.SetColor[dc, color] ELSE { intensity: REAL _ ImagerColorPrivate.IntensityFromColor[NARROW[color]]; Imager.SetColor[dc, ImagerColor.ColorFromGray[1.0-intensity]]}; }; SaveSelections: PUBLIC PROC [scene: Scene] = { scene.savedSelected.normal _ NARROW[GList.Append[scene.selected.normal, NIL]]; }; RestoreSelections: PUBLIC PROC [scene: Scene] = { normalSelectedList: LIST OF SliceDescriptor _ scene.savedSelected.normal; SVSelect.DeselectAll[scene, normal]; FOR list: LIST OF SliceDescriptor _ normalSelectedList, list.rest UNTIL list = NIL DO SVSelect.SelectSlice[list.first, scene, normal]; ENDLOOP; }; END. šSVSceneImplB.mesa Last edited by Bier on June 1, 1987 11:08:04 am PDT Copyright c 1984 by Xerox Corporation. All rights reserved. Imported Types DisplayList Types Databases, Scenes, Assemblies, and Lightsources Master Object Class Types Master Object Types Delete Parts of the Scene Tree For now, we won't delete the built-in instances. Removes all but WORLD, SCREEN and sceneAssembly. Assumes for now that WORLD, and SCREEN are the first 2 coordsystems on the list. Removes all but "block", "sphere", "cone", and "cylinder" from current scene. Assumes for now that "sphere","cone", and "cylinder", and "block" are the first five master objects. Tree walk through the assembly deleting all of its coordinate systems. Then, cut the assembly loose and feed it to the garbage collector. A simple list remove operation. Does not break up the assembly and its sons, nor does it delete their coordinate systems. This routine is called by MoveToFrontOfAssembly to splice an assembly out of an SliceList. className must be a master object class, e.g. "sphere" or "jack". All primitive (leaf) assemblies refering to shapes of this class will be deleted in subtree rooted at root. Removes assembly from the assemblyList of superAssembly and deletes the coordinate systems of all of its children. All assemblies A such that A.sittingOn = chair.name will be deleted along with their children. Removes assembly from the assemblyList of superAssembly and deletes the coordinate systems of all of its children. We will certainly delete the coincident of all movee's. We may also delete an assembly indirectly referenced by a selection. Worst of all, we may delete an assembly and forget to delete the hooks which are on it. This last may be fixed soon. Removes assembly from superAssembly; deletes the coordinate systems of its children. Copy Parts of the Scene Tree For copying assemblies within the same scene. The copies can refer to the same master object records as other objects in this scene. The prefix rope is prepended to the names of each node as it is copied to distinguish it from the original. CreateClusterAssemblyAtExistingCoordSys is used for filing in, so it doesn't do all we would like. We must wire up parents to the children manually. CopyAssemblyAndSonsRename returns an assembly which is complete and wired up to parent. For copying an assembly from one scene to another. This presents problems since the needed masterobject may not be already present in the target scene. We assume that procedure MergeAssemblyIntoScene has already added the necessary master objects. No prefix is added. We just pray that there are no name conflicts. CreateClusterAssemblyAtExistingCoordSys is used for filing in, so it doesn't do all we would like. We must wire up parents to the children manually. CopyAssemblyAndSonsNoRename returns an assembly which is complete and wired up to parent. Finds an integer such that "." is unique in the scene of assembly for all strings . i.e. Find the highest .num extension in the tree rooted at assembly. oldScene is the scene assembly belongs to. newScene is the scene copy will belong to. parent must be an assembly in the new scene. An attempt to do it right. For assembly and all of its successors, we find an integer a just high enough so that if name.# becomes name.a then all names will be unique. We copy the assembly and its successors and rename them this way. CopyAssemblyAndSonsUniqueNamesAux returns an assembly which is complete and wired up to parent. We assume that none of the mo's in moList is already in scene Makes a list of all of the masterobjects needed. Compares this list to the list of masterobjects available in the new scene, subtracting any that are available. Copies those that are still needed and adds them to the new scene. Assumes that if two master objects have the same name, they are the same. Other List Auxiliaries Removing Duplicates **** Naive algorithm for now. Go through moList. Add anything to uniqueList which it doesn't already have Find all elements of moList1 which are not in moList2 Currently this has O[n2] behavior. Since moList typically has 4 elements, this is alright. Improve if moList grows. Find Scene Entities from their Names Draw Parts of the Scene Tree SVGraphics.Clip[dc, camera]; Draw the current bounding frame if there is one. Draw a background color. this is a trick to make a copy of the list quickly. The list will be modified in place later on. สษ˜Ihead1šœ™Iproc– "Cedar" stylešœ3™3Jšœ ฯmœ1™˜>Jšœ1˜1Jšœ@˜@Jšœ$˜$Jšœ#˜#J˜J™——™™šŸœžœžœžœ#˜eJ™kJšœ˜Jšœ žœ˜šžœ,žœžœž˜BJšœ˜šžœžœ,ž˜6Jšœ žœ˜&——Jšžœ˜J˜J˜—š Ÿœžœžœžœžœ˜Všžœ,žœžœž˜BJš žœ%žœžœžœžœ˜?—Jšžœ˜Jšžœžœ˜Jšœ˜J˜—šŸœžœžœ&žœ,˜wJšœ5™5Jšœžœ˜šžœ-žœžœž˜Cšžœžœ,ž˜6Jšœžœ"˜<——Jšžœ˜J˜J˜—šŸœžœžœžœ˜aJšœu™uJšœžœ˜ šžœ,žœžœž˜BJšœ9˜9—Jšžœ˜J˜———šœ$™$š Ÿœžœžœ.žœžœžœ˜iJšœžœ&˜8Jšžœ/žœžœžœ˜Dšžœžœž˜Jšœžœžœ˜Jšœžœ5˜OJšžœžœžœ˜—Jšœ˜—J˜š Ÿœžœ6žœžœžœ˜pš žœžœžœ&žœžœž˜JJšžœ3žœžœžœ˜H—Jšžœ˜Jšžœžœ˜Jšœ˜——šœ™šŸ œžœžœDžœ˜bšŸ œž œ˜Jšœ™šžœž˜Jšœ.˜.JšœE˜EJšœ4˜4Jšžœžœ˜$—J˜J™0šžœžœžœ˜%Jšœ#˜#Jšœ!˜!Jšœ˜—J˜—Jšœ>˜>Jšœ#˜#Jšœ˜—Jšกœžœžœžœ˜)šŸœžœ7˜OJšœžœ˜Jšœžœ˜ Jšœ˜š žœžœžœžœ'žœžœž˜UJšœ˜Jšœžœ˜ šœC˜CLšœ&žœžœ˜8—šžœžœ˜Lšœ-˜-L˜—Jšžœ˜—J˜—šŸœžœažœ˜ƒJšœžœ˜Jšœ˜Jšœžœ˜ J˜Jšก™Jšœ,˜,Jšœ%˜%š žœžœžœžœ'žœžœž˜UJšœ˜Jšœžœ˜ šœC˜CLšœ&žœžœ˜8—šžœžœ˜Lšœ-˜-L˜——Jšžœ˜J˜—šŸœžœ7˜RJšœžœ˜Jšœ˜Jšœžœ˜ š žœžœžœžœ'žœžœž˜UJšœ˜Jšœžœ˜ šœC˜CLšœ&žœžœ˜8—šžœžœ˜Lšœ-˜-L˜——Jšžœ˜J˜J˜—J˜šŸœžœ7˜EJšžœžœ˜3šžœ˜Lšœ žœ)žœ ˜GLšœ?˜?—Jšœ˜—J˜J˜—šŸœžœžœ˜.šœžœ%žœ˜NN™`—N˜N˜—šŸœžœžœ˜1Nšœžœžœ.˜INšœ$˜$š žœžœžœ1žœžœž˜UNšœ0˜0Jšžœ˜—N˜N˜—Jšžœ˜—…—Wvู