mirror of https://gitee.com/cf-fz/WebCAD.git
parent
7192dfc5f9
commit
ec2e359292
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue