Skip to content

Layout engine drops module view elements during diagram regeneration #340

@bpowers

Description

@bpowers

Summary

The generate_best_layout function in src/simlin-engine/src/layout/mod.rs explicitly skips Variable::Module elements (lines 1768, 2144, 2153-2158). When sync_diagram regenerates the diagram layout (e.g., after MCP edits via EditModel), any module view elements in the original diagram are silently dropped from the output.

Impact

A user could open an existing XMILE or Vensim file containing modules, edit a variable via the MCP EditModel tool (in src/simlin-mcp), and the subsequent diagram regeneration would permanently remove module view elements from the persisted file. This is silent data loss -- the model equations remain intact, but the visual representation of modules in the diagram is destroyed.

Currently the MCP server does not expose module creation/editing operations, so the scope is limited to models that already contain modules being edited through non-module operations. However, as MCP functionality expands, this gap becomes more significant.

Components affected

  • src/simlin-engine/src/layout/mod.rs -- generate_best_layout function
  • src/simlin-mcp -- sync_diagram calls generate_best_layout after model edits

Possible approaches

  1. Preserve existing module view elements: During layout regeneration, carry forward any ViewElement::Module entries from the original view that correspond to module variables still present in the model. This is the simpler fix and avoids needing full module layout support.
  2. Add module support to the layout engine: Teach generate_best_layout to position module elements alongside stocks, flows, and auxiliaries. This is the more complete fix but requires more work.

Approach (1) is likely sufficient for now and avoids introducing layout heuristics for modules.

Context

Identified during review of the layout engine's interaction with the MCP server's sync_diagram path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingengineIssues with the rust-based simulation enginelayoutDiagram auto-layout engine

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions