修复:设置直线对象坐标系实现错误

pull/2357/MERGE
ChenX 1 year ago
parent 7192dfc5f9
commit ec2e359292

@ -318,7 +318,7 @@ export enum CommandNames
TestM = "TESTM",//模拟走刀
TestFB = "TESTFB",//模拟封边
FlipZMatrix = "FLIPZMATRIX",//Z向量翻转 对Arc Circle Polyline Line进行翻转 Z轴方向相反,图形保持不变
SetLineUCS = "SETLINEUCS",//设置直线的UCS
SetLineOCS = "SETLINEOCS",//设置直线的UCS
Z0 = "Z0",
M0 = "M0",
PackageGroupMove0 = "PACKAGEGROUPMOVE0",

@ -0,0 +1,130 @@
import { Matrix4, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { Line } from "../DatabaseServices/Entity/Line";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { GetPointUCS } from "../Editor/UCSRAII";
import { equalv3 } from "../Geometry/GeUtils";
import { LogType } from "./Log";
//设置Line的自定义oCS
export class Command_SetLineOCS implements Command
{
async exec()
{
//选择直线
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Line] } });
if (enRes.Status !== PromptStatus.OK) return;
let line = enRes.Entity as Line;
let ucsMtx = new Matrix4();
//选择坐标原点
let posRes = await app.Editor.GetPoint(
{
Msg: "请点击坐标原点或",
Raycast: true,
KeyWordList: [
{ key: "W", msg: "使用世界坐标原点" }
]
}
);
if (posRes.Status === PromptStatus.Cancel) return;
if (posRes.Status === PromptStatus.Keyword)
{
switch (posRes.StringResult)
{
case "W":
ucsMtx = app.Editor.UCSMatrix.clone();
break;
default:
break;
}
}
let pointUCS = GetPointUCS(posRes);
if (!pointUCS)
{
//指定UCS的XYZ基向量
let xv: Vector3, yv: Vector3, zv: Vector3;
ucsMtx = new Matrix4().setPosition(posRes.Point);
//点选X轴方向
while (true)
{
let xRes = await app.Editor.GetPoint({ Msg: "请点击X轴方向(空格接受当前UCS):", BasePoint: posRes.Point, AllowDrawRubberBand: true, AllowNone: true });
if (xRes.Status === PromptStatus.None)
{
//空格时使用世界UCS向量
ucsMtx = GetPointUCS(posRes);
if (!ucsMtx) ucsMtx = app.Editor.UCSMatrix.setPosition(posRes.Point);
this.UpdateUCS(line, ucsMtx);
return;
}
else if (xRes.Status === PromptStatus.OK)
{
if (equalv3(xRes.Point, posRes.Point))
app.Editor.Prompt("与第一个点重复!", LogType.Error);
else
{
xv = xRes.Point.sub(posRes.Point).normalize();
break;
}
}
else
return;
}
//点选XY轴平面上的点确定UCS
while (true)
{
let yRes = await app.Editor.GetPoint({
Msg: "XY轴平面上的点(空格接受自动计算坐标系):",
BasePoint: posRes.Point,
AllowDrawRubberBand: true,
AllowNone: true
});
if (yRes.Status === PromptStatus.None)
{
//空格接受自动计算坐标系
zv = new Vector3().setFromMatrixColumn(ucsMtx, 2);
yv = zv.clone().cross(xv);
ucsMtx.makeBasis(xv.normalize(), yv.normalize(), zv.normalize());
break;
}
else if (yRes.Status === PromptStatus.OK)
{
if (equalv3(yRes.Point, posRes.Point))
app.Editor.Prompt("与第一个点重复!", LogType.Error);
else
{
yv = yRes.Point.sub(posRes.Point).normalize();
zv = xv.clone().cross(yv);
yv = zv.clone().cross(xv);
ucsMtx.makeBasis(xv.normalize(), yv.normalize(), zv.normalize());
break;
}
}
else
return;
}
ucsMtx.setPosition(posRes.Point);
}
else
ucsMtx = pointUCS;
this.UpdateUCS(line, ucsMtx);
}
private UpdateUCS(line: Line, ucsMtx: Matrix4)
{
let sp = line.StartPoint;
let ep = line.EndPoint;
line.ApplyMatrix(line.OCSInv).ApplyMatrix(ucsMtx);
line.StartPoint = sp;
line.EndPoint = ep;
}
}

