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

84 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-07-22 18:38:25 +08:00
import { Processor, ProcessorModule } from "../../src/device";
import { ErrorInfo } from "../../src/device";
import { FaceType, PlaceBlockDetail } from "../confClass";
// import { PolylineHelper } from "../handleAbility/common/LayoutEngine/PolylineHelper";
// import {PolylineHelper} from "../handleAbility/common/LayoutEngine/PolylineHelper.js"
/** ,
*
* input
*/
export const Init2VModel: ProcessorModule<any, any> = {
moduleName: "Init2VModel",
moduleVersion: '20250714',
config: {
},
setConfig(config) {
this.config = { ...this.config, ...config };
},
// 会在处理器自动执行
/**
*
* @param input
* @param next
* @param context
* @returns
*/
process(input, next, context) {
const { blockDetailList } = input
for (const bd of blockDetailList) {
init2VModel(bd);
}
function init2VModel(blockDetail: PlaceBlockDetail, isCNC = false) {
for (let model of blockDetail.models) {
if (!model.isVKnifeModel)
continue
let vModels: any = []
model.VLines = vModels
let isFaceB = model.face == FaceType.BACK
if (model.pointList.length < 1)
continue
let ps = model.pointList.map((t) => { return { x: t.pointX, y: t.pointY, bul: t.curve } })
let pl = PolylineHelper.create(ps)
if (model.VLines?.length > 0)
return // 已经分析了
model.VLines = []
for (let os of model.offsetList) {
let knife1 = isCNC ? null : this.getModelKnifeByName(os.name)
let knifeR = os.radius
let knifeId = knife1 ? knife1.knifeId : -1
try {
let vps_1 = PolylineHelper.getVModelPoints_offset(pl, os.offset, os.depth, os.angle)
let vLine = { isFaceB, name: os.name, value: os.offset, knife: knife1, knifeId, knifeRadius: knifeR, depth: os.depth, points: vps_1, offset: os }
vModels.push(vLine) // 偏移路径
model.VLines.push(vLine)
}
catch (err) {
console.log('v型刀走刀路径算法出错。' + err)
}
}
model.VLines = vModels
}
}
return next ? next(input) : input;
},
onError(error) {
console.error('出错了哦', error);
}
};