!420 选择板件快速标注

pull/420/MERGE
肖诗雅 5 years ago committed by ChenX
parent b24c4a2156
commit 725d816d8a

@ -6,7 +6,8 @@ import { Board } from "../../DatabaseServices/Entity/Board";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { CoordinateSystem } from "../../Geometry/CoordinateSystem";
import { equalnn } from "../../Geometry/GeUtils";
import { equalnn, equaln } from "../../Geometry/GeUtils";
import { JigUtils } from "../../Editor/JigUtils";
export class Command_AutoDimBrs implements Command
{
@ -14,10 +15,8 @@ export class Command_AutoDimBrs implements Command
{
//选择板件
let enRes = await app.Editor.GetSelection({
Msg: "选择需要标注的板件",
Filter: {
filterTypes: [Board]
}
Msg: "选择需要标注的柜体",
Filter: { filterTypes: [Board] }
});
if (enRes.Status === PromptStatus.Cancel)
return;
@ -71,24 +70,36 @@ export class Command_AutoDimBrs implements Command
* @param brs
* @param drawCS
*/
DrawDim(brs: Board[], drawCS: Matrix4, textRotation?: number)
DrawDim(brs: Board[], drawCS: Matrix4, textRotation?: number, needJig?: boolean, useMaxZ?: boolean)
{
let als: AlignedDimension[] = [];
let foots: number[] = [];
let minY: number = Infinity;
let minZ: number = Infinity;
let maxZ: number = -Infinity;
let drawCSInv = new Matrix4().getInverse(drawCS);
for (let br of brs)
{
//排除酒格
if (!(equaln(br.Rotation.x, 0) && equaln(br.Rotation.y, 0) && equaln(br.Rotation.z, 0)))
continue;
let mtx = new Matrix4().multiplyMatrices(drawCSInv, br.OCS);
let box = br.BoundingBoxInOCS.applyMatrix4(mtx);
foots.push(box.min.x, box.max.x);
minY = Math.min(minY, box.min.y);
minZ = Math.min(minZ, box.min.z);
maxZ = Math.max(maxZ, box.max.z);
}
if (!needJig)
minZ = 0;
arraySortByNumber(foots);
arrayRemoveDuplicateBySort(foots, equalnn(1));
let drawY = minY - 20;
let armY = drawY - 100;
let z = useMaxZ ? maxZ : minZ;
//draw
for (let i = 0; i < foots.length - 1; i++)
@ -97,16 +108,24 @@ export class Command_AutoDimBrs implements Command
let x2 = foots[i + 1];
let alDim = new AlignedDimension(
new Vector3(x1, drawY),
new Vector3(x2, drawY),
new Vector3(x1, armY),
new Vector3(x2, armY)
new Vector3(x1, drawY, z),
new Vector3(x2, drawY, z),
new Vector3(x1, armY, z),
new Vector3(x2, armY, z)
);
if (textRotation)
if (!equaln(textRotation, 0) && textRotation)
alDim.TextRotation = textRotation;
alDim.ApplyMatrix(drawCS);
if (needJig)
{
als.push(alDim);
JigUtils.Draw(alDim);
}
else
app.Database.ModelSpace.Append(alDim);
}
return als;
}
}

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

@ -558,7 +558,9 @@ export class Board extends ExtureSolid
{
this.WriteAllObjectRecord();
this.m_Rotation = { x: rox, y: roy, z: roz };
this.m_Rotation.x = rox;
this.m_Rotation.y = roy;
this.m_Rotation.z = roz;
let spcocs = this.SpaceOCS;
let roMatX = new Matrix4().makeRotationX(rox);
@ -696,11 +698,13 @@ export class Board extends ExtureSolid
this.layerNails.push(objId);
}
}
if (ver > 4)
this.m_Rotation = { x: file.Read(), y: file.Read(), z: file.Read() };
}
WriteFile(file: CADFiler)
{
super.WriteFile(file);
file.Write(4);
file.Write(5);
file.Write(this.m_SpecOCS.toArray())
file.Write(this.m_BoardType);
file.Write(this.m_Name);
@ -723,6 +727,9 @@ export class Board extends ExtureSolid
{
file.WriteObjectId(nail);
}
file.Write(this.m_Rotation.x);
file.Write(this.m_Rotation.y);
file.Write(this.m_Rotation.z);
}
}

@ -123,6 +123,7 @@ import { BatchModify } from '../Add-on/Batch/BatchModifySealOrDrill';
import { ShowTemplate } from '../Add-on/Template/ShowTemplate';
import { ReverseDrillFace } from '../Add-on/DrawDrilling/ReverseDrillFace';
import { DeleteDim } from '../Add-on/DrawDim/DeleteDim';
import { Command_FastDimBrs } from '../Add-on/DrawDim/FastDim';
export function registerCommand()
@ -272,6 +273,7 @@ export function registerCommand()
commandMachine.RegisterCommand("bbs", new LookOverBoardInfos())
commandMachine.RegisterCommand("boardbatchcurtail", new BoardBatchCurtail());
commandMachine.RegisterCommand("autodimbrs", new Command_AutoDimBrs());
commandMachine.RegisterCommand("fastdimbrs", new Command_FastDimBrs());
commandMachine.RegisterCommand("deletedim", new DeleteDim());
commandMachine.RegisterCommand("rotatelybr", new RotateLayerBoard());

Loading…
Cancel
Save