Skip to content

feat(schematic): symbol-bbox, dry-run collision check, connectivity check, and auto-router tools - #357

Closed
daniSoares08 wants to merge 2 commits into
mixelpixx:mainfrom
daniSoares08:feat/schematic-wiring-tools
Closed

daniSoares08 wants to merge 2 commits into
mixelpixx:mainfrom
daniSoares08:feat/schematic-wiring-tools

Conversation

@daniSoares08

@daniSoares08 daniSoares08 commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • get_schematic_symbol_bbox: returns absolute-coordinate bounding boxes (body + pins) for requested symbol references.
  • add_schematic_wire gains a dryRun mode: reports symbol crossings and foreign-net collisions before writing anything.
  • check_schematic_connectivity: fast same-net check between two points (pin or x/y), without a full ERC run.
  • connect_schematic_pins: new auto-router (python/commands/schematic_router.py) that A*-routes orthogonal wires between 2+ pins on a coordinate-compressed grid, avoiding symbol bodies and foreign-net wires, with own-net conflict detection and multi-pin sequential nearest-insertion.
  • Also includes an unrelated, already-staged fix: native footprint placement with save/reload fallback for KiCad 10, plus command-timeout refactor.

Motivation: while manually converting a real schematic sheet from net-labels to point-to-point wires, the biggest bottlenecks were no visibility into symbol geometry, no way to detect a wire silently shorting two nets before writing it, and no fast same-net check. These tools close those gaps and add a first-pass auto-router.

Test plan

  • npm run build (TS compiles, registry-completeness test passes)
  • npm run lint:ts (0 errors)
  • Python: pytest full suite — 1829 passed, 32 skipped
  • black --check on touched files
  • Live MCP smoke test against a real, densely-wired schematic (found and fixed an A* performance bug via this)

…Cad 10; refactor command timeouts

- ipc_backend: attempt the native ParseAndCreateItemsFromString path for
  footprint placement first, falling back to a save/reload compatibility
  path since KiCad 10's PCB handler for that command currently returns an
  empty response. Guard pcbnew.SaveBoard calls with preserve_project_settings
  so a board save can no longer clobber .kicad_pro net_settings.
- freerouting: support a FREEROUTING_JAVA environment override for locating
  the Java executable used to run the router.
- command-timeout: extract per-command timeout policy into a pure,
  unit-testable computeCommandTimeout() (src/command-timeout.ts), with an
  autoroute-aware budget instead of a flat ceiling; add open_project and
  create_project to the long-running command list.
…outer tools

Adds four tools that close the gaps hit while manually converting a real
33-net, ~150-wire schematic from net-labels to point-to-point wiring:

- get_schematic_symbol_bbox: absolute-coordinate bounding box (body + pins)
  for one or more symbols, computed via the same lib_symbols-graphics logic
  find_wires_crossing_symbols already used internally, now exposed directly
  so a route can be planned from real geometry instead of guessing from pin
  coordinates alone.
- add_schematic_wire dryRun: preview a candidate wire's symbol crossings and
  collisions with wires on a different net without writing anything. The
  different-net check is new: own-net is resolved once from the file's
  pre-existing state (exact-IU wire endpoint match, by component id rather
  than net name so unnamed nets are handled correctly too), and any existing
  wire on a different net that the candidate path would touch is reported
  rather than silently written.
- check_schematic_connectivity: fast same-net check between two points/pins
  using the existing strict, vertex-exact wire_connectivity BFS, instead of
  shelling out to a full kicad-cli ERC just to sanity-check one connection.
- connect_schematic_pins: orthogonal auto-router for 2+ pins. Builds a
  coordinate-compressed local grid (obstacle edges + uniform fill) around
  each pin pair and A*-searches it with a bend penalty, avoiding symbol
  bodies and foreign-net wires; 3+ pin nets use sequential nearest-pin
  insertion. Blocked-edge lookups are precomputed per obstacle rather than
  rescanned per edge during search — the naive per-edge scan was fast on
  synthetic test fixtures but took 30+ seconds against a real, busy sheet
  with ~250 existing wires/symbols; precomputing brought that under 1.5s.

Shared groundwork: _load_wire_net_membership (wire_connectivity.py)
classifies every wire on a sheet into its net in one pass instead of one
BFS per query point/net; _load_obstacle_model (schematic_analysis.py) is a
refactor-for-reuse of find_wires_crossing_symbols's own per-symbol bbox
precomputation, now shared by the dry-run check and the router.
@mixelpixx

Copy link
Copy Markdown
Owner

Reviewed — and this needs a split before it can be reviewed properly, because the title describes maybe half the diff.

The buried half is the problem. python/kicad_api/ipc_backend.py alone is ~740 lines of this diff — a wholesale kipy-0.7 rewrite — and its base blob is pre-#369, so it reimplements get_open_board_path differently from the version that merged with tests on Aug 9. Merging as-is would either conflict loudly or, resolved carelessly, silently replace a tested implementation with an untested near-duplicate. It also collides head-on with #378, which touches the same functions with a different approach; only one PR can own the kipy-0.7 story, and that decision should not be forced through a PR titled 'schematic tools'. The '1829 passed' claim also cannot be current — it was run against a base that is now several weeks stale.

The good news: the title half is genuinely useful, and its registry hygiene is correct (all three tools registered, first README count bumped).

Concrete ask — split into three:

  1. get_schematic_symbol_bbox + add_schematic_wire dryRun + check_schematic_connectivity — small, well-scoped, wanted. Rebase on current main, fix the second README count occurrence (~line 489, which readme-counts.test.ts does not catch but readers do), and this part merges quickly.
  2. connect_schematic_pins / schematic_router.py — a 549-line A* router needs its own scope discussion (the project just declined a PCB-side A* router on maintenance-ownership grounds in feat(routing): add route_net — obstacle-aware A* net routing #355; schematic wire routing is a different question, but it deserves to be asked, not buried).
  3. The IPC/kipy-0.7 work — rebase on post-fix: correct get_open_board_path so IPC sessions are not silently pinned to SWIG #369 main and reconcile with fix: kipy 0.7.x / KiCad 10 IPC backend compatibility (IPC 后端兼容修复) #378 (see the review there: the fp-lib-table-based discovery is the direction). Between the two PRs, one factored implementation should win.

The freerouting.py and command-timeout.ts changes are unexplained in the body — justify or drop them in whichever split they belong to.

@mixelpixx

Copy link
Copy Markdown
Owner

Closing for now. The split asked for on 2026-08-20 (the symbol-bbox / dry-run collision check / connectivity check trio separated from the kipy 0.7 rewrite of ipc_backend.py) did not get a reply, and the branch is now 88 commits behind main with conflicts in src/server.ts, python/kicad_api/ipc_backend.py and README.md, so it cannot be merged as it stands.

The three schematic tools are still wanted: a fresh PR with just them, rebased on main, gets a prompt review. The ipc_backend half should not come back in that PR; #369 already fixed get_open_board_path with tests, and the kipy compatibility work has its own thread in #378.

@mixelpixx mixelpixx closed this Sep 10, 2026
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