Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Edit dialogs: a stored number shows with its unit, Fillet, Chamfer, Shell, Draft and more (#1936) (#8697)

austin62jake8558b37e4417
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index c5b5004545..cdb18bd0e3 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<usize>) -> Option<Dia
AxisRef::Model { geo } if model_axis_sel(s, geo).is_none() => 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<usize>) -> Option<Dia
|i: usize, p: Vec3| f.edge_names.get(i).and_then(|name| named_refill(s, body.as_deref(), name, p, true)).or_else(|| edge_sel(s, p));
let chamfer = matches!(f.kind, FeatureKind::Chamfer { .. });
let mut d = start(if chamfer { "solid.chamfer" } else { "solid.fillet" })?;
- d.kind = fillet_kind(radius, chamfer);
+ d.kind = fillet_kind(&shown_expr(radius, ValueKind::Length), chamfer);
if let Kind::Fillet { chain, ctype, distance2, angle, flip, .. } = &mut d.kind {
*chain = false;
// An unequal chamfer: two distances, or a distance and an angle.
if let FeatureKind::Chamfer { distance2: d2, angle: a, flip: f, .. } = &f.kind {
if let Some(v) = d2 {
*ctype = 1;
- *distance2 = v.to_string();
+ *distance2 = shown_expr(v, ValueKind::Length);
} else if let Some(v) = a {
*ctype = 2;
- *angle = v.to_string();
+ *angle = shown_expr(v, ValueKind::Angle);
}
*flip = *f;
}
@@ -6444,7 +6444,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
}
d.kind = Kind::Thread {
designation: designation.clone().unwrap_or_default(),
- length: length.as_deref().map(str::to_string).unwrap_or_default(),
+ length: length.as_deref().map(|e| shown_expr(e, ValueKind::Length)).unwrap_or_default(),
handedness: *handedness,
suggested: None,
of: Vec::new(),
@@ -6495,8 +6495,8 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
let mut d = start(if *web { "solid.web" } else { "solid.rib" })?;
d.kind = Kind::Rib {
web: *web,
- thickness: thickness.to_string(),
- depth: depth.as_deref().map(str::to_string).unwrap_or_default(),
+ thickness: shown_expr(thickness, ValueKind::Length),
+ depth: depth.as_deref().map(|e| shown_expr(e, ValueKind::Length)).unwrap_or_default(),
flip: *flip,
normal: *normal,
};
diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs
index 42795a8e96..82ca574f8b 100644
--- a/crates/ui-egui/src/dialogs_all_tests.rs
+++ b/crates/ui-egui/src/dialogs_all_tests.rs
@@ -1243,3 +1243,59 @@ fn pattern_says_why_a_clicked_sketch_is_not_taken() {
assert!(!crate::i18n::tr_label(crate::dialogs::SKETCH_NOT_OBJECT).is_ascii(), "the hint reads in the user's language");
assert!(!crate::i18n::tr("ui.pattern_object_type_tip").is_ascii(), "so does the Object Type tooltip");
}
+
+/// Features stored with bare numbers edit with their units written out, as the Plastic ones do
+/// (#1936): Fillet, Chamfer, Shell, Draft, Offset Face, Stock, Offset Plane and Revolve among them.
+/// OK in the editor keeps the feature in place.
+#[test]
+fn stored_bare_numbers_edit_with_their_units() {
+ use serde_json::{Value, json};
+ let profile = [
+ ("sketch.create", json!({"plane": "XZ", "name": "Profile"})),
+ ("sketch.rectangle.two_point", json!({"p0": [50, 0], "p1": [60, 10]})),
+ ("sketch.finish", json!({})),
+ ];
+ let one = |command: &'static str, params: Value| vec![(command, params)];
+ let cases: Vec<(Vec<(&str, Value)>, &[&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");
+ }
+}