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

87 lines
2.7 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 { HotCMD } from '../Hot/HotCommand';
import { JigUtils } from './../Editor/JigUtils';
@HotCMD
export class DrawSpline implements Command
{
async exec()
{
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);
spline.ApplyMatrix(app.Editor.UCSMatrix);
let jigline: Spline;
while (true)
{
ptLast = ptLast.clone();
pts.push(ptLast);
spline.Points = pts;
if (pts.length === 2)
{
app.Database.ModelSpace.Append(spline);
jigline = JigUtils.Draw(spline);
}
ptRes = await app.Editor.GetPoint({
Msg: "请输入点2:",
BasePoint: ptLast,
AllowNone: true,
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;
spline.Points = pts;
}
else if (ptRes.Status === PromptStatus.Keyword)
{
if (ptRes.StringResult === "C")
{
if (pts.length >= 2)
{
pts[pts.length - 1].copy(pts[0]);
spline.Points = pts;
app.Database.ModelSpace.Append(spline);
}
return;
}
else if (ptRes.StringResult === "U")
{
if (pts.length > 3)
{
ptLast.copy(pts.pop());
pts.pop();
jigline.Points = pts;
}
}
}
else if (ptRes.Status === PromptStatus.None || ptRes.Status === PromptStatus.Cancel)
{
pts.pop();
if (pts.length >= 2)
{
spline.Points = pts;
app.Database.ModelSpace.Append(spline);
}
return;
}
}
}
}