dsh-cad-studio 0.8.0 → 0.8.2
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 +4 -0
- package/client.js +108 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,6 +138,10 @@ npm 包:<https://www.npmjs.com/package/dsh-cad-studio>(`dsh plugin` / DSH
|
|
|
138
138
|
|
|
139
139
|
`rot` 是行主序 3×3,`translate` 是 mm。几何按**逐面三角化**,平面与孔壁不共享顶点(避免法线平均出暗色扇形)。
|
|
140
140
|
|
|
141
|
+
### 视图撤销
|
|
142
|
+
|
|
143
|
+
透明度、颜色、显隐、线框这些**外观改动**也进撤销栈(服务端 `doc.undo` 只管文档结构,管不到它们):同一目标 1.5 s 内的连续拖动合并成一条,切场景清空,最多 40 步。面板「活跃」时(焦点在面板内,或 8 s 内点过面板)按 `Ctrl/Cmd+Z` 撤销、`Shift+Ctrl/Cmd+Z` 或 `Ctrl+Y` 重做;视口右下角还有一对 ↶ / ↷ 按钮,没东西可撤销时是灰的。输入框里的 `Ctrl+Z` 不劫持,「特征」页签里仍归文档撤销。
|
|
144
|
+
|
|
141
145
|
## 开发
|
|
142
146
|
|
|
143
147
|
```bash
|
package/client.js
CHANGED
|
@@ -61,6 +61,13 @@ 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)',
|
|
67
|
+
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',
|
|
70
|
+
}),
|
|
64
71
|
stats: { position: 'absolute', left: 8, bottom: 6, zIndex: 10, fontSize: 10, opacity: 0.62, pointerEvents: 'none', whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' },
|
|
65
72
|
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)' },
|
|
66
73
|
menuRow: { display: 'flex', gap: 4, padding: '3px 4px', flexWrap: 'wrap' },
|
|
@@ -1553,6 +1560,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1553
1560
|
// One floating panel at a time, opened from the rail: 'parts' | 'view' |
|
|
1554
1561
|
// 'models' | 'info' | '' (closed). Same icon again closes it.
|
|
1555
1562
|
const [panel, setPanel] = useState('')
|
|
1563
|
+
useEffect(() => { panelRef.current = panel }, [panel])
|
|
1556
1564
|
const theme = useTheme()
|
|
1557
1565
|
// Colour overrides picked by hand in the tree. Two levels, because an
|
|
1558
1566
|
// assembly can show one part many times: `inst` is one row, `part` is
|
|
@@ -1565,11 +1573,94 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1565
1573
|
const [opacities, setOpacities] = useState({})
|
|
1566
1574
|
const [wireframes, setWireframes] = useState({})
|
|
1567
1575
|
|
|
1576
|
+
// ---- 视图撤销:透明度 / 颜色 / 显隐 / 线框 ----
|
|
1577
|
+
// 这些是纯客户端的外观改动,服务端的 doc.undo 管不到。用快照栈记录整组
|
|
1578
|
+
// 外观状态(JSON 串比较),同一目标 700 ms 内连续变动合并成一条,切场景清空。
|
|
1579
|
+
const panelRootRef = useRef(null)
|
|
1580
|
+
const panelRef = useRef('')
|
|
1581
|
+
const panelTouchRef = useRef(0)
|
|
1582
|
+
const lookSnap = JSON.stringify({ v: visibility, o: overrides, a: opacities, w: wireframes })
|
|
1583
|
+
const histRef = useRef({ undo: [], redo: [], last: lookSnap, scene: '', quiet: false, at: 0 })
|
|
1584
|
+
const [histTick, setHistTick] = useState(0)
|
|
1585
|
+
const applyLook = (snap) => {
|
|
1586
|
+
try {
|
|
1587
|
+
const parsed = JSON.parse(snap)
|
|
1588
|
+
histRef.current.quiet = true
|
|
1589
|
+
setVisibility(parsed.v || {})
|
|
1590
|
+
setOverrides(parsed.o || { inst: {}, part: {} })
|
|
1591
|
+
setOpacities(parsed.a || {})
|
|
1592
|
+
setWireframes(parsed.w || {})
|
|
1593
|
+
} catch (err) { /* 坏快照不该拖垮面板 */ }
|
|
1594
|
+
}
|
|
1595
|
+
const doUndo = () => {
|
|
1596
|
+
const h = histRef.current
|
|
1597
|
+
const entry = h.undo.pop()
|
|
1598
|
+
if (!entry) return
|
|
1599
|
+
h.redo.push(entry)
|
|
1600
|
+
applyLook(entry.before)
|
|
1601
|
+
setHistTick((t) => t + 1)
|
|
1602
|
+
}
|
|
1603
|
+
const doRedo = () => {
|
|
1604
|
+
const h = histRef.current
|
|
1605
|
+
const entry = h.redo.pop()
|
|
1606
|
+
if (!entry) return
|
|
1607
|
+
h.undo.push(entry)
|
|
1608
|
+
applyLook(entry.after)
|
|
1609
|
+
setHistTick((t) => t + 1)
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1568
1612
|
// Async callbacks (the 1.5 s poller) close over the render they were
|
|
1569
1613
|
// created in, so the live look has to be read from a ref, not from state.
|
|
1570
1614
|
// Declared after the states it mirrors: reading them earlier would put
|
|
1571
1615
|
// `overrides` in its temporal dead zone during the first render.
|
|
1572
1616
|
const visibleIdRef = useRef('')
|
|
1617
|
+
useEffect(() => {
|
|
1618
|
+
const h = histRef.current
|
|
1619
|
+
const now = Date.now()
|
|
1620
|
+
if (h.scene !== sceneKey) {
|
|
1621
|
+
h.scene = sceneKey
|
|
1622
|
+
h.undo = []
|
|
1623
|
+
h.redo = []
|
|
1624
|
+
h.last = lookSnap
|
|
1625
|
+
h.at = 0
|
|
1626
|
+
setHistTick((t) => t + 1)
|
|
1627
|
+
return
|
|
1628
|
+
}
|
|
1629
|
+
if (h.quiet) { h.quiet = false; h.last = lookSnap; return }
|
|
1630
|
+
if (lookSnap === h.last) return
|
|
1631
|
+
const top = h.undo[h.undo.length - 1]
|
|
1632
|
+
if (top && now - h.at < 1500) top.after = lookSnap
|
|
1633
|
+
else {
|
|
1634
|
+
h.undo.push({ before: h.last, after: lookSnap })
|
|
1635
|
+
if (h.undo.length > 40) h.undo.shift()
|
|
1636
|
+
}
|
|
1637
|
+
h.redo = []
|
|
1638
|
+
h.last = lookSnap
|
|
1639
|
+
h.at = now
|
|
1640
|
+
setHistTick((t) => t + 1)
|
|
1641
|
+
}, [lookSnap, sceneKey])
|
|
1642
|
+
|
|
1643
|
+
useEffect(() => {
|
|
1644
|
+
const onKey = (event) => {
|
|
1645
|
+
const key = String(event.key || '').toLowerCase()
|
|
1646
|
+
if (!(event.ctrlKey || event.metaKey)) return
|
|
1647
|
+
if (key !== 'z' && key !== 'y') return
|
|
1648
|
+
const target = event.target
|
|
1649
|
+
const tag = target && target.tagName ? target.tagName.toLowerCase() : ''
|
|
1650
|
+
if (tag === 'input' || tag === 'textarea' || tag === 'select' || (target && target.isContentEditable)) return
|
|
1651
|
+
if (panelRef.current === 'features') return
|
|
1652
|
+
const host = panelRootRef.current
|
|
1653
|
+
const focused = document.activeElement
|
|
1654
|
+
const touched = Date.now() - panelTouchRef.current < 8000
|
|
1655
|
+
const inPanel = touched || Boolean(host && (host.contains(focused) || host.contains(target)))
|
|
1656
|
+
if (!inPanel) return
|
|
1657
|
+
event.preventDefault()
|
|
1658
|
+
if (key === 'y' || event.shiftKey) doRedo()
|
|
1659
|
+
else doUndo()
|
|
1660
|
+
}
|
|
1661
|
+
window.addEventListener('keydown', onKey)
|
|
1662
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
1663
|
+
}, [])
|
|
1573
1664
|
const lookRef = useRef({ visibility: {}, overrides: { inst: {}, part: {} }, opacities: {}, wireframes: {} })
|
|
1574
1665
|
useEffect(() => { visibleIdRef.current = visibleId }, [visibleId])
|
|
1575
1666
|
useEffect(() => {
|
|
@@ -2511,7 +2602,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2511
2602
|
{ id: 'info', label: '模型信息' },
|
|
2512
2603
|
]
|
|
2513
2604
|
|
|
2514
|
-
return h('div', { style: styles.root, 'data-cad-panel-root': '1' }, [
|
|
2605
|
+
return h('div', { style: styles.root, 'data-cad-panel-root': '1', onMouseDown: () => { panelTouchRef.current = Date.now() } }, [
|
|
2515
2606
|
h('div', {
|
|
2516
2607
|
key: 'head',
|
|
2517
2608
|
style: styles.head,
|
|
@@ -2626,7 +2717,22 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2626
2717
|
!runtime.available
|
|
2627
2718
|
? guideNode
|
|
2628
2719
|
: payload
|
|
2629
|
-
? h('div', { key: 'stage', style: styles.stage },
|
|
2720
|
+
? h('div', { key: 'stage', style: styles.stage }, [
|
|
2721
|
+
h(Viewport, { payload, visibility, options: { ...display, overrides, opacities, wireframes, restoreCamera: pendingCameraRef.current, onPick: pickInViewport }, handleRef: viewportRef }),
|
|
2722
|
+
h('div', { key: 'undo', style: styles.undoPair, ref: panelRootRef }, [
|
|
2723
|
+
h('button', {
|
|
2724
|
+
key: 'u', type: 'button', style: styles.undoBtn(histRef.current.undo.length > 0),
|
|
2725
|
+
title: histRef.current.undo.length ? '撤销上一次外观改动' : '没有可撤销的改动',
|
|
2726
|
+
'aria-label': '撤销外观改动', 'data-cad-undo': histRef.current.undo.length,
|
|
2727
|
+
onClick: doUndo,
|
|
2728
|
+
}, '↶'),
|
|
2729
|
+
h('button', {
|
|
2730
|
+
key: 'r', type: 'button', style: styles.undoBtn(histRef.current.redo.length > 0),
|
|
2731
|
+
title: '重做外观改动', 'aria-label': '重做外观改动', 'data-cad-redo': histRef.current.redo.length,
|
|
2732
|
+
onClick: doRedo,
|
|
2733
|
+
}, '↷'),
|
|
2734
|
+
]),
|
|
2735
|
+
])
|
|
2630
2736
|
: h('div', { key: 'empty', style: styles.empty }, '还没有模型。让 AI 跑一次 FreeCAD 脚本或打开一个 STEP 文件,这里会自动显示。'),
|
|
2631
2737
|
picked && panel !== 'parts'
|
|
2632
2738
|
? h('button', {
|