Files
cut-abstractions/samples/moduleManager/module_RectOptimizeMachine.ts

245 lines
7.5 KiB
TypeScript
Raw Normal View History

2025-07-22 18:38:25 +08:00
import { Processor, ProcessorModule } from "../../src/device";
import { confItem, PlaceBlock, PlaceBlockDetail, PlaceMaterial } from "../confClass";
import { Big_bang, ComposingType, LineType, WorkerItemType, xbang } from "../handleAbility/RectOptimizeWorker/bang";
import resData from './res1.json'
import { UniversalWorker } from "../WorkerHelper";
import { RectOptimizeMachine } from "./RectOptimizeWorker/RectOptimizeMachine";
/**
*
* input
*
* ProcessorModule<any, any>any
*/
export const RectOptimizeMachineModule: ProcessorModule<any, any> = {
moduleName: "RectOptimizeMachine",
moduleVersion: '20250714',
config: {
placeStyle: 1,
/** 总修边宽度 */
cutBoardBorder: 3,
cutKnifeGap: 1,
isDoubleFaceBlockFirst: true,
blockKnifeLineSpacing: 0,
isRectPlace: false,
isDoubleFaceBlockInRemain: true,
},
workerList: [],
setConfig(config) {
this.config = { ...this.config, ...config };
},
before(input) {
// console.log(`优化前要做的事情`, input);
},
// 会在处理器自动执行
/**
*
* @param input
* @param next
* @param context
* @returns
*/
process(input, next, context) {
let { blockList, materialList } = input
let bList: any = []
let pm = materialList[0]
blockList.map(e => {
if (e.goodsId == pm.goodsId) {
bList[e.blockNo] = e
// let detail = blockDetailList.find(x => x.blockId == e.blockId)
// // 处理可能出现的异常 --没有板明细
// if (!Reflect.has(bList[e.blockNo], 'blockDetail')) {
// bList[e.blockNo].blockDetail = new PlaceBlockDetail(detail)
// }
// bList[e.blockNo].isTurnFaceToPlace = !this.getDoFace(bList[e.blockNo], this.processMode())
// 是否翻面后续处理
bList[e.blockNo].isTurnFaceToPlace = true
if (Array.isArray(pm.blockList)) {
pm.blockList.push(e)
} else {
pm.blockList = [e]
}
}
})
pm.cutBorder = this.config.cutBoardBorder
pm.cutKnifeGap = this.config.cutKnifeGap
/** 小板 */
let bans: xbang[] = []
// 实际开料大板的列表
let big_Bang: Big_bang[] = []
let big_BangSL: number[] = []
let border = this.config.cutBoardBorder
let borderOff = (pm.diameter + pm.cutKnifeGap) / 2
// 余料板 以及实际开料大板
for (const cuttingBoard of pm.remainBoardList) {
big_Bang.push({ w: cuttingBoard.width - border * 2 + borderOff * 2, l: cuttingBoard.length - border * 2 + borderOff * 2, x: border - borderOff, y: border - borderOff })
big_BangSL.push(cuttingBoard.count || 999)
}
// big_Bang = []
// big_BangSL = []
// 母板 兜底的
big_Bang.push({ w: pm.width - border * 2 + borderOff * 2, l: pm.length - border * 2 + borderOff * 2, x: border - borderOff, y: border - borderOff })
// 生成小板
for (let key in bList) {
let b = bList[key]
let bid = b.blockNo
let width = b.placeFullWidth
let length = b.placeFullLength
let line = toLine(b.texture)
bans.push({
l: length,
w: width,
line,
face: toface(b),
id: bid,
bno: b.blockNo,
holeFaceCount: 3,
isRect: !b.isUnRegular,
hasHole: false,
isdtwosided: true,
})
}
let bestCount = 0
if (bans.length == 0) // 没有板了
{
if (context.CallBack) {
let best = []
let yl: Big_bang[] = []
let fit = 0
let resObj = {
data: { bList, best, yl, fit, bans, width: pm.width, length: pm.length, bestCount: bestCount++, pm },
info: {
times: -1,
type: 'noBan'
}
}
context.CallBack(resObj)
}
return
}
let xyhcs = 50
if (bans.length > 1000) { xyhcs = 40 }
else if (bans.length > 1500) { xyhcs = 30 }
else if (bans.length > 2000) { xyhcs = 25 }
else if (bans.length > 4000) { xyhcs = 20 }
else if (bans.length > 6000) { xyhcs = 15 }
else if (bans.length > 10000) { xyhcs = 10 }
else if (bans.length > 15000) { xyhcs = 5 }
else if (bans.length > 20000) { xyhcs = 1 }
let isDoubleFaceBlockFirst = this.config.isDoubleFaceBlockFirst // 双面加工排前面
let gap = this.config.blockKnifeLineSpacing
/** 这里要做个多线程 测试环境下 这部分有问题 暂时略过 */
const m = new RectOptimizeMachine()
const self = this
m.CallBack = async (best, fit, arg, info) => {
console.log('优化结果', pm, [best, fit, arg, info]);
let res={
moduleName:self.moduleName,
pm,
result: [best, fit, arg, info],
input,
context
}
self.onMessage(res)
}
const data = {
type: 'start',
data: [bans, big_Bang, big_BangSL, xyhcs, isDoubleFaceBlockFirst, gap, this.config.isRectPlace, this.config.isDoubleFaceBlockInRemain],
}
m.Start(bans, big_Bang, big_BangSL, xyhcs, isDoubleFaceBlockFirst, gap, this.config.isRectPlace, this.config.isDoubleFaceBlockInRemain)
return next ? next(input) : input;
},
after(result, input, context) {
console.log(`优化后要做的事情`,);
},
onError(error) {
console.log('出错了哦', error);
}
};
function toLine(texture): LineType {
if (texture == 0)
return LineType.Positive
if (texture == 1)
return LineType.CanReversal
return LineType.Reverse
}
/** 小板加工面Positive=0正面 Reverse=1反面 Arbitrary=2任意 */
function toface(block: PlaceBlock): ComposingType {
let turnF = block.isTurnFaceToPlace
// if (this.isTurnFaceToPlace)
if (true)
turnF = !turnF
if (!turnF)
return ComposingType.Positive
return ComposingType.Reverse
}
/** 配置列表 */
export const confList: confItem[] = [
{
key: 'isCutProcess',
label: '开料机(雕刻机)加工',
value: true
},
{
key: 'isCutAndCNCProcess',
label: '开料机CNC组合',
value: false
},
{
key: 'isCustomized',
label: '定制加工',
value: false
},
{
key: 'cutBoardBorder',
label: '总修边宽度',
value: 3
},
{
key: 'blockKnifeLineSpacing',
label: '刀路间距',
value: 0
},
{
key: 'isDoubleFaceBlockFirst',
label: '双面开料优先排版',
value: true
},
{
key: 'isRectPlace',
label: '新优化规则排版',
value: false
},
{
// yuLiaoBoardDo2FaceBlock
key: 'isDoubleFaceBlockInRemain',
label: '余料板允许排入双面加工的小板',
value: true
},
]