mirror of https://gitee.com/cf-fz/WebCAD.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.7 KiB
100 lines
2.7 KiB
10 months ago
|
import { Circle } from "../../src/DatabaseServices/Entity/Circle";
|
||
|
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
|
||
|
import { InitClipperCpp } from "../../src/Nest/Common/ClipperCpp";
|
||
|
import { NestFiler } from "../../src/Nest/Common/Filer";
|
||
|
import { CurveWrap } from "../../src/Nest/Converter/CurveWrap";
|
||
|
import { Circle2Points } from "../../src/Nest/Converter/Curves2Points";
|
||
|
import { DefaultBin } from "../../src/Nest/Core/DefaultBin";
|
||
|
import { Individual } from "../../src/Nest/Core/Individual";
|
||
|
import { NestCache } from "../../src/Nest/Core/NestCache";
|
||
|
import { DefaultComparePointKeys, NestDatabase } from "../../src/Nest/Core/NestDatabase";
|
||
|
import { OptimizeMachine } from "../../src/Nest/Core/OptimizeMachine";
|
||
|
import { Part } from "../../src/Nest/Core/Part";
|
||
|
import { Path } from "../../src/Nest/Core/Path";
|
||
|
import { PathGeneratorSingle } from "../../src/Nest/Core/PathGenerator";
|
||
|
|
||
|
//@ts-ignore
|
||
|
globalThis.document = {};
|
||
|
|
||
|
export function Curve2Path(curve: Circle | Polyline, outside = false): Path
|
||
|
{
|
||
|
if (curve.IsClockWise)
|
||
|
curve.Reverse();
|
||
|
if (curve instanceof Circle)
|
||
|
{
|
||
|
return new Path(Circle2Points(curve, 0, 10, outside), 3);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
let w = new CurveWrap(curve, 3, outside);
|
||
|
return new Path(outside ? w.GetOutsidePoints() : w.GetInsidePoints());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
test('异形优化测试', async () =>
|
||
|
{
|
||
|
await InitClipperCpp();
|
||
|
|
||
|
PathGeneratorSingle.Clear();
|
||
|
NestCache.Clear();
|
||
|
DefaultBin.InsideNFPCache = {};
|
||
|
|
||
|
let binPath = DefaultBin;
|
||
|
binPath.Id = undefined;
|
||
|
PathGeneratorSingle.RegisterId(binPath);
|
||
|
|
||
|
let path = Curve2Path(new Polyline().Rectangle(100, 100));
|
||
|
let part1 = new Part().Init(path, binPath);
|
||
|
|
||
|
let path2 = Curve2Path(new Polyline().Rectangle(1200, 2400));
|
||
|
let part2 = new Part().Init(path2, binPath);
|
||
|
|
||
|
part1.IsPrePlace = true;
|
||
|
part2.IsPrePlace = false;
|
||
|
|
||
|
let parts = [part1, part2];
|
||
|
|
||
|
parts.forEach((p, i) => p.Id = i);
|
||
|
|
||
|
let db = new NestDatabase();
|
||
|
db.Paths = PathGeneratorSingle.paths;
|
||
|
db.Parts = parts;
|
||
|
db.Bin = DefaultBin;
|
||
|
db.OddmentsBins = [];
|
||
|
db.ComparePointKeys = DefaultComparePointKeys;
|
||
|
|
||
|
let f = new NestFiler();
|
||
|
db.WriteFile(f);
|
||
|
|
||
|
db = new NestDatabase;
|
||
|
db.ReadFile(f);
|
||
|
|
||
|
let m = new OptimizeMachine;
|
||
|
m.Bin = db.Bin;
|
||
|
m.OddmentsBins = db.OddmentsBins;
|
||
|
|
||
|
|
||
|
m.PutParts(db.Parts);
|
||
|
|
||
|
let promise = new Promise<void>((res, rej) =>
|
||
|
{
|
||
|
m.callBack = async (inv) =>
|
||
|
{
|
||
|
m.Suspend();
|
||
|
|
||
|
let f = new NestFiler;
|
||
|
inv.WriteFile(f);
|
||
|
expect(f._datas).toMatchSnapshot();
|
||
|
|
||
|
let inv2 = new Individual(db.Parts);
|
||
|
inv2.ReadFile(f);
|
||
|
|
||
|
res();
|
||
|
};
|
||
|
});
|
||
|
|
||
|
m.Start();
|
||
|
|
||
|
await promise;
|
||
|
});
|