From cd88a9950a2030168e7331896cda08deab620272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Sun, 11 Oct 2026 00:37:45 +0800 Subject: [PATCH] fix: persist native menus and validate every tool workflow --- ...0-persistent-menu-and-native-validation.md | 30 ++ docs/testing/dxdesigner-795-live.md | 2 +- docs/testing/native-acceptance-20261010.md | 68 +++ docs/testing/native-acceptance.md | 2 + docs/user/PDF_export.md | 6 +- docs/user/一叶知秋_重构版_更新说明.md | 9 +- .../dxdesigner795/CompatibilityProbe.vbs | 10 +- integration/dxdesigner795/MenuAdd.vbs | 58 ++- integration/dxdesigner795/core/BomExport.vbs | 33 +- integration/dxdesigner795/core/Mailbox.vbs | 36 +- integration/dxdesigner795/core/Snapshot.vbs | 107 ++++- .../dxdesigner795/core/Transaction.vbs | 32 +- .../expedition/ExpeditionBridge.vbs | 190 +++++++- packaging/DxDesignerTools.spec | 4 +- src/dx_productivity/bridge/launcher.py | 5 + src/dx_productivity/bridge/protocol.py | 4 + src/dx_productivity/bridge/run_store.py | 18 +- src/dx_productivity/bridge/startup.py | 27 +- src/dx_productivity/domain/models.py | 1 + src/dx_productivity/domain/restore.py | 96 ++-- src/dx_productivity/domain/schedule.py | 4 +- src/dx_productivity/features/bom/planner.py | 5 +- .../features/pdf_export/cli.py | 2 + .../features/pdf_export/exporter.py | 141 +++++- .../features/pdf_export/listener.py | 44 +- .../features/pdf_export/native_listener.py | 289 ++++++++++++ src/dx_productivity/ui/app.py | 34 +- src/dx_productivity/ui/bom_controller.py | 29 +- src/dx_productivity/ui/history_controller.py | 12 +- src/dx_productivity/ui/history_page.py | 7 +- .../ui/inspection_controller.py | 18 + src/dx_productivity/ui/inspection_page.py | 36 +- .../ui/pdf_export_controller.py | 14 +- src/dx_productivity/ui/pdf_export_page.py | 11 +- .../ui/property_change_controller.py | 27 +- .../ui/property_change_page.py | 4 +- .../ui/property_visibility_controller.py | 5 +- .../ui/property_visibility_page.py | 4 +- src/dx_productivity/ui/refdes_controller.py | 4 +- src/dx_productivity/ui/settings_controller.py | 7 + src/dx_productivity/ui/settings_page.py | 2 + src/dx_productivity/update/installer.py | 57 ++- tests/bridge/test_run_store.py | 23 + tests/bridge/test_startup.py | 30 +- tests/domain/test_operation_restore.py | 123 +++++ tests/features/test_bom_export_vbs.py | 28 ++ tests/features/test_bom_planner.py | 74 ++- tests/features/test_expedition_bridge_vbs.py | 31 ++ tests/features/test_pdf_export.py | 235 ++++++++++ tests/features/test_pdf_export_settings.py | 54 +++ tests/features/test_pdf_save_listener.py | 64 +++ tests/integration/test_compatibility_probe.py | 16 + tests/integration/test_vbs_bridge.py | 6 +- tests/packaging/test_built_release.py | 37 +- tests/ui/test_bom_controller.py | 138 ++++++ tests/ui/test_history_controller.py | 77 +++ tests/ui/test_history_page.py | 13 + tests/ui/test_inspection_controller.py | 133 ++++++ tests/ui/test_pdf_export_page.py | 44 ++ tests/ui/test_property_controllers.py | 230 +++++++++ tests/ui/test_refdes_controller.py | 19 + tests/ui/test_settings_controller.py | 32 ++ tests/ui/test_settings_page.py | 39 ++ tests/ui/test_snapshot_refresh.py | 40 ++ tests/ui/test_update_launch.py | 111 +++++ tests/update/test_installer.py | 58 +++ tests/vbs/test_bom_export.vbs | 160 +++++++ tests/vbs/test_expedition_bridge.vbs | 244 ++++++++++ tests/vbs/test_refdes_bridge.vbs | 5 + tests/vbs/test_refdes_export.vbs | 47 +- tools/acceptance/frozen_pdf.py | 115 +++++ tools/acceptance/native_features.py | 443 ++++++++++++++++++ tools/acceptance/packaged_menu.py | 167 +++++++ tools/acceptance/packaged_update.py | 88 ++++ tools/acceptance/probe_native_attributes.vbs | 45 ++ tools/acceptance/run_dx_script.py | 50 ++ 76 files changed, 4249 insertions(+), 264 deletions(-) create mode 100644 docs/superpowers/plans/2026-10-10-persistent-menu-and-native-validation.md create mode 100644 docs/testing/native-acceptance-20261010.md create mode 100644 src/dx_productivity/features/pdf_export/native_listener.py create mode 100644 tests/domain/test_operation_restore.py create mode 100644 tests/features/test_bom_export_vbs.py create mode 100644 tests/features/test_expedition_bridge_vbs.py create mode 100644 tests/features/test_pdf_export.py create mode 100644 tests/features/test_pdf_export_settings.py create mode 100644 tests/features/test_pdf_save_listener.py create mode 100644 tests/ui/test_bom_controller.py create mode 100644 tests/ui/test_inspection_controller.py create mode 100644 tests/ui/test_pdf_export_page.py create mode 100644 tests/ui/test_property_controllers.py create mode 100644 tests/ui/test_snapshot_refresh.py create mode 100644 tests/ui/test_update_launch.py create mode 100644 tests/vbs/test_bom_export.vbs create mode 100644 tests/vbs/test_expedition_bridge.vbs create mode 100644 tools/acceptance/frozen_pdf.py create mode 100644 tools/acceptance/native_features.py create mode 100644 tools/acceptance/packaged_menu.py create mode 100644 tools/acceptance/packaged_update.py create mode 100644 tools/acceptance/probe_native_attributes.vbs create mode 100644 tools/acceptance/run_dx_script.py diff --git a/docs/superpowers/plans/2026-10-10-persistent-menu-and-native-validation.md b/docs/superpowers/plans/2026-10-10-persistent-menu-and-native-validation.md new file mode 100644 index 0000000..56ec885 --- /dev/null +++ b/docs/superpowers/plans/2026-10-10-persistent-menu-and-native-validation.md @@ -0,0 +1,30 @@ +# 菜单持久化与逐项实机验证 + +> For agentic workers: execute independent validation domains with dispatching-parallel-agents; keep all live DxDesigner operations on the root agent. + +**Goal:** Start 注册后,普通启动、切换工程及重启仍保留菜单;每个工具功能都有明确验证结果和证据。 + +**Architecture:** 在实际 WDIR 的 scripts.ini 中备份后幂等注册用户目录下的生成菜单,保留其他脚本。宿主事件负责工程切换后的菜单刷新。工程数据操作与 PDF 出图仅在复制的验收工程上执行;源工程保持原状。 + +**Tech stack:** Python 3.12、PySide6、32 位 WSH、DxDesigner/Expedition 7.9.5、Excel COM。 + +**Spec:** 用户 2026-10-10 明确要求“Start 持久化,一直都在菜单,每个功能都测试”;范围见 docs/testing/native-acceptance.md。 + +## Constraints + +- 不操作用户原工程的图纸或关闭未保存文档;使用独立实例和验收副本。 +- 不改用户/系统环境变量;修改实际启动配置时先备份,保留公司条目及原编码。 +- 只有实际 native 输出和读回证据支持实机通过;自动化模拟结果单独记录。 +- 单个 DxDesigner 实例由 root 协调,PDF 独立副本及 Excel/PCB 测试分别执行。 + +## Tasks + +- [x] 复现 scripts.ini 缺少工具条目;新增测试要求普通 WDIR 配置持久含一个入口、重复 Start 幂等且保留原脚本。 +- [x] 修改 src/dx_productivity/bridge/startup.py:备份并写入实际配置,记录注册位置;修改 integration/dxdesigner795/MenuAdd.vbs:订阅 ProjectChanged/AfterDocumentOpened 并幂等恢复菜单。 +- [x] 用普通环境启动独立 Dx 实例,确认 Start Page 与工程页菜单存在;关闭验收实例后重新启动、切换副本工程,重新读取菜单计数。 +- [x] 修复实机快照中命名页号、坐标、网络等 API 差异;tests/integration 回归覆盖实际 VBS 方法签名。 +- [x] 在验收副本完成自动位号预览/应用/第二次应用/历史恢复、属性修改/隐藏/显示/恢复、设计检查与定位,读回原生对象验证结果。 +- [x] PDF 三种范围和保存事件在独立副本验证;BOM Excel 模板及 PCB 装配整理逐项记录。 +- [ ] 推送当前分支(构建、395 项源码测试、16 项便携包测试和最终菜单/冻结监听器/更新安装已完成)。 + +结果与边界:`docs/testing/native-acceptance-20261010.md`。额外修复发布 ZIP 目录兼容、Windows 更新程序自锁、持续重启与计划文件竞争,实际便携包更新及回滚通过。 diff --git a/docs/testing/dxdesigner-795-live.md b/docs/testing/dxdesigner-795-live.md index 074cc9a..751d0fd 100644 --- a/docs/testing/dxdesigner-795-live.md +++ b/docs/testing/dxdesigner-795-live.md @@ -1,6 +1,6 @@ # DxDesigner 7.9.5 现场验收记录 -> 发布状态:Start 注册菜单、菜单启动工具及工程快照刷新已在 DxDesigner 7.9.5 实机核对;写回、PDF 出图及保存事件验收待完成。 +> 当前验收:2026-10-10 至 2026-10-11 已完成持久菜单、原生写回与恢复、定位、BOM、PCB、PDF 范围及自动导出的副本测试,详见 [逐项验收报告](native-acceptance-20261010.md)。下文保留早期记录与扩展验收模板,不代表本轮仍未验证。 ## 1. 测试信息 diff --git a/docs/testing/native-acceptance-20261010.md b/docs/testing/native-acceptance-20261010.md new file mode 100644 index 0000000..8edb2d2 --- /dev/null +++ b/docs/testing/native-acceptance-20261010.md @@ -0,0 +1,68 @@ +# 持久菜单与全工具验收(2026-10-10—11) + +本轮针对 Start 不持久、菜单无法打开、工程未桥接和“每个功能都测试”的反馈完成修复与验收。设计写回、PDF 和 PCB 测试均在独立工程副本上执行,用户原 DxDesigner 实例未关闭、未写回。 + +## 环境与证据 + +- Windows 11 x64,Python 3.12,DxDesigner / Expedition Enterprise 7.9.5。 +- 位号与属性副本:`%LOCALAPPDATA%\DxProductivity\acceptance\native-20261010\1GPHY_RTL8211F`,114 个器件、56 个命名网络,活动页 `GE_PHY_8211`。 +- 菜单与自动 PDF 副本:同目录下 `switch-audio\Audio_D2128_SURGE_ESD.prj`。 +- PDF 多页工程副本:`%LOCALAPPDATA%\DxProductivity\acceptance\pdf-scopes-20261010`。 +- BOM / PCB 原生证据:`%TEMP%\dx-native-bom-pcb-20261010`。 +- 源码全套:`395 passed`,便携包测试:`16 passed`;JUnit 位于 `build/test-evidence/full-source.xml` 和 `packaged.xml`。 + +## 逐项结果 + +| 功能 | 实际验证 | 结果与边界 | +|---|---|---| +| Start 持久注册 | 写入平时 WDIR 的启动配置;普通启动、打开工程、关闭验收实例后重新普通启动;重复注册读取两栏菜单 | Main / Sheet Menu Bar 各一个菜单、每菜单八个动作。中文宿主需 `脚本#n`,兼容英文 `Script#n`;保留原条目并备份 | +| 工程桥接与刷新 | 宿主快照枚举、真实路径、命名图页、坐标、属性与网络;多次刷新 | 114 个器件与 56 个网络;桥接标识及活动页正确 | +| 自动位号 | CE17 / LE03 改为 C7000 / L7000,再次应用 8000;CE17 / CE18 交换;分别恢复 | 原生读回一致,循环位号无临时值残留;114 个器件身份、位置和未涉及属性核对 | +| 属性批改 | Value、Value1、Part Number 写回,空值清理、缺失属性跳过及历史恢复 | 原生读回及备份值一致。Value1 夹具仅在副本新增 | +| 属性显示 | PartName / PartLabel 显示、隐藏及对应恢复,共八次事务 | 原生可见性读回一致,恢复不依赖旧位号 | +| 设计检查 / 网络工具 | 空 Value / Value1 查找,56 个真实网络列表、孤立与跨页计算;清除目标选择后执行器件和 GND 定位 | 器件独占选择 CE17,GND 被真实选中;多页网络计算由离线夹具覆盖,原生定位工程为单页 | +| 历史 / 预检 / 回滚 | 位号、属性与可见性恢复;旧快照、错误工程、篡改摘要、实际外部修改;第二步赋值失败 | 不一致事务均在写入前拒绝;实际失败回滚状态 `rolled-back`、`failing_sequence=2`、`rollback_state=verified` | +| BOM | 真实 Dx 114 器件生成 15 行 BOM;独立 Excel 输出 XLSX/XLS、重新打开逐格与颜色核对 | 合并、NC 和 MARK 等过滤、重复红色及创维料号橙色标记通过;Excel 格式分别为 51(XLSX)与 56(XLS),重复色号 3、料号色号 44 | +| Expedition PCB | 真实许可证、原生文字导出、104 项计划写回、参数读回和 Edit → Undo;对照旧脚本真实运行结果 | 88 项位置移动、5 项仅格式修改、11 项删除;79 项未计划文字不变;一次撤销 172 → 183 恢复完整,锁计数 0;93 个位号的几何/格式对照一致,数值舍入差小于 0.00005 | +| PCB 菜单 | 独立导入脚本、从 Start 记录解析实际工具根目录、重复安装 | 修复宿主无脚本路径元数据和菜单接口;菜单幂等,回调验收见原生报告 | +| PDF 整工程 | PON 多页工程原生 sch2pdf 输出 | 24 页 | +| PDF 当前页 | PON / `03_FLASH` 精确书签筛页,与整工程第 10 页比较 | 1 页,文本与渲染像素一致;书签不存在或重复时拒绝发布,不覆盖旧 PDF | +| PDF 指定 Block | PON 与 DCDC_T56220_C 两个范围 | 分别 17 页(含层次子页)和 1 页 | +| 自动 PDF | 按工程路径绑定独立实例;原生属性变更,稳定后导出;恢复再导出;关闭后再次变更 | 开启时 PDF 正文含 `IC/D2128_PDF_NATIVE_ON`;恢复后标记消失;关闭后次数保持 2、PDF 哈希不变。EE iCDB 使用原生变更事件,保留传统保存完成事件 | +| 设置 / 更新 | 版本检查、持久设置、每日检查、签名/摘要/协议保护;发布 ZIP 目录、外部更新运行目录与实际跨进程互斥 | 最终 exe 在中文临时目录完成等待旧窗口退出、安装、持续重启窗口和启动探针失败后的回滚;真实发布包及备份内容核对 | +| 兼容性 / 说明 | 最终菜单调用原生 API 检测及 Word 打开说明 | 114 个器件、属性、页、坐标、路径与保留对象均成功读取;消息让出方式 `ActiveView.Refresh`;说明打开后关闭测试文档 | + +## 具体证据文件 + +- 菜单:`native-20261010\persistent-menu-check.txt`、`persistent-after-switch.txt`,明确 `DONE` 回执。 +- 位号等事务:`native-20261010\native-feature-tests\<用例>\verified.json`、`apply-status.json`、`host-trace.txt`。`inspection-final\after.json` 对照初始 `refdes\before.json`,114 个器件的位号、位置、属性值和可见性恢复。 +- BOM:`bom-actual-native-verified.json`、`bom-native-final-verified.json`、`BOM-actual-DxDesigner.xlsx`、`bom-final.xlsx`、`bom-final.xls`。 +- PCB:`pcb-native-report.json`、`pcb-texts-before.txt`、`pcb-texts-after.txt`、`pcb-texts-undo.txt`。 +- PDF 范围:`pdf-scopes-20261010\verification.json`、`pon-scope-results.json` 和输出 PDF。 +- PDF 自动:`native-20261010\pdf-native-acceptance.json`、`pdf-native-enabled-result.json`、`pdf-native-restored-result.json`、`pdf-native-disabled-result.json`、监听器原生日志。 + +## 适用边界 + +实际 API 行为通过上述样例工程验证;多单元、锁定、排序规则和跨页计算还有离线回归,未声称穷举所有公司工程。原始 Surge 267 文件与 PON 133 个相关文件比较无增加、删除或修改。 + +PCB 整理保留 79 个未匹配到已知器件的文字;旧脚本会额外删除它们。本版验证了这些文字不变,以及非装配层正交位号只调整格式、保留位置。安装目录为 7.9.5EE,本机 Expedition Automation 返回版本 `7.9.4.543380`。 + +原生 sch2pdf 在本机有缺失字体造成的中文乱码或裁切,范围筛页没有引入额外变化。活动工程的数据库可能被宿主共享锁锁住,此时导出记录明确列出未能核验内容的原生数据库文件;可读设计文件及工程配置仍严格比较,普通权限错误继续阻止导出。 + +## 最终便携包复验 + +交付目录:`release\一叶知秋_重构版_持久菜单与全功能修复版`。ZIP 名称在目录名后增加 `_Win11_x64.zip`,校验记录为同名 `_SHA256SUMS.txt`。 + +- ZIP SHA-256:`efa435acf568c92fe467be33d8eec782a4c4311cf27095466bd1d22599fcf26d`。 +- exe SHA-256:`d592d941543057622d2bc0867d2bd2e5c82aff07ed95424bf3c7f19ce948802e`。 +- 隔离构建 PATH,避免混入其他软件 DLL;最终 VBS 文件逐个比较,与本轮源码一致。 +- 最终 GUI 的 Start 已实际调用并收到“菜单已持久注册并加入当前 DxDesigner”。随后普通启动新的 DxDesigner,未点击 Start,两栏各一个菜单、八个动作;证据 `persistent-final-startup.json`。 +- 八个菜单回调均执行:六个设计功能打开最终 exe 的正确页面并连接副本工程,兼容性检测生成原生结果,使用说明通过 Word 打开;证据 `packaged-menu-acceptance.json`。 +- 最终包的 Expedition 脚本直接导入原生宿主,解析到最终交付目录,菜单 13 → 14,实际注册 Target 的回调调用通过;证据 `%TEMP%\dx-native-bom-pcb-20261010\pcb-native-menu-verified.json`。 +- 最终 exe 的九个页面、兼容性 CLI、PCB 计算 CLI、关闭的保存监听入口及中文空格目录运行,在 PATH 不含 Python 时通过便携包测试。 +- 最终冻结监听器按准确 ROT 实例生成含新值的一页 PDF,恢复原值后再次输出,关闭后退出码 0;证据 `pdf-frozen-final-acceptance.json`。保留本机 Mentor 原生引擎运行库路径,PATH 不含 Python。 +- 最终 exe 使用真实交付 ZIP 在临时副本完成安装、持续重启和失败回滚;证据 `build/test-evidence/packaged-update.json`。测试没有替换交付目录。 + +35 个设计实机用例:26 个应用、4 个预检拒绝、1 个读回验证的回滚、4 个检查/定位/无写入用例。验收结束后已关闭本轮独立 Dx 副本,用户原实例继续运行。 + +最终工具窗口已打开并连接用户当前 `Audio_D2128_ESD.prj`,保持可见;只读取工程快照。记录为 `final-open-tool.json`。 diff --git a/docs/testing/native-acceptance.md b/docs/testing/native-acceptance.md index c98894c..80dc1ff 100644 --- a/docs/testing/native-acceptance.md +++ b/docs/testing/native-acceptance.md @@ -2,6 +2,8 @@ 本清单用于在真实 DxDesigner 7.9.5 / Expedition PCB 环境中验收原生迁移后的功能。各功能的计算逻辑已由自动化测试覆盖;本清单关注 COM 宿主行为(属性写回、读回验证、定位、Excel 输出)与端到端体验。没有真实宿主运行记录时,不得写成“已验证”。 +2026-10-10 至 2026-10-11 的逐项实际结果见 [本轮验收报告](native-acceptance-20261010.md),包括持久菜单、PDF 三种范围、自动导出关闭检查及失败回滚。以下为后续工程复测清单。 + ## 通用前置条件 - 从完整便携包打开 `DxDesignerTools.exe`,点击 Start 自动注册并加载 DxDesigner 菜单;Expedition 侧导入 `expedition\ExpeditionBridge.vbs`。 diff --git a/docs/user/PDF_export.md b/docs/user/PDF_export.md index ed154c3..e3e8da5 100644 --- a/docs/user/PDF_export.md +++ b/docs/user/PDF_export.md @@ -5,11 +5,13 @@ 范围有三种: - **整工程**:导出当前工程中的全部原理图页。 -- **当前页**:导出打开工具时 DxDesigner 活动视图对应的 Block。 +- **当前页**:导出活动视图对应的命名图页,多页 Block 只保留该页。 - **指定原理图或 Block**:输入本机 DxDesigner 工程中的实际 Block 名称。 默认输出到 `%LOCALAPPDATA%\DxProductivity\pdf-output` 下按工程区分的目录。可在页面选择其他输出目录,但不能选择源工程目录或其子目录。覆盖现有 PDF 前,手动导出会先询问;自动导出只在新 PDF 验证成功后替换原文件。 -“保存工程后自动导出”默认关闭。开启后,DxDesigner 7.9.5 的保存完成事件会触发后台导出;关闭后监听器会自行退出。导出状态显示在 DxDesigner 状态栏,详细记录位于 `%LOCALAPPDATA%\DxProductivity\pdf-runs`。 +“保存工程后自动导出”默认关闭。EE iCDB 工程会即时保存设计变更,工具收到原生变更事件、等待变更稳定后导出当前数据库;传统文件工程在保存完成后导出。重复通知会合并,已有导出进程结束后才执行下一次导出。监听器按配置中的工程路径绑定实例,关闭开关后自行退出。导出状态显示在 DxDesigner 状态栏,详细记录位于 `%LOCALAPPDATA%\DxProductivity\pdf-runs`。 PDF 使用本机 `sch2pdf.exe`、DxDesigner 配置和许可。原生出图可能更新工程数据库或运行记录;发布 PDF 前工具会检查工程文件变化,未确认的变化会阻止发布。 + +工程打开时数据库可能被锁定,工具会明确记录无法核验数据库内容;工程配置和其他可读设计文件继续进行变化检查。 diff --git a/docs/user/一叶知秋_重构版_更新说明.md b/docs/user/一叶知秋_重构版_更新说明.md index bca5c4f..3924b70 100644 --- a/docs/user/一叶知秋_重构版_更新说明.md +++ b/docs/user/一叶知秋_重构版_更新说明.md @@ -3,9 +3,9 @@ ## 本版变更(原生迁移版) - 打开完整工具包中的 `DxDesignerTools.exe`,点击顶部 **Start**,即可自动加入 DxDesigner 菜单。已打开的 DxDesigner 会加载菜单;未打开时工具会带菜单配置启动它。 -- 菜单包含自动位号、属性批改、属性显示、设计检查、BOM、PDF 导出、兼容性检测及使用说明。Start 使用用户目录中的独立启动配置,保留公司原有启动脚本;生成入口明确绑定当前工具目录,支持中文及空格路径。 +- 菜单包含自动位号、属性批改、属性显示、设计检查、BOM、PDF 导出、兼容性检测及使用说明。Start 会先备份,再向 DxDesigner 平时使用的 `scripts.ini` 注册入口,保留公司原有启动脚本;关闭工具、普通重启 DxDesigner、切换工程后菜单继续存在。生成的动作保存在用户目录,绑定当前工具包,支持中文及空格路径。 - 移动完整工具包后重新打开其中的 exe 并点击 Start,入口会更新到新位置。工具目录不完整或宿主未加载成功时,界面会显示原因。DxDesigner 若正在等待报错对话框,先关闭该对话框,再点击 Start。 -- 修复菜单动作与 DxDesigner 内置常量重名、桥接心跳函数名错误,以及刷新快照时重复对象编号的问题。工程路径改用 7.9.5 的 `GetProjectData().GetProjectFilePath()`,PDF 保存监听也使用同一接口。 +- 修复中文宿主需要本地化启动键、命名图页、器件坐标与属性读取、网络名称、定位请求末尾换行、循环位号交换和事务信箱读取等实机兼容问题。 - 菜单点击、快照生成与工具启动阶段写入 `%LOCALAPPDATA%\DxProductivity\bridge-diagnostics.log`,桥接异常会显示具体错误。 - 原“一叶知秋”七大功能全部**原生迁移**进新工具,不再桥接旧 EFM/VBS:Value/Value1/Part Number 批量修改、PartName/PartLabel 批量隐藏(新增“显示”方向)、孤立网络/网络列表/跨页互动、Value/Value1 遗漏查找、BOM 导出(含创维料号校验)与 Expedition PCB 装配位号整理。 @@ -13,6 +13,9 @@ - 桥接协议升级到 v2:快照包含属性全集、可见性、网络分布与真实锁定状态;调度表按“操作类型 + 属性名”泛化,同一事务核心承载所有功能。 - 宿主侧信箱支持多次应用、真实休眠(不再空转占用 CPU)、心跳检测与旧运行目录自动清理;界面增加“刷新设计快照”的真实重新导出。 - 更新通道安全强化:stable 频道强制 Ed25519 签名验证(公钥内置于程序),下载地址仅允许 https 与 file 协议,阻止跨协议重定向;更新器加单实例互斥并等待主程序退出后再切换版本。 +- PDF 支持整工程、当前页、指定原理图或 Block。当前页通过原生 PDF 的准确书签保留一页;书签缺失或歧义时保留旧输出并报错。自动导出默认关闭,开启后监听原生事件;EE 数据库即时保存后等待变更稳定再导出。 +- 修复 BOM 只输出表头、合并行内重复位号检测及 Excel 失败后的资源清理;修复 Expedition 的工具目录解析、菜单接口和脚本入口。 +- 修复更新器对发布 ZIP 外层目录的处理,并将更新程序复制到缓存后运行,避免 Windows 上自身锁住待替换 exe。 ## 设置页 @@ -20,4 +23,4 @@ ## 实机验收 -DxDesigner 7.9.5 与 Expedition PCB 的宿主行为(COM 属性写回、网络定位、Excel 输出)仍需按 `docs/testing/native-acceptance.md` 在真实环境验收;逻辑正确性已由自动化测试覆盖。 +本轮已在 DxDesigner / Expedition 7.9.5 的独立工程副本上验证位号、属性、可见性、历史恢复、器件与网络定位、BOM、PCB 整理和 PDF 导出。逐项结果和适用边界见 `docs/testing/native-acceptance-20261010.md`。原生 PDF 字体缺失造成的中文乱码或裁切仍依赖本机字体和出图配置。 diff --git a/integration/dxdesigner795/CompatibilityProbe.vbs b/integration/dxdesigner795/CompatibilityProbe.vbs index d56b8d6..4ef2d68 100644 --- a/integration/dxdesigner795/CompatibilityProbe.vbs +++ b/integration/dxdesigner795/CompatibilityProbe.vbs @@ -169,7 +169,7 @@ Function DxToolsProbePathMethod(comp) If comp Is Nothing Then Exit Function On Error Resume Next - ignored = CStr(comp.Parent) & "\" & CStr(comp.GetName(SHORT_NAME)) + ignored = CStr(comp.Parent.GetName(SHORT_NAME)) & "\" & CStr(comp.GetName(SHORT_NAME)) If Err.Number = 0 Then DxToolsProbePathMethod = "Parent+GetName(SHORT_NAME)" Err.Clear On Error GoTo 0 @@ -181,6 +181,14 @@ Function DxToolsProbePositionMethod(comp) DxToolsProbePositionMethod = "" If comp Is Nothing Then Exit Function + On Error Resume Next + x = comp.GetLocation().X + y = comp.GetLocation().Y + If Err.Number = 0 Then DxToolsProbePositionMethod = "GetLocation().X/Y" + Err.Clear + On Error GoTo 0 + If DxToolsProbePositionMethod <> "" Then Exit Function + On Error Resume Next x = comp.X y = comp.Y diff --git a/integration/dxdesigner795/MenuAdd.vbs b/integration/dxdesigner795/MenuAdd.vbs index 552dc05..3343467 100644 --- a/integration/dxdesigner795/MenuAdd.vbs +++ b/integration/dxdesigner795/MenuAdd.vbs @@ -17,8 +17,56 @@ If DxToolsHome = "" Then MsgBox DxToolsPathErrorMessage(), vbExclamation Else Call DxToolsInstallMenu() + Call DxToolsAttachMenuEvents() End If +Sub DxToolsAttachMenuEvents() + ' Native startup scripts must remain alive to receive project/view events. + On Error Resume Next + Scripting.AttachEvents Application, "DxToolsHost" + Scripting.DontExit = True + Err.Clear + On Error GoTo 0 +End Sub + +Sub DxToolsHost_ProjectChanged(projectData) + Call DxToolsRestoreMenus() +End Sub + +Sub DxToolsHost_AfterDocumentOpened(dataType, name, path) + Call DxToolsRestoreMenus() +End Sub + +Sub DxToolsHost_ActivateView() + Call DxToolsRestoreMenus() +End Sub + +Sub DxToolsHost_ProjectClosed() + Call DxToolsRestoreMenus() +End Sub + +Sub DxToolsRestoreMenus() + Call DxToolsRestoreMenuBar("Main Menu Bar") + Call DxToolsRestoreMenuBar("Sheet Menu Bar") +End Sub + +Sub DxToolsRestoreMenuBar(barName) + Dim menuBar, item, index + On Error Resume Next + Set menuBar = CommandBars(CStr(barName)) + If Err.Number <> 0 Then + Err.Clear + On Error GoTo 0 + Exit Sub + End If + On Error GoTo 0 + For index = 1 To menuBar.Controls.Count + Set item = menuBar.Controls.Item(index) + If item.Caption = DxToolsSuiteCaption() Then Exit Sub + Next + Call DxToolsInstallMenuBar(barName) +End Sub + Sub DxToolsInstallMenu() Call DxToolsInstallMenuBar("Main Menu Bar") Call DxToolsInstallMenuBar("Sheet Menu Bar") @@ -190,16 +238,10 @@ Sub DxToolsMaybeStartPdfListener() expression.Global = False If Not expression.Test(settingsText) Then Exit Sub - listenerPath = fso.BuildPath(DxToolsHome, "PdfSaveListener.vbs") executablePath = fso.BuildPath(DxToolsHome, "DxDesignerTools.exe") - hostPath = shell.ExpandEnvironmentStrings( _ - "%WINDIR%\SysWOW64\wscript.exe") - If Not fso.FileExists(listenerPath) Then Exit Sub If Not fso.FileExists(executablePath) Then Exit Sub - If Not fso.FileExists(hostPath) Then Exit Sub - commandLine = DxToolsQuote(hostPath) & " //B //NoLogo " & _ - DxToolsQuote(listenerPath) & " " & DxToolsQuote(settingsPath) & " " & _ - DxToolsQuote(executablePath) & " exe " & DxToolsQuote(DxToolsHome) + commandLine = DxToolsQuote(executablePath) & " pdf-export-listen --settings " & _ + DxToolsQuote(settingsPath) shell.Run commandLine, 0, False End Sub diff --git a/integration/dxdesigner795/core/BomExport.vbs b/integration/dxdesigner795/core/BomExport.vbs index aede5e9..0a9b91b 100644 --- a/integration/dxdesigner795/core/BomExport.vbs +++ b/integration/dxdesigner795/core/BomExport.vbs @@ -30,13 +30,35 @@ Sub DxBridgeRenderBom(runRoot, claimedPath) End Sub Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError) + Dim excel + Dim workbook + Set excel = Nothing + Set workbook = Nothing + On Error Resume Next + Set excel = CreateObject("Excel.Application") + If Err.Number = 0 Then + Call DxBomPopulateWorkbook(excel, workbook, text) + End If + If Err.Number <> 0 Then + statusState = "failed" + statusError = Err.Description + Err.Clear + If Not workbook Is Nothing Then workbook.Close False + If Not excel Is Nothing Then excel.Quit + Err.Clear + Else + statusState = "ok" + statusError = "" + End If + On Error GoTo 0 +End Sub + +Sub DxBomPopulateWorkbook(excel, ByRef workbook, text) Dim templatePath Dim outputPath Dim designName Dim descriptionHeader - Dim excel Dim workbooks - Dim workbook Dim sheet Dim saveFormat @@ -45,7 +67,6 @@ Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError) Call DxBomField(text, "design_name", designName) Call DxBomField(text, "description_header", descriptionHeader) - Set excel = CreateObject("Excel.Application") excel.Visible = False excel.DisplayAlerts = False Set workbooks = excel.Workbooks @@ -68,20 +89,20 @@ Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError) Call workbook.SaveAs(CStr(outputPath), saveFormat) excel.Visible = True excel.DisplayAlerts = True - statusState = "ok" - statusError = "" End Sub Sub DxBomWriteSections(excel, sheet, text) ' Sections and rows are embedded as line-oriented records to keep the VBS ' JSON reading trivial: S| / R||||| Dim lines + Dim records Dim line Dim parts Dim rowIndex Dim flagParts rowIndex = 2 - lines = Split(Replace(CStr(text), vbCr, ""), vbLf) + Call DxBomField(text, "records", records) + lines = Split(Replace(CStr(records), vbCr, ""), vbLf) For Each line In lines If Left(line, 2) = "S|" Then sheet.Cells(rowIndex, 1).Value = Mid(line, 3) diff --git a/integration/dxdesigner795/core/Mailbox.vbs b/integration/dxdesigner795/core/Mailbox.vbs index 98e2786..f987f87 100644 --- a/integration/dxdesigner795/core/Mailbox.vbs +++ b/integration/dxdesigner795/core/Mailbox.vbs @@ -10,6 +10,7 @@ Sub DxToolsDesignBridgeStart(featureKey) Dim snapshotId Dim process Dim state + Dim messageStyle Set objectMap = CreateObject("Scripting.Dictionary") Set originalMap = CreateObject("Scripting.Dictionary") @@ -22,8 +23,9 @@ Sub DxToolsDesignBridgeStart(featureKey) state = DxBridgeMailboxLoop(process, runRoot, runId, snapshotId, _ objectMap, originalMap) If state <> "" Then - MsgBox DxBridgeStateMessage(state), _ - IIf(state = "applied", vbInformation, vbExclamation) + messageStyle = vbExclamation + If state = "applied" Then messageStyle = vbInformation + MsgBox DxBridgeStateMessage(state), messageStyle End If End Sub @@ -184,7 +186,7 @@ Sub DxBridgeConsumeLocate(runRoot, objectMap) If Not fso.FileExists(locatePath) Then Exit Sub If Not DxBridgeClaimFile(fso, locatePath, processingPath) Then Exit Sub On Error Resume Next - bridgeId = Trim(DxToolsReadUtf8(processingPath)) + bridgeId = Trim(Replace(Replace(DxToolsReadUtf8(processingPath), vbCr, ""), vbLf, "")) If Err.Number <> 0 Then Err.Clear On Error GoTo 0 @@ -211,6 +213,7 @@ Sub DxBridgeLocateNet(netName, pageNumber) Dim topBlock Dim net Dim found + Dim page, pageIndex, sheetName On Error Resume Next Set projectData = Application.GetProjectData() If Err.Number <> 0 Then @@ -222,13 +225,22 @@ Sub DxBridgeLocateNet(netName, pageNumber) designId = CStr(designs.GetItem(1)) topBlock = projectData.GetiCDBDesignRootBlock(designId) Err.Clear - ActiveView.UnselectAll + ActiveView.Block.DeSelectAll Err.Clear - Application.PushPath topBlock, "", CLng(pageNumber) + pageIndex = 0 + sheetName = CStr(pageNumber) + For Each page In Application.QueryPages(topBlock) + pageIndex = pageIndex + 1 + If pageIndex = CLng(pageNumber) Then + sheetName = CStr(page.SheetNum) + Exit For + End If + Next + Application.PushPath topBlock, "", sheetName Err.Clear found = False For Each net In ActiveView.Query(VDM_NET, VD_ALL) - If CStr(net.Name) = CStr(netName) Then + If StrComp(DxBridgeNetName(net), CStr(netName), vbTextCompare) = 0 Then net.Selected = True If Err.Number <> 0 Then Err.Clear ActiveView.ZoomSelect @@ -254,15 +266,13 @@ End Function Sub DxBridgeLocateComponent(component) On Error Resume Next - ActiveView.UnselectAll + Application.PushPath component.Parent.GetName(SHORT_NAME), "", CStr(component.Parent.SheetNum) Err.Clear - ActiveView.Select component - If Err.Number <> 0 Then - Err.Clear - ActiveView.SelectObject component - End If + ActiveView.Block.DeSelectAll Err.Clear - ActiveView.ZoomTo component + ActiveView.SelectByName component.GetName(SHORT_NAME) + Err.Clear + ActiveView.ZoomSelect Err.Clear ActiveView.Refresh Err.Clear diff --git a/integration/dxdesigner795/core/Snapshot.vbs b/integration/dxdesigner795/core/Snapshot.vbs index 8fdb215..8d2b70c 100644 --- a/integration/dxdesigner795/core/Snapshot.vbs +++ b/integration/dxdesigner795/core/Snapshot.vbs @@ -99,10 +99,11 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _ refdes = DxBridgeRefdes(component) symbolDefault = DxBridgeSymbolDefault(component, refdes) sheetNumber = DxBridgeSheetNumber(component) - sheetName = CStr(sheetNumber) + sheetName = CStr(component.Parent.SheetNum) identityKey = DxBridgeIdentityKey(stableUid, fullPath) selectedValue = selectedKeys.Exists(identityKey) - currentSheetValue = (sheetNumber = DxBridgeCurrentSheetNumber()) + currentSheetValue = (LCase(DxBridgeBlockName(component.Parent)) = LCase(activeBlockName) _ + And LCase(sheetName) = LCase(DxBridgeCurrentSheetName())) attributesText = DxBridgeExportAttributes(component) objectMap.Add bridgeId, component @@ -151,6 +152,7 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _ " ""active_block_name"": """ & _ DxToolsJson(activeBlockName) & """," & vbCrLf & _ " ""current_sheet_number"": " & currentSheetNumberJson & "," & vbCrLf & _ + " ""current_sheet_name"": """ & DxToolsJson(DxBridgeCurrentSheetName()) & """," & vbCrLf & _ " ""nets"": " & netsText & "," & vbCrLf & _ " ""selected_nets"": " & selectedNetsText & "," & vbCrLf & _ " ""components"": [" & vbCrLf & componentText & vbCrLf & _ @@ -215,12 +217,12 @@ Function DxBridgeExportNets(topBlock) For Each net In nets name = "" page = -1 - name = CStr(net.Name) + name = DxBridgeNetName(net) If Err.Number <> 0 Then Err.Clear name = "" End If - page = CLng(net.SheetNum) + page = DxBridgeBlockSheetNumber(net.Parent) If Err.Number <> 0 Then Err.Clear page = DxBridgeCurrentSheetNumber() @@ -230,7 +232,7 @@ Function DxBridgeExportNets(topBlock) If Not names.Exists(nameText) Then names.Add nameText, name pages.Add nameText, CStr(page) - ElseIf InStr(pages(nameText), CStr(page)) = 0 Then + ElseIf InStr("," & Replace(pages(nameText), " ", "") & ",", "," & CStr(page) & ",") = 0 Then pages(nameText) = pages(nameText) & ", " & CStr(page) End If End If @@ -256,7 +258,7 @@ Function DxBridgeExportSelectedNets() text = "" On Error Resume Next For Each net In ActiveView.Query(VDM_NET, VD_SELECTED) - name = CStr(net.Name) + name = DxBridgeNetName(net) If Err.Number <> 0 Then Err.Clear ElseIf name <> "" Then @@ -328,7 +330,7 @@ Function DxBridgeFullPath(component) parentName = "" componentName = "" On Error Resume Next - parentName = CStr(component.Parent.Name) + parentName = CStr(component.Parent.GetName(SHORT_NAME)) componentName = CStr(component.GetName(SHORT_NAME)) Err.Clear On Error GoTo 0 @@ -369,28 +371,83 @@ Function DxBridgeRefdes(component) End Function Function DxBridgeSymbolDefault(component, refdes) + Dim symbolAttribute DxBridgeSymbolDefault = "" On Error Resume Next DxBridgeSymbolDefault = CStr(component.SymbolRefdesDefault) Err.Clear On Error GoTo 0 + If DxBridgeSymbolDefault = "" Then + On Error Resume Next + Set symbolAttribute = component.SymbolBlock.FindAttribute("Ref Designator") + If Not symbolAttribute Is Nothing Then + DxBridgeSymbolDefault = CStr(symbolAttribute.Value) + End If + Err.Clear + On Error GoTo 0 + End If If DxBridgeSymbolDefault = "" And InStr(CStr(refdes), "?") > 0 Then DxBridgeSymbolDefault = CStr(refdes) End If End Function Function DxBridgeSheetNumber(component) - DxBridgeSheetNumber = DxBridgeCurrentSheetNumber() - On Error Resume Next - DxBridgeSheetNumber = CLng(component.Parent.SheetNum) - Err.Clear - On Error GoTo 0 + DxBridgeSheetNumber = DxBridgeBlockSheetNumber(component.Parent) End Function Function DxBridgeCurrentSheetNumber() DxBridgeCurrentSheetNumber = 0 On Error Resume Next - DxBridgeCurrentSheetNumber = CLng(ActiveView.Block.SheetNum) + DxBridgeCurrentSheetNumber = DxBridgeBlockSheetNumber(ActiveView.Block) + Err.Clear + On Error GoTo 0 +End Function + +Function DxBridgeBlockSheetNumber(block) + Dim rawName, page, index + DxBridgeBlockSheetNumber = 0 + On Error Resume Next + rawName = CStr(block.SheetNum) + If IsNumeric(rawName) Then + DxBridgeBlockSheetNumber = CLng(rawName) + Else + index = 0 + For Each page In Application.QueryPages(DxBridgeBlockName(block)) + index = index + 1 + If StrComp(CStr(page.SheetNum), rawName, vbTextCompare) = 0 Then + DxBridgeBlockSheetNumber = index + Exit For + End If + Next + End If + Err.Clear + On Error GoTo 0 +End Function + +Function DxBridgeBlockName(block) + DxBridgeBlockName = "" + On Error Resume Next + DxBridgeBlockName = CStr(block.GetName(SHORT_NAME)) + Err.Clear + On Error GoTo 0 +End Function + +Function DxBridgeCurrentSheetName() + DxBridgeCurrentSheetName = "" + On Error Resume Next + DxBridgeCurrentSheetName = CStr(ActiveView.Block.SheetNum) + Err.Clear + On Error GoTo 0 +End Function + +Function DxBridgeNetName(net) + DxBridgeNetName = "" + On Error Resume Next + DxBridgeNetName = CStr(net.LogicalNetName) + If Err.Number <> 0 Then + Err.Clear + DxBridgeNetName = CStr(net.Name) + End If Err.Clear On Error GoTo 0 End Function @@ -404,14 +461,13 @@ Function DxBridgeCurrentBlockName() End Function Function DxBridgeCurrentSheetNumberJson() - DxBridgeCurrentSheetNumberJson = "null" - On Error Resume Next - DxBridgeCurrentSheetNumberJson = CStr(CLng(ActiveView.Block.SheetNum)) - If Err.Number <> 0 Then + Dim number + number = DxBridgeCurrentSheetNumber() + If number > 0 Then + DxBridgeCurrentSheetNumberJson = CStr(number) + Else DxBridgeCurrentSheetNumberJson = "null" - Err.Clear End If - On Error GoTo 0 End Function Function DxBridgeCoordinate(component, readX) @@ -419,16 +475,16 @@ Function DxBridgeCoordinate(component, readX) value = 0 On Error Resume Next If CBool(readX) Then - value = component.X + value = component.GetLocation().X Else - value = component.Y + value = component.GetLocation().Y End If If Err.Number <> 0 Then Err.Clear If CBool(readX) Then - value = component.PositionX + value = component.X Else - value = component.PositionY + value = component.Y End If End If Err.Clear @@ -461,7 +517,7 @@ End Function Function DxBridgeAttribute(component, name) DxBridgeAttribute = "" On Error Resume Next - DxBridgeAttribute = CStr(component.Attributes.Item(CStr(name)).Value) + DxBridgeAttribute = CStr(component.FindAttribute(CStr(name)).Value) Err.Clear On Error GoTo 0 End Function @@ -472,8 +528,9 @@ Function DxBridgeLocked(component) DxBridgeLocked = CBool(component.Locked) If Err.Number <> 0 Then Err.Clear - DxBridgeLocked = False + DxBridgeLocked = CBool(component.Parent.IsReadOnly) End If + Err.Clear On Error GoTo 0 End Function diff --git a/integration/dxdesigner795/core/Transaction.vbs b/integration/dxdesigner795/core/Transaction.vbs index 5931b5d..72c87b0 100644 --- a/integration/dxdesigner795/core/Transaction.vbs +++ b/integration/dxdesigner795/core/Transaction.vbs @@ -49,18 +49,38 @@ Function DxPreflightApply(runRoot, runId, snapshotId, objectMap, _ Dim projected Dim key Dim component + Dim snapshotPath, snapshotText, snapshotDesignPath, currentProjectPath DxPreflightApply = False errorText = "" backupPath = "" Set fso = CreateObject("Scripting.FileSystemObject") requestPath = fso.BuildPath(runRoot, "apply-request.json") - resultPath = fso.BuildPath(runRoot, "result.tsv") + resultPath = fso.BuildPath(runRoot, "result.processing") + If Not fso.FileExists(resultPath) Then resultPath = fso.BuildPath(runRoot, "result.tsv") If Not fso.FileExists(requestPath) Or Not fso.FileExists(resultPath) Then errorText = "Apply request is incomplete" Exit Function End If + snapshotPath = fso.BuildPath(runRoot, "request.json") + If fso.FileExists(snapshotPath) Then + snapshotText = DxToolsReadUtf8(snapshotPath) + If Not DxToolsJsonString(snapshotText, "design_path", snapshotDesignPath) Then + errorText = "Design snapshot project path is invalid" + Exit Function + End If + currentProjectPath = "" + On Error Resume Next + currentProjectPath = CStr(Application.GetProjectData().GetProjectFilePath()) + Err.Clear + On Error GoTo 0 + If currentProjectPath = "" Or StrComp(currentProjectPath, snapshotDesignPath, vbTextCompare) <> 0 Then + errorText = "Design snapshot belongs to a different current project" + Exit Function + End If + End If + requestText = DxToolsReadUtf8(requestPath) If InStr(requestText, """format_version"": 2,") = 0 Then errorText = "Unsupported apply request version" @@ -215,7 +235,7 @@ Function DxApplySchedule(resultText, objectMap, _ touched, rollbackState, errorText) Exit Function End If - finals.Add key, Array(CStr(op), CStr(propertyName), _ + finals(key) = Array(CStr(op), CStr(propertyName), _ CStr(bridgeId), CStr(finalValue)) End If Next @@ -331,7 +351,7 @@ Function DxBridgeReadOpValue(component, op, propertyName) DxBridgeReadOpValue = "" On Error Resume Next DxBridgeReadOpValue = CStr( _ - component.Attributes.Item(CStr(propertyName)).Value) + component.FindAttribute(CStr(propertyName)).Value) If Err.Number <> 0 Then Err.Clear DxBridgeReadOpValue = "" @@ -341,7 +361,7 @@ Function DxBridgeReadOpValue(component, op, propertyName) DxBridgeReadOpValue = "" On Error Resume Next DxBridgeReadOpValue = DxBridgeNormalizeVisible( _ - component.Attributes.Item(CStr(propertyName)).Visible) + component.FindAttribute(CStr(propertyName)).Visible) If Err.Number <> 0 Then Err.Clear DxBridgeReadOpValue = "" @@ -361,9 +381,9 @@ Function DxBridgeWriteOpValue(component, op, propertyName, value, _ Case "refdes" component.Refdes = CStr(value) Case "property" - component.Attributes.Item(CStr(propertyName)).Value = CStr(value) + component.FindAttribute(CStr(propertyName)).Value = CStr(value) Case "visibility" - component.Attributes.Item(CStr(propertyName)).Visible = _ + component.FindAttribute(CStr(propertyName)).Visible = _ CBool(CStr(value)) Case Else Err.Raise vbObjectError + 801, "DxBridgeWriteOpValue", _ diff --git a/integration/dxdesigner795/expedition/ExpeditionBridge.vbs b/integration/dxdesigner795/expedition/ExpeditionBridge.vbs index bbad9c0..2c50ec5 100644 --- a/integration/dxdesigner795/expedition/ExpeditionBridge.vbs +++ b/integration/dxdesigner795/expedition/ExpeditionBridge.vbs @@ -4,6 +4,25 @@ ' host applies it inside one undoable transaction. Dim DxToolsHome +Dim DxExpeditionMenu + +Call DxEpInitialize() + +Sub DxEpInitialize() + Dim host + Set host = Nothing + On Error Resume Next + Set host = Application + Err.Clear + On Error GoTo 0 + If host Is Nothing Then Exit Sub + Call DxToolsInstallExpeditionMenu() + If DxToolsHome = "" Then Exit Sub + On Error Resume Next + Scripting.DontExit = True + Err.Clear + On Error GoTo 0 +End Sub Sub DxToolsInstallExpeditionMenu() Dim menuBar @@ -14,13 +33,13 @@ Sub DxToolsInstallExpeditionMenu() DxToolsHome = DxEpResolveRoot() If DxToolsHome = "" Then - MsgBox "DxDesignerTools.exe not found next to this script.", _ + MsgBox "Run Start in DxDesignerTools.exe before importing this script.", _ vbExclamation Exit Sub End If caption = "Dx " & ChrW(&H6548) & ChrW(&H7387) & ChrW(&H5DE5) & ChrW(&H5177) - Set menuBar = CommandBars("Document Menu Bar") + Set menuBar = Application.Gui.CommandBars("Document Menu Bar") For i = menuBar.Controls.Count To 1 Step -1 Set existing = menuBar.Controls.Item(i) If existing.Caption = caption Then @@ -31,14 +50,19 @@ Sub DxToolsInstallExpeditionMenu() End If Next - Set DxExpeditionMenu = menuBar.Controls.Add(10) ' cmdControlPopup + Set DxExpeditionMenu = menuBar.Controls.Add(1) ' cmdControlPopup DxExpeditionMenu.Caption = caption Set button = DxExpeditionMenu.Controls.Add button.Caption = ChrW(&H81EA) & ChrW(&H52A8) & ChrW(&H8C03) & _ ChrW(&H6574) & ChrW(&H88C5) & ChrW(&H914D) & ChrW(&H5C42) & _ ChrW(&H4F4D) & ChrW(&H53F7) - button.OnAction = "DxExpeditionRunAssemblyRefdes" + button.Target = ScriptEngine + button.ExecuteMethod = "DxEpAssemblyMenuCommand" +End Sub + +Sub DxEpAssemblyMenuCommand(nID) + Call DxExpeditionRunAssemblyRefdes() End Sub Sub DxExpeditionRunAssemblyRefdes() @@ -66,9 +90,9 @@ Sub DxExpeditionRunAssemblyRefdes() Dim exec Dim commandLine - commandLine = DxToolsQuote(DxToolsHome & "\DxDesignerTools.exe") & _ - " compute assembly-refdes --request " & DxToolsQuote(requestPath) & _ - " --output " & DxToolsQuote(planPath) + commandLine = DxEpQuote(DxToolsHome & "\DxDesignerTools.exe") & _ + " compute assembly-refdes --request " & DxEpQuote(requestPath) & _ + " --output " & DxEpQuote(planPath) On Error Resume Next Set exec = shell.Exec(commandLine) If Err.Number <> 0 Then @@ -109,6 +133,7 @@ Function DxEpExportRequest(docObj) Dim componentKey Dim orientation Dim hasComponent + Dim assemblyFlag Set spans = CreateObject("Scripting.Dictionary") lines = "" @@ -191,10 +216,12 @@ Function DxEpExportRequest(docObj) On Error GoTo 0 If lines <> "" Then lines = lines & vbCrLf + assemblyFlag = "0" + If fabtxt.Type = epcbFabAssembly Then assemblyFlag = "1" lines = lines & "T|" & textIndex & _ "|" & CStr(fabtxt.TextType) & _ "|" & CStr(fabtxt.Side) & _ - "|" & IIf(fabtxt.Type = epcbFabAssembly, "1", "0") & _ + "|" & assemblyFlag & _ "|" & fabtxt.TextString & _ "|" & orientation & _ "|" & componentKey @@ -254,7 +281,11 @@ Sub DxEpApplyLine(line, fabtxt) fabtxt.Format.Height(epcbUnitMM) = CDbl(parts(5)) End If fabtxt.Format.Orientation(epcbAngleUnitDegrees) = CDbl(parts(4)) - Call fabtxt.Move(CDbl(parts(2)), CDbl(parts(3))) + ' Blank height represents the legacy nonassembly/cardinal branch: + ' change text format while retaining the existing text position. + If parts(5) <> "" Then + Call fabtxt.Move(CDbl(parts(2)), CDbl(parts(3))) + End If End If Err.Clear On Error GoTo 0 @@ -268,6 +299,17 @@ Sub DxEpWriteAscii(path, text) stream.Close End Sub +Function DxEpQuote(value) + Dim text, expression + text = CStr(value) + Set expression = CreateObject("VBScript.RegExp") + expression.Pattern = "\\+$" + expression.Global = False + text = expression.Replace(text, "$&$&") + DxEpQuote = Chr(34) & Replace(text, Chr(34), _ + Chr(92) & Chr(34)) & Chr(34) +End Function + Function DxEpReadAscii(path) Dim stream Set stream = CreateObject("Scripting.FileSystemObject"). _ @@ -285,28 +327,136 @@ Sub DxEpSleep(milliseconds) End Sub Function DxEpResolveRoot() - Dim fso Dim candidate - Set fso = CreateObject("Scripting.FileSystemObject") DxEpResolveRoot = "" On Error Resume Next candidate = CStr(WScript.ScriptFullName) + Err.Clear + On Error GoTo 0 + DxEpResolveRoot = DxEpRootForScript(candidate) + If DxEpResolveRoot <> "" Then Exit Function + candidate = "" + On Error Resume Next + candidate = CStr(Scripting.CurrentScriptFullName) + Err.Clear + On Error GoTo 0 + DxEpResolveRoot = DxEpRootForScript(candidate) + If DxEpResolveRoot <> "" Then Exit Function + candidate = "" + On Error Resume Next + candidate = CStr(Scripting.ScriptFullName) + Err.Clear + On Error GoTo 0 + DxEpResolveRoot = DxEpRootForScript(candidate) + If DxEpResolveRoot <> "" Then Exit Function + DxEpResolveRoot = DxEpRegisteredRoot() +End Function + +Function DxEpRootForScript(path) + Dim fso, root + DxEpRootForScript = "" + If CStr(path) = "" Then Exit Function + Set fso = CreateObject("Scripting.FileSystemObject") + ' expedition\