From 538f1fd89cd9d3521c67c6322306526d0c7406c0 Mon Sep 17 00:00:00 2001 From: ChenX Date: Thu, 16 Jan 2020 11:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9E=E7=BB=AD=E5=81=8F?= =?UTF-8?q?=E7=A7=BB=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/Offset.ts | 55 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/Add-on/Offset.ts b/src/Add-on/Offset.ts index 7d0f8e56d..964724427 100644 --- a/src/Add-on/Offset.ts +++ b/src/Add-on/Offset.ts @@ -1,6 +1,7 @@ import { Vector3 } from 'three'; import { app } from '../ApplicationServices/Application'; import { GetPointAtCurveDir } from '../Common/CurveUtils'; +import { Log } from '../Common/Log'; import { Curve } from '../DatabaseServices/Entity/Curve'; import { Polyline } from '../DatabaseServices/Entity/Polyline'; import { Command } from '../Editor/CommandMachine'; @@ -12,11 +13,18 @@ const OffsetKey = "offset"; //获取偏移距离的返回状态. type GetOffsetStatus = { Status: PromptStatus, offsetDist?: number; }; +enum OffsetType +{ + Direction = 0, + Dynamic = 1, + Continuous = 2, +} + //曲线偏移 export class Command_Offset implements Command { offsetDis: number = 1; - isDyn = false; + type = OffsetType.Direction; constructor() { let o = window.localStorage.getItem(OffsetKey); @@ -25,17 +33,22 @@ export class Command_Offset implements Command } async exec() { - this.isDyn = false; + this.type = OffsetType.Direction; let disRes = await app.Editor.GetDistance({ Msg: "指定偏移距离:", - KeyWordList: [{ msg: "通过:", key: "T" }], + KeyWordList: [{ msg: "通过(动态选点):", key: "T" }, { msg: "连续", key: "C" }], Default: this.offsetDis }); 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) + { + this.type = OffsetType.Direction; this.UpdateDistance(disRes.Distance); + } else return; @@ -65,10 +78,12 @@ export class Command_Offset implements Command { app.Viewer.OutlinePass.selectedObjects = [cu.DrawObject]; let state: GetOffsetStatus; - if (this.isDyn) + if (this.type === OffsetType.Dynamic) state = await this.GetDynOffsetDist(cu); - else + else if (this.type === OffsetType.Direction) state = await this.GetOffsetDir(cu); + else + state = await this.GetOffsetContinuous(cu); JigUtils.End(); if (state.Status === PromptStatus.OK) @@ -83,6 +98,32 @@ export class Command_Offset implements Command app.Editor.UCSMatrix = oldUCS; } + async GetOffsetContinuous(cu: Curve): Promise + { + let numberSet: Set = 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) { this.offsetDis = offsetDist || this.offsetDis; @@ -184,7 +225,7 @@ export class Command_DynOffset extends Command_Offset { async exec() { - this.isDyn = true; + this.type = OffsetType.Dynamic; await this.Run(); app.Viewer.OutlinePass.selectedObjects = []; }