Skip to content

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

Coil: up and down arrows on the Revolutions field (#7481) (#7766)

semmelrinde835e2615930f
diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs
index 82ca574f8b..5a59b364e3 100644
--- a/crates/ui-egui/src/dialogs_all_tests.rs
+++ b/crates/ui-egui/src/dialogs_all_tests.rs
@@ -963,6 +963,51 @@ fn coil_from_a_profile_hides_the_primitive_section() {
assert!(p.get("operation").is_some(), "{p}");
}
+/// The Revolutions field steps by whole turns like the other counts (#7481).
+#[test]
+fn coil_revolutions_arrows_step_whole_turns() {
+ let mut h = fixture();
+ h.app.run("parameters.add", json!({"name":"turns","expression":"3","unit":""})).unwrap();
+ h.app.dialog = Some(Dialog::for_command(&h.app, "solid.coil").unwrap());
+ h.settle();
+ let sent = |h: &Harness| {
+ let cmds = crate::dialogs::preview_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ cmds.iter().find(|(id, _)| id == "solid.coil").map(|(_, p)| p["revolutions"].clone()).unwrap_or_else(|| panic!("{cmds:?}"))
+ };
+ let set = |h: &mut Harness, text: &str| {
+ if let Some(Kind::Primitive { fields, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind)
+ && let Some((_, value)) = fields.iter_mut().find(|(k, _)| *k == "revolutions")
+ {
+ *value = text.into();
+ }
+ h.frames(2);
+ };
+ let click = |h: &mut Harness, arrow: &str| h.step(&json!({"click":{"handle":format!("dialog:ui.revolutions {arrow}")}})).unwrap();
+ assert_eq!(sent(&h), json!("4"));
+ click(&mut h, "up");
+ assert_eq!(sent(&h), json!("5"));
+ click(&mut h, "down");
+ click(&mut h, "down");
+ assert_eq!(sent(&h), json!("3"));
+ // A fraction steps to the next whole turn either way.
+ set(&mut h, "2.5");
+ click(&mut h, "up");
+ assert_eq!(sent(&h), json!("3"));
+ set(&mut h, "2.5");
+ click(&mut h, "down");
+ assert_eq!(sent(&h), json!("2"));
+ // From 1 to the helix's 200 turns.
+ set(&mut h, "1");
+ click(&mut h, "down");
+ assert_eq!(sent(&h), json!("1"));
+ set(&mut h, "200");
+ click(&mut h, "up");
+ assert_eq!(sent(&h), json!("200"));
+ set(&mut h, "turns");
+ click(&mut h, "up");
+ assert_eq!(sent(&h), json!("turns + 1"));
+}
+
fn extrude_focus_fixture() -> Harness {
let mut h = Harness::new();
h.app.home.open = false;
diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs
index 1ae0c525e5..da8f7b5722 100644
--- a/crates/ui-egui/src/dialogs_dense.rs
+++ b/crates/ui-egui/src/dialogs_dense.rs
@@ -115,8 +115,18 @@ const MAX_PATTERN_INSTANCES: i64 = 1000;
/// A solid pattern's quantity row, with step arrows from 1 to `MAX_PATTERN_INSTANCES`. The
/// count goes to the command as typed, so it is evaluated as the document evaluates it.
fn quantity_row(ui: &mut egui::Ui, doc: &solidcraft_engine::doc::Document, label: &str, value: &mut String) -> bool {
+ count_row_to(ui, doc, label, value, MAX_PATTERN_INSTANCES)
+}
+
+/// The most revolutions a coil makes (the helix's own limit).
+const MAX_COIL_REVOLUTIONS: i64 = 200;
+
+/// A count row with step arrows by whole numbers from 1 to `max`, evaluated as the document
+/// evaluates it. A fraction still types in (a coil's revolutions); an arrow steps it to the next
+/// whole number.
+fn count_row_to(ui: &mut egui::Ui, doc: &solidcraft_engine::doc::Document, label: &str, value: &mut String, max: i64) -> bool {
let eval = |text: &str| doc.eval(text.trim(), solidcraft_engine::doc::expr::Kind::Unitless).ok();
- ui_kit::count_row(ui, label, value, &ui_kit::Count { min: 1, max: MAX_PATTERN_INSTANCES, eval: &eval })
+ ui_kit::count_row(ui, label, value, &ui_kit::Count { min: 1, max, eval: &eval })
}
fn fillet_type(extra: &serde_json::Map<String, Value>) -> usize {
@@ -860,7 +870,12 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo
if from_sketch && (*k == "diameter" || *k == "section_size") {
continue;
}
- enter |= expr_row(ui, primitive_label(k), v);
+ // Revolutions steps by whole turns like the other counts (#7481).
+ enter |= if *k == "revolutions" {
+ count_row_to(ui, &app.session.doc, primitive_label(k), v, MAX_COIL_REVOLUTIONS)
+ } else {
+ expr_row(ui, primitive_label(k), v)
+ };
}
if *cmd == "solid.coil" {
enter |= coil_rows(ui, &mut d.extra);