MakeTool:
PUBLIC
PROC
[
name: Rope.ROPE ¬ NIL,
primitives: PrimitiveList ¬ NIL,
convexSolids: LIST OF PrimitiveList ¬ NIL,
res: IntegerPair ¬ [50, 50],
client: G3dTool.Client ¬ [],
ops: G3dTool.Operations ¬ G3dTool.allOps,
extraControls: LIST OF Controls.Control ¬ NIL,
extraButtons: LIST OF Controls.Button ¬ NIL,
controlSizes: Controls.ControlSizes ¬ [],
useArcBalls: BOOL ¬ TRUE,
arcBallSize: INT ¬ 136,
graphicsHeight: INT ¬ 475,
camera: G3dTool.CameraRep ¬ [[0, 2, 0], [], 1, 60],
background: Triple ¬ [0.3, 0.3, 1.0],
noOpen: BOOL ¬ FALSE,
toolSettings: ImplicitDesign.ToolRep ¬ [],
tool3dSettings: G3dTool.ToolRep ¬ []]
RETURNS [Tool]
~ {
CountActive: PrimitiveProc ~ {IF p.active THEN t.nPrimitives ¬ t.nPrimitives+1};
SetID: PrimitiveProc ~ {IF p.id = -1 THEN {p.id ¬ id; id ¬ id+1}};
id: INTEGER ¬ 0;
t: Tool ¬ NEW[ToolRep¬[client:client, res:res, primitives:primitives, convexSolids:convexSolids]];
DoWithAllPrimitives[t, CountActive];
DoWithAllPrimitives[t, SetID];
IF res = [0, 0] THEN t.res ¬ [50, 50] ELSE SetRes[t, res];
FOR b:
LIST
OF Controls.Button ¬
LIST[
Controls.ClickButton["Maps", Maps, t, 1],
Controls.ClickButton["DoAll", DoAll, t, 1]],
Controls.ClickButton["Interp: On", InterpButton, t, 1],
b.rest
WHILE b #
NIL
DO
extraButtons ¬ CONS[b.first, extraButtons];
ENDLOOP;
t.cmd ¬ NARROW[ProcessProps.GetProp[$CommanderHandle], Commander.Handle];
t.tool ¬ ImplicitDesign.MakeTool[
name: name,
function: Function,
start: Start,
client: [draw: Draw, data: t],
ops: ops,
extraButtons: extraButtons,
extraControls: extraControls,
controlSizes: controlSizes,
useArcBalls: useArcBalls,
arcBallSize: arcBallSize,
graphicsHeight: graphicsHeight,
camera: camera,
background: background,
noOpen: noOpen,
toolSettings: toolSettings,
tool3dSettings: tool3dSettings
];
SetToolSettingsFromLog[t, name];
RETURN[t];
};
SetToolSettingsFromLog:
PROC [t: Tool, name:
ROPE] ~ {
GetArg:
PROC [key:
ROPE]
RETURNS [rope:
ROPE ¬
NIL] ~ {
i: INT ¬ Rope.Find[entry, key,, FALSE];
IF i # -1
THEN {
ii: INT ¬ Rope.SkipOver[entry, i+Rope.Length[key], ": \t"];
rope ¬ Rope.Substr[entry, ii, Rope.SkipTo[entry, ii, ",: \t\n"]-ii];
};
};
GetInt:
PROC [key:
ROPE, def:
INT]
RETURNS [r:
INT] ~ {
r ¬ Convert.IntFromRope[GetArg[key] ! Convert.Error => {r ¬ def; CONTINUE}];
};
GetBool:
PROC [key:
ROPE, def:
BOOL]
RETURNS [r:
BOOL] ~ {
Eq: PROC [r1, r2: ROPE] RETURNS [b: BOOL] ~ {b ¬ Rope.Equal[r1, r2, FALSE]};
a: ROPE ¬ GetArg[key];
r ¬ SELECT TRUE FROM Eq[a, "true"] => TRUE, Eq[a, "false"] => FALSE, ENDCASE => def;
};
entry: ROPE ¬ ImplicitDesign.GetLogEntry[t.tool, name];
IF entry = NIL THEN RETURN;
t.res ¬ [GetInt["resx", t.res.x], GetInt["resx", t.res.y]];
t.filter ¬ GetBool["filter", t.filter];
t.interp ¬ GetBool["interp", t.interp];
};
Draw: G3dTool.DrawProc ~ {
t: Tool ¬ NARROW[clientData];
IF whatChanged = $Overlay THEN RETURN;
IF t.client.draw #
NIL
THEN t.client.draw[context, viewer, whatChanged, view, vp, v, tool, t.client.data];
ImplicitConvolve.DrawPrimitives[t.primitives, context, view, vp, whatChanged, solid];
FOR s:
LIST
OF PrimitiveList ¬ t.convexSolids, s.rest
WHILE s #
NIL
DO
ImplicitConvolve.DrawPrimitives[s.first, context, view, vp, whatChanged, solid];
ENDLOOP;
IF debug
THEN
FOR l: PrimitiveList ¬ t.primitives, l.rest
WHILE l #
NIL
DO
p: Primitive ¬ l.first;
IF
p.twist.tw0
# 0
THEN {
G3dDraw.Vector[context, p.origin, p.normal, view, vp, "n"];
G3dDraw.Vector[context, p.origin, p.xAxis, view, vp, "x"];
G3dDraw.Vector[context, p.origin, p.yAxis, view, vp, "y"];
G3dDraw.Mark[context, p.p0x, view, vp, "p0x", asterisk];
G3dDraw.Mark[context, p.twist.p0, view, vp, "p0", asterisk];
G3dDraw.Mark[context, p.twist.p1, view, vp, "p1", asterisk];
};
IF p.points.length = 2
THEN {
G3dDraw.Mark[context, p.points[0], view, vp];
G3dDraw.Mark[context, p.points[1], view, vp];
};
ENDLOOP;
};