!2803 修复:异形优化,复用容器时,考虑板外下刀

pull/2658/MERGE
zc 4 months ago committed by ChenX
parent da3604d47d
commit e55954a7d7

@ -1,5 +1,4 @@
import { insertSorted } from "../../csg/core/utils";
import { arraySortByNumber } from "../Common/ArrayExt";
import { Container } from "./Container";
import { Part } from "./Part";
@ -12,7 +11,7 @@ type TBestContainerMap = Map<number, {
export interface IContourIdToParts
{
[key: number]: Part[];
[key: string]: Part[];
}
export class BestNestContainers
@ -57,7 +56,8 @@ export class BestNestContainers
// 如果当前StatusKey未排序则进行排序并存储到StatusKey映射表中
if (!sortedStatusKey)
{
sortedStatusKey = arraySortByNumber(newC.PlacedParts.map(p => p.State.Contour.Id)).join(",");
const ids = newC.PlacedParts.map(p => p.State.Contour.Id + (p.State.KnifeContour ? "|" + p.State.KnifeContour.Id : ""));
sortedStatusKey = ids.sort().join(",");
sortedStatusKeyMap.set(rawStatusKey, sortedStatusKey);
}
// 如果当前 StatusKey已存在于状态键集合中则跳过该容器
@ -105,7 +105,7 @@ export class BestNestContainers
for (const part of parts)
for (const state of part.RotatedStates)
{
const id = state.Contour.Id;
const id = state.Contour.Id + (state.KnifeContour ? "|" + state.KnifeContour.Id : "");
obj[id] = obj[id] || [];
obj[id].push(part);
}
@ -136,17 +136,18 @@ export class BestNestContainers
// 检查是否所有容器零件都被匹配
const isAllMatch = containerParts.every((p1) =>
{
let parts = cIdToPartsObj[p1.State.Contour.Id] || [];
const state = p1.State;
const cid = state.Contour.Id;
const parts = cIdToPartsObj[cid + (state.KnifeContour ? "|" + state.KnifeContour.Id : "")] || [];// 含有刀路轮廓,需要同时匹配刀路轮廓
for (const part of parts)
{
if (remainingPartsSet.has(part))
{
part.StateIndex = part.RotatedStates.findIndex((p2) => p2.Contour.Id === p1.State.Contour.Id);
part.StateIndex = part.RotatedStates.findIndex((p) => (p.Contour.Id === cid));
matchedParts.push(part);
remainingPartsSet.delete(part);
return true; // 匹配成功
}
}
return false; // 匹配失败
});

@ -95,7 +95,8 @@ export class Container
if (this.BinPath.Area - this.PlacedArea < part.State.Contour.Area)
return;
const cacheKey = this.StatusKey + "," + part.State.Contour.Id;
let cacheKey = this.StatusKey + "," + part.State.Contour.Id;
if (part.State.KnifeContour) cacheKey += "|" + part.State.KnifeContour.Id;
const cacheP = NestCache.GetPos(cacheKey);
//读取缓存位置
if (cacheP)
@ -333,6 +334,7 @@ export class Container
private AppendPart(part: Part, calc = true): void
{
this.StatusKey += "," + part.State.Contour.Id;
if (part.State.KnifeContour) this.StatusKey += "|" + part.State.KnifeContour.Id;
this.UpdateCurNotPuts();
this.PlacedParts.push(part);
this.PlacedArea += part.State.Contour.Area;

Loading…
Cancel
Save