feat: 提交
This commit is contained in:
152
samples/moduleManager/module_handleMaterialPlaceResult.ts
Normal file
152
samples/moduleManager/module_handleMaterialPlaceResult.ts
Normal file
@@ -0,0 +1,152 @@
|
||||
import { Processor, ProcessorModule } from "../../src/device";
|
||||
|
||||
import { ErrorInfo } from "../../src/device";
|
||||
import { BlockPlaceResult, BoardPlaceResult, BoardPosition, MaterialPlaceResult, PlaceStyle } from "../confClass";
|
||||
|
||||
/** 模块 处理优化源数据 数据处理 将优化数据转 为 MaterialPlaceResult
|
||||
*
|
||||
* input 入参
|
||||
|
||||
*/
|
||||
|
||||
export const HandleMaterialPlaceResult: ProcessorModule<any, any> = {
|
||||
moduleName: "HandleMaterialPlaceResult",
|
||||
moduleVersion: '20250714',
|
||||
config: {
|
||||
cutBoardBorder:3,
|
||||
// 是否跟随大板定位
|
||||
placeOriginByBoardLocation: true,
|
||||
boardLocation: 0
|
||||
},
|
||||
setConfig(config) {
|
||||
this.config = { ...this.config, ...config };
|
||||
},
|
||||
|
||||
// 会在处理器自动执行
|
||||
/**
|
||||
*
|
||||
* @param input 输入数据
|
||||
* @param next 下一个流程的函数
|
||||
* @param context 上下文
|
||||
* @returns
|
||||
*/
|
||||
|
||||
process(input, next, context) {
|
||||
|
||||
let {
|
||||
bList, best, yl, pm, width, length
|
||||
} = context.MaterialPlaceSource
|
||||
let blocks = bList
|
||||
let retData = new MaterialPlaceResult()
|
||||
let boardCount = 0
|
||||
let remainCount = 0
|
||||
let border = this.config.cutBoardBorder
|
||||
let borderOff = (pm.diameter + pm.cutKnifeGap) / 2
|
||||
|
||||
|
||||
// 所有大板上的小板面积
|
||||
let size_all = 0
|
||||
|
||||
for (let i = 0; i < best.length; i++) {
|
||||
let bd = best[i]
|
||||
let isRemainBoard = false
|
||||
boardCount = retData.boards.length + 1
|
||||
if (i < yl.length) // 余料板
|
||||
{
|
||||
width = yl[i].w + border * 2 - borderOff * 2
|
||||
length = yl[i].l + border * 2 - borderOff * 2
|
||||
isRemainBoard = true
|
||||
remainCount++
|
||||
}
|
||||
|
||||
let boardResult = new BoardPlaceResult()
|
||||
boardResult.boardId = boardCount
|
||||
boardResult.width = width
|
||||
boardResult.length = length
|
||||
boardResult.isRemainBoard = isRemainBoard
|
||||
|
||||
let pid = 0
|
||||
for (let b of bd) {
|
||||
pid++
|
||||
let block = blocks[b.bangid]
|
||||
let placeStyle = PlaceStyle.FRONT
|
||||
if (!block) {
|
||||
return
|
||||
}
|
||||
let faceF = block.isTurnFaceToPlace || false
|
||||
let isTurnFaceToPlace = this.config.placeOriginByBoardLocation && (
|
||||
this.config.boardLocation == BoardPosition.RIGHT_BOTTOM || this.boardLocation == BoardPosition.LEFT_TOP)
|
||||
if (isTurnFaceToPlace)
|
||||
faceF = !faceF
|
||||
if (faceF) // 翻面开料
|
||||
{
|
||||
if (block.texture == 0) {
|
||||
placeStyle = PlaceStyle.BACK
|
||||
}
|
||||
else if (block.texture == 2) {
|
||||
placeStyle = PlaceStyle.BACK_TURN_LEFT
|
||||
}
|
||||
else {
|
||||
placeStyle = (b.pbg == block.placeFullLength ? PlaceStyle.BACK : PlaceStyle.BACK_TURN_LEFT)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (block.texture == 0) {
|
||||
placeStyle = PlaceStyle.FRONT
|
||||
}
|
||||
else if (block.texture == 2) {
|
||||
placeStyle = PlaceStyle.FRONT_TURN_RIGHT
|
||||
}
|
||||
else {
|
||||
placeStyle = (b.pbg == block.placeFullLength ? PlaceStyle.FRONT : PlaceStyle.FRONT_TURN_RIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
let br: any = null
|
||||
br = new BlockPlaceResult(block.blockNo, boardCount, pid, b.x, b.y, b.pbk, b.pbg, placeStyle, block.area)
|
||||
boardResult.blocks.push(br)
|
||||
boardResult.area += block.area
|
||||
}
|
||||
retData.boards.push(boardResult)
|
||||
size_all += boardResult.area
|
||||
|
||||
let val = (size_all - boardResult.area) / (retData.boards.length - 1)
|
||||
retData.avgUsageRateAll = size_all / retData.boards.length
|
||||
retData.avgUsageRateExcludeLastBoard = Number.isNaN(val) ? boardResult.area : val
|
||||
retData.usageRateLastBoard = boardResult.area
|
||||
retData.boardCount = retData.boards.length
|
||||
}
|
||||
retData.boardCount = retData.boards.length // 大板数
|
||||
let remainBoardCount = retData.boards.filter(t => t.remainNo != '').length // 异形大板数
|
||||
let remianCount = 0
|
||||
|
||||
if (Array.isArray(pm.remainBoardList)) {
|
||||
pm.remainBoardList.forEach(e => {
|
||||
if (e?.placeBoardJSON) {
|
||||
let str = e?.placeBoardJSON
|
||||
e.placeBoardList = JSON.parse(str)
|
||||
remianCount += e.placeBoardList.length
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
retData.remainBoardCount = pm?.remainBoardList ? remianCount : yl.length + remainBoardCount
|
||||
|
||||
console.log({ placeResult: retData, pm } )
|
||||
let res = { module:this.moduleName, placeResult: retData, pm }
|
||||
|
||||
Reflect.set(context,'MaterialPlaceResult',res)
|
||||
return next ? next(input) : input;
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
onError(error) {
|
||||
|
||||
console.error('出错了哦', error);
|
||||
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user