From 8558b37e4417c2157a0fde52e02b28ade20c21b2 Mon Sep 17 00:00:00 2001 From: austin62jake Date: Sat, 31 Oct 2026 16:58:34 +0000 Subject: [PATCH] Edit dialogs: a stored number shows with its unit, Fillet, Chamfer, Shell, Draft and more (#1936) (#8697) * claim: #1936 (Fillet, Chamfer, Extrude, Shell and Draft edit dialogs) * Fillet, Chamfer, Shell and Draft: a stored number edits with its unit (#1936) Their edit dialogs showed a value stored as a bare number as it was, so a fillet made with a radius of 2 opened as "2" and a chamfer angle of 30 as "30", where the other dialogs, and since #2107 the Plastic ones, read "2 mm" and "30 deg". The Fillet radius, the Chamfer distances and angle, the Shell thickness and the Draft angle now go through shown_expr, as the Plastic dialogs do. Extrude is left as it is: its editor keeps an unchanged expression exactly as stored (extrude_edit_tests), and writing the unit would change it. Co-Authored-By: Claude Opus 5.5 * Offset Face, Stock, Offset Plane, Plane at Angle, Pipe and Emboss too (#1936) The rest of the dialog_descriptors! table's length and angle fields that copied the stored text as it was now go through shown_expr as well: the Offset Face distance, the Stock margin, the Offset Plane offset, the Plane at Angle angle, the Pipe diameter and wall, and the Emboss depth. Scale's factor has no unit and still shows as stored. The test also edits an offset face, a stock and an offset plane. Co-Authored-By: Claude Opus 5.5 * Revolve, Thread, Rib and Web too (#1936) The custom edit paths that copied a stored length or angle as it was now go through shown_expr as well: the Revolve angle, the Thread length, and the Rib and Web thickness and depth. The test also edits a revolve. The Rectangular and Circular Patterns stay as they are, like Extrude: their editors keep an unchanged definition exactly as stored (preselect_tests::feature_mirror_and_patterns_reopen_as_feature_replays_even_for_body_creators). Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude --- crates/ui-egui/src/dialogs.rs | 32 +++++++------- crates/ui-egui/src/dialogs_all_tests.rs | 56 +++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index c5b500454..cdb18bd0e 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -107,20 +107,20 @@ crate::dialog_descriptor::dialog_descriptors! { pub enum Kind { Shell("solid.shell", "SHELL", [("Faces/Body", FACES, true)], FeatureKind::Shell { thickness, .. }) { - thickness: String = "2 mm".into() => thickness.to_string(), + thickness: String = "2 mm".into() => shown_expr(thickness, ValueKind::Length), } => json!({"thickness": thickness}); Draft("solid.draft", "DRAFT", [("Faces", FACES, true), ("Neutral plane", PLANES | PLANAR_FACES, false)], FeatureKind::Draft { angle, .. }) { - angle: String = "5 deg".into() => angle.to_string(), + angle: String = "5 deg".into() => shown_expr(angle, ValueKind::Angle), } => json!({"angle": angle}); // A point picked as well puts the plane through it instead of at the distance. OffsetPlane("construct.plane.offset", "OFFSET PLANE", [("Plane", PLANES | PLANAR_FACES, false), ("Through point", selection::VERTICES | selection::POINTS, false)], FeatureKind::ConstructionPlane { plane: PlaneRef::Offset { distance, .. } }) { - offset: String = "0 mm".into() => distance.to_string(), + offset: String = "0 mm".into() => shown_expr(distance, ValueKind::Length), } => json!({"offset": offset}); AnglePlane("construct.plane.at_angle", "PLANE AT ANGLE", [("Plane", PLANES | PLANAR_FACES, false), ("Axis", AXIS_PICKS, false)], FeatureKind::ConstructionPlane { plane: PlaneRef::AtAngle { angle, .. } }) { - angle: String = "45 deg".into() => angle.to_string(), + angle: String = "45 deg".into() => shown_expr(angle, ValueKind::Angle), } => json!({"angle": angle}); Scale("solid.scale", "SCALE", [("Bodies", BODIES, true)], FeatureKind::Scale { factor, .. }) { @@ -128,21 +128,21 @@ crate::dialog_descriptor::dialog_descriptors! { } => json!({"factor": factor}); OffsetFaces("solid.offset_face", "OFFSET FACE", [("Faces", FACES, true)], FeatureKind::OffsetFace { distance, .. }) { - distance: String = "2 mm".into() => distance.to_string(), + distance: String = "2 mm".into() => shown_expr(distance, ValueKind::Length), } => json!({"distance": distance}); Stock("solid.bounding_solid", "STOCK", [("Bodies (all if none)", BODIES, true)], FeatureKind::BoundingSolid { margin, .. }) { - margin: String = "2 mm".into() => margin.to_string(), + margin: String = "2 mm".into() => shown_expr(margin, ValueKind::Length), } => json!({"margin": margin}); Pipe("solid.pipe", "PIPE", [("Path", CURVES, true)], FeatureKind::Pipe { diameter, wall, operation, .. }) { - diameter: String = "5 mm".into() => diameter.to_string(), - wall: String = String::new() => wall.as_deref().map(str::to_string).unwrap_or_default(), + diameter: String = "5 mm".into() => shown_expr(diameter, ValueKind::Length), + wall: String = String::new() => wall.as_deref().map(|e| shown_expr(e, ValueKind::Length)).unwrap_or_default(), operation: usize = 0 => op_index(operation), } => json!({"diameter": diameter, "operation": OPS.get(*operation).copied().unwrap_or("new")}); Emboss("solid.emboss", "EMBOSS", [("Profiles", PROFILES, true), ("Target Face (optional)", FACES, false)], FeatureKind::Emboss { depth, deboss, .. }) { - depth: String = "1 mm".into() => depth.to_string(), + depth: String = "1 mm".into() => shown_expr(depth, ValueKind::Length), deboss: bool = false => *deboss, } => json!({"depth": depth, "mode": if *deboss { "deboss" } else { "emboss" }}); ; custom { @@ -5734,7 +5734,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option) -> Option serde_json::to_value(geo).ok(), _ => None, }; - d.kind = Kind::Revolve { angle: angle.to_string(), operation: op_index(operation), axis: stored_axis }; + d.kind = Kind::Revolve { angle: shown_expr(angle, ValueKind::Angle), operation: op_index(operation), axis: stored_axis }; d.extra.insert("convention".into(), json!(convention)); if let Some(a2) = angle2 { d.extra.insert("angle2".into(), json!(a2)); @@ -5773,17 +5773,17 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option) -> Option) -> Option) -> Option, &[&str])> = vec![ + (one("solid.fillet", json!({"edges": [[20, 0, 20]], "radius": 2})), &["2 mm"]), + (one("solid.chamfer", json!({"edges": [[20, 0, 20]], "distance": 1, "distance2": 1.5})), &["1 mm", "1.5 mm"]), + (one("solid.chamfer", json!({"edges": [[20, 0, 20]], "distance": 1, "angle": 30})), &["1 mm", "30 deg"]), + (one("solid.shell", json!({"faces": [[20, 15, 20]], "thickness": 2})), &["2 mm"]), + (one("solid.draft", json!({"faces": [[0, 15, 10]], "angle": 3, "neutral": "XY"})), &["3 deg"]), + (one("solid.offset_face", json!({"faces": [[20, 15, 20]], "distance": 2})), &["2 mm"]), + (one("solid.bounding_solid", json!({"margin": 2})), &["2 mm"]), + (one("construct.plane.offset", json!({"base": "XY", "offset": 5})), &["5 mm"]), + (profile.iter().cloned().chain([("solid.revolve", json!({"sketch": "Profile", "axis": "Z", "angle": 90}))]).collect(), &["90 deg"]), + ]; + for (cmds, expected) in cases { + let mut h = Harness::new(); + h.app.home.open = false; + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + let command = cmds.last().map(|(c, _)| *c).unwrap_or_default(); + for (c, p) in cmds { + h.app.run(c, p).unwrap(); + } + h.frames(2); + let id = h.app.session.doc.features.last().unwrap().id; + let count = h.app.session.doc.features.len(); + h.app.edit_feature(id); + h.frames(4); + let shown = match &h.app.dialog.as_ref().unwrap().kind { + Kind::Fillet { radius, ctype: 0, .. } => vec![radius.clone()], + Kind::Fillet { radius, distance2, ctype: 1, .. } => vec![radius.clone(), distance2.clone()], + Kind::Fillet { radius, angle, ctype: 2, .. } => vec![radius.clone(), angle.clone()], + Kind::Shell { thickness } => vec![thickness.clone()], + Kind::Draft { angle } => vec![angle.clone()], + Kind::OffsetFaces { distance } => vec![distance.clone()], + Kind::Stock { margin } => vec![margin.clone()], + Kind::OffsetPlane { offset } => vec![offset.clone()], + Kind::Revolve { angle, .. } => vec![angle.clone()], + other => panic!("{command}: {other:?}"), + }; + assert_eq!(shown, expected, "{command}"); + h.step(&json!({"widget": "OK"})).unwrap(); + h.frames(4); + assert!(h.app.dialog.is_none(), "{command}: OK applies the unchanged editor"); + assert_eq!(h.app.session.doc.features.len(), count, "{command}: the feature is redefined in place"); + } +}