SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Convert Mesh asks for the mesh body and its tolerance (#3001) (#3012)
DuBearte45ae7c00e0ba
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 498737b31b..8965fdeab0 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -173,6 +173,10 @@ pub enum Kind {},/// Halfway between two planes or planar faces.Midplane,+ /// An imported mesh body rebuilt as editable faces (#3001).+ MeshConvert {+ tolerance: String,+ },/// A construction axis, point or plane made from picks alone (#2474): input `i` is the/// command's parameter `keys[i]`, and `t` (along a path) when it takes one.Construct {@@ -590,6 +594,7 @@ impl Dialog {"construct.plane.offset" => {Dialog::new(Kind::OffsetPlane { offset: "0 mm".into() }, vec![SelInput::new("Plane", PLANES | PLANAR_FACES, false)])}+ "mesh.convert" => Dialog::new(Kind::MeshConvert { tolerance: "0.05 mm".into() }, vec![SelInput::new("Mesh body", BODIES, false)]),"construct.plane.midplane" => Dialog::new(Kind::Midplane,vec![SelInput::new("First plane", PLANES | PLANAR_FACES, false), SelInput::new("Second plane", PLANES | PLANAR_FACES, false)],@@ -1484,6 +1489,7 @@ fn title(k: &Kind) -> &'static str {Kind::Material { .. } => "PHYSICAL MATERIAL",Kind::OffsetPlane { .. } => "OFFSET PLANE",Kind::Midplane => "MIDPLANE",+ Kind::MeshConvert { .. } => "CONVERT MESH",Kind::Construct { title, .. } => title,Kind::PathPlane { .. } => "PLANE ALONG PATH",Kind::Rib { web: false, .. } => "RIB",@@ -2820,6 +2826,11 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {ui.end_row();}Kind::Split | Kind::ReplaceFace | Kind::Remove | Kind::Midplane | Kind::Construct { t: None, .. } => {}+ Kind::MeshConvert { tolerance } => {+ row_label(ui, "Tolerance");+ enter |= field(ui, tolerance);+ ui.end_row();+ }Kind::Construct { t: Some(t), .. } => {row_label(ui, "Position (0 to 1)");enter |= field(ui, t);@@ -4102,6 +4113,14 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, Slet base = plane_arg(app, sels(d, 0).first())?;("construct.plane.offset", json!({"base": base, "offset": offset}))}+ Kind::MeshConvert { tolerance } => {+ need(0, "the mesh body")?;+ let body = match sels(d, 0).first() {+ Some(Sel::Body { name }) => name.clone(),+ _ => return Err("pick the mesh body to convert".into()),+ };+ ("mesh.convert", json!({"body": body, "tolerance": tolerance}))+ }Kind::Midplane => {need(0, "the first plane")?;need(1, "the second plane")?;diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rsindex d2ca0d5482..033a1f9a91 100644--- a/crates/ui-egui/src/preselect_tests.rs+++ b/crates/ui-egui/src/preselect_tests.rs@@ -1932,3 +1932,43 @@ fn point_along_path_has_its_position_and_missing_picks_are_named() {let e = h.app.dialog.as_ref().and_then(|d| d.error.clone()).unwrap_or_default();assert!(e.contains("path"), "{e}");}++/// #3001: Convert Mesh opens a dialog instead of failing with "select a mesh body". With the+/// mesh selected first it takes it, and OK rebuilds it as faces.+#[test]+fn convert_mesh_asks_for_the_body_and_converts_the_selected_one() {+ use solidcraft_engine::doc::{Document, FeatureKind, MeshData};+ let body = solidcraft_engine::kernel::box_solid(Vec3::ZERO, Vec3::new(10., 20., 30.)).unwrap();+ let mesh = body.tessellate(0.01).unwrap();+ let mut doc = Document::default();+ doc.add_feature(+ FeatureKind::MeshImport {+ file: "box.stl".into(),+ meshes: vec![MeshData {+ name: "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 = crate::scenario::Harness::new();+ h.app.session = Session::new(doc);+ h.app.start("mesh.convert");+ h.frames(1);+ let status = h.app.status.as_ref().map(|s| s.0.clone()).unwrap_or_default();+ assert!(!status.contains("select a mesh body"), "{status}");+ assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(Kind::MeshConvert { .. })));+ crate::dialogs::cancel(&mut h.app);++ h.app.session.selection = vec![Sel::Body { name: "Mesh".into() }];+ h.app.start("mesh.convert");+ h.frames(1);+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![Sel::Body { name: "Mesh".into() }]);+ h.step(&json!({"key":"Enter"})).unwrap();+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().and_then(|d| d.error.clone()));+ let state = h.app.session.model.state();+ assert!(!state.body("Mesh").unwrap().body.is_mesh(), "rebuilt as faces");+}