File: SVEditUserImplC.mesa
Last edited by Bier on May 24, 1985 0:31:56 am PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Author: Eric Bier
Contents: All of the procedures called by SVEditTool when menus and buttons are pressed (part 3)
DIRECTORY
BasicObject3d,
ColorMap,
CoordSys,
CSG,
CSGGraphics,
DisplayList3d,
FS,
Graphics,
GraphicsColor,
IO,
Labels,
Matrix3d,
Menus,
Preprocess3d,
Rope,
Scratchpad2dUser,
SV2d,
SV3d,
SVEditUser,
SVEditUserB,
SVError,
SVHalfSpaces,
SVInputMonitor,
SVInterfaceTypes,
SVModelTypes,
SVRayTypes,
SVSceneTypes,
SVPolygon2d,
SVSelections,
SVTransforms,
SVViewerTools,
SVViewerUser,
SweepGeometry,
TiogaMenuOps,
ViewerClasses,
ViewerTools;
SVEditUserImplC:
CEDAR
PROGRAM
IMPORTS ColorMap, CoordSys, DisplayList3d, FS, IO, Labels, Matrix3d, Preprocess3d, Rope, Scratchpad2dUser, SVEditUser, SVError, SVInputMonitor, SVPolygon2d, SVSelections, SVTransforms, SVViewerTools, SVViewerUser, SweepGeometry, TiogaMenuOps, ViewerTools
EXPORTS SVEditUser, SVEditUserB =
BEGIN
Assembly: TYPE = REF AssemblyObj;
AssemblyObj: TYPE = SVSceneTypes.AssemblyObj;
AssemblyList: TYPE = SVSceneTypes.AssemblyList;
Camera: TYPE = SVModelTypes.Camera;
Color: TYPE = GraphicsColor.Color;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
EditToolData: TYPE = SVInterfaceTypes.EditToolData;
LinearMesh: TYPE = SweepGeometry.LinearMesh;
MasterObject: TYPE = SVSceneTypes.MasterObject;
Matrix4by4: TYPE = SV3d.Matrix4by4;
MouseButton: TYPE = Menus.MouseButton;
Path: TYPE = SV2d.Path;
Point3d: TYPE = SV3d.Point3d;
Polygon: TYPE = SV2d.Polygon;
PointSetOp: TYPE = SVRayTypes.PointSetOp;
RevoluteMesh: TYPE = SweepGeometry.RevoluteMesh;
Scene: TYPE = SVSceneTypes.Scene;
ScratchpadData: TYPE = SVInterfaceTypes.ScratchpadData;
ScratchViewerData: TYPE = SVInterfaceTypes.ScratchViewerData;
Selection: TYPE = SVInterfaceTypes.Selection;
SelectionGenerator: TYPE = SVInterfaceTypes.SelectionGenerator;
Shape: TYPE = SVSceneTypes.Shape;
Vector: TYPE = SV3d.Vector;
Viewer: TYPE = ViewerClasses.Viewer;
ViewerCell: TYPE = REF ViewerCellObj;
ViewerCellObj: TYPE = SVInterfaceTypes.ViewerCellObj;
ViewerToolData: TYPE = SVInterfaceTypes.ViewerToolData;
Basic Shapes
HalfSpaceRec: TYPE = SVHalfSpaces.HalfSpaceRec;
SphereRec: TYPE = BasicObject3d.SphereRec;
BlockRec: TYPE = BasicObject3d.BlockRec;
CylinderRec: TYPE = BasicObject3d.CylinderRec;
ConeRec: TYPE = BasicObject3d.ConeRec;
TorusRec: TYPE = BasicObject3d.TorusRec;
GLOBAL VARIABLES
globalOpIndex: NAT ← 1;
globalOpCount: NAT = 3;
globalOpArray: ARRAY[1..globalOpCount] OF Rope.ROPE ←
["union", "intersection", "difference"];
globalIsColor: BOOL ← FALSE;
Text Input Section
PlaneButtonAux:
PRIVATE
PROC [planeName: Rope.
ROPE, editToolData: EditToolData] =
TRUSTED {
Use planeName to coordsys-select. Create a plane-selection of this assembly.
currentScene: Scene ← editToolData.sceneSection.currentScene;
viewerToolData: ViewerToolData ← editToolData.currentViewerToolData;
planeSel: Selection;
planeAssem: Assembly;
success: BOOL;
DrawPlane:
PROC [dc: Graphics.Context, viewerToolData: ViewerToolData] =
TRUSTED {
SVSelections.ComplementSelectionDC[dc, planeSel, viewerToolData];
};
[planeAssem, ----, success] ← SVEditUser.FindAssemblyFromName[planeName, currentScene];
IF NOT success THEN RETURN;
planeSel ← SVSelections.CreatePlaneSelection[planeAssem, viewerToolData];
SVSelections.PushPlane[planeSel];
SVEditUser.PaintSceneAllViewers[DrawPlane, editToolData, currentScene];
};
SourceButtonAux:
PRIVATE
PROC [sourceName: Rope.
ROPE, editToolData: EditToolData] =
TRUSTED {
Use sourceName to coordsys-select. Create a source-selection of this assembly.
currentScene: Scene ← editToolData.sceneSection.currentScene;
viewerToolData: ViewerToolData ← editToolData.currentViewerToolData;
sourceSel: Selection;
source: Assembly;
success: BOOL;
DrawSource:
PROC [dc: Graphics.Context, viewerToolData: ViewerToolData] =
TRUSTED {
SVSelections.ComplementSelectionDC[dc, sourceSel, viewerToolData];
};
IF Rope.Equal[sourceName, "background",
TRUE]
THEN {
source ← NEW[AssemblyObj ← ["background", currentScene.coordSysRoot, NIL, normal, FALSE, NIL, NIL, NIL]];
success ← TRUE;
}
ELSE [source, ----, success] ← SVEditUser.FindAssemblyFromName[sourceName, currentScene];
IF NOT success THEN RETURN;
sourceSel ← SVSelections.CreateCoordSysMovee[source, viewerToolData];
SVSelections.PushMovee[sourceSel];
SVEditUser.PaintSceneAllViewers[DrawSource, editToolData, currentScene];
};
TargetButtonAux:
PRIVATE
PROC [targetName: Rope.
ROPE, editToolData: EditToolData] =
TRUSTED {
Use targetName to coordsys-select. Create a target-selection of this assembly.
currentScene: Scene ← editToolData.sceneSection.currentScene;
viewerToolData: ViewerToolData ← editToolData.currentViewerToolData;
targetSel: Selection;
target: Assembly;
success: BOOL;
DrawTarget:
PROC [dc: Graphics.Context, viewerToolData: ViewerToolData] =
TRUSTED {
SVSelections.ComplementSelectionDC[dc, targetSel, viewerToolData];
};
IF Rope.Equal[targetName, "WORLD",
TRUE]
THEN {
target ← NEW[AssemblyObj ← ["WORLD", currentScene.coordSysRoot, NIL, normal, FALSE, NIL, NIL, NIL]];
success ← TRUE;
}
ELSE [target, ----, success] ← SVEditUser.FindAssemblyFromName[targetName, currentScene];
IF NOT success THEN RETURN;
targetSel ← SVSelections.CreateCoordSysTarget[target, viewerToolData];
SVSelections.PushTarget[targetSel];
SVEditUser.PaintSceneAllViewers[DrawTarget, editToolData, currentScene];
};
ParentButtonAux:
PRIVATE
PROC [parentName: Rope.
ROPE, editToolData: EditToolData] = {
Stuff parentName into the Parent slot.
currentScene: Scene ← editToolData.sceneSection.currentScene;
success: BOOL;
[----, ----, success] ← SVEditUser.FindAssemblyFromName[parentName, currentScene];
IF NOT success THEN RETURN;
ViewerTools.SetContents[editToolData.sceneSection.parent, parentName];
};
SkitterSourceButton:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
Use the text in the skitter area as the name of an assembly to coordsys-select. Create a source-selection of this assembly.
sourceName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
sourceName ← ViewerTools.GetContents[editToolData.sceneSection.current];
SourceButtonAux[sourceName, editToolData];
};
SkitterTargetButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
targetName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
targetName ← ViewerTools.GetContents[editToolData.sceneSection.current];
TargetButtonAux[targetName, editToolData];
};
SkitterParentButton:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
Stuff the text next to Skitter: into the Parent slot.
editToolData: EditToolData ← NARROW[clientData];
parentName: Rope.ROPE;
parentName ← ViewerTools.GetContents[editToolData.sceneSection.current];
ParentButtonAux[parentName, editToolData];
};
Text1PromptButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
editToolData: EditToolData ← NARROW[clientData];
ViewerTools.SetSelection[editToolData.sceneSection.text1];
};
Text1SourceButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
sourceName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
sourceName ← ViewerTools.GetContents[editToolData.sceneSection.text1];
SourceButtonAux[sourceName, editToolData];
};
Text1TargetButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
targetName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
targetName ← ViewerTools.GetContents[editToolData.sceneSection.text1];
TargetButtonAux[targetName, editToolData];
};
Text1ParentButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
Stuff the text next to Text1: into the Parent slot.
editToolData: EditToolData ← NARROW[clientData];
parentName: Rope.ROPE;
parentName ← ViewerTools.GetContents[editToolData.sceneSection.text1];
ParentButtonAux[parentName, editToolData];
};
SelectedTextPlaneButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
planeName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
planeName ← ViewerTools.GetSelectionContents[];
PlaneButtonAux[planeName, editToolData];
};
SelectedTextSourceButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
sourceName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
sourceName ← ViewerTools.GetSelectionContents[];
SourceButtonAux[sourceName, editToolData];
};
SelectedTextTargetButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
targetName: Rope.ROPE;
editToolData: EditToolData ← NARROW[clientData];
targetName ← ViewerTools.GetSelectionContents[];
TargetButtonAux[targetName, editToolData];
};
SelectedTextParentButton:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] = {
Stuff the text of the current selection into the Parent slot.
editToolData: EditToolData ← NARROW[clientData];
parentName: Rope.ROPE;
parentName ← ViewerTools.GetSelectionContents[];
ParentButtonAux[parentName, editToolData];
};
Prompts which cycle through possibilities
SelectOp:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
globalOpIndex ← IF globalOpIndex = globalOpCount THEN 1 ELSE globalOpIndex + 1;
Labels.Set[editToolData.sceneSection.opLabel, globalOpArray[globalOpIndex]];
SELECT globalOpArray[globalOpIndex]
FROM
"union" => editToolData.sceneSection.op ← union;
"intersection" => editToolData.sceneSection.op ← intersection;
"difference" => editToolData.sceneSection.op ← difference;
ENDCASE => ERROR;
};
IsColor:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
truthRope: Rope.ROPE;
globalIsColor ← NOT globalIsColor;
truthRope ← IF globalIsColor THEN "TRUE" ELSE "FALSE";
Labels.Set[editToolData.artworkSection.isColor, truthRope];
};
Command Buttons
First:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
Make sure that the assembly named in "Assembly: " is the first element in the AssemblyList of its super assembly (useful when csg op = "difference" since the result of difference is that of the first element minus all of the rest.
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
assembly, superA: Assembly;
found: BOOL;
namePresent: BOOL ← FALSE;
IF mouseButton = blue
THEN {
SVError.Append["Can't undo First!", TRUE, TRUE];
SVError.Blink[];
RETURN};
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
[assembly, superA, found] ← SVEditUser.FindAssemblyFromName[assembly.name, scene];
IF NOT found THEN RETURN;
DisplayList3d.MoveToFrontOfAssembly[assembly, superA, scene];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
}; -- end of First
DrawCS: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control:
BOOL] =
TRUSTED {
find the assembly mentioned by the edittool and draw its coordinate system.
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
assembly: Assembly;
cs: CoordSystem;
viewerToolData: ViewerToolData;
success: BOOL;
viewerCell: ViewerCell;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
cs ← assembly.coordSys;
[viewerCell, success] ← SVEditUser.FindSceneInAllViewers[scene, editToolData.allViewers];
IF NOT success THEN ERROR;
Draw the first viewer if there is one.
IF viewerCell.viewersOnScene = NIL THEN RETURN;
viewerToolData ← NARROW[viewerCell.viewersOnScene.data];
SVViewerUser.DrawOneCSInViewer[viewerToolData, cs];
draw the rest (remember they are linked in a ring)
IF viewerCell.viewersOnScene.link = NIL THEN RETURN;
FOR list: Viewer ← viewerCell.viewersOnScene.link, list.link
UNTIL list = viewerCell.viewersOnScene
DO
viewerToolData ← NARROW[list.data];
SVViewerUser.DrawOneCSInViewer[viewerToolData, cs];
ENDLOOP;
};
DeleteButton:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
IF mouseButton = blue
THEN {
SVError.Append["Can't undo Delete!", TRUE, TRUE];
SVError.Blink[];
RETURN;
};
DeleteSources[editToolData];
};
DeleteSources:
PUBLIC
PROC [editToolData: EditToolData] =
TRUSTED {
found: BOOL ← TRUE;
success: BOOL;
coin, assembly, superAssembly: Assembly;
scene: Scene;
FOR sel: Selection ← SVSelections.PopMovee[], SVSelections.NextMovee[]
UNTIL sel =
NIL
DO
coin ← sel.coincident;
scene ← sel.viewerToolData.scene;
[assembly, superAssembly, success] ←
SVEditUser.FindAssemblyFromName[coin.name, scene];
IF NOT success THEN LOOP;
success ← DisplayList3d.
DeleteSubassemblyFromAssembly[assembly, superAssembly, scene];
Removes assembly from the assemblyList of superAssembly and deletes the coordinate systems of all of its children.
IF NOT success THEN ERROR;
ENDLOOP;
SVSelections.ClearMoveeStack[editToolData];
-- This should be superfluous
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.
SVSelections.ClearTargetStack[editToolData];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
};
SetOp:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
the name in the assembly slot should refer to an already existing Composite Assembly. Make its CSG pointSetOp equal to the op shown next to "Op:". Error if Assembly is a Primitive Assembly.
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
pointSetOp: PointSetOp ← editToolData.sceneSection.op;
compAssembly: Assembly;
namePresent: BOOL ← FALSE;
IF mouseButton = blue
THEN {
SVError.Append["Can't undo SetOp!", TRUE, TRUE];
SVError.Blink[];
RETURN};
compAssembly ← SVSelections.PopMoveeCoincident[];
IF compAssembly = NIL THEN RETURN;
WITH compAssembly.shape
SELECT
FROM
shape: Shape => {
SVError.Append["Can't add op to primitive assembly ", TRUE];
SVError.Append[compAssembly.name];
SVError.Append[".", FALSE, TRUE];
SVError.Blink[];
RETURN};
al: AssemblyList => al.pointSetOp ← pointSetOp;
ENDCASE => ERROR;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
}; -- end of SetOp
Help:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
fullName: Rope.ROPE;
wdir: Rope.ROPE;
success: BOOL ← TRUE;
wdir ← editToolData.originalWorkingDirectory;
[fullName,,] ← FS.ExpandName["SVHelpFile.tioga", wdir
! FS.Error => IF error.group = user THEN {
success ← FALSE;
CONTINUE;
}
];
IF NOT success THEN RETURN;
[] ← TiogaMenuOps.Open[fullName];
};
SetColorMap:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
Preprocess3d.SetUpColorMap[Rope.Concat[editToolData.originalWorkingDirectory, "Std.Tab"]];
};
BWMap:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
ColorMap.GrayMap[];
ColorMap.SetUpGrayTable[];
};
Restart:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
SVInputMonitor.Restart[];
};
RotX:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
degrees: REAL ← SVViewerTools.GetReal[editToolData.transformSection.degrees, 0];
targetCS: CoordSystem;
g: SelectionGenerator;
selectionsExist: BOOL;
targetCSspecified: BOOL ← TRUE;
IF mouseButton = blue THEN degrees ← -degrees;
targetCS ← SVSelections.TopTargetCoinCoordSys[];
IF targetCS = NIL THEN targetCSspecified ← FALSE;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
IF NOT targetCSspecified THEN targetCS ← thisSource.coordSys;
SVTransforms.XRotate[thisSource.coordSys, targetCS, degrees];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
RotY:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
degrees: REAL ← SVViewerTools.GetReal[editToolData.transformSection.degrees, 0];
targetCS: CoordSystem;
g: SelectionGenerator;
selectionsExist: BOOL;
targetCSspecified: BOOL ← TRUE;
IF mouseButton = blue THEN degrees ← -degrees;
targetCS ← SVSelections.TopTargetCoinCoordSys[];
IF targetCS = NIL THEN targetCSspecified ← FALSE;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
IF NOT targetCSspecified THEN targetCS ← thisSource.coordSys;
SVTransforms.YRotate[thisSource.coordSys, targetCS, degrees];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
RotZ:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
degrees: REAL ← SVViewerTools.GetReal[editToolData.transformSection.degrees, 0];
targetCS: CoordSystem;
g: SelectionGenerator;
selectionsExist: BOOL;
targetCSspecified: BOOL ← TRUE;
IF mouseButton = blue THEN degrees ← -degrees;
targetCS ← SVSelections.TopTargetCoinCoordSys[];
IF targetCS = NIL THEN targetCSspecified ← FALSE;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
IF NOT targetCSspecified THEN targetCS ← thisSource.coordSys;
SVTransforms.ZRotate[thisSource.coordSys, targetCS, degrees];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
Trans:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
x, y, z: REAL;
targetCS: CoordSystem;
g: SelectionGenerator;
selectionsExist: BOOL;
targetCSspecified: BOOL ← TRUE;
[x, y, z] ← SVViewerTools.GetThreeReals[editToolData.transformSection.transXYZ];
IF mouseButton = blue THEN {x ← -x; y ← -y; z ← -z};
targetCS ← SVSelections.TopTargetCoinCoordSys[];
IF targetCS = NIL THEN targetCSspecified ← FALSE;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
IF NOT targetCSspecified THEN targetCS ← thisSource.coordSys;
SVTransforms.Translate[thisSource.coordSys, targetCS, x, y, z];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
ScalePrimitive:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
errorRope: Rope.ROPE;
g: SelectionGenerator;
selectionsExist: BOOL;
x, y, z: REAL;
[x, y, z] ← SVViewerTools.GetThreeReals[editToolData.transformSection.scaleXYZ];
IF x = 0
OR y = 0
OR z = 0
THEN {
SVError.Append["Can't scale by 0", TRUE, TRUE];
SVError.Blink[];
RETURN};
IF mouseButton = blue THEN {x ← 1/x; y ← 1/y; z ← 1/z};
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
IF
NOT
ISTYPE[thisSource.shape, Shape]
THEN {
errorRope ← IO.PutFR["Can't ScalePrimitive! a cluster assembly [%g]",[rope[thisSource.name]]];
SVError.Append[errorRope, TRUE, TRUE];
SVError.Blink[];
LOOP;
};
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
SVTransforms.ScalePrimitive[thisSource, x, y, z];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
EvenScale: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
targetCS: CoordSystem;
g: SelectionGenerator;
selectionsExist: BOOL;
scalar: REAL;
targetCSspecified: BOOL ← TRUE;
scalar ← SVViewerTools.GetReal[editToolData.transformSection.scalar, 0];
IF scalar = 0
THEN {
SVError.Append["Can't scale by 0", TRUE, TRUE];
SVError.Blink[];
RETURN};
IF mouseButton = blue THEN {scalar ← 1/scalar};
targetCS ← SVSelections.TopTargetCoinCoordSys[];
IF targetCS = NIL THEN targetCSspecified ← FALSE;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR thisSource: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g]
UNTIL thisSource =
NIL
DO
IF NOT targetCSspecified THEN targetCS ← thisSource.coordSys;
IF thisSource.coordSys.parent #
NIL
THEN {
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
SVTransforms.ScaleEven[thisSource, targetCS, scalar];
SVEditUser.PaintAssemblyAllViewers[SVViewerUser.DrawAssemblyXOR, editToolData, scene, thisSource];
}
ELSE {
SVTransforms.ScaleEven[thisSource, targetCS, scalar];
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
};
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
Edit:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
Find out if the current object is a sweep shape. If so, extract its path and feed to the scratchpad. Otherwise complain in SVError.
editToolData: EditToolData ← NARROW[clientData];
scratchpad: Viewer ← editToolData.scratchpad;
scratchpadData: ScratchpadData ← NARROW[scratchpad.data];
scratchViewerData: ScratchViewerData ← scratchpadData.scratchViewerData;
scene: Scene ← editToolData.sceneSection.currentScene;
mo: MasterObject;
shape: Shape;
scalars: Vector;
path: Path;
poly: Polygon;
moClassName: Rope.ROPE;
assembly: Assembly;
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
IF
NOT
ISTYPE[assembly.shape, Shape]
THEN {
SVError.Append["Cannot Edit Composite Assembly", TRUE, TRUE];
SVError.Blink[];
RETURN};
shape ← NARROW[assembly.shape];
mo ← shape.mo;
scalars ← CoordSys.GetScalars[shape.coordSys];
moClassName ← mo.class.name;
SELECT
TRUE
FROM
Rope.Equal[moClassName, "revoluteSweep"] => {
path ← SweepGeometry.GetRevolutePath[NARROW[mo.lineBody, RevoluteMesh]];
Scratchpad2dUser.Edit[path, revo, scratchViewerData];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1], scalars[2], scalars[3]];
};
Rope.Equal[moClassName, "linearSweep"] => {
linMesh: LinearMesh ← NARROW[mo.lineBody];
depth: REAL;
poly ← SweepGeometry.GetLinearPoly[linMesh];
path ← SVPolygon2d.PolygonToPath[poly];
Scratchpad2dUser.Edit[path, lin, scratchViewerData];
depth ← linMesh.array[1][1][3]*2;
SVViewerTools.SetReal[editToolData.linSection.depth, depth];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1], scalars[2], scalars[3]];
};
Rope.Equal[moClassName, "sphere"] => {
A sphere may actually be an oblate spheroid if the scalars are uneven. If they are even, I will will stuff the radius. Otherwise, I will set radius = 1 and stuff the scalars in the scaling part of the transform section. **** This should also stuff the name of the sphere's parent in "With Respect To:".
radius: REAL;
sphereRec: SphereRec ← NARROW[mo.mainBody];
radius ← sphereRec.radius;
IF scalars[1] = scalars[2] AND scalars[2] = scalars[3]
THEN {
-- stuff the radius and 1's into the scalars
SVViewerTools.SetReal[editToolData.sphereSection.radius, scalars[1]*radius];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, 1,1,1];
}
ELSE {
-- radius = 1; write scalars
SVViewerTools.SetReal[editToolData.sphereSection.radius, 1];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1]*radius, scalars[2]*radius, scalars[3]*radius];
};
};
Rope.Equal[moClassName, "block"] => {
bx, by, bz: REAL;
blockRec: BlockRec ← NARROW[mo.mainBody];
bx ← blockRec.x; by ← blockRec.y; bz ← blockRec.z;-- size of the primitive object
since the system doesn't currently allow shear in primitives, this is easy
SVViewerTools.SetThreeReals[editToolData.blockSection.xyz, bx*scalars[1], by*scalars[2], bz*scalars[3]];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, 1,1,1];
};
Rope.Equal[moClassName, "cylinder"] => {
if sx = sz then stuff radius and height. Otherwise using scaling blank to list all scalars
radius, height: REAL;
cylinderRec: CylinderRec ← NARROW[mo.mainBody];
radius ← cylinderRec.radius;
height ← cylinderRec.height;-- dimensions of the master object
IF scalars[1] = scalars[3]
THEN {
SVViewerTools.SetReal[editToolData.cylinderSection.radius, radius*scalars[1]];
SVViewerTools.SetReal[editToolData.cylinderSection.height, height*scalars[2]];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, 1,1,1];
}
ELSE {
SVViewerTools.SetReal[editToolData.cylinderSection.radius, 1];
SVViewerTools.SetReal[editToolData.cylinderSection.height, 1];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1]*radius, scalars[2]*height, scalars[3]*radius];
};
};
Rope.Equal[moClassName, "cone"] => {
similar to cylinder
radius, height: REAL;
coneRec: ConeRec ← NARROW[mo.mainBody];
radius ← coneRec.radius;
height ← coneRec.height;-- dimensions of the master object
IF scalars[1] = scalars[3]
THEN {
SVViewerTools.SetReal[editToolData.coneSection.radius, radius*scalars[1]];
SVViewerTools.SetReal[editToolData.coneSection.height, height*scalars[2]];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, 1,1,1];
}
ELSE {
SVViewerTools.SetReal[editToolData.coneSection.radius, 1];
SVViewerTools.SetReal[editToolData.coneSection.height, 1];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1]*radius, scalars[2]*height, scalars[3]*radius];
};
};
Rope.Equal[moClassName, "torus"] => {
in the case of the torus, we write the current scalars AND take the radius data directly from the torus record (master object)
bigRadius, sectionRadius: REAL;
torusRec: TorusRec ← NARROW[mo.mainBody];
bigRadius ← torusRec.bigRadius;
sectionRadius ← torusRec.sectionRadius;
SVViewerTools.SetReal[editToolData.torusSection.bigRadius, bigRadius];
SVViewerTools.SetReal[editToolData.torusSection.sectionRadius, sectionRadius];
SVViewerTools.SetThreeReals[editToolData.transformSection.scaleXYZ, scalars[1], scalars[2], scalars[3]];
};
ENDCASE => {
SVError.Append[Rope.Concat["I don't know how to edit ", moClassName], TRUE, TRUE];
SVError.Blink[];
};
}; -- end of Edit
AddComposite:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
Use the name in the assembly slot to name this new composite. It is a subassembly of the assembly named in "WithRespectTo"; It has no sub-assemblies to begin with. Add * will now add objects to the assembly named in "WithRespectTo".
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
pointSetOp: PointSetOp ← editToolData.sceneSection.op;
compName: Rope.ROPE;
newAssembly, superAssembly: Assembly;
success: BOOL;
addSucceeds: BOOL ← TRUE;
compName ← ViewerTools.GetContents[editToolData.sceneSection.new];
[superAssembly, success] ← SVEditUser.GetParent[editToolData];
IF NOT success THEN RETURN;
[newAssembly, addSucceeds] ← DisplayList3d.CreateAndAddClusterAssembly[compName, pointSetOp, scene, superAssembly, Matrix3d.Identity[]];
IF NOT addSucceeds THEN RETURN;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
}; -- end of AddComposite
SetAmbient:
PUBLIC
PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
color: Color;
success: BOOLEAN;
[color, success] ← SVViewerTools.GetColor[editToolData.lightSection.color];
IF NOT success THEN RETURN;
IF NOT scene.lightSources.first.type = ambient THEN ERROR;
scene.lightSources.first.color ← color;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
};
GetAmbient:
PUBLIC PROC [parent:
REF
ANY, clientData:
REF
ANY, mouseButton: MouseButton, shift, control:
BOOL] =
TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
color: Color;
IF NOT scene.lightSources.first.type = ambient THEN ERROR;
color ← scene.lightSources.first.color;
SVViewerTools.SetColor[editToolData.lightSection.color, color];
};
END.