增加连续偏移模式

pull/718/head
ChenX 5 years ago
parent ac5d2260a0
commit 538f1fd89c

@ -1,6 +1,7 @@
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { GetPointAtCurveDir } from '../Common/CurveUtils'; import { GetPointAtCurveDir } from '../Common/CurveUtils';
import { Log } from '../Common/Log';
import { Curve } from '../DatabaseServices/Entity/Curve'; import { Curve } from '../DatabaseServices/Entity/Curve';
import { Polyline } from '../DatabaseServices/Entity/Polyline'; import { Polyline } from '../DatabaseServices/Entity/Polyline';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
@ -12,11 +13,18 @@ const OffsetKey = "offset";
//获取偏移距离的返回状态. //获取偏移距离的返回状态.
type GetOffsetStatus = { Status: PromptStatus, offsetDist?: number; }; type GetOffsetStatus = { Status: PromptStatus, offsetDist?: number; };
enum OffsetType
{
Direction = 0,
Dynamic = 1,
Continuous = 2,
}
//曲线偏移 //曲线偏移
export class Command_Offset implements Command export class Command_Offset implements Command
{ {
offsetDis: number = 1; offsetDis: number = 1;
isDyn = false; type = OffsetType.Direction;
constructor() constructor()
{ {
let o = window.localStorage.getItem(OffsetKey); let o = window.localStorage.getItem(OffsetKey);
@ -25,17 +33,22 @@ export class Command_Offset implements Command
} }
async exec() async exec()
{ {
this.isDyn = false; this.type = OffsetType.Direction;
let disRes = await app.Editor.GetDistance({ let disRes = await app.Editor.GetDistance({
Msg: "指定偏移距离:", Msg: "指定偏移距离:",
KeyWordList: [{ msg: "通过:", key: "T" }], KeyWordList: [{ msg: "通过(动态选点):", key: "T" }, { msg: "连续", key: "C" }],
Default: this.offsetDis Default: this.offsetDis
}); });
if (disRes.StringResult === "T") if (disRes.StringResult === "T")
this.isDyn = true; this.type = OffsetType.Dynamic;
else if (disRes.StringResult === "C")
this.type = OffsetType.Continuous;
else if (disRes.Status === PromptStatus.OK) else if (disRes.Status === PromptStatus.OK)
{
this.type = OffsetType.Direction;
this.UpdateDistance(disRes.Distance); this.UpdateDistance(disRes.Distance);
}
else else
return; return;
@ -65,10 +78,12 @@ export class Command_Offset implements Command
{ {
app.Viewer.OutlinePass.selectedObjects = [cu.DrawObject]; app.Viewer.OutlinePass.selectedObjects = [cu.DrawObject];
let state: GetOffsetStatus; let state: GetOffsetStatus;
if (this.isDyn) if (this.type === OffsetType.Dynamic)
state = await this.GetDynOffsetDist(cu); state = await this.GetDynOffsetDist(cu);
else else if (this.type === OffsetType.Direction)
state = await this.GetOffsetDir(cu); state = await this.GetOffsetDir(cu);
else
state = await this.GetOffsetContinuous(cu);
JigUtils.End(); JigUtils.End();
if (state.Status === PromptStatus.OK) if (state.Status === PromptStatus.OK)
@ -83,6 +98,32 @@ export class Command_Offset implements Command
app.Editor.UCSMatrix = oldUCS; app.Editor.UCSMatrix = oldUCS;
} }
async GetOffsetContinuous(cu: Curve): Promise<GetOffsetStatus>
{
let numberSet: Set<number> = new Set();
while (true)
{
let disRes = await app.Editor.GetDistance({
Msg: "指定偏移距离:",
Default: this.offsetDis
});
if (disRes.Status !== PromptStatus.OK)
return { Status: disRes.Status };
else
{
if (numberSet.has(disRes.Distance))
{
Log("你已经偏移过这个距离!");
continue;
}
numberSet.add(disRes.Distance);
this.DrawOffset(cu, disRes.Distance);
this.offsetDis = disRes.Distance;
}
}
}
UpdateDistance(offsetDist: number) UpdateDistance(offsetDist: number)
{ {
this.offsetDis = offsetDist || this.offsetDis; this.offsetDis = offsetDist || this.offsetDis;
@ -184,7 +225,7 @@ export class Command_DynOffset extends Command_Offset
{ {
async exec() async exec()
{ {
this.isDyn = true; this.type = OffsetType.Dynamic;
await this.Run(); await this.Run();
app.Viewer.OutlinePass.selectedObjects = []; app.Viewer.OutlinePass.selectedObjects = [];
} }

Loading…
Cancel
Save