feat(kcsolve): pybind11 bindings and Python solver support #298
Reference in New Issue
Block a user
Delete Branch "feat/solver-api-types"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Phase 2 of the pluggable solver system (#288): exposes the KCSolve C++ API to Python via pybind11, enabling scripted solver access and pure-Python solver backends.
Builds on Phase 1 (PR #297) which introduced the
IKCSolverinterface,SolverRegistry, andOndselAdapter.Changes
New files
Solver/bindings/PyIKCSolver.h— pybind11 trampoline class enabling PythonIKCSolversubclasses. UsesPYBIND11_OVERRIDE_PUREfor 3 pure virtuals (name,supported_joints,solve) andPYBIND11_OVERRIDEfor 10 defaulted virtuals.Solver/bindings/kcsolve_py.cpp— Complete pybind11 module (import kcsolve):BaseJointKind(24 values),SolveStatus,DiagnosticKind,MotionKind,LimitKindTransform,Part,Constraint+Limit,MotionDef,SimulationParams,SolveContext,ConstraintDiagnostic,SolveResult+PartResultIKCSolver(with trampoline),OndselAdapterSolverRegistry:available(),load(),joints_for(),set_default(),get_default(),register_solver()PySolverHolder— forwards all virtual calls with GIL acquisition, prevents Python GC of solver instancesAPI_VERSION_MAJOR = 1Solver/bindings/CMakeLists.txt— pybind11 build target following thetsp_solverpattern. Output placed inMod/Assembly/askcsolve.so.AssemblyTests/TestKCSolvePy.py— 16 Python tests across 4 classes:TestKCSolveImport— module loads, key symbols exist, API versionTestKCSolveTypes— Transform identity, Part defaults, SolveContext construction, enum values, Constraint/SolveResult fieldsTestKCSolveRegistry— available(), load(), unknown solver handling, default managementTestPySolver— Python subclass instantiation, solve round-trip, register/load/solve full cycle, default virtual methodsModified files
IKCSolver.h— Constructor moved fromprotectedtopublicfor pybind11 trampoline access. Class remains abstract (3 pure virtuals prevent direct instantiation).Solver/CMakeLists.txt—add_subdirectory(bindings)gated onFREECAD_USE_PYBIND11CMakeLists.txt— AddedTestKCSolvePy.pytoAssemblyTests_SRCSTestAssemblyWorkbench.py— Registered 4 new test classesUsage
Testing
KCSolve_tests_run) — no regressionsTestKCSolvePy)Closes #288