过滤无法优化的板件

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

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

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

@ -3,6 +3,9 @@ import { Part } from "./Part";
import { Individual } from "./Individual"; import { Individual } from "./Individual";
import { Sleep } from "../Common/Sleep"; import { Sleep } from "../Common/Sleep";
import { NestCache } from "./NestCache"; 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[]) 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; this.Parts = parts;
} }

Loading…
Cancel
Save