|
|
|
@ -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<Board, ObjectId[][]>();
|
|
|
|
|
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<Board, ObjectId[][]>();
|
|
|
|
|
|
|
|
|
|
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<ObjectId>();
|
|
|
|
|
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<ObjectId>();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|