dsh-cad-studio 0.18.0 → 0.20.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/client.js +57 -0
- package/index.js +174 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
|
|
|
23
23
|
| 几何自检 | `cad_studio_check {source}` 在导出/打印前问一次:是否有效实体、外壳是否闭合、每个实体体积多少,返回中文问题清单(零体积 / 外壳未闭合 / 几何无效 / 没有实体) |
|
|
24
24
|
| 打印网格 | `cad_studio_mesh {source, target:"…/x.stl"}` 三角化 + 去重合并点/面、修形变、统一法向,可选 `fillHoles`、`targetSize`(减面);回报修复前后的 facets/points,避免「导出成功但网格是碎的」 |
|
|
25
25
|
| 旋转体与凹槽 | `revolve` 的 `axis` 取草图平面内的轴(`"Y"` 或 `[0,1,0]`)才是实体;垂直轴(XY 草图的 Z)只会扫出零厚度圆环,插件会直接报错。凹槽=`{kind:"cut", with:{kind:"revolve", …}}`,不需要单独 op |
|
|
26
|
+
| 面板改草图 | 特征抽屉里点「草图 N」展开:数值约束是可编辑输入框(`distance*`/`radius`/`angle` 按度),改完立刻重解并重建;解不出来就回滚并报错 |
|
|
27
|
+
| 撤销跨重启 | 文档级撤销栈(建/删/改名)写进 `<数据目录>/journal.json`,重启后仍可撤销;装配与视图的撤销只在本次会话内有效 |
|
|
26
28
|
| 草图约束 | `equal`(等长)、`symmetric`(三点对称,需 `c` 点)、`angle`(**单位是度**,内部转弧度并在求解后重测);`distance` 是两点距离、`distance_x/y` 是该点的绝对坐标 |
|
|
27
29
|
| 草图 + 放样/扫掠 | 草图存在文档里(`cad_studio_doc {action:"create", kind:"features", sketches:{S1:{geometry:[…],constraints:[…]}}, features:[{kind:"extrude",sketch:"S1",h:10}]}`);`loft` 用 `sections:[{sketch:"S1"},{sketch:"S2",at:[0,0,40]}]`,`sweep` 用 `path:[[x,y,z],…]`。改草图会重建(草图进了缓存哈希,不会命中旧 BREP) |
|
|
28
30
|
| 特征 → STEP | `cad_studio_export {model:"名字", target:"…/x.step"}` 或 `cad_studio_doc {action:"show", name, export:"…/x.step"}`;特征列表是源,STEP 是产物,不用自己复刻发射器 |
|
package/client.js
CHANGED
|
@@ -1677,6 +1677,8 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1677
1677
|
const [featDraft, setFeatDraft] = useState({})
|
|
1678
1678
|
const [featAdd, setFeatAdd] = useState(false)
|
|
1679
1679
|
const [featError, setFeatError] = useState('')
|
|
1680
|
+
// Which document sketch is expanded in the 草图 section.
|
|
1681
|
+
const [openSketch, setOpenSketch] = useState('')
|
|
1680
1682
|
const featTimer = useRef(null)
|
|
1681
1683
|
const dragRef = useRef({ timer: 0, pending: null })
|
|
1682
1684
|
const viewportRef = useRef(null)
|
|
@@ -2019,10 +2021,64 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2019
2021
|
}, [featureModel])
|
|
2020
2022
|
const graphNodes = (payload && payload.graph && payload.graph.nodes) || []
|
|
2021
2023
|
const graphTip = (payload && payload.graph && payload.graph.tip) || null
|
|
2024
|
+
// Sketches are document data, so the panel edits the same thing the
|
|
2025
|
+
// agent writes: change a dimension, the sketch is re-solved, re-measured
|
|
2026
|
+
// and the whole feature chain rebuilds. Non-numeric constraints are shown
|
|
2027
|
+
// read-only — they are geometry relations, not numbers.
|
|
2028
|
+
const sketchDocs = (payload && payload.sketches) || {}
|
|
2029
|
+
const sketchNames = Object.keys(sketchDocs || {})
|
|
2030
|
+
const sketchSection = sketchNames.length
|
|
2031
|
+
? [
|
|
2032
|
+
h('div', { key: 'sk-h', style: { ...styles.treeHint, display: 'flex', gap: 6, alignItems: 'center', marginTop: 2 }, 'data-cad-sketch-head': '1' }, `草图 ${sketchNames.length}`),
|
|
2033
|
+
...sketchNames.map((name) => {
|
|
2034
|
+
const sk = sketchDocs[name] || {}
|
|
2035
|
+
const geos = Array.isArray(sk.geometry) ? sk.geometry : []
|
|
2036
|
+
const cons = Array.isArray(sk.constraints) ? sk.constraints : []
|
|
2037
|
+
const open = openSketch === name
|
|
2038
|
+
const setValue = (cid, raw) => {
|
|
2039
|
+
const value = Number(raw)
|
|
2040
|
+
if (!Number.isFinite(value)) return
|
|
2041
|
+
const next = JSON.parse(JSON.stringify(sk))
|
|
2042
|
+
const hit = (next.constraints || []).find((c) => String(c.id) === String(cid))
|
|
2043
|
+
if (!hit) return
|
|
2044
|
+
hit.value = value
|
|
2045
|
+
postFeature({ action: 'sketch', sketch: { name, def: next } })
|
|
2046
|
+
}
|
|
2047
|
+
return h('div', { key: `sk-${name}`, style: styles.featBlock, 'data-cad-sketch': name }, [
|
|
2048
|
+
h('div', {
|
|
2049
|
+
key: 'r',
|
|
2050
|
+
style: { ...styles.featHead, cursor: 'pointer' },
|
|
2051
|
+
'data-cad-sketch-toggle': name,
|
|
2052
|
+
onClick: (event) => { event.stopPropagation(); setOpenSketch(open ? '' : name) },
|
|
2053
|
+
}, [
|
|
2054
|
+
h('span', { key: 'n', style: { ...styles.featLabel, minWidth: 0, flex: '1 1 auto', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: `${name}:${geos.length} 条线 · ${cons.length} 个约束` }, `${name} · ${geos.length} 线 ${cons.length} 约束`),
|
|
2055
|
+
]),
|
|
2056
|
+
open
|
|
2057
|
+
? h('div', { key: 'b', style: { paddingLeft: 8, paddingBottom: 4 } }, [
|
|
2058
|
+
...cons.filter((c) => typeof c.value === 'number').map((c) => h('div', { key: `d-${c.id}`, style: { display: 'flex', gap: 6, alignItems: 'center', margin: '2px 0' } }, [
|
|
2059
|
+
h('span', { key: 'l', style: { fontSize: 11, opacity: 0.72, flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: `${c.type} ${c.a || ''} ${c.b || ''}` }, `${c.type}${c.a ? ` ${c.a}` : ''}`),
|
|
2060
|
+
h('input', {
|
|
2061
|
+
key: 'i',
|
|
2062
|
+
type: 'number',
|
|
2063
|
+
style: { ...styles.jointNum, width: 62, fontSize: 11, flex: '0 0 auto', boxSizing: 'border-box' },
|
|
2064
|
+
'data-cad-sk-value': `${name}:${c.id}`,
|
|
2065
|
+
value: String(c.value),
|
|
2066
|
+
onChange: (event) => setValue(c.id, event.currentTarget.value),
|
|
2067
|
+
}),
|
|
2068
|
+
])),
|
|
2069
|
+
...cons.filter((c) => typeof c.value !== 'number').map((c) => h('div', { key: `g-${c.id}`, style: { fontSize: 11, opacity: 0.62, margin: '1px 0' }, 'data-cad-sk-geo': `${name}:${c.id}` }, `${c.type} ${c.a || ''}${c.b ? ` · ${c.b}` : ''}`)),
|
|
2070
|
+
h('div', { key: 'geo', style: { fontSize: 10.5, opacity: 0.5, marginTop: 2, whiteSpace: 'normal' } }, geos.map((g) => g.id).join(' · ')),
|
|
2071
|
+
])
|
|
2072
|
+
: null,
|
|
2073
|
+
])
|
|
2074
|
+
}),
|
|
2075
|
+
]
|
|
2076
|
+
: []
|
|
2022
2077
|
const featureBody = paramsSection.length
|
|
2023
2078
|
? [...paramsSection, ...(!featureList.length
|
|
2024
2079
|
? [h('div', { key: 'script-hint', style: { ...styles.treeHint, whiteSpace: 'nowrap' }, title: '脚本模型:改参数会重跑脚本;逐条特征只适用于声明式模型' }, '脚本模型 · 改参数即重跑脚本')]
|
|
2025
2080
|
: [h('div', { key: 'feat-h', style: { ...styles.treeHint, marginTop: 2 } }, `${featureList.length} 特征`)])]
|
|
2081
|
+
.concat(sketchSection)
|
|
2026
2082
|
: !featureModel || !featureList.length
|
|
2027
2083
|
? [h('div', { key: 'none', style: styles.propEmpty },
|
|
2028
2084
|
featureModel
|
|
@@ -2054,6 +2110,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2054
2110
|
}, kind)))
|
|
2055
2111
|
: null,
|
|
2056
2112
|
featError ? h('div', { key: 'e', style: styles.featError, 'data-cad-feat-error': '1' }, featError) : null,
|
|
2113
|
+
...sketchSection,
|
|
2057
2114
|
...featureList.map((feature, index) => {
|
|
2058
2115
|
const off = feature.enabled === false
|
|
2059
2116
|
const node = graphNodes.find((n) => n.id === feature.id)
|
package/index.js
CHANGED
|
@@ -919,6 +919,39 @@ class FreeCadBridge {
|
|
|
919
919
|
this.sessionUndo.push({ at: new Date().toISOString(), ...entry })
|
|
920
920
|
if (this.sessionUndo.length > 50) this.sessionUndo.shift()
|
|
921
921
|
this.sessionRedo = []
|
|
922
|
+
// Only entries carrying a serialisable `record` survive a restart: a raw
|
|
923
|
+
// closure cannot be written to disk, so those stay session-only.
|
|
924
|
+
if (entry && entry.record) this.persistJournal()
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** Write the replayable slice of the undo stack (newest 20) to journal.json. */
|
|
928
|
+
persistJournal() {
|
|
929
|
+
const rows = this.sessionUndo
|
|
930
|
+
.filter((e) => e && e.record)
|
|
931
|
+
.slice(-20)
|
|
932
|
+
.map((e) => ({ at: e.at, kind: e.kind, label: e.label, record: e.record }))
|
|
933
|
+
writeFile(join(FreeCadBridge.dataDir, 'journal.json'), JSON.stringify({ version: 1, entries: rows }, null, 2)).catch(() => {})
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Rebuild undo entries from journal.json. `makeEntry(record)` supplies the
|
|
938
|
+
* closures (it needs the document helpers, which live in the plugin scope),
|
|
939
|
+
* so the bridge itself stays free of FreeCAD knowledge.
|
|
940
|
+
*/
|
|
941
|
+
async loadJournal(makeEntry) {
|
|
942
|
+
let raw = null
|
|
943
|
+
try { raw = JSON.parse(await readFile(join(FreeCadBridge.dataDir, 'journal.json'), 'utf8')) } catch { return 0 }
|
|
944
|
+
const rows = Array.isArray(raw && raw.entries) ? raw.entries : []
|
|
945
|
+
let restored = 0
|
|
946
|
+
for (const row of rows) {
|
|
947
|
+
let built = null
|
|
948
|
+
try { built = makeEntry(row.record) } catch { built = null }
|
|
949
|
+
if (!built) continue
|
|
950
|
+
this.sessionUndo.push({ at: row.at, kind: row.kind, label: row.label, ...built, restored: true })
|
|
951
|
+
restored += 1
|
|
952
|
+
}
|
|
953
|
+
if (restored) this.sessionUndo = this.sessionUndo.slice(-50)
|
|
954
|
+
return restored
|
|
922
955
|
}
|
|
923
956
|
|
|
924
957
|
async applyAssemblySnapshot(snapshot) {
|
|
@@ -931,6 +964,7 @@ class FreeCadBridge {
|
|
|
931
964
|
}
|
|
932
965
|
|
|
933
966
|
async undoSession(kind) {
|
|
967
|
+
if (this.journalReady) { try { await this.journalReady } catch {} }
|
|
934
968
|
const stack = kind ? this.sessionUndo.filter((e) => e.kind === kind) : this.sessionUndo
|
|
935
969
|
const entry = stack[stack.length - 1]
|
|
936
970
|
if (!entry) return null
|
|
@@ -3359,7 +3393,7 @@ if _TARGET:
|
|
|
3359
3393
|
const code = isFeatures
|
|
3360
3394
|
? featuresScript(featureOps(doc), null, { cache, resume, sketches: doc.sketches })
|
|
3361
3395
|
: `${PRELUDE}\nP = ${JSON.stringify(doc.params ?? {})}\n${doc.script}`
|
|
3362
|
-
const meta = isFeatures ? { model: doc.name, features: publicFeatures(doc), tip: doc.tip ?? null } : { model: doc.name, params: doc.params ?? {} }
|
|
3396
|
+
const meta = isFeatures ? { model: doc.name, features: publicFeatures(doc), sketches: doc.sketches ?? {}, tip: doc.tip ?? null } : { model: doc.name, params: doc.params ?? {} }
|
|
3363
3397
|
doc.run = (doc.run ?? 0) + 1
|
|
3364
3398
|
doc.updatedAt = new Date().toISOString()
|
|
3365
3399
|
// One row per model: a rebuild rewrites the model's existing scene.
|
|
@@ -3483,6 +3517,7 @@ if _TARGET:
|
|
|
3483
3517
|
bridge.journal({
|
|
3484
3518
|
kind: 'doc',
|
|
3485
3519
|
label: `create ${key}`,
|
|
3520
|
+
record: { op: 'doc-create', model: key, dir, sceneId: sceneRow ? sceneRow.id : '' },
|
|
3486
3521
|
undo: async () => {
|
|
3487
3522
|
await unlink(file).catch(() => {})
|
|
3488
3523
|
if (sceneRow) { try { await bridge.removeScene(sceneRow.id, { journal: false }) } catch {} }
|
|
@@ -3497,6 +3532,83 @@ if _TARGET:
|
|
|
3497
3532
|
})
|
|
3498
3533
|
}
|
|
3499
3534
|
|
|
3535
|
+
/**
|
|
3536
|
+
* Rebuild one undo entry from a persisted journal record. Only document-level
|
|
3537
|
+
* operations are replayable: they are data (a name, a file, bytes). Assembly
|
|
3538
|
+
* and view journal entries are closures over live objects and stay
|
|
3539
|
+
* session-only — after a restart they are not in the stack at all, which is
|
|
3540
|
+
* honest: the panel then says there is nothing to undo instead of undoing
|
|
3541
|
+
* something else.
|
|
3542
|
+
*/
|
|
3543
|
+
const restoredEntry = (record) => {
|
|
3544
|
+
const r = record || {}
|
|
3545
|
+
const retitle = async (target, other) => {
|
|
3546
|
+
const row = bridge.history.find((h) => h.docKey === `model:${other}` || h.title === other)
|
|
3547
|
+
if (row) {
|
|
3548
|
+
row.title = target
|
|
3549
|
+
if (row.docKey) row.docKey = `model:${target}`
|
|
3550
|
+
await bridge.persist()
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
if (r.op === 'doc-create') {
|
|
3554
|
+
const file = modelFile(r.model, r.dir)
|
|
3555
|
+
return {
|
|
3556
|
+
undo: async () => {
|
|
3557
|
+
await unlink(file).catch(() => {})
|
|
3558
|
+
if (r.sceneId) { try { await bridge.removeScene(r.sceneId, { journal: false }) } catch {} }
|
|
3559
|
+
return { model: r.model }
|
|
3560
|
+
},
|
|
3561
|
+
redo: async () => {
|
|
3562
|
+
// Re-creating needs the emitter to publish again; let the caller do it.
|
|
3563
|
+
throw new Error('重启后不能「重做创建」:请用 cad_studio_doc create 重新发布')
|
|
3564
|
+
},
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
if (r.op === 'doc-delete') {
|
|
3568
|
+
const file = modelFile(r.model, r.dir)
|
|
3569
|
+
const bytes = Buffer.from(String(r.b64 || ''), 'base64')
|
|
3570
|
+
return {
|
|
3571
|
+
undo: async () => {
|
|
3572
|
+
await writeFile(file, bytes)
|
|
3573
|
+
try {
|
|
3574
|
+
const doc = await readModel(r.model, r.dir)
|
|
3575
|
+
await rebuild(doc, r.dir, { note: 'undo delete (restored journal)' })
|
|
3576
|
+
} catch {}
|
|
3577
|
+
return { model: r.model }
|
|
3578
|
+
},
|
|
3579
|
+
redo: async () => {
|
|
3580
|
+
await unlink(file).catch(() => {})
|
|
3581
|
+
return { model: r.model }
|
|
3582
|
+
},
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
if (r.op === 'doc-rename') {
|
|
3586
|
+
const from = modelFile(r.from, r.dir)
|
|
3587
|
+
const to = modelFile(r.to, r.dir)
|
|
3588
|
+
const move = async (src, dst, name) => {
|
|
3589
|
+
const doc = JSON.parse(await readFile(src, 'utf8'))
|
|
3590
|
+
doc.name = name
|
|
3591
|
+
await writeModel(doc, r.dir)
|
|
3592
|
+
await unlink(dst).catch(() => {})
|
|
3593
|
+
return { model: name }
|
|
3594
|
+
}
|
|
3595
|
+
return {
|
|
3596
|
+
undo: async () => { const out = await move(to, from, r.from); await retitle(r.from, r.to); return out },
|
|
3597
|
+
redo: async () => { const out = await move(from, to, r.to); await retitle(r.to, r.from); return out },
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
return null
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
// Restore the replayable journal once per plugin start (a hot reload keeps the
|
|
3604
|
+
// same bridge, so guard against stacking duplicates).
|
|
3605
|
+
if (bridge && !bridge.journalLoaded) {
|
|
3606
|
+
bridge.journalLoaded = true
|
|
3607
|
+
// Keep the promise: an undo issued before the file has been read would
|
|
3608
|
+
// otherwise see an empty stack and report "nothing to undo".
|
|
3609
|
+
bridge.journalReady = bridge.loadJournal(restoredEntry).catch(() => 0)
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3500
3612
|
const runFeatureAction = async (args, dir) => {
|
|
3501
3613
|
bridge.noteModelsDir(dir)
|
|
3502
3614
|
const action = String(args.action ?? 'list')
|
|
@@ -3505,8 +3617,55 @@ if _TARGET:
|
|
|
3505
3617
|
throw new Error(`${doc.name} 是脚本模型,没有特征列表(用 cad_studio_doc update 改 params,或新建 kind="features" 的模型)`)
|
|
3506
3618
|
}
|
|
3507
3619
|
if (action === 'list') {
|
|
3508
|
-
return { ok: true, model: doc.name, kind: doc.kind, features: publicFeatures(doc), graph: graphView(doc, { errors: [], executed: null }), stats: doc.stats ?? null }
|
|
3620
|
+
return { ok: true, model: doc.name, kind: doc.kind, features: publicFeatures(doc), sketches: doc.sketches ?? {}, graph: graphView(doc, { errors: [], executed: null }), stats: doc.stats ?? null }
|
|
3509
3621
|
}
|
|
3622
|
+
if (action === 'sketch') {
|
|
3623
|
+
// Sketches are document data (geometry + constraints), so editing one is
|
|
3624
|
+
// a document edit: same rollback rule as a feature edit, and the sketch
|
|
3625
|
+
// rides into the BREP cache hash so geometry actually changes.
|
|
3626
|
+
const raw = args.sketch && typeof args.sketch === 'object' ? args.sketch : {}
|
|
3627
|
+
const name = String(raw.name ?? '')
|
|
3628
|
+
if (!name) throw new Error('sketch 需要 name(要改的草图名)')
|
|
3629
|
+
const beforeSketches = JSON.parse(JSON.stringify(doc.sketches ?? {}))
|
|
3630
|
+
const beforeStats = doc.stats ? JSON.parse(JSON.stringify(doc.stats)) : null
|
|
3631
|
+
doc.sketches = normalizeSketches({ [name]: raw.remove ? null : (raw.def ?? raw) }, doc.sketches ?? {})
|
|
3632
|
+
let result
|
|
3633
|
+
try {
|
|
3634
|
+
result = await rebuild(doc, dir, { note: `sketch ${name} ${raw.remove ? 'remove' : 'edit'}` })
|
|
3635
|
+
} catch (error) {
|
|
3636
|
+
doc.sketches = beforeSketches
|
|
3637
|
+
doc.stats = beforeStats
|
|
3638
|
+
await writeModel(doc, dir)
|
|
3639
|
+
return { ok: false, evaluated: false, model: doc.name, action, error: String(error?.message ?? error), sketches: doc.sketches }
|
|
3640
|
+
}
|
|
3641
|
+
doc.history = Array.isArray(doc.history) ? doc.history : []
|
|
3642
|
+
doc.history.push({ at: new Date().toISOString(), note: `sketch ${name}`, params: null, run: result.ok !== false })
|
|
3643
|
+
doc.history = doc.history.slice(-20)
|
|
3644
|
+
await writeModel(doc, dir)
|
|
3645
|
+
return {
|
|
3646
|
+
ok: true,
|
|
3647
|
+
evaluated: result.ok !== false && (result.errors ?? []).length === 0,
|
|
3648
|
+
model: doc.name,
|
|
3649
|
+
kind: doc.kind,
|
|
3650
|
+
action,
|
|
3651
|
+
// A whole-emitter failure has no per-node error, only this message.
|
|
3652
|
+
error: result.ok === false ? String(result.error ?? 'rebuild failed') : '',
|
|
3653
|
+
features: publicFeatures(doc),
|
|
3654
|
+
sketches: doc.sketches ?? {},
|
|
3655
|
+
graph: result.graph,
|
|
3656
|
+
errors: result.errors ?? [],
|
|
3657
|
+
undo: doc.undo.length,
|
|
3658
|
+
redo: doc.redo.length,
|
|
3659
|
+
volume: doc.stats?.volume ?? null,
|
|
3660
|
+
triangles: doc.stats?.triangles ?? null,
|
|
3661
|
+
sceneId: doc.stats?.sceneId ?? '',
|
|
3662
|
+
run: doc.run,
|
|
3663
|
+
cached: result.cached ?? 0,
|
|
3664
|
+
computed: result.computed ?? null,
|
|
3665
|
+
revalidated: result.revalidated === true,
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3510
3669
|
const snapshot = () => JSON.parse(JSON.stringify({ features: doc.features, tip: doc.tip ?? null }))
|
|
3511
3670
|
const restore = (snap) => {
|
|
3512
3671
|
doc.features = JSON.parse(JSON.stringify(snap.features))
|
|
@@ -3607,6 +3766,7 @@ if _TARGET:
|
|
|
3607
3766
|
kind: doc.kind,
|
|
3608
3767
|
action,
|
|
3609
3768
|
features: publicFeatures(doc),
|
|
3769
|
+
sketches: doc.sketches ?? {},
|
|
3610
3770
|
graph: result.graph,
|
|
3611
3771
|
errors: result.errors ?? [],
|
|
3612
3772
|
undo: doc.undo.length,
|
|
@@ -3624,12 +3784,18 @@ if _TARGET:
|
|
|
3624
3784
|
|
|
3625
3785
|
tool({
|
|
3626
3786
|
name: 'cad_studio_features',
|
|
3627
|
-
description: `Edit a feature-list model one feature at a time (the "边画边改" path): change one feature's parameters and the whole list is re-derived in ~0.2–0.6 s. Actions: list / add / update / remove / move / toggle (alias suppress) / tip / undo / redo. Feature kinds: ${FEATURE_KINDS.join(', ')}. A feature is {kind, label?, params} — params hold that kind's fields (box: size:[dx,dy,dz], at?; cylinder: r,h,at?,axis?; cut/fuse/common: with:<primitive>; fillet: r; chamfer: d; shell: t,open?; pattern_linear: delta,count; rotate: axis?,at?,deg; mirror: normal?,at?). Flat form ({kind:'box', size:[…]}) is accepted too.`,
|
|
3787
|
+
description: `Edit a feature-list model one feature at a time (the "边画边改" path): change one feature's parameters and the whole list is re-derived in ~0.2–0.6 s. Actions: list / add / update / remove / move / toggle (alias suppress) / tip / undo / redo / sketch (edit one document sketch and rebuild). Feature kinds: ${FEATURE_KINDS.join(', ')}. A feature is {kind, label?, params} — params hold that kind's fields (box: size:[dx,dy,dz], at?; cylinder: r,h,at?,axis?; cut/fuse/common: with:<primitive>; fillet: r; chamfer: d; shell: t,open?; pattern_linear: delta,count; rotate: axis?,at?,deg; mirror: normal?,at?). Flat form ({kind:'box', size:[…]}) is accepted too.`,
|
|
3628
3788
|
parameters: {
|
|
3629
3789
|
type: 'object',
|
|
3630
3790
|
properties: {
|
|
3631
3791
|
model: { type: 'string', description: 'Feature-list model name (created with cad_studio_doc kind="features").' },
|
|
3632
|
-
action: { type: 'string', enum: ['list', 'add', 'update', 'remove', 'move', 'toggle', 'suppress', 'tip', 'undo', 'redo'] },
|
|
3792
|
+
action: { type: 'string', enum: ['list', 'add', 'update', 'remove', 'move', 'toggle', 'suppress', 'tip', 'undo', 'redo', 'sketch'] },
|
|
3793
|
+
sketch: {
|
|
3794
|
+
type: 'object',
|
|
3795
|
+
description: 'With action:"sketch": {name, def:{geometry:[…],constraints:[…]}} replaces one sketch, {name, remove:true} deletes it. The document is rebuilt immediately; a constraint the solver cannot meet rolls the sketch back.',
|
|
3796
|
+
properties: { name: { type: 'string' }, remove: { type: 'boolean' }, def: { type: 'object' } },
|
|
3797
|
+
required: ['name'],
|
|
3798
|
+
},
|
|
3633
3799
|
feature: { type: 'object', description: 'add: the feature to append. update/toggle: {id, ...fields to change}. remove/move: {id}.' },
|
|
3634
3800
|
id: { type: 'string', description: 'Feature id (f1, f2 …); alternative to feature.id.' },
|
|
3635
3801
|
to: { type: 'integer', description: 'move: target index (0-based). Default: to the end.' },
|
|
@@ -3825,6 +3991,9 @@ __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scen
|
|
|
3825
3991
|
bridge.journal({
|
|
3826
3992
|
kind: 'doc',
|
|
3827
3993
|
label: `delete ${key}`,
|
|
3994
|
+
// The bytes live in journal.json so "undo delete" still works after a
|
|
3995
|
+
// restart; models are small JSON documents.
|
|
3996
|
+
record: { op: 'doc-delete', model: key, dir, b64: bytes.toString('base64') },
|
|
3828
3997
|
undo: async () => {
|
|
3829
3998
|
await writeFile(file, bytes)
|
|
3830
3999
|
const doc = await readModel(key, dir)
|
|
@@ -3870,6 +4039,7 @@ __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scen
|
|
|
3870
4039
|
bridge.journal({
|
|
3871
4040
|
kind: 'doc',
|
|
3872
4041
|
label: `rename ${key} → ${to}`,
|
|
4042
|
+
record: { op: 'doc-rename', dir, from: key, to },
|
|
3873
4043
|
undo: async () => {
|
|
3874
4044
|
const back = await readModel(to, dir)
|
|
3875
4045
|
back.name = key
|