dsh-cad-studio 0.14.0 → 0.15.0
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.
- package/README.md +2 -0
- package/index.js +85 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
|
|
|
20
20
|
| 其它 | `cad_studio_open`(STEP/STL/BREP/IGES 进来看)、`cad_studio_export`、`cad_studio_measure`、`cad_studio_env` |
|
|
21
21
|
| 模型清单 | `cad_studio_scene`(`action: list / delete / rename`)——面板里那条列表就是它;探查脚本留下的卡片可以直接删 |
|
|
22
22
|
| 模型改名 / 复制 | `cad_studio_doc {action:"rename", name, to}` 与 `{action:"duplicate", name, to}`:改名会同步列表里的标题与 `docKey`,复制会得到一条独立的新场景(副本不继承运行历史与撤销栈);两者都可 `cad_studio_undo` 回退 |
|
|
23
|
+
| 几何自检 | `cad_studio_check {source}` 在导出/打印前问一次:是否有效实体、外壳是否闭合、每个实体体积多少,返回中文问题清单(零体积 / 外壳未闭合 / 几何无效 / 没有实体) |
|
|
24
|
+
| 旋转体与凹槽 | `revolve` 的 `axis` 取草图平面内的轴(`"Y"` 或 `[0,1,0]`)才是实体;垂直轴(XY 草图的 Z)只会扫出零厚度圆环,插件会直接报错。凹槽=`{kind:"cut", with:{kind:"revolve", …}}`,不需要单独 op |
|
|
23
25
|
| 特征 → STEP | `cad_studio_export {model:"名字", target:"…/x.step"}` 或 `cad_studio_doc {action:"show", name, export:"…/x.step"}`;特征列表是源,STEP 是产物,不用自己复刻发射器 |
|
|
24
26
|
| 旧 dsh-cad 文档 | `cad_studio_legacy`(`action: list / show`)只读列出 `/app/.dsh-cad` 的文档、op 数与体数 |
|
|
25
27
|
| 自检/安装 | `cad_studio_setup`:报告 freecadcmd 是否可用、版本、包管理器与可执行命令;`action=install` 直接装 |
|
package/index.js
CHANGED
|
@@ -1212,6 +1212,10 @@ def _v3(x, d=(0.0, 0.0, 0.0)):
|
|
|
1212
1212
|
return Vector(float(x[0]), float(x[1]), float(x[2]))
|
|
1213
1213
|
|
|
1214
1214
|
def _dir(x, d=(0.0, 0.0, 1.0)):
|
|
1215
|
+
# "X"/"Y"/"Z" are accepted everywhere a direction is expected, not just
|
|
1216
|
+
# [x,y,z]: writing axis:'Y' is what a human means when revolving a sketch.
|
|
1217
|
+
if isinstance(x, str) and x.strip().upper() in ("X", "Y", "Z"):
|
|
1218
|
+
x = {"X": (1.0, 0.0, 0.0), "Y": (0.0, 1.0, 0.0), "Z": (0.0, 0.0, 1.0)}[x.strip().upper()]
|
|
1215
1219
|
v = _v3(x, d)
|
|
1216
1220
|
return v if v.Length > 1e-9 else _v3(d, (0.0, 0.0, 1.0))
|
|
1217
1221
|
|
|
@@ -1377,18 +1381,17 @@ def _prim(op, _cur=None):
|
|
|
1377
1381
|
return body
|
|
1378
1382
|
if k == "revolve":
|
|
1379
1383
|
if op.get("sketch"):
|
|
1384
|
+
# Measured on 0.20.2: a face revolved about an axis that LIES IN its
|
|
1385
|
+
# plane gives a valid solid (ring: area x 2*pi*r_centroid); about an
|
|
1386
|
+
# axis PERPENDICULAR to its plane it gives a zero-thickness annulus
|
|
1387
|
+
# (Volume 0, isValid() still True). So the axis has to be explicit:
|
|
1388
|
+
# guessing it silently would produce 0 mm3 instead of an error.
|
|
1389
|
+
if op.get("axis") is None:
|
|
1390
|
+
raise RuntimeError("草图旋转要显式给 axis:草图平面内的轴(如 'Y' 或 [0,1,0])会扫出实体;垂直于草图平面的轴(XY 草图的 Z)扫出的是零厚度圆环")
|
|
1380
1391
|
face = Part.Face(_sketch(str(op["sketch"])))
|
|
1381
1392
|
rev = face.revolve(_v3(op.get("origin")), _dir(op.get("axis"), (0.0, 0.0, 1.0)), float(op.get("angle", 360.0)))
|
|
1382
|
-
# A revolve of a face yields a shell; a full turn closes it, but only
|
|
1383
|
-
# becomes a solid after we say so. Volume 0 means "still a shell".
|
|
1384
|
-
if abs(rev.Volume) < 1e-9 and rev.Shells:
|
|
1385
|
-
try:
|
|
1386
|
-
rev = Part.makeSolid(rev.Shells[0])
|
|
1387
|
-
except Exception:
|
|
1388
|
-
pass
|
|
1389
1393
|
if abs(rev.Volume) < 1e-9:
|
|
1390
|
-
|
|
1391
|
-
raise RuntimeError("草图旋转得到的是壳体、没有闭合(需要 sewShape 缝合);先用挤出,或把草图轮廓贴住旋转轴")
|
|
1394
|
+
raise RuntimeError("草图旋转得到零体积:旋转轴垂直于草图平面(XY 草图 + Z 轴只会扫出零厚度圆环)。把 axis 换成草图平面内的轴,例如 axis:'Y'")
|
|
1392
1395
|
return rev
|
|
1393
1396
|
ps = [Vector(float(p[0]), 0.0, float(p[1])) for p in op["points"]]
|
|
1394
1397
|
ang = float(op.get("angle", 360.0))
|
|
@@ -2374,6 +2377,79 @@ ${pair ? ` __out["distance"] = round((FreeCAD.Vector(${JSON.stringify(from)})
|
|
|
2374
2377
|
},
|
|
2375
2378
|
})
|
|
2376
2379
|
|
|
2380
|
+
tool({
|
|
2381
|
+
name: 'cad_studio_check',
|
|
2382
|
+
description: 'Check a model before you export or print it: is it a valid solid, is every shell closed, how many solids/shells/faces, volume per solid, and a plain-language list of problems (零体积 / 外壳未闭合 / 几何无效 / 没有实体). Run this instead of trusting a file size.',
|
|
2383
|
+
parameters: {
|
|
2384
|
+
type: 'object',
|
|
2385
|
+
properties: {
|
|
2386
|
+
source: { type: 'string', description: 'Existing model file (STEP/IGES/BREP/STL).' },
|
|
2387
|
+
code: { type: 'string', description: 'FreeCAD Python that binds `scene` or `export_shapes`.' },
|
|
2388
|
+
minVolume: { type: 'number', description: 'Flag solids below this volume in mm3 as suspicious (default 0.001).' },
|
|
2389
|
+
},
|
|
2390
|
+
additionalProperties: false,
|
|
2391
|
+
},
|
|
2392
|
+
output: {
|
|
2393
|
+
schema: { type: 'object', properties: { ok: { type: 'boolean' }, problems: { type: 'array', items: { type: 'string' } } } },
|
|
2394
|
+
render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }],
|
|
2395
|
+
},
|
|
2396
|
+
execute: async ({ source, code, minVolume }) => {
|
|
2397
|
+
if (!source && !code) return { ok: false, error: 'pass either source (a model file) or code (FreeCAD Python)' }
|
|
2398
|
+
const floor = Number.isFinite(minVolume) ? Number(minVolume) : 0.001
|
|
2399
|
+
const src = shapesFrom({ source, code })
|
|
2400
|
+
// Volume 0 with ShapeType "Solid" is a real failure mode on this kernel
|
|
2401
|
+
// (lofting two faces, revolving about an axis perpendicular to the profile),
|
|
2402
|
+
// so a file that opens and has faces can still be unprintable. Say it here.
|
|
2403
|
+
const py = `${PRELUDE}
|
|
2404
|
+
${src}
|
|
2405
|
+
_problems = []
|
|
2406
|
+
_items = []
|
|
2407
|
+
if not _shapes:
|
|
2408
|
+
_problems.append("没有实体:文件里读不出任何 shape")
|
|
2409
|
+
for _i, _s in enumerate(_shapes):
|
|
2410
|
+
_vol = float(_s.Volume or 0.0)
|
|
2411
|
+
_shells = list(_s.Shells)
|
|
2412
|
+
_open = []
|
|
2413
|
+
for _k, _sh in enumerate(_shells):
|
|
2414
|
+
try:
|
|
2415
|
+
if not _sh.isClosed():
|
|
2416
|
+
_open.append(_k)
|
|
2417
|
+
except Exception:
|
|
2418
|
+
pass
|
|
2419
|
+
_item = {
|
|
2420
|
+
"index": _i,
|
|
2421
|
+
"type": str(_s.ShapeType),
|
|
2422
|
+
"volume": round(_vol, 3),
|
|
2423
|
+
"area": round(float(_s.Area or 0.0), 3),
|
|
2424
|
+
"solids": len(_s.Solids),
|
|
2425
|
+
"shells": len(_shells),
|
|
2426
|
+
"faces": len(_s.Faces),
|
|
2427
|
+
"edges": len(_s.Edges),
|
|
2428
|
+
"valid": bool(_s.isValid()),
|
|
2429
|
+
"closed": not _open,
|
|
2430
|
+
}
|
|
2431
|
+
_items.append(_item)
|
|
2432
|
+
_tag = "shape #%d" % _i
|
|
2433
|
+
if abs(_vol) <= ${JSON.stringify(floor)}:
|
|
2434
|
+
_problems.append("%s 体积为零(%.6f mm3):面在,实体不在" % (_tag, _vol))
|
|
2435
|
+
if not _item["valid"]:
|
|
2436
|
+
_problems.append("%s 几何无效(OCC isValid=false),后续布尔/导出可能失败" % _tag)
|
|
2437
|
+
if len(_s.Solids) == 0:
|
|
2438
|
+
_problems.append("%s 没有实体(只有面/壳)" % _tag)
|
|
2439
|
+
if _open:
|
|
2440
|
+
_problems.append("%s 有 %d 个外壳未闭合:不是水密体,打印/布尔会漏" % (_tag, len(_open)))
|
|
2441
|
+
__out = {
|
|
2442
|
+
"ok": len(_problems) == 0,
|
|
2443
|
+
"checked": len(_items),
|
|
2444
|
+
"volume": round(sum(float(x.Volume or 0.0) for x in _shapes), 3),
|
|
2445
|
+
"problems": _problems,
|
|
2446
|
+
"solids": _items,
|
|
2447
|
+
}
|
|
2448
|
+
`
|
|
2449
|
+
return bridge.run(py, { title: 'check', publishHint: false })
|
|
2450
|
+
},
|
|
2451
|
+
})
|
|
2452
|
+
|
|
2377
2453
|
tool({
|
|
2378
2454
|
name: 'cad_studio_section',
|
|
2379
2455
|
description: `Cross-section of a solid: slice it with a plane and report closed loops, area and perimeter; optionally write the outline as SVG (for laser/CNC nesting). Axis is X/Y/Z, at is the plane offset in mm.`,
|