@huaqiu/dsh-tool-pcb-viewer 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 深圳华秋智联股份有限公司
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @huaqiu/dsh-tool-pcb-viewer
2
+
3
+ KiCad `.kicad_pcb` → 会话内嵌的 **2D 走线视图 + 3D 板卡渲染** DSH 插件。
4
+
5
+ 在 DSH 会话里给出板子路径,模型调用 `pcb_preview` 工具:
6
+
7
+ 1. **工具调用瞬间** → 官方即时信息卡(标题 + 参数行:`180×100mm · 10 层 · 1125 器件 · 22151 走线`)
8
+ 2. **该回合结束** → 回合末尾推送可交互卡片:实时 **3D 缩略图** + 文件名 + 参数 + 三个按钮
9
+ - 「显示 PCB」→ 右侧大屏只看 2D 走线视图(可拖拽平移 · 滚轮缩放)
10
+ - 「显示 3D」→ 只看 3D 渲染(可轨道旋转 · 滑杆拆解 · AUTO DEMO)
11
+ - 「浏览器打开」→ 新标签页整页(左板子 + 右 3D,可分享)
12
+ 3. 大板(>8MB)走**预加载 + 轻渲染**:卡片出现即后台拉数据,缩略图先出无纹理轻量 3D,
13
+ 点开详情时解析结果已缓存
14
+
15
+ ## 解析引擎
16
+
17
+ `src/parse.ts` 是唯一解析入口,两条引擎产出同一个 `BoardModel`:
18
+
19
+ | 引擎 | 位置 | 说明 |
20
+ |---|---|---|
21
+ | **自带(默认)** | `src/pcb/parseKicad.ts` | 随板子规模保持线性;多 MB 大板上有明显优势 |
22
+ | 备选 | `src/adapter.ts` + `@huaqiu/kicad-sexpr-parser` | 保留可用、测试常跑;适合板子规模较大时不一定适用,实测大板上明显更慢 |
23
+
24
+ 选择理由:本插件要应对十 MB 级真实板,解析必须随规模近似线性。
25
+ `test/parity.test.ts` 用 7 个 fixture 把两条路钉在**同一个模型**上(逐字段严格相等,含拼接外框环),
26
+ 所以这个选择是**可逆的**——需要时改 `src/parse.ts` 一行即可切换。
27
+
28
+ ## 性能要点
29
+
30
+ | 项 | 做法 |
31
+ |---|---|
32
+ | 器件几何 | 按尺寸自适应细分(<1.5mm 直角盒 / <4mm 1 段圆角 / 其余 3 段):Jetson 512 万顶点 → **54.6 万** |
33
+ | 画质档位 | `high / medium / low`(SSAO/Bloom/DOF 逐 pass 开关 + 像素比),按器件数自动选;HUD 实时 FPS 芯片可点击循环切档 |
34
+ | 2D 视图 | 走线/铜皮/焊盘/过孔批量成 `Path2D`;整板渲染进**离屏缓存**,平移只做一次 `drawImage`(10 步平移 1ms) |
35
+ | 内层纹理 | 内层夹在叠层里几乎不可见 → **半分辨率**(像素 1/4) |
36
+ | 解析缓存 | 卡片缩略图 ↔ 大屏面板 ↔ 2D/3D 切换**共享一次解析** |
37
+ | 缩略图 | `hud:false / post:false / interactive:false` 轻量路径,只建几何 |
38
+
39
+ ## 安装与开发
40
+
41
+ ```bash
42
+ pnpm install
43
+ pnpm build # tsdown → lib/index.mjs(host)+ lib/client.js + lib/standalone.js
44
+ pnpm test # vitest:adapter 对齐 + 双引擎 parity(38 例)
45
+ pnpm typecheck # strict tsc
46
+ ```
47
+
48
+ 登记进 DSH profile(`~/.dsh/profiles/<name>/package.json`):依赖加
49
+ `"@huaqiu/dsh-tool-pcb-viewer": "link:<本包绝对路径>"`,`dsh.profile.bundles` 加包名,
50
+ 然后 `pnpm install` → **重启 DSH** → 刷新浏览器。
51
+
52
+ ## 架构
53
+
54
+ ```
55
+ src/
56
+ ├── model.ts # 扁平板模型(BoardModel)——全包契约
57
+ ├── parse.ts # 唯一解析入口(默认自带 parser,一行可切上游)
58
+ ├── adapter.ts # 上游 parser(I_KicadPCB)→ BoardModel
59
+ ├── viewer.ts # createViewer():split/2d/3d + 画质档位 + FPS HUD + 轻量模式
60
+ ├── index.ts # host:pcb_preview 工具 + /pcb-viewer/* 路由 + 即时卡片
61
+ ├── pcb/ # parseKicad(线性解析)+ outline(板框缝合 + 绕向归一化)
62
+ ├── scene/ # 纹理 / 器件模板库 / 叠层组装 / 2D 视图
63
+ └── client/ # 会话卡片 + 单例大屏面板 + 独立整页
64
+ ```
65
+
66
+ 审计与后续文档:`AUDIT.md`(任务单)→ `AUDIT-FINDINGS.md`(发现)→ `AUDIT-RESPONSE.md`(修复响应)
67
+ → `AUDIT-VERIFICATION.md`(独立复核 14/14 属实)→ `FOLLOWUPS.md`(遗留)→ `MILESTONE.md`(阶段范围与验收)。
@@ -0,0 +1,4 @@
1
+ # @huaqiu/dsh-tool-pcb-viewer 的 bundle 补丁:把插件条目插入 loader 树,host 半边由此加载。
2
+ - insert:
3
+ - id: dsh-tool-pcb-viewer
4
+ name: '@huaqiu/dsh-tool-pcb-viewer'