|
|
|
@ -1,11 +1,16 @@
|
|
|
|
|
import { Vector3 } from 'three';
|
|
|
|
|
import { app } from '../ApplicationServices/Application';
|
|
|
|
|
import { GetPointAtCurveDir } from '../Common/CurveUtils';
|
|
|
|
|
import { Curve } from '../DatabaseServices/Curve';
|
|
|
|
|
import { Command } from '../Editor/CommandMachine';
|
|
|
|
|
import { PromptStatus } from '../Editor/PromptResult';
|
|
|
|
|
import { Vector3 } from 'three';
|
|
|
|
|
import { Jig } from '../Editor/Jig';
|
|
|
|
|
import { PromptStatus } from '../Editor/PromptResult';
|
|
|
|
|
import { RenderType } from '../GraphicsSystem/Enum';
|
|
|
|
|
|
|
|
|
|
//获取偏移距离的返回状态.
|
|
|
|
|
type GetOffsetStatus = { Status: PromptStatus, offsetDist?: number };
|
|
|
|
|
|
|
|
|
|
//曲线偏移
|
|
|
|
|
export class Command_Offset implements Command
|
|
|
|
|
{
|
|
|
|
|
offsetDis: number = 1;
|
|
|
|
@ -13,59 +18,132 @@ export class Command_Offset implements Command
|
|
|
|
|
{
|
|
|
|
|
let disRes = await app.m_Editor.GetDistance({
|
|
|
|
|
Msg: "指定偏移距离:",
|
|
|
|
|
KeyWordList: [{ msg: "通过", key: "T" }],
|
|
|
|
|
KeyWordList: [{ msg: "通过:", key: "T" }],
|
|
|
|
|
Default: this.offsetDis
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let dyn = false;
|
|
|
|
|
if (disRes.Status === PromptStatus.Keyword && disRes.StringResult === "T")
|
|
|
|
|
dyn = true;
|
|
|
|
|
else if (disRes.Status != PromptStatus.OK)
|
|
|
|
|
return;
|
|
|
|
|
else
|
|
|
|
|
let isDyn = false;//动态偏移.
|
|
|
|
|
if (disRes.StringResult === "T")
|
|
|
|
|
isDyn = true;
|
|
|
|
|
else if (disRes.Status === PromptStatus.OK)
|
|
|
|
|
this.offsetDis = disRes.Value;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
let enRes = await app.m_Editor.GetEntity({ Msg: "选择要偏移的对象:" });
|
|
|
|
|
if (enRes.Status === PromptStatus.Cancel)
|
|
|
|
|
break;
|
|
|
|
|
else if (enRes.Status !== PromptStatus.OK)
|
|
|
|
|
if (enRes.Status === PromptStatus.OK)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else if (enRes.Status === PromptStatus.None)
|
|
|
|
|
continue;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
let cu = enRes.Entity as Curve;
|
|
|
|
|
if (cu instanceof Curve)
|
|
|
|
|
{
|
|
|
|
|
let ptRes = await app.m_Editor.GetPoint({
|
|
|
|
|
Msg: "指定要偏移的那一侧的点",
|
|
|
|
|
Callback: dyn ? (p: Vector3) =>
|
|
|
|
|
{
|
|
|
|
|
Jig.Destroy();
|
|
|
|
|
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1
|
|
|
|
|
cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir)
|
|
|
|
|
.forEach(c => Jig.Draw(c));
|
|
|
|
|
} : undefined
|
|
|
|
|
});
|
|
|
|
|
app.m_Viewer.m_OutlinePass.selectedObjects = [cu.Draw(RenderType.Wireframe)];
|
|
|
|
|
let state: GetOffsetStatus;
|
|
|
|
|
if (isDyn)
|
|
|
|
|
state = await this.GetDynOffsetDist(cu);
|
|
|
|
|
else
|
|
|
|
|
state = await this.GetOffsetDir(cu);
|
|
|
|
|
|
|
|
|
|
Jig.End();
|
|
|
|
|
if (ptRes.Status === PromptStatus.OK)
|
|
|
|
|
if (state.Status === PromptStatus.OK)
|
|
|
|
|
this.DrawOffset(cu, state.offsetDist);
|
|
|
|
|
else if (state.Status === PromptStatus.None)
|
|
|
|
|
continue;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}//end exec
|
|
|
|
|
|
|
|
|
|
//绘制偏移的对象
|
|
|
|
|
DrawOffset(cu: Curve, offsetDist: number)
|
|
|
|
|
{
|
|
|
|
|
cu.GetOffsetCurves(offsetDist).forEach(c =>
|
|
|
|
|
{
|
|
|
|
|
app.m_Database.ModelSpace.Append(c);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//单一对象,已经确定偏移距离的时候,用户选择偏移方向.
|
|
|
|
|
async GetOffsetDir(cu: Curve): Promise<GetOffsetStatus>
|
|
|
|
|
{
|
|
|
|
|
let oldDir = 0;
|
|
|
|
|
let ptRes = await app.m_Editor.GetPoint({
|
|
|
|
|
Msg: "指定要偏移的那一侧的点",
|
|
|
|
|
Callback: (p: Vector3) =>
|
|
|
|
|
{
|
|
|
|
|
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
|
|
|
|
|
if (dir !== oldDir)
|
|
|
|
|
{
|
|
|
|
|
let p = ptRes.Value;
|
|
|
|
|
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
|
|
|
|
|
let offCus: Curve[];
|
|
|
|
|
if (dyn)
|
|
|
|
|
offCus = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir);
|
|
|
|
|
else
|
|
|
|
|
offCus = cu.GetOffsetCurves(this.offsetDis * dir);
|
|
|
|
|
offCus.forEach((offCur) =>
|
|
|
|
|
{
|
|
|
|
|
app.m_Database.ModelSpace.Append(offCur);
|
|
|
|
|
})
|
|
|
|
|
app.m_Viewer.m_bNeedUpdate = true;
|
|
|
|
|
Jig.Destroy();
|
|
|
|
|
let offCus = cu.GetOffsetCurves(this.offsetDis * dir);
|
|
|
|
|
offCus.forEach(c => { Jig.Draw(c) });
|
|
|
|
|
oldDir = dir;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
let status = { Status: ptRes.Status, offsetDist: 0 };
|
|
|
|
|
if (ptRes.Status === PromptStatus.OK)
|
|
|
|
|
{
|
|
|
|
|
let dir = GetPointAtCurveDir(cu, ptRes.Value) ? 1 : -1;
|
|
|
|
|
status.offsetDist = this.offsetDis * dir;
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//动态偏移用户点到哪里偏移到哪里.
|
|
|
|
|
async GetDynOffsetDist(cu: Curve): Promise<GetOffsetStatus>
|
|
|
|
|
{
|
|
|
|
|
let basePoint: Vector3 = new Vector3();
|
|
|
|
|
|
|
|
|
|
let isMulti = false;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
let dir: number = 0;
|
|
|
|
|
let distRes = await app.m_Editor.GetDistance(
|
|
|
|
|
{
|
|
|
|
|
Msg: "指定通过点或输入偏移距离:",
|
|
|
|
|
KeyWordList: [{ key: "D", msg: isMulti ? "单个" : "多个" }],
|
|
|
|
|
BasePoint: basePoint,
|
|
|
|
|
CalcDistance: (p: Vector3) =>
|
|
|
|
|
{
|
|
|
|
|
basePoint.copy(cu.GetClosestPointTo(p, false));
|
|
|
|
|
dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
|
|
|
|
|
return p.distanceTo(basePoint) * dir;
|
|
|
|
|
},
|
|
|
|
|
Callback: (dis: number) =>
|
|
|
|
|
{
|
|
|
|
|
Jig.Destroy();
|
|
|
|
|
cu.GetOffsetCurves(dis).forEach(c => Jig.Draw(c));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (distRes.Status === PromptStatus.OK)
|
|
|
|
|
{
|
|
|
|
|
let offsetDist = distRes.Value;
|
|
|
|
|
if (dir !== Math.sign(offsetDist))
|
|
|
|
|
offsetDist = -offsetDist;
|
|
|
|
|
this.DrawOffset(cu, offsetDist);
|
|
|
|
|
|
|
|
|
|
if (isMulti)
|
|
|
|
|
continue;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
return { Status: PromptStatus.None, offsetDist: distRes.Value };
|
|
|
|
|
}
|
|
|
|
|
else if (distRes.StringResult === "D")
|
|
|
|
|
{
|
|
|
|
|
isMulti = !isMulti;
|
|
|
|
|
app.m_Editor.Prompt(`切换成功,当前<${isMulti ? "多个" : "单个"}>`);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return { Status: distRes.Status, offsetDist: distRes.Value };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|