* claim: #3001 * fix(ui): Convert Mesh asks for the mesh body and its tolerance (#3001) It had no dialog, so the toolbar ran mesh.convert with no body and it always reported "select a mesh body". A dialog now takes the mesh body (a selected one fills it) and the tolerance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)>, S
|
||||
let 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")?;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user