SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Draft: preserve the selected faces’ body (#6350) (#6446)
Colin Faulkingham7c31631ea6bd
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 6fea08abe8..298aec974b 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<Vec<(String, Value)>, SKind::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.rsindex 51a44bd412..bd4b6b6507 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();