Skip to content

feat(pcb): export pcb_copper_pour records as KiCad zones#299

Open
watcharaponthod-code wants to merge 5 commits intotscircuit:mainfrom
watcharaponthod-code:feat/add-copper-pour-export
Open

feat(pcb): export pcb_copper_pour records as KiCad zones#299
watcharaponthod-code wants to merge 5 commits intotscircuit:mainfrom
watcharaponthod-code:feat/add-copper-pour-export

Conversation

@watcharaponthod-code
Copy link
Copy Markdown

Summary

Fixes #284pcb_copper_pour records in circuit-json were silently dropped during KiCad PCB export. Opening the resulting .kicad_pcb showed zero (zone) blocks even when copper pours were present.

Root Cause

The PCB converter pipeline had stages for traces, vias, footprints, graphics, etc., but no stage existed to handle pcb_copper_pour elements. They were read into the circuit-json DB but never converted.

Fix

Added AddCopperPoursStage.ts — a new pipeline stage that:

  1. Reads all pcb_copper_pour records from the circuit-json DB
  2. Converts each to a KiCad (zone ...) block using the kicadts Zone class
  3. Handles the two common shapes:
    • rect → 4-corner rectangular polygon (with optional rotation support)
    • polygon → arbitrary polygon from the points array
  4. Resolves the net number/name from pcbNetMap via source_net_id
  5. brep shapes are logged and skipped (tessellation support is future work)

Registered the stage in CircuitJsonToKicadPcbConverter.ts between AddViasStage/AddStandalonePcbElements and AddGraphicsStage.

Tests

Added tests/pcb/basics/basics17-copper-pour.test.ts covering:

  • Rectangular pour → zone with 4 polygon corners on F.Cu
  • Polygon pour → zone with N polygon points on B.Cu
  • Empty circuit → no zone blocks emitted

Test plan

  • AddCopperPoursStage created with stage pattern matching existing stages
  • CircuitJsonToKicadPcbConverter pipeline updated
  • Tests cover rect, polygon, and empty-circuit cases
  • KiCad layer mapping (topF.Cu, bottomB.Cu) verified

🤖 Generated with Claude Code

… zones

Fixes tscircuit#284

Converts pcb_copper_pour records (rect and polygon shapes) from circuit-json
into KiCad (zone) blocks. BRep shapes are logged and skipped pending future
tessellation support.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
circuit-json-to-kicad Ready Ready Preview, Comment May 10, 2026 3:41pm

Request Review

The kicadts v0.0.25 Zone class uses raw PrimitiveSExpr children rather
than class-based properties. Replace ZoneNet/ZoneNetName/ZoneHatch etc.
imports (which don't exist in this version) with zone.rawChildren array
using nested PrimitiveSExpr tuples. Also fix inline import() type usage
by importing Matrix from transformation-matrix at the top level.

Fixes format-check and type-check CI failures.
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.

KiCad export drops <copperpour> — emits 0 (zone) blocks despite pcb_copper_pour records in circuit.json

1 participant