From c463a58bcf53e43de7e5f16a177f7622f792915e Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 3 Nov 2020 11:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD:=E6=9E=84=E9=80=A0=E7=BA=BF,?= =?UTF-8?q?=E5=91=BD=E4=BB=A4XLINE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/DrawLine.ts | 37 +++++++++++++++++++++++++++++++++++ src/Common/CommandNames.ts | 1 + src/Editor/CommandRegister.ts | 4 +++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Add-on/DrawLine.ts b/src/Add-on/DrawLine.ts index ecf99f503..34c4de672 100644 --- a/src/Add-on/DrawLine.ts +++ b/src/Add-on/DrawLine.ts @@ -8,6 +8,7 @@ import { JigUtils } from '../Editor/JigUtils'; import { ObjectSnapMode } from '../Editor/ObjectSnapMode'; import { PromptStatus } from '../Editor/PromptResult'; import { SelectPick } from '../Editor/SelectPick'; +import { equalv3, ZeroVec } from '../Geometry/GeUtils'; export class DrawLine implements Command { @@ -107,3 +108,39 @@ export class DrawLine implements Command } } } + +export class Command_DrawXLine implements Command +{ + async exec() + { + let ptRes = await app.Editor.GetPoint({ Msg: "请输入第一个点:" }); + if (ptRes.Status !== PromptStatus.OK) + return; + + let p1 = ptRes.Point; + let line = new Line(); + JigUtils.Draw(line); + + const UpdateLine = (p2: Vector3) => + { + let normal = p2.clone().sub(p1); + if (equalv3(normal, ZeroVec, 1e-2)) return; + + normal.normalize().multiplyScalar(4000); + let p3 = p1.clone().add(normal); + let p4 = p1.clone().sub(normal); + line.StartPoint = p3; + line.EndPoint = p4; + }; + + let pt2Res = await app.Editor.GetPoint({ + BasePoint: p1, + Msg: "输入方向:", Callback: UpdateLine + }); + if (pt2Res.Status !== PromptStatus.OK) + return; + + UpdateLine(pt2Res.Point); + app.Database.ModelSpace.Append(line); + } +} diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index 5e2435bba..8b356632f 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -6,6 +6,7 @@ export enum CommandNames DXFImport = "DXF", Insert = "INSERT", Line = "LINE", + XLine = "XLINE", Undo = "UNDO", Redo = "REDO", RECTANG = "RECTANG", diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 5169cb54b..dba4a8ab3 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -69,7 +69,7 @@ import { DrawGripStretch } from "../Add-on/DrawGripStretch"; import { DrawPointLight, DrawPointLight2 } from "../Add-on/DrawLight/DrawPointLight"; import { DrawRectAreaLight } from "../Add-on/DrawLight/DrawRectAreaLight"; import { DrawSpotLight, DrawSpotLight2 } from "../Add-on/DrawLight/DrawSpotLight"; -import { DrawLine } from "../Add-on/DrawLine"; +import { Command_DrawXLine, DrawLine } from "../Add-on/DrawLine"; import { CMD_DrawPoint } from "../Add-on/DrawPoint"; import { DrawPolyline } from "../Add-on/DrawPolyline"; import { DrawRect } from "../Add-on/DrawRect"; @@ -223,6 +223,8 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.Insert, new Command_Insert()); commandMachine.RegisterCommand(CommandNames.Line, new DrawLine()); + commandMachine.RegisterCommand(CommandNames.XLine, new Command_DrawXLine()); + commandMachine.RegisterCommand(CommandNames.Undo, new Undo()); commandMachine.RegisterCommand(CommandNames.Redo, new Redo()); commandMachine.RegisterCommand("ze", new ZoomE());