feat(product): multi-body parts: a Part holds one Solid or several named bodies

Spike of design-docs/multi-solid-design.md. make_part_rpart(bodies={id: solid})
keeps several solids apart in one Part (not an assembly): Body values with
stable ids, Part.bodies / get_body / body_ids; Part.body raises on a multi-body
part instead of returning one body. Recorded and replayed, pickled for the cell
cache, previewed as one node per body (node/<part>/body:<id>), packaged with a
BRep and topology snapshot per body (solid_cache.bodies; one-body manifests are
byte-identical), drawn as solid child nodes in the package scene, exported to
STEP as one product holding every solid, flattened into assemblies, and weighed
per body by the new measure_part_mass_rmassreport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiJingzhe
2026-11-04 03:57:27 +08:00
parent 093ef71e53
commit b607c85248
41 changed files with 1162 additions and 99 deletions
@@ -52,6 +52,26 @@ inline sp::OptionalString optional_name(const py::object& value) {
return py::str(value).cast<std::string>();
}
// The bodies of a multi-body Part: a mapping body_id -> Solid (in its order), or a sequence of Body values.
inline std::vector<sp::Body> body_list(const py::object& value) {
std::vector<sp::Body> out;
if (py::isinstance<py::dict>(value) || py::hasattr(value, "items")) {
for (const py::handle item : value.attr("items")()) {
const py::tuple pair = py::reinterpret_borrow<py::tuple>(item);
out.emplace_back(text(py::reinterpret_borrow<py::object>(pair[0]), "body_id"),
typed<Solid>(py::reinterpret_borrow<py::object>(pair[1]), "bodies values must be Solids"));
}
return out;
}
if (py::isinstance<py::str>(value) || !py::isinstance<py::sequence>(value))
throw scad::TypeError("bodies must be a mapping body_id -> Solid or a sequence of Body values");
for (const py::handle item : value) {
out.push_back(typed<sp::Body>(py::reinterpret_borrow<py::object>(item),
"bodies must be a mapping body_id -> Solid or a sequence of Body values"));
}
return out;
}
inline scad::Scalar scalar(const py::object& value, const char* field) {
try {
return value.cast<scad::Scalar>();