Skip to content

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

A body dropped on a component's Bodies folder moves into that component (#3270) (#3347)

phanoob9a0e6f8ae0c3
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 42adc5cffb..04c457275e 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1820,11 +1820,17 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Option
if let Some(p) = r.secondary {
acts.menu = Some((p, Target::Folder { component: comp, folder: fstatic.to_string(), scope: prefix.clone() }));
}
- // Dropping on the folder row takes items out of their groups, to the end.
+ // Dropping on the folder row takes items out of their groups, to the end. Bodies or sketches
+ // from another component's folder move into this component, as a drop on its row does
+ // (#3270: the Bodies folder looked like the place to drop a body, and took nothing).
if let Some(resp) = &r.resp
- && let Some(d) = drop_target(ui, resp, |d: &Drag| d.comp == comp && d.folder == fstatic, DropMark::Box)
+ && let Some(d) = drop_target(ui, resp, |d: &Drag| d.folder == fstatic && (d.comp == comp || d.folder != "construction"), DropMark::Box)
{
- acts.drop = Some(DropAction::Move { comp, folder: fstatic, keys: d.keys.clone(), group: None, before: None });
+ acts.drop = Some(if d.comp == comp {
+ DropAction::Move { comp, folder: fstatic, keys: d.keys.clone(), group: None, before: None }
+ } else {
+ DropAction::Component { to: comp, folder: d.folder, keys: d.keys.clone() }
+ });
}
if !open {
return;
diff --git a/crates/ui-egui/src/occurrence_ui_tests.rs b/crates/ui-egui/src/occurrence_ui_tests.rs
index 0c1c698d53..18e3df738a 100644
--- a/crates/ui-egui/src/occurrence_ui_tests.rs
+++ b/crates/ui-egui/src/occurrence_ui_tests.rs
@@ -230,3 +230,29 @@ fn occurrence_distance_editor_reads_inches_and_keeps_four_digits_in_model_space(
crate::browser::revert_occurrence_dialog(&mut h.app, &movement);
assert!(h.app.session.pending_moves.is_empty());
}
+
+/// #3270: a body dragged from a child component onto the parent's Bodies folder moves back into
+/// the parent, as a drop on the parent's own row does.
+#[test]
+fn a_body_dropped_on_a_bodies_folder_moves_into_that_component() {
+ let mut h = Harness::new();
+ h.app.home.open = false;
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Plate"})).unwrap();
+ h.app.run("solid.box", json!({"corner":[20,0,0],"length":5,"width":5,"height":5,"body_name":"Lid"})).unwrap();
+ let part = h.app.run("component.create", json!({"name":"Part"})).unwrap()["component"].as_u64().unwrap();
+ h.app.run("solid.box", json!({"corner":[40,0,0],"length":5,"width":5,"height":5,"body_name":"Pin"})).unwrap();
+ h.app.run("component.activate", json!({"component":0})).unwrap();
+ h.frames(4);
+ let owner = |h: &Harness, name: &str| {
+ let state = h.app.session.model.state();
+ h.app.session.doc.model_body_component(state.body(name).unwrap())
+ };
+ assert_eq!(owner(&h, "Pin"), part);
+ let at = |h: &mut Harness, handle: &str| h.at(&json!({"handle": handle})).unwrap();
+ let (plate, lid, pin) = (at(&mut h, "row:Plate"), at(&mut h, "row:Lid"), at(&mut h, "row:Pin"));
+ // The root's Bodies folder row sits one row above its first body.
+ let folder = [plate[0], plate[1] - (lid[1] - plate[1])];
+ h.step(&json!({"drag": [pin, folder], "steps": 12})).unwrap();
+ h.frames(3);
+ assert_eq!(owner(&h, "Pin"), 0, "Pin moved back into the root component");
+}