From 9cd286359015b9f1c904342631f2841463014279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=89?= <940119273@qq.com> Date: Thu, 7 Dec 2023 12:35:31 +0000 Subject: [PATCH] =?UTF-8?q?!2497=20=E5=BC=80=E5=8F=91:=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=94=BB=E9=97=A8=E6=97=B6=E9=93=B0=E9=93=BE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawBoard/DrawDoorDrawer/DrawDoorTool.ts | 110 +++-- .../DrawDoorDrawer/DrawLeftRightOpenDoor.ts | 124 ++--- .../DrawDoorDrawer/DrawUpDownOpenDoor.ts | 120 ++--- .../Template/TemplateDrawHingeTool.ts | 425 +++++++++++------- 4 files changed, 387 insertions(+), 392 deletions(-) diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts index 02783198b..b31902311 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts @@ -8,7 +8,6 @@ import { DuplicateRecordCloning } from "../../../Common/Status"; import { safeEval } from "../../../Common/eval"; import { ExtrudeHole } from "../../../DatabaseServices/3DSolid/ExtrudeHole"; import { SweepSolid } from "../../../DatabaseServices/3DSolid/SweepSolid"; -import { CADObject } from "../../../DatabaseServices/CADObject"; import { Board } from "../../../DatabaseServices/Entity/Board"; import { BoardOpenDir, BoardType } from "../../../DatabaseServices/Entity/BoardInterface"; import { Entity } from '../../../DatabaseServices/Entity/Entity'; @@ -25,6 +24,7 @@ import { Box3Ext } from "../../../Geometry/Box"; import { equaln, isParallelTo } from "../../../Geometry/GeUtils"; import { OBB } from "../../../Geometry/OBB/obb"; import { ISpaceParse } from "../../../Geometry/SpaceParse/ISpaceParse"; +import { GetHingeType } from "../../../UI/Components/Template/TemplateDrawHingeTool"; import { AppToaster } from "../../../UI/Components/Toaster"; import { DoorStore, IHingeRule, openDirTitle } from "../../../UI/Store/DoorDrawerStore/DoorStore"; import { DisableChangeParName, DoorOpenDir, HandleHorPos, HandleVePos, IDoorConfigOption, IDoorInfo } from "../../../UI/Store/DoorInterface"; @@ -337,8 +337,8 @@ export class DrawDoorTool } } } - // hingeTypes[0]绑定左开门或上开门 hingeTypes[1]绑定右开门或下开门 - protected GetHingeTemp(info: IDoorInfo, door: TemplateRecord, hingeTypes: HingeType[]) + + protected GetHingeTemp(info: IDoorInfo, door: TemplateRecord) { if (info.tempInfo.hingeTemp && info.tempInfo.hingeTemp.id && this._idTempMap.has(info.tempInfo.hingeTemp.id)) { @@ -349,8 +349,6 @@ export class DrawDoorTool let count = this.option.hingeCount; const isLROpen = info.openDir === DoorOpenDir.Left || info.openDir === DoorOpenDir.Right; - let hingeName = (info.openDir === DoorOpenDir.Left || info.openDir === DoorOpenDir.Top) ? hingeTypes[0] : hingeTypes[1]; - let zExpr = ""; let jlsjExpr = "___JLSJ"; let jlxjExpr = "___JLXJ"; @@ -410,10 +408,7 @@ export class DrawDoorTool { let hinge = objId.Object; if (hinge instanceof HardwareCompositeEntity) - { - hinge.HardwareOption.name = hingeName; this.hingeSet.add(objId); - } } temp.HParam.expr = "0"; temp.LParam.expr = "0"; @@ -553,6 +548,7 @@ export class DrawDoorTool { let boards: Board[] = []; let doors: Entity[] = []; + let relativeDoors = new Set(); //有被铰链关联的门板 let ironwareEnts: HardwareCompositeEntity[] = []; //五金 let hardwareCompositeEnts: Entity[] = [];//除铰链和把手以外的复合实体 let layerBoards: Entity[] = []; //层板 左右门板判断铰链碰撞 @@ -609,17 +605,13 @@ export class DrawDoorTool let doorWidth = doorSize.x; let doorHight = doorSize.z; - let brBoxCache: Map = new Map(); - + let moveFail = false; let needUpdate = false; - + let brBoxCache: Map = new Map(); let parseTypedHinges = new Set();//已经设置了铰链的类型的铰链 let hingeTr2Size_Map = new Map();//铰链模板存在编组情况 (铰链模块id->尺寸) - let br2GrooveOutlinesCache = new Map();//板->板上的槽的轮廓缓存(在WCS0中) - let moveFail = false; - const allOtherEntitys = hardwareCompositeEnts.concat(boards);//除了拉手和铰链以外的板和复合实体 for (let ironware of ironwareEnts) @@ -654,7 +646,7 @@ export class DrawDoorTool } //铰链Z轴延伸 与其他实体相交判断 - if (IsBoxAndEntitysIntersect([br], [ironware], ZNormal)) + if (IsBoxAndEntitysIntersect([br], [ironware], ZNormal, isDoor)) { const center = ironBox.getCenter(new Vector3).applyMatrix4(br.OCSInv).setZ(0); if (grooveOutlines.some(c => c.PtInCurve(center)))//五金的中心在造型内部 @@ -703,18 +695,20 @@ export class DrawDoorTool } br.RelativeHardware.push(ironware.Id); ironware.RelevanceBoards.push(br.Id); + if (isDoor) relativeDoors.add(br); } } else if (otherEnt instanceof HardwareCompositeEntity) //层板复合实体 铰链偏移 { if (!IsHinge(ironware)) continue; - if (!IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal)) continue; + if (!IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal, isDoor)) continue; if (isDoor) { //铰链归属复合门板 ironware.RelevanceBoards.push(otherEnt.Id); otherEnt.RelevanceHardware.push(ironware.Id); + relativeDoors.add(otherEnt); continue; } let hingeTr = ironware.Template.Object as TemplateRecord;//铰链模块 @@ -754,7 +748,7 @@ export class DrawDoorTool intent: Intent.DANGER, }); - // SetNoPareTypeHigneName(parseTypedHinges, this.hingeSet); + SetTypeHigneName(relativeDoors, allOtherEntitys, !isUpDownDoor); return needUpdate; } @@ -944,7 +938,7 @@ export class DrawDoorTool let intersect = false; if (box1Info + (isUpDownDoor ? 10 : 100) < doorSpecs) { - if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, false, translate)) intersect = true; } else @@ -978,7 +972,7 @@ export class DrawDoorTool let intersect = false; if (box2Info - (isUpDownDoor ? 10 : 100) > 0) { - if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, false, translate)) intersect = true; } else @@ -1024,25 +1018,72 @@ export class DrawDoorTool * @param parseTypedHinges 已经解析了类型的铰链 * @param hingeSet */ -export function SetNoPareTypeHigneName(parseTypedHinges: Set>, hingeSet: Set>): void +export function SetTypeHigneName(relativeDoors: Set, allSpaceEnts: Entity[], isLROpen: boolean): void { - for (let e of hingeSet) + for (let door of relativeDoors) { - if (!parseTypedHinges.has(e)) + let openDir = BoardOpenDir.Left; + if (door instanceof Board) { - let ironware = e.Object as HardwareCompositeEntity; - let temp = ironware.Template?.Object as TemplateRecord; - if (temp?.AllEntitys.length > 1 && !ironware.HardwareOption.name.includes("铰链"))//新增了这个 如果没有铰链就不设置为无盖铰链? - continue; - ironware.HardwareOption.name = "无盖铰链"; + openDir = door.OpenDir; + let hingeName = GetHingeType(door, openDir, allSpaceEnts, isLROpen); + for (let obj of door.RelativeHardware) + { + let hinge = obj.Object as HardwareCompositeEntity; + if (IsHinge(hinge)) + hinge.HardwareOption.name = hingeName; + } + } + else if (door instanceof HardwareCompositeEntity) + { + if (door.Template) + { + let temp = door.Template.Object as TemplateRecord; + if (temp.Parent) + { + const tempSpace = temp.Parent.Object as TemplateRecord; + if (tempSpace.Name === "门板空间") + { + let doorGroup = tempSpace.Parent.Object as TemplateRecord; + let zkmPar = doorGroup.GetParam("ZKM"); + if (zkmPar) + { + openDir = zkmPar.value === 1 ? BoardOpenDir.Left : BoardOpenDir.Right; + } + else + { + let skmPar = doorGroup.GetParam("SKM"); + if (skmPar) + openDir = skmPar.value === 1 ? BoardOpenDir.Up : BoardOpenDir.Down; + } + } + } + let hingeName = GetHingeType(door, openDir, allSpaceEnts, isLROpen); + for (let obj of door.RelevanceHardware) + { + let hinge = obj.Object as HardwareCompositeEntity; + if (IsHinge(hinge)) + hinge.HardwareOption.name = hingeName; + } + } } } } -//OBB增加10容差 -export function getFuzzOBB(obb: OBB, normalizeZ: Vector3, parentIntersectEntOCS: Matrix4, isExtrudeSolid: boolean): OBB +/** + * + * + * @export + * @param {OBB} obb + * @param {Vector3} normalizeZ + * @param {Matrix4} parentIntersectEntOCS + * @param {boolean} isExtrudeSolid + * @param {boolean} isDoor 门板类型不增加误差值 + * @return {*} {OBB} + */ +export function getFuzzOBB(obb: OBB, normalizeZ: Vector3, parentIntersectEntOCS: Matrix4, isExtrudeSolid: boolean, isDoor: boolean): OBB { - let addSize = new Vector3(-0.1, -0.1, 10); + let addSize = isDoor ? new Vector3() : new Vector3(-0.1, -0.1, 10); if (!isExtrudeSolid) addSize.applyMatrix4(parentIntersectEntOCS.clone().setPosition(0, 0, 0)); let halfSizes = obb.halfSizes.add(addSize.applyMatrix4((obb.ocs).clone().setPosition(0, 0, 0))); @@ -1075,9 +1116,10 @@ export function getFuzzOBB(obb: OBB, normalizeZ: Vector3, parentIntersectEntOCS: * @param intersectEnts 这里规定是铰链列表 * @param parentOCS 父空间的坐标系 * @param ZNormal 铰链Z向量方向 + * @param isDoor 门板类型不参与obb误差计算 * @param translate checkEnts偏移 */ -export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Entity[], ZNormal: Vector3, translate?: Vector3, parentIntersectEntOCS?: Matrix4, parentcheckEntOCS?: Matrix4): boolean +export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Entity[], ZNormal: Vector3, isDoor?: boolean, translate?: Vector3, parentIntersectEntOCS?: Matrix4, parentcheckEntOCS?: Matrix4): boolean { for (let checkEnt of checkEnts) if (checkEnt instanceof HardwareCompositeEntity) @@ -1086,7 +1128,7 @@ export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Ent if (parentcheckEntOCS) ocs = new Matrix4().multiplyMatrices(parentcheckEntOCS, ocs); let ents = checkEnt.Entitys.filter(ent => ent instanceof ExtrudeHole || ent instanceof SweepSolid || ent instanceof ExtrudeSolid || ent instanceof HardwareCompositeEntity); - if (IsBoxAndEntitysIntersect(ents, intersectEnts, ZNormal, translate, undefined, ocs)) + if (IsBoxAndEntitysIntersect(ents, intersectEnts, ZNormal, isDoor, translate, undefined, ocs)) return true; } else @@ -1101,7 +1143,7 @@ export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Ent let ocs = intersectEnt.OCS; if (parentIntersectEntOCS) ocs = new Matrix4().multiplyMatrices(parentIntersectEntOCS, ocs); let ents = intersectEnt.Entitys.filter(ent => ent instanceof ExtrudeHole || ent instanceof SweepSolid || ent instanceof ExtrudeSolid || ent instanceof HardwareCompositeEntity); - if (IsBoxAndEntitysIntersect([newCheckEnt], ents, ZNormal, translate, ocs)) + if (IsBoxAndEntitysIntersect([newCheckEnt], ents, ZNormal, isDoor, translate, ocs)) return true; } else @@ -1110,7 +1152,7 @@ export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Ent if (parentIntersectEntOCS) ent.ApplyMatrix(parentIntersectEntOCS); if (translate) ent.ApplyMatrix(new Matrix4().setPosition(translate)); - let obb = getFuzzOBB(newCheckEnt.OBB, ZNormal, parentIntersectEntOCS, newCheckEnt instanceof ExtrudeSolid); + let obb = getFuzzOBB(newCheckEnt.OBB, ZNormal, parentIntersectEntOCS, newCheckEnt instanceof ExtrudeSolid, isDoor); if (obb.intersectsOBB(ent.OBB)) return true; } diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts index 8e6f5e0fb..f79756012 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts @@ -1,5 +1,4 @@ import { Intent } from "@blueprintjs/core"; -import { Vector3 } from "three"; import { app } from "../../../ApplicationServices/Application"; import { EBoardKeyList } from "../../../Common/BoardKeyList"; import { Board } from "../../../DatabaseServices/Entity/Board"; @@ -9,7 +8,6 @@ import { TemplateSizeBoard } from "../../../DatabaseServices/Template/ProgramTem import { SetTemplatePositionAndSetParent } from "../../../DatabaseServices/Template/TempateUtils"; import { TemplateRecord } from "../../../DatabaseServices/Template/TemplateRecord"; import { TemplateSplitType } from "../../../DatabaseServices/Template/TemplateType"; -import { isParallelTo } from "../../../Geometry/GeUtils"; import { AppToaster } from "../../../UI/Components/Toaster"; import { DoorOpenDir, IDoorInfo } from "../../../UI/Store/DoorInterface"; import { DrillType } from "../../DrawDrilling/DrillType"; @@ -40,93 +38,10 @@ export class DrawLeftRightOpenDoor extends DrawDoorTool cbHightDrillOption: { down: cbDrillDown, up: cbDrillUp, left: cbDrillLeft, right: cbDrillRight }, } = this.option; - //最左侧立板 - let leftParallelToXBoard: Board; - //最右侧立板 - let rightParallelToXBoard: Board; - - let spaceBox = this.spaceParse.SpaceBox.clone(); - const xNormal = new Vector3().setFromMatrixColumn(this.spaceParse.SpaceOCS, 0); - - let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); - - //计算与空间X向量平行的侧板 - for (let ent of spaceAllBoards) - { - if (ent instanceof Board) - { - let isParallelToX = isParallelTo(xNormal, ent.Normal); - let entBox = ent.GetBoundingBoxInMtx(this.spaceParse.SpaceOCSInv); - if (entBox.max.x - spaceBox.min.x <= 1e-2) - { - if (!leftParallelToXBoard && entBox.intersectsBox(spaceBox) && isParallelToX) - leftParallelToXBoard = ent; - } - else if (entBox.min.x - spaceBox.max.x >= -1e-2) - { - if (!rightParallelToXBoard && entBox.intersectsBox(spaceBox) && isParallelToX) - rightParallelToXBoard = ent; - } - } - } - - //每块门板组所在的左右侧板 - let leftBoard: Board = leftParallelToXBoard; - let rightBoard: Board; - - let ZGParam: number = this.option.leftExt - this.option.leftSpace; - let YGParam: number; - - //按列处理 for (let i = 0; i < col; i++) { let lValue = this.colWidths[i]; let colTemp = this.GetColTemplate(lValue, i); - let verTemp: TemplateRecord; - - //预先加载 补的立板 - if (i < col - 1) - { - verTemp = this.GetVerticalTemp(size.z, size.y - offset, thickness, !this.isDrawVerBrS[i], isAuto); - if (verTemp.Objects.length > 0) - { - verBoardIds.push(...verTemp.Objects); - let en = verTemp.Objects[0].Object as Board; - en.Name = verticalBoardName; - en.BoardProcessOption[EBoardKeyList.UpSealed] = lbSealedUp.toString(); - en.BoardProcessOption[EBoardKeyList.DownSealed] = lbSealedDown.toString(); - en.BoardProcessOption[EBoardKeyList.LeftSealed] = lbSealedLeft.toString(); - en.BoardProcessOption[EBoardKeyList.RightSealed] = lbSealedRight.toString(); - en.BoardProcessOption.highDrill = [lbDrillDown, lbDrillRight, lbDrillUp, lbDrillLeft]; - let drillSet = new Set(en.BoardProcessOption.highDrill); - if (drillSet.size > 1) - en.BoardProcessOption.drillType = DrillType.More; - else if (drillSet.size === 1) - en.BoardProcessOption.drillType = en.BoardProcessOption.highDrill[0]; - if (this.surroundOption && useBoardProcessOption) - { - en.BoardProcessOption[EBoardKeyList.RoomName] = this.surroundOption[EBoardKeyList.RoomName]; - en.BoardProcessOption[EBoardKeyList.CabinetName] = this.surroundOption[EBoardKeyList.CabinetName]; - en.BoardProcessOption[EBoardKeyList.Mat] = this.surroundOption[EBoardKeyList.Mat]; - en.BoardProcessOption[EBoardKeyList.BrMat] = this.surroundOption[EBoardKeyList.BrMat]; - en.BoardProcessOption[EBoardKeyList.Color] = this.surroundOption[EBoardKeyList.Color]; - } - - //使用补的立板当作右侧板 - rightBoard = en; - YGParam = rightBoard.Thickness / 2 - this.option.midSpace / 2; - } - else - rightBoard = undefined; - } - else - { - rightBoard = rightParallelToXBoard; - YGParam = this.option.rightExt - this.option.rightSpace; - } - - let leftOpenDirType = this.GetHingeType(leftBoard?.Thickness, ZGParam); - let rightOpenDirType = this.GetHingeType(rightBoard?.Thickness, YGParam); for (let j = 0; j < row; j++) { @@ -136,10 +51,9 @@ export class DrawLeftRightOpenDoor extends DrawDoorTool let hasLayerDown = j === 0 ? this.isDrawLayBrS[j + 1] : this.isDrawLayBrS[j]; let rowTemplate = this.GetRowTemplate(info, this.rowHeighs[j], hasLayerDown, this.isDrawLayBrS[j + 1]); - isWarnHingeRules = this.GetHingeTemp(info, rowTemplate, [leftOpenDirType, rightOpenDirType]) || isWarnHingeRules; + isWarnHingeRules = this.GetHingeTemp(info, rowTemplate) || isWarnHingeRules; colTemp.Children.push(rowTemplate.Id); - //补层板 if (j < row - 1) { if (this.isDrawLayBrS[j + 1]) @@ -172,21 +86,37 @@ export class DrawLeftRightOpenDoor extends DrawDoorTool } } } + } - //添加占位空间或者层板 templateSpace.Children.push(colTemp.Id); - - //添加占位空间或者立板 立板的话绑定左侧板 - if (verTemp) + if (i < col - 1) { - templateSpace.Children.push(verTemp.Id); + let verTemp = this.GetVerticalTemp(size.z, size.y - offset, thickness, !this.isDrawVerBrS[i], isAuto); if (verTemp.Objects.length > 0) { - leftBoard = verTemp.Objects[0].Object as Board; - ZGParam = leftBoard.Thickness / 2 - this.option.midSpace / 2; + verBoardIds.push(...verTemp.Objects); + let en = verTemp.Objects[0].Object as Board; + en.Name = verticalBoardName; + en.BoardProcessOption[EBoardKeyList.UpSealed] = lbSealedUp.toString(); + en.BoardProcessOption[EBoardKeyList.DownSealed] = lbSealedDown.toString(); + en.BoardProcessOption[EBoardKeyList.LeftSealed] = lbSealedLeft.toString(); + en.BoardProcessOption[EBoardKeyList.RightSealed] = lbSealedRight.toString(); + en.BoardProcessOption.highDrill = [lbDrillDown, lbDrillRight, lbDrillUp, lbDrillLeft]; + let drillSet = new Set(en.BoardProcessOption.highDrill); + if (drillSet.size > 1) + en.BoardProcessOption.drillType = DrillType.More; + else if (drillSet.size === 1) + en.BoardProcessOption.drillType = en.BoardProcessOption.highDrill[0]; + if (this.surroundOption && useBoardProcessOption) + { + en.BoardProcessOption[EBoardKeyList.RoomName] = this.surroundOption[EBoardKeyList.RoomName]; + en.BoardProcessOption[EBoardKeyList.CabinetName] = this.surroundOption[EBoardKeyList.CabinetName]; + en.BoardProcessOption[EBoardKeyList.Mat] = this.surroundOption[EBoardKeyList.Mat]; + en.BoardProcessOption[EBoardKeyList.BrMat] = this.surroundOption[EBoardKeyList.BrMat]; + en.BoardProcessOption[EBoardKeyList.Color] = this.surroundOption[EBoardKeyList.Color]; + } } - else - leftBoard = undefined; + templateSpace.Children.push(verTemp.Id); } } @@ -203,7 +133,7 @@ export class DrawLeftRightOpenDoor extends DrawDoorTool await SetTemplatePositionAndSetParent(this.spaceParse, templateSpace); - spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); + let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, false); if (needReUpdate) diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts index f8d8ec676..9cea16ab8 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts @@ -1,5 +1,4 @@ import { Intent } from "@blueprintjs/core"; -import { Vector3 } from "three"; import { app } from "../../../ApplicationServices/Application"; import { EBoardKeyList } from "../../../Common/BoardKeyList"; import { Board } from "../../../DatabaseServices/Entity/Board"; @@ -9,7 +8,6 @@ import { TemplateSizeBoard } from "../../../DatabaseServices/Template/ProgramTem import { SetTemplatePositionAndSetParent } from "../../../DatabaseServices/Template/TempateUtils"; import { TemplateRecord } from "../../../DatabaseServices/Template/TemplateRecord"; import { TemplateSplitType } from "../../../DatabaseServices/Template/TemplateType"; -import { isParallelTo } from "../../../Geometry/GeUtils"; import { AppToaster } from "../../../UI/Components/Toaster"; import { DoorOpenDir, IDoorInfo } from "../../../UI/Store/DoorInterface"; import { DrillType } from "../../DrawDrilling/DrillType"; @@ -39,92 +37,10 @@ export class DrawUpDownOpenDoor extends DrawDoorTool cbHightDrillOption: { down: cbDrillDown, up: cbDrillUp, left: cbDrillLeft, right: cbDrillRight }, } = this.option; - //最上面层板 - let topParallelToXBoard: Board; - //最下面层板 - let bottomParallelToXBoard: Board; - - let spaceBox = this.spaceParse.SpaceBox.clone(); - const zNormal = new Vector3().setFromMatrixColumn(this.spaceParse.SpaceOCS, 2); - - let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); - - //计算与空间X向量平行的侧板 - for (let ent of spaceAllBoards) - { - if (ent instanceof Board) - { - const isParallelToZ = isParallelTo(zNormal, ent.Normal); - let entBox = ent.GetBoundingBoxInMtx(this.spaceParse.SpaceOCSInv); - if (entBox.min.z - spaceBox.max.z >= -1e-3) - { - if (!topParallelToXBoard && entBox.intersectsBox(spaceBox) && isParallelToZ) - topParallelToXBoard = ent; - } - else if (spaceBox.min.z - entBox.max.z >= -1e-3) - { - if (!bottomParallelToXBoard && entBox.intersectsBox(spaceBox) && zNormal) - bottomParallelToXBoard = ent; - } - } - } - - //每块门板组所在的上下层板 - let topBoard: Board = topParallelToXBoard; - let bottomBoard: Board = bottomParallelToXBoard; - - let SGParam: number = this.option.topExt - this.option.topSpace; - let XGParam: number = this.option.bottomExt - this.option.bottomSpace; - for (let i = 0; i < row; i++) { let lValue = this.rowHeighs[i]; let rowTemp = this.GetRowTemplate(lValue, i); - let layerTemp: TemplateRecord; - - //预先加载 补的层板 - if (i < row - 1) - { - layerTemp = this.GetLayerTemp(size.y, size.x, thickness, !this.isDrawLayBrS[i + 1], isAuto); - if (layerTemp.Objects.length > 0) - { - layBoardIds.push(...layerTemp.Objects); - let en = layerTemp.Objects[0].Object as Board; - en.Name = layerBoardName; - en.BoardProcessOption[EBoardKeyList.UpSealed] = topBrSeal.toString(); - en.BoardProcessOption[EBoardKeyList.DownSealed] = bottomBrSeal.toString(); - en.BoardProcessOption[EBoardKeyList.LeftSealed] = leftBrSeal.toString(); - en.BoardProcessOption[EBoardKeyList.RightSealed] = rightBrSeal.toString(); - en.BoardProcessOption.highDrill = [cbDrillDown, cbDrillRight, cbDrillUp, cbDrillLeft]; - let drillSet = new Set(en.BoardProcessOption.highDrill); - if (drillSet.size > 1) - en.BoardProcessOption.drillType = DrillType.More; - else if (drillSet.size === 1) - en.BoardProcessOption.drillType = en.BoardProcessOption.highDrill[0]; - if (this.surroundOption && useBoardProcessOption) - { - en.BoardProcessOption[EBoardKeyList.RoomName] = this.surroundOption[EBoardKeyList.RoomName]; - en.BoardProcessOption[EBoardKeyList.CabinetName] = this.surroundOption[EBoardKeyList.CabinetName]; - en.BoardProcessOption[EBoardKeyList.Mat] = this.surroundOption[EBoardKeyList.Mat]; - en.BoardProcessOption[EBoardKeyList.BrMat] = this.surroundOption[EBoardKeyList.BrMat]; - en.BoardProcessOption[EBoardKeyList.Color] = this.surroundOption[EBoardKeyList.Color]; - } - - //使用补的层板当作上层板 - topBoard = en; - SGParam = topBoard.Thickness / 2 - this.option.midSpace / 2; - } - else - topBoard = undefined; - } - else - { - topBoard = topParallelToXBoard; - SGParam = this.option.topExt - this.option.topSpace; - } - - let topOpenDirType = this.GetHingeType(topBoard?.Thickness, SGParam); - let bottomOpenDirType = this.GetHingeType(bottomBoard?.Thickness, XGParam); for (let j = 0; j < col; j++) { @@ -135,7 +51,7 @@ export class DrawUpDownOpenDoor extends DrawDoorTool let hasVerRight = j === col - 1 ? this.isDrawVerBrS[j - 1] : this.isDrawVerBrS[j]; let colTemplate = this.GetColTemplate(info, this.colWidths[j], hasVerLeft, hasVerRight); - isWarnHingeRules = this.GetHingeTemp(info, colTemplate, [topOpenDirType, bottomOpenDirType]) || isWarnHingeRules; + isWarnHingeRules = this.GetHingeTemp(info, colTemplate) || isWarnHingeRules; rowTemp.Children.push(colTemplate.Id); if (j < col - 1) @@ -172,20 +88,36 @@ export class DrawUpDownOpenDoor extends DrawDoorTool } } - //添加占位空间或者层板 templateSpace.Children.push(rowTemp.Id); - //添加占位空间或者层板 层板的话绑定上层板 - if (layerTemp) + if (i < row - 1) { - templateSpace.Children.push(layerTemp.Id); + let layerTemp = this.GetLayerTemp(size.y, size.x, thickness, !this.isDrawLayBrS[i + 1], isAuto); if (layerTemp.Objects.length > 0) { - bottomBoard = layerTemp.Objects[0].Object as Board; - XGParam = bottomBoard.Thickness / 2 - this.option.midSpace / 2; + layBoardIds.push(...layerTemp.Objects); + let en = layerTemp.Objects[0].Object as Board; + en.Name = layerBoardName; + en.BoardProcessOption[EBoardKeyList.UpSealed] = topBrSeal.toString(); + en.BoardProcessOption[EBoardKeyList.DownSealed] = bottomBrSeal.toString(); + en.BoardProcessOption[EBoardKeyList.LeftSealed] = leftBrSeal.toString(); + en.BoardProcessOption[EBoardKeyList.RightSealed] = rightBrSeal.toString(); + en.BoardProcessOption.highDrill = [cbDrillDown, cbDrillRight, cbDrillUp, cbDrillLeft]; + let drillSet = new Set(en.BoardProcessOption.highDrill); + if (drillSet.size > 1) + en.BoardProcessOption.drillType = DrillType.More; + else if (drillSet.size === 1) + en.BoardProcessOption.drillType = en.BoardProcessOption.highDrill[0]; + if (this.surroundOption && useBoardProcessOption) + { + en.BoardProcessOption[EBoardKeyList.RoomName] = this.surroundOption[EBoardKeyList.RoomName]; + en.BoardProcessOption[EBoardKeyList.CabinetName] = this.surroundOption[EBoardKeyList.CabinetName]; + en.BoardProcessOption[EBoardKeyList.Mat] = this.surroundOption[EBoardKeyList.Mat]; + en.BoardProcessOption[EBoardKeyList.BrMat] = this.surroundOption[EBoardKeyList.BrMat]; + en.BoardProcessOption[EBoardKeyList.Color] = this.surroundOption[EBoardKeyList.Color]; + } } - else - bottomBoard = undefined; + templateSpace.Children.push(layerTemp.Id); } } @@ -202,7 +134,7 @@ export class DrawUpDownOpenDoor extends DrawDoorTool await SetTemplatePositionAndSetParent(this.spaceParse, templateSpace); - spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); + let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, true); if (needReUpdate) diff --git a/src/UI/Components/Template/TemplateDrawHingeTool.ts b/src/UI/Components/Template/TemplateDrawHingeTool.ts index 40147eadd..9139835ce 100644 --- a/src/UI/Components/Template/TemplateDrawHingeTool.ts +++ b/src/UI/Components/Template/TemplateDrawHingeTool.ts @@ -146,7 +146,7 @@ export class TemplateDrawHingeTool const DrawHinge = (dist?: number, rule?: IHingeRule) => { - let hingeType = this.GetHingeType(door, openDir, allSpaceEnts, isLROpen); + let hingeType = GetHingeType(door, openDir, allSpaceEnts, isLROpen); for (let i = 0; i < count; i++) { if (hingestore.m_Option.useRule && !ParseRules(i, count, dist, rule)) continue; @@ -311,166 +311,6 @@ export class TemplateDrawHingeTool return [isLROpen, isWarn]; }; - private GetHingeType(door: Entity, openDir: BoardOpenDir, allSpaceEnts: Entity[], isLROpen: boolean): HingeType - { - const Positioning = (door.Template.Object as TemplateRecord).Positioning; - if (!Positioning) - { - Log("存在无效门板!"); - return; - } - const DoorSpaceBox = new Box3(new Vector3, Positioning.SpaceSize); - const DoorBox = DoorSpaceBox.clone().applyMatrix4(Positioning.SpaceCS); - - let isParallelToXYEnts = allSpaceEnts.filter(ent => - ent instanceof Board && - isParallelTo(ent.Normal, new Vector3().setFromMatrixColumn(Positioning.SpaceCS, isLROpen ? 0 : 2)) && - ent.BoundingBox.intersectsBox(DoorBox, 10) - ) as Board[]; - - let ocsInv = new Matrix4().getInverse(Positioning.SpaceCS); - - const hingeLidRule = userConfig.hingeLidRule; - - if (openDir === BoardOpenDir.Left) - { - let minX = DoorSpaceBox.min.x; - for (let ent of isParallelToXYEnts) - { - let entBox = ent.GetBoundingBoxInMtx(ocsInv); - - //防止关联无关侧板 - if (DoorSpaceBox.min.z - entBox.max.z > -100 || entBox.min.z - DoorSpaceBox.max.z > -100) continue; - - //盖过立板长度 - let passDoorExtend = entBox.min.x - minX; - //无盖距离值 - let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); - - //先判断半盖 - if (minX - entBox.min.x > FUZZ && entBox.max.x - minX - noLid > FUZZ) - { - let doorExtend = entBox.max.x - minX; - //全盖距离值 - let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); - - if (doorExtend - allLid < -FUZZ) - return "半盖铰链"; - else - return "全盖铰链"; - } - else if (passDoorExtend >= 0 && passDoorExtend < 30) - { - //盖过立板小于30的 认定为左侧板 - return "全盖铰链"; - } - } - return "无盖铰链"; - } - else if (openDir === BoardOpenDir.Right) - { - let maxX = DoorSpaceBox.max.x; - for (let ent of isParallelToXYEnts) - { - let entBox = ent.GetBoundingBoxInMtx(ocsInv); - - //防止关联无关侧板 - if (DoorSpaceBox.min.z - entBox.max.z > -100 || entBox.min.z - DoorSpaceBox.max.z > -100) continue; - - //盖过立板长度 - let passDoorExtend = maxX - entBox.max.x; - //无盖距离值 - let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); - - //先判断半盖 - if (maxX - entBox.min.x - noLid > FUZZ && entBox.max.x - maxX > FUZZ) - { - let doorExtend = maxX - entBox.min.x; - //全盖距离值 - let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); - if (doorExtend - allLid < -FUZZ) - return "半盖铰链"; - else - return "全盖铰链"; - } - else if (passDoorExtend >= 0 && passDoorExtend < 30) - { - //盖过立板小于30的 认定为右侧板 - return "全盖铰链"; - } - } - return "无盖铰链"; - } - else if (openDir === BoardOpenDir.Up) - { - let maxZ = DoorSpaceBox.max.z; - for (let ent of isParallelToXYEnts) - { - let entBox = ent.GetBoundingBoxInMtx(ocsInv); - - //防止关联无关层板 - if (DoorSpaceBox.min.x - entBox.max.x > -100 || entBox.min.x - DoorSpaceBox.max.x > -100) continue; - - //盖过立板长度 - let passDoorExtend = maxZ - entBox.max.z; - //无盖距离值 - let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); - - //先判断半盖 - if (maxZ - entBox.min.z - noLid > FUZZ && entBox.max.z - maxZ > FUZZ) - { - let doorExtend = maxZ - entBox.min.z; - //全盖距离值 - let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); - if (doorExtend - allLid < -FUZZ) - return "半盖铰链"; - else - return "全盖铰链"; - } - else if (passDoorExtend >= 0 && passDoorExtend < 30) - { - //盖过立板小于30的 认定为上层板 - return "全盖铰链"; - } - } - return "无盖铰链"; - } - else if (openDir === BoardOpenDir.Down) - { - let minZ = DoorSpaceBox.min.z; - for (let ent of isParallelToXYEnts) - { - let entBox = ent.GetBoundingBoxInMtx(ocsInv); - - //防止关联无关层板 - if (DoorSpaceBox.min.x - entBox.max.x > -100 || entBox.min.x - DoorSpaceBox.max.x > -100) continue; - - //盖过立板长度 - let passDoorExtend = entBox.min.z - minZ; - //无盖距离值 - let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); - - //先判断半盖 - if (minZ - entBox.min.z > -FUZZ && entBox.max.z - minZ - noLid > FUZZ) - { - let doorExtend = entBox.max.z - minZ; - //全盖距离值 - let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); - if (doorExtend - allLid < -FUZZ) - return "半盖铰链"; - else - return "全盖铰链"; - } - else if (passDoorExtend >= 0 && passDoorExtend < 30) - { - //盖过立板小于30的 认定为下层板 - return "全盖铰链"; - } - } - return "无盖铰链"; - } - }; - //设置五金(拉手 铰链)和板的关联切割 RelativeMetalsToBoard(allEntitys: Entity[], isLROpen: boolean, door: Board | HardwareCompositeEntity) { @@ -566,7 +406,7 @@ export class TemplateDrawHingeTool const isParallelToX = isParallelTo(xNormal, br.Normal); //门板/背板 不增加误差,防止误关联 - if (IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal)) + if (IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal, isDoor)) { const center = inventedBox.getCenter(new Vector3).applyMatrix4(br.OCSInv).setZ(0); if (grooveOutlines.some(c => c.PtInCurve(center))) @@ -611,7 +451,7 @@ export class TemplateDrawHingeTool { if (!IsHinge(ironware)) continue; - if (!IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal)) continue; + if (!IsBoxAndEntitysIntersect([otherEnt], [ironware], ZNormal, isDoor)) continue; if (isDoor) { @@ -677,7 +517,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box1Z + 100 < doorHight) { - if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, false, translate)) { intersect = true; } @@ -696,7 +536,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box2Z - 100 > 0) { - if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, false, translate)) intersect = true; } else intersect = true; @@ -725,7 +565,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box1Z + 100 < doorHight) { - if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, false, translate)) intersect = true; } else intersect = true; @@ -742,7 +582,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box2Z - 100 > 0) { - if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, translate)) + if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, false, translate)) intersect = true; } else intersect = true; @@ -763,3 +603,254 @@ export class TemplateDrawHingeTool } } } + +export function GetHingeType(door: Entity, openDir: BoardOpenDir, allSpaceEnts: Entity[], isLROpen: boolean): HingeType +{ + const Positioning = (door.Template?.Object as TemplateRecord)?.Positioning; + if (!Positioning) + { + Log("存在无效门板!"); + return; + } + const DoorSpaceBox = new Box3(new Vector3, Positioning.SpaceSize); + const DoorBox = DoorSpaceBox.clone().applyMatrix4(Positioning.SpaceCS); + + let isParallelToXYEnts = allSpaceEnts.filter(ent => + ent instanceof Board && + isParallelTo(ent.Normal, new Vector3().setFromMatrixColumn(Positioning.SpaceCS, isLROpen ? 0 : 2)) && + ent.BoundingBox.intersectsBox(DoorBox, 10) + ) as Board[]; + + let ocsInv = new Matrix4().getInverse(Positioning.SpaceCS); + + const hingeLidRule = userConfig.hingeLidRule; + + //门板 + let minDist = Infinity; + let minDistType: HingeType = "无盖铰链"; + + if (openDir === BoardOpenDir.Left) + { + let minX = DoorSpaceBox.min.x; + for (let ent of isParallelToXYEnts) + { + let entBox = ent.GetBoundingBoxInMtx(ocsInv); + + //防止关联无关侧板 + if (entBox.getSize(new Vector3).z < DoorSpaceBox.max.z / 2) continue; //过滤掉小于门板高度一半(抽测板) + if (DoorSpaceBox.min.z - entBox.max.z > -100 || entBox.min.z - DoorSpaceBox.max.z > -100) continue; + + //无盖距离值 + let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); + + //先判断半盖 + if (minX - entBox.min.x > FUZZ && entBox.max.x - minX - noLid > FUZZ) + { + let doorExtend = entBox.max.x - minX; + //全盖距离值 + let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); + + if (doorExtend - allLid < -FUZZ) + return "半盖铰链"; + else + return "全盖铰链"; + } + else + { + //盖过立板长度 + let passDoorExtend = entBox.min.x - minX; + let noPassDoorExtend = minX - entBox.max.x; + + if (passDoorExtend > -FUZZ) + { + if (minDist > passDoorExtend) + { + minDist = passDoorExtend; + minDistType = "全盖铰链"; + } + } + else + { + if (minDist > noPassDoorExtend) + { + minDist = passDoorExtend; + minDistType = "无盖铰链"; + } + } + } + } + + if (minDist >= -FUZZ && minDist < 30) + return minDistType; + else + return "无盖铰链"; + } + else if (openDir === BoardOpenDir.Right) + { + let maxX = DoorSpaceBox.max.x; + for (let ent of isParallelToXYEnts) + { + let entBox = ent.GetBoundingBoxInMtx(ocsInv); + + //防止关联无关侧板 + if (entBox.getSize(new Vector3).z < DoorSpaceBox.max.z / 2) continue; //过滤掉小于门板高度一半(抽测板) + if (DoorSpaceBox.min.z - entBox.max.z > -100 || entBox.min.z - DoorSpaceBox.max.z > -100) continue; + + //无盖距离值 + let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); + + //先判断半盖 + if (maxX - entBox.min.x - noLid > FUZZ && entBox.max.x - maxX > FUZZ) + { + let doorExtend = maxX - entBox.min.x; + //全盖距离值 + let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); + if (doorExtend - allLid < -FUZZ) + return "半盖铰链"; + else + return "全盖铰链"; + } + else + { + //盖过立板长度 + let passDoorExtend = maxX - entBox.max.x; + //没有盖过立板长度 + let noPassDoorExtend = entBox.min.x - maxX; + + if (passDoorExtend > -FUZZ) + { + if (minDist > passDoorExtend) + { + minDist = passDoorExtend; + minDistType = "全盖铰链"; + } + } + else + { + if (minDist > noPassDoorExtend) + { + minDist = passDoorExtend; + minDistType = "无盖铰链"; + } + } + } + } + + if (minDist >= -FUZZ && minDist < 30) + return minDistType; + else + return "无盖铰链"; + } + else if (openDir === BoardOpenDir.Up) + { + let maxZ = DoorSpaceBox.max.z; + for (let ent of isParallelToXYEnts) + { + let entBox = ent.GetBoundingBoxInMtx(ocsInv); + + //防止关联无关层板 + if (entBox.getSize(new Vector3).x < DoorSpaceBox.max.x / 2) continue; //过滤掉小于门板高度一半(抽测板) + if (DoorSpaceBox.min.x - entBox.max.x > -100 || entBox.min.x - DoorSpaceBox.max.x > -100) continue; + + //无盖距离值 + let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); + + //先判断半盖 + if (maxZ - entBox.min.z - noLid > FUZZ && entBox.max.z - maxZ > FUZZ) + { + let doorExtend = maxZ - entBox.min.z; + //全盖距离值 + let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); + if (doorExtend - allLid < -FUZZ) + return "半盖铰链"; + else + return "全盖铰链"; + } + else + { + //盖过立板长度 + let passDoorExtend = maxZ - entBox.max.z; + //没有盖过立板长度 + let noPassDoorExtend = entBox.min.z - maxZ; + + if (passDoorExtend > -FUZZ) + { + if (minDist > passDoorExtend) + { + minDist = passDoorExtend; + minDistType = "全盖铰链"; + } + } + else + { + if (minDist > noPassDoorExtend) + { + minDist = passDoorExtend; + minDistType = "无盖铰链"; + } + } + } + } + + if (minDist >= -FUZZ && minDist < 30) + return minDistType; + else + return "无盖铰链"; + } + else if (openDir === BoardOpenDir.Down) + { + let minZ = DoorSpaceBox.min.z; + for (let ent of isParallelToXYEnts) + { + let entBox = ent.GetBoundingBoxInMtx(ocsInv); + + //防止关联无关层板 + if (entBox.getSize(new Vector3).x < DoorSpaceBox.max.x / 2) continue; //过滤掉小于门板高度一半(抽测板) + if (DoorSpaceBox.min.x - entBox.max.x > -100 || entBox.min.x - DoorSpaceBox.max.x > -100) continue; + + //无盖距离值 + let noLid = safeEval(hingeLidRule.noLid, { BH: ent.Thickness }); + + //先判断半盖 + if (minZ - entBox.min.z > -FUZZ && entBox.max.z - minZ - noLid > FUZZ) + { + let doorExtend = entBox.max.z - minZ; + //全盖距离值 + let allLid = safeEval(hingeLidRule.allLid, { BH: ent.Thickness }); + if (doorExtend - allLid < -FUZZ) + return "半盖铰链"; + else + return "全盖铰链"; + } + else + { + //盖过立板长度 + let passDoorExtend = entBox.min.x - minZ; + //没有盖过立板长度 + let noPassDoorExtend = minZ - entBox.max.x; + + if (passDoorExtend > -FUZZ) + { + if (minDist > passDoorExtend) + { + minDist = passDoorExtend; + minDistType = "全盖铰链"; + } + } + else + { + if (minDist > noPassDoorExtend) + { + minDist = passDoorExtend; + minDistType = "无盖铰链"; + } + } + } + } + + if (minDist >= -FUZZ && minDist < 30) + return minDistType; + else + return "无盖铰链"; + } +};