@ -1,130 +0,0 @@
import { Matrix4, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { Line } from "../DatabaseServices/Entity/Line";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { GetPointUCS } from "../Editor/UCSRAII";
import { equalv3 } from "../Geometry/GeUtils";
import { LogType } from "./Log";
//设置Line的自定义UCS
export class Command_SetLineUCS implements Command
{
async exec()
{
//选择直线
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Line] } });
if (enRes.Status !== PromptStatus.OK) return;
let line = enRes.Entity as Line;
let ucsMtx = new Matrix4();
//选择坐标原点
let posRes = await app.Editor.GetPoint(
{
Msg: "请点击坐标原点或",
Raycast: true,
KeyWordList: [
{ key: "O", msg: "使用世界坐标原点" }
]
}
);
if (posRes.Status === PromptStatus.Keyword)
{
switch (posRes.StringResult)
{
case "O":
ucsMtx = app.Editor.UCSMatrix.clone();
break;
default:
break;
}
}
//指定UCS的XYZ基向量
let xv: Vector3, yv: Vector3, zv: Vector3;
ucsMtx = new Matrix4().setPosition(posRes.Point);
//点选X轴方向
while (true)
{
let xRes = await app.Editor.GetPoint({ Msg: "请点击X轴方向(空格接受当前UCS):", BasePoint: posRes.Point, AllowDrawRubberBand: true, AllowNone: true });
if (xRes.Status === PromptStatus.None)
{
//空格时使用世界UCS向量
ucsMtx = GetPointUCS(posRes);
if (!ucsMtx) ucsMtx = app.Editor.UCSMatrix.setPosition(posRes.Point);
this.UpdateUCS(line, ucsMtx);
return;
}
else if (xRes.Status === PromptStatus.OK)
{
if (equalv3(xRes.Point, posRes.Point))
app.Editor.Prompt("与第一个点重复!", LogType.Error);
else
{
xv = xRes.Point.sub(posRes.Point).normalize();
break;
}
}
else
return;
}
//点选XY轴平面上的点确定UCS
while (true)
{
let yRes = await app.Editor.GetPoint({
Msg: "XY轴平面上的点(空格接受自动计算坐标系):",
BasePoint: posRes.Point,
AllowDrawRubberBand: true,
AllowNone: true
});
if (yRes.Status === PromptStatus.None)
{
//空格接受自动计算坐标系
zv = new Vector3().setFromMatrixColumn(ucsMtx, 2);
yv = zv.clone().cross(xv);
ucsMtx.makeBasis(xv.normalize(), yv.normalize(), zv.normalize());
break;
}
else if (yRes.Status === PromptStatus.OK)
{
if (equalv3(yRes.Point, posRes.Point))
app.Editor.Prompt("与第一个点重复!", LogType.Error);
else
{
yv = yRes.Point.sub(posRes.Point).normalize();
zv = xv.clone().cross(yv);
yv = zv.clone().cross(xv);
ucsMtx.makeBasis(xv.normalize(), yv.normalize(), zv.normalize());
break;
}
}
else
return;
}
ucsMtx.setPosition(posRes.Point);
this.UpdateUCS(line, ucsMtx);
}
private UpdateUCS(line: Line, ucsMtx: Matrix4)
{
line.ApplyMatrix(line.OCSInv);
let pos = line.BoundingBox.getCenter(new Vector3);
let sp = line.StartPoint.clone().sub(pos);
let ep = line.EndPoint.clone().sub(pos);
sp.applyMatrix4(ucsMtx);
ep.applyMatrix4(ucsMtx);
line.WriteAllObjectRecord();
line.ApplyMatrix(ucsMtx);
line.StartPoint = sp;
line.EndPoint = ep;
line.Update();
}
}

@ -254,7 +254,7 @@ import { Polyline2Board } from "../Add-on/twoD2threeD/Polyline2Board";
import { Rect2Board } from "../Add-on/twoD2threeD/Rect2Board";
import { Command_FlipZMatrix } from "../Common/CommandFlipZMatrix";
import { CommandNames } from "../Common/CommandNames";
import { Command_SetLineUCS } from "../Common/CommandSetLineUCS";
import { Command_SetLineOCS } from "../Common/CommandSetLineOCS";
import { IsTest } from "../Common/Deving";
import { Command_SelectEntity } from "../Common/SelectEntity";
import { Dimension } from "../DatabaseServices/Dimension/Dimension";
@ -362,7 +362,7 @@ export function registerCommand()
commandMachine.RegisterCommand(CommandNames.Move, new Command_Move());
commandMachine.RegisterCommand(CommandNames.FlipZMatrix, new Command_FlipZMatrix());
commandMachine.RegisterCommand(CommandNames.SetLineUCS, new Command_SetLineUCS());
commandMachine.RegisterCommand(CommandNames.SetLineOCS, new Command_SetLineOCS());
commandMachine.RegisterCommand(CommandNames.Z0, new Command_EntitytMoveToZ0());
commandMachine.RegisterCommand(CommandNames.M0, new Command_M0());

@ -2136,8 +2136,8 @@ export const CommandList: ICommand[] = [
{
typeId: "util",
link: `#`,
defaultCustom: CommandNames.SetLineUCS,
command: CommandNames.SetLineUCS,
defaultCustom: CommandNames.SetLineOCS,
command: CommandNames.SetLineOCS,
type: "工具",
chName: "设置直线的UCS",
chDes: "设置直线的UCS",

Loading…
Cancel
Save