Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Mirror and Pattern: a body feature reopens with Bodies and its Operation (#8207) (#8298)

semmelrindebcb67cc2ec99
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 6b1865bb42..ea16cd7d68 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -5653,12 +5653,17 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
}
d
}
- FeatureKind::Mirror { features, plane, bodies, placements, .. } => {
+ FeatureKind::Mirror { features, plane, bodies, placements, combine } => {
let mut d = start("solid.mirror")?;
let ids: Vec<u64> = features.iter().map(|f| f.0).collect();
// Replay references stay features, including features that created a body.
let as_features = !features.is_empty();
if let Some(inp) = d.inputs.get_mut(0) {
+ if !as_features {
+ // Bodies, though the editor opened with this feature selected in the timeline (#8207).
+ inp.accept = BODIES;
+ inp.label = objects_label(inp.accept);
+ }
if !bodies.is_empty() {
// Each body as the placement it was mirrored at shows it (an instance by its world name).
let own = s.model.state();
@@ -5678,6 +5683,10 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
if let Some(inp) = d.inputs.get_mut(1) {
inp.items = plane_sel(s, plane).into_iter().collect();
}
+ // Body copies are a new body or joined to their source; a feature replay keeps its own operation.
+ if !as_features {
+ d.extra.insert("combine".into(), json!(combine));
+ }
d
}
FeatureKind::Pattern { features, pattern, bodies: copied } => {
@@ -5755,6 +5764,8 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
inp.label = objects_label(inp.accept);
inp.items = ids.iter().map(|id| Sel::Feature { id: *id }).collect();
} else {
+ inp.accept = BODIES;
+ inp.label = objects_label(inp.accept);
inp.items = bodies;
}
}
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs
index ba2318280b..9d08722f79 100644
--- a/crates/ui-egui/src/preselect_tests.rs
+++ b/crates/ui-egui/src/preselect_tests.rs
@@ -163,6 +163,45 @@ fn feature_mirror_and_patterns_reopen_as_feature_replays_even_for_body_creators(
}
}
+/// #8207: a Mirror of bodies reopens with its bodies and its Operation (Join or New Body), and OK
+/// keeps it so, also when the editor opens with the feature selected in the timeline (which
+/// otherwise turns a pattern's objects into features). A body pattern reopens with bodies too.
+#[test]
+fn a_body_mirror_reopens_with_its_bodies_and_operation() {
+ for (combine, from_timeline) in [(true, false), (true, true), (false, true)] {
+ let mut app = app_with(json!([
+ {"command":"solid.box","params":{"corner":[40,0,0],"length":2,"width":2,"height":2,"name":"Base"}}
+ ]));
+ let body = app.session.world_state().bodies[0].name.clone();
+ app.session.execute("solid.mirror", &json!({"bodies":[body],"plane":"YZ","combine":combine})).unwrap();
+ let feature = app.session.doc.features.last().unwrap().clone();
+ app.session = Session::new(solidcraft_engine::doc::Document::from_json(&app.session.doc.to_json()).unwrap());
+ if from_timeline {
+ app.session.selection = vec![Sel::Feature { id: feature.id }];
+ }
+ let at = format!("combine {combine}, from the timeline {from_timeline}");
+ let d = crate::dialogs::for_feature(&app, feature.id, None).unwrap();
+ assert_eq!(d.inputs[0].accept, crate::selection::BODIES, "{at}: the Object Type stays Bodies");
+ assert_eq!(d.inputs[0].items, vec![Sel::Body { name: body.clone() }], "{at}");
+ assert_eq!(d.extra.get("combine"), Some(&json!(combine)), "{at}: the Operation stays as it was made");
+ let (edit, p) = apply_commands(&app, &d).unwrap().remove(0);
+ assert_eq!(edit, "timeline.redefine");
+ assert_eq!(p["params"]["bodies"], json!([body]), "{at}");
+ app.session.execute(&edit, &p).unwrap();
+ assert_eq!(app.session.doc.feature(feature.id).unwrap().kind, feature.kind, "{at}: accepting the reopened editor preserves it");
+ }
+ let mut app = app_with(json!([
+ {"command":"solid.box","params":{"corner":[40,0,0],"length":2,"width":2,"height":2,"name":"Base"}}
+ ]));
+ let body = app.session.world_state().bodies[0].name.clone();
+ app.session.execute("solid.pattern.rectangular", &json!({"bodies":[body],"dir1":[1,0,0],"count1":3,"spacing1":5})).unwrap();
+ let feature = app.session.doc.features.last().unwrap().clone();
+ app.session.selection = vec![Sel::Feature { id: feature.id }];
+ let d = crate::dialogs::for_feature(&app, feature.id, None).unwrap();
+ assert_eq!(d.inputs[0].accept, crate::selection::BODIES, "a body pattern reopens with bodies");
+ assert_eq!(d.inputs[0].items, vec![Sel::Body { name: body }]);
+}
+
/// #3567: an Offset Plane built on a face reopened with its Plane input empty when the face's
/// plane origin lay off the face (here the world origin's foot, beside the box), so OK asked to
/// pick a plane first. It reopens with the face, and OK keeps the plane on it.