|
|
|
@ -1,19 +1,23 @@
|
|
|
|
|
import { Vector3 } from "three";
|
|
|
|
|
import { Vector2, Vector3 } from "three";
|
|
|
|
|
import { app } from "../../ApplicationServices/Application";
|
|
|
|
|
import { arrayRemoveIf } from "../../Common/ArrayExt";
|
|
|
|
|
import { FixedNotZero } from "../../Common/Utils";
|
|
|
|
|
import { arrayPushArray } from "../../Common/ArrayExt";
|
|
|
|
|
import { Log } from "../../Common/Log";
|
|
|
|
|
import { Intent } from "../../Common/Toaster";
|
|
|
|
|
import { Board } from "../../DatabaseServices/Entity/Board";
|
|
|
|
|
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
|
|
|
|
|
import { Command } from "../../Editor/CommandMachine";
|
|
|
|
|
import { PromptStatus } from "../../Editor/PromptResult";
|
|
|
|
|
import { comparePoint } from "../../Geometry/GeUtils";
|
|
|
|
|
import { AppToaster } from "../../UI/Components/Toaster";
|
|
|
|
|
import { BoardOpenDir } from "../../UI/Store/BoardInterface";
|
|
|
|
|
|
|
|
|
|
export class ParseHinge implements Command
|
|
|
|
|
{
|
|
|
|
|
async exec()
|
|
|
|
|
{
|
|
|
|
|
Log("注意:绘制的铰链五金名称必须包含\"铰链\"");
|
|
|
|
|
let res = await app.Editor.GetSelection({
|
|
|
|
|
Msg: "请选择需要分析铰链的门板",
|
|
|
|
|
Msg: "请选择需要分析铰链的门板:",
|
|
|
|
|
Filter: {
|
|
|
|
|
filterFunction: (o, e) => e instanceof Board && e.OpenDir !== BoardOpenDir.None
|
|
|
|
|
}
|
|
|
|
@ -22,9 +26,12 @@ export class ParseHinge implements Command
|
|
|
|
|
{
|
|
|
|
|
let doors = res.SelectSet.SelectEntityList as Board[];
|
|
|
|
|
|
|
|
|
|
let succeedCount = 0;
|
|
|
|
|
let emptyCount = 0;
|
|
|
|
|
|
|
|
|
|
for (let door of doors)
|
|
|
|
|
{
|
|
|
|
|
let hingeMap = new Map<string, string>();
|
|
|
|
|
let hingeMap = new Map<string, Vector2[]>();
|
|
|
|
|
for (let hid of door.RelativeHardware)
|
|
|
|
|
{
|
|
|
|
|
let hw = hid.Object;
|
|
|
|
@ -33,18 +40,59 @@ export class ParseHinge implements Command
|
|
|
|
|
if (hw.HardwareOption.name.includes("铰链"))
|
|
|
|
|
{
|
|
|
|
|
let pos = new Vector3().setFromMatrixPosition(hw.SpaceOCS).applyMatrix4(door.OCSInv);
|
|
|
|
|
let posStr = hingeMap.get("jl-" + hw.HardwareOption.name);
|
|
|
|
|
if (!posStr)
|
|
|
|
|
posStr = "";
|
|
|
|
|
posStr += `${FixedNotZero(pos.x, 2)},${FixedNotZero(pos.y, 2)},${FixedNotZero(pos.z, 2)}|`;
|
|
|
|
|
hingeMap.set("jl-" + hw.HardwareOption.name, posStr);
|
|
|
|
|
let key = "jl-" + hw.HardwareOption.name;
|
|
|
|
|
let posArr = hingeMap.get(key);
|
|
|
|
|
if (!posArr)
|
|
|
|
|
{
|
|
|
|
|
posArr = [];
|
|
|
|
|
hingeMap.set(key, posArr);
|
|
|
|
|
}
|
|
|
|
|
posArr.push(new Vector2(Math.round(pos.x), Math.round(pos.y)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let oldRemarks = door.BoardProcessOption.remarks.slice();
|
|
|
|
|
arrayRemoveIf(oldRemarks, (r) => hingeMap.has(r[0]));
|
|
|
|
|
oldRemarks.push(...hingeMap.entries());
|
|
|
|
|
door.BoardProcessOption.remarks = oldRemarks;
|
|
|
|
|
|
|
|
|
|
let remarks = door.BoardProcessOption.remarks.filter(r => !hingeMap.has(r[0]));
|
|
|
|
|
|
|
|
|
|
let hingeMarks: [string, string][] = [];
|
|
|
|
|
for (let d of hingeMap)
|
|
|
|
|
{
|
|
|
|
|
let arr = d[1];
|
|
|
|
|
arr.sort(comparePoint("xy"));
|
|
|
|
|
if (arr.every(p => p.x === arr[0].x))//所有的X都相等
|
|
|
|
|
hingeMarks.push([d[0], `X:${arr[0].x} Y:${arr.map(p => p.y).join(",")}`]);
|
|
|
|
|
else if (arr.every(p => p.y === arr[0].y))
|
|
|
|
|
hingeMarks.push([d[0], `Y:${arr[0].y} X:${arr.map(p => p.x).join(",")}`]);
|
|
|
|
|
else
|
|
|
|
|
hingeMarks.push([d[0], "位置(x,y): " + arr.map(p => `(${p.x},${p.y})`).join(", ")]);
|
|
|
|
|
}
|
|
|
|
|
hingeMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));
|
|
|
|
|
if (hingeMarks.length)
|
|
|
|
|
{
|
|
|
|
|
arrayPushArray(remarks, hingeMarks);
|
|
|
|
|
door.BoardProcessOption.remarks = remarks;
|
|
|
|
|
succeedCount++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
emptyCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (succeedCount)
|
|
|
|
|
{
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: `成功分析${succeedCount}个门板的铰链位置!(已经写入到板件备注!)`,
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
intent: Intent.SUCCESS,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (emptyCount)
|
|
|
|
|
{
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: `有${emptyCount}个门板没有铰链!`,
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
intent: Intent.WARNING,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|