You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Add-on/DrawSpline.ts

76 lines
2.2 KiB

import { Vector3 } from 'three';
import { app } from '../ApplicationServices/Application';
import { Spline } from '../DatabaseServices/Spline';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { JigUtils } from './../Editor/JigUtils';
export class DrawSpline implements Command
{
async exec()
{
app.Editor.Prompt("请输入一个点:");
let ptRes = await app.Editor.GetPoint({ Msg: "请输入第一个点:" });
if (ptRes.Status != PromptStatus.OK)
return;
let ptLast = ptRes.Point;
let pts: Vector3[] = [ptLast];
let spline = new Spline(pts);
let jigline: Spline;
while (true)
{
ptLast = ptLast.clone();
spline.Points = pts;
pts.push(ptLast);
if (pts.length === 2)
{
app.Database.ModelSpace.Append(spline);
jigline = JigUtils.Draw(spline);
}
app.Editor.Prompt("请输入点2:");
ptRes = await app.Editor.GetPoint({
Msg: "请输入点2:",
BasePoint: ptLast,
AllowDrawRubberBand: true,
KeyWordList: [{ msg: "闭合", key: "C" }, { msg: "放弃", key: "U" }],
Callback: (v) =>
{
ptLast.copy(v);
jigline.Points = pts;
}
});
if (ptRes.Status == PromptStatus.OK)
{
ptLast = ptRes.Point;
}
else if (ptRes.Status === PromptStatus.Keyword)
{
if (ptRes.StringResult === "C")
{
pts.push(pts[0].clone());
spline.Points = pts;
break;
}
else if (ptRes.StringResult === "U")
{
if (pts.length > 3)
{
ptLast.copy(pts.pop());
pts.pop();
jigline.Points = pts;
}
}
}
else
{
pts.pop();
break;
}
}
}
}