From 7c31631ea6bd2425bf12f54a78adbe7d1cdba6c0 Mon Sep 17 00:00:00 2001 From: Colin Faulkingham Date: Mon, 26 Oct 2026 10:45:09 +0000 Subject: [PATCH] =?UTF-8?q?Draft:=20preserve=20the=20selected=20faces?= =?UTF-8?q?=E2=80=99=20body=20(#6350)=20(#6446)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * claim: #6350 * fix(ui): preserve the selected faces' body in Draft (#6350) --- crates/ui-egui/src/dialogs.rs | 6 ++- crates/ui-egui/src/dialogs_all_tests.rs | 62 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 6fea08abe..298aec974 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -3689,8 +3689,12 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result, S Kind::Draft { .. } => { need(0, "faces")?; need(1, "the neutral plane")?; + let Some(Sel::Face { body, .. }) = sels(d, 0).first() else { return Err("select faces first".into()) }; + if sels(d, 0).iter().any(|pick| !matches!(pick, Sel::Face { body: other, .. } if other == body)) { + return Err("pick faces of one body".into()); + } let neutral = plane_value(s, sels(d, 1).first()).ok_or("the neutral plane must be a plane or a planar face")?; - ("solid.draft", json!({"faces": face_points(0), "neutral": neutral})) + ("solid.draft", json!({"body": body, "faces": face_points(0), "neutral": neutral})) } Kind::Mirror => { need(0, "objects")?; diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 51a44bd41..bd4b6b650 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -595,6 +595,68 @@ fn face_editor_refills_named_faces_after_sketch_resize() { } } +#[test] +fn draft_uses_the_picked_solid_beside_a_hidden_overlapping_mesh() { + use solidcraft_engine::doc::{Document, MeshData, naming}; + + let mesh = solidcraft_engine::kernel::box_solid(Vec3::ZERO, Vec3::new(20.0, 20.0, 10.0)).unwrap().tessellate(0.01).unwrap(); + let mut doc = Document::default(); + doc.add_feature( + FeatureKind::MeshImport { + file: "overlapping-box.stl".into(), + meshes: vec![MeshData { + name: "Hidden mesh".into(), + positions: mesh.positions.iter().flat_map(|p| [p.x, p.y, p.z]).collect(), + triangles: mesh.triangles.iter().flatten().copied().collect(), + color: None, + }], + }, + Some("Imported mesh"), + ) + .unwrap(); + let mut h = Harness::new(); + h.app.session = Session::new(doc); + h.app.run("solid.box", json!({"length":20,"width":20,"height":10})).unwrap(); + h.app.run("browser.visibility", json!({"items":["Hidden mesh"],"visible":false})).unwrap(); + let state = h.app.session.world_state(); + let hidden_mesh = state.body("Hidden mesh").unwrap().mesh(); + let body = state.bodies.iter().find(|body| !body.body.is_mesh()).unwrap(); + let target = body.name.clone(); + let point = Vec3::new(20.0, 10.0, 5.0); + let name = naming::face_name_at_body(body, point).unwrap(); + let (index, _, _) = naming::face_on_body(body, &name, point).unwrap(); + h.app.session.selection = vec![Sel::Face { body: target.clone(), index, point }]; + let mut d = Dialog::for_command(&h.app, "solid.draft").unwrap(); + d.inputs[1].items = vec![Sel::Plane { name: "XY".into() }]; + d.kind = Kind::Draft { angle: "5 deg".into() }; + let commands = apply_commands(&h.app, &d).unwrap(); + assert_eq!(preview_commands(&h.app, &d).unwrap(), commands); + let (command, params) = &commands[0]; + h.app.run(command, params.clone()).unwrap(); + assert_eq!(params["body"], target); + let state = h.app.session.model.state(); + assert_eq!(state.bodies.len(), 2); + assert!(state.body("Hidden mesh").unwrap().body.is_mesh()); + assert_eq!(state.body("Hidden mesh").unwrap().mesh().positions, hidden_mesh.positions); + assert_eq!(state.body("Hidden mesh").unwrap().mesh().triangles, hidden_mesh.triangles); + let volume = state.body(&target).unwrap().body.volume_at(0.01).unwrap(); + assert!((volume - 4000.0).abs() > 50.0, "the picked wall should taper: {volume}"); + assert!(matches!( + &h.app.session.doc.features.last().unwrap().kind, + FeatureKind::Draft { body: Some(body), .. } if *body == target + )); +} + +#[test] +fn draft_rejects_faces_from_different_bodies() { + let h = Harness::new(); + let mut d = Dialog::for_command(&h.app, "solid.draft").unwrap(); + d.inputs[0].items = + vec![Sel::Face { body: "First".into(), index: 0, point: Vec3::ZERO }, Sel::Face { body: "Second".into(), index: 0, point: Vec3::X }]; + d.inputs[1].items = vec![Sel::Plane { name: "XY".into() }]; + assert_eq!(apply_commands(&h.app, &d).unwrap_err(), "pick faces of one body"); +} + #[test] fn solid_pattern_quantity_arrows_step_the_count_the_command_receives() { let mut h = fixture();