feat(product): owner decisions on multi-body parts
- A cut that splits the body is no longer refused: cut_rsolid(on_split="pieces")
(the default) returns every piece as list[Solid] ordered by centroid, recorded as
make_cut_rsolid_list with piece_order=centroid and replayed in that order;
on_split="error" keeps the strict contract. One-piece cuts are unchanged.
- Pieces become bodies: make_part_rpart(body=pieces) -> body_1..n,
bodies={"bar": pieces} -> bar_1..n.
- Overlapping bodies are allowed and warned: inspect_body_overlaps_rlist and a
BodyOverlapWarning when the definition is built.
- Multi-body definitions use profile simplecad-part-definition-3 (new schema);
profile 2 is back to its dev bytes, so profile-2 readers refuse them.
- part_from_bodies: the implicit-Part rule (all open bodies, named by variable).
- Skill pages, API docs, stubs, design doc section 9, SDK defect 24.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,14 +52,35 @@ 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.
|
||||
// True for a list or tuple of Solids: the pieces of a cut that split a body.
|
||||
inline bool is_pieces(const py::object& value) {
|
||||
return (py::isinstance<py::list>(value) || py::isinstance<py::tuple>(value)) && py::len(value) > 0 &&
|
||||
py::isinstance<Solid>(py::reinterpret_borrow<py::object>(value[py::int_(0)]));
|
||||
}
|
||||
|
||||
// One mapping entry: a Solid is one body; the pieces of a split cut are bodies <id>_1 .. <id>_n (one piece keeps <id>).
|
||||
inline void add_bodies(std::vector<sp::Body>& out, const std::string& body_id, const py::object& value) {
|
||||
if (!is_pieces(value)) {
|
||||
out.emplace_back(body_id, typed<Solid>(value, "bodies values must be Solids or lists of Solids"));
|
||||
return;
|
||||
}
|
||||
const py::sequence pieces = py::reinterpret_borrow<py::sequence>(value);
|
||||
const std::size_t count = pieces.size();
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
out.emplace_back(count == 1 ? body_id : body_id + "_" + std::to_string(index + 1),
|
||||
typed<Solid>(py::reinterpret_borrow<py::object>(pieces[index]),
|
||||
"bodies values must be Solids or lists of Solids"));
|
||||
}
|
||||
}
|
||||
|
||||
// The bodies of a multi-body Part: a mapping body_id -> Solid or pieces (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"));
|
||||
add_bodies(out, text(py::reinterpret_borrow<py::object>(pair[0]), "body_id"),
|
||||
py::reinterpret_borrow<py::object>(pair[1]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user