Frames: a renamed cut-off piece keeps its name when the design is rebuilt from its features (#10438) (#10466)

* Frames: test that a renamed cut-off piece keeps its name in a rebuild from the features alone (#10438)

solidcraft-cli eval rebuilds a saved design without its saved model; the
rename made after a cut then lands on the first line's member. The test
reproduces it on main; the fix follows.

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

* Frames: a renamed cut-off piece keeps its name when the design is rebuilt from its features (#10438)

Since #10132 a cut's pieces past the first belong to the cut and the piece
that keeps the body's name to the body's own feature. Ordering the pieces
by their faces then moved the names among them but left each body's
feature behind, so the cut-off piece said the frame member feature made
it. body.rename stored its new name there, in the first line's slot, and a
rebuild from the features alone (solidcraft-cli eval of the saved file)
named member A after it. A name now moves together with the feature it
belongs to.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-11-01 06:43:40 +00:00
committed by GitHub
parent d96d547f6b
commit 38b9ff223b
2 changed files with 14 additions and 2 deletions
+6 -2
View File
@@ -587,10 +587,14 @@ pub(crate) fn order_lumps(bodies: &mut [crate::ModelBody], origin: &Arc<crate::n
let keys: Option<Vec<(String, usize)>> = members.iter().map(|i| bodies.get(*i).and_then(least).map(|k| (k, *i))).collect();
let Some(mut keys) = keys else { continue };
keys.sort();
let names: Vec<String> = members.iter().filter_map(|i| bodies.get(*i).map(|b| b.name.clone())).collect();
for (name, (_, i)) in names.into_iter().zip(keys) {
// A name moves with the feature it belongs to: in a cut's family the first name is the
// cut body's own feature's and the rest are the cut's, and `body.rename` stores a name in
// the `body_names` of the feature a body says made it (#10438).
let names: Vec<(String, u64)> = members.iter().filter_map(|i| bodies.get(*i).map(|b| (b.name.clone(), b.feature))).collect();
for ((name, feature), (_, i)) in names.into_iter().zip(keys) {
if let Some(b) = bodies.get_mut(i) {
b.name = name;
b.feature = feature;
}
}
}
+8
View File
@@ -1588,10 +1588,18 @@ mod tests {
assert_eq!(sorted(names(&s)), ["A", "B", "B (1)", "Cutter"]);
run(&mut s, "body.rename", json!({"body": "B (1)", "name": "B2"}));
assert_eq!(sorted(names(&s)), ["A", "B", "B2", "Cutter"]);
// The new name is the cut's second piece's, stored by the cut, not in the members' slots.
let stored = |id: u64| s.doc.features.iter().find(|f| f.id == id).map(|f| f.body_names.clone()).unwrap_or_default();
assert!(!stored(2).contains(&"B2".to_string()), "members: {:?}", stored(2));
assert_eq!(stored(4), ["B2"], "the cut stores its piece's name");
run(&mut s, "file.save_as", json!({"path": saved.to_string_lossy()}));
let mut reopened = Session::default();
run(&mut reopened, "doc.open", json!({"path": saved.to_string_lossy()}));
assert_eq!(sorted(names(&reopened)), ["A", "B", "B2", "Cutter"], "the rename must not move to member A on rebuild");
// `solidcraft-cli eval` of the saved file rebuilds it from its features alone, with no
// saved model to take the names from (#10438).
let rebuilt = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
assert_eq!(sorted(names(&rebuilt)), ["A", "B", "B2", "Cutter"], "a rebuild from the features alone keeps the rename too");
let _ = std::fs::remove_dir_all(&dir);
}