|
|
|
@ -6,7 +6,6 @@ import { arrayPushArray } from "../../Common/ArrayExt";
|
|
|
|
|
import { Log } from "../../Common/Log";
|
|
|
|
|
import { Intent } from "../../Common/Toaster";
|
|
|
|
|
import { ParseExpr } from "../../Common/eval";
|
|
|
|
|
import { CADObject } from "../../DatabaseServices/CADObject";
|
|
|
|
|
import { Board } from "../../DatabaseServices/Entity/Board";
|
|
|
|
|
import { Entity } from "../../DatabaseServices/Entity/Entity";
|
|
|
|
|
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
|
|
|
|
@ -63,65 +62,7 @@ export class ParseHinge implements Command
|
|
|
|
|
else if (res.Status === PromptStatus.OK)
|
|
|
|
|
{
|
|
|
|
|
let doors = res.SelectSet.SelectEntityList as Entity[];
|
|
|
|
|
|
|
|
|
|
let succeedCount = 0;
|
|
|
|
|
let emptyCount = 0;
|
|
|
|
|
|
|
|
|
|
for (let door of doors)
|
|
|
|
|
{
|
|
|
|
|
let hingeMap = new Map<string, HingeRemarkInformation[]>();
|
|
|
|
|
let dataList: [string, string][] = [];
|
|
|
|
|
let hingeMarks: [string, string][] = [];
|
|
|
|
|
let hingObjId: ObjectId[] = [];
|
|
|
|
|
|
|
|
|
|
if (door instanceof Board)
|
|
|
|
|
{
|
|
|
|
|
hingObjId = door.RelativeHardware;
|
|
|
|
|
dataList = door.BoardProcessOption.remarks;
|
|
|
|
|
}
|
|
|
|
|
else if (door instanceof HardwareCompositeEntity)
|
|
|
|
|
{
|
|
|
|
|
hingObjId = door.RelevanceHardware;
|
|
|
|
|
dataList = door.DataList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParseHingeToDoor(door, hingObjId, hingeMap, this.options);
|
|
|
|
|
|
|
|
|
|
//会去掉所有之前的"jl"开头的备注
|
|
|
|
|
let remarks = dataList.filter(r => !(hingeMap.has(r[0]) || r[0].substring(0, 2) === "jl"));
|
|
|
|
|
|
|
|
|
|
convertToString(hingeMap, hingeMarks);
|
|
|
|
|
hingeMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));
|
|
|
|
|
if (hingeMarks.length)
|
|
|
|
|
{
|
|
|
|
|
arrayPushArray(remarks, hingeMarks);
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ParseHingeToDoor(doors, this.options);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -165,61 +106,117 @@ function convertToString(hingeMap: Map<string, HingeRemarkInformation[]>, hingeM
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断铰链在门板上的位置和铰链详细信息
|
|
|
|
|
* @param {Entity} door
|
|
|
|
|
* @param {ObjectId<CADObject>[]} hingObjId
|
|
|
|
|
* @param {Map<string, HingeRemarkInformation>} hingeMap 关系表 <铰链名,{位置XY信息,铰链详细信息}[]>
|
|
|
|
|
* 解析铰链在门板上的位置和铰链详细信息
|
|
|
|
|
* @param {Entity[]} doors
|
|
|
|
|
* @param options 需要解析铰链的属性
|
|
|
|
|
*/
|
|
|
|
|
function ParseHingeToDoor(door: Entity, hingObjId: ObjectId<CADObject>[], hingeMap: Map<string, HingeRemarkInformation[]>, options: { name: string; key: string; checked: boolean; }[])
|
|
|
|
|
export function ParseHingeToDoor(doors: Entity[], options: { name: string; key: string; checked: boolean; }[])
|
|
|
|
|
{
|
|
|
|
|
let doorBox = door.Clone().ApplyMatrix(door.SpaceOCSInv).BoundingBox;
|
|
|
|
|
let succeedCount = 0;
|
|
|
|
|
let emptyCount = 0;
|
|
|
|
|
|
|
|
|
|
let fuzz = new FuzzyFactory(1, 0.1);
|
|
|
|
|
|
|
|
|
|
for (let hid of hingObjId)
|
|
|
|
|
for (let door of doors)
|
|
|
|
|
{
|
|
|
|
|
let hw = hid?.Object;
|
|
|
|
|
if (!hw || hw.IsErase || !(hw instanceof HardwareCompositeEntity)) //过滤掉铰链模板其他类型实体
|
|
|
|
|
continue;
|
|
|
|
|
let hingeMap = new Map<string, HingeRemarkInformation[]>();
|
|
|
|
|
let dataList: [string, string][] = [];
|
|
|
|
|
let hingeMarks: [string, string][] = [];
|
|
|
|
|
let hingObjId: ObjectId[] = [];
|
|
|
|
|
|
|
|
|
|
if (hw.HardwareOption.name.includes("铰链"))
|
|
|
|
|
if (door instanceof Board)
|
|
|
|
|
{
|
|
|
|
|
hingObjId = door.RelativeHardware;
|
|
|
|
|
dataList = door.BoardProcessOption.remarks;
|
|
|
|
|
}
|
|
|
|
|
else if (door instanceof HardwareCompositeEntity)
|
|
|
|
|
{
|
|
|
|
|
const size = hw.BoundingBoxInOCS.getSize(new Vector3);
|
|
|
|
|
let pos = new Vector3().setFromMatrixPosition(hw.Clone().ApplyMatrix(door.SpaceOCSInv).SpaceOCS).sub(doorBox.min);
|
|
|
|
|
let key = "jl-" + hw.HardwareOption.name; //设置铰链名称
|
|
|
|
|
hingObjId = door.RelevanceHardware;
|
|
|
|
|
dataList = door.DataList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let newDetailedInformation = ""; //获取铰链详细信息
|
|
|
|
|
const accuracy = HostApplicationServices.chaidanOption.hardwareExpressionFormattingAccuracy;
|
|
|
|
|
for (const { key, checked } of options)
|
|
|
|
|
{
|
|
|
|
|
if (!checked) continue;
|
|
|
|
|
newDetailedInformation += ParseExpr(hw.HardwareOption[key], accuracy, { L: size.x, W: size.y, H: size.z }) + " ";
|
|
|
|
|
}
|
|
|
|
|
let doorBox = door.Clone().ApplyMatrix(door.SpaceOCSInv).BoundingBox;
|
|
|
|
|
|
|
|
|
|
const newPosion = new Vector2(fuzz.lookupOrCreate([pos.x], parseFloat(pos.x.toFixed(1))), parseFloat(pos.z.toFixed(1)));//获取位置信息
|
|
|
|
|
let fuzz = new FuzzyFactory(1, 0.1);
|
|
|
|
|
|
|
|
|
|
const hingeRemarkInformations = hingeMap.get(key) || [] as HingeRemarkInformation[];
|
|
|
|
|
for (let hid of hingObjId)
|
|
|
|
|
{
|
|
|
|
|
let hw = hid?.Object;
|
|
|
|
|
if (!hw || hw.IsErase || !(hw instanceof HardwareCompositeEntity)) //过滤掉铰链模板其他类型实体
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const hingeRemarkInformation = hingeRemarkInformations.find(info => info.detailedInformation === newDetailedInformation);
|
|
|
|
|
if (hingeRemarkInformation) //如果存在铰链详细信息且是相同的,将位置写入到一起
|
|
|
|
|
if (hw.HardwareOption.name.includes("铰链"))
|
|
|
|
|
{
|
|
|
|
|
let x = fuzz.lookupOrCreate([pos.x], parseFloat(pos.x.toFixed(1)));
|
|
|
|
|
let y = parseFloat(pos.z.toFixed(1));
|
|
|
|
|
//过滤重复点
|
|
|
|
|
let v2 = hingeRemarkInformation.postion.find((v) => equaln(v.x, x) && equaln(v.y, y));
|
|
|
|
|
if (!v2)
|
|
|
|
|
hingeRemarkInformation.postion.push(newPosion);
|
|
|
|
|
}
|
|
|
|
|
else //不存在就创建一条新的数据
|
|
|
|
|
{
|
|
|
|
|
const newHingeRemarkInformation = {
|
|
|
|
|
postion: [newPosion],
|
|
|
|
|
detailedInformation: newDetailedInformation
|
|
|
|
|
};
|
|
|
|
|
hingeRemarkInformations.push(newHingeRemarkInformation);
|
|
|
|
|
const size = hw.BoundingBoxInOCS.getSize(new Vector3);
|
|
|
|
|
let pos = new Vector3().setFromMatrixPosition(hw.Clone().ApplyMatrix(door.SpaceOCSInv).SpaceOCS).sub(doorBox.min);
|
|
|
|
|
let key = "jl-" + hw.HardwareOption.name; //设置铰链名称
|
|
|
|
|
|
|
|
|
|
let newDetailedInformation = ""; //获取铰链详细信息
|
|
|
|
|
const accuracy = HostApplicationServices.chaidanOption.hardwareExpressionFormattingAccuracy;
|
|
|
|
|
for (const { key, checked } of options)
|
|
|
|
|
{
|
|
|
|
|
if (!checked) continue;
|
|
|
|
|
newDetailedInformation += ParseExpr(hw.HardwareOption[key], accuracy, { L: size.x, W: size.y, H: size.z }) + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newPosion = new Vector2(fuzz.lookupOrCreate([pos.x], parseFloat(pos.x.toFixed(1))), parseFloat(pos.z.toFixed(1)));//获取位置信息
|
|
|
|
|
|
|
|
|
|
const hingeRemarkInformations = hingeMap.get(key) || [] as HingeRemarkInformation[];
|
|
|
|
|
|
|
|
|
|
const hingeRemarkInformation = hingeRemarkInformations.find(info => info.detailedInformation === newDetailedInformation);
|
|
|
|
|
if (hingeRemarkInformation) //如果存在铰链详细信息且是相同的,将位置写入到一起
|
|
|
|
|
{
|
|
|
|
|
let x = fuzz.lookupOrCreate([pos.x], parseFloat(pos.x.toFixed(1)));
|
|
|
|
|
let y = parseFloat(pos.z.toFixed(1));
|
|
|
|
|
//过滤重复点
|
|
|
|
|
let v2 = hingeRemarkInformation.postion.find((v) => equaln(v.x, x) && equaln(v.y, y));
|
|
|
|
|
if (!v2)
|
|
|
|
|
hingeRemarkInformation.postion.push(newPosion);
|
|
|
|
|
}
|
|
|
|
|
else //不存在就创建一条新的数据
|
|
|
|
|
{
|
|
|
|
|
const newHingeRemarkInformation = {
|
|
|
|
|
postion: [newPosion],
|
|
|
|
|
detailedInformation: newDetailedInformation
|
|
|
|
|
};
|
|
|
|
|
hingeRemarkInformations.push(newHingeRemarkInformation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hingeMap.set(key, hingeRemarkInformations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//会去掉所有之前的"jl"开头的备注
|
|
|
|
|
let remarks = dataList.filter(r => !(hingeMap.has(r[0]) || r[0].substring(0, 2) === "jl"));
|
|
|
|
|
|
|
|
|
|
hingeMap.set(key, hingeRemarkInformations);
|
|
|
|
|
convertToString(hingeMap, hingeMarks);
|
|
|
|
|
hingeMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));
|
|
|
|
|
if (hingeMarks.length)
|
|
|
|
|
{
|
|
|
|
|
arrayPushArray(remarks, hingeMarks);
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|