diff --git a/src/Add-on/Viewport/OneKeyLayout.ts b/src/Add-on/Viewport/OneKeyLayout.ts index 8b995960a..24322555d 100644 --- a/src/Add-on/Viewport/OneKeyLayout.ts +++ b/src/Add-on/Viewport/OneKeyLayout.ts @@ -1,7 +1,7 @@ import { Intent } from "@blueprintjs/core"; import { Box3, Matrix4, Object3D, Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; -import { arrayRemoveIf } from "../../Common/ArrayExt"; +import { arrayPushArray, arrayRemoveIf } from "../../Common/ArrayExt"; import { EBoardKeyList } from "../../Common/BoardKeyList"; import { IRectInfo, IsRect } from "../../Common/CurveUtils"; import { GroupEntitysByBox } from "../../Common/GroupEntitysByBox"; @@ -13,10 +13,8 @@ import { Sleep } from "../../Common/Sleep"; import { inflateBase64 } from "../../Common/inflate"; import { Hole } from "../../DatabaseServices/3DSolid/Hole"; import { SweepSolid } from "../../DatabaseServices/3DSolid/SweepSolid"; -import { AlignedDimension } from "../../DatabaseServices/Dimension/AlignedDimension"; import { Board } from "../../DatabaseServices/Entity/Board"; import { CompositeEntity } from "../../DatabaseServices/Entity/CompositeEntity"; -import { Curve } from "../../DatabaseServices/Entity/Curve"; import { Entity } from "../../DatabaseServices/Entity/Entity"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { FileServer } from "../../DatabaseServices/FileServer"; @@ -247,10 +245,11 @@ export class OneKeyLayout implements Command else return; } + //板、复合实体、模型 let ents: Entity[] = []; - let hideEntitys: Entity[] = []; //隐藏的实体 用来判断把手是不是跟它们有关系 隐藏门板或者隐藏抽屉时把手一起隐藏 + //文字 标注 曲线 其他(不包括Hole、墙 天花板 地板 地脚线) let others: Entity[] = []; - let modelSpaceTexts: Text[] = []; + let hideEntitys: Entity[] = []; //隐藏的实体 用来判断把手是不是跟它们有关系 隐藏门板或者隐藏抽屉时把手一起隐藏 for (let en of app.Database.ModelSpace.Entitys) { @@ -265,8 +264,6 @@ export class OneKeyLayout implements Command } else if (en instanceof CompositeEntity || en instanceof SweepSolid || IsModel(en)) ents.push(en); - else if (en instanceof Text) - modelSpaceTexts.push(en); else if (!(en instanceof Hole || IsRoomBase(en))) //一键布局都隐藏户型 others.push(en); } @@ -275,7 +272,7 @@ export class OneKeyLayout implements Command } } - if (ents.length === 0) + if (!ents.length) { AppToaster.show({ message: "没有找到柜体!", @@ -284,81 +281,54 @@ export class OneKeyLayout implements Command }); return; } - const ocsInv = app.Editor.UCSMatrixInv; - - let box2entitys_map = GroupEntitysByBox(ents); - - const gourpedEntitys = new WeakSet();//已经归属的实体 - let boxMap = new WeakMap(); + //板、复合实体、模型 + let box2EntMap = GroupEntitysByBox(ents); + //文字 标注 曲线 + let othersBox2EntMap = GroupEntitysByBox(others); //将标注 文字对象加入编组 - for (let [box, entitys] of box2entitys_map) + for (let [box, entitys] of box2EntMap) { - for (let en of others) + for (let [otherBoxs, otherEntitys] of othersBox2EntMap) { - if (gourpedEntitys.has(en)) continue; - let enBox = boxMap.get(en); - if (!enBox) - { - enBox = en.BoundingBox as Box3Ext; - boxMap.set(en, enBox); - } - - if (!enBox.isEmpty()) + if (!otherBoxs.isEmpty() && otherEntitys.length) { - if (en instanceof AlignedDimension) + //容差100 考虑到标注离得较远 + if (box.intersectsBox(otherBoxs, 100)) { - let dist = box.distanceToPoint(en.FootP1.applyMatrix4(ocsInv)); - if (dist <= 100) - { - gourpedEntitys.add(en); - entitys.push(en); - } - } - else if (box.intersectsBox(enBox.clone().applyMatrix4(ocsInv))) - { - gourpedEntitys.add(en); - entitys.push(en); - if (!(en instanceof Curve)) - box.union(enBox); + arrayPushArray(entitys, otherEntitys); + othersBox2EntMap.set(otherBoxs, []); } } } - - //字体文本跟随 - let ensBox = new Box3(); - for (let en of entitys) - ensBox.union(en.BoundingBox); - - for (let text of modelSpaceTexts) - if (ensBox.containsBox(text.BoundingBox) || ensBox.intersectsBox(text.BoundingBox)) - entitys.push(text); } + //出图附加条件 if (groupType === GroupByType.y) //同Y轴柜体合并 { - let boxs = Array.from(box2entitys_map.keys()); + 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, box2entitys_map)); + arrayRemoveIf(boxs, (box) => this.checkBoxOnY(firstBox, box, box2EntMap)); } } else if (groupType === GroupByType.roomName) //默认一个块里面都是同一个房名(不会有人会做房名不一样的吧) { - let boxs = Array.from(box2entitys_map.keys()); + 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.checkBoxbyRoomName(firstBox, box, box2entitys_map)); + arrayRemoveIf(boxs, (box) => this.checkBoxbyRoomName(firstBox, box, box2EntMap)); } } + //根据图框生成视口 const Total_Length = tkWidth * 9 / 8; let left = 600; let bottom = 230; @@ -385,7 +355,7 @@ export class OneKeyLayout implements Command Entity.__ReadFileIng__ = true; //按X轴顺序出图 - box2entitys_map = new Map([...box2entitys_map].sort((a, b) => a[0].min.x - b[0].min.x)); + box2EntMap = new Map([...box2EntMap].sort((a, b) => a[0].min.x - b[0].min.x)); let moveUpDistance = 0; let allEnt: Entity[] = []; @@ -403,8 +373,9 @@ export class OneKeyLayout implements Command moveUpDistance = 100 + curvesBox.max.y; } + //图框信息解析 let i = 0; - for (let [, bs] of box2entitys_map) + for (let [, bs] of box2EntMap) { let g = new GroupRecord(); g.Name = "图框"; @@ -431,7 +402,7 @@ export class OneKeyLayout implements Command if (pagTexts.has(c)) { let text = cloneC as Text; - text.TextString = `第 ${i + 1} 页/共${box2entitys_map.size}页`; + text.TextString = `第 ${i + 1} 页/共${box2EntMap.size}页`; if (!(cloneC).TextString) continue; }