File: SVEditUserImplE.mesa
Author: Eric Bier on June 14, 1985 5:49:18 pm PDT
Last edited by Bier on September 7, 1985 5:26:48 pm PDT
Copyright © 1985 by Xerox Corporation. All rights reserved.
Contents: All of the procedures called by SVEditTool when menus and buttons are pressed (part 5)
DIRECTORY
BasicObject3d,
CoordSys,
CSG,
CSGGraphics,
DisplayList3d,
FileNames,
FS,
Imager,
IO,
Labels,
Matrix3d,
Menus,
Preprocess3d,
Rope,
Scratchpad2dUser,
SV2d,
SV3d,
SVArtwork,
SVArtworkUser,
SVEditUser,
SVEditUserB,
SVError,
SVHalfSpaces,
SVInputMonitor,
SVInterfaceTypes,
SVMappings,
SVMatrix2d,
SVModelTypes,
SVRayTypes,
SVSceneTypes,
SVPolygon2d,
SVSelections,
SVTransforms,
SVViewerTools,
SVViewerUser,
SweepGeometry,
TiogaMenuOps,
ViewerClasses,
ViewerTools;
SVEditUserImplE: CEDAR PROGRAM
IMPORTS DisplayList3d, FileNames, FS, Labels, Rope, SVArtwork, SVArtworkUser, SVEditUser, SVError, SVMappings, SVMatrix2d, SVSelections, SVViewerTools, SVViewerUser, ViewerTools
EXPORTS SVEditUser, SVEditUserB =
BEGIN
IMPORTED TYPES
Artwork: TYPE = SVModelTypes.Artwork;
Assembly: TYPE = SVSceneTypes.Assembly;
Camera: TYPE = SVModelTypes.Camera;
Color: TYPE = Imager.Color;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
EditToolData: TYPE = SVEditUser.EditToolData;
Material: TYPE = SVModelTypes.Material;
Matrix3by3: TYPE = SV2d.Matrix3by3;
MouseButton: TYPE = Menus.MouseButton;
OMap: TYPE = SVModelTypes.OMap;
Scene: TYPE = SVSceneTypes.Scene;
Selection: TYPE = SVInterfaceTypes.Selection;
SelectionGenerator: TYPE = SVInterfaceTypes.SelectionGenerator;
SpaceFunction: TYPE = SVModelTypes.SpaceFunction;
SMap: TYPE = SVModelTypes.SMap;
Tube: TYPE = SVModelTypes.Tube;
Box: TYPE = SVModelTypes.Box;
Viewer: TYPE = ViewerClasses.Viewer;
GLOBAL VARIABLES
globalBoxOMapIndex: PUBLIC NAT ← 1;
globalBoxOMapCount: NAT = 2;
globalBoxOMapArray: PUBLIC ARRAY[1..globalBoxOMapCount] OF Rope.ROPE
["Orthogonal", "Radial"];
BoxOCycle: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
globalBoxOMapIndex ← IF globalBoxOMapIndex = globalBoxOMapCount THEN 1 ELSE globalBoxOMapIndex + 1;
Labels.Set[editToolData.artworkSection.oMapLabel, globalBoxOMapArray[globalBoxOMapIndex]];
};
GetSimpleArtworkParameters: PRIVATE PROC [editToolData: EditToolData, scene: Scene] RETURNS [color: Color, success: BOOL, material: Material] = TRUSTED {
materialName: Rope.ROPE ← SVEditUser.globalMatArray[editToolData.artworkSection.materialValue];
partialSuccess: BOOL;
success ← TRUE;
[color, partialSuccess] ← SVViewerTools.GetColor[editToolData.artworkSection.rgb];
IF NOT partialSuccess THEN {
successFALSE;
SVError.Append["Can't read your rgb color.", TRUE, TRUE];
SVError.Blink[];
};
[material, partialSuccess] ← SVArtwork.RopeToMaterial[materialName];
IF NOT partialSuccess THEN {
successFALSE;
SVError.Append[Rope.Cat["Material ", materialName," not known."], TRUE, TRUE];
SVError.Blink[];
RETURN;
};
};
Set3DArtwork: 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;
threeDArtwork: Artwork;
material: Material;
success: BOOL;
x, y, z: REAL;
spaceFunction: SpaceFunction;
g: SelectionGenerator;
selectionsExist: BOOL;
IF mouseButton = blue THEN {
SVError.Append["Can't undo Set3DArtwork.", TRUE, TRUE]; SVError.Blink[]; RETURN};
[color, success, material] ← GetSimpleArtworkParameters[editToolData, scene];
IF NOT success THEN RETURN;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR assembly: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g] UNTIL assembly = NIL DO
IF Rope.Equal[assembly.name, "background", FALSE] THEN {
SVError.Append["Can't apply 3DArtwork to the background ... ignored",TRUE,TRUE];
SVError.Blink[];
LOOP;
}; -- a special case to set background color
[x, y, z] ← SVViewerTools.GetThreeReals[editToolData.artworkSection.boxXYZ];
spaceFunction ← SVMappings.CreateFunction[[x, y, z]];
threeDArtwork ← SVArtwork.Create3DArtwork[assembly.coordSys, material, spaceFunction];
DisplayList3d.SetArtworkAssembly[assembly, threeDArtwork, scene];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
};
GetFullPicname: PRIVATE PROC [editToolData: EditToolData] RETURNS [fullName: Rope.ROPE, success: BOOL] = {
wdir: Rope.ROPE ← editToolData.originalWorkingDirectory;
picName: Rope.ROPE ← ViewerTools.GetContents[editToolData.artworkSection.picName];
success ← TRUE;
[fullName,,] ← FS.ExpandName[picName, wdir
! FS.Error => IF error.group = user THEN {
success ← FALSE;
SVError.Append[error.explanation, TRUE, TRUE];
SVError.Blink[];
CONTINUE;
}
];
};
SetColorArtwork: 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;
colorArtwork: Artwork;
material: Material;
success: BOOL;
g: SelectionGenerator;
selectionsExist: BOOL;
IF mouseButton = blue THEN {
SVError.Append["Can't undo SetColorArtwork.", TRUE, TRUE]; SVError.Blink[]; RETURN};
[color, success, material] ← GetSimpleArtworkParameters[editToolData, scene];
IF NOT success THEN RETURN;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR assembly: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g] UNTIL assembly = NIL DO
IF Rope.Equal[assembly.name, "background", FALSE] THEN {
scene.backgroundColor ← color;
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
LOOP;
}; -- a special case to set background color
colorArtwork ← SVArtwork.CreateColorArtwork[color, material];
DisplayList3d.SetArtworkAssembly[assembly, colorArtwork, scene];
ENDLOOP;
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
SVEditUser.PaintSceneAllViewers[SVViewerUser.EraseAndDrawSceneEtc, editToolData, scene];
};
SetTubeArtwork: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
tubeHeight: REAL ← SVViewerTools.GetReal[editToolData.artworkSection.tubeHeight, 100];
tubeRadius: REAL ← SVViewerTools.GetReal[editToolData.artworkSection.tubeRadius, 50];
picName: Rope.ROPE;
resolution: REAL ← SVViewerTools.GetReal[editToolData.artworkSection.resolution, 72.0];
material: Material;
backgroundColor: Color;
tube: Tube;
isColor: BOOL;
mat: Matrix3by3;
artwork, oldArtwork: Artwork;
success: BOOL;
g: SelectionGenerator;
selectionsExist: BOOL;
lastAssembly: Assembly;
[picName, success] ← GetFullPicname[editToolData];
IF NOT success THEN RETURN;
[backgroundColor, success, material] ← GetSimpleArtworkParameters[editToolData, scene];
IF NOT success THEN RETURN;
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
FOR assembly: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g] UNTIL assembly = NIL DO
tube ← SVMappings.CreateTube[tubeRadius, tubeHeight];
This is a horrible breach of information hiding, but I haven't the time. I shouldn't be picking apart artwork records and CoordSystem2d's in the user interface.
oldArtwork ← assembly.artwork;
IF oldArtwork = NIL THEN mat ← SVMatrix2d.Identity[]
ELSE {
IF ISTYPE[oldArtwork.surface, Tube] THEN mat ← oldArtwork.artWRTPad.mat
ELSE mat ← SVMatrix2d.Identity[];
};
End of horrible kludge.
isColor ← SVViewerTools.GetBool[editToolData.artworkSection.isColor];
artwork ← SVArtwork.CreateFileArtwork[coordSys: assembly.coordSys, material: material, surface: tube, oMap: tubeO, sMap: tubeS, filename: picName, isColor: isColor, background: backgroundColor, resolution: resolution, mat: mat
! SVArtwork.FileNotFound => {
SVError.Append[Rope.Cat["Sampled image ", picName, " not found."], TRUE, TRUE];
SVError.Blink[];
GOTO FileProblem}
];
DisplayList3d.SetArtworkAssembly[assembly, artwork, scene];
Sets the artwork of all of assembly's leaf subassemblies.
lastAssembly ← assembly;
REPEAT
FileProblem => NULL;
FINISHED => {
SVArtworkUser.SetArtwork[editToolData.artworkTool, artwork, scene.name, lastAssembly.name];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
ENDLOOP;
};
GetBoxOMap: PRIVATE PROC [viewer: Viewer] RETURNS [oMap: OMap] = TRUSTED {
mapRope: Rope.ROPE ← ViewerTools.GetContents[viewer];
SELECT TRUE FROM
Rope.Equal[mapRope, "Orthogonal", FALSE] => RETURN[orthogonal];
Rope.Equal[mapRope, "Radial", FALSE] => RETURN[radial];
ENDCASE => ERROR UnknownOMap;
};
UnknownOMap: ERROR = CODE;
SetBoxArtwork: 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;
picName: Rope.ROPE ← ViewerTools.GetContents[editToolData.artworkSection.picName];
resolution: REAL ← SVViewerTools.GetReal[editToolData.artworkSection.resolution, 72.0];
material: Material;
backgroundColor: Color;
box: Box;
isColor: BOOL;
oMap: OMap ← GetBoxOMap[editToolData.artworkSection.oMapLabel];
artwork: Artwork;
success: BOOL;
g: SelectionGenerator;
selectionsExist: BOOL;
oldAssembly: Assembly;
[picName, success] ← GetFullPicname[editToolData];
IF NOT success THEN RETURN;
[backgroundColor, success, material] ← GetSimpleArtworkParameters[editToolData, scene];
IF NOT success THEN RETURN;
[x, y, z] ← SVViewerTools.GetThreeReals[editToolData.artworkSection.boxXYZ];
isColor ← SVViewerTools.GetBool[editToolData.artworkSection.isColor];
[g, selectionsExist] ← SVSelections.GetSelectionGenerator[movee];
SVSelections.ComplainIfNot[selectionsExist];
IF NOT selectionsExist THEN RETURN;
success ← TRUE;
FOR assembly: Assembly ← SVSelections.NextSelectionCoincident[g], SVSelections.NextSelectionCoincident[g] UNTIL assembly = NIL DO
box ← SVMappings.CreateBox[x,y,z];
artwork ← SVArtwork.CreateFileArtwork[coordSys: assembly.coordSys, material: material, surface: box, oMap: oMap, sMap: unfoldedBox, filename: picName, isColor: isColor, background: backgroundColor, resolution: resolution
! SVArtwork.FileNotFound => {success ← FALSE; CONTINUE}];
IF NOT success THEN RETURN;
DisplayList3d.SetArtworkAssembly[assembly, artwork, scene];
oldAssembly ← assembly;
REPEAT
FINISHED => {
SVArtworkUser.SetArtwork[editToolData.artworkTool, artwork, scene.name, oldAssembly.name];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
ENDLOOP;
};
GetArtwork: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
Get the artwork of the currently named assembly. Stuff this information into the artwork section and display the artwork.
editToolData: EditToolData ← NARROW[clientData];
scene: Scene ← editToolData.sceneSection.currentScene;
assembly: Assembly;
artwork: Artwork;
materialName: Rope.ROPE;
IF Rope.Equal[ViewerTools.GetContents[editToolData.sceneSection.source],
"background", FALSE] THEN {
ViewerTools.SetContents[editToolData.artworkSection.picName, NIL];
SVViewerTools.SetColor[editToolData.artworkSection.rgb, scene.backgroundColor];
RETURN}; -- a special case to get background color
assembly ← SVSelections.TopMoveeCoincident[];
IF assembly = NIL THEN RETURN;
artwork ← assembly.artwork;
ViewerTools.SetContents[editToolData.artworkSection.picName, FileNames.GetShortName[artwork.source]];
SVViewerTools.SetColor[editToolData.artworkSection.rgb, artwork.color];
materialName ← SVArtwork.MaterialToRope[artwork.material];
ViewerTools.SetContents[editToolData.artworkSection.material, materialName];
IF artwork.source = NIL THEN {
ViewerTools.SetContents[editToolData.artworkSection.isColor, NIL];
ViewerTools.SetContents[editToolData.artworkSection.resolution, NIL];
ViewerTools.SetContents[editToolData.artworkSection.tubeHeight, NIL];
ViewerTools.SetContents[editToolData.artworkSection.tubeRadius, NIL];
ViewerTools.SetContents[editToolData.artworkSection.boxXYZ, NIL];
}-- a pure color artwork. Update color and material only. Blank out other info.
ELSE {-- a file artwork. Display isColorFile, resolution, simple surface parameters and mapping types
SVViewerTools.SetBool[editToolData.artworkSection.isColor, artwork.isColorFile];
SVViewerTools.SetReal[editToolData.artworkSection.resolution, artwork.resolution];
WITH artwork.surface SELECT FROM
tube: SVMappings.Tube => {
SVViewerTools.SetReal[editToolData.artworkSection.tubeHeight, tube.H];
SVViewerTools.SetReal[editToolData.artworkSection.tubeRadius, tube.R];
};
box: SVMappings.Box => {
SVViewerTools.SetThreeReals[editToolData.artworkSection.boxXYZ, box.x, 2*box.halfY, box.z];
SELECT artwork.oMap FROM
orthogonal => {
globalBoxOMapIndex ← 1;
ViewerTools.SetContents[editToolData.artworkSection.oMapLabel, SVArtwork.OMapToRope[orthogonal]];
};
radial => {
globalBoxOMapIndex ← 2;
ViewerTools.SetContents[editToolData.artworkSection.oMapLabel, SVArtwork.OMapToRope[radial]];
};
ENDCASE => ERROR;
};
ENDCASE => ERROR;
};
SVArtworkUser.SetArtwork[editToolData.artworkTool, artwork, scene.name, assembly.name];
}; -- end of GetArtwork
RotateArtwork: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton,
shift, control: BOOL] = TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
degrees: REAL ← SVViewerTools.GetReal[editToolData.artworkTransformSection.degrees, 45];
SVArtworkUser.RotateArtwork[editToolData.artworkTool, degrees];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
NormalizeArtwork: PUBLIC PROC [parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL] = TRUSTED {
editToolData: EditToolData ← NARROW[clientData];
SVArtworkUser.NormalizeArtwork[editToolData.artworkTool];
SVEditUser.SceneNewVersion[editToolData.currentViewerToolData];
};
END.