dsh-qizhoucnc-cam 1.3.6 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +45 -4
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { defineTool } from '@deepseek-ai/dsh-tools';
2
+ import z from '@deepseek-ai/schemastery';
2
3
  import { spawnSync } from 'node:child_process';
3
4
  import { mkdtempSync, readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, unlinkSync, rmdirSync } from 'node:fs';
4
5
  import { tmpdir, homedir } from 'node:os';
@@ -6,7 +7,16 @@ import { join, dirname, basename, isAbsolute, relative, resolve } from 'node:pat
6
7
  import { fileURLToPath } from 'node:url';
7
8
 
8
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
- const FREECAD_BIN = '/Applications/FreeCAD.app/Contents/Resources/bin/freecadcmd';
10
+ // 默认 FreeCAD 路径(macOS)。其它机器可经插件设置覆盖 freecadBin。
11
+ const FREECAD_BIN_DEFAULT = '/Applications/FreeCAD.app/Contents/Resources/bin/freecadcmd';
12
+ // 常见 FreeCAD 可执行文件位置(按顺序探测)。
13
+ const FREECAD_BIN_CANDIDATES = [
14
+ '/Applications/FreeCAD.app/Contents/Resources/bin/freecadcmd',
15
+ '/usr/bin/freecadcmd',
16
+ '/usr/local/bin/freecadcmd',
17
+ '/opt/freecad/bin/freecadcmd',
18
+ '/snap/bin/freecadcmd',
19
+ ];
10
20
  const CAM_SCRIPT = join(__dirname, 'cam_script.py');
11
21
  const RENDER_SCRIPT = join(__dirname, 'toolpath_render.py');
12
22
  const MODEL_SCRIPT = join(__dirname, 'model_tessellate.py');
@@ -72,6 +82,29 @@ function findPython() {
72
82
  return null;
73
83
  }
74
84
 
85
+ // 解析 FreeCAD 可执行文件路径:优先插件设置 freecadBin,其次默认路径,最后按候选列表探测。
86
+ function resolveFreecadBin(configured) {
87
+ if (typeof configured === 'string' && configured.trim()) {
88
+ if (existsSync(configured.trim())) return configured.trim();
89
+ return null; // 显式配置但不存在 → 报错提示,不用探测结果混淆
90
+ }
91
+ if (existsSync(FREECAD_BIN_DEFAULT)) return FREECAD_BIN_DEFAULT;
92
+ for (const cand of FREECAD_BIN_CANDIDATES) {
93
+ if (existsSync(cand)) return cand;
94
+ }
95
+ return null;
96
+ }
97
+
98
+ // 给出 FreeCAD 缺失时的友好错误(含安装指引)。
99
+ function freecadMissingError(configured) {
100
+ if (typeof configured === 'string' && configured.trim()) {
101
+ return 'FreeCAD 可执行文件不存在:' + configured.trim() +
102
+ '\n请在插件设置里把「FreeCAD 路径」改成正确的 freecadcmd 绝对路径。';
103
+ }
104
+ return '找不到 FreeCAD(freecadcmd)。' +
105
+ '\n请安装 FreeCAD,或在插件设置里填写「FreeCAD 路径」指向 freecadcmd 可执行文件的绝对路径。';
106
+ }
107
+
75
108
  // ---- persistence (survives restart) ----
76
109
  function loadState() {
77
110
  try { return JSON.parse(readFileSync(STATE_FILE, 'utf8')); } catch { return null; }
@@ -222,7 +255,8 @@ function assertModelPath(modelPath) {
222
255
  }
223
256
 
224
257
  function tessellateModel(modelPath, opts = {}) {
225
- const freecadBin = opts.freecadBin ?? FREECAD_BIN;
258
+ const freecadBin = resolveFreecadBin(opts.freecadBin);
259
+ if (!freecadBin) throw new Error(freecadMissingError(opts.freecadBin));
226
260
  const p = assertModelPath(modelPath);
227
261
  const tmp = mkdtempSync(join(tmpdir(), 'dsh-cam-model-'));
228
262
  const outFile = join(tmp, 'model.json');
@@ -382,7 +416,8 @@ function assetSceneOf(asset) {
382
416
 
383
417
  // ---- generate a G-code toolpath from a STEP/BREP/IGES model via FreeCAD CAM ----
384
418
  function generateToolpathFromModel(modelPath, opts = {}) {
385
- const freecadBin = opts.freecadBin ?? FREECAD_BIN;
419
+ const freecadBin = resolveFreecadBin(opts.freecadBin);
420
+ if (!freecadBin) throw new Error(freecadMissingError(opts.freecadBin));
386
421
  const p = resolvePath(modelPath);
387
422
  if (!existsSync(p)) throw new Error('Model file not found: ' + p);
388
423
  // write the NC file next to the model, with the same base name (panda.step -> panda.nc)
@@ -410,8 +445,14 @@ function generateToolpathFromModel(modelPath, opts = {}) {
410
445
  export const name = 'dsh-cam';
411
446
  export const inject = ['tools', 'workspaceChanges'];
412
447
 
448
+ // 插件设置:可覆盖 FreeCAD 可执行文件路径(其它机器 FreeCAD 不在默认位置时用)。
449
+ export const Config = z.object({
450
+ freecadBin: z.string().description('FreeCAD freecadcmd 可执行文件的绝对路径;留空则自动探测。').default(''),
451
+ }).loose();
452
+
413
453
  export function apply(ctx, config = {}) {
414
- const freecadBin = config.freecadBin ?? FREECAD_BIN;
454
+ // 原始配置值;真正解析(含探测与友好报错)在 tessellateModel / generateToolpathFromModel 内按需进行。
455
+ const freecadBin = config.freecadBin;
415
456
 
416
457
  // restore persisted toolpath so the viewer is not empty after a restart
417
458
  latestToolpath = loadState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qizhoucnc-cam",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "CNC program (NC/CNC/G-code) toolpath recognition, 3D toolpath + 3D STEP model viewport (face/edge machining-position annotation), and a large editing view with quote-to-composer, for DeepSeek Harness (DSH). Made by Chengdu Qizhou Machinery Technology Co., Ltd., for research and study only.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,7 +42,8 @@
42
42
  "qrcode.png"
43
43
  ],
44
44
  "peerDependencies": {
45
- "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.3.0"
45
+ "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.3.0",
46
+ "@deepseek-ai/schemastery": ">=3.18.0"
46
47
  },
47
48
  "dsh": {
48
49
  "bundle": {