dsh-cad-studio 0.2.4 → 0.2.6

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/client.js +48 -15
  2. package/index.js +22 -8
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -146,6 +146,8 @@ window.__ModuleLoader__.load({
146
146
  propLabel: { fontSize: 10.5, opacity: 0.62, flex: 'none', width: 34 },
147
147
  propValue: { marginLeft: 'auto', fontSize: 10, opacity: 0.75, fontVariantNumeric: 'tabular-nums', flex: 'none' },
148
148
  slider: { flex: '1 1 auto', minWidth: 0, height: 14, accentColor: '#4d6bfe', cursor: 'pointer' },
149
+ jointNum: { width: 52, flex: '0 0 auto', padding: '1px 3px', fontSize: 10.5, textAlign: 'right', color: 'inherit', background: 'rgba(125,135,155,0.12)', border: '1px solid transparent', borderRadius: 4, outline: 'none', fontVariantNumeric: 'tabular-nums' },
150
+ sliderRow: { display: 'flex', alignItems: 'center', gap: 6, padding: '0 8px 5px 8px' },
149
151
  propBtn: { font: 'inherit', fontSize: 10.5, padding: '3px 8px', borderRadius: 5, border: '1px solid', background: 'transparent', color: 'inherit', cursor: 'pointer', whiteSpace: 'nowrap' },
150
152
  propBtns: { display: 'flex', flexWrap: 'wrap', gap: 5, padding: '6px 2px 2px' },
151
153
  propEmpty: { padding: '10px 6px', fontSize: 10.5, opacity: 0.6, lineHeight: 1.7 },
@@ -1640,21 +1642,52 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1640
1642
  ...(assembly.joints || []).map((joint) => {
1641
1643
  const value = motionDraft[joint.id] !== undefined ? motionDraft[joint.id] : joint.value
1642
1644
  const unit = joint.type === 'linear' ? ' mm' : '°'
1643
- return h('div', { key: joint.id, style: styles.propRow, 'data-cad-joint': joint.id }, [
1644
- h('span', { key: 'l', style: jointLabel, title: `${joint.id} · ${joint.instance}` }, joint.instance),
1645
- h('span', { key: 'v', style: styles.propValue, 'data-cad-joint-value': joint.id }, `${Math.round(value * 10) / 10}${unit}`),
1646
- h('input', {
1647
- key: 's',
1648
- type: 'range',
1649
- style: styles.slider,
1650
- 'data-cad-joint-slider': joint.id,
1651
- min: joint.min,
1652
- max: joint.max,
1653
- step: 1,
1654
- value,
1655
- title: `${joint.id}(${joint.type === 'linear' ? '滑动 mm' : '旋转 °'})`,
1656
- onInput: (event) => driveJoint(joint.id, Number(event.target.value)),
1657
- }),
1645
+ const clamp = (raw) => Math.max(joint.min, Math.min(joint.max, Math.round(raw)))
1646
+ return h('div', { key: joint.id, 'data-cad-joint': joint.id }, [
1647
+ h('div', { key: 'r', style: styles.propRow }, [
1648
+ h('span', { key: 'l', style: jointLabel, title: `${joint.id} · ${joint.instance}` }, joint.instance),
1649
+ h('span', { key: 'v', style: styles.propValue, 'data-cad-joint-value': joint.id }, `${Math.round(value * 10) / 10}${unit}`),
1650
+ // Typing beats dragging for exact values: 180° across this narrow
1651
+ // slider makes a hand-hit 0° almost impossible.
1652
+ h('input', {
1653
+ key: 'n',
1654
+ type: 'number',
1655
+ style: styles.jointNum,
1656
+ 'data-cad-joint-input': joint.id,
1657
+ min: joint.min,
1658
+ max: joint.max,
1659
+ step: 1,
1660
+ value: String(Math.round(value * 10) / 10),
1661
+ title: '输入数值后回车',
1662
+ onChange: (event) => {
1663
+ const next = Number(event.target.value)
1664
+ if (Number.isFinite(next)) driveJoint(joint.id, clamp(next))
1665
+ },
1666
+ onKeyDown: (event) => { if (event.key === 'Enter') event.currentTarget.blur() },
1667
+ }),
1668
+ h('button', {
1669
+ key: 'z',
1670
+ type: 'button',
1671
+ style: styles.microBtn,
1672
+ 'data-cad-joint-zero': joint.id,
1673
+ title: `把 ${joint.id} 设回 0`,
1674
+ onClick: () => driveJoint(joint.id, 0),
1675
+ }, '归零'),
1676
+ ]),
1677
+ h('div', { key: 's', style: styles.sliderRow }, [
1678
+ h('input', {
1679
+ key: 'sl',
1680
+ type: 'range',
1681
+ style: styles.slider,
1682
+ 'data-cad-joint-slider': joint.id,
1683
+ min: joint.min,
1684
+ max: joint.max,
1685
+ step: 1,
1686
+ value,
1687
+ title: `${joint.id}(${joint.type === 'linear' ? '滑动 mm' : '旋转 °'})`,
1688
+ onInput: (event) => driveJoint(joint.id, Number(event.target.value)),
1689
+ }),
1690
+ ]),
1658
1691
  ])
1659
1692
  }),
1660
1693
  h('div', { key: 'eh', style: styles.treeHint }, '爆炸图'),
package/index.js CHANGED
@@ -444,6 +444,18 @@ class FreeCadBridge {
444
444
  if (Array.isArray(pointer.modelsDirs)) this.modelsSeen = [...new Set([...this.modelsSeen, ...pointer.modelsDirs.filter((d) => typeof d === 'string' && d)])].slice(0, 12)
445
445
  if (!this.lastSession && typeof pointer.lastSession === 'string') this.lastSession = pointer.lastSession
446
446
  const disk = Array.isArray(pointer.history) ? pointer.history : []
447
+ const asmTitles = new Map()
448
+ for (const a of Array.isArray(pointer.assemblies) ? pointer.assemblies : []) {
449
+ if (a && typeof a.id === 'string' && typeof a.title === 'string') asmTitles.set(`asm:${a.id}`, a.title)
450
+ }
451
+ // Earlier builds appended the joint value / explode factor to the model
452
+ // name (`运动演示 · hinge 60`). Rewrite those rows to the plain title.
453
+ const SUFFIX = /\s·\s(?:合拢|爆炸\s-?\d+(?:\.\d+)?|[A-Za-z_][\w-]*\s-?\d+(?:\.\d+)?)$/
454
+ for (const row of [...this.history, ...disk]) {
455
+ if (!row || typeof row.title !== 'string') continue
456
+ const base = typeof row.docKey === 'string' && asmTitles.has(row.docKey) ? asmTitles.get(row.docKey) : row.title.replace(SUFFIX, '')
457
+ row.title = base
458
+ }
447
459
  const seen = new Set(this.history.map((h) => h.id))
448
460
  const merged = [...this.history, ...disk.filter((h) => !seen.has(h.id))]
449
461
  merged.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')))
@@ -573,9 +585,11 @@ class FreeCadBridge {
573
585
  }
574
586
 
575
587
  /** Recompute instance placements from base + joints + explode, then publish. */
576
- async republishAssembly(record, titleSuffix) {
588
+ async republishAssembly(record) {
577
589
  const scene = assembleScene(record)
578
- const title = titleSuffix ? `${record.title} · ${titleSuffix}` : record.title
590
+ // The title is the model's name, never its state: dragging a joint or
591
+ // changing the explode factor must not rename the model.
592
+ const title = record.title
579
593
  // In place: the assembly owns one scene id and one row in the models list.
580
594
  const published = await this.publishScene(scene, title, this.currentSession ?? '', {
581
595
  docKey: `asm:${record.id}`,
@@ -1550,7 +1564,7 @@ if _TARGET:
1550
1564
  const before = record.joints.length
1551
1565
  record.joints = record.joints.filter((j) => j.id !== joint)
1552
1566
  if (record.joints.length === before) return { ok: false, error: `没有这个关节:${joint ?? '(未指定)'}` }
1553
- const published = await bridge.republishAssembly(record, '')
1567
+ const published = await bridge.republishAssembly(record)
1554
1568
  return { ok: true, assembly: record.id, removed: joint, sceneId: published.id, joints: record.joints.length }
1555
1569
  }
1556
1570
  let stored
@@ -1559,7 +1573,7 @@ if _TARGET:
1559
1573
  } catch (error) {
1560
1574
  return { ok: false, error: String(error?.message ?? error) }
1561
1575
  }
1562
- const published = await bridge.republishAssembly(record, `${stored.id} ${round6(stored.value)}`)
1576
+ const published = await bridge.republishAssembly(record)
1563
1577
  return {
1564
1578
  ok: true,
1565
1579
  assembly: record.id,
@@ -1598,7 +1612,7 @@ if _TARGET:
1598
1612
  const id = joint ?? record.joints[0].id
1599
1613
  const moved = bridge.driveJoint(record, id, value)
1600
1614
  if (!moved) return { ok: false, error: `没有这个关节:${id}(现有 ${record.joints.map((j) => j.id).join(', ')})` }
1601
- const published = await bridge.republishAssembly(record, `${id} ${round6(moved.value)}`)
1615
+ const published = await bridge.republishAssembly(record)
1602
1616
  return {
1603
1617
  ok: true,
1604
1618
  assembly: record.id,
@@ -1636,7 +1650,7 @@ if _TARGET:
1636
1650
  }
1637
1651
  const next = bridge.setExplode(record, factor ?? 1)
1638
1652
  if (next === null) return { ok: false, error: 'factor 必须是数字' }
1639
- const published = await bridge.republishAssembly(record, next ? `爆炸 ${round6(next)}` : '合拢')
1653
+ const published = await bridge.republishAssembly(record)
1640
1654
  return { ok: true, assembly: record.id, sceneId: published.id, explode: round6(next), instances: published.stats.instances }
1641
1655
  },
1642
1656
  })
@@ -2207,12 +2221,12 @@ if _TARGET:
2207
2221
  const jointId = typeof body?.joint === 'string' ? body.joint : record.joints[0]?.id
2208
2222
  const moved = live.driveJoint(record, jointId, body?.value)
2209
2223
  if (!moved) return send(400, JSON.stringify({ error: 'bad joint or value' }))
2210
- const published = await live.republishAssembly(record, `${moved.id} ${round6(moved.value)}`)
2224
+ const published = await live.republishAssembly(record)
2211
2225
  return send(200, JSON.stringify({ ok: true, sceneId: published.id, at: published.stats.at, joint: moved.id, value: round6(moved.value) }))
2212
2226
  }
2213
2227
  const next = live.setExplode(record, body?.factor ?? 1)
2214
2228
  if (next === null) return send(400, JSON.stringify({ error: 'bad factor' }))
2215
- const published = await live.republishAssembly(record, next ? `爆炸 ${round6(next)}` : '合拢')
2229
+ const published = await live.republishAssembly(record)
2216
2230
  return send(200, JSON.stringify({ ok: true, sceneId: published.id, at: published.stats.at, explode: round6(next) }))
2217
2231
  }
2218
2232
  if (url.pathname.startsWith(`${ROUTE_PREFIX}/scene/`)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {