Commit Graph

6 Commits

Author SHA1 Message Date
Ni Jingzhe 654a6d3e33 part: a Part holds exactly one solid (the constructor refuses several; make_part_rpart and Part lose bodies=)
DECISION: the product item `Part` is one solid again. The multi-body Part added on 2026-11-04
(b607c852, design-docs/multi-solid-design.md) is withdrawn. This commit is the C++ half; the Python
consumers, the editor and the docs follow in the later commits of this series, one decision each.

WHY - THE DISCUSSION THIS DECISION COMES FROM (owner and assistant, 2026-11-10)
1. Why a Part was ever allowed several solids (the owner's account). The editor must support several
   solids existing in one notebook with no assembly constraint between them: to pattern a tool and then
   cut, there is necessarily a moment where more than one tool and the body exist together. That is easy
   to understand and it is a real need. At the time the Part was the only product value a notebook could
   end in, so the Part was made to hold several named bodies.
2. Why it is the wrong place (the owner's judgement). It makes assembly hard. The whole design was made
   for a human-friendly editor and it led to a wrong decision: a multi-solid Part. The question put was:
   should we go back to "a Part has exactly one solid" and support the editor some other, better way?
3. The assistant's analysis, which the owner accepted. The solids side by side in the pattern-then-cut
   example are INTERMEDIATE VALUES OF A NOTEBOOK, not product items. A Part is a line of the bill of
   materials and the unit an Assembly places, mates and gives connectors to; "the working set of solids
   while modelling" and "the product" were two levels that got mixed. The editor's need is a PREVIEW /
   notebook-value need (show every open solid), and a deliverable that really is several solids is an
   Assembly of Parts. So: Part = one solid; the editor shows open solids as loose values (later commit).
4. Urgency. The owner asked for the audit and the change at once because the multi-body Part might be a
   malignant bug in the released 2.2.8; its GitHub release was deleted on 2026-11-10 while this was done.

WHAT THE AUDIT FOUND (checked on 2026-11-10 against the code and by running it)
- Connectors on a multi-body Part were refused outright (Part constructor, part.cpp), so no mate, no
  public connector and no ConnectorRef could ever reach one: it could join an assembly only as a rigid
  blob placed by its origin.
- explode_rassembly raised TypeError on any assembly that held one (ops_explode.cpp collect_box called
  Part::body(), which throws for a multi-body Part).
- The scene compiler scene/compiler.py read part.body in four places (compile_scene fails on a
  multi-body Part). Every consumer needed a second code path, and some were missed. Not yet checked:
  joint / constraint solving, interference and MJCF paths (they depend on connectors anyway).

ALTERNATIVE CONSIDERED AND REJECTED: keep multi-body Parts and finish stage 3 of the design (a
connector anchored by body_id + entity). It changes the part-definition contract, the interface and
binding hashes and the entity bindings, and it still leaves a concept that overlaps with Assembly (a
multi-body part is "an assembly without constraints").

WHAT THIS COMMIT DOES
- The invariant is enforced in the lowest layer so that every consumer can rely on it instead of each
  branching on `multi_body`: Part(std::vector<Body>) throws ValueError unless there is exactly one body,
  and the message says what to do (one Part per solid in an Assembly, or union / cut to one solid).
  Part::multi_body() is gone.
- Binding: make_part_rpart(part_id, body, name) and Part(part_id, body, ...) take one Solid, one Body, or
  a list of exactly one piece. `bodies=` is removed (TypeError: unexpected keyword); more than one piece
  is a ValueError with the same guidance. Part(body=Body) is how a body that carries a name / colour /
  opacity survives pickling and copying (it replaces Part(bodies=(Body,))).
- The make_part_rpart(vector<Body>) overload and the mapping / sequence parsing helpers are removed.

KEPT ON PURPOSE: Body (it carries the body's display name, colour and opacity), Part::bodies() (always
one element), body_ids(), get_body(), set_body_appearance_rpart: one-body Parts already use them and
removing them would only churn the one-body path, which did not break.

Verified with the native module directly: a Solid, a one-element list and a Body are accepted; `bodies=`,
two solids and Part(body=[a, b]) are refused with the guidance.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 03:48:34 +08:00
NiJingzhe 4ff66173c5 feat(product): set_body_appearance_rpart: a display colour, opacity and name per body
A Body carries an optional colour (RGB in [0, 1], typed simplecadapi.types.Color,
catalog kind 'color') and opacity. The material colour is the default; a body
colour overrides it for display only (mass never reads it). The op is recorded
(make_set_body_appearance_rpart) and replayed, pickles for the cell cache, and
reaches the live preview (node color/opacity), the legacy scene compiler
(base_color), the part definition (optional 'appearance' block in profiles 2
and 3; a definition without one keeps its bytes), the package scene (node
properties.color/opacity) and STEP (part colour, or a named and coloured XCAF
sub-shape per body). Material.color is typed Color too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:12:12 +08:00
NiJingzhe 9778a8e0a9 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>
2026-11-04 04:46:26 +08:00
NiJingzhe b607c85248 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>
2026-11-04 03:57:27 +08:00
NiJingzhe 7edd550f29 style: add .clang-format and format the C++ tree with it
One mechanical pass (clang-format 18.1.8, Google base, 120 columns, T& x, includes untouched). Nothing but whitespace and
line breaks moves; tools/check_format.sh lists what would change and CI runs it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:28:29 +08:00
NiJingzhe 8971279494 feat: the geometry engine is C++ on OpenCASCADE, one package, prebuilt wheels
The modeling API (shapes, operators, sketches, products, queries, the reactive graph) is implemented in
C++20 on OpenCASCADE (src/cpp) and ships inside the wheel as simplecadapi._cpp.  The Python layers that stay
Python (runtime, build, artifacts, editor, inspect, exporter, translators, scene) run on it unchanged; the
previous Python test suite passes on the new engine.

Layout: src/cpp and src/simplecadapi side by side, one distribution built by scikit-build-core.
simplecadapi.core, .operators.*, .ql, .std.* and the other legacy modules are real forwarding modules; the
Python adapter layer is simplecadapi/_glue.  OCP is no longer a dependency and nothing imports it.

Release: .github/workflows/release.yml builds wheels for Linux x86_64 and aarch64, macOS arm64 and Windows
x86_64 (Python 3.10-3.13) against one static OCCT, runs the test suite on the Linux wheels and publishes to
GitHub and PyPI; ci.yml caches the static OCCT for the test jobs.

Errors: every message the library writes is English; the tag-validation and semantic-query errors render in
full with possible causes and fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 02:55:35 +08:00