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