G3dToolIOImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, April 2, 1993 3:37 pm PST
3d Tool: IO
DIRECTORY CedarProcess, Controls, Draw2d, FS, G3dBasic, G3dShape, G3dTool, IO, MessageWindow, Rope;
G3dToolIOImpl: CEDAR PROGRAM
IMPORTS CedarProcess, Controls, Draw2d, FS, G3dShape, G3dTool, IO, MessageWindow, Rope
EXPORTS G3dTool
~ BEGIN
Types
Surface:    TYPE ~ G3dBasic.Surface;
Shape:    TYPE ~ G3dShape.Shape;
Vertex:    TYPE ~ G3dShape.Vertex;
Tool:     TYPE ~ G3dTool.Tool;
Triple:    TYPE ~ G3dTool.Triple;
ROPE:     TYPE ~ Rope.ROPE;
STREAM:    TYPE ~ IO.STREAM;
IO
IOOpsButton: PUBLIC G3dTool.ClickProc ~ {
t: Tool ¬ NARROW[clientData];
Inner: PROC ~ {
choice: INT ¬ Controls.PopUpRequest[["Output"], LIST[
-- 1 -- ["Read Shape"],
-- 2 -- ["Read Shape and Auto Scale"],
-- 3 -- ["Write .SHAPE", "Output a points-polygons shape file"],
-- 4 -- ["Write .NONE", "Output a points-polygons .none file"],
-- 5 -- ["Write INTERPRESS", "Output interpress file of the current display"],
-- 6 -- ["IP stroke width", "width of strokes for IP output"],
-- 7 -- ["Write RIB", "write output to a named file"]]];
G3dTool.SetCursor[t, TRUE];
SELECT choice FROM
1 => ReadShape[t, FALSE];
2 => ReadShape[t, TRUE];
3, 4 => {
shape: INT ¬ G3dTool.ChooseShape[t, "Output Shape"];
SELECT shape FROM
-2 => G3dTool.TSWrite[t, "No shape to write."];
-1 => G3dTool.TSWrite[t, "Choose only one shape."];
ENDCASE => {
r: ROPE ¬ Controls.TypescriptReadFileName[t.typescript];
IF choice = 3
THEN G3dShape.ShapeToFile[r, t.shapes[shape]]
ELSE {
out: STREAM ¬ FS.StreamOpen[r, $create];
s: Shape ¬ t.shapes[shape];
IF NOT s.vertices.valid[normal] THEN G3dShape.SetVertexNormals[s];
IF NOT G3dShape.ShapeToStreamPerFormat[s, out, $DotNone]
THEN G3dTool.TSWrite[t, "can't write shape"];
IO.Close[out];
};
};
};
5 => {
Draw: Controls.DrawProc ~ {
v: G3dTool.View ¬ G3dTool.GetView[viewer, t];
G3dTool.Draw[context, viewer, $IPOut, v.camera.matrix, v.viewport, v, t, t];
};
t.forInterpress ¬ TRUE;
Draw2d.IPOut[Controls.TypescriptReadFileName[t.typescript], Draw, t];
t.forInterpress ¬ FALSE;
};
6 => t.ipStrokeWidth ¬ Controls.GetReal[t.typescript, "Stroke width", t.ipStrokeWidth];
7 => G3dTool.WriteRIBtoFile[t, Controls.TypescriptReadFileName[t.typescript]];
ENDCASE;
G3dTool.SetCursor[t, FALSE];
};
CedarProcess.DoWithPriority[background, Inner];
};
ReadShape: PROC [t: Tool, autoScale: BOOL] ~ {
prompt: ROPE ¬ IO.PutFR1["Add shape: (dir = %g) ", IO.rope[t.outerData.directory]];
r: ROPE ¬ Controls.TypescriptRead[t.typescript, prompt];
IF r # NIL THEN {
c: CHAR ¬ Rope.Fetch[r, 0];
IF c # '[ AND c # '/ THEN r ¬ Rope.Concat[t.outerData.directory, r];
IF (r ¬ G3dTool.ReadFromShapeFile[t, r, autoScale]) # NIL
THEN Blink[r]
ELSE G3dTool.Repaint[t, $ShapeOps];
};
};
Blink: PROC [r: ROPE] ~ {
MessageWindow.Append[Rope.Concat["\t\t", r], TRUE];
MessageWindow.Blink[];
};
END.
..
--6-- ["RIB to selection", "write output to current (Tioga) selection"],
--7-- ["Color Display", "Write out Color Image"]]];
6 => {
v: ViewerClasses.Viewer ¬ ViewerTools.GetSelectedViewer[];
IF v # NIL AND (v.class.flavor = $Text OR v.class.flavor = $Typescript)
THEN WriteRIBtoStream[t, ViewerIO.CreateViewerStreams[NIL, v].out]
ELSE Blink["Make a primary selection first\n"];
};
7 =>
IF G3dTool.Context3dOk[t] THEN
G3dRenderWithImager.MakeInterpressPage[GetFirstActiveContext3d[t],
Controls.TypescriptReadFileName[t.typescript] ! G3dRender.Error => CONTINUE]