优化:简化铰链位置备注

pull/1467/head
ChenX 4 years ago
parent 7e6e0f60f8
commit 66687a8615

@ -1,5 +1,5 @@
import { Intent } from "@blueprintjs/core";
import DxfParser from "dxf-parser";
const DxfParser = require("dxf-parser");
import { MathUtils, Matrix4, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { arrayLast } from "../Common/ArrayExt";

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

@ -322,7 +322,7 @@ export function UpdateBoundingSphere(obj: Object3D)
}
export type compareVectorFn = (v1: Vector, v2: Vector3) => number;
export type compareVectorFn = (v1: Vector, v2: Vector) => number;
const comparePointCache: Map<string, compareVectorFn> = new Map();
@ -359,7 +359,7 @@ export function comparePoint(sortKey: string): compareVectorFn
sortIndex.push([ci, i2 > ci ? 1 : -1]);
}
let compareFunction = (v1: Vector, v2: Vector3): number =>
let compareFunction = (v1: Vector, v2: Vector): number =>
{
if (!v1) return -1;
if (!v2) return 1;

Loading…
Cancel
Save