3 Commits

Author SHA1 Message Date
6dd2b6b5c0 feat: 提交 2025-08-22 14:21:33 +08:00
257f228a98 feat: 提交 2025-08-11 10:05:26 +08:00
ee90d21cfb feat:提交 2025-08-01 16:07:39 +08:00
9 changed files with 387 additions and 1734 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@imes-procesor/libs",
"version": "0.1.0",
"name": "@imes-cutpoint/libs",
"version": "0.1.3",
"description": "",
"type": "module",
"scripts": {

View File

@@ -1,8 +1,8 @@
/**
* @package @mes-processors/libs
* @package @mes-cutpoint/libs
* @author LX
* @description 工作流处理器类库,在这个文件中使用导出时,不要在路径中使用'@',否则模块无法加载
*/
// CutOrder
export * from "./processors/cutOrder/CutOrder";
export * from "./processors/cutPoint/CutPoint";

View File

@@ -1,2 +0,0 @@
### react-layout
矩形优化算法(陈总新优化)

File diff suppressed because it is too large Load Diff

View File

@@ -1,124 +0,0 @@
import { ProcessorBase, ProcessorContext, CutOrderInput, CutorderOutput, CutorderConfig } from "cut-abstractions";
import { KLSC, YH_bang } from "../../modules/cutOrder/KLSCclass";
/**
* 开料顺序 --新算法
*/
export class CutOrderProc extends ProcessorBase<CutOrderInput, CutorderOutput, CutorderConfig> {
get name(): string {
return 'imes-cutOrder';
}
get version(): string {
return '1.0.0';
}
exec(context: ProcessorContext<CutOrderInput, CutorderOutput, CutorderConfig>): Promise<void> | void {
return new Promise(async (resolve, reject) => {
try {
/** 验证入参 */
let check = this.checkInput(context?.input)
if (check.isOk == false) {
reject(check.msg)
return
} else {
let bangs: YH_bang[] = []
let blocks = new Array()
let length = context.input?.blocks.length || 0
let beginId = 0;
let dt = context.input?.gap || 6;
let k = context.input?.boardWidth || 0;
let g = context.input?.boardHeight || 0;
for (let i = 0; i < length; i++) {
let block = context.input?.blocks[i];
let bangid = i + 1;
let x = block?.x;
let y = block?.y;
let pbg = block?.length;
let pbk = block?.width;
blocks[bangid] = block;
if (x == undefined) {
reject(`block ${block?.id} x is undefined`)
return
} else if (y == undefined) {
reject(`block ${block?.id} y is undefined`)
return
}
else if (pbg == undefined) {
reject(`block ${block?.id} pbg is undefined`)
return
} else if (pbk == undefined) {
reject(`block ${block?.id} pbk is undefined`)
return
}
bangs.push({
bangid,
line: 0,
pbg,
pbk,
x,
y,
ishb: false,
hb: [],
isbig: false,
isqg: false,
isgr: false,
gr: [],
grid: -1
});
}
let xdsc = new KLSC(bangs, k, g, dt, 0, 0, 1);
let rt = xdsc.SCid;
if (rt.length < length) {
reject('开料顺序算法异常,计算结果与板件数不匹配。')
return
};
for (let i = 0; i < rt.length; i++) {
let bid = rt[i];
beginId++;
blocks[bid].cutOrder = beginId;
}
context.output = {
blocks
}
}
resolve()
} catch (error) {
reject(error);
}
});
}
private checkInput(input?: CutOrderInput) {
let info: any = {
isOk: true,
msg: ''
}
if (input == undefined) {
info.isOk = false
info.msg = 'context.input is undefind'
} else if (input.blocks == undefined) {
info.isOk = false
info.msg = 'context.input.blocks is undefind'
} else if (input.gap == undefined) {
info.isOk = false
info.msg = 'context.input.gap is undefind'
} else if (input.boardWidth == undefined) {
info.isOk = false
info.msg = 'context.input.boardWidth is undefind'
} else if (input.boardHeight == undefined) {
info.isOk = false
info.msg = 'context.input.boardHeight is undefind'
}
return info
}
}

View File

@@ -1,61 +0,0 @@
import { test } from 'vitest'
import { CutOrderProc } from './CutOrder';
import { CutorderConfig, CutOrderInput, CutorderInputBlock } from 'cut-abstractions';
test('cutOrderTest', async () => {
let cutOrderProc = new CutOrderProc()
let params: CutorderConfig = new CutorderConfig()
let blocks: CutorderInputBlock[] = [
{
id: 25030882560,
length: 598,
width: 398,
x: 3.005,
y: 4,
},
{
id: 25030882561,
length: 598,
width: 398,
x: 3.005,
y: 610,
},
{
id: 25030882562,
length: 598,
width: 398,
x: 3.005,
y: 1216,
},
{
id: 25030882563,
length: 598,
width: 398,
x: 3.005,
y: 1821.005,
},
{
id: 25030882564,
length: 598,
width: 398,
x: 407.015,
y: 3.005,
},
]
let input: CutOrderInput = {
boardWidth: 1220,
boardHeight: 2440,
gap: 6,
blocks
}
const context = {
input,
params
}
await cutOrderProc.exec(context)
// 将在context的output中显示结果
console.log(context);
})

View File

@@ -0,0 +1,296 @@
import { test } from 'vitest'
import { CutPointInput, CutPointProc } from './CutPoint'
test('cutPointTest', async() => {
let context = {
"input": {
"boardWidth": 1220,
"boardLength": 2440,
"blocks": [
{
"id": "25030882560",
"width": 600,
"length": 400,
"waveType": 0,
"x": 3,
"y": 3,
"cutOrder": 2,
"isUnRegular": false,
"blockPoints": {
"pts": [
{
"x": 0,
"y": 0
},
{
"x": 398,
"y": 0
},
{
"x": 398,
"y": 598
},
{
"x": 0,
"y": 598
}
],
"buls": [
0,
0,
0,
0
]
}
},
{
"id": "25030882561",
"width": 600,
"length": 400,
"waveType": 0,
"x": 3,
"y": 604,
"cutOrder": 3,
"isUnRegular": false,
"blockPoints": {
"pts": [
{
"x": 0,
"y": 0
},
{
"x": 398,
"y": 0
},
{
"x": 398,
"y": 598
},
{
"x": 0,
"y": 598
}
],
"buls": [
0,
0,
0,
0
]
}
},
{
"id": "25030882562",
"width": 600,
"length": 400,
"waveType": 0,
"x": 404,
"y": 3,
"cutOrder": 4,
"isUnRegular": false,
"blockPoints": {
"pts": [
{
"x": 0,
"y": 0
},
{
"x": 398,
"y": 0
},
{
"x": 398,
"y": 598
},
{
"x": 0,
"y": 598
}
],
"buls": [
0,
0,
0,
0
]
}
},
{
"id": "25030882563",
"width": 600,
"length": 400,
"waveType": 0,
"x": 404,
"y": 604,
"cutOrder": 5,
"isUnRegular": false,
"blockPoints": {
"pts": [
{
"x": 0,
"y": 0
},
{
"x": 398,
"y": 0
},
{
"x": 398,
"y": 598
},
{
"x": 0,
"y": 598
}
],
"buls": [
0,
0,
0,
0
]
}
},
{
"id": "25030882564",
"width": 600,
"length": 400,
"waveType": 0,
"x": 805,
"y": 3,
"cutOrder": 1,
"isUnRegular": false,
"blockPoints": {
"pts": [
{
"x": 0,
"y": 0
},
{
"x": 398,
"y": 0
},
{
"x": 398,
"y": 598
},
{
"x": 0,
"y": 598
}
],
"buls": [
0,
0,
0,
0
]
}
}
]
},
"params": {}
}
let cutPointProc = new CutPointProc()
await cutPointProc.exec(context)
console.log(context)
})
const testData = {
input: {
boardWidth: 1220,
boardLength: 2440,
gap: 6,
blocks: [
{
id: 25030882560,
length: 598,
width: 398,
x: 3.005,
y: 4,
cutOrder: 2,
},
{
id: 25030882561,
length: 598,
width: 398,
x: 3.005,
y: 610,
cutOrder: 3,
},
{
id: 25030882562,
length: 598,
width: 398,
x: 3.005,
y: 1216,
cutOrder: 5,
},
{
id: 25030882563,
length: 598,
width: 398,
x: 3.005,
y: 1821.005,
cutOrder: 4,
},
{
id: 25030882564,
length: 598,
width: 398,
x: 407.015,
y: 3.005,
cutOrder: 1,
},
],
},
params: {
name: "",
version: "1.0.0",
},
output: {
blocks: [
{
id: 25030882560,
length: 598,
width: 398,
x: 3.005,
y: 4,
cutOrder: 2,
},
{
id: 25030882561,
length: 598,
width: 398,
x: 3.005,
y: 610,
cutOrder: 3,
},
{
id: 25030882562,
length: 598,
width: 398,
x: 3.005,
y: 1216,
cutOrder: 5,
},
{
id: 25030882563,
length: 598,
width: 398,
x: 3.005,
y: 1821.005,
cutOrder: 4,
},
{
id: 25030882564,
length: 598,
width: 398,
x: 407.015,
y: 3.005,
cutOrder: 1,
},
],
},
}

View File

@@ -1,5 +1,6 @@
import { ArrayExt } from "@libs/modules/cutOrder/ArrayExt";
import { ConfigBase, CutorderoutputBlock, ProcessorBase, ProcessorContext } from "cut-abstractions";
import { ArrayExt } from "../../modules/cutPoint/ArrayExt";
import { ConfigBase, ProcessorBase, ProcessorContext } from "cut-abstractions";
@@ -13,10 +14,7 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
get version(): string {
return '1.0.0';
}
/** 刀路间距 */
private gap = 7
/** 走刀100内 不能算靠板 */
private cutedSpace = 100
/** 垂直线, x ,y1,y2 */
private lines_V: type_lines_V[] = []
/** 水平线 x1,x2, y */
@@ -24,7 +22,6 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
exec(context: ProcessorContext<CutPointInput, CutPointOutput, CutPointConfig>): Promise<void> | void {
return new Promise(async (resolve, reject) => {
try {
this.gap = context.input?.gap || 7
this.lines_H = []; //开料水平线
this.lines_V = []; //开料垂直线
if (Array.isArray(context.input?.boardPointInfo?.pts) && context.input?.boardPointInfo?.pts?.length > 0) {
@@ -34,17 +31,17 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
this.pushLine(context.input.boardPointInfo.pts[i], context.input.boardPointInfo.pts[j]);
}
} else {
if (context.input?.boardWidth && context.input?.boardHeight) {
if (context.input?.boardWidth && context.input?.boardLength) {
let p0 = { x: 0, y: 0 };
let p1 = { x: context.input.boardWidth, y: 0 };
let p2 = { x: context.input.boardWidth, y: context.input.boardHeight };
let p3 = { x: 0, y: context.input.boardHeight };
let p2 = { x: context.input.boardWidth, y: context.input.boardLength };
let p3 = { x: 0, y: context.input.boardLength };
this.pushLine(p0, p1);
this.pushLine(p1, p2);
this.pushLine(p2, p3);
this.pushLine(p3, p0);
} else {
reject('imes-cutPoint error:input.boardWidth or input.boardHeight is undefined')
reject('imes-cutPoint error:input.boardWidth or input.boardLength is undefined')
}
}
@@ -55,8 +52,11 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
}
for (let b of blocks) {
this.findCutPoint(b);
console.log(b)
}
context.output = {
blocks
}
resolve()
} catch (error) {
reject(error);
@@ -64,7 +64,7 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
});
}
/** 计算下刀点 */
private findCutPoint(block: CutPointInputBlock) {
private findCutPoint(block: CutPointOutputBlock) {
let list = block.blockPoints.pts
//计算没边的靠板情况,并自动生成 铣板走线 数据
let borders_cuting = [];
@@ -74,14 +74,82 @@ export class CutPointProc extends ProcessorBase<CutPointInput, CutPointOutput, C
borders_cuting.push([i, rt[0], rt[1]]);
}
//计算最优下刀点
let unCutedlength = 0;
let unCutedSize = 0;
let cutPointIndex = -1;
for (let i = 0; i < borders_cuting.length; i++) {
let data = borders_cuting[i];
let index = data[0];
let len = data[1];
let size = data[2];
if (isBest(len, size)) {
cutPointIndex = index;
unCutedlength = len;
unCutedSize = size;
}
}
if (cutPointIndex >= list.length) cutPointIndex -= list.length;
block.cutPointId = cutPointIndex + 1;
//四周都没有靠的
if (cutPointIndex == -1) {
}
function isBest(len1: number, size1: number) //判断那条边 更优
{
if (len1 == 0) return false; //没有考的
let dis_avg = size1 / len1;
if (dis_avg < 50) return false; //跟最近的 平均距离 < 50 ,当作没有考的
if (cutPointIndex == -1) return true;
//return len1 > unCutedlength;
if (len1 > 150 && unCutedlength < 150) return true;
if (len1 > unCutedlength * 2) return true;
if (size1 > unCutedSize * 1.2) return true; //未切面积 相差很大. 取
if (size1 < unCutedSize * 0.8) return false; //小于 以获得的 边 , 不取
if (len1 > unCutedlength) return true; //面积相差无几, 取边长的
return false;
}
}
// private getCutPointWithClick(block, mousePos: Point): BlockBorderPoint
// {
// let curves = BlockPlus.getBorder(block);
// let dis = Number.MAX_VALUE;
// let point: Point;
// let index = -1;
// for (let i = 0; i < curves.length; i++)
// {
// let line = curves[i];
// let d = Math.pow(line.StartPoint.m_X + block.placeX - mousePos.x, 2) + Math.pow(line.StartPoint.m_Y + block.placeY - mousePos.y, 2);
// if (d < dis)
// {
// point = new Point(line.StartPoint.m_X, line.StartPoint.m_Y);
// dis = d;
// index = i;
// }
// }
// if (index == -1) return null; //距离太远,不选择
// let apexId = BlockHelper.getApexAngleNumFromBlock(block, point);
// block.cutPointId = index;
// return new BlockBorderPoint(block, point.x, point.y, index, apexId);
// }
private createByWidthLength(w: number, l: number) {
let plps = []
plps.push({ pt: { x: 0, y: 0 }, bul: 0 })
plps.push({ pt: { x: w, y: 0 }, bul: 0 })
plps.push({ pt: { x: w, y: l }, bul: 0 })
plps.push({ pt: { x: 0, y: l }, bul: 0 })
return plps
}
/**获取未切边长度 */
private getUnCutedLength(block: CutPointInputBlock, curs: IPoint[], i: number): [number, number] {
let cur = curs[i];
let next = i + 1
if (next == curs.length - 1) {
if (next > curs.length - 1) {
next = 0
}
let curNext = curs[next]
@@ -355,14 +423,13 @@ type type_lines_H = {
* 下刀点 入参
*/
export type CutPointInput = {
/** 刀路间距 */
gap: number,
/** (余料板异形点) 开料大板的开料轮廓数据 若没有则需要传 开料大板宽、高*/
boardPointInfo?: IProcessingItem,
/** 开料大板宽 若有 boardPointInfo 则不需要传 */
boardWidth?: number,
/** 开料大板 若有 boardPointInfo 则不需要传 */
boardHeight?: number
/** 开料大板 若有 boardPointInfo 则不需要传 */
boardLength?: number
/** 小板数据集 */
blocks?: CutPointInputBlock[]
}
@@ -399,7 +466,7 @@ export type CutPointInputBlock = {
/** 小板类型 输出 */
export type CutPointOutputBlock = CutPointInputBlock & {
/** 下刀点 板件轮廓的下标 */
cutPointId: number,
cutPointId?: number,
}
/** 下刀点配置