Skip to content

fix: kipy 0.7.x / KiCad 10 IPC backend compatibility (IPC 后端兼容修复) - #378

Open
AlloyPlane wants to merge 1 commit into
mixelpixx:mainfrom
AlloyPlane:main
Open

fix: kipy 0.7.x / KiCad 10 IPC backend compatibility (IPC 后端兼容修复)#378
AlloyPlane wants to merge 1 commit into
mixelpixx:mainfrom
AlloyPlane:main

Conversation

@AlloyPlane

Copy link
Copy Markdown

修复内容 / What this fixes

让 KiCAD-MCP-Server 的 IPC 后端在 kicad-python 0.7.x + KiCad 10 环境下可用(实时 UI 同步)。
Fixes the IPC backend so it works with kicad-python 0.7.x + KiCad 10 (real-time UI sync).

问题 / Problem

在 KiCad 10.0.5 + kicad-python 0.7.1 下,IPC 后端连接失败并静默回退到 SWIG(_realtime: false),
因为服务器代码针对的是旧版 kipy API。另外 KiCad 10 移除了 pcbnew.GetGlobalFootprintLib
Under KiCad 10.0.5 + kicad-python 0.7.1, the IPC backend fails to connect and silently
falls back to SWIG (_realtime: false), because the server code targets an older kipy API.
Also, KiCad 10 removed pcbnew.GetGlobalFootprintLib.

改动 / Changes

  1. ipc_backend.py – connect(): KiCad() 自动拨号 + 用 get_version() 验证(新 kipy 的 ping() 会超时)
    KiCad() auto-dial + verify via get_version() (new kipy's ping() times out)
  2. ipc_backend.py – board path: get_open_documents(DocumentType.DOCTYPE_PCB)(新 kipy 需要参数),
    并用 board_filename + project.path 组装板文件路径(DocumentSpecifier 已无 path 字段)
    get_open_documents(DocumentType.DOCTYPE_PCB) (new kipy requires the arg) and assemble the
    board path from board_filename + project.path (no more path field on DocumentSpecifier)
  3. ipc_backend.py – footprint loading: 改为按 .pretty 目录 pcbnew.FootprintLoad
    (KiCad 10 移除了 GetGlobalFootprintLib
    load footprints by .pretty dir path (KiCad 10 removed GetGlobalFootprintLib)
  4. kicad_interface.py – _ipc_place_component: 当 footprint 参数缺失时回退到 componentId
    fall back to componentId when the footprint param is missing
  5. command-timeout.ts: 将 open_project / create_project / open_board / place_component
    等加入长时命令列表(SWIG 初始化可能超过 30s)
    treat open_project / create_project / open_board / place_component as long-running
    (SWIG init can exceed 30s)

测试 / Testing

  • 环境: Windows 11 · KiCad 10.0.5(便携版)· kicad-python 0.7.1 · Node 24 / TS 2.6.0
  • Environment: Windows 11 · KiCad 10.0.5 (portable) · kicad-python 0.7.1 · Node 24 / TS 2.6.0
  • open_project_backend: "ipc", _realtime: true(实时会话)
  • ✅ IPC place_component → 成功,KiCad GUI 实时显示(含自定义库封装)
  • npm run build 通过;冒烟测试通过

相关 / Related


中文说明:本 PR 修复 KiCad 10 + kicad-python 0.7.x 环境下 IPC 实时控制不可用的问题,共 5 处改动,
已在 Windows 上实测(实时放件成功)。如有任何格式或命名规范问题,请告知,我会调整。谢谢!

- ipc_backend: KiCad() auto-connect + get_version() verification (ping times out)
- ipc_backend: get_open_documents(DocumentType.DOCTYPE_PCB) + board_filename path resolution
- ipc_backend: load footprints by .pretty dir (GetGlobalFootprintLib removed in KiCad 10)
- kicad_interface: _ipc_place_component falls back componentId when footprint param missing
- command-timeout: treat open_project/create_project/open_board/place_component as long-running
@mixelpixx

Copy link
Copy Markdown
Owner

Reviewed. The kipy 0.7 / KiCad 10 claims are plausible and consistent with what #369 independently found, and the two-arg pcbnew.FootprintLoad(libPath, fpName) call is the correct KiCad 10 signature. But there is one blocker and two structural asks before this can merge.

Blocker — hardcoded developer-machine paths. _pretty_dirs() ships two absolute D:\ paths from your own portable install (D:\kicad\share\kicad\footprints as the default for the env-var escape hatch, and D:\kicad\custom-lib unconditionally), plus Windows-only separators that mean nothing on macOS/Linux. On every other user's machine this silently probes the wrong disk. The correct replacement already exists in this repo: python/commands/library.py has _get_global_fp_lib_table() (line 60) and _parse_fp_lib_table() (line 84), with platform roots handled by python/utils/platform_helper.py. Route footprint discovery through fp-lib-table and hand the resolved .pretty directory to the two-arg FootprintLoad — only the path discovery needs replacing, the load call itself is right.

Second: this adds a third copy of the DocumentSpecifier decoding (#369's in get_open_board_path, yours in _place_loaded_footprint, plus the legacy doc.path fallback). Factor one helper and use it at both sites — three copies is exactly how the next kipy break gets fixed in one place and missed in two. Relatedly, the legacy hasattr(doc, 'path') check now sits after an unconditional break and reads as dead code; restructure so the fallback is explicit.

Third: src/command-timeout.ts promotes eight commands to the long-running bucket, including the read-only get_component_list and get_board_info. That changes a hang from a 30 s failure into a 10-minute wait on queries. Justify those two per-command or drop them.

And tests: #369 shipped a 138-line test file for a 12-line change to this same subsystem; hold this to that bar (the DocumentSpecifier helper is easily unit-testable with fakes). A CHANGELOG entry (English, under Unreleased) is also missing.

The IPC-compat work itself is wanted — #357 collides with this same territory on a stale base, and a corrected version of this PR is the better vehicle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants