feat(solver): pack SolveContext into .kc archives on save (#289 phase 3d) #302

Merged
forbes merged 1 commits from feat/solver-context-packing into main 2026-02-21 00:03:15 +00:00
Owner

Summary

Expose AssemblyObject::getSolveContext() to Python and hook into the .kc save flow so that silo/solver/context.json is packed into every assembly archive on save. This lets server-side solver runners operate on pre-extracted constraint graphs without a full FreeCAD installation.

Implements phase 3d of #289.

Changes

  • AssemblyObject.h/.cpp — Add public getSolveContext() that mirrors the setup in solve() (clear maps → get grounded → get joints → build context) but skips solver invocation, placement updates, and undo tracking
  • AssemblyObject.pyi — Python stub for getSolveContext() -> dict
  • AssemblyObjectPyImp.cpp — CPython C API implementation that converts the C++ SolveContext struct to a Python dict matching kcsolve.SolveContext.to_dict() format exactly (enum-to-string switch tables + Py::Dict/Py::List builders for all nested types)
  • kc_format.py — Register _solver_context_hook as a pre-reinject hook: on every .kc save, if the document contains an Assembly::AssemblyObject, extracts the context and packs it as silo/solver/context.json
  • silo_tree.py — Add silo/solver/context.json to _KNOWN_ENTRIES so it appears in the document tree

Testing

  • Build passes clean (cmake --build build/release --target Assembly)
  • Smoke test: assembly.getSolveContext() returns a dict with keys api_version, parts, constraints, motions, simulation, bundle_fixed
  • Round-trips via kcsolve.SolveContext.from_dict(ctx)
  • Non-assembly .kc files: silo/solver/context.json is not present
## Summary Expose `AssemblyObject::getSolveContext()` to Python and hook into the `.kc` save flow so that `silo/solver/context.json` is packed into every assembly archive on save. This lets server-side solver runners operate on pre-extracted constraint graphs without a full FreeCAD installation. Implements phase 3d of #289. ## Changes - **AssemblyObject.h/.cpp** — Add public `getSolveContext()` that mirrors the setup in `solve()` (clear maps → get grounded → get joints → build context) but skips solver invocation, placement updates, and undo tracking - **AssemblyObject.pyi** — Python stub for `getSolveContext() -> dict` - **AssemblyObjectPyImp.cpp** — CPython C API implementation that converts the C++ `SolveContext` struct to a Python dict matching `kcsolve.SolveContext.to_dict()` format exactly (enum-to-string switch tables + Py::Dict/Py::List builders for all nested types) - **kc_format.py** — Register `_solver_context_hook` as a pre-reinject hook: on every `.kc` save, if the document contains an `Assembly::AssemblyObject`, extracts the context and packs it as `silo/solver/context.json` - **silo_tree.py** — Add `silo/solver/context.json` to `_KNOWN_ENTRIES` so it appears in the document tree ## Testing - Build passes clean (`cmake --build build/release --target Assembly`) - Smoke test: `assembly.getSolveContext()` returns a dict with keys `api_version`, `parts`, `constraints`, `motions`, `simulation`, `bundle_fixed` - Round-trips via `kcsolve.SolveContext.from_dict(ctx)` - Non-assembly `.kc` files: `silo/solver/context.json` is not present
forbes added 1 commit 2026-02-20 23:13:01 +00:00
feat(solver): pack SolveContext into .kc archives on save (#289 phase 3d)
All checks were successful
Build and Test / build (pull_request) Successful in 29m51s
4cf54caf7b
Expose AssemblyObject::getSolveContext() to Python and hook into the
.kc save flow so that silo/solver/context.json is packed into every
assembly archive. This lets server-side solver runners operate on
pre-extracted constraint graphs without a full FreeCAD installation.

Changes:
- Add public getSolveContext() to AssemblyObject (C++ and Python)
- Build Python dict via CPython C API matching kcsolve.SolveContext.to_dict()
- Register _solver_context_hook in kc_format.py pre-reinject hooks
- Add silo/solver/context.json to silo_tree.py _KNOWN_ENTRIES
forbes merged commit 805be1e213 into main 2026-02-21 00:03:15 +00:00
forbes deleted branch feat/solver-context-packing 2026-02-21 00:03:15 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#302