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"); + } +}