From 3966b862566a659d3c282a4b6037de44ba6573e8 Mon Sep 17 00:00:00 2001 From: "2817212736@qq.com" <2817212736@qq.com> Date: Thu, 14 Aug 2025 10:14:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96NCWriter=20G=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8F=82=E6=95=B0=E5=AE=9A=E4=B9=89=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nc/ncWriter.ts | 114 +++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/src/nc/ncWriter.ts b/src/nc/ncWriter.ts index 420f7aa..cfbf240 100644 --- a/src/nc/ncWriter.ts +++ b/src/nc/ncWriter.ts @@ -1,5 +1,48 @@ import { Knife } from "../models/knife"; +/** + * NC代码构建器接口,实现该接口来定义一个处理器用的NC代码构建器 + * @author CZY + * @since 0.3.0 + * @version 0.1.1 + */ +export interface INcWriter { + get ncActions(): NcAction[]; + + /** 添加G代码 */ + gCode(code: TCode, params: Partial): void; + + /** 基于刀具实体执行换刀操作 */ + changeKnife(knife: Knife): void; + + /** 添加一行注释 */ + comment(content: string): void; + + /** + * 记录一次NC加工操作 + * + * NC加工操作指的是一次完整的加工过程,例如一次排钻,一次造型切割,或是一次小板加工 + * + * 一次NC加工操作可能包含多行的GCode + * + * 该方法旨在为NC文件提供记录加工步骤的能力 + * + * 返回本次NC操作的ID,此ID由内部生成 + * @param type NC操作类型 + * @returns 本次NC操作的ID + */ + recordAction(type: NcActionType): string; + + /** 直接在末尾追加任意字符串 */ + append(str: string): void; + + /** 直接在末尾追加一行任意字符串 */ + appendLine(str: string): void; + + /** 返回当前构建的NC代码 */ + toString(): string; +} + /** 基础G代码 */ export const GCode = { /** @@ -55,7 +98,19 @@ export const GCode = { G3: 'G3', } as const; -/** */ +/** 自定义数控代码,由内部解析并实现,不直接输出给设备 */ +export const CCode = { + /** + * 自动圆弧插补 + * @param X X 坐标 + * @param Y Y 坐标 + * @param Z Z 坐标 + * @param B Bulge圆弧凸度,表示圆弧所包含角度的四分之一的正切值。当B=0时,圆弧为直线,当B>0时,圆弧为顺时针圆弧,当B<0时,圆弧为逆时针圆弧 (所谓“顺时针”和“逆时针”是指从起始点到结束点的绘制角度) + */ + CArc: 'CArc', +}; + +/** NC GCode 参数结构 */ export class GCodeParams { /** X坐标值 mm */ x: number = 0; @@ -73,6 +128,18 @@ export class GCodeParams { f: number = 0; }; +/** 自定义数控代码参数结构 */ +export class CCodeParams { + /** X坐标值 mm */ + x: number = 0; + /** Y坐标值 mm */ + y: number = 0; + /** Z坐标值 mm */ + z: number = 0; + /** 使用自动圆弧(CArc)命令时,定义圆弧凸度 */ + b: number = 0; +} + /** 单次NC加工行为 */ export interface NcAction { readonly id: string; @@ -80,47 +147,4 @@ export interface NcAction { readonly lineIndex: number; } -export type NcActionType = string; - -/** - * NC代码构建器接口,实现该接口来定义一个处理器用的NC代码构建器 - * @author CZY - * @since 0.3.0 - * @version 0.1.0 - */ -export interface INcWriter { - get ncActions(): NcAction[]; - - /** 添加G代码 */ - gCode(code: keyof typeof GCode, params: Partial & { bul: number; }>): void; - - /** 基于刀具实体执行换刀操作 */ - changeKnife(knife: Knife): void; - - /** 添加一行注释 */ - comment(content: string): void; - - /** - * 记录一次NC加工操作 - * - * NC加工操作指的是一次完整的加工过程,例如一次排钻,一次造型切割,或是一次小板加工 - * - * 一次NC加工操作可能包含多行的GCode - * - * 该方法旨在为NC文件提供记录加工步骤的能力 - * - * 返回本次NC操作的ID,此ID由内部生成 - * @param type NC操作类型 - * @returns 本次NC操作的ID - */ - recordAction(type: NcActionType): string; - - /** 直接在末尾追加任意字符串 */ - append(str: string): void; - - /** 直接在末尾追加一行任意字符串 */ - appendLine(str: string): void; - - /** 返回当前构建的NC代码 */ - toString(): string; -} +export type NcActionType = string; \ No newline at end of file From f1a9a6ba5e3eaa914e6151a6c153cb11ea1c95d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=A2=93=E9=98=B3?= <2817212736@qq.com> Date: Thu, 14 Aug 2025 10:16:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 08ae4a6..84ae79a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cut-abstractions", - "version": "0.3.1", + "version": "0.3.2", "description": "", "files": [ "dist/**/*" From 290bbf2b5e28e280eb5d2d1c17e414a10939bacb Mon Sep 17 00:00:00 2001 From: "2817212736@qq.com" <2817212736@qq.com> Date: Thu, 14 Aug 2025 10:34:08 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96NCWriter=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=BC=E5=BC=8F=E5=92=8C=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/nc/ncWriter.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 84ae79a..10fc008 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cut-abstractions", - "version": "0.3.2", + "version": "0.3.3", "description": "", "files": [ "dist/**/*" diff --git a/src/nc/ncWriter.ts b/src/nc/ncWriter.ts index cfbf240..1bf2e51 100644 --- a/src/nc/ncWriter.ts +++ b/src/nc/ncWriter.ts @@ -4,13 +4,18 @@ import { Knife } from "../models/knife"; * NC代码构建器接口,实现该接口来定义一个处理器用的NC代码构建器 * @author CZY * @since 0.3.0 - * @version 0.1.1 + * @version 0.1.2 */ export interface INcWriter { get ncActions(): NcAction[]; - /** 添加G代码 */ - gCode(code: TCode, params: Partial): void; + /** + * 写入G代码或解析一条自定义代码 + * @example + * gCode('G0', { x: 0, y: 0, z: 0, f: 25000 }); + * gCode('CArc', { x: 0, y: 0, z: 0, b: 1, f: 25000 }); + */ + gCode(code: TCode, params: Partial): void; /** 基于刀具实体执行换刀操作 */ changeKnife(knife: Knife): void; @@ -106,9 +111,13 @@ export const CCode = { * @param Y Y 坐标 * @param Z Z 坐标 * @param B Bulge圆弧凸度,表示圆弧所包含角度的四分之一的正切值。当B=0时,圆弧为直线,当B>0时,圆弧为顺时针圆弧,当B<0时,圆弧为逆时针圆弧 (所谓“顺时针”和“逆时针”是指从起始点到结束点的绘制角度) + * @description 使用此命令时,X, Y, Z作为圆弧的结束点,当前刀具的位置作为起始点。 + * @example + * FROM: CArc X0 Y10 Z0 B1 + * TO: G2 X0 Y10 R5 */ CArc: 'CArc', -}; +} as const; /** NC GCode 参数结构 */ export class GCodeParams { @@ -138,6 +147,8 @@ export class CCodeParams { z: number = 0; /** 使用自动圆弧(CArc)命令时,定义圆弧凸度 */ b: number = 0; + /** 给进速度(Feed Rate) mm/min */ + f: number = 0; } /** 单次NC加工行为 */