mirror of https://gitee.com/cf-fz/WebCAD.git
!2266 优化:门板拉手位置支持给出备注信息
parent
d6ef4049a7
commit
338225ca3e
@ -0,0 +1,141 @@
|
||||
import { Vector2, Vector3 } from "three";
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { arrayPushArray } from "../../Common/ArrayExt";
|
||||
import { Log } from "../../Common/Log";
|
||||
import { Intent } from "../../Common/Toaster";
|
||||
import { CADObject } from "../../DatabaseServices/CADObject";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { Entity } from "../../DatabaseServices/Entity/Entity";
|
||||
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
|
||||
import { ObjectId } from "../../DatabaseServices/ObjectId";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { ComparePointFnGenerate } from "../../Geometry/GeUtils";
|
||||
import { AppToaster } from "../../UI/Components/Toaster";
|
||||
import { FuzzyFactory } from "../../csg/core/FuzzyFactory";
|
||||
import { IsDoor } from "../HideSelect/HideSelectUtils";
|
||||
|
||||
export class ParseHandle implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
Log("注意:绘制的拉手五金名称必须包含\"拉手\"");
|
||||
let res = await app.Editor.GetSelection({
|
||||
Msg: "请选择需要分析拉手的门板:",
|
||||
Filter: {
|
||||
filterFunction: (o, e) => { return e && IsDoor(e); }
|
||||
}
|
||||
});
|
||||
if (res.Status === PromptStatus.OK)
|
||||
{
|
||||
let doors = res.SelectSet.SelectEntityList as Entity[];
|
||||
|
||||
let succeedCount = 0;
|
||||
let emptyCount = 0;
|
||||
|
||||
for (let door of doors)
|
||||
{
|
||||
let HandleMap = new Map<string, Vector2[]>(); // 关系表 <把手名,位置XY信息>
|
||||
let dataList: [string, string][] = [];
|
||||
let handleMarks: [string, string][] = [];
|
||||
let handleObjId: ObjectId[] = [];
|
||||
|
||||
if (door instanceof Board)
|
||||
{
|
||||
handleObjId = door.RelativeHandle;
|
||||
dataList = door.BoardProcessOption.remarks;
|
||||
}
|
||||
else if (door instanceof HardwareCompositeEntity)
|
||||
{
|
||||
handleObjId = door.RelevanceHandle;
|
||||
dataList = door.DataList;
|
||||
}
|
||||
|
||||
ParsehandleToDoor(door, handleObjId, HandleMap);
|
||||
|
||||
//会去掉所有之前的"ls"开头的备注
|
||||
let remarks = dataList.filter(r => !(HandleMap.has(r[0]) || r[0].substring(0, 2) === "ls"));
|
||||
|
||||
convertToString(HandleMap, handleMarks);
|
||||
handleMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));
|
||||
if (handleMarks.length)
|
||||
{
|
||||
arrayPushArray(remarks, handleMarks);
|
||||
if (door instanceof Board)
|
||||
door.BoardProcessOption.remarks = remarks;
|
||||
else if (door instanceof HardwareCompositeEntity)
|
||||
door.DataList = 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function convertToString(hingeAndHandleMap: Map<string, Vector2[]>, hingeMarks: [string, string][])
|
||||
{
|
||||
for (let d of hingeAndHandleMap)
|
||||
{
|
||||
let arr = d[1];
|
||||
arr.sort(ComparePointFnGenerate("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(", ")]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断拉手在门板上的位置
|
||||
* @param {Entity} door
|
||||
* @param {ObjectId<CADObject>[]} handleObjId
|
||||
* @param {Map<string, Vector2[]>} HandleMap 关系表 <把手名,位置XY信息>
|
||||
*/
|
||||
function ParsehandleToDoor(door: Entity, handleObjId: ObjectId<CADObject>[], HandleMap: Map<string, Vector2[]>)
|
||||
{
|
||||
let doorBox = door.Clone().ApplyMatrix(door.SpaceOCSInv).BoundingBox;
|
||||
|
||||
let fuzz = new FuzzyFactory(1, 0.1);
|
||||
|
||||
for (let hand of handleObjId)
|
||||
{
|
||||
let handle = hand?.Object;
|
||||
if (!handle || handle.IsErase || !(handle instanceof HardwareCompositeEntity))
|
||||
continue;
|
||||
|
||||
if (handle.HardwareOption.name.includes("拉手"))
|
||||
{
|
||||
let pos = new Vector3().setFromMatrixPosition(handle.Clone().ApplyMatrix(door.SpaceOCSInv).SpaceOCS).sub(doorBox.min);
|
||||
let key = "ls-" + handle.HardwareOption.name;
|
||||
let posArr = HandleMap.get(key);
|
||||
if (!posArr)
|
||||
{
|
||||
posArr = [];
|
||||
HandleMap.set(key, posArr);
|
||||
}
|
||||
posArr.push(new Vector2(fuzz.lookupOrCreate([pos.x], Math.round(pos.x)), Math.round(pos.z)));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue