功能:构造线,命令XLINE

pull/1226/MERGE
ChenX 4 years ago
parent 57f3eb4f59
commit c463a58bcf

@ -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);
}
}

@ -6,6 +6,7 @@ export enum CommandNames
DXFImport = "DXF",
Insert = "INSERT",
Line = "LINE",
XLine = "XLINE",
Undo = "UNDO",
Redo = "REDO",
RECTANG = "RECTANG",

@ -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());

Loading…
Cancel
Save