File: SVEditUserImplB.mesa
Created in October 1982
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Bier on May 25, 1987 5:15:17 pm PDT
Contents: All of the procedures called by SVEditTool when menus and buttons are pressed
DIRECTORY
CoordSys, Feedback, Imager, IO, Matrix3d, Menus, Rope, SVScratchpad, SV2d, SV3d, SVAssembly, SVEditUser, SVHalfSpaces, SVInterfaceTypes, SVMasterObject, SVMasterObjectTypes, SVModelTypes, SVPolygon2d, SVScene, SVSceneTypes, SVSelections, SVViewersOnScene, SVViewerTools, SweepGeometry, ViewerClasses, ViewerTools;
SVEditUserImplB:
CEDAR
PROGRAM
IMPORTS CoordSys, Feedback, IO, Matrix3d, Rope, SVScratchpad, SVAssembly, SVEditUser, SVMasterObject, SVPolygon2d, SVScene, SVSelections, SVViewersOnScene, SVViewerTools, SweepGeometry, ViewerTools
EXPORTS SVEditUser =
BEGIN
Slice: TYPE = SVSceneTypes.Slice;
SliceList: TYPE = SVSceneTypes.SliceList;
AssemblyGenerator: TYPE = SVScene.AssemblyGenerator;
Color: TYPE = Imager.Color;
EditToolData: TYPE = SVInterfaceTypes.EditToolData;
LightSource: TYPE = SVModelTypes.LightSource;
LinearMesh: TYPE = SweepGeometry.LinearMesh;
MasterObject: TYPE = SVSceneTypes.MasterObject;
Matrix4by4: TYPE = SV3d.Matrix4by4;
MouseButton: TYPE = Menus.MouseButton;
NameAlreadyPresent: SIGNAL = SVScene.NameAlreadyPresent;
Point3d: TYPE = SV3d.Point3d;
Polygon: TYPE = SV2d.Polygon;
RevoluteMesh: TYPE = SweepGeometry.RevoluteMesh;
Path: TYPE = SV2d.Path;
Scene: TYPE = SVSceneTypes.Scene;
SelectionGenerator: TYPE = SVInterfaceTypes.SelectionGenerator;
Shape: TYPE = SVSceneTypes.Shape;
Vector3d: TYPE = SV3d.Vector3d;
Viewer: TYPE = ViewerClasses.Viewer;
ViewerCell: TYPE = SVInterfaceTypes.ViewerCell;
SVData: TYPE = SVInterfaceTypes.SVData;
Basic Shapes
HalfSpaceRec: TYPE = SVHalfSpaces.HalfSpaceRec;
SphereRec: TYPE = SVMasterObjectTypes.SphereRec;
BlockData: TYPE = SVMasterObjectTypes.BlockData;
CylinderRec: TYPE = SVMasterObjectTypes.CylinderRec;
ConeRec: TYPE = SVMasterObjectTypes.ConeRec;
TorusRec: TYPE = SVMasterObjectTypes.TorusRec;
AddHalfSpace:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
If mouseButton = red or yellow, then make sure this assembly name is unique and add a new sphere by this name. if mouseButton = blue, then find the old assembly by this name. Make sure it is a primitive assembly. Let it refer to halfSpace as its master object and use the new scalar values.
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
errorRope: Rope.ROPE;
addSucceeds: BOOL ← TRUE;
halfSpaceName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
newAssembly, superAssembly, assembly: Slice;
success: BOOL;
arg: ATOM ← NARROW[event.rest.first];
halfSpaceMO: MasterObject;
moFound: BOOL ← TRUE;
halfSpaceRec: HalfSpaceRec;
[halfSpaceMO, moFound] ← SVScene.FindObjectFromName["halfSpace", scene];
IF NOT moFound THEN ERROR;
halfSpaceRec ← NARROW[halfSpaceMO.mainBody];
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
[newAssembly, ----, addSucceeds] ← SVAssembly.CreatePrimitive[halfSpaceName, "halfSpace", scene];
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, [1, 1, 1], superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.SceneNewVersion[editToolData.currentSVData];
SVViewersOnScene.PaintSceneAllViewers[$ObjectAdded, editToolData, scene];
}
ELSE
IF arg = $Replace
THEN {
mo, oldMo: MasterObject;
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[mo, moFound] ← SVScene.FindObjectFromName["halfSpace", scene];
IF NOT moFound THEN ERROR;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't replace cluster assembly [%g] with a halfSpace.",[rope[assembly.name]]];
Feedback.AppendRaw[$Solidviews, errorRope, oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews] };
CoordSys.SetScalars[shape.coordSys, [1, 1, 1]];
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, edited: TRUE];
};
}; -- end of AddHalfSpace
AddSphere:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
If mouseButton = red or yellow, then make sure this assembly name is unique and add a new sphere by this name. if mouseButton = blue, then find the old assembly by this name. Make sure it is a primitive assembly. Let it refer to sphere as its master object and use the new scalar values.
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
errorRope: Rope.ROPE;
addSucceeds: BOOL ← TRUE;
sphereName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
radius: REAL ← SVViewerTools.GetReal[editToolData.sphereSection.radius, 200];
newAssembly, superAssembly, assembly: Slice;
success: BOOL;
arg: ATOM ← NARROW[event.rest.first];
sphereMO: MasterObject;
moFound: BOOL ← TRUE;
sphereRec: SphereRec;
moRadius: REAL;
[sphereMO, moFound] ← SVScene.FindObjectFromName["sphere", scene];
IF NOT moFound THEN ERROR;
sphereRec ← NARROW[sphereMO.mainBody];
moRadius ← sphereRec.radius;
radius ← radius/moRadius;
We need to know the size of the master object in order to know what scalars to use to achieve a sphere of the size requested by the user.
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
[newAssembly, ----, addSucceeds] ← SVAssembly.CreatePrimitive[sphereName, "sphere", scene];
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, [radius, radius, radius], superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectAdded, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
}
ELSE
IF arg = $Replace
THEN {
mo, oldMo: MasterObject;
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[mo, moFound] ← SVScene.FindObjectFromName["sphere", scene];
IF NOT moFound THEN ERROR;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't substitue a sphere for a cluster assembly [%g]",[rope[assembly.name]]];
Feedback.AppendRaw[$Solidviews, errorRope, oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews] };
CoordSys.SetScalars[shape.coordSys, [radius, radius, radius]];
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
};
}; -- end of AddSphere
AddBlock:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
x, y, z: REAL;
blockName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
arg: ATOM ← NARROW[event.rest.first];
scalars: Vector3d;
blockMO: MasterObject;
blockMO ← SVMasterObject.BlockMakeMasterObject[blockName];
[x, y, z] ← SVViewerTools.GetThreeReals[editToolData.blockSection.xyz];
scalars ← [x/2.0, y/2.0, z/2.0];
AddUnsharedAux[editToolData, blockMO, blockName, arg, "Block", scalars];
};
AddCyl:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
errorRope: Rope.ROPE;
addSucceeds: BOOL ← TRUE;
cylName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
radius: REAL ← SVViewerTools.GetReal[editToolData.cylinderSection.radius, 200];
height: REAL ← SVViewerTools.GetReal[editToolData.cylinderSection.height, 300];
newAssembly, superAssembly, assembly: Slice;
success: BOOL;
arg: ATOM ← NARROW[event.rest.first];
cylMO: MasterObject;
moFound: BOOL ← TRUE;
cylinderRec: CylinderRec;
[cylMO, moFound] ← SVScene.FindObjectFromName["cylinder", scene];
IF NOT moFound THEN ERROR;
cylinderRec ← NARROW[cylMO.mainBody];
We need to know the size of the master object in order to know what scalars to use to achieve a cylinder of the size requested by the user.
radius ← radius/cylinderRec.radius; height ← height/cylinderRec.height;
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
[newAssembly, ----, addSucceeds] ← SVAssembly.CreatePrimitive[cylName, "cylinder", scene];
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, [radius, height, radius], superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectAdded, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
}
ELSE
IF arg = $Replace
THEN {
mo, oldMo: MasterObject;
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[mo, moFound] ← SVScene.FindObjectFromName["cylinder", scene];
IF NOT moFound THEN ERROR;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't substitute a cylinder for a cluster assembly [%g]",[rope[assembly.name]]];
Feedback.AppendRaw[$Solidviews, errorRope, oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews] };
CoordSys.SetScalars[shape.coordSys, [radius, height, radius]];
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
};
}; -- end of AddCyl
AddCone:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
coneName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
radius: REAL ← SVViewerTools.GetReal[editToolData.coneSection.radius, 200];
height: REAL ← SVViewerTools.GetReal[editToolData.coneSection.height, 300];
arg: ATOM ← NARROW[event.rest.first];
scalars: Vector3d;
addSucceeds: BOOL ← TRUE;
errorRope: Rope.ROPE;
newAssembly, superAssembly, assembly: Slice;
success: BOOL;
scene: Scene ← editToolData.sceneSection.currentScene;
coneMO: MasterObject;
moFound: BOOL ← TRUE;
coneRec: ConeRec;
[coneMO, moFound] ← SVScene.FindObjectFromName["cone", scene];
IF NOT moFound THEN ERROR;
coneRec ← NARROW[coneMO.mainBody];
radius ← radius/coneRec.radius; height ← height/coneRec.height;
scalars ← [radius, height, radius];
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
[newAssembly, ----, addSucceeds] ← SVAssembly.CreatePrimitive[coneName, "cone", scene];
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, scalars, superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectAdded, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
}
ELSE
IF arg = $Replace
THEN {
mo, oldMo: MasterObject;
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[mo, moFound] ← SVScene.FindObjectFromName["cone", scene];
IF NOT moFound THEN ERROR;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't substitue a cone for a cluster assembly [%g]",[rope[assembly.name]]];
Feedback.AppendRaw[$Solidviews, errorRope, oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews] };
CoordSys.SetScalars[shape.coordSys, scalars];
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
};
}; -- end of AddCone
AddTorus:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
mo: MasterObject;
torusName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
bigRadius, sectionRadius: REAL;
arg: ATOM ← NARROW[event.rest.first];
bigRadius ← SVViewerTools.GetReal[editToolData.torusSection.bigRadius, 100];
sectionRadius ← SVViewerTools.GetReal[editToolData.torusSection.sectionRadius, 100];
mo ← SVMasterObject.TorusMakeMasterObject[torusName, bigRadius, sectionRadius];
AddUnsharedAux[editToolData, mo, torusName, arg, "Torus"];
}; -- end of AddTorus
AddRevo:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scratchpad: Viewer ← editToolData.scratchpad;
linesOfLongitude: NAT ← 10;
scene: Scene ← editToolData.sceneSection.currentScene;
errorRope: Rope.ROPE;
addSucceeds: BOOL ← TRUE;
revName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
mo, oldMo: MasterObject;
path: Path;
newAssembly, superAssembly, assembly: Slice;
success: BOOL;
arg: ATOM ← NARROW[event.rest.first];
Create a new revolute master object.
path ← SVScratchpad.GetPath[scratchpad];
IF path.len = 0
THEN {
Feedback.AppendRaw[$Solidviews, "There is no 2d shape in the scratchpad", oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
mo ← SVMasterObject.RevoSweepMakeMasterObject[revName, path, linesOfLongitude];
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
SVScene.
AddMasterObjectToScene[mo, scene
! NameAlreadyPresent => {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Revolute sweep name ", mo.name, " is already registered. Try another."], oneLiner];
Feedback.BlinkRaw[$Solidviews]; addSucceeds ← FALSE; CONTINUE}
];
IF NOT addSucceeds THEN RETURN;
[newAssembly, ----, addSucceeds] ← SVAssembly.CreatePrimitive[revName, revName, scene];
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, [1,1,1], superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectAdded, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
}
ELSE
IF arg = $Replace
THEN {
oldMoWasRevo, moFound: BOOL ← TRUE;
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't substitue a revolute sweep for a cluster assembly [%g]",[rope[assembly.name]]];
Feedback.AppendRaw[$Solidviews, errorRope, oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN};
mo.name ← SVScene.UniqueObjectNameFrom[mo.name, scene];
SVScene.
AddMasterObjectToScene[mo, scene];
mo.name should be unique, so NameAlreadyPresent would be a surprise.
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
oldMoWasRevo ← Rope.Equal[oldMo.class.name, "revoluteSweep", TRUE];
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews] };
If we are replacing an old revolute sweep with a new one, then leave the scalars as they are. Otherwise, set them all to unity.
IF NOT oldMoWasRevo THEN CoordSys.SetScalars[shape.coordSys, [1, 1, 1]];
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
};
}; -- end of AddRevolute
AddLinear:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scratchpad: Viewer ← editToolData.scratchpad;
sweepOK: BOOL ← TRUE;
frontDepth, backDepth: REAL;
lengthRope: Rope.ROPE;
mo: MasterObject;
linMesh: LinearMesh;
path: Path;
poly: Polygon;
arg: ATOM ← NARROW[event.rest.first];
linName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
lengthRope ← ViewerTools.GetContents[editToolData.linSection.depth];
frontDepth ← SVViewerTools.GetReal[editToolData.linSection.depth, 100]/2.0;
backDepth ← -frontDepth;
Create a new linear master object
path ← SVScratchpad.GetPath[scratchpad];
poly ← SVPolygon2d.PathToPolygon[path];
linMesh ← SweepGeometry.LinearSweep[poly, frontDepth, backDepth
! SweepGeometry.TooFewPointsForShadedSweep => {
Feedback.AppendRaw[$Solidviews, "Too few points for a linear sweep.", oneLiner];
Feedback.BlinkRaw[$Solidviews];
sweepOK ← FALSE;
CONTINUE;
};
];
IF NOT sweepOK THEN RETURN;
mo ← SVMasterObject.LinSweepMakeMasterObject[linName, linMesh];
AddUnsharedAux[editToolData, mo, linName, arg, "Linear sweep", [1,1,1], "linearSweep"];
}; -- end of AddLinear
AddUnsharedAux:
PROC [editToolData: EditToolData, mo: MasterObject, newName: Rope.
ROPE, arg:
ATOM, objType: Rope.
ROPE, scalars: Vector3d ← [1,1,1], leaveScalarsClass: Rope.
ROPE ←
NIL] = {
newAssembly, superAssembly, assembly: Slice;
oldMo: MasterObject;
moFound: BOOL ← TRUE;
scene: Scene ← editToolData.sceneSection.currentScene;
addSucceeds: BOOL ← TRUE;
success: BOOL;
IF arg = $Add
THEN {
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
SVScene.
AddMasterObjectToScene[mo, scene
! NameAlreadyPresent => {
Feedback.PutFRaw[$Solidviews, oneLiner, "%g name %g is already registered. Try another.", [rope[objType]], [rope[mo.name]]];
Feedback.BlinkRaw[$Solidviews]; addSucceeds ← FALSE; CONTINUE}
];
IF NOT addSucceeds THEN RETURN;
[newAssembly, moFound, addSucceeds] ← SVAssembly.CreatePrimitive[newName, newName, scene];
IF NOT moFound THEN ERROR;
IF NOT addSucceeds THEN RETURN;
addSucceeds ← SVAssembly.AddPrimitive[newAssembly, scalars, superAssembly, Matrix3d.Identity[], scene];
IF NOT addSucceeds THEN RETURN;
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectAdded, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
}
ELSE
IF arg = $Replace
THEN {
shape: Shape;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
Feedback.PutFRaw[$Solidviews, oneLiner, "Can't substitute a %g for a cluster assembly (%g)", [rope[objType]], [rope[assembly.name]] ];
Feedback.BlinkRaw[$Solidviews];
RETURN};
mo.name ← SVScene.UniqueObjectNameFrom[mo.name, scene];
SVScene.AddMasterObjectToScene[mo, scene];
shape ← NARROW[assembly.shape];
oldMo ← shape.mo;
IF NOT (leaveScalarsClass # NIL AND Rope.Equal[oldMo.class.name, leaveScalarsClass, TRUE]) THEN CoordSys.SetScalars[shape.coordSys, scalars];
shape.mo ← mo;
IF NOT SVScene.MasterObjectIsUsed[oldMo, scene] THEN moFound ← SVScene.DeleteMasterObjectNamed[oldMo.name, scene];
IF
NOT moFound
THEN {
Feedback.AppendRaw[$Solidviews, Rope.Cat["Old master object ", oldMo.name, "mysteriously disappeared. Save your work"], oneLiner];
Feedback.BlinkRaw[$Solidviews]
};
SVViewersOnScene.PaintSceneAllViewers[paintAction: $ObjectChangedBoundBoxProvided, editToolData: editToolData, scene: scene, remake: sceneBag, backgndOK: FALSE, edited: TRUE, okToClearFeedback: TRUE];
};
};
Copy:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
parentToBe, assembly, assemblyCopy: Slice;
found, success: BOOL;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[parentToBe, found] ← SVEditUser.GetParent[editToolData];
IF NOT found THEN RETURN;
success ← TRUE;
assemblyCopy ← SVScene.CopyAssemblyAndSonsUniqueNames[assembly, scene, scene, parentToBe, editToolData.currentSVData.feedback
!SVScene.NameAlreadyPresent => {success ← FALSE; CONTINUE}];
IF
NOT success
THEN {
Feedback.AppendRaw[$Solidviews, "Some name in assembly is already present", oneLiner];
Feedback.BlinkRaw[$Solidviews];
RETURN;
};
SVViewersOnScene.SceneNewVersion[editToolData.currentSVData];
Since the copy is on top of the original, there is no need to redraw.
}; -- end of Copy
Rename:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
assembly: Slice;
oldName: Rope.ROPE;
newName: Rope.ROPE ← ViewerTools.GetContents[editToolData.sceneSection.new];
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
oldName ← assembly.name;
SVScene.RenameAssembly[assembly, newName, scene];
Feedback.AppendRaw[$Solidviews, Rope.Cat["Slice ", oldName, " renamed to ", newName, "."], oneLiner];
SVViewersOnScene.SceneNewVersion[editToolData.currentSVData];
};
NewParent:
PUBLIC
PROC [event:
LIST
OF
REF
ANY, svData: SVData] = {
editToolData: EditToolData ← svData.editToolData;
scene: Scene ← editToolData.sceneSection.currentScene;
parentToBe: Slice;
found, parentIsPrimitive: BOOL;
g: SelectionGenerator;
selectionsExist: BOOL;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
[parentToBe, found] ← SVEditUser.GetParent[editToolData];
IF NOT found THEN RETURN;
FOR assembly: Slice ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL assembly =
NIL
DO
SVScene.MoveSubassembly[assembly, parentToBe, scene
! SVAssembly.AttemptToAddSubassemblyToPrimitive =>
{parentIsPrimitive ← TRUE; CONTINUE}];
IF parentIsPrimitive THEN GOTO PrimitiveParent;
REPEAT
PrimitiveParent => {
Feedback.AppendRaw[$Solidviews, "A primitive can't be a parent.", oneLiner];
Feedback.BlinkRaw[$Solidviews];
};
ENDLOOP;
SVViewersOnScene.SceneNewVersion[editToolData.currentSVData];
};
END.