processParser/demoPage.md
2025-06-13 15:35:51 +08:00

1476 lines
40 KiB
Markdown
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.

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { TreeSelect, Form, FormItem, Input, Button, Table, Modal, Textarea, Tooltip, Switch, InputNumber, Checkbox } from 'ant-design-vue'
import { CodeParams, CodeParamsObj, CodeParamsList, GCodeAction, GCode, processServe, _knifeType, ProcessFileInfo } from '@/imes/processParser/confClass'
import { BasicTable } from '@/components/Table'
import { useRender, useTable, TableAction } from '@/components/Table'
import type { BasicColumn, FormSchema } from '@/components/Table'
import { ProcessInfo } from '@/imes/processParser/confClass'
import { processItemType } from '@/imes/processParser/confClass'
import { Knife } from '@/imes/biz/SysConfig'
import { ParserMain, device1, device2 } from '@/imes/processParser/parseMain'
import { FaceType } from '@/imes/vo/enums/FaceType'
// import { PlusOutlined } from '@ant-design/icons-vue'
onMounted(() => {
init()
})
const showOrderConfig = ref()
const showKnifeConfig = ref()
const boardLocation = ref('3')
const widthSideAxis = ref('0')
const lengthSideAxis = ref('2')
const boardLocationOptions = [
{
label: '左下角',
value: '0'
},
{
label: '右下角',
value: '1'
},
{
label: '右上角',
value: '2'
},
{
label: '左上角',
value: '3'
}
]
const SideAxisOptions = [
{
label: 'X轴正',
value: '0'
},
{
label: 'X轴负',
value: '1'
},
{
label: 'Y轴正',
value: '2'
},
{
label: 'Y轴负',
value: '3'
},
]
const heightSideAxisOptions = [
{
label: 'Z轴正',
value: 4
},
{
label: 'Z轴负',
value: 5
},
]
// /** 台面向上Z轴正 */
// WorkTop = 0,
// /** 板面向上Z轴正 */
// BoardFace = 1,
const options1 = [
{
label: '台面',
value: 0
},
{
label: '板面',
value: 1
}
]
// 加工项数据集
let testProcessListData: CodeParamsList = {
processListInfo: {
// 订单数据 (可选)
order: undefined,
/** 排单信息 (可选)*/
planOrderInfo: undefined,
// 商品信息 (可选)
materialInfo: undefined,
/** 所在板件信息 */
block: undefined,
/** 压缩包名称 处理器那边生成*/
zipFileName: 'demo.zip',
/** 文件名数据集 处理器那边生成 */
fileNameList: ['202504302211.ban'],
fileName: {
name: '202504302211',
Suffix: 'ban'
}
},
processList: [
{
processItemInfo: {
code: 'MARK',
order: 'Mark',
codeParams: '// start fileHead',
},
list: []
},
{
processItemInfo: {
code: 'FSTART',
order: 'FSTART',
},
list: []
},
{
processItemInfo: {
code: 'MARK',
order: 'Mark',
codeParams: '// changeKnife',
},
list: []
},
{
processItemInfo: {
knife: undefined,
code: 'T',
order: 'TD',
codeParams: {
diameter: 6
}
},
list: []
},
{
processItemInfo: {
code: 'MARK',
order: 'Mark',
codeParams: '// process Hole',
},
list: []
},
{
// 一个加工项 模拟一个孔的加工
processItemInfo: {
knife: {
diameter: 5,
},
code: 'C',
order: 'KnifeMove',
type: processItemType.Hole,
block: {
cutWidth: 400,
cutLength: 600
}
},
list: [
// 移动到安全点
{ x: 100.01, y: 100.01, z: 30.01, dir: 0, f: 10000 },
// 下刀
{ x: 100.01, y: 100.01, z: 0.01, dir: 1, f: 8000 },
// 抬刀
{ x: 100.01, y: 100.01, z: 30.01, dir: 0, f: 10000 },
]
},
{
// 一个加工项 模拟一个孔的加工
processItemInfo: {
knife: {
diameter: 6
},
code: 'C',
order: 'KnifeMove',
type: processItemType.Model,
block: {
cutWidth: 400,
cutLength: 600
}
},
list: [
// 移动到安全点
{ x: 150.01, y: 150.01, z: 30.01, dir: 0, f: 10000 },
// 下刀
{ x: 150.01, y: 150.01, z: 0.01, dir: 1, f: 8000 },
// 走刀
{ x: 345.01, y: 150.01, z: 0.01, r: 5, dir: 1, f: 8000 },
// 走刀
{ x: 350.01, y: 155.01, z: 0.01, dir: 2, r: 5.01, f: 8000 },
// 走刀
{ x: 350.01, y: 160.01, z: 0.01, dir: 1, f: 8000 },
// 走刀
{ x: 150.01, y: 160.01, z: 0.01, dir: 1, f: 8000 },
// 走刀
{ x: 150.01, y: 150.01, z: 0.01, dir: 1, f: 8000 },
// 抬刀
{ x: 150.01, y: 150.01, z: 30.01, dir: 0, f: 10000 },
]
},
{
processItemInfo: {
code: 'MARK',
order: 'Mark',
codeParams: '// cut block',
},
list: []
},
{
processItemInfo: {
code: 'C',
order: 'KnifeMove',
codeParams: '// process CutBlock',
type: processItemType.CutBlock,
block: {
cutWidth: 400,
cutLength: 600
}
},
list: [
// 移动到安全点
{ x: 0.01, y: 0.01, z: 30.01, dir: 0, f: 10000 },
// 下刀 到板面
{ x: 0.01, y: 0.01, z: 18.01, dir: 0, f: 10000 },
//切入
{ x: 0.01, y: 0.01, z: 6.01, dir: 1, f: 10000 },
// 斜线下刀
{ x: 10.01, y: 0.01, z: 0.01, dir: 1, f: 5000 },
// 走刀
{ x: 380.01, y: 0.01, z: 0.01, dir: 1, f: 8000 },
// 弧线走刀 G2
{ x: 400.01, y: 30.01, z: 0.01, r: 20.01, dir: 2, f: 8000 },
// 走刀
{ x: 400.01, y: 600.01, z: 0.01, dir: 1, f: 8000 },
// 走刀
{ x: 50.01, y: 600.01, z: 0.01, dir: 1, f: 8000 },
// 弧线走刀 G3
{ x: 0.01, y: 560.01, z: 0.01, r: 40.01, dir: 3, f: 8000 },
// 走刀
{ x: 0.01, y: 0.01, z: 0.01, dir: 1, f: 8000 },
// 斜线下刀没走的 走掉
{ x: 10.01, y: 0.01, z: 0.01, dir: 1, f: 8000 },
// 抬刀
{ x: 10.01, y: 0.01, z: 30.01, dir: 0, f: 10000 },
]
},
{
// 程序结束 ----停刀 + 停 轴
processItemInfo: {
knife: undefined,
code: 'CE',
order: 'CE1',
},
list: [
]
},
{
// 文件尾
processItemInfo: {
knife: undefined,
code: 'FEND',
order: 'FEND',
},
list: [
]
}
]
}
const parserMain = ref<ParserMain>(new ParserMain())
const deviceOptions = ref<any[]>([
{
label: '解析器1',
value: 'device1',
},
{
label: '解析器2',
value: 'device2',
}
])
const deviceSelectVal = ref()
const codeOptions = [
{
label: '文件头(FSTART)',
value: 'FSTART',
},
// {
// label: '调刀(T)',
// value: 'T',
// },
// {
// label: '主程序(C)',
// value: 'C',
// },
// {
// label: '主程序结束(CE)',
// value: 'CE',
// },
{
label: '文件尾(FEND)',
value: 'FEND',
},
// {
// label: '备注(MARK)',
// value: 'MARK',
// }
]
const codeSelectVal = ref()
const codeStr = ref('')
const help = ref('')
const param = ref()
const processData = ref<CodeParams[]>([
{ x: 0, y: 0, z: 0, dir: 3, i: 20, j: 10, k: 2, f: 10000 },
{ x: 100, y: 0, z: 0, dir: 3, r: 10, i: 20, j: 10, k: 2, f: 10000 },
{ x: 100, y: 200, z: 0, dir: 2, i: 20, j: 10, k: 2, f: 10000 },
{ x: 0, y: 200, z: 0, dir: 2, r: 10, i: 20, j: 10, k: 2, f: 10000 },
{ x: 0, y: 0, z: 0, dir: 1, f: 10000 },
])
const output = ref('')
const codeTextareaDisable = ref(true)
const formModel = ref({
/** x坐标 */
x: undefined,
/** y坐标 */
y: undefined,
/** z坐标 */
z: undefined,
/** 主程序代码编号*/
dir: undefined,
/** 圆弧半径 */
r: undefined,
/** 转速 */
s: undefined,
/** 给进 */
f: undefined,
/** IJK 模式的i */
i: undefined,
/** IJK 模式的j */
j: undefined,
/** IJK 模式的k */
k: undefined,
})
const columns = [
{
title: '指令',
dataIndex: 'name',
key: 'name',
},
// {
// title: '类型',
// dataIndex: 'type',
// key: 'type',
// },
{
title: '值',
dataIndex: 'value',
key: 'value',
},
{
title: '操作',
key: 'action',
width: 120,
}
]
const columns_knife = [
{
title: '序号',
dataIndex: 'index',
key: 'index',
width: 60,
},
{
title: '刀具名称',
dataIndex: 'knifeName',
key: 'knifeName',
width: 120,
},
{
title: '刀具类型',
dataIndex: 'knifeType',
key: 'knifeType',
width: 120,
},
{
title: '启用',
dataIndex: 'isEnabled',
key: 'isEnabled',
width: 50,
},
{
title: '直径',
dataIndex: 'diameter',
key: 'diameter',
width: 60,
},
{
title: '刀长',
dataIndex: 'length',
key: 'length',
width: 60,
},
{
title: '给进速度',
dataIndex: 'stepDepth',
key: 'stepDepth',
width: 100,
},
{
title: '偏置-X',
dataIndex: 'offsetX',
key: 'offsetX',
width: 80,
},
{
title: '偏置-Y',
dataIndex: 'offsetY',
key: 'offsetY',
width: 80,
},
{
title: '偏置-Z',
dataIndex: 'offsetZ',
key: 'offsetZ',
width: 80,
},
{
title: '基准坐标-长边',
dataIndex: 'axiosX',
key: 'axiosX',
width: 110,
},
{
title: '基准坐标-短边',
dataIndex: 'axiosY',
key: 'axiosY',
width: 110,
},
{
title: '轴启动指令后置',
dataIndex: 'isAxisStartCodePostpost',
key: 'isAxisStartCodePostpost',
width: 120,
},
{
title: '轴启动指令前置',
dataIndex: 'isAxisStartCodePrepost',
key: 'isAxisStartCodePrepost',
width: 120,
},
// {
// title: '启动代码',
// dataIndex: 'axisStartCode',
// key: 'axisStartCode',
// width: 110,
// },
{
title: '启动代码',
dataIndex: 'knifeStartCode',
key: 'knifeStartCode',
width: 110,
},
{
title: '停止代码',
dataIndex: 'knifeStopCode',
key: 'knifeStopCode',
width: 110,
},
{
title: '操作',
key: 'action',
width: 120,
}
]
function init() {
deviceOptions.value = parserMain.value.getDeviceList();
deviceSelectVal.value = 'device1'
deviceChange('device1')
}
/** 解析器切换 */
function deviceChange(val) {
console.log('deviceChange', val)
parserMain.value.setDeviceByKey(val)
parserMain.value._device.boardLocation = parseInt(boardLocation.value)
parserMain.value._device.widthSideAxis = parseInt(widthSideAxis.value)
parserMain.value._device.lengthSideAxis = parseInt(lengthSideAxis.value)
// switch (val) {
// case 'device1':
// let d1 = new device1();
// parserMain.value.setDevice(d1)
// break;
// case 'device2':
// let d2 = new device2();
// parserMain.value.setDevice(d2)
// break;
// default:
// break;
// }
codeSelectVal.value = 'FSTART'
codeChange('FSTART')
}
/** 代码切换 */
function codeChange(val) {
let keys = Object.keys(parserMain.value?._device[val])
help.value = keys.toString()
if (typeof (parserMain.value?._device[val]) == 'function') {
needParam.value = true
}
}
const needParam = ref(false)
/** 指令变化 */
function codeStrChange(e) {
let s = e.target.value
console.log('codeStrChange', parserMain.value?._device[codeSelectVal.value][s])
if (typeof (parserMain.value?._device[codeSelectVal.value][s]) == 'function') {
needParam.value = true
} else {
needParam.value = false
}
}
/*** 指令输入按钮 */
function handleSubmit() {
output.value += parserMain.value?.handleCode(codeSelectVal.value, codeStr.value, param.value)
}
/** 刀路数据输入 */
function processIn(data) {
console.log('processIn', data);
let param: CodeParamsObj = {
list: [data]
}
let str = parserMain.value?._device['C']['KnifeMove'](param)
output.value += str
}
/** 右侧清除按钮 */
function clearTextarea() {
output.value = '';
}
/** 完整数据测试 */
async function finalTest() {
let str = await parserMain.value?.getCode(testProcessListData)
output.value += str
}
async function exportTest() {
await parserMain.value?._device.exportFile(testProcessListData)
}
/**压力导出测试*/
async function exportTest1() {
}
/** 数据转换demo */
async function checkProcessData() {
let data = parserMain.value?.checkProcessDataPosition(testProcessListData)
console.log('checkProcessData', data)
}
const orderSettingArr = ref<any[]>()
function showOrderSetting() {
showOrderConfig.value = true
let settingArr: any[] = [...codeOptions];
for (let settingItem of settingArr) {
let code = settingItem.value
let orderArr = Object.keys(parserMain.value?._device[code])
settingItem.orderArr = []
for (const order of orderArr) {
let temp = {
type: typeof (parserMain.value?._device[code][order]),
name: order,
value: parserMain.value?._device[code][order]
}
// if (temp.type != 'function') {
settingItem.orderArr.push(temp);
// }
}
}
orderSettingArr.value = settingArr
console.log(settingArr);
}
function clearOrderSetting() {
orderSettingArr.value = [];
}
const knifeListTableData = ref<Array<Knife | _knifeType>>([])
function showKnifeSetting() {
showKnifeConfig.value = true
knifeListTableData.value = [];
console.log(parserMain.value?._device);
knifeListTableData.value = parserMain.value?._device.knifeList || []
}
function remove(orderSetting, i, column, _record, index) {
if (orderSettingArr.value) {
orderSettingArr.value[i].orderArr = orderSettingArr.value[i].orderArr.filter((e, x) => x != index)
}
}
function add(orderSetting, i) {
if (orderSettingArr.value == undefined) {
return
}
let name = `${orderSetting.value}${orderSettingArr.value[i].orderArr.length + 1}`
let temp = {
name: name,
value: ''
}
orderSettingArr.value[i].orderArr.push(temp)
}
function addKnife() {
let newKnife: _knifeType = {
diameter: 6,
knifeName: '',
}
knifeListTableData.value.push(newKnife)
}
function removeKnife(record, index) {
console.log(record, index, knifeListTableData);
knifeListTableData.value = knifeListTableData.value.filter((e, x) => x != index)
}
async function orderConfigSubmit() {
await parserMain.value?._device.updateCode(orderSettingArr.value)
console.log(orderSettingArr.value, parserMain.value?._device)
codeChange(codeSelectVal.value)
showOrderConfig.value = false
clearOrderSetting();
}
function KnifeConfigSubmit() {
parserMain.value?.setKnifeList(knifeListTableData.value)
showKnifeConfig.value = false
}
const testData1 = ref('')
// 导出加工信息
// "processListInfo": {
// /** 压缩包名称 处理器那边生成*/
// "zipFileName": "demo.zip"
// },
/** 测试数据 */
const jsonData = `
//数据说明
//1加工前先调6厘的刀
//2做孔加工的时候找【T1】的刀加工
//3做造型的加工找【T2】的刀
//4开料时 找5厘的刀
{
// 加工项信息
"processList": [
{
// 加工指令数据集
"processItemInfo": {
// 代码
"code": "MARK",
// 指令
"order": "Mark",
// 指令参数
"codeParams": "// start fileHead"
},
// 加工刀路信息
"list": []
},
{
"processItemInfo": {
"code": "FSTART",
"order": "F1"
},
"list": []
},
{
"processItemInfo": {
"code": "T",
"order": "TD",
"codeParams": {
"diameter": 6
}
},
"list": []
},
{
// 一个加工项 模拟一个孔的加工
"processItemInfo": {
"knife":{
"knifeName": "T1"
},
"code": "C",
"order": "KnifeMove",
"block":{
"cutWidth":400,
"cutLength":600
}
},
"list": [
// 移动到安全点
{ "x": 100.01, "y": 100.01, "z": 30.01, "dir": 0, "f": 10000 },
// 下刀
{ "x": 100.01, "y": 100.01, "z": 0.01, "dir": 1, "f": 8000 },
// 抬刀
{ "x": 100.01, "y": 100.01, "z": 30.01, "dir": 0, "f": 10000 }
]
},
{
// 一个加工项 模拟一个造型的加工
"processItemInfo": {
"knife":{
"knifeName": "T2"
},
"code": "C",
"order": "KnifeMove",
"block":{
"cutWidth":400,
"cutLength":600
}
},
"list": [
// 移动到安全点
{ "x": 150.01, "y": 150.01, "z": 30.01, "dir": 0, "f": 10000 },
// 下刀
{ "x": 150.01, "y": 150.01, "z": 0.01, "dir": 1, "f": 8000 },
// 走刀
{ "x": 345.01, "y": 150.01, "z": 0.01, "r": 5, "dir": 1, "f": 8000 },
// 走刀
{ "x": 350.01, "y": 155.01, "z": 0.01, "dir": 2, "r": 5.01, "f": 8000 },
// // 走刀
// { "x": 350.01, "y": 150.01, "z": 0.01, "dir": 1, "f": 8000 },
// 走刀
{ "x": 350.01, "y": 160.01, "z": 0.01, "dir": 1, "f": 8000 },
// 走刀
{ "x": 150.01, "y": 160.01, "z": 0.01, "dir": 1, "f": 8000 },
// 走刀
{ "x": 150.01, "y": 150.01, "z": 0.01, "dir": 1, "f": 8000 },
// 抬刀
{ "x": 150.01, "y": 150.01, "z": 30.01, "dir": 0, "f": 10000 }
]
},
{
"processItemInfo": {
"code": "MARK",
"order": "Mark",
"codeParams": "// cut block"
},
"list": []
},
{
"processItemInfo": {
"knife":{
"diameter": 5
},
"code": "C",
"order": "KnifeMove",
"block":{
"cutWidth":400,
"cutLength":600
}
},
"list": [
// 移动到安全点
{ "x": 0.01, "y": 0.01, "z": 30.01, "dir": 0, "f": 10000 },
// 下刀 到板面
{ "x": 0.01, "y": 0.01, "z": 18.01, "dir": 0, "f": 10000 },
//切入
{ "x": 0.01, "y": 0.01, "z": 6.01, "dir": 1, "f": 10000 },
// 斜线下刀
{ "x": 20.01, "y": 0.01, "z": 0.01, "dir": 1, "f": 5000 },
// 走刀
{ "x": 380.01, "y": 0.01, "z": 0.01, "dir": 1, "f": 8000 },
// 弧线走刀 G2
{ "x": 400.01, "y": 30.01, "z": 0.01, "r": 20.01, "dir": 2, "f": 8000 },
// 走刀
{ "x": 400.01, "y": 600.01, "z": 0.01, "dir": 1, "f": 8000 },
// 走刀
{ "x": 50.01, "y": 600.01, "z": 0.01, "dir": 1, "f": 8000 },
// 弧线走刀 G3
{ "x": 0.01, "y": 560.01, "z": 0.01, "r": 40.01, "dir": 3, "f": 8000 },
// 走刀
{ "x": 0.01, "y": 0.01, "z": 0.01, "dir": 1, "f": 8000 },
// 斜线下刀没走的 走掉
{ "x": 20.01, "y": 0.01, "z": 0.01, "dir": 1, "f": 8000 },
// 抬刀
{ "x": 20.01, "y": 0.01, "z": 30.01, "dir": 0, "f": 10000 }
]
},
{
// 程序结束 ----停刀 + 停 轴
"processItemInfo": {
"code": "CE",
"order": "CE1"
},
"list": [
]
},
{
// 文件尾
"processItemInfo": {
"code": "FEND",
"order": "FEND1"
},
"list": [
]
}
]
}`
/** 测试数据 */
const txtData = `FSTART\nTD 5\nG0 X100 Y100 Z10 F8000\ng0 x100 y100 z18 f8000\ng2 x120 y120 z18 R20 f8000\ng3 x100 y100 z18 i20 j0 k0 f8000\nTN T2\nFEND\n`
const testData = ref(jsonData)
const showTest2 = ref(false)
const _flag = ref('JSON')
/** 输出按钮*/
function testDataSubmit() {
// handleJsonData()
// handleTxtData()
let flag = _flag.value
// flag = 'JSON'
switch (flag) {
case 'txt':
handleTxtData()
break;
case 'JSON':
handleJsonData()
break;
default:
break;
}
}
/**处理JSON格式的数据 */
async function handleJsonData() {
let str = testData1.value
let strArr = str.split('\n')
let arr = strArr.filter(e => !e.includes('//') && !e.includes('/**') || e.includes('"//'))
arr.forEach(s => {
s = s.trim()
})
let realStr = arr.join('\n')
let dd: any = ''
try {
dd = JSON.parse(realStr)
} catch (error) {
alert('输入的Json有误')
}
let tt = await parserMain.value?.getCode(dd) || ''
output.value += tt
}
/** 处理指令txt文本数据 */
function handleTxtData() {
let str = testData1.value
let strArr = str.split('\n')
let code = ''
let orderList = parserMain.value._device.getCodeListByOrderKeys(['FSTART', 'T', 'C', 'FEND', 'MARK'])
const reg_G = /^[Gg](\d+\.?\d*)$/
const reg_X = /^[Xx](\d+\.?\d*)$/
const reg_Y = /^[Yy](\d+\.?\d*)$/
const reg_Z = /^[Zz](\d+\.?\d*)$/
const reg_F = /^[Ff](\d+\.?\d*)$/
const reg_R = /^[Rr](\d+\.?\d*)$/
const reg_I = /^[Ii](\d+\.?\d*)$/
const reg_J = /^[Jj](\d+\.?\d*)$/
const reg_K = /^[Kk](\d+\.?\d*)$/
strArr.forEach(str => {
let codeLineData = str.split(' ')
if (Object.keys(codeLineData) && codeLineData.length > 0) {
let orderKey = codeLineData[0]
let paramsValue = codeLineData[1]
let orderItem = orderList.find(e => e.order == orderKey)
if (orderItem) {
/** */
console.log('orderKey', orderKey);
if (orderItem.order == 'KnifeMove') {
// let codeParams: CodeParams = {
// }
} else {
code += parserMain.value.handleCode(orderItem.code, orderItem.order, paramsValue)
}
} else {
let tempCodeParams: CodeParams = {}
codeLineData.forEach(e => {
if (['G0', 'G00', 'G1', 'G01', 'G2', 'G02', 'G3', 'G03',
'g0', 'g00', 'g1', 'g01', 'g2', 'g02', 'g3', 'g03'
].includes(e)) {
let match = e.match(reg_G)
if (match != null) {
if (match[1] == '0' || match[1] == '00') {
tempCodeParams.dir = 0
} else if (match[1] == '1' || match[1] == '01') {
tempCodeParams.dir = 1
} else if (match[1] == '2' || match[1] == '02') {
tempCodeParams.dir = 2
} else if (match[1] == '3' || match[1] == '03') {
tempCodeParams.dir = 3
}
}
} else if (e.includes('x') || e.includes('X')) {
let match = e.match(reg_X)
if (match != null) {
tempCodeParams.x = match[1]
}
} else if (e.includes('y') || e.includes('Y')) {
let match = e.match(reg_Y)
if (match != null) {
tempCodeParams.y = match[1]
}
} else if (e.includes('z') || e.includes('Z')) {
let match = e.match(reg_Z)
if (match != null) {
tempCodeParams.z = match[1]
}
} else if (e.includes('f') || e.includes('F')) {
let match = e.match(reg_F)
if (match != null) {
tempCodeParams.f = match[1]
}
} else if (e.includes('r') || e.includes('R')) {
let match = e.match(reg_R)
if (match != null) {
tempCodeParams.r = match[1]
}
} else if (e.includes('i') || e.includes('I')) {
let match = e.match(reg_I)
if (match != null) {
tempCodeParams.i = match[1]
}
} else if (e.includes('j') || e.includes('J')) {
let match = e.match(reg_J)
if (match != null) {
tempCodeParams.j = match[1]
}
} else if (e.includes('k') || e.includes('K')) {
let match = e.match(reg_K)
if (match != null) {
tempCodeParams.k = match[1]
}
}
})
console.log('tempCodeParams.dir', tempCodeParams.dir, str);
if (tempCodeParams.dir != undefined) {
let tempProcessItem: CodeParamsObj = {
list: [tempCodeParams]
}
code += parserMain.value.handleCode('C', 'KnifeMove', tempProcessItem)
} else {
code += str + '\n'
}
}
}
})
if (parserMain.value._device.isUseSimpleCode == true) {
code = parserMain.value._device.handleSimpleCode(code)
}
output.value += code
}
/** 测试 */
async function testFileExportSubmit() {
let str = testData1.value
let strArr = str.split('\n')
let arr = strArr.filter(e => !e.includes('//') && !e.includes('/**') || e.includes('"//'))
arr.forEach(s => {
s = s.trim()
})
let realStr = arr.join('\n')
let dd = ''
try {
dd = JSON.parse(realStr)
} catch (error) {
alert('输入的Json有误')
}
let processListInfo: ProcessFileInfo = {
zipFileName: 'demo.zip',
fileName: {
name: '202504302211',
Suffix: 'ban'
}
}
await parserMain.value?.handleCode('FILE', 'START', processListInfo.zipFileName)
// 测试 到出的文件数量
let testRound = 10000
await loopHandCode(0)
async function loopHandCode(i) {
let fileName = `demo_${i}.ban`
let content = await parserMain.value?.getCode(dd) || ''
let data = {
fileName,
content,
isBase64: false,
ncFileEncoding: 'UTF-8'
}
await parserMain.value?.handleCode('FILE', 'ADDFILE', data)
if (i < testRound) {
i++
await loopHandCode(i)
} else {
await parserMain.value?.handleCode('FILE', 'END')
console.timeEnd('loopHandCode')
}
}
}
function boardLocationSelectChange() {
parserMain.value._device.boardLocation = parseInt(boardLocation.value)
}
function widthSideAxisSelectChange() {
if (checkSideAxisVal()) {
parserMain.value._device.widthSideAxis = parseInt(widthSideAxis.value)
} else {
alert('轴向设置不正确')
}
}
function lengthSideAxisSelectChange() {
if (checkSideAxisVal()) {
parserMain.value._device.lengthSideAxis = parseInt(lengthSideAxis.value)
} else {
alert('轴向设置不正确')
}
}
function checkSideAxisVal() {
let check = false
let arr_x = ['0', '1']
let arr_y = ['2', '3']
if (arr_x.includes(widthSideAxis.value)) {
if (arr_y.includes(lengthSideAxis.value)) {
check = true
} else {
check == false
}
}
if (arr_x.includes(lengthSideAxis.value)) {
if (arr_y.includes(widthSideAxis.value)) {
check = true
} else {
check == false
}
}
return check
}
</script>
<template>
<div class="processDemo">
<div class="setting">
<div class="settingTop">
解析器
<TreeSelect v-model:value="deviceSelectVal" @change="deviceChange" tree-node-filter-prop="label"
:tree-data="deviceOptions" class="typeSelect">
</TreeSelect>
<Button @click="showKnifeSetting">刀库设置</Button>
<Button @click="showOrderSetting">指令设置</Button>
<Button @click="handleSubmit">输入</Button>
<div style="float: right;">
</div>
</div>
<div>
代码
<TreeSelect v-model:value="codeSelectVal" @change="codeChange" tree-node-filter-prop="label"
:tree-data="codeOptions" class="typeSelect">
</TreeSelect>
指令
<Input style="width: 100px;" @change="codeStrChange" v-model:value="codeStr" />
<span v-show="help" style="color:red">
<template v-if="needParam && codeStr != 'Mark'">
该指令为内置方法。无法在此处调用
</template>
<template v-else>
解析器对应的代码已配置的指令为 {{ help }}
</template>
</span>
<span v-show="needParam">参数</span>
<Input v-show="needParam" style="width: 300px;" v-model:value="param" />
</div>
<div style="margin-top: 20px;">
<span>
加工刀路数据测试---主程序CKnifeMove 测试
<Button @click="showTest2 = !showTest2">{{ showTest2 ? '隐藏' : '显示' }}</Button>
<!-- <span>范例数据:{x:100,y:100,z:0,dir:1,f:8000,r:0,i:0}</span> -->
</span>
<Form v-if="showTest2" class="form" :model="formModel">
<FormItem class="formItem" label="x">
<Input v-model:value="formModel.x" /><span>x坐标</span>
</FormItem>
<FormItem class="formItem" label="y">
<Input v-model:value="formModel.y" /><span>y坐标</span>
</FormItem>
<FormItem class="formItem" label="z">
<Input v-model:value="formModel.z" /><span>z坐标</span>
</FormItem>
<FormItem class="formItem" label="dir">
<Input v-model:value="formModel.dir" /><span>使用的G代码编号,<br>例如1 = G1,目前仅支持0-3 即 G0、G1、G2、G3</span>
</FormItem>
<FormItem class="formItem" label="f">
<Input v-model:value="formModel.f" /><span>速度</span>
</FormItem>
<FormItem class="formItem" label="r">
<Input v-model:value="formModel.r" /><span>圆弧半径</span>
</FormItem>
<FormItem class="formItem" label="i">
<Input v-model:value="formModel.i" /><span>IJK模式的i,圆心相对起点的X坐标偏移</span>
</FormItem>
<FormItem class="formItem" label="j">
<Input v-model:value="formModel.j" /><span>IJK模式的i,圆心相对起点的Y坐标偏移</span>
</FormItem>
<FormItem class="formItem" label="k">
<Input v-model:value="formModel.k" /><span>IJK模式的i,圆心相对起点的Z坐标偏移</span>
</FormItem>
<FormItem class="formItem" style="float: right;">
<Button @click="processIn(formModel)">刀路数据输入</Button>
</FormItem>
</Form>
</div>
<div style="margin-top: 20px;">
<!-- <Button @click="checkProcessData">数据转换</Button> -->
<Tooltip placement="top">
<template #title>
<span>该测试的数据源为内置数据</span>
</template>
<div>
<Button @click="finalTest">完整数据测试</Button>
<Button @click="exportTest">导出测试</Button>
<!-- <Button @click="exportTest1">压力导出测试</Button> -->
</div>
</Tooltip>
</div>
<div>
<span>测试数据 </span>
<div style="display: flex;">
<div v-if="parserMain._device">
机台宽
<Input class="typeSelect1" v-model:value="parserMain._device.boardWidth" />
</div>
<div v-if="parserMain._device">
机台长
<Input class="typeSelect1" v-model:value="parserMain._device.boardLength" />
</div>
<div v-if="parserMain._device">
机台高
<Input class="typeSelect1" v-model:value="parserMain._device.boardHeight" />
</div>
</div>
<div style="display: flex;">
<div>
水平原点
<TreeSelect v-model:value="boardLocation" @change="boardLocationSelectChange" tree-node-filter-prop="label"
:tree-data="boardLocationOptions" class="typeSelect1"></TreeSelect>
</div>
<div v-if="parserMain._device">
垂直原点
<TreeSelect v-model:value="parserMain._device.originZ0Position" tree-node-filter-prop="label"
:tree-data="options1" class="typeSelect1"></TreeSelect>
</div>
<div>
纵轴轴向
<TreeSelect v-model:value="widthSideAxis" @change="widthSideAxisSelectChange" tree-node-filter-prop="label"
:tree-data="SideAxisOptions" class="typeSelect1"></TreeSelect>
</div>
<div>
横轴轴向
<TreeSelect v-model:value="lengthSideAxis" @change="lengthSideAxisSelectChange"
tree-node-filter-prop="label" :tree-data="SideAxisOptions" class="typeSelect1"></TreeSelect>
</div>
<div v-if="parserMain._device">
垂直轴向
<TreeSelect v-model:value="parserMain._device.heightAxis" tree-node-filter-prop="label"
:tree-data="heightSideAxisOptions" class="typeSelect1"></TreeSelect>
</div>
</div>
<div style="display: flex;">
<div v-if="parserMain._device">
是否空行处理
<Switch v-model:checked="parserMain._device.isFilterEmptyLine"></Switch>
<!-- <Input class="typeSelect1" v-model:value="parserMain._device.boardWidth" /> -->
</div>
<div v-if="parserMain._device">
是否显示注释
<Switch v-model:checked="parserMain._device.isNcFileComment"></Switch>
</div>
<div v-if="parserMain._device">
空行插入前缀
<Switch v-model:checked="parserMain._device.isNcLinePrefixEnabled"></Switch>
<Input class="typeSelect1" v-model:value="parserMain._device.ncLinePrefix" />
</div>
<div v-if="parserMain._device">
空行插入后缀
<Switch v-model:checked="parserMain._device.isNcLineSuffixEnabled"></Switch>
<Input class="typeSelect1" v-model:value="parserMain._device.ncLineSuffix" />
</div>
<div v-if="parserMain._device">
精简指令
<Switch v-model:checked="parserMain._device.isUseSimpleCode"></Switch>
</div>
<div v-if="parserMain._device">
换刀后精简
<Switch v-model:checked="parserMain._device.isSimpleFirstCode"></Switch>
</div>
<div v-if="parserMain._device">
圆弧反转
<Switch v-model:checked="parserMain._device.reverseArcCode"></Switch>
</div>
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="margin:auto 0;">NC标识符----:</div>
<div v-if="parserMain._device">
G0
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeFreeMove" />
</div>
<div v-if="parserMain._device">
G1
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeLineInterpolation" />
</div>
<div v-if="parserMain._device">
G2
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeClockwiseArcInterpolation" />
</div>
<div v-if="parserMain._device">
G3
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeAnticlockwiseArcInterpolation" />
</div>
<!-- <div v-if="parserMain._device">
X
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeAxisX" />
</div>
<div v-if="parserMain._device">
Y
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeAxisY" />
</div>
<div v-if="parserMain._device">
Z
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeAxisZ" />
</div>
<div v-if="parserMain._device">
F
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeSpeed" />
</div>
<div v-if="parserMain._device">
I
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeIncrementAxisX" />
</div>
<div v-if="parserMain._device">
J
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeIncrementAxisY" />
</div>
<div v-if="parserMain._device">
K
<Input class="typeSelect2" v-model:value="parserMain._device.NcCodeIncrementAxisZ" />
</div> -->
</div>
<Button @click="testDataSubmit">输出</Button>
<span style="color: red;">说明G代码支持大小写兼容 ,指令可以参考指令设置,换刀指令:【TD】【TN】,G2、G3 圆弧指令输入R则优先为R模式 否则根据IJK值生成代码</span>
<!-- <Button @click="testFileExportSubmit">导出测试</Button> -->
<div class="testDataBox">
<Textarea class="testData" v-model:value="testData1"></Textarea>
<Tooltip>
<template #title>
<span>范例</span>
</template>
<Textarea class="testData" :disabled="true" v-model:value="testData"></Textarea>
</Tooltip>
</div>
</div>
</div>
<div class="code">
<div class="tool">
<Button @click="clearTextarea">clear</Button>
</div>
<Textarea class="codeTextarea" :disabled="codeTextareaDisable" v-model:value="output"></Textarea>
</div>
<Modal v-model:open="showOrderConfig" :title="'指令设置--' + deviceOptions.find(e => e.value == deviceSelectVal)?.label"
:width="1000" @cancel="clearOrderSetting" @ok="orderConfigSubmit">
<div class="modelContent" v-if="orderSettingArr">
<template v-for="(orderSetting, i) in orderSettingArr">
<div>
<span>{{ orderSetting.label }}</span>
<Button @click="add(orderSetting, i)" style="float: right;" type="primary" shape="circle">
<template #icon>
<PlusOutlined />
</template>
</Button>
<Table :data-source="orderSetting.orderArr" :columns="columns" :pagination="false">
<template #bodyCell="{ column, record: _record, index }">
<template v-if="column.key === 'name'">
<Input :disabled="true" v-model:value="orderSettingArr[i].orderArr[index].name"></Input>
</template>
<template v-if="column.key === 'value'">
<Textarea v-if="orderSettingArr[i].orderArr[index].type != 'function'"
v-model:value="orderSettingArr[i].orderArr[index].value"></Textarea>
<span v-else>
内置指令,无法修改
</span>
</template>
<template v-if="column.key === 'action' && orderSettingArr[i].orderArr[index].type != 'function'">
<span @click="remove(orderSetting, i, column, _record, index)"
style="color:red;cursor: pointer;">移除</span>
</template>
</template>
</Table>
</div>
</template>
</div>
</Modal>
<Modal v-model:open="showKnifeConfig" :title="'设置刀库'" :width="1000" @ok="KnifeConfigSubmit">
<div class="modelContent">
<Button style="float:right" @click="addKnife">新增刀具</Button>
<Table :data-source="knifeListTableData" :columns="columns_knife" :scroll="{ x: 1500, y: 300 }">
<template #bodyCell="{ column, record: _record, index }">
<template v-if="column.key === 'knifeName' || column.key === 'knifeType'">
<Input v-model:value="knifeListTableData[index][column.key]"></Input>
</template>
<template
v-if="['diameter', 'length', 'stepDepth', 'offsetX', 'offsetY', 'offsetZ', 'axiosX', 'axiosY'].includes(column.key?.toString())">
<InputNumber v-model:value="knifeListTableData[index][column.key]" />
</template>
<template
v-else-if="column.key == 'knifeStartCode' || column.key == 'knifeStopCode' || column.key == 'axisStartCode' || column.key == 'axisStopCode'">
<Textarea v-model:value="knifeListTableData[index][column.key]"></Textarea>
</template>
<template
v-else-if="['isEnabled', 'isAxisStartCodePostpost', 'isAxisStartCodePrepost'].includes(column.key?.toString())">
<Checkbox v-model:checked="knifeListTableData[index][column.key]" />
</template>
<template v-else-if="column.key === 'action'">
<span @click="removeKnife(_record, index)" style="color:red;cursor: pointer;">移除</span>
</template>
</template>
</Table>
</div>
</Modal>
</div>
</template>
<style>
.processDemo {
height: 100%;
width: 100%;
display: flex;
flex-direction: row;
}
.setting {
flex: 2;
padding: 10px 8px;
}
.code {
flex: 1
}
.codeTextarea {
width: 90%;
height: 90% !important;
background-color: #FFFFFF !important;
overflow: auto;
color: #000000 !important;
}
.testDataBox {
display: flex;
flex-direction: row;
}
.testData {
overflow: auto;
min-height: 450px !important;
background-color: #FFFFFF !important;
color: #000000 !important;
}
.typeSelect {
width: 160px;
padding-bottom: 10px;
}
.form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.formItem {
width: 160px;
}
.processListStrTextarea {
width: 100%;
height: 270px;
}
.modelContent {
max-height: 650px;
overflow: auto;
}
.typeSelect1 {
width: 100px;
}
.typeSelect2 {
width: 50px;
}
</style>