dsh-cad-studio 0.26.1 → 0.27.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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/client.js +209 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -157,13 +157,13 @@ npm 包:<https://www.npmjs.com/package/dsh-cad-studio>(`dsh plugin` / DSH
157
157
  |---|---|---|
158
158
  | 文档 | 特征增删改、移动、抑制、回滚点、变量 | 面板 `Ctrl+Z` / 工具 `cad_studio_features {action:"undo"}` |
159
159
  | 装配 | 关节值、关节增删、爆炸系数 | 工具 `cad_studio_undo` / `cad_studio_redo`(`scope: auto|assembly|doc`) |
160
- | 外观 | 透明度、颜色、显隐、线框、隔离 | 面板 `Ctrl+Z` / 右下角 ↶↷(只活在这个浏览器页签里) |
160
+ | 外观 | 透明度、颜色、显隐、线框、隔离 | 面板 `Ctrl+Z` / 面板右上角 ↶↷(只活在这个浏览器页签里) |
161
161
 
162
162
  `scope:auto` 先看装配栈,空则退回文档栈(文档栈要求给 `model`)。导出写文件、出工程图、删模型属于不可逆动作,不进任何栈。
163
163
 
164
164
  ### 视图撤销
165
165
 
166
- 透明度、颜色、显隐、线框这些**外观改动**也进撤销栈(服务端 `doc.undo` 只管文档结构,管不到它们):同一目标 1.5 s 内的连续拖动合并成一条,切场景清空,最多 40 步。面板「活跃」时(焦点在面板内,或 8 s 内点过面板)按 `Ctrl/Cmd+Z` 撤销、`Shift+Ctrl/Cmd+Z` 或 `Ctrl+Y` 重做;视口右下角还有一对 ↶ / ↷ 按钮,没东西可撤销时是灰的。输入框里的 `Ctrl+Z` 不劫持,「特征」页签里仍归文档撤销。
166
+ 透明度、颜色、显隐、线框这些**外观改动**也进撤销栈(服务端 `doc.undo` 只管文档结构,管不到它们):同一目标 1.5 s 内的连续拖动合并成一条,切场景清空,最多 40 步。面板「活跃」时(焦点在面板内,或 8 s 内点过面板)按 `Ctrl/Cmd+Z` 撤销、`Shift+Ctrl/Cmd+Z` 或 `Ctrl+Y` 重做;面板右上角还有一对 ↶ / ↷ 按钮,没东西可撤销时是灰的。**左侧图标条里的「操作历史」**(表盘箭头图标)把整个栈列成一行一条(`隐藏 缸体_外包络`、`透明度 篮1_U纵10 40%`、`换色 … → #d55e00`),点任意一行直接跳到那一步,已撤销的步骤以灰行显示、再点一次就重做;最上面一行「回到最初的样子」一次性退回所有外观改动。输入框里的 `Ctrl+Z` 不劫持,「特征」页签里仍归文档撤销。
167
167
 
168
168
  ## 开发
169
169
 
