Skip to content

feat(layout): add --only-new incremental placement mode - #14

Open
tobsch wants to merge 1 commit into
eisber:mainfrom
tobsch:feat/layout-only-new
Open

feat(layout): add --only-new incremental placement mode#14
tobsch wants to merge 1 commit into
eisber:mainfrom
tobsch:feat/layout-only-new

Conversation

@tobsch

@tobsch tobsch commented Aug 25, 2026

Copy link
Copy Markdown

What

Adds an incremental mode to config layout. Today config layout re-arranges the whole page (grid_layout). With this PR:

lox config layout config.Loxone            # unchanged: re-layout whole page
lox config layout config.Loxone --only-new # NEW: place only unpositioned blocks

--only-new positions only blocks that have no Px yet and leaves every already-positioned block byte-identical.

Why

After config add, new blocks land at no coordinates while the rest of the page is already laid out by hand. Re-running the full layout throws that hand-work away. Un-positioned blocks also trip the check warning:

missing canvas layout (Px/Py/Px2/Py2) — Loxone Config will repair this block on first save and may drop wires

--only-new clears exactly those blocks without touching the existing diagram — so the editor won't "repair" (and possibly re-wire) them on first save.

How

incremental_layout() does a small Sugiyama-style layered layout over just the new blocks:

  • layer = longest path over the sub-DAG of new blocks (only predecessors that are themselves new count)
  • order within a layer by barycenter of predecessor rows (crossing reduction)
  • coordinates snapped to the 96-unit editor grid, anchored in the free area to the right of the page's existing content (max Px2 + gap)

Existing blocks are never re-read for placement, so their coordinates are preserved exactly.

Verification

On a real ~500-block house config with 9 freshly-added logic gates (Or/And/Not chain):

  • 9 gates placed in clean left→right layers (layer 0 → 1 → 2)
  • 498 already-positioned blocks: 0 changed
  • config validate0 errors
  • the 9 missing canvas layout warnings cleared

Adds two unit tests (incremental_places_only_new_in_layers, incremental_noop_when_all_positioned). Full suite green (406 tests).

Notes

🤖 Generated with Claude Code

`config layout` currently re-arranges the whole page (grid_layout). After
`config add`, new blocks land without coordinates while the rest of the page is
already laid out by hand — re-running the full layout throws that hand-work away.

Add `--only-new`: position ONLY blocks that have no `Px`, leaving every
already-positioned block byte-identical. New blocks are placed with a
Sugiyama-style layered layout so they flow left→right along their wiring:

- layer = longest path over the sub-DAG of new blocks (predecessors that are
  themselves new)
- order within a layer by barycenter of predecessor rows (fewer crossings)
- coordinates snapped to the 96-unit editor grid, anchored in the free area to
  the right of the page's existing content

Motivation: clears the "missing canvas layout — Loxone Config will repair this
block on first save and may drop wires" warning without disturbing the existing
diagram. Verified on a real 500-block config: 9 added logic gates placed in
clean layers, 498 positioned blocks unchanged, `config validate` 0 errors.

Adds `incremental_layout()` + two unit tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TT6BSmf3uXakmtfexfDt
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.

1 participant