feat(pcb): translate pcb_copper_pour records to KiCad (zone …) blocks#285
Open
gsdali wants to merge 2 commits intotscircuit:mainfrom
Open
feat(pcb): translate pcb_copper_pour records to KiCad (zone …) blocks#285gsdali wants to merge 2 commits intotscircuit:mainfrom
gsdali wants to merge 2 commits intotscircuit:mainfrom
Conversation
Closes tscircuit#284. The PCB exporter previously emitted no `(zone)` blocks regardless of how many `pcb_copper_pour` records were in the input circuit JSON. Copper pours rendered correctly in gerber export (G36/G37 region commands) but were silently dropped on the KiCad path, so KiCad's pcbnew showed pads + traces + silkscreen but no ground plane. Add `AddCopperPoursStage`, slotted into the PCB pipeline after `AddViasStage`. For each `pcb_copper_pour`: - resolve the KiCad net via `source_net_id` → source_net's subcircuit_connectivity_map_key → pcbNetMap (same lookup pattern as AddViasStage) - map `layer` to the KiCad layer name via the existing layerMapping helper - transform `brep_shape.outer_ring.vertices` through the `c2kMatPcb` matrix to emit `(polygon (pts (xy …)))` - preserve `brep_shape.inner_rings` as additional `(polygon …)` children so KiCad subtracts them when refilling - assign a deterministic UUID Build the zone via `parseKicadSexpr` round-trip on a sexpr-string template, since `kicadts` exposes Zone primarily through that path. Tests: - 3 new tests in `tests/pcb/copperpour-zone-export.test.ts`: - basic pour with resolvable net → 1 zone, correct net id/name/layer - pour without source_net_id → falls back to net 0 - pour with inner_rings → emits both outline and cutout polygons - All previously-passing tests still pass (89/97; the 8 failing tests fail on `main` too — pre-existing unrelated issues with the KiCad-CLI snapshot fixtures) Smoke-tested against an InsightSiP ISP3080-UX daughter board (`circuit.json` with 4 pcb_copper_pour fragments, all on net.GND bottom layer): output `.kicad_pcb` contains 4 `(zone)` blocks each with `(net 1) (net_name GND) (layer B.Cu)` and the correct transformed polygon vertices. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #284.
The PCB exporter previously emitted no
(zone)blocks regardless of how manypcb_copper_pourrecords were in the input circuit JSON. Pours rendered correctly in gerber export (G36/G37 region commands inB_Cu.gbr/F_Cu.gbr) but were silently dropped on the KiCad path — so opening the resulting.kicad_pcbin pcbnew showed pads + traces + silkscreen but no ground plane.Fix
New
AddCopperPoursStageslotted into the PCB pipeline afterAddViasStage. For eachpcb_copper_pourrecord:source_net_id→ source_net'ssubcircuit_connectivity_map_key→pcbNetMap(same lookup pattern asAddViasStage).layerto the KiCad layer name via the existinggetKicadLayerhelper (bottom→B.Cu,inner1→In1.Cu, etc.).brep_shape.outer_ring.verticesthrough the existingc2kMatPcbmatrix (origin shift + Y-flip) to emit(polygon (pts (xy …))).brep_shape.inner_ringsas additional(polygon …)children so KiCad subtracts them when refilling.AddViasStage.Build the Zone via
parseKicadSexprround-trip on a sexpr-string template, sincekicadtsexposes Zone primarily through that path (the class itself is sparse —rawChildrenonly).Test plan
tests/pcb/copperpour-zone-export.test.ts:(net 1) (net_name GND) (layer B.Cu)source_net_id→ falls back to(net 0)maintoo (pre-existing unrelated issues with the KiCad-CLI snapshot fixtures — verified viagit stash && bun test <failing> && git stash popround-trip)bun run typecheck: cleanbiome format: cleanSmoke test against a real board
Tested against an InsightSiP ISP3080-UX daughter board (
circuit.jsonwith 4pcb_copper_pourfragments, all onnet.GND, bottom layer). Output.kicad_pcbcontains 4(zone)blocks each with(net 1) (net_name GND) (layer B.Cu)and correctly transformed polygon vertices:What's not in this PR
(polygon)children rather than as parts of a(filled_polygon). This works for the "outline as input to refill" model but the visual representation in pcbnew before refill may show outline-only. After Edit → Fill All Zones (B), the actual fill matches the source pour intent.🤖 Generated with Claude Code