* claim: #5288 * Mirror keeps the preselected feature when the object type changes (#5288) The pre-selection moves into the objects input when a pattern window opens, and switching Object Type cleared that input, so switching to Bodies and back lost the selected feature. The window now keeps the objects of the type not shown and restores them when it is chosen again. A plain timeline click on a feature already picked keeps it; Ctrl+click takes it out.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user