dsh-cad-studio 0.25.0 → 0.26.1

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 CHANGED
@@ -24,6 +24,7 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
24
24
  | 模型清单 | `cad_studio_scene`(`action: list / delete / rename`)——面板里那条列表就是它;探查脚本留下的卡片可以直接删 |
25
25
  | 模型改名 / 复制 | `cad_studio_doc {action:"rename", name, to}` 与 `{action:"duplicate", name, to}`:改名会同步列表里的标题与 `docKey`,复制会得到一条独立的新场景(副本不继承运行历史与撤销栈);两者都可 `cad_studio_undo` 回退 |
26
26
  | 几何自检 | `cad_studio_check {source}` 在导出/打印前问一次:是否有效实体、外壳是否闭合、每个实体体积多少,返回中文问题清单(零体积 / 外壳未闭合 / 几何无效 / 没有实体) |
27
+ | 拔模挤出 | `{kind:"extrude", sketch:"S1", h:20, draft:3}` 按 3° 拔模:截面按 `h*tan(3°)` 偏移后 loft 成体,正角度内收、负角度外放 |
27
28
  | 展开图 | `cad_studio_unfold {source, target:"…/net.dxf"}` 把板类零件按共享边摊平成下料图(面片等距铺开,面积与模型一致;孔各自成环;圆柱/圆角等曲面报 `curvedSkipped` 而不是瞎编),可写 DXF 或 SVG |
28
29
  | 打印网格 | `cad_studio_mesh {source, target:"…/x.stl"}` 三角化 + 去重合并点/面、修形变、统一法向,可选 `fillHoles`、`targetSize`(减面);回报修复前后的 facets/points,避免「导出成功但网格是碎的」 |
29
30
  | 旋转体与凹槽 | `revolve` 的 `axis` 取草图平面内的轴(`"Y"` 或 `[0,1,0]`)才是实体;垂直轴(XY 草图的 Z)只会扫出零厚度圆环,插件会直接报错。凹槽=`{kind:"cut", with:{kind:"revolve", …}}`,不需要单独 op |
package/client.js CHANGED
@@ -1097,6 +1097,21 @@ window.__ModuleLoader__.load({
1097
1097
  // better-sidebar matches on the extension WITHOUT the dot (see its builtin
1098
1098
  // viewers: ['md','markdown']), so a dot-prefixed list would never match.
1099
1099
  /** mm³ → a unit a human reads without counting zeros (1 L = 1e6 mm³). */
1100
+ // Ctrl+Z belongs to the panel whenever the focus is not in a text field.
1101
+ // Checking the tag alone is wrong: a range slider (opacity) is an INPUT too,
1102
+ // and while it keeps focus after a drag every undo press was swallowed until
1103
+ // the popover closed. Only elements that actually edit text keep the browser's
1104
+ // own undo.
1105
+ const TEXT_INPUT_TYPES = new Set(['', 'text', 'search', 'url', 'tel', 'email', 'password', 'number', 'date', 'time', 'datetime-local', 'month', 'week'])
1106
+ function isTextEntry(el) {
1107
+ if (!el || !el.tagName) return false
1108
+ const tag = String(el.tagName).toLowerCase()
1109
+ if (tag === 'textarea') return true
1110
+ if (el.isContentEditable) return true
1111
+ if (tag !== 'input') return false
1112
+ return TEXT_INPUT_TYPES.has(String(el.type || 'text').toLowerCase())
1113
+ }
1114
+
1100
1115
  function formatVolume(mm3) {
1101
1116
  const v = Number(mm3) || 0
1102
1117
  if (v >= 1e6) return `${(v / 1e6).toFixed(2)} L`
@@ -1685,8 +1700,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1685
1700
  if (!(event.ctrlKey || event.metaKey)) return
1686
1701
  if (key !== 'z' && key !== 'y') return
1687
1702
  const target = event.target
1688
- const tag = target && target.tagName ? target.tagName.toLowerCase() : ''
1689
- if (tag === 'input' || tag === 'textarea' || tag === 'select' || (target && target.isContentEditable)) return
1703
+ if (isTextEntry(target)) return
1690
1704
  if (panelRef.current === 'features') return
1691
1705
  const host = panelRootRef.current
1692
1706
  const focused = document.activeElement
@@ -2073,8 +2087,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2073
2087
  : []
2074
2088
  useEffect(() => {
2075
2089
  const onKey = (event) => {
2076
- const tag = (event.target && event.target.tagName) || ''
2077
- if (/^(INPUT|TEXTAREA|SELECT)$/.test(tag)) return
2090
+ if (isTextEntry(event.target)) return
2078
2091
  if (!(event.metaKey || event.ctrlKey) || !featureModel) return
2079
2092
  const key = String(event.key || '').toLowerCase()
2080
2093
  if (key === 'z') {
package/index.js CHANGED
@@ -1722,8 +1722,32 @@ def _prim(op, _cur=None):
1722
1722
  return Part.makeTorus(float(op["r1"]), float(op["r2"]), at, _dir(op.get("axis")))
1723
1723
  if k == "extrude":
1724
1724
  if op.get("sketch"):
1725
- face = Part.Face(_sketch(str(op["sketch"])))
1726
- return face.extrude(_dir(op.get("dir"), (0.0, 0.0, float(op.get("h") or 10.0))))
1725
+ wire = _sketch(str(op["sketch"]))
1726
+ vec = _dir(op.get("dir"), (0.0, 0.0, float(op.get("h") or 10.0)))
1727
+ draft = float(op.get("draft", 0.0) or 0.0)
1728
+ if abs(draft) < 1e-9:
1729
+ return Part.Face(wire).extrude(vec)
1730
+ # Draft: the section shrinks toward the far end, so the wall leans by
1731
+ # the requested angle instead of going straight up. Offsetting the
1732
+ # section in its own plane and lofting keeps the sides planar; a
1733
+ # plain extrude plus a taper would need a real BRepOffsetAPI call
1734
+ # that FreeCAD 0.20 does not expose to Python.
1735
+ if abs(draft) >= 89.0:
1736
+ raise RuntimeError("draft 需要 -89 到 89 度之间的角度")
1737
+ drop = abs(vec.Length) * math.tan(math.radians(abs(draft)))
1738
+ sign = -1.0 if draft > 0 else 1.0
1739
+ try:
1740
+ ring = wire.makeOffset2D(sign * drop, 0, False, False)
1741
+ except Exception:
1742
+ raise RuntimeError("draft 无法偏移这个截面:向内缩 %.3f mm 后没有面积了(减小角度或加大截面)" % drop)
1743
+ if ring.ShapeType != "Wire":
1744
+ raise RuntimeError("draft 无法偏移这个截面(可能是自交或太窄:需要向内缩 %.3f mm)" % drop)
1745
+ ring = ring.copy()
1746
+ ring.translate(vec)
1747
+ solid = Part.makeLoft([wire, ring], True)
1748
+ if abs(solid.Volume) < 1e-9:
1749
+ raise RuntimeError("draft 得到零体积:截面缩 %.3f mm 后已经没有面积了,减小角度" % drop)
1750
+ return solid
1727
1751
  base = float(op.get("base", 0.0))
1728
1752
  h = float(op.get("h", 0.0))
1729
1753
  # Points may be 2D (z = base) or 3D; dir replaces the +Z extrusion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.25.0",
3
+ "version": "0.26.1",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {