From 3bcd93e2ca4b431932761db04eeca7c949cc8653 Mon Sep 17 00:00:00 2001 From: yhamil04 <147720712+yhamil04@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:31:40 +0000 Subject: [PATCH] Sketch: a preference to turn off scaling the sketch to its first dimension (#4109) (#6807) * claim: #4109 Co-Authored-By: Claude Opus 5.5 * Sketch: a preference to turn off scaling the sketch to its first dimension (#4109) Co-Authored-By: Claude Opus 5.5 * Test the first-dimension preference at small, typical and large values Co-Authored-By: Claude Opus 5.5 * Engine: the scale_sketch doc names the Sketch preference Co-Authored-By: Claude Opus 5.5 * Translate the first-dimension preference into the complete catalogs (ja, zh) Co-Authored-By: Claude Opus 5.5 * Add the Arabic, Hebrew and Vietnamese texts for the first-dimension preference Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: bherbruck --- .../sketch-first-dimension-scales.json | 26 +++++++++++++++++++ crates/engine/src/cmd/sketch.rs | 2 +- crates/ui-egui/src/dim_view.rs | 9 +++++-- .../ui-egui/src/dimension_create_ui_tests.rs | 25 ++++++++++++++++++ crates/ui-egui/src/prefs.rs | 3 +++ crates/ui-egui/src/prefs/sketch.rs | 9 +++++++ docs/book/src/guide/sketching.md | 5 ++++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 assets/locales/pending/sketch-first-dimension-scales.json diff --git a/assets/locales/pending/sketch-first-dimension-scales.json b/assets/locales/pending/sketch-first-dimension-scales.json new file mode 100644 index 000000000..41b7c1532 --- /dev/null +++ b/assets/locales/pending/sketch-first-dimension-scales.json @@ -0,0 +1,26 @@ +{ + "en": { + "ui.first_dimension_scales": "The first dimension scales the drawing", + "ui.first_dimension_scales_tip": "On: a sketch's first length dimension scales the drawing it measures, so its shape stays the same. Off: the dimension sizes only what it measures." + }, + "ar": { + "ui.first_dimension_scales": "البُعد الأول يغيّر مقياس الرسم", + "ui.first_dimension_scales_tip": "تشغيل: أول بُعد طولي في المخطط يغيّر مقياس الرسم الذي يقيسه، فيبقى شكله كما هو. إيقاف: يغيّر البُعد حجم ما يقيسه فقط." + }, + "he": { + "ui.first_dimension_scales": "המידה הראשונה משנה את קנה המידה של הציור", + "ui.first_dimension_scales_tip": "פועל: מידת האורך הראשונה בסקיצה משנה את קנה המידה של הציור שהיא מודדת, כך שצורתו נשמרת. כבוי: המידה משנה רק את גודל מה שהיא מודדת." + }, + "ja": { + "ui.first_dimension_scales": "最初の寸法で図形全体をスケールする", + "ui.first_dimension_scales_tip": "オン: スケッチの最初の長さ寸法で、測定する図形全体をスケールし、形を保ちます。オフ: 寸法は測定する対象のサイズだけを変えます。" + }, + "vi": { + "ui.first_dimension_scales": "Kích thước đầu tiên co giãn bản vẽ", + "ui.first_dimension_scales_tip": "Bật: kích thước chiều dài đầu tiên của bản phác thảo co giãn toàn bộ hình mà nó đo, nên hình dạng được giữ nguyên. Tắt: kích thước chỉ đổi cỡ phần mà nó đo." + }, + "zh": { + "ui.first_dimension_scales": "第一个尺寸缩放整个图形", + "ui.first_dimension_scales_tip": "开启:草图的第一个长度尺寸会缩放它所测量的图形,保持其形状不变。关闭:尺寸只改变所测量对象的大小。" + } +} diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rs index b83fd20f5..ba5a808c0 100644 --- a/crates/engine/src/cmd/sketch.rs +++ b/crates/engine/src/cmd/sketch.rs @@ -141,7 +141,7 @@ pub static COMMANDS: &[CommandSpec] = &[ .params(concat!("p0, p1: overall ends, width", connect_doc!(), created_doc!())), CommandSpec::new("sketch.point", "Point", draw_point).at("SKETCH", "CREATE").icon("point").enabled(in_sketch).params(concat!("point: [x,y] (each a number or an expression over the design's parameters: the point is then fixed where it comes to and follows them) or a snap: \"mid:\" (held at the line's midpoint), \"on::x,y\" (on the curve near x,y), {vertex: [x,y,z]} or {on_edge: [x,y,z]} of the model; id?", connect_doc!(), created_doc!())), CommandSpec::new("sketch.dimension", "Sketch Dimension", dimension).at("SKETCH", "CREATE").icon("dimension").key("D").enabled(in_sketch).params( - "entities: [refs] (a line midpoint is \"mid:line_id\"; a model edge or vertex, {edge: [x,y,z], body?} or {vertex: [x,y,z], body?}, is projected into the sketch first and measured there: a point against the projected edge measures the distance to it), type?: auto|distance|horizontal|distance_x|vertical|distance_y|length|radius|diameter|major|minor|angle, value?: number or expression (default: current; a bare number is in the design's units, e.g. 2 means 2 in in an inch design; give a unit such as \"50 mm\" to override), or `name = expression` (e.g. \"width = 40\"; also `#name = expression`), which adds the user parameter `name` with that expression and dimensions with `name` (refused when the name is taken or reserved; the reply's `defined` names it); text_at?: [x, y]. Two points or a line off the axes: with auto, text_at across from them (between the perpendiculars through them, or a tenth of their distance past) is the distance between them; pulled further past an end, up or down from it horizontal, sideways vertical. Two midpoints: placing text above or below their bounding box measures horizontally, beside it vertically, anywhere else (inside it or past its corners) the distance between them. Two lines: the angle between them (acute, or 180° − it when the value is nearer that) unless text_at picks a sector. A line and a circle or arc: the distance from the line to its edge (the gap, or how far the edge reaches past a line that cuts it; 0 is tangent); dimension the centre point for the distance to the centre. A point and a circle or arc: the distance from the point to its edge (or how far within it a point inside lies). Two circles or arcs: the gap between their edges (or how far they overlap when they cross, or the narrowest gap between them when one lies inside the other), or the centre-to-centre distance when they are the two caps of a slot. An ellipse: a half-axis, the distance from the centre to an axis end (major or minor; with auto, text_at pulled across the major axis gives the major half-axis, pulled out past an end of it the minor one, the minor without text_at; previous_axis?: major|minor, the half-axis an earlier placement chose, kept while text_at is near the boundary between them; the reply's axis names the one chosen; with auto, when a driving dimension already holds one half-axis (or its whole axis), the other one, wherever text_at is; without its major axis line the major half-axis goes to the ellipse's own major end, without its minor axis line the minor half-axis is the minor radius); any other type, radius among them, the minor radius; an ellipse's axis line with auto: its length, the whole axis, wherever text_at is; half_axes?: bool (default true; false: with auto, the minor radius wherever text_at is, as before half-axes, which the Dimension tool sends with Draw ellipses with their axes off). An arc and one of its end points: the arc's length (type arc_length does it from the arc alone). A dimension the sketch already determines is refused (naming what determines it); if_redundant?: \"driven\" places it as a driven (reference) dimension instead. scale_sketch?: bool (the dimension tool sends true): when this is the sketch's first length dimension and nothing in the sketch fixes a size (no other driving length dimension, nothing fixed or projected), the whole sketch scales about its origin to the value instead of distorting. Returns measured in unit (mm or deg), and scaled: the factor when the sketch was scaled", + "entities: [refs] (a line midpoint is \"mid:line_id\"; a model edge or vertex, {edge: [x,y,z], body?} or {vertex: [x,y,z], body?}, is projected into the sketch first and measured there: a point against the projected edge measures the distance to it), type?: auto|distance|horizontal|distance_x|vertical|distance_y|length|radius|diameter|major|minor|angle, value?: number or expression (default: current; a bare number is in the design's units, e.g. 2 means 2 in in an inch design; give a unit such as \"50 mm\" to override), or `name = expression` (e.g. \"width = 40\"; also `#name = expression`), which adds the user parameter `name` with that expression and dimensions with `name` (refused when the name is taken or reserved; the reply's `defined` names it); text_at?: [x, y]. Two points or a line off the axes: with auto, text_at across from them (between the perpendiculars through them, or a tenth of their distance past) is the distance between them; pulled further past an end, up or down from it horizontal, sideways vertical. Two midpoints: placing text above or below their bounding box measures horizontally, beside it vertically, anywhere else (inside it or past its corners) the distance between them. Two lines: the angle between them (acute, or 180° − it when the value is nearer that) unless text_at picks a sector. A line and a circle or arc: the distance from the line to its edge (the gap, or how far the edge reaches past a line that cuts it; 0 is tangent); dimension the centre point for the distance to the centre. A point and a circle or arc: the distance from the point to its edge (or how far within it a point inside lies). Two circles or arcs: the gap between their edges (or how far they overlap when they cross, or the narrowest gap between them when one lies inside the other), or the centre-to-centre distance when they are the two caps of a slot. An ellipse: a half-axis, the distance from the centre to an axis end (major or minor; with auto, text_at pulled across the major axis gives the major half-axis, pulled out past an end of it the minor one, the minor without text_at; previous_axis?: major|minor, the half-axis an earlier placement chose, kept while text_at is near the boundary between them; the reply's axis names the one chosen; with auto, when a driving dimension already holds one half-axis (or its whole axis), the other one, wherever text_at is; without its major axis line the major half-axis goes to the ellipse's own major end, without its minor axis line the minor half-axis is the minor radius); any other type, radius among them, the minor radius; an ellipse's axis line with auto: its length, the whole axis, wherever text_at is; half_axes?: bool (default true; false: with auto, the minor radius wherever text_at is, as before half-axes, which the Dimension tool sends with Draw ellipses with their axes off). An arc and one of its end points: the arc's length (type arc_length does it from the arc alone). A dimension the sketch already determines is refused (naming what determines it); if_redundant?: \"driven\" places it as a driven (reference) dimension instead. scale_sketch?: bool (the dimension tool sends the Sketch preference, on by default): when this is the sketch's first length dimension and nothing in the sketch fixes a size (no other driving length dimension, nothing fixed or projected), the whole sketch scales about its origin to the value instead of distorting. Returns measured in unit (mm or deg), and scaled: the factor when the sketch was scaled", ), CommandSpec::new("sketch.constraint.horizontal_vertical", "Horizontal/Vertical", c_horizontal_vertical) .at("SKETCH", "CONSTRAINTS") diff --git a/crates/ui-egui/src/dim_view.rs b/crates/ui-egui/src/dim_view.rs index a1b068032..5992c5cbb 100644 --- a/crates/ui-egui/src/dim_view.rs +++ b/crates/ui-egui/src/dim_view.rs @@ -114,6 +114,9 @@ struct DimensionDraft { driven: bool, /// Draw ellipses with their axes, when the draft was made (see [`ellipse_as_before`]). half_axes: bool, + /// The first dimension of a sketch scales it rather than distorting it (#1365), unless the + /// Sketch preference is off (#4109). + scale_sketch: bool, } impl DimensionDraft { @@ -125,8 +128,9 @@ impl DimensionDraft { && app.session.pending_moves == self.pending } fn params(&self, expr: &str) -> serde_json::Value { - // The first dimension of a sketch scales it rather than distorting it (#1365). - let mut params = json!({"entities": entities_value(&self.entities), "value": expr, "scale_sketch": true}); + // The first dimension of a sketch scales it rather than distorting it (#1365), unless the + // Sketch preference is off (#4109). + let mut params = json!({"entities": entities_value(&self.entities), "value": expr, "scale_sketch": self.scale_sketch}); if let Some(at) = self.at { params["text_at"] = json!([at.x, at.y]); } @@ -404,6 +408,7 @@ fn draft_of(app: &SolveApp, sketch: u64, entities: &[String], at: Option, error: None, driven, half_axes: app.preferences.ellipse_axes, + scale_sketch: app.preferences.first_dimension_scales, }; if !draft.preview.sketch(sketch).is_some_and(|solved| solved.report.ok()) { return Err("That dimension conflicts with the sketch constraints".into()); diff --git a/crates/ui-egui/src/dimension_create_ui_tests.rs b/crates/ui-egui/src/dimension_create_ui_tests.rs index 0b48012ee..cb0c1a5fa 100644 --- a/crates/ui-egui/src/dimension_create_ui_tests.rs +++ b/crates/ui-egui/src/dimension_create_ui_tests.rs @@ -554,6 +554,31 @@ fn rectangle_side_and_fixed_origin_line_dimensions_preserve_other_constraints() } } +/// With the Sketch preference off, the first dimension sizes only what it measures (#4109). +#[test] +fn the_first_dimension_scales_the_drawing_unless_the_preference_is_off() { + for (scales, side) in [true, false].into_iter().flat_map(|s| [2_f64, 30., 500.].map(|v| (s, v))) { + let mut h = Harness::new(); + crate::dim_view::cancel(); + assert!(h.app.preferences.first_dimension_scales, "on by default (#1365)"); + h.app.preferences.first_dimension_scales = scales; + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,10]})).unwrap(); + h.call("ui.view", json!({"view":"top"})); + h.app.cam.distance = 80.; + h.app.cam.target = solidcore_record::Vec3::new(10., 5., 0.); + h.settle(); + place(&mut h, &[[10., 0.]], [10., -5.]); + type_value(&mut h, &format!("{side} mm")); + h.step(&json!({"key":"Enter"})).unwrap(); + let state = h.app.session.world_state().unwrap(); + let area = state.sketch(h.app.session.active_sketch.unwrap()).unwrap().profiles[0].area; + // On: 20 × 10 scales to side × side / 2. Off: only the side changes, side × 10. + let want: f64 = if scales { side * side / 2. } else { side * 10. }; + assert!((area - want).abs() < 1e-6 * want.max(1.), "scales: {scales}, side {side}, area {area}"); + } +} + #[test] fn pending_second_nested_plane_uses_world_picks_but_one_local_dimension() { use solidcore_record::Vec2; diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index be7727548..be6774a01 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1683,6 +1683,9 @@ preference_settings! { /// converted to the unit the value is written in) and to an angle (degrees). dimension_step_mm: f64 = 1.0, PAGE_SKETCH, accept(DIMENSION_STEP_MM); dimension_step_deg: f64 = 1.0, PAGE_SKETCH, accept(DIMENSION_STEP_DEG); + /// The first length dimension of a sketch with nothing sized yet scales the whole drawing to + /// its value (#1365). Off: it sizes only what it measures (#4109). + first_dimension_scales: bool = true, PAGE_SKETCH; /// When true: Shift+click adds without removing; Primary toggles. /// When false (default): Shift and Primary both toggle. selection_shift_add_only: bool = false, PAGE_SKETCH; diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs index ee2a232e2..53db3e166 100644 --- a/crates/ui-egui/src/prefs/sketch.rs +++ b/crates/ui-egui/src/prefs/sketch.rs @@ -94,6 +94,7 @@ fn drawing(app: &mut SolveApp, ui: &mut egui::Ui) { "prefs.sketch.ellipse_axes", "prefs.sketch.auto_dimensions", "prefs.sketch.auto_locate", + "ui.first_dimension_scales", ]; let right_labels = ["prefs.sketch.shortcut_cycles_modes", "prefs.ribbon_click_ends_tool", "ui.project_face_edges_sketch", "prefs.sketch.project_options"]; @@ -147,6 +148,13 @@ fn drawing(app: &mut SolveApp, ui: &mut egui::Ui) { &mut app.preferences.sketch_auto_locate, ); }); + check( + ui, + "first_dimension_scales", + "ui.first_dimension_scales", + Some("ui.first_dimension_scales_tip"), + &mut app.preferences.first_dimension_scales, + ); }); ui.allocate_ui_with_layout(egui::vec2(right, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| { check( @@ -480,6 +488,7 @@ fn targets(key: &str, response: &egui::Response) { "sketch_align_points" => "Line up with other sketch points while drawing", "sketch_auto_dimensions" => "Dimension new shapes", "sketch_auto_locate" => "Also place them from the origin (fully constrained)", + "first_dimension_scales" => "The first dimension scales the drawing", "center_arc_follows_cursor" => "Center point arc follows the cursor's direction", "shortcut_cycles_modes" => "Pressing a tool's shortcut again switches its mode", "project_options_dialog" => "Project options dialog", diff --git a/docs/book/src/guide/sketching.md b/docs/book/src/guide/sketching.md index 3c61f91fe..1b5c71775 100644 --- a/docs/book/src/guide/sketching.md +++ b/docs/book/src/guide/sketching.md @@ -413,6 +413,11 @@ in one step. While you type, the dimension text follows the cursor, and Enter pl it there (or in its default place if you haven't moved the cursor) as one undo step. Esc cancels the dimension. +The first length dimension of a sketch with nothing sized yet scales the drawing it measures +to its value, so the shape stays as drawn; separate shapes that nothing joins keep their +size. To have the first dimension size only what it measures, turn off **The first dimension +scales the drawing** in Preferences › Sketch. + You can still place the text first. Before you type, a click on empty sketch space puts the text there and keeps the value box focused; a click on another point or line makes the dimension a distance or angle instead; Tab leaves the picks waiting for a click to place the