package/client.js CHANGED
@@ -61,13 +61,29 @@ window.__ModuleLoader__.load({
61
61
  boxShadow: '6px 0 18px rgba(0,0,0,.16)',
62
62
  },
63
63
  headBtn: { font: 'inherit', fontSize: 11, padding: '2px 7px', borderRadius: 5, border: '1px solid rgba(120,130,145,.45)', background: 'transparent', cursor: 'pointer', flex: 'none', lineHeight: 1.5 },
64
- undoPair: { position: 'absolute', right: 8, bottom: 8, display: 'flex', gap: 4, zIndex: 12 },
65
- undoBtn: (active) => ({
66
- width: 24, height: 24, borderRadius: 6, border: '1px solid rgba(140,150,165,.34)',
64
+ // Undo/redo live at the top-right of the panel header, not floating over
65
+ // the viewport: they act on the whole panel, and a floating pair sat on
66
+ // top of the model exactly where the user wanted to look.
67
+ headActions: { display: 'flex', alignItems: 'center', gap: 2, flex: '0 0 auto', marginLeft: 2 },
68
+ histBtn: (active) => ({
69
+ width: 22, height: 22, borderRadius: 5, border: '1px solid transparent',
67
70
  background: active ? 'rgba(120,130,145,.16)' : 'transparent', color: 'inherit',
68
- opacity: active ? 0.9 : 0.28, cursor: active ? 'pointer' : 'default',
69
- fontSize: 14, padding: 0, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
71
+ opacity: active ? 0.9 : 0.3, cursor: active ? 'pointer' : 'default',
72
+ fontSize: 13, padding: 0, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
73
+ lineHeight: 1,
70
74
  }),
75
+ histRow: (active) => ({
76
+ display: 'flex', alignItems: 'center', gap: 6, width: '100%', minWidth: 0,
77
+ padding: '4px 6px', border: 'none', borderRadius: 5, textAlign: 'left',
78
+ font: 'inherit', fontSize: 11.5, cursor: 'pointer', color: 'inherit',
79
+ background: active ? 'rgba(77,107,254,.16)' : 'transparent',
80
+ }),
81
+ histIndex: {
82
+ flex: '0 0 auto', width: 18, textAlign: 'right', fontSize: 10,
83
+ opacity: 0.55, fontVariantNumeric: 'tabular-nums',
84
+ },
85
+ histTime: { flex: '0 0 auto', fontSize: 9.5, opacity: 0.5, fontVariantNumeric: 'tabular-nums' },
86
+ histEmpty: { padding: '4px 6px', fontSize: 11, opacity: 0.7, display: 'flex', flexDirection: 'column', gap: 5, lineHeight: 1.5 },
71
87
  stats: { position: 'absolute', left: 8, bottom: 6, zIndex: 10, fontSize: 10, opacity: 0.62, pointerEvents: 'none', whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' },
72
88
  menu: { position: 'absolute', right: 6, top: 30, zIndex: 40, minWidth: 132, padding: 4, borderRadius: 6, border: '1px solid', boxShadow: '0 10px 26px rgba(0,0,0,.3)' },
73
89
  menuRow: { display: 'flex', gap: 4, padding: '3px 4px', flexWrap: 'wrap' },
@@ -392,6 +408,64 @@ window.__ModuleLoader__.load({
392
408
  // Icons are inline SVG on a 20x20 grid rendered at exactly 20 CSS px, so the
393
409
  // scale is 1:1 and the strokes land on whole pixels (a 16-unit viewBox
394
410
  // stretched to 17 px is what made the previous set look soft).
411
+ // What one appearance step actually changed, in one short line. The history
412
+ // drawer exists so a user can tell "which step hid that part", which means
413
+ // the label has to name the target, not just say "外观改动".
414
+ function lookDiffLabel(before, after) {
415
+ let a = {}
416
+ let b = {}
417
+ try { a = JSON.parse(before) || {} } catch (err) { a = {} }
418
+ try { b = JSON.parse(after) || {} } catch (err) { b = {} }
419
+ const out = []
420
+ const av = a.v || {}
421
+ const bv = b.v || {}
422
+ const names = new Set([...Object.keys(av), ...Object.keys(bv)])
423
+ const hidden = []
424
+ const shown = []
425
+ for (const name of names) {
426
+ const was = av[name] !== false
427
+ const now = bv[name] !== false
428
+ if (was === now) continue
429
+ if (now) shown.push(name)
430
+ else hidden.push(name)
431
+ }
432
+ if (hidden.length === 1) out.push(`隐藏 ${hidden[0]}`)
433
+ else if (hidden.length > 1) out.push(`隐藏 ${hidden.length} 件`)
434
+ if (shown.length === 1) out.push(`显示 ${shown[0]}`)
435
+ else if (shown.length > 1) out.push(`显示 ${shown.length} 件`)
436
+ const colors = []
437
+ for (const kind of ['inst', 'part']) {
438
+ const ao = (a.o && a.o[kind]) || {}
439
+ const bo = (b.o && b.o[kind]) || {}
440
+ for (const key of new Set([...Object.keys(ao), ...Object.keys(bo)])) {
441
+ const from = ao[key] || ''
442
+ const to = bo[key] || ''
443
+ if (from !== to) colors.push({ key, to })
444
+ }
445
+ }
446
+ if (colors.length === 1) out.push(colors[0].to ? `换色 ${colors[0].key} → ${colors[0].to}` : `恢复默认色 ${colors[0].key}`)
447
+ else if (colors.length > 1) out.push(`换色 ${colors.length} 处`)
448
+ const ao2 = a.a || {}
449
+ const bo2 = b.a || {}
450
+ const ops = []
451
+ for (const key of new Set([...Object.keys(ao2), ...Object.keys(bo2)])) {
452
+ const from = typeof ao2[key] === 'number' ? ao2[key] : 1
453
+ const to = typeof bo2[key] === 'number' ? bo2[key] : 1
454
+ if (Math.abs(from - to) > 1e-6) ops.push({ key, to })
455
+ }
456
+ if (ops.length === 1) out.push(`透明度 ${ops[0].key} ${Math.round(ops[0].to * 100)}%`)
457
+ else if (ops.length > 1) out.push(`透明度 ${ops.length} 件`)
458
+ const aw = a.w || {}
459
+ const bw = b.w || {}
460
+ const wires = []
461
+ for (const key of new Set([...Object.keys(aw), ...Object.keys(bw)])) {
462
+ if (Boolean(aw[key]) !== Boolean(bw[key])) wires.push({ key, on: Boolean(bw[key]) })
463
+ }
464
+ if (wires.length === 1) out.push(`线框 ${wires[0].on ? '开' : '关'} ${wires[0].key}`)
465
+ else if (wires.length > 1) out.push(`线框 ${wires.length} 件`)
466
+ return out.join(' · ') || '外观改动'
467
+ }
468
+
395
469
  function RailIcon({ name }) {
396
470
  const common = {
397
471
  width: 20,
@@ -453,6 +527,14 @@ window.__ModuleLoader__.load({
453
527
  h('path', { key: 'b', d: 'M2.6 9.4h14.8' }),
454
528
  ])
455
529
  }
530
+ if (name === 'history') {
531
+ // A clock face with a counter-clockwise arrow: "what changed, in order".
532
+ return h('svg', common, [
533
+ h('path', { key: 'a', d: 'M10 3.1a6.9 6.9 0 1 1-6.1 3.7' }),
534
+ h('path', { key: 'b', d: 'M2.6 3.2v3.9h3.9' }),
535
+ h('path', { key: 'c', d: 'M10 6.6V10l2.6 1.7' }),
536
+ ])
537
+ }
456
538
  return h('svg', common, [
457
539
  h('circle', { key: 'c', cx: 10, cy: 10, r: 7.4 }),
458
540
  h('path', { key: 'd', d: 'M10 9.2v5' }),
@@ -1638,6 +1720,30 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1638
1720
  applyLook(entry.after)
1639
1721
  setHistTick((t) => t + 1)
1640
1722
  }
1723
+ // Jump to an arbitrary point of the stack, which is what the history
1724
+ // drawer's rows do: index -1 means "the look before the first step".
1725
+ const jumpTo = (index) => {
1726
+ const h = histRef.current
1727
+ if (!h.undo.length) return
1728
+ const target = index < 0 ? h.undo[0].before : h.undo[Math.min(index, h.undo.length - 1)].after
1729
+ const tail = h.undo.splice(index + 1)
1730
+ h.redo = tail.reverse().concat(h.redo)
1731
+ h.at = 0
1732
+ applyLook(target)
1733
+ setHistTick((t) => t + 1)
1734
+ }
1735
+ // Clicking a dimmed (already undone) row walks forward again.
1736
+ const jumpForward = (step) => {
1737
+ const h = histRef.current
1738
+ const seq = h.redo.slice().reverse()
1739
+ const entry = seq[step]
1740
+ if (!entry) return
1741
+ h.undo = h.undo.concat(seq.slice(0, step + 1))
1742
+ h.redo = seq.slice(step + 1).reverse()
1743
+ h.at = 0
1744
+ applyLook(entry.after)
1745
+ setHistTick((t) => t + 1)
1746
+ }
1641
1747
 
1642
1748
  // Async callbacks (the 1.5 s poller) close over the render they were
1643
1749
  // created in, so the live look has to be read from a ref, not from state.
@@ -1659,9 +1765,12 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1659
1765
  if (h.quiet) { h.quiet = false; h.last = lookSnap; return }
1660
1766
  if (lookSnap === h.last) return
1661
1767
  const top = h.undo[h.undo.length - 1]
1662
- if (top && now - h.at < 1500) top.after = lookSnap
1663
- else {
1664
- h.undo.push({ before: h.last, after: lookSnap })
1768
+ if (top && now - h.at < 1500) {
1769
+ top.after = lookSnap
1770
+ top.label = lookDiffLabel(top.before, lookSnap)
1771
+ top.at = now
1772
+ } else {
1773
+ h.undo.push({ before: h.last, after: lookSnap, label: lookDiffLabel(h.last, lookSnap), at: now })
1665
1774
  if (h.undo.length > 40) h.undo.shift()
1666
1775
  }
1667
1776
  h.redo = []
@@ -2488,7 +2597,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2488
2597
  ]
2489
2598
  : []
2490
2599
 
2491
- const panelTitle = { parts: '零件', features: '特征', props: '选中项', motion: '运动', view: '视图', models: '模型', info: '信息' }[panel] || ''
2600
+ const panelTitle = { parts: '零件', features: '特征', props: '选中项', history: '操作历史', motion: '运动', view: '视图', models: '模型', info: '信息' }[panel] || ''
2492
2601
  // The scene carries `asm:<id>` for an assembly, which is how the deps list
2493
2602
  // is matched to what is on screen.
2494
2603
  const depsModel = deps && payload && typeof payload.docKey === 'string' && payload.docKey.startsWith('asm:')
@@ -2697,12 +2806,79 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2697
2806
  const base = String(sc.title || sc.id || '').split('/').pop()
2698
2807
  return base.replace(/\.(step|stp|stl|brep|iges|igs|stpz)$/i, '') || String(sc.id || '')
2699
2808
  }
2809
+ // ---- 操作历史抽屉 ----------------------------------------------------
2810
+ // The undo stack is a list of appearance snapshots; the drawer turns it
2811
+ // into readable rows ("隐藏 缸体_外包络 · 14:22:03") and lets a click
2812
+ // land on any of them instead of stepping through Ctrl+Z one by one.
2813
+ const histStamp = (ms) => (ms ? new Date(ms).toLocaleTimeString('zh-CN', { hour12: false }) : '')
2814
+ const histRows = (() => {
2815
+ const state = histRef.current
2816
+ const rows = []
2817
+ if (!state.undo.length && !state.redo.length) {
2818
+ return [h('div', { key: 'none', style: styles.histEmpty }, [
2819
+ h('div', { key: 'a' }, '还没有外观改动。'),
2820
+ h('div', { key: 'b' }, '改颜色、显隐、透明度或线框之后,每一步都会记在这里,点一行就能跳回那一步。'),
2821
+ ])]
2822
+ }
2823
+ if (state.undo.length) {
2824
+ rows.push(h('button', {
2825
+ key: 'origin',
2826
+ type: 'button',
2827
+ 'data-cad-hist': 'origin',
2828
+ style: { ...styles.histRow(false), fontSize: 10.5, opacity: 0.72 },
2829
+ title: '回到所有外观改动之前',
2830
+ onClick: () => jumpTo(-1),
2831
+ }, '回到最初的样子'))
2832
+ }
2833
+ for (let i = state.undo.length - 1; i >= 0; i -= 1) {
2834
+ const entry = state.undo[i]
2835
+ rows.push(h('button', {
2836
+ key: `u${i}`,
2837
+ type: 'button',
2838
+ 'data-cad-hist': `u${i}`,
2839
+ 'data-cad-hist-state': i === state.undo.length - 1 ? 'current' : 'past',
2840
+ style: styles.histRow(i === state.undo.length - 1),
2841
+ title: `${entry.label || '外观改动'}(回到这一步之后)`,
2842
+ onClick: () => jumpTo(i),
2843
+ }, [
2844
+ h('span', { key: 'n', style: styles.histIndex }, String(i + 1)),
2845
+ h('span', { key: 'l', style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, entry.label || '外观改动'),
2846
+ h('span', { key: 't', style: styles.histTime }, histStamp(entry.at)),
2847
+ ]))
2848
+ }
2849
+ const future = state.redo.slice().reverse()
2850
+ for (let k = 0; k < future.length; k += 1) {
2851
+ const entry = future[k]
2852
+ rows.push(h('button', {
2853
+ key: `r${k}`,
2854
+ type: 'button',
2855
+ 'data-cad-hist': `r${k}`,
2856
+ 'data-cad-hist-state': 'undone',
2857
+ style: { ...styles.histRow(false), opacity: 0.45 },
2858
+ title: `${entry.label || '外观改动'}(已撤销,点一下再做一次)`,
2859
+ onClick: () => jumpForward(k),
2860
+ }, [
2861
+ h('span', { key: 'n', style: styles.histIndex }, '↷'),
2862
+ h('span', { key: 'l', style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, entry.label || '外观改动'),
2863
+ h('span', { key: 't', style: styles.histTime }, histStamp(entry.at)),
2864
+ ]))
2865
+ }
2866
+ return rows
2867
+ })()
2868
+ const historyBody = h('div', { key: 'hist', style: { display: 'flex', flexDirection: 'column', gap: 1 }, 'data-cad-history': `${histRef.current.undo.length}/${histRef.current.redo.length}` }, [
2869
+ ...histRows,
2870
+ h('div', { key: 'note', style: { ...styles.treeHint, whiteSpace: 'normal', padding: '6px 6px 0' } },
2871
+ '这里只记外观(颜色/显隐/透明度/线框),一步一条,快捷键 Ctrl+Z / Ctrl+Shift+Z。模型特征与参数的撤销在「特征」里。'),
2872
+ ])
2873
+
2700
2874
  const panelBody = panel === 'parts'
2701
2875
  ? rows
2702
2876
  : panel === 'features'
2703
2877
  ? featureBody
2704
2878
  : panel === 'props'
2705
2879
  ? inspectorBody
2880
+ : panel === 'history'
2881
+ ? historyBody
2706
2882
  : panel === 'motion'
2707
2883
  ? motionBody
2708
2884
  : panel === 'view'
@@ -2784,13 +2960,14 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2784
2960
  { id: 'parts', label: '零件:显隐与配色' },
2785
2961
  { id: 'features', label: '特征列表:改一条就重建' },
2786
2962
  { id: 'props', label: '选中项属性' },
2963
+ { id: 'history', label: '操作历史:外观改动的每一步,可点回' },
2787
2964
  { id: 'motion', label: '关节与运动、爆炸图' },
2788
2965
  { id: 'view', label: '视图与显示' },
2789
2966
  { id: 'models', label: '切换模型' },
2790
2967
  { id: 'info', label: '模型信息' },
2791
2968
  ]
2792
2969
 
2793
- return h('div', { style: styles.root, 'data-cad-panel-root': '1', onMouseDown: () => { panelTouchRef.current = Date.now() } }, [
2970
+ return h('div', { style: styles.root, ref: panelRootRef, 'data-cad-panel-root': '1', onMouseDown: () => { panelTouchRef.current = Date.now() } }, [
2794
2971
  h('div', {
2795
2972
  key: 'head',
2796
2973
  style: styles.head,
@@ -2883,6 +3060,28 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2883
3060
  : null,
2884
3061
  ]),
2885
3062
  ]),
3063
+ h('div', { key: 'hist', style: styles.headActions, 'data-cad-head-actions': '1' }, [
3064
+ h('button', {
3065
+ key: 'u',
3066
+ type: 'button',
3067
+ style: styles.histBtn(histRef.current.undo.length > 0),
3068
+ title: histRef.current.undo.length ? `撤销:${histRef.current.undo[histRef.current.undo.length - 1].label || '外观改动'}` : '没有可撤销的外观改动',
3069
+ 'aria-label': '撤销外观改动',
3070
+ 'data-cad-undo': histRef.current.undo.length,
3071
+ disabled: !histRef.current.undo.length,
3072
+ onClick: doUndo,
3073
+ }, '↶'),
3074
+ h('button', {
3075
+ key: 'r',
3076
+ type: 'button',
3077
+ style: styles.histBtn(histRef.current.redo.length > 0),
3078
+ title: histRef.current.redo.length ? '重做外观改动' : '没有可重做的改动',
3079
+ 'aria-label': '重做外观改动',
3080
+ 'data-cad-redo': histRef.current.redo.length,
3081
+ disabled: !histRef.current.redo.length,
3082
+ onClick: doRedo,
3083
+ }, '↷'),
3084
+ ]),
2886
3085
  ]),
2887
3086
  error ? h('div', { key: 'err', style: styles.warn }, error) : null,
2888
3087
  h('div', { key: 'body', style: { display: 'flex', flex: 1, minHeight: 0, minWidth: 0 } }, [
@@ -2907,19 +3106,6 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2907
3106
  : payload
2908
3107
  ? h('div', { key: 'stage', style: styles.stage }, [
2909
3108
  h(Viewport, { payload, visibility, options: { ...display, overrides, opacities, wireframes, restoreCamera: pendingCameraRef.current, onPick: pickInViewport }, handleRef: viewportRef }),
2910
- h('div', { key: 'undo', style: styles.undoPair, ref: panelRootRef }, [
2911
- h('button', {
2912
- key: 'u', type: 'button', style: styles.undoBtn(histRef.current.undo.length > 0),
2913
- title: histRef.current.undo.length ? '撤销上一次外观改动' : '没有可撤销的改动',
2914
- 'aria-label': '撤销外观改动', 'data-cad-undo': histRef.current.undo.length,
2915
- onClick: doUndo,
2916
- }, '↶'),
2917
- h('button', {
2918
- key: 'r', type: 'button', style: styles.undoBtn(histRef.current.redo.length > 0),
2919
- title: '重做外观改动', 'aria-label': '重做外观改动', 'data-cad-redo': histRef.current.redo.length,
2920
- onClick: doRedo,
2921
- }, '↷'),
2922
- ]),
2923
3109
  ])
2924
3110
  : h('div', { key: 'empty', style: styles.empty }, '还没有模型。让 AI 跑一次 FreeCAD 脚本或打开一个 STEP 文件,这里会自动显示。'),
2925
3111
  picked && panel !== 'parts'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {