Skip to content

Fix copper layer stackup ordering - #4

Open
PoeAlex wants to merge 4 commits into
codex/add-gui-options-for-polygon-handlingfrom
codex/fix-layer-order-and-bottom-index-issue
Open

PoeAlex wants to merge 4 commits into
codex/add-gui-options-for-polygon-handlingfrom
codex/fix-layer-order-and-bottom-index-issue

Conversation

@PoeAlex

@PoeAlex PoeAlex commented Jan 4, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The previous layer detection built copper_ids from enabled layers and then sorted them, which could place B.Cu not at the last index and cause incorrect top/bottom mapping and physics at outer faces.
  • Need to preserve the actual stackup order provided by modern KiCad APIs so top/bottom indices are correct for plotting and cooling.

Description

  • Prefer stackup-derived sequence by calling GetLayerStackup/GetStackup and iterating GetCopperLayers/GetLayerSequence/GetLayers when available to preserve real stack order.
  • Add an add_unique helper to de-duplicate layer IDs while preserving discovered order and ensure layers are enabled and pcbnew.IsCopperLayer before inclusion.
  • Provide fallbacks to GetCopperLayerCount and constants like pcbnew.F_Cu, pcbnew.In1_Cu, pcbnew.B_Cu, and finally a legacy numeric scan over layer IDs for older KiCad versions.
  • Rebuild layer_names from the final ordered copper_ids so plotting and top/bottom references are correct.

Testing

  • No automated tests were executed because the plugin environment / KiCad API is not available in CI for this change.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant