mirror of https://gitee.com/cf-fz/WebCAD.git
!420 选择板件快速标注
parent
b24c4a2156
commit
725d816d8a
@ -0,0 +1,96 @@
|
||||
import { Box3, Matrix4, Vector3 } from "three";
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { JigUtils } from "../../Editor/JigUtils";
|
||||
import { AlignedDimension } from "../../DatabaseServices/Dimension/AlignedDimension";
|
||||
import { CoordinateSystem } from "../../Geometry/CoordinateSystem";
|
||||
import { Command_AutoDimBrs } from "./AutoDimBrs";
|
||||
|
||||
export class Command_FastDimBrs implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
//选择板件
|
||||
let enRes = await app.Editor.GetSelection({
|
||||
Msg: "选择需要标注的板件",
|
||||
Filter: { filterTypes: [Board] },
|
||||
});
|
||||
|
||||
if (enRes.Status === PromptStatus.Cancel) return;
|
||||
|
||||
let brs = enRes.SelectSet.SelectEntityList as Board[];
|
||||
|
||||
let autoDim = new Command_AutoDimBrs();
|
||||
|
||||
let ucs = app.Editor.UCSMatrix;
|
||||
let ucsInv = app.Editor.UCSMatrixInv;
|
||||
let ucsDir = new Vector3().setFromMatrixColumn(app.Editor.UCSMatrix, 2);
|
||||
let isFS = ucsDir.equals(new Vector3(-0, -0, 1));
|
||||
|
||||
let brBoxs = brs.map(br =>
|
||||
{
|
||||
return br.BoundingBoxInOCS.applyMatrix4(ucsInv.clone().multiply(br.OCS));
|
||||
});
|
||||
let boxAll = new Box3();
|
||||
for (let box of brBoxs)
|
||||
boxAll.union(box);
|
||||
|
||||
let cs = new CoordinateSystem().CopyForm(ucs);
|
||||
|
||||
let als: AlignedDimension[] = [];
|
||||
let ptRes = await app.Editor.GetPoint({
|
||||
Msg: "指定尺寸线位置:",
|
||||
Callback: p =>
|
||||
{
|
||||
let pUcs = p.clone().applyMatrix4(ucsInv);
|
||||
let drawCS = new Matrix4();
|
||||
let textRo = 0;
|
||||
|
||||
//right
|
||||
if (pUcs.x > boxAll.max.x)
|
||||
{
|
||||
textRo = Math.PI;
|
||||
drawCS.makeBasis(cs.YAxis, cs.XAxis.clone().negate(), cs.ZAxis);
|
||||
}
|
||||
//top
|
||||
else if (pUcs.y > (boxAll.max.y + boxAll.min.y) / 2 && (pUcs.x > boxAll.min.x && pUcs.x < boxAll.max.x))
|
||||
{
|
||||
textRo = Math.PI;
|
||||
drawCS.makeBasis(cs.XAxis.clone().negate(), cs.YAxis.clone().negate(), cs.ZAxis);
|
||||
}
|
||||
//down
|
||||
else if (pUcs.y < (boxAll.max.y + boxAll.min.y) / 2 && (pUcs.x > boxAll.min.x && pUcs.x < boxAll.max.x))
|
||||
{
|
||||
textRo = 0;
|
||||
drawCS.copy(ucs);
|
||||
}
|
||||
//left
|
||||
else if (pUcs.x < boxAll.min.x)
|
||||
{
|
||||
textRo = Math.PI;
|
||||
drawCS.makeBasis(cs.YAxis.clone().negate(), cs.XAxis, cs.ZAxis);
|
||||
}
|
||||
|
||||
JigUtils.Destroy();
|
||||
|
||||
als = autoDim.DrawDim(brs, drawCS, textRo, true, !isFS);
|
||||
|
||||
for (let aldim of als)
|
||||
{
|
||||
aldim.TextPosition = p;
|
||||
}
|
||||
}
|
||||
})
|
||||
if (ptRes.Status == PromptStatus.OK)
|
||||
{
|
||||
for (let aldim of als)
|
||||
{
|
||||
aldim.TextPosition = ptRes.Point;
|
||||
app.Database.ModelSpace.Append(aldim);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue