SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Mirror keeps the preselected feature when the object type changes (#5288) (#5453)
raykholo26340882c04c
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 2031a062da..04b79b59c3 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -452,6 +452,8 @@ pub struct Dialog {pub(crate) picked_edges: Vec<Sel>,/// Whether `inputs[0]` currently includes the tangent chains of `picked_edges`.pub(crate) chain_applied: bool,+ /// A pattern's objects of the Object Type not shown now, restored when it is chosen again.+ pub(crate) other_objects: Vec<Sel>,/// Shell feedback is derived from the picks, never saved as additional face references.shell_chain: std::cell::RefCell<Option<ShellChain>>,/// An extrude Press Pull opened with nothing selected: its first pick may be a curved face or@@ -635,6 +637,7 @@ impl Dialog {then_start: None,picked_edges: Vec::new(),chain_applied,+ other_objects: Vec::new(),shell_chain: Default::default(),press_pull: false,}@@ -1944,7 +1947,10 @@ fn object_type_row(d: &mut Dialog, ui: &mut egui::Ui) {if ty != cur {inp.accept = if ty == 1 { selection::FEATURES } else { BODIES };inp.label = objects_label(inp.accept);- inp.items.clear();+ // The pre-selection moved into this input when the dialog opened, so switching back+ // restores what the other type held instead of losing it.+ let back = std::mem::take(&mut d.other_objects);+ d.other_objects = std::mem::replace(&mut inp.items, back);d.active = 0;}}diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rsindex 16b4520b98..1486a62d17 100644--- a/crates/ui-egui/src/dialogs_all_tests.rs+++ b/crates/ui-egui/src/dialogs_all_tests.rs@@ -251,6 +251,60 @@ form_case!(revolve, "solid.revolve", ["Angle", "Direction", "Type"]);form_case!(shell, "solid.shell", ["Thickness", "Direction"]);form_case!(draft, "solid.draft", ["Angle"]);form_case!(mirror, "solid.mirror", ["Operation"]);++fn mirror_preselection() -> (Harness, Vec<Sel>) {+ let mut h = Harness::new();+ h.app.run("sketch.create", json!({"plane":"XY","name":"Sketch1"})).unwrap();+ h.app.run("sketch.rectangle.two_point", json!({"p0":[2,2],"p1":[6,6]})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ h.app.run("solid.extrude", json!({"sketch":"Sketch1","distance":5})).unwrap();+ let id = h.app.session.doc.features.iter().find(|f| f.name == "Extrude1").unwrap().id;+ let picked = vec![Sel::Feature { id }];+ h.app.session.selection = picked.clone();+ h.app.start("solid.mirror");+ h.frames(4);+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, picked);+ (h, picked)+}++fn mirror_object_type(h: &mut Harness, choice: &str) {+ h.step(&json!({"click":{"handle":"dialog:Object Type"}})).unwrap();+ h.step(&json!({"click":{"handle":format!("dialog:Object Type:{choice}")}})).unwrap();+}++#[test]+fn mirror_object_type_switch_back_restores_preselected_feature() {+ let (mut h, picked) = mirror_preselection();+ mirror_object_type(&mut h, "Bodies");+ assert!(h.app.dialog.as_ref().unwrap().inputs[0].items.is_empty());+ mirror_object_type(&mut h, "Features");+ let d = h.app.dialog.as_mut().unwrap();+ assert_eq!(d.inputs[0].items, picked);+ d.inputs[1].items = vec![Sel::Plane { name: "YZ".into() }];+ let commands = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();+ assert_eq!(commands[0].1["features"], json!(["Extrude1"]));+ for (command, params) in commands {+ h.app.run(&command, params).unwrap();+ }+ assert_eq!(h.app.session.world_state().bodies.len(), 2);+}++#[test]+fn mirror_timeline_click_keeps_picked_feature() {+ let (mut h, picked) = mirror_preselection();+ // Mirror moves on to the plane; the objects input takes timeline clicks once it is active.+ h.step(&json!({"click":{"handle":"dialog:Features"}})).unwrap();+ assert_eq!(h.app.dialog.as_ref().unwrap().active, 0);+ h.step(&json!({"click":{"handle":"timeline:Extrude1"}})).unwrap();+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, picked);+ // Wait out the double-click time: a double click opens the feature to edit.+ h.frames(30);+ h.step(&json!({"click":{"handle":"timeline:Extrude1"},"ctrl":true})).unwrap();+ let d = h.app.dialog.as_ref().unwrap();+ assert!(matches!(d.kind, Kind::Mirror));+ assert!(d.inputs[0].items.is_empty());+}+form_case!(loft, "solid.loft", ["Operation"]);form_case!(sweep, "solid.sweep", ["Orientation"]);form_case!(offset_plane, "construct.plane.offset", ["Distance"]);diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex fcdfd971d8..b409b89125 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -488,8 +488,14 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {// A dialog input that takes features (pattern objects) gets the click.let takes = app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::FEATURES != 0);if takes {+ // A click adds the feature and keeps one already picked (it shows as+ // selected); Ctrl+click takes it out, as Ctrl+click toggles outside a dialog.+ let toggle = ui.input(|i| i.modifiers.command || i.modifiers.ctrl);if let Some(mut d) = app.dialog.take() {- d.pick(&app.session, solidcraft_engine::Sel::Feature { id: *id });+ let feature = solidcraft_engine::Sel::Feature { id: *id };+ if toggle || !d.active_input().is_some_and(|i| i.items.contains(&feature)) {+ d.pick(&app.session, feature);+ }app.dialog = Some(d);}} else {