!3026 优化:一键布局根据房间名出图重构

pull/3074/MERGE
林三 4 weeks ago committed by ChenX
parent e228e18068
commit 75e8cb0dff

@ -19,6 +19,8 @@ import { Entity } from "../../DatabaseServices/Entity/Entity";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { FileServer } from "../../DatabaseServices/FileServer";
import { GroupRecord } from "../../DatabaseServices/GroupTableRecord";
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { HardwareTopline } from "../../DatabaseServices/Hardware/HardwareTopline";
import { Text } from "../../DatabaseServices/Text/Text";
import { ViewportEntity } from "../../DatabaseServices/ViewportEntity";
import { Command } from "../../Editor/CommandMachine";
@ -291,48 +293,147 @@ export class OneKeyLayout implements Command
}
//板、复合实体、模型
let box2EntMap = GroupEntitysByBox(ents);
//文字 标注 曲线
let othersBox2EntMap = GroupEntitysByBox(others);
let box2EntMap: Map<Box3Ext, Entity[]> = new Map();
let othersBox2EntMap: Map<Box3Ext, Entity[]> = new Map();
//将标注 文字对象加入编组
for (let [box, entitys] of box2EntMap)
//按房名出图
if (groupType === GroupByType.roomName)
{
for (let [otherBoxs, otherEntitys] of othersBox2EntMap)
let roomNameEntsMap: Map<string, Set<Entity>> = new Map();
let alreadyAllocated: Set<Entity> = new Set(); //提前加入组织的实体
//按房名分类
while (ents.length)
{
if (!otherBoxs.isEmpty() && otherEntitys.length)
let ent = ents.pop();
let roomName = "";
if (ent instanceof Board)
roomName = ent.BoardProcessOption.roomName;
else if (ent instanceof HardwareCompositeEntity || ent instanceof HardwareTopline)
roomName = ent.HardwareOption.roomName;
else
{
//容差100 考虑到标注离得较远
if (box.intersectsBox(otherBoxs, 100))
others.push(ent);
continue;
}
//加入组织
let group = roomNameEntsMap.get(roomName);
if (group)
group.add(ent);
else
{
group = new Set([ent]);
roomNameEntsMap.set(roomName, group);
}
//查看编组
let groupId = ent.GroupId?.Object as GroupRecord;
if (groupId)
{
for (let obj of groupId.Entitys)
{
arrayPushArray(entitys, otherEntitys);
othersBox2EntMap.set(otherBoxs, []);
let groupEn = obj.Object as Entity;
if (groupEn instanceof Board)
{
if (roomName !== groupEn.BoardProcessOption.roomName)
continue;
}
else if (groupEn instanceof HardwareCompositeEntity || groupEn instanceof HardwareTopline)
{
if (roomName !== groupEn.HardwareOption.roomName)
continue;
}
arrayRemoveIf(ents, (en) =>
{
if (en === groupEn)
{
group.add(en);
alreadyAllocated.add(en);
return true;
}
});
arrayRemoveIf(others, (en) =>
{
if (en === groupEn)
{
group.add(en);
alreadyAllocated.add(en);
return true;
}
});
}
}
}
}
//出图附加条件
if (groupType === GroupByType.y) //同Y轴柜体合并
{
let boxs = Array.from(box2EntMap.keys());
boxs.sort((box1, box2) => box1.min.x - box2.min.x);
while (boxs.length > 1)
//计算包围盒
for (let [str, ents] of roomNameEntsMap)
{
let firstBox = boxs[0];
boxs.shift();
arrayRemoveIf(boxs, (box) => this.checkBoxOnY(firstBox, box, box2EntMap));
let box = new Box3Ext();
for (let ent of ents)
box.union(ent.BoundingBox);
box2EntMap.set(box, Array.from(ents));
}
//分配剩余others实体
if (others.length)
{
box2EntMap = new Map(Array.from(box2EntMap).sort((b1, b2) => { return b1[0].Volume - b2[0].Volume; }));
//将标注 文字 模型 SweepSolid 对象加入编组
for (let [box, entitys] of box2EntMap)
{
arrayRemoveIf(others, (ent) =>
{
let box3 = ent.BoundingBox as Box3Ext;
//容差100 考虑到标注离得较远
if (box3.intersectsBox(box, 100))
{
entitys.push(ent);
return true;
}
});
}
}
}
else if (groupType === GroupByType.roomName) //默认一个块里面都是同一个房名(不会有人会做房名不一样的吧)
else
{
let boxs = Array.from(box2EntMap.keys());
boxs.sort((box1, box2) => box1.min.x - box2.min.x);
while (boxs.length > 1)
box2EntMap = GroupEntitysByBox(ents);
//文字 标注 曲线
othersBox2EntMap = GroupEntitysByBox(others);
//将标注 文字对象加入编组
for (let [box, entitys] of box2EntMap)
{
for (let [otherBoxs, otherEntitys] of othersBox2EntMap)
{
if (!otherBoxs.isEmpty() && otherEntitys.length)
{
//容差100 考虑到标注离得较远
if (box.intersectsBox(otherBoxs, 100))
{
arrayPushArray(entitys, otherEntitys);
othersBox2EntMap.set(otherBoxs, []);
}
}
}
}
//出图附加条件
if (groupType === GroupByType.y) //同Y轴柜体合并
{
let firstBox = boxs[0];
boxs.shift();
arrayRemoveIf(boxs, (box) => this.checkBoxbyRoomName(firstBox, box, box2EntMap));
let boxs = Array.from(box2EntMap.keys());
boxs.sort((box1, box2) => box1.min.x - box2.min.x);
while (boxs.length > 1)
{
let firstBox = boxs[0];
boxs.shift();
arrayRemoveIf(boxs, (box) => this.checkBoxOnY(firstBox, box, box2EntMap));
}
}
}

Loading…
Cancel
Save