过滤无法优化的板件

pull/579/MERGE
ChenX 5 years ago
parent d630f053d9
commit da1f2a675a

@ -80,39 +80,34 @@ export class Container
this.AppendPartHoles(part);
return true;
}
if (NestCache.PartCaled.has(cacheKey)) return false;
NestCache.PartCaled.add(cacheKey);
let combinedNfp: Paths = NestCache.NFPCache.get(cacheKey);
if (!combinedNfp)
//------------计算nfp------------
//合并(零件和所有已经放置零件的NFP)
let clipper = new Clipper();
for (let placedPart of this.Placed)
{
combinedNfp = [];
NestCache.NFPCache.set(cacheKey, []);
//------------计算nfp------------
//合并(零件和所有已经放置零件的NFP)
let clipper = new Clipper();
for (let placedPart of this.Placed)
let nfp = placedPart.State.PlaceOutline.GetOutsideNFP(part.State.PlaceOutline);
if (!nfp)
return false;
let x = placedPart.PlacePosition.x;
let y = placedPart.PlacePosition.y;
for (let n of nfp)
{
let nfp = placedPart.State.PlaceOutline.GetOutsideNFP(part.State.PlaceOutline);
if (!nfp)
return false;
let x = placedPart.PlacePosition.x;
let y = placedPart.PlacePosition.y;
for (let n of nfp)
{
let f = n.map(v => { return { x: v.x + x, y: v.y + y }; });
clipper.AddPath(f, PolyType.ptSubject, true);
}
let f = n.map(v => { return { x: v.x + x, y: v.y + y }; });
clipper.AddPath(f, PolyType.ptSubject, true);
}
if (!clipper.Execute(ClipType.ctUnion, combinedNfp, PolyFillType.pftNonZero, PolyFillType.pftNonZero))
return false;
}
else
NestCache.count2++;
let combinedNfp = [];
if (!clipper.Execute(ClipType.ctUnion, combinedNfp, PolyFillType.pftNonZero, PolyFillType.pftNonZero))
return false;
if (combinedNfp.length === 0) return false;
//binNfp 减去 combinedNfp 得到最终的nfp
let clipper = new Clipper();
clipper = new Clipper();
clipper.AddPaths(binNfp, PolyType.ptSubject, true);
clipper.AddPaths(combinedNfp, PolyType.ptClip, true);
let finalNfp: Paths = [];
@ -128,10 +123,6 @@ export class Container
if (finalNfp.length === 0)
return false;
//缓存combinedNfp
NestCache.NFPCache.set(cacheKey, combinedNfp);
/**
* (box).
* 使

@ -12,14 +12,8 @@ export class NestCache
{
return this._pathId++;
}
/**
*
*/
static PartCaled = new Set<string>();
static PositionCache = new Map<string, Point>();
static NFPCache = new Map<string, Point[][]>();
private static CacheRect = new Map<string, Path>();
/**
@ -53,6 +47,6 @@ export class NestCache
this._pathId = -1;
this.CacheRect.clear();
this.PositionCache.clear();
this.NFPCache.clear();
this.PartCaled.clear();
}
}

@ -3,6 +3,9 @@ import { Part } from "./Part";
import { Individual } from "./Individual";
import { Sleep } from "../Common/Sleep";
import { NestCache } from "./NestCache";
import { arrayRemoveIf } from "../Common/ArrayExt";
import { MoveMatrix } from "../Geometry/GeUtils";
import { Vector3 } from "three";
/**
*
@ -34,6 +37,19 @@ export class OptimizeMachine
//放入零件
PutParts(parts: Part[])
{
let m = MoveMatrix(new Vector3(0, 3000, 0));
arrayRemoveIf(parts, p =>
{
if (p.RotatedStates.length === 0)
{
for (let c of p.UserData)
{
c.ColorIndex = 1;
c.ApplyMatrix(m);
}
return true;
}
});
this.Parts = parts;
}

Loading…
Cancel
Save