Skip to content

POC: "Import from file" panel — place a local .kicad_sym / .kicad_mod on the canvas - #41

Open
matejcsok-pcb wants to merge 1 commit into
stagingfrom
feature/filesystem-poc
Open

matejcsok-pcb wants to merge 1 commit into
stagingfrom
feature/filesystem-poc

Conversation

@matejcsok-pcb

Copy link
Copy Markdown

What

Proof of concept for plugin-style item ingress in the standalone editor: a floating Import from file panel (session menu → Import from file) that takes a .kicad_sym or .kicad_mod from the user's machine and places it on the open eeschema / pcbnew canvas.

  • File picker or drag-and-drop onto the panel.
  • A multi-symbol library shows a symbol dropdown (top-level symbols only, units hidden).
  • Add to canvas arms a click catcher over the drawing area; the next click is the drop point, grid-snapped. Esc cancels. Viewport centre is the fallback if the canvas rect can't be found.

How (no C++)

The blob goes through the editors' existing collab items-apply bridge, Module.kicadCollabApplyItems, i.e. the clipboard-paste parsers:

  • pcbnew accepts a bare (footprint …); the panel adds (at x y) and caps the format version.
  • eeschema takes the clipboard dialect (lib_symbols (symbol "Nick:Name" …)) (symbol (lib_id "Nick:Name") …) — the definition travels with the instance, so a library the editor has never seen still works.

Click → position: CSS px → canvas px (rect ratio, HiDPI-safe) → world IU via kicadCollabGetViewport, the same mapping the comment pins use.

Files

  • wasm/import-item.ts — blob builders + click/viewport mapping (pure, unit-tested: 12 tests).
  • components/ImportItemPanel.tsx — the panel.
  • WasmTool.tsx, wasm-tool/SessionMenu.tsx — wiring + menu toggle.

Verified

  • Demo schematic: Device R and C placed; the stored (at …) equals the mapped click exactly.
  • Demo board: R_0603_1608Metric placed with pads / courtyard / REF**.
  • vitest 492 green, tsc --noEmit clean, no console errors from the feature.

Known POC limits (documented in wasm/import-item.ts)

  • The apply commits with SKIP_UNDO and is folded into the collab baseline: not undoable, not broadcast to peers / the Y.Doc. Fine in api doc mode (File→Save writes it), wrong for ydoc mode.
  • The symbol lands unannotated (R?) without instance data; Annotate fixes it.
  • Placement is a commit at a point, not an interactive drag.

Follow-up route for the real feature

One embind export per editor feeding a pre-built item to SCH_ACTIONS::placeSymbol / PCB_ACTIONS::placeFootprint (both take an item and go interactive at the cursor, with normal undo), plus registering the file as a runtime lib via localFileLibsSource + kicadLibsAddEntry so the stock chooser lists it. The wx-side browser→canvas file DnD hook (registerDragDropHandlers / Module._OnFileDropped) exists but has no JS half yet.

🤖 Generated with Claude Code

…kicad_mod on the canvas

Proof of concept for plugin-style item ingress: a floating panel (session
menu → "Import from file") takes a symbol library or footprint file from the
user's machine (file picker or drag-and-drop onto the panel), lets them pick a
symbol when the library holds several, and places it where they next click on
the canvas (Esc cancels; viewport centre is the fallback).

No C++: the blob goes through the editors' existing collab items-apply
bridge (Module.kicadCollabApplyItems), i.e. the clipboard-paste parsers —
pcbnew takes a bare (footprint …) with an (at …) added, eeschema takes the
clipboard dialect (lib_symbols …) + (symbol …) so the definition travels with
the instance and a never-seen library works. The click maps CSS px → canvas px
(HiDPI) → world IU through kicadCollabGetViewport, same as the comment pins.

Known POC limits, documented in wasm/import-item.ts: the apply commits with
SKIP_UNDO and is folded into the collab baseline (not undoable, not broadcast
to peers); the symbol lands unannotated; placement is a commit, not an
interactive drag. The follow-up route is one embind export per editor feeding
placeSymbol / placeFootprint a pre-built item.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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