init
This commit is contained in:
commit
305a30372a
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
dist-packs/
|
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Orta.vscode-jest"]
|
||||
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"jest.useJest30": true
|
||||
}
|
6
jest.config.js
Normal file
6
jest.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
transform: {
|
||||
'^.+\\.(t|j)sx?$': '@swc/jest',
|
||||
},
|
||||
extensionsToTreatAsEsm: ['.ts', '.tsx']
|
||||
};
|
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "cut-abstractions",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"exports": {
|
||||
".": "./**/*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"release": "pnpm pack --pack-destination ./dist-packs",
|
||||
"clean":"rimraf ./dist",
|
||||
"test": "jest"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@9.1.1+sha1.09ada6cd05003e0ced25fb716f9fda4063ec2e3b",
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^30.0.2",
|
||||
"@swc/core": "^1.12.4",
|
||||
"@swc/jest": "^0.2.38",
|
||||
"jest": "^30.0.2",
|
||||
"rimraf": "^6.0.1",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
3057
pnpm-lock.yaml
Normal file
3057
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
348
samples/confClass.ts
Normal file
348
samples/confClass.ts
Normal file
@ -0,0 +1,348 @@
|
||||
|
||||
|
||||
|
||||
/** 内部指令 接收 */
|
||||
export class CodeAction {
|
||||
code?: String
|
||||
order?: String
|
||||
codeParams?: any
|
||||
}
|
||||
/**内部响应类 */
|
||||
export class GCodeResType {
|
||||
code: number = -1
|
||||
data: any = null
|
||||
msg: string = ''
|
||||
logError(msg) {
|
||||
console.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 加工项 点数据
|
||||
export class CodeParams {
|
||||
/** x坐标 */
|
||||
x?: Number | String
|
||||
/** y坐标 */
|
||||
y?: Number | String
|
||||
/** z坐标 */
|
||||
z?: Number | String
|
||||
/** 调用的代码编号 */
|
||||
dir?: Number | String
|
||||
/** 圆弧半径 */
|
||||
r?: Number | String
|
||||
/** 速度 */
|
||||
f?: Number | String
|
||||
/** IJK 模式的i */
|
||||
i?: Number | String
|
||||
/** IJK 模式的j */
|
||||
j?: Number | String
|
||||
/** IJK 模式的k */
|
||||
k?: Number | String
|
||||
|
||||
/** 代码标识 */
|
||||
codeKey?: String
|
||||
/** x坐标 */
|
||||
xKey?: String
|
||||
/** y坐标 */
|
||||
yKey?: String
|
||||
/** z坐标 */
|
||||
zKey?: String
|
||||
/** 圆弧半径 */
|
||||
rKey?: String
|
||||
/** 速度 */
|
||||
fKey?: String
|
||||
/** IJK 模式的i */
|
||||
iKey?: String
|
||||
/** IJK 模式的j */
|
||||
jKey?: String
|
||||
/** IJK 模式的k */
|
||||
kKey?: String
|
||||
}
|
||||
|
||||
|
||||
export type _knifeType = Partial<Knife>
|
||||
|
||||
/**
|
||||
* 板面类型
|
||||
* 0正面 1反面 2侧面 21左侧面 22右侧面 23上侧面 24下侧面 29 弧形侧面 30异形侧面
|
||||
*/
|
||||
export enum FaceType {
|
||||
/** 正面 */
|
||||
FRONT = 0,
|
||||
/** 反面 */
|
||||
BACK = 1,
|
||||
/** 侧面 */
|
||||
SIDE = 2,
|
||||
/** 左侧面 */
|
||||
LEFT_SIDE = 21,
|
||||
/** 右侧面 */
|
||||
RIGHT_SIDE = 22,
|
||||
/** 上侧面 */
|
||||
TOP_SIDE = 23,
|
||||
/** 下侧面 */
|
||||
BOTTOM_SIDE = 24,
|
||||
/** 弧形侧面 */
|
||||
CURVED_SIDE = 29,
|
||||
/** 异形侧面 */
|
||||
SPECIAL_SHAPED_SIDE = 30,
|
||||
}
|
||||
|
||||
/** 开料刀 */
|
||||
export class Knife {
|
||||
/** 是否启用 */
|
||||
isEnabled = true;
|
||||
/** 轴号 */
|
||||
axleId = 0;
|
||||
/** 开料刀ID号 */
|
||||
knifeId = 1;
|
||||
/** 加工面(0正面 1反面 2左侧面 3右侧面 4上侧面 5下侧面 6任意) */
|
||||
processFace = 0;
|
||||
/** 刀名称 */
|
||||
knifeName = '';
|
||||
/** 刀具类型(1铣刀 2成型刀 3钻头 4锯 5刀片) */
|
||||
knifeType = KnifeType.MILLING_CUTTER;
|
||||
/** 功能属性(数组): 1开料/切割 2拉槽 3铣型 4铣孔 5钻孔 6拉米诺 7乐扣 8T型 */
|
||||
ability: any = [];
|
||||
|
||||
// /** 默认开料刀 */
|
||||
// isDefaultCutKnife = false;
|
||||
// /** 是否可用于开料切割 */
|
||||
// isCuttingKnife = false;
|
||||
// /** 是否允许铣孔(knifeType为铣刀生效) */
|
||||
// isMillingAllowed = false;
|
||||
/** 刀直径mm */
|
||||
diameter = 6;
|
||||
/** 刀长(最大深度) */
|
||||
length = 20;
|
||||
/** 锯齿厚度,单次加工切缝宽度 */
|
||||
sawThiness = 0;
|
||||
/**锯向: 0横向(或长边) 1纵向(短边) 2自由角度*/
|
||||
sawDirection = 0;
|
||||
/**切向加工方向: 0横向左往右 2横向右往左 3纵向上往下 4纵向下往上 5随意 */
|
||||
processDirection = 0;
|
||||
/**进给速度, 0取系统默认 */
|
||||
speed = 0;
|
||||
/** 进给深度 */
|
||||
stepDepth = 0;
|
||||
// /** 组号 */
|
||||
// groupNo = 0;
|
||||
// /** 主刀 */
|
||||
// isMainKnife = false;
|
||||
// /** 是否高级加工 */
|
||||
// isAdvancedProcessEnabled = false;
|
||||
// /** 是否集合加工 */
|
||||
// isBatchProcessEnabled = false;
|
||||
// /** 副刀偏置长边偏移(Y轴) */
|
||||
// auxKnifeOffsetY = 0;
|
||||
// /** 副刀偏置短边偏移(X轴) */
|
||||
// auxKnifeOffsetX = 0;
|
||||
/** 偏置短边偏移(X轴)-相对于工件原点位置XY坐标的短边方向偏移量 */
|
||||
offsetX = 0;
|
||||
/** 偏置长边偏移(Y轴) -相对于工件原点位置XY坐标的长边方向偏移量*/
|
||||
offsetY = 0;
|
||||
/** 偏置垂直偏移(Z轴) -相对于工件原点位置XY坐标的垂直方向偏移量*/
|
||||
offsetZ = 0;
|
||||
/** 基准坐标-短边(X轴) -钻头在钻包中短边方向(纵向)的相对位置 */
|
||||
baseX = 0;
|
||||
/** 基准坐标-长边(Y轴) -钻头在钻包中长边方向(横向)的相对位置 */
|
||||
baseY = 0;
|
||||
/**组合钻 */
|
||||
isModularDrill = false;
|
||||
/** 是否预启动 */
|
||||
isPreStartEnabled = false;
|
||||
/** 预启动提前动作数 */
|
||||
preStartAheadActionCount = 5;
|
||||
/** 预启动延迟换刀 */
|
||||
isPreStartToolChangeDelay = false;
|
||||
/** 预启动延迟换刀指令 */
|
||||
preStartToolChangeDelayCode = '';
|
||||
/** 轴启动指令后置 */
|
||||
isAxisStartCodePostpost = false;
|
||||
/** 轴停止指令前置 */
|
||||
isAxisStopCodePrepose = false;
|
||||
/** 钻组独立指令(启用后,刀起始指令、刀结束指令使用钻组起始指令、钻组结束指令替换) */
|
||||
drillGroupCode = '';
|
||||
|
||||
/** 轴启动代码*/
|
||||
axisStartCode = "";
|
||||
/** 刀启动代码 */
|
||||
knifeStartCode = '';
|
||||
/** 钻组起始指令 */
|
||||
drillGroupStartCode = '';
|
||||
/** 钻组结束指令 */
|
||||
drillGroupEndCode = '';
|
||||
/** 刀停止代码 */
|
||||
knifeStopCode = '';
|
||||
/** 轴停止指令 */
|
||||
axisStopCode = '';
|
||||
// /** 高级加工指令 */
|
||||
// advancedCode = '';
|
||||
|
||||
|
||||
/** 设置刀具(轴号, 刀名, 刀直径, 是否主刀, 是否铣孔, 是否开料刀) */
|
||||
// set(axleId: number, name: string, diameter: number, isMainKnife: boolean, isMillingAllowed: boolean, isCuttingKnife: boolean)
|
||||
/** 设置刀具(轴号, 刀名, 刀类型, 刀直径, 刀长, 是否默认刀) */
|
||||
}
|
||||
|
||||
|
||||
/** 刀类型: MILLING_CUTTER铣刀 FORMING_CUTTER成型刀 DRILL钻头 SAW锯 BLADE刀片 */
|
||||
export enum KnifeType {
|
||||
/** 铣刀 */
|
||||
MILLING_CUTTER = 1,
|
||||
/** 成型刀 */
|
||||
FORMING_CUTTER = 2,
|
||||
/** 钻头 */
|
||||
DRILL = 3,
|
||||
/** 锯 */
|
||||
SAW = 4,
|
||||
/** 刀片 */
|
||||
BLADE = 5
|
||||
}
|
||||
|
||||
/** 刀功能:
|
||||
** 1-CUT开料/切割 2-PULLING_GROOVE拉槽 3-MILLING_MODEL铣型 4-MILLING_HOLE铣孔
|
||||
** 5-DRILL_HOLE钻孔 6-RAMINO拉米诺 7-EASY_FASTEN乐扣 8-T_TYPE T型 */
|
||||
export enum AbilityType {
|
||||
/** 1开料/切割 */
|
||||
CUT = 1,
|
||||
/** 2拉槽 */
|
||||
PULLING_GROOVE = 2,
|
||||
/** 3铣型 */
|
||||
MILLING_MODEL = 3,
|
||||
/** 4铣孔 */
|
||||
MILLING_HOLE = 4,
|
||||
/** 5钻孔 */
|
||||
DRILL_HOLE = 5,
|
||||
/** 6拉米诺 */
|
||||
RAMINO = 6,
|
||||
/** 7乐扣 */
|
||||
EASY_FASTEN = 7,
|
||||
/** 8T型 */
|
||||
T_TYPE = 8
|
||||
}
|
||||
|
||||
/** 枚举 坐标轴类型 */
|
||||
export enum AxisType {
|
||||
/** X轴正 */
|
||||
X_POS = 0,
|
||||
/** X轴负 */
|
||||
X_NEG = 1,
|
||||
/** Y轴正 */
|
||||
Y_POS = 2,
|
||||
/** Y轴负 */
|
||||
Y_NEG = 3,
|
||||
/** 向上Z轴正 */
|
||||
Z_POS = 4,
|
||||
/** 向下Z轴负 */
|
||||
Z_NEG = 5,
|
||||
}
|
||||
|
||||
/** 枚举 坐标轴类型 */
|
||||
export enum OriginZPosition {
|
||||
/** 台面向上Z轴正 */
|
||||
WorkTop = 0,
|
||||
/** 板面向上Z轴正 */
|
||||
BoardFace = 1,
|
||||
}
|
||||
|
||||
// nc文件编码
|
||||
export const ncEncodeMap = {
|
||||
'UTF-8': 'UTF-8',
|
||||
'GB2312': 'GB2312',
|
||||
'UTF-8-BOM': 'UTF-8-BOM',
|
||||
'GBK': 'GBK',
|
||||
'Big-5': 'Big-5',
|
||||
'GB18030': 'GB18030',
|
||||
'Unicode': 'Unicode'
|
||||
}
|
||||
|
||||
// 小板文件名选项
|
||||
export const smallPlateOptionsMap = {
|
||||
板宽: '{0}',
|
||||
板长: '{1}',
|
||||
颜色: '{2}',
|
||||
材质: '{3}',
|
||||
大板号: '{4}',
|
||||
工位号: '{5}',
|
||||
板厚: '{6}',
|
||||
开料顺序: '{7}',
|
||||
批次识别: '{8}',
|
||||
小板编号: '{9}',
|
||||
全局大板号: '{10}',
|
||||
品牌: '{11}',
|
||||
}
|
||||
|
||||
// zip压缩包文件名选项
|
||||
export const zipFileOptionsMap = {
|
||||
'板宽': '{0}',
|
||||
'板长': '{1}',
|
||||
'颜色': '{2}',
|
||||
'材质': '{3}',
|
||||
'大板号': '{4}',
|
||||
'工位号': '{5}',
|
||||
'板厚': '{6}',
|
||||
'开料顺序': '{7}',
|
||||
'批次识别': '{8}',
|
||||
'小板编号': '{9}',
|
||||
'全局大板号': '{10}',
|
||||
'品牌': '11',
|
||||
}
|
||||
|
||||
/** 枚举 大板边角位置 */
|
||||
export enum BoardPosition {
|
||||
/** 左上角 */
|
||||
// LEFT_TOP = 0,
|
||||
// /** 左下角 */
|
||||
// LEFT_BOTTOM = 1,
|
||||
// /** 右下角 */
|
||||
// RIGHT_BOTTOM = 2,
|
||||
// /** 右上角 */
|
||||
// RIGHT_TOP = 3,
|
||||
/** 左上角 */
|
||||
LEFT_TOP = 3,
|
||||
/** 左下角 */
|
||||
LEFT_BOTTOM = 0,
|
||||
/** 右下角 */
|
||||
RIGHT_BOTTOM = 1,
|
||||
/** 右上角 */
|
||||
RIGHT_TOP = 2,
|
||||
/**
|
||||
* 左下角 = 0,
|
||||
右下角 = 1,
|
||||
右上角 = 2,
|
||||
左上角 = 3
|
||||
*/
|
||||
}
|
||||
|
||||
/** 排版样式 */
|
||||
export enum PlaceStyle {
|
||||
/** 正面 */
|
||||
FRONT = 0,
|
||||
/** 正面右转 */
|
||||
FRONT_TURN_RIGHT = 1,
|
||||
/** 正面后转 */
|
||||
FRONT_TURN_BACK = 2,
|
||||
/** 正面左转 */
|
||||
FRONT_TURN_LEFT = 3,
|
||||
/** 反面 */
|
||||
BACK = 4,
|
||||
/** 反面右转 */
|
||||
BACK_TURN_RIGHT = 5,
|
||||
/** 反面后转 */
|
||||
BACK_TURN_BACK = 6,
|
||||
/** 反面左转 */
|
||||
BACK_TURN_LEFT = 7,
|
||||
}
|
||||
|
||||
/** 小板边的位置类型 */
|
||||
export enum EdgeType
|
||||
{
|
||||
/** 下=0 */
|
||||
BOTTOM = 0,
|
||||
/** 右=1 */
|
||||
RIGHT = 1,
|
||||
/** 上=2 */
|
||||
TOP = 2,
|
||||
/** 左=3 */
|
||||
LEFT = 3,
|
||||
}
|
112
samples/demoKnives.ts
Normal file
112
samples/demoKnives.ts
Normal file
@ -0,0 +1,112 @@
|
||||
import { _knifeType } from "./confClass"
|
||||
|
||||
/** demo 刀具数据 */
|
||||
export const knifeData :_knifeType= {
|
||||
"isEnabled": true,
|
||||
"axleId": 2,
|
||||
"knifeId": 2,
|
||||
"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",
|
||||
}
|
||||
export const knifeData1:_knifeType = {
|
||||
"isEnabled": true,
|
||||
"axleId": 2,
|
||||
"knifeId": 2,
|
||||
"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",
|
||||
}
|
||||
export const knifeData2:_knifeType = {
|
||||
"isEnabled": true,
|
||||
"axleId": 2,
|
||||
"knifeId": 2,
|
||||
"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",
|
||||
}
|
124
samples/demoParser.ts
Normal file
124
samples/demoParser.ts
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
import { ConfigBase } from "../src/base";
|
||||
import { ParserBase } from "../src/parsers";
|
||||
import { _knifeType, CodeParams } from "./confClass";
|
||||
import { knifeData, knifeData1, knifeData2 } from "./demoKnives";
|
||||
import { GCodeAction } from "./gcodes";
|
||||
export class DemoParser extends ParserBase {
|
||||
usedKnife?:_knifeType
|
||||
knifeList:_knifeType[] = [
|
||||
knifeData,
|
||||
knifeData1,
|
||||
knifeData2
|
||||
]
|
||||
constructor(config?: Record<string, ConfigBase>) {
|
||||
super();
|
||||
// if(config){
|
||||
// if(config['knives']){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
const gcodeActions = new GCodeAction();
|
||||
this.codeManager['FSTART'] = {
|
||||
name: 'FileStart',
|
||||
// type:'Global',
|
||||
// paramType:'array',
|
||||
exec:(params) =>{
|
||||
return `G54 G90\nM03\n`
|
||||
}
|
||||
};
|
||||
this.codeManager['FEND'] = {
|
||||
name: 'FileEnd',
|
||||
exec:(params) =>{
|
||||
return `M30\n`;
|
||||
}
|
||||
}
|
||||
this.codeManager['G0'] = {
|
||||
name: 'G0',
|
||||
paramType: 'kv:number',
|
||||
exec:(params: CodeParams) => {
|
||||
return gcodeActions.G0(params) + '\n';
|
||||
}
|
||||
}
|
||||
this.codeManager['G2'] = {
|
||||
name: 'G2',
|
||||
paramType: 'kv:number',
|
||||
exec:(params: CodeParams)=> {
|
||||
return gcodeActions.G2(params) + '\n';
|
||||
}
|
||||
}
|
||||
this.codeManager['G3'] = {
|
||||
name: 'G3',
|
||||
paramType: 'kv:number',
|
||||
exec:(params: CodeParams)=> {
|
||||
return gcodeActions.G3(params) + '\n';
|
||||
}
|
||||
}
|
||||
this.codeManager['TD'] = {
|
||||
name: '',
|
||||
exec:(diameter:number)=> {
|
||||
let code = ''
|
||||
let _knife: any
|
||||
|
||||
if (diameter) {
|
||||
_knife = this.knifeList?.find(e => e.diameter == diameter)
|
||||
}
|
||||
|
||||
|
||||
if (_knife != undefined) {
|
||||
code += this.checkChangeKnife(_knife)
|
||||
this.usedKnife = _knife
|
||||
// code += _knife.axisStartCode
|
||||
code += _knife.knifeStartCode
|
||||
}
|
||||
return code
|
||||
}
|
||||
}
|
||||
this.codeManager['TN'] = {
|
||||
name: 'TN',
|
||||
exec:(knifeName:string) =>{ /**根据刀名称找刀 换刀 */
|
||||
let code = ''
|
||||
let _knife: any = null
|
||||
if (knifeName) {
|
||||
_knife = this.knifeList?.find(e => e.knifeName == knifeName)
|
||||
}
|
||||
|
||||
if (_knife != undefined) {
|
||||
code += this.checkChangeKnife(_knife)
|
||||
this.usedKnife = _knife
|
||||
// code += _knife.axisStartCode
|
||||
code += _knife.knifeStartCode
|
||||
}
|
||||
return code
|
||||
}
|
||||
}
|
||||
this.codeManager['TE'] = {
|
||||
name:'TE',
|
||||
exec:()=>{
|
||||
if(!this.usedKnife) return '';
|
||||
return this.usedKnife.knifeStopCode+'\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 内部功能逻辑 换刀时判断是否需要 上一把刀的停止代码 */
|
||||
private checkChangeKnife(knife: _knifeType) {
|
||||
let code = '';
|
||||
/** true 需要 输出停刀代码 false 不需要 */
|
||||
let flag = false
|
||||
// 必须要有刀
|
||||
if (this.usedKnife) {
|
||||
let keys = Object.keys(knife)
|
||||
for (const key of keys) {
|
||||
if (knife[key] != this.usedKnife[key]) {
|
||||
flag = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
code += this.exec('TE',[]);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
528
samples/gcodes.ts
Normal file
528
samples/gcodes.ts
Normal file
@ -0,0 +1,528 @@
|
||||
import { CodeParams } from "./confClass"
|
||||
|
||||
function checkVal(val) {
|
||||
let r = true
|
||||
if ((val == undefined || val == '')) {
|
||||
r = false
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
/**G代码指令
|
||||
* 目前 只需要做 G0 - G3
|
||||
*/
|
||||
export enum GCode {
|
||||
/**快速定位 空程移动 范例:G00 X100 Y50(刀具快速移动至X100、Y50位置) */
|
||||
G0 = 'G0',
|
||||
/**快速定位 空程移动 范例:G00 X100 Y50(刀具快速移动至X100、Y50位置)*/
|
||||
G00 = 'G00',
|
||||
/**直线 直线插补 范例:G01 X200 Y300 F150(刀具以150mm/min的进给速度直线移动至X200、Y300)*/
|
||||
G1 = 'G1',
|
||||
/**直线 范例:G01 X200 Y300 F150(刀具以150mm/min的进给速度直线移动至X200、Y300)*/
|
||||
G01 = 'G01',
|
||||
/** 顺时针 范例:G17 G02 X150 Y50 I50 J0 F100(在XY平面,以半径50mm顺时针圆弧插补至X150、Y50)*/
|
||||
G2 = 'G2',
|
||||
/** 顺时针 范例:G17 G02 X150 Y50 I50 J0 F100(在XY平面,以半径50mm顺时针圆弧插补至X150、Y50)*/
|
||||
G02 = 'G02',
|
||||
/** 逆时针 范例:G17 G03 X150 Y50 I50 J0 F100(在XY平面,以半径50mm逆时针圆弧插补至X150、Y50)*/
|
||||
G3 = 'G3',
|
||||
/** 逆时针 范例:G17 G03 X150 Y50 I50 J0 F100(在XY平面,以半径50mm逆时针圆弧插补至X150、Y50)*/
|
||||
G03 = 'G03',
|
||||
/**暂停 范例:G04 X2(暂停2秒)*/
|
||||
G4 = 'G4',
|
||||
/**暂停 范例:G04 X2(暂停2秒)*/
|
||||
G04 = 'G04',
|
||||
/** 通过中间点圆弧插补
|
||||
* 1. 通过中间点圆弧插补
|
||||
* 示例:G05 X60 Z50 IX50 IZ60 F120 刀具从当前位置出发,经过中间点 (50, 60),最终到达终点 (60, 50),形成圆弧轨迹。
|
||||
* 2. 高精轨迹控制(HPCC)模式
|
||||
* 功能:G05 可启动高精轨迹控制模式(HPCC),通过曲线拟合和参数优化,实现高精度、高速度的轨迹加工,适用于复杂曲面或高精度零件。
|
||||
* 指令格式:
|
||||
* 启动:G05 P10000(P值设为10000)
|
||||
* 关闭:G05 P0(P值设为0)
|
||||
* 3、注意事项:
|
||||
* 轴类型限制:建议线性轴参与HPCC模式,旋转轴需谨慎设置。
|
||||
与其他功能冲突:
|
||||
在HPCC模式下,G61(准确停止检查)、G63(攻螺纹)等功能可能失效,需退出HPCC模式后恢复。
|
||||
启用 RTCP(旋转刀具中心点)或 STCP 模式时,禁止同时启用HPCC功能。
|
||||
不支持的功能:
|
||||
不支持单节停止(C40/M00)、反向手轮模拟、图形模拟等。
|
||||
剩余距离显示可能不准确,因显示的是离曲线终点的距离,而非单节终点。
|
||||
* */
|
||||
G5 = 'G5',
|
||||
/** 通过中间点圆弧插补 */
|
||||
G05 = 'G05',
|
||||
/** 抛物线插补 */
|
||||
G6 = 'G6',
|
||||
/** 抛物线插补 */
|
||||
G06 = 'G06',
|
||||
/** z样条曲线插补 */
|
||||
G7 = 'G7',
|
||||
/** z样条曲线插补 */
|
||||
G07 = 'G07',
|
||||
/** 进给加速 */
|
||||
G8 = 'G8',
|
||||
/** 进给加速 */
|
||||
G08 = 'G08',
|
||||
/** 进给减速 */
|
||||
G9 = 'G9',
|
||||
/** 进给减速 */
|
||||
G09 = 'G09',
|
||||
/** 参数写入方式有效 */
|
||||
G10 = 'G10',
|
||||
/** 参数写入方式取消 */
|
||||
G11 = 'G11',
|
||||
/** 极坐标变成 */
|
||||
G16 = 'G16',
|
||||
/** XY平面选择 */
|
||||
G17 = 'G17',
|
||||
/** XZ平面选择 */
|
||||
G18 = 'G18',
|
||||
/** YZ平面选择 */
|
||||
G19 = 'G19',
|
||||
/** 英制输入 */
|
||||
G20 = 'G20',
|
||||
/** 公制输入 */
|
||||
G21 = 'G21',
|
||||
/** 半径尺寸编程方式 */
|
||||
G22 = 'G22',
|
||||
/** 系统操作界面上使用 */
|
||||
G220 = 'G220',
|
||||
/** 直径尺寸编程方式 */
|
||||
G23 = 'G23',
|
||||
/** 系统操作界面上使用 */
|
||||
G230 = 'G230',
|
||||
/** 子程序结束 */
|
||||
G24 = 'G24',
|
||||
/** 跳转加工 */
|
||||
G25 = 'G25',
|
||||
/** 循环加工 */
|
||||
G26 = 'G26',
|
||||
/** 参考点返回 */
|
||||
G28 = 'G28',
|
||||
/** 倍率注销 */
|
||||
G30 = 'G30',
|
||||
/** 倍率定义 */
|
||||
G31 = 'G31',
|
||||
/** 等螺距螺纹切削,英制 */
|
||||
G32 = 'G32',
|
||||
/** 等螺距螺纹切削,公制 */
|
||||
G33 = 'G33',
|
||||
/** 增螺距螺纹切削 */
|
||||
G34 = 'G34',
|
||||
/** 减螺距螺纹切削 */
|
||||
G35 = 'G35',
|
||||
//** 刀具半径补正取消 */
|
||||
G40 = 'G40',
|
||||
//** 刀具半径补正 左*/
|
||||
G41 = 'G41',
|
||||
//** 刀具半径补正 右*/
|
||||
G42 = 'G42',
|
||||
//** 刀具长度补正+ */
|
||||
G43 = 'G43',
|
||||
//** 刀具长度补正- */
|
||||
G44 = 'G44',
|
||||
//** 道具偏置+/+ */
|
||||
G45 = 'G45',
|
||||
//** 道具偏置+/- */
|
||||
G46 = 'G46',
|
||||
//** 道具偏置-/- */
|
||||
G47 = 'G47',
|
||||
//** 道具偏置-/+ */
|
||||
G48 = 'G48',
|
||||
//** 刀具长度 补正取消 */
|
||||
G49 = 'G49',
|
||||
//** 局部坐标系设定 */
|
||||
G52 = 'G52',
|
||||
//** 机床坐标系选择 */
|
||||
G53 = 'G53',
|
||||
//** 工件坐标系选择1 */
|
||||
G54 = 'G54',
|
||||
//** 工件坐标系选择2 */
|
||||
G55 = 'G55',
|
||||
//** 工件坐标系选择3 */
|
||||
G56 = 'G56',
|
||||
//** 工件坐标系选择4 */
|
||||
G57 = 'G57',
|
||||
//** 工件坐标系选择5 */
|
||||
G58 = 'G58',
|
||||
//** 工件坐标系选择6 */
|
||||
G59 = 'G59',
|
||||
//** 坐标系旋转有效 */
|
||||
G68 = 'G68',
|
||||
//** 坐标系旋转取消 */
|
||||
G69 = 'G69',
|
||||
/** 高速深孔钻 */
|
||||
G73 = 'G73',
|
||||
/** 精搪孔 */
|
||||
G76 = 'G76',
|
||||
/** 固定循环取消/取消循环指令 */
|
||||
G80 = 'G80',
|
||||
/**程序停止 */
|
||||
M00 = 'M00',
|
||||
/**选择性停止 */
|
||||
M01 = 'M01',
|
||||
/** 程序结束 */
|
||||
M02 = 'M02',
|
||||
/**主轴正转 */
|
||||
M03 = 'M03',
|
||||
/**主轴反转 */
|
||||
M04 = 'M04',
|
||||
/**主轴停止 */
|
||||
M05 = 'M05',
|
||||
/**自动换刀 */
|
||||
M06 = 'M06',
|
||||
}
|
||||
|
||||
/**G代码基类 */
|
||||
export class GCodeAction {
|
||||
|
||||
/** 空程直线 */
|
||||
G0(params: CodeParams) {
|
||||
const { x, y, z, f, xKey, yKey, zKey, fKey, codeKey } = params
|
||||
let val: string = GCode.G0
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 空程直线 */
|
||||
G00(params: CodeParams) {
|
||||
const { x, y, z, f, xKey, yKey, zKey, fKey, codeKey } = params
|
||||
let val: string = GCode.G00
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 直线 */
|
||||
G1(params: CodeParams) {
|
||||
const { x, y, z, f, xKey, yKey, zKey, fKey, codeKey } = params
|
||||
let val: string = GCode.G1
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
|
||||
|
||||
|
||||
return val
|
||||
}
|
||||
/** 直线 */
|
||||
G01(params: CodeParams) {
|
||||
const { x, y, z, f, xKey, yKey, zKey, fKey, codeKey } = params
|
||||
let val: string = GCode.G01
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 顺时针 弧线
|
||||
* @param x x坐标
|
||||
* @param y y坐标
|
||||
* @param z z坐标
|
||||
* @param i 圆弧 对于起点的偏移量 x
|
||||
* @param y 圆弧 对于起点的偏移量 Y
|
||||
* @param z 圆弧 对于起点的偏移量 Y
|
||||
* @param f 速度
|
||||
*/
|
||||
G2(params: CodeParams) {
|
||||
const { x, y, z, i, j, k, r, f, xKey, yKey, zKey, fKey, iKey, jKey, kKey, codeKey } = params
|
||||
let val: string = GCode.G2
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
let _iKey = iKey || 'I'
|
||||
let _jKey = jKey || 'J'
|
||||
let _kKey = kKey || 'K'
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
if (checkVal(r)) {
|
||||
val += ` R${r}`
|
||||
} else {
|
||||
if (checkVal(i)) {
|
||||
val += ` ${_iKey}${i}`
|
||||
}
|
||||
if (checkVal(j)) {
|
||||
val += ` ${_jKey}${j}`
|
||||
}
|
||||
if (checkVal(k)) {
|
||||
val += ` ${_kKey}${k}`
|
||||
}
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 顺时针 弧线
|
||||
* @param x x坐标
|
||||
* @param y y坐标
|
||||
* @param z z坐标
|
||||
* @param i 圆弧 对于起点的偏移量 x
|
||||
* @param y 圆弧 对于起点的偏移量 Y
|
||||
* @param z 圆弧 对于起点的偏移量 Y
|
||||
* @param f 速度
|
||||
*/
|
||||
G02(params: CodeParams) {
|
||||
const { x, y, z, i, j, k, r, f, xKey, yKey, zKey, fKey, iKey, jKey, kKey, codeKey } = params
|
||||
let val: string = GCode.G02
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
let _iKey = iKey || 'I'
|
||||
let _jKey = jKey || 'J'
|
||||
let _kKey = kKey || 'K'
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
|
||||
if (checkVal(r)) {
|
||||
val += ` R${r}`
|
||||
} else {
|
||||
if (checkVal(i)) {
|
||||
val += ` ${_iKey}${i}`
|
||||
}
|
||||
if (checkVal(j)) {
|
||||
val += ` ${_jKey}${j}`
|
||||
}
|
||||
if (checkVal(k)) {
|
||||
val += ` ${_kKey}${k}`
|
||||
}
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 逆时针 弧线
|
||||
* @param x x坐标
|
||||
* @param y y坐标
|
||||
* @param z z坐标
|
||||
* @param i 圆弧 对于起点的偏移量 x
|
||||
* @param y 圆弧 对于起点的偏移量 Y
|
||||
* @param z 圆弧 对于起点的偏移量 Y
|
||||
* @param f 速度
|
||||
*/
|
||||
G3(params: CodeParams) {
|
||||
const { x, y, z, i, j, k, r, f, xKey, yKey, zKey, fKey, iKey, jKey, kKey, codeKey } = params
|
||||
let val: string = GCode.G3
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
let _iKey = iKey || 'I'
|
||||
let _jKey = jKey || 'J'
|
||||
let _kKey = kKey || 'K'
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
|
||||
if (checkVal(r)) {
|
||||
val += ` R${r}`
|
||||
} else {
|
||||
if (checkVal(i)) {
|
||||
val += ` ${_iKey}${i}`
|
||||
}
|
||||
if (checkVal(j)) {
|
||||
val += ` ${_jKey}${j}`
|
||||
}
|
||||
if (checkVal(k)) {
|
||||
val += ` ${_kKey}${k}`
|
||||
}
|
||||
}
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 逆时针 弧线
|
||||
* @param x x坐标
|
||||
* @param y y坐标
|
||||
* @param z z坐标
|
||||
* @param i 圆弧 对于起点的偏移量 x
|
||||
* @param y 圆弧 对于起点的偏移量 Y
|
||||
* @param z 圆弧 对于起点的偏移量 Y
|
||||
* @param f 速度
|
||||
*/
|
||||
G03(params: CodeParams) {
|
||||
const { x, y, z, i, j, k, r, f, xKey, yKey, zKey, fKey, iKey, jKey, kKey, codeKey } = params
|
||||
let val: string = GCode.G03
|
||||
if (typeof (codeKey) == 'string' && codeKey != '') {
|
||||
val = codeKey
|
||||
}
|
||||
let _xkey = xKey || 'X'
|
||||
let _yKey = yKey || 'Y'
|
||||
let _zKey = zKey || 'Z'
|
||||
let _fKey = fKey || 'F'
|
||||
let _iKey = iKey || 'I'
|
||||
let _jKey = jKey || 'J'
|
||||
let _kKey = kKey || 'K'
|
||||
|
||||
if (checkVal(x)) {
|
||||
val += ` ${_xkey}${x}`
|
||||
}
|
||||
if (checkVal(y)) {
|
||||
val += ` ${_yKey}${y}`
|
||||
}
|
||||
if (checkVal(z)) {
|
||||
val += ` ${_zKey}${z}`
|
||||
}
|
||||
|
||||
if (checkVal(r)) {
|
||||
val += ` R${r}`
|
||||
} else {
|
||||
if (checkVal(i)) {
|
||||
val += ` ${_iKey}${i}`
|
||||
}
|
||||
if (checkVal(j)) {
|
||||
val += ` ${_jKey}${j}`
|
||||
}
|
||||
if (checkVal(k)) {
|
||||
val += ` ${_kKey}${k}`
|
||||
}
|
||||
}
|
||||
|
||||
if (checkVal(f)) {
|
||||
val += ` ${_fKey}${f}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/** 主轴正转
|
||||
*
|
||||
* @param s 转速
|
||||
*/
|
||||
M03(s: any) {
|
||||
let val: string = GCode.M03
|
||||
if (checkVal(s)) {
|
||||
val += ` S${s}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
/**主轴反向转
|
||||
* @param s 转速
|
||||
*/
|
||||
M04(s: any) {
|
||||
let val: string = GCode.M04
|
||||
if (checkVal(s)) {
|
||||
val += ` S${s}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
/**主轴停止 */
|
||||
M05() {
|
||||
let val: string = GCode.M05
|
||||
|
||||
return val
|
||||
}
|
||||
/**换刀指令 */
|
||||
M06(t: String) {
|
||||
let val: string = GCode.M06
|
||||
if (checkVal(t)) {
|
||||
val += ` T${t}`
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
}
|
15
src/base.ts
Normal file
15
src/base.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export class ConfigBase {
|
||||
name: string = '';
|
||||
version:string = '1.0.0';
|
||||
enable:boolean = true;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface FileOptions {
|
||||
encode?: string;
|
||||
addBOM?: boolean;
|
||||
}
|
||||
export interface FileInfo extends FileOptions {
|
||||
name: string,
|
||||
content: string | Blob | Uint8Array,
|
||||
}
|
50
src/parsers.ts
Normal file
50
src/parsers.ts
Normal file
@ -0,0 +1,50 @@
|
||||
export type ParserCodeManager = Record<string,
|
||||
{ name: string, exec: (...params: any[]) => string, type?: string, paramType?: 'array' | 'kv:number' }>;
|
||||
|
||||
export abstract class ParserBase {
|
||||
protected codeManager: ParserCodeManager = {};
|
||||
/**
|
||||
* 代码调用转换命令
|
||||
* @param codeKey
|
||||
* @param params
|
||||
* @returns
|
||||
*/
|
||||
exec(codeKey:string,params:unknown[]){
|
||||
const code = this.codeManager[codeKey];
|
||||
if (code) {
|
||||
return code.exec(...params);
|
||||
}
|
||||
throw Error('未注册命令'+ codeKey);
|
||||
}
|
||||
/**
|
||||
* 测试文本输入
|
||||
* @param text
|
||||
* @returns 返回结果
|
||||
*/
|
||||
execTest(text: string) {
|
||||
let result: string = '';
|
||||
for (const line of text.split('\n')) {
|
||||
if(line.trim().length==0) continue;
|
||||
const columns = line.split(' ');
|
||||
const codeKey = columns[0].toUpperCase();
|
||||
const code = this.codeManager[codeKey];
|
||||
if (code) {
|
||||
if (code.paramType == "kv:number") {
|
||||
const dic: Record<string, number> = {};
|
||||
for (const i of columns.slice(1)) {
|
||||
const match = i.match(/([a-zA-Z]+)(\d+)/);
|
||||
if (match) {
|
||||
dic[match[1].toLowerCase()] = Number(match[2]);
|
||||
}
|
||||
}
|
||||
result += code.exec(dic);
|
||||
} else {
|
||||
result += code.exec(...columns.slice(1));
|
||||
}
|
||||
} else {
|
||||
console.log(codeKey + '不支持')
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
7
src/processors.ts
Normal file
7
src/processors.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export abstract class ProcessorBase {
|
||||
public readonly name: string = '';
|
||||
public readonly version: string = '1.0.0';
|
||||
public abstract exec(...args: any[]): any
|
||||
}
|
||||
|
||||
|
16
tests/paser.test.ts
Normal file
16
tests/paser.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { test } from '@jest/globals'
|
||||
import { DemoParser } from '../samples/demoParser';
|
||||
test('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);
|
||||
})
|
26
tsconfig.json
Normal file
26
tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"include": ["src"],
|
||||
"exclude": ["samples","tests"],
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
|
||||
/* Emit */
|
||||
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user