From 04beadad7363203635824eae861258c10e81919a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=AF=97=E6=B4=A5?= <2723065175@qq.com> Date: Thu, 14 Dec 2023 08:24:47 +0000 Subject: [PATCH] =?UTF-8?q?!2417=20=E4=BC=98=E5=8C=96:=E6=8B=86=E5=8D=95?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=94=9F=E4=BA=A7=E6=97=B6=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=8E=92=E9=92=BB=E5=B9=B2=E6=B6=89,=E7=BB=99=E5=87=BA?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/CheckHoles.ts | 241 +++++++++++++++++----------------- src/Add-on/Erp/ErpCommands.ts | 19 +++ 2 files changed, 142 insertions(+), 118 deletions(-) diff --git a/src/Add-on/CheckHoles.ts b/src/Add-on/CheckHoles.ts index e06c1a836..a64fd813a 100644 --- a/src/Add-on/CheckHoles.ts +++ b/src/Add-on/CheckHoles.ts @@ -16,8 +16,6 @@ export class CheckHoles implements Command { async exec() { - const drillTool = DrawDrillingTool.GetInstance(); - let brRes = await app.Editor.GetSelection({ Msg: "选择要检查排钻碰撞的板件", Filter: { filterTypes: [Board] } @@ -26,152 +24,159 @@ export class CheckHoles implements Command if (brRes.Status === PromptStatus.OK) { let brs = brRes.SelectSet.SelectEntityList as Board[]; + let res = InterferenceCheck(brs); - let b2boxMap = new Map(); + if (res.length) + app.Editor.ModalManage.RenderModeless(CollsionModal, { faces: res }, { position: ModalPosition.Right, canMinimize: false }); + else + AppToaster.show({ + message: "排钻没有干涉!", + timeout: 5000, + intent: Intent.SUCCESS, + }); + } + } +} + +//干涉检查 +export function InterferenceCheck(brs: Board[]) +{ + const drillTool = DrawDrillingTool.GetInstance(); + let b2boxMap = new Map(); - for (let b of brs) + for (let b of brs) + { + let drills: ObjectId[][] = []; + for (let [, dss] of b.DrillList) + { + for (let ds of dss) { - let drills: ObjectId[][] = []; - for (let [, dss] of b.DrillList) + if (ds.some(d => !d?.Object)) + continue; + //仅用母板件上的排钻用作碰撞检测 + let ds2 = ds.filter(d => { - for (let ds of dss) + if (d?.Object && !d.IsErase) { - if (ds.some(d => !d?.Object)) - continue; - //仅用母板件上的排钻用作碰撞检测 - let ds2 = ds.filter(d => - { - if (d?.Object && !d.IsErase) - { - let h = d.Object as Hole; - if (h.MId?.Index === b.Id.Index) - return true; - else if (h.MId?.Index < 0 && (h.MId.Index === b.Id.Index * -100 || h.MId.Index === b.Id.Index * -100 - 1)) //兼容旧关联错误排钻检测 - return true; - } - return false; - }); - if (ds2.length > 0) - drills.push(ds2); + let h = d.Object as Hole; + if (h.MId?.Index === b.Id.Index) + return true; + else if (h.MId?.Index < 0 && (h.MId.Index === b.Id.Index * -100 || h.MId.Index === b.Id.Index * -100 - 1)) //兼容旧关联错误排钻检测 + return true; } - } - b2boxMap.set(b, drills); + return false; + }); + if (ds2.length > 0) + drills.push(ds2); } + } + b2boxMap.set(b, drills); + } - let res: ICollsionBrs[] = []; + let res: ICollsionBrs[] = []; - //自身排钻碰撞检测 - for (let [, dss] of b2boxMap) + //自身排钻碰撞检测 + for (let [, dss] of b2boxMap) + { + if (dss.length === 0) continue; + for (let i = 0; i < dss.length; i++) + { + let ds1 = dss[i]; + let ocsInv = (ds1[0].Object as Hole).OCSInv; + let boxes1 = drillTool.GetDrillsBox(ds1, ocsInv); + let j = i + 1; + for (; j < dss.length; j++) { - if (dss.length === 0) continue; - for (let i = 0; i < dss.length; i++) + let ds2 = dss[j]; + if ((ds1[0].Object as Hole).MId.Object !== (ds2[0].Object as Hole).MId.Object //如果是同一个板上的排钻(就不可能是通孔了) + && IsThough(ds1) + && IsThough(ds2)) + continue; + + let boxes2 = drillTool.GetDrillsBox(ds2, ocsInv); + if (IsCollsion([boxes1], [boxes2])) { - let ds1 = dss[i]; - let ocsInv = (ds1[0].Object as Hole).OCSInv; - let boxes1 = drillTool.GetDrillsBox(ds1, ocsInv); - let j = i + 1; - for (; j < dss.length; j++) - { - let ds2 = dss[j]; - if ((ds1[0].Object as Hole).MId.Object !== (ds2[0].Object as Hole).MId.Object //如果是同一个板上的排钻(就不可能是通孔了) - && this.IsThough(ds1) - && this.IsThough(ds2)) - continue; - - let boxes2 = drillTool.GetDrillsBox(ds2, ocsInv); - if (this.IsCollsion([boxes1], [boxes2])) - { - let h = ds1[0].Object as Hole; - if (h.FId.Object && h.MId.Object) - res.push({ - InterBoard: h.FId.Object as Board, - LocalBoard: h.MId.Object as Board, - }); - break; - } - } - if (j < dss.length) - break; + let h = ds1[0].Object as Hole; + if (h.FId.Object && h.MId.Object) + res.push({ + InterBoard: h.FId.Object as Board, + LocalBoard: h.MId.Object as Board, + }); + break; } } + if (j < dss.length) + break; + } + } - for (let i = 0; i < brs.length; i++) - { - let b1 = brs[i]; - let drills = b2boxMap.get(b1); - if (!drills || drills.length === 0) continue; - let ocsInv = (drills[0][0].Object as Hole).OCSInv; - let boxlist: Box3Ext[][] = []; - - //通孔对应的穿孔板件 - let tkHoleFidSet = new Set(); - for (let ds of drills) - { - boxlist.push(drillTool.GetDrillsBox(ds, ocsInv)); - if (this.IsThough(ds)) - tkHoleFidSet.add((ds[0].Object as CylinderHole).FId); - } - - for (let j = i + 1; j < brs.length; j++) - { - let b2 = brs[j]; - let drills2 = b2boxMap.get(b2); + for (let i = 0; i < brs.length; i++) + { + let b1 = brs[i]; + let drills = b2boxMap.get(b1); + if (!drills || drills.length === 0) continue; + let ocsInv = (drills[0][0].Object as Hole).OCSInv; + let boxlist: Box3Ext[][] = []; + + //通孔对应的穿孔板件 + let tkHoleFidSet = new Set(); + for (let ds of drills) + { + boxlist.push(drillTool.GetDrillsBox(ds, ocsInv)); + if (IsThough(ds)) + tkHoleFidSet.add((ds[0].Object as CylinderHole).FId); + } - if (drills2.length === 0) continue; - const boxlist2: Box3Ext[][] = []; + for (let j = i + 1; j < brs.length; j++) + { + let b2 = brs[j]; + let drills2 = b2boxMap.get(b2); - for (let ds of drills2) - { - let h1 = ds[0].Object as CylinderHole; - //同一穿孔板件的通孔不参与碰撞计算 - if (this.IsThough(ds) && tkHoleFidSet.has(h1.FId)) - continue; - boxlist2.push(drillTool.GetDrillsBox(ds, ocsInv)); - } + if (drills2.length === 0) continue; + const boxlist2: Box3Ext[][] = []; - if (this.IsCollsion(boxlist, boxlist2)) - { - res.push({ - InterBoard: b1, - LocalBoard: b2, - }); - } - } + for (let ds of drills2) + { + let h1 = ds[0].Object as CylinderHole; + //同一穿孔板件的通孔不参与碰撞计算 + if (IsThough(ds) && tkHoleFidSet.has(h1.FId)) + continue; + boxlist2.push(drillTool.GetDrillsBox(ds, ocsInv)); } - if (res.length) - app.Editor.ModalManage.RenderModeless(CollsionModal, { faces: res }, { position: ModalPosition.Right, canMinimize: false }); - else - AppToaster.show({ - message: "排钻没有干涉!", - timeout: 5000, - intent: Intent.SUCCESS, + if (IsCollsion(boxlist, boxlist2)) + { + res.push({ + InterBoard: b1, + LocalBoard: b2, }); + } } } + return res; +} - /** +/** * 存在通孔 */ - private IsThough(ds: ObjectId[]): boolean - { - return ds.some(d => (d.Object as CylinderHole).Type === GangDrillType.TK); - } - private IsCollsion(boxlist: Box3Ext[][], boxlist2: Box3Ext[][]) - { - const drillTool = DrawDrillingTool.GetInstance(); +function IsThough(ds: ObjectId[]): boolean +{ + return ds.some(d => (d.Object as CylinderHole).Type === GangDrillType.TK); +} +function IsCollsion(boxlist: Box3Ext[][], boxlist2: Box3Ext[][]) +{ + const drillTool = DrawDrillingTool.GetInstance(); - for (let boxs of boxlist) + for (let boxs of boxlist) + { + for (let boxs2 of boxlist2) { - for (let boxs2 of boxlist2) + if (boxs.some(bo => boxs2.some(bo2 => drillTool.DrillIsCollsion(bo, bo2)))) { - if (boxs.some(bo => boxs2.some(bo2 => drillTool.DrillIsCollsion(bo, bo2)))) - { - return true; - } + return true; } } - return false; } + return false; } diff --git a/src/Add-on/Erp/ErpCommands.ts b/src/Add-on/Erp/ErpCommands.ts index 835960178..0a4c65717 100644 --- a/src/Add-on/Erp/ErpCommands.ts +++ b/src/Add-on/Erp/ErpCommands.ts @@ -21,8 +21,11 @@ import { SelectSetBase } from "../../Editor/SelectBase"; import { userConfig } from "../../Editor/UserConfig"; import { IHardwareType } from "../../Production/Product"; import { AppConfirm } from "../../UI/Components/Common/Confirm"; +import { ModalPosition } from "../../UI/Components/Modal/ModalInterface"; import { AppToaster } from "../../UI/Components/Toaster"; import { BoardStore } from "../../UI/Store/BoardStore"; +import { InterferenceCheck } from "../CheckHoles"; +import { CollsionModal } from "../DrawDrilling/CollisionModal"; import { Purge } from "../Purge"; import { blockBuilder, objectBuilder } from './CheckBuilder'; import { ErpGroupBy } from "./ErpGroupBy"; @@ -139,9 +142,25 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes) { let selction = await GetProductsEntitys(); if (!selction) return; + let intSelfBoards = new Set(); let minBoardCount = 0; const boardList = GetSelectionBoards(selction.selectEntityList, selction.selectRelativeHardware); + + const interference = InterferenceCheck(boardList); + if (interference.length) + { + let res = await AppConfirm.show({ + intent: Intent.WARNING, + message: "存在排钻碰撞,是否先排查?" + }); + if (res) + { + app.Editor.ModalManage.RenderModeless(CollsionModal, { faces: interference }, { position: ModalPosition.Right, canMinimize: false }); + return; + } + } + for (let br of boardList) { let b = br.__OriginalEnt__ ?? br;