Opening: a design saved by 0.24 opens with its sketches in later versions (#8151) (#10379)

* claim: #8151

* Opening: a design saved by 0.24 keeps the body a Join To Object runs to (#8151)

Since 0.24.1 a Join extrude To Object also joins the body it runs to
(#6424). Designs saved by 0.24.0 and earlier were built without that,
so on 0.25 the reported box swallowed its lid: the lid's sketch, the
holes, the cut and the moves after it failed.

An extent may now save `to_body_apart: true`, which leaves that body
apart. One pending format change sets it on every Join extrude To
Object of a design of format 39 or older as it opens; designs of
format 40 and later keep the join. Editing the extrude keeps the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Markus Kaltenbrunner <kaltenbrunnermarkus@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kaltenbrunnermarkus
2026-11-02 18:13:04 +00:00
committed by GitHub
parent d7ad69e64f
commit 686056e4de
11 changed files with 139 additions and 2 deletions
+6
View File
@@ -1776,6 +1776,12 @@ fn redefine(s: &mut Session, p: &Value) -> Result<Value> {
*sketch = Some(*before);
*profiles = picked.clone();
}
// An old design's Join To Object keeps the body it runs to apart through an edit (#8151).
if let (FeatureKind::Extrude { extent: before, .. }, FeatureKind::Extrude { extent: after, .. }) = (&old.kind, &mut new.kind)
&& after.to.is_some()
{
after.to_body_apart = before.to_body_apart;
}
// A boundary surface's loop of sketch curves and its curve network are one command's two
// forms: an edit may turn one into the other.
let boundary = |k: &FeatureKind| matches!(k, FeatureKind::SurfaceBoundary { .. } | FeatureKind::SurfaceNetwork { .. });
+47
View File
@@ -230,3 +230,50 @@ fn join_extrude_to_another_body_joins_that_body() {
assert!((volume("Base") - 60_000.0).abs() < 1e-6, "the target took the tool: {}", volume("Base"));
assert_eq!(state.body("Base").unwrap().body.lumps().map_or(1, |l| l.len()), 1, "one piece");
}
/// #8151: a design saved before a Join To Object also joined the body it runs to (format 39 and
/// older) keeps that body apart when it opens, so its later features still find it, and an edit
/// of the extrude keeps it apart too.
#[test]
fn join_extrude_to_another_body_saved_before_it_joined_keeps_that_body() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length":40,"width":40,"height":10,"body_name":"Base"}));
run(&mut s, "solid.box", json!({"corner":[0,0,40],"length":40,"width":40,"height":20,"body_name":"Target"}));
let sketch = run(&mut s, "sketch.create", json!({"plane":{"face":[20,20,10]}}))["sketch"].as_u64().unwrap();
let plane = s.model.state().sketch(sketch).unwrap().plane;
let at = |x: f64, y: f64| {
let p = plane.to_local(Vec3::new(x, y, 10.0));
json!([p.x, p.y])
};
run(&mut s, "sketch.rectangle.two_point", json!({"p0": at(10.0,10.0), "p1": at(30.0,30.0)}));
run(&mut s, "sketch.finish", json!({}));
// A feature after the extrude names the body it runs to, as the lid's sketch and moves did.
// Today's join leaves no such body to name, so the move is made first and put last below.
let moved = run(&mut s, "solid.move", json!({"bodies":["Target"],"translate":[0,0,5]}))["feature"].clone();
let extrude = run(&mut s, "solid.extrude", json!({"sketch":sketch,"to":[20,20,40],"operation":"join","targets":["Base"]}))["feature"].clone();
let mut saved: Value = serde_json::from_str(&s.doc.to_json()).unwrap();
let features = saved["features"].as_array_mut().unwrap();
let at_move = features.iter().position(|f| f["id"] == moved).unwrap();
let feature = features.remove(at_move);
features.push(feature);
saved["format"] = json!("solidcraft/39");
saved.as_object_mut().unwrap().remove("format_pending");
let mut old = Session::new(solidcraft_doc::format::read(&saved.to_string()).unwrap());
let check = |s: &Session| {
assert!(s.model.results.iter().all(|r| r.error.is_none()), "{:?}", s.model.results);
let state = s.model.state();
let volume = |name: &str| solidcraft_kernel::measure(&state.body(name).unwrap().body).unwrap().volume;
assert_eq!(state.bodies.len(), 2, "the body the extrude runs to stays its own body");
assert!((volume("Base") - 28_000.0).abs() < 1e-6, "the base took the tool: {}", volume("Base"));
assert!((volume("Target") - 32_000.0).abs() < 1e-6, "the target is untouched: {}", volume("Target"));
};
check(&old);
run(
&mut old,
"timeline.redefine",
json!({"feature":extrude,"command":"solid.extrude","params":{"sketch":sketch,"to":[20,20,40],"operation":"join","targets":["Base"]}}),
);
check(&old);
// The design saves the choice and opens with it again.
check(&Session::new(solidcraft_doc::format::read(&old.doc.to_json()).unwrap()));
}
+1
View File
@@ -1209,6 +1209,7 @@ pub(super) fn extent_param(s: &Session, p: &Value, cmd: &str) -> Result<Extent>
to: p.get("to").and_then(vec3).map(FacePick),
to_offset: expr(p, "to_offset"),
from: p.get("from").and_then(vec3).map(FacePick),
to_body_apart: false,
})
}