Files
cut-abstractions/tests/paser.test.ts
2025-07-14 16:04:08 +08:00

186 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect, test } from 'vitest';
import { DemoParser } from '../samples/demoParser';
import { ProcessorModule, StepControllerProcessor } from '../src/device';
import { ProcessorManager } from '../src/device';
import { demoHandleGroupCutting } from '../samples/demoDatahandle/demoDataHandle1';
import testJson from "./test.json"
import { Worker, parentPort } from 'worker_threads';
import { UniversalWorker } from '../samples/WorkerHelper';
describe('demoParser', () => {
const text = `FSTART
TD 5
G0 X100 Y100 Z10 F8000
g0 x100 y100 z18 f8000
g2 x120 y120 z18 R20 f8000
g3 x100 y100 z18 i20 j0 f8000
TN T2
FEND
`
const demoParser = new DemoParser();
const result = demoParser.execTest(text);
console.log(result);
})
describe('data', async () => {
const sysConfig = {
placeStyle: 1,
boardWidth: 2440,
boardLength: 1220,
// 测试刀库数据
knifeList: [knifeData, knifeData1, knifeData2]
}
const json = testJson
// 创建处理器集合
const processorManager = new ProcessorManager<any, any>();
// 这里省略了 选择处理器的环节 --这里选了demo开料机
const cuttingHandle = new demoHandleGroupCutting()
// 注册处理器
processorManager.registerProcessor(cuttingHandle.processorName, cuttingHandle.processor)
// 使用XX处理器 会返回激活【正在使用】的 处理器
let processor = processorManager.useProcessor(cuttingHandle.processorName)
// 或者 这样 获取 正在使用的处理器 注若未执行useProcessor 将会返回 undefind
// processor = processorManager.getCurrentProcessor()
/** 处理器配置加载 */
processor.updateModuleConfig(sysConfig)
const res = await processor.process(json)
// console.log('处理器所有流程都结束了', res);
})
/** demo 刀具数据 */
export const knifeData = {
"isEnabled": true,
"axleId": 2,
"knifeId": 2,
"processFace": "",
"knifeName": "T1",
"knifeType": 3,
"ability": [
5
],
"diameter": 5,
"length": 20,
"sawThiness": 7,
"sawDirection": 2,
"processDirection": 4,
"speed": 0,
"stepDepth": 0,
"offsetX": 0,
"offsetY": 0,
"offsetZ": 0,
"baseX": 0,
"baseY": 0,
"isModularDrill": false,
"isPreStartEnabled": false,
"preStartAheadActionCount": 5,
"isPreStartToolChangeDelay": false,
"preStartToolChangeDelayCode": "",
"isAxisStartCodePostpost": false,
"isAxisStopCodePrepose": false,
"drillGroupCode": "",
"axisStartCode": "M03 S18000\n",
"knifeStartCode": `M06 T1\nG43 H1\n`,
"drillGroupStartCode": "T1",
"drillGroupEndCode": "",
"knifeStopCode": "",
"axisStopCode": "M05\n",
"preStartActionDeferCode": "",
"useHolesGroupKnife": false,
"preStartActionStepsLimit": "",
"knifeNo": "",
"editable": true,
"isDefaultCutKnife": false,
"isPreStartChangeKnifeDefer": false
}
export const knifeData1 = {
"isEnabled": true,
"axleId": 2,
"knifeId": 2,
"processFace": "",
"knifeName": "T2",
"knifeType": 3,
"ability": [
5
],
"diameter": 6,
"length": 20,
"sawThiness": 7,
"sawDirection": 2,
"processDirection": 4,
"speed": 0,
"stepDepth": 0,
"offsetX": 0,
"offsetY": 0,
"offsetZ": 0,
"baseX": 0,
"baseY": 0,
"isModularDrill": false,
"isPreStartEnabled": false,
"preStartAheadActionCount": 5,
"isPreStartToolChangeDelay": false,
"preStartToolChangeDelayCode": "",
"isAxisStartCodePostpost": false,
"isAxisStopCodePrepose": false,
"drillGroupCode": "",
"axisStartCode": "M03 S18000\n",
"knifeStartCode": `M06 T2\nG43 H2\n`,
"drillGroupStartCode": "T2",
"drillGroupEndCode": "",
"knifeStopCode": "",
"axisStopCode": "M05\n",
"preStartActionDeferCode": "",
"useHolesGroupKnife": false,
"preStartActionStepsLimit": "",
"knifeNo": "",
"editable": true,
"isDefaultCutKnife": false,
"isPreStartChangeKnifeDefer": false
}
export const knifeData2 = {
"isEnabled": true,
"axleId": 2,
"knifeId": 2,
"processFace": "",
"knifeName": "T3",
"knifeType": 3,
"ability": [
5
],
"diameter": 6,
"length": 20,
"sawThiness": 7,
"sawDirection": 2,
"processDirection": 4,
"speed": 0,
"stepDepth": 0,
"offsetX": 0,
"offsetY": 0,
"offsetZ": 0,
"baseX": 0,
"baseY": 0,
"isModularDrill": false,
"isPreStartEnabled": false,
"preStartAheadActionCount": 5,
"isPreStartToolChangeDelay": false,
"preStartToolChangeDelayCode": "",
"isAxisStartCodePostpost": false,
"isAxisStopCodePrepose": false,
"drillGroupCode": "",
"axisStartCode": "M03 S18000\n",
"knifeStartCode": `M06 T2\nG43 H2\n`,
"drillGroupStartCode": "T3",
"drillGroupEndCode": "",
"knifeStopCode": "",
"axisStopCode": "M05\n",
"preStartActionDeferCode": "",
"useHolesGroupKnife": false,
"preStartActionStepsLimit": "",
"knifeNo": "",
"editable": true,
"isDefaultCutKnife": false,
"isPreStartChangeKnifeDefer": false
}