File: SVViewerImpl.mesa
Author: Eric Bier on July 2, 1983 5:03 pm
Last edited by Bier on August 18, 1983 4:30 pm
Contents: Code to create a view onto a 3d scene.
DIRECTORY
BitMap3d,
Buttons,
Containers,
CoordSys,
CSGGraphics,
DisplayList3d,
Graphics,
GraphicsColor,
Icons,
Labels,
Matrix3d,
Menus,
Rope,
SV2d,
SVPolygon3d,
SVViewer,
SVViewerInput,
SVViewerTool,
SVViewerUser,
TIPUser,
VFonts,
ViewerClasses,
ViewerOps,
ViewerTools;
SVViewerImpl: PROGRAM
IMPORTS BitMap3d, Buttons, Containers, CoordSys, DisplayList3d, Icons, Labels, Matrix3d, Menus, Rope, SVViewerInput, SVViewerUser, SVViewerTool, TIPUser, VFonts, ViewerOps, ViewerTools
EXPORTS SVViewer
SHARES ViewerClasses =
BEGIN
Camera: TYPE = CSGGraphics.Camera;
CoordSystem: TYPE = CoordSys.CoordSystem;
FileCamera: TYPE = DisplayList3d.FileCamera;
Plane: TYPE = SVPolygon3d.Plane;
Point2d: TYPE = SV2d.Point2d;
Scene: TYPE = DisplayList3d.Scene;
Viewer: TYPE = ViewerClasses.Viewer;
entryHeight: CARDINAL = 15; -- height of a line of items
entryVSpace: CARDINAL = 2; -- vertical leading between lines
entryHSpace: CARDINAL = 2; -- horizontal space between items on a line
column1: CARDINAL = 200; -- horizontal space between margin and column 1;
column2: CARDINAL = 250; -- horizontal space between margin and column 2.
column3: CARDINAL = 500; -- horizontal space between margin and column 3;
ViewerToolData: TYPE = REF ViewerToolDataObj;
ViewerToolDataObj: TYPE = SVViewerTool.ViewerToolDataObj;
ViewerPictureData: TYPE = REF ViewerPictureDataObj;
ViewerPictureDataObj: TYPE = SVViewerUser.ViewerPictureDataObj;
SolidPaint: SAFE PROC [self: Viewer, context: Graphics.Context,
whatChanged: REF ANY, clear: BOOL] = TRUSTED {
ViewerClasses.PaintProc
whatChanged is a ViewerToolData. self is a ViewerPicture.
viewerToolData: ViewerToolData;
viewerPictureData: ViewerPictureData;
IF whatChanged = NIL THEN { --we are being called by Window Manager
scene: Scene;
camera: Camera;
viewerPictureData ← NARROW[self.data];
scene ← viewerPictureData.scene;
camera ← viewerPictureData.camera;
SVViewerUser.PlaceOrigin[self];
SVViewerUser.ResizeBitMap[self];
SVViewerUser.DrawSceneEtc[context, viewerPictureData.viewerToolData];
DisplayList3d.DrawScene[context, scene, camera];
}
ELSE {
proc: PROC [Graphics.Context];
viewerToolData ← NARROW[whatChanged];
viewerPictureData ← NARROW[viewerToolData.viewerPicture.data];
proc ← viewerPictureData.proc;
proc[context];
RETURN};
};
Init: PROC = {
solidWindowClass: ViewerClasses.ViewerClass;
solidWindowClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: SolidPaint,
notify: SVViewerInput.InputNotify,
tipTable: TIPUser.InstantiateNewTIPTable["SolidViews.TIP"]
]];
ViewerOps.RegisterViewerClass[$SolidWindow, solidWindowClass];
};
confirmReset: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmReset];
confirmSave: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmSave];
confirmGet: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmGet];
confirmStore: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmStore];
confirmEmpty: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmEmpty];
confirmRayCast: REF Menus.ClickProc ← NEW[Menus.ClickProc ← SVViewerUser.ConfirmRayCast];
CreateViewerTool: PUBLIC PROC [parentData: REF ANY, scene: Scene, iconic: BOOL, paint: BOOL] RETURNS [viewerToolData: ViewerToolData, viewerPicture: Viewer] = {
parent is the EditTool
Create the Container and the top menu which looks like this:
Clear, Reset, Get, Store, Save, Split, Erase, Raycast, Stop, Aray, Press, Dither, Extend, Move
#BBox #Scene #Coords #Point #Cross #Color #B&W #Dither Coords Screen/Hornet Bands
screenCS, worldCS: CoordSystem;
success: BOOL;
fileCamera: FileCamera;
viewerPictureData: ViewerPictureData ← NEW[ViewerPictureDataObj];
vToolMenu: Menus.Menu ← Menus.CreateMenu[1];
viewerToolData ← NEW[ViewerToolDataObj];
Clear, Reset, Get, Store, Save, Split, Erase, Raycast, Stop, Aray, Press, Dither, Extend, Move
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Clear",
proc: SVViewerUser.Empty,
clientData: viewerToolData,
documentation: confirmEmpty,
guarded: TRUE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Reset",
proc: SVViewerUser.Reset,
clientData: viewerToolData,
documentation: confirmReset,
guarded: TRUE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Get",
proc: SVViewerUser.Get,
clientData: viewerToolData,
documentation: confirmGet,
guarded: TRUE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Store",
proc: SVViewerUser.Store,
clientData: viewerToolData,
documentation: confirmStore,
guarded: TRUE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Save",
proc: SVViewerUser.Save,
clientData: viewerToolData,
documentation: "Save the current picture file edits.",
guarded: FALSE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Split",
proc: SVViewerUser.Split,
clientData: viewerToolData,
documentation: "Make another viewer onto this scene"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Erase",
proc: SVViewerUser.Erase,
clientData: viewerToolData,
documentation: "Erase this window"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "RayCast",
proc: SVViewerUser.RayCast,
clientData: viewerToolData,
documentation: confirmRayCast,
guarded: TRUE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Stop",
proc: SVViewerUser.Stop,
clientData: viewerToolData,
documentation: "stop ray casting",
guarded: FALSE
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "ARay",
proc: SVViewerUser.ARay,
clientData: viewerToolData,
documentation: "Cast a ray from screen point given in this viewer's x, y, z blank"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Press",
proc: SVViewerUser.Press,
clientData: viewerToolData,
documentation: "Do a DrawScene to the press file named in 'AIS:'"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Dither",
proc: SVViewerUser.Dither,
clientData: viewerToolData,
documentation: "Create an 8 bit dithered image from 3 separations"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Extend",
proc: SVViewerUser.Extend,
clientData: viewerToolData,
documentation: "Extend the current secondary selection"
],
line: 0
];
Menus.AppendMenuEntry[
menu: vToolMenu,
entry: Menus.CreateEntry[
name: "Move",
proc: SVViewerUser.Move,
clientData: viewerToolData,
documentation: "Move secondary to primary"
],
line: 0
];
viewerToolData.editToolData ← parentData;
viewerPictureData.scene ← scene;
Construct the outer container.
viewerToolData.outer ← SVViewerTool.Create[
info: [
name: Rope.Concat["Solid Scene: ", viewerPictureData.scene.name],
menu: vToolMenu,
data: viewerToolData,
iconic: TRUE,
column: left,
scrollable: FALSE,
icon: Icons.NewIconFromFile["SolidViews.icons", 0]
],
paint: FALSE];
Find the current scene.
screenCS ← CoordSys.CreateCoordSys["SCREEN",
Matrix3d.MakeTranslateMat[-100,-100,0], NIL];
IF scene.cameraOrder # NIL THEN [fileCamera, ----] ← DisplayList3d.FindFileCameraFromName[scene.cameraOrder.first,
viewerPictureData.scene]
ELSE {
[fileCamera, success] ← DisplayList3d.FindFileCameraFromName["Front",
viewerPictureData.scene];
IF NOT success THEN ERROR;
};
worldCS ← CoordSys.FindCoordSysFromName["WORLD", scene.coordSystems];
viewerPictureData.camera ← DisplayList3d.CameraFromFileCamera[fileCamera, worldCS, screenCS, wire]; -- wireframe
viewerPictureData.sceneStyleIndex ← 1;-- wireframe
viewerPictureData.mode ← cast;
viewerPictureData.showCoordSys ← FALSE;
viewerPictureData.doubleBuffer ← FALSE;
viewerPictureData.altDC ← BitMap3d.GetAltDisplayContext[];
viewerPictureData.viewerToolData ← viewerToolData;
BuildLine1[viewerToolData];
BuildLine2[viewerToolData];
BuildPictureSection[viewerToolData, viewerPictureData];
viewerPicture ← viewerToolData.viewerPicture;
IF paint THEN ViewerOps.ComputeColumn[viewerToolData.outer.column, TRUE];
IF NOT iconic THEN ViewerOps.OpenIcon[icon: viewerToolData.outer, closeOthers: FALSE, bottom: FALSE, paint: TRUE];
};
BuildLine1: PRIVATE PROC [viewerToolData: ViewerToolData] = {
This section implements a set of buttons, text windows, and options listers in this format:
#BBox #Scene #Coords #Point #Cross #Color #B&W #Dither Coords Screen/Hornet Bands
boxButton, sceneButton, drawCoordsButton, pointButton, crossButton, colorButton, bwButton, ditherButton, coordsButton: Buttons.Button;
viewerToolData.height ← viewerToolData.height + entryVSpace;
Space down from the top of the viewer.
boxButton ← Buttons.Create[
info: [
name: "#BBox", wy: viewerToolData.height, wh: entryHeight, parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawBoundBoxes,
clientData: viewerToolData
];
sceneButton ← Buttons.Create[
info: [
name: "#Scene",
wx: boxButton.wx + boxButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawScene,
clientData: viewerToolData
];
drawCoordsButton ← Buttons.Create[
info: [
name: "#Coords",
wx: sceneButton.wx + sceneButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawCoordSystems,
clientData: viewerToolData
];
pointButton ← Buttons.Create[
info: [
name: "#Point", wx: drawCoordsButton.wx + drawCoordsButton.ww + entryHSpace, wy: viewerToolData.height, wh: entryHeight, parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawPt,
clientData: viewerToolData
];
crossButton ← Buttons.Create[
info: [name: "#Cross",
wx: pointButton.wx + pointButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.CrossHairs,
clientData: viewerToolData
];
colorButton ← Buttons.Create[
info: [
name: "#Color",
wx: crossButton.wx + crossButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawColor,
clientData: viewerToolData
];
bwButton ← Buttons.Create[
info: [
name: "#B&W",
wx: colorButton.wx + colorButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawBlackAndWhite,
clientData: viewerToolData
];
ditherButton ← Buttons.Create[
info: [
name: "#Dither",
wx: bwButton.wx + bwButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DrawDither,
clientData: viewerToolData
];
coordsButton ← Buttons.Create[
info: [
name: "Coords",
wx: ditherButton.wx + ditherButton.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.ShowCoordsMode,
clientData: viewerToolData
];
viewerToolData.height ← viewerToolData.height + entryVSpace + entryHeight;
}; -- end of BuildLine1
BuildLine2: PRIVATE PROC [viewerToolData: ViewerToolData] = {
This section implements a set of buttons, text windows, and options listers in this format:
Pic: <somefile> AIS: <filename>STYLE: <drawStyle> x,y,z: <x, y, z>
2Buffer Selected
textPrompt, aisPrompt, stylePrompt: Buttons.Button;
xyzPrompt, doubleBufferButton: Buttons.Button;
initialPictureFileRope: Rope.ROPE ← "default3d.pic";
initialAISRope: Rope.ROPE ← "default.ais";
initialXYZRope: Rope.ROPE ← "0, 0, 0";
textPrompt ← Buttons.Create[
info: [
name: "Text:", wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.TextPrompt,
clientData: viewerToolData
];
viewerToolData.textSection.text ← ViewerTools.MakeNewTextViewer[[
parent: viewerToolData.outer,
wx: textPrompt.wx + textPrompt.ww + entryHSpace,
wy: viewerToolData.height,
ww: VFonts.StringWidth["FairlyLongName.pic"],
wh: entryHeight,
data: initialPictureFileRope,
scrollable: FALSE, border: FALSE]];
aisPrompt ← Buttons.Create[
info: [
name: "AIS:",
wx: viewerToolData.textSection.text.wx +
viewerToolData.textSection.text.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.AISPrompt,
clientData: viewerToolData
];
viewerToolData.textSection.ais ← ViewerTools.MakeNewTextViewer[[
parent: viewerToolData.outer,
wx: aisPrompt.wx + aisPrompt.ww + entryHSpace,
wy: viewerToolData.height,
ww: VFonts.StringWidth["MediumName.ais"],
wh: entryHeight,
data: initialAISRope,
scrollable: FALSE, border: FALSE]];
stylePrompt ← Buttons.Create[
info: [
name: "Style:",
wx: viewerToolData.textSection.ais.wx +
viewerToolData.textSection.ais.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.StylePrompt,
clientData: viewerToolData
];
viewerToolData.textSection.viewStyle ← Labels.Create[
info: [
name: "WireFrame",
wx: stylePrompt.wx + stylePrompt.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
ww: VFonts.StringWidth["ALongStyle"],
parent: viewerToolData.outer, border: FALSE]];
X, Y, Z:<x, y, z>DoubleBuffer Selected
xyzPrompt ← Buttons.Create[
info: [
name: "x,y,z:",
wx: viewerToolData.textSection.viewStyle.wx +
viewerToolData.textSection.viewStyle.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.XYZPrompt,
clientData: viewerToolData
];
viewerToolData.textSection.xyz ← ViewerTools.MakeNewTextViewer[[
parent: viewerToolData.outer,
wx: xyzPrompt.wx + xyzPrompt.ww + entryHSpace,
wy: viewerToolData.height,
ww: VFonts.StringWidth["18, 18, 18"],
wh: entryHeight,
data: initialXYZRope,
scrollable: FALSE, border: FALSE]];
viewerToolData.textSection.selected ← Buttons.Create[
info: [
name: "Selected",
wx: viewerToolData.textSection.xyz.wx +
viewerToolData.textSection.xyz.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.Selected,
clientData: viewerToolData
];
doubleBufferButton ← Buttons.Create[
info: [
name: "2Buffer",
wx: viewerToolData.textSection.selected.wx +
viewerToolData.textSection.selected.ww + entryHSpace,
wy: viewerToolData.height, wh: entryHeight,
parent: viewerToolData.outer, border: FALSE],
proc: SVViewerUser.DoubleBuffer,
clientData: viewerToolData
];
viewerToolData.height ← viewerToolData.height + entryVSpace + entryHeight;
}; -- end of BuildTextSection
BuildPictureSection: PRIVATE PROC [viewerToolData: ViewerToolData, viewerPictureData: ViewerPictureData] = {
Create a SolidWindow which fills the bottom of the container
viewerToolData.viewerPicture ← ViewerOps.CreateViewer[
flavor: $SolidWindow,
info: [
parent: viewerToolData.outer,
wx: 0, wy: viewerToolData.height,
ww: viewerToolData.outer.ww,
wh: viewerToolData.outer.wh, -- only initial values for ww and wh. They are constrained below
data: viewerPictureData, -- contains the current scene
scrollable: FALSE
]
];
Containers.ChildXBound[viewerToolData.outer, viewerToolData.viewerPicture];
Containers.ChildYBound[viewerToolData.outer, viewerToolData.viewerPicture];
viewerToolData.height ← viewerToolData.height + viewerToolData.viewerPicture.wh;
}; -- end of BuildDrawSection
Init[];
END.