SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch Concentric: accept a circle or arc and a sketch point (#10487)
Leo24b91bd45345
diff --git a/assets/locales/ar.json b/assets/locales/ar.jsonindex 8d53e9fefb..dc4bb89ef4 100644--- a/assets/locales/ar.json+++ b/assets/locales/ar.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "يطبق القيد الذي يكاد منحنى أو منحنيان محددان يحققانه، مثل الأفقي أو التوازي أو التماس أو التساوي. استخدمه لتهذيب رسم يدوي علاقة بعد أخرى.","help.sketch.constraint.coincident": "يجعل نقطة تقع على نقطة أخرى أو على منحنى أو على محور الرسم. استخدمه لسد الفجوات في المقطع أو لوضع نقطة على خط.","help.sketch.constraint.collinear": "يجعل خطين يقعان على خط مستقيم واحد. استخدمه لمحاذاة الحواف المتقطعة، مثل جانبي حز.",- "help.sketch.constraint.concentric": "يعطي دائرتين أو قوسين المركز نفسه. استخدمه للحلقات والتجاويف المتدرجة والأعمدة ذات الأكتاف.",+ "help.sketch.constraint.concentric": "يجعل دائرتين أو قوسين يشتركان في المركز نفسه، أو يضع مركز دائرة أو قوس على نقطة في الرسم التخطيطي، بما في ذلك نقطة الأصل. اختر العنصرين بأي ترتيب.","help.sketch.constraint.curvature": "يجعل منحنيين يلتقيان عند نقطة نهاية يتابعان بالانحناء نفسه (G2). استخدمه حيث لا يكفي الوصل المماسي نعومة، مثلًا على الأسطح الظاهرة.","help.sketch.constraint.equal": "يجعل الخطوط بالطول نفسه، أو الدوائر والأقواس بنصف القطر نفسه. استخدمه ليتحكم بُعد واحد في عدة ميزات متماثلة.","help.sketch.constraint.fix": "يثبّت النقاط أو المنحنيات في مكانها، أو يفك تثبيتها. استخدمه للهندسة التي يجب ألا تتحرك عند سحب الرسم أو حله.",diff --git a/assets/locales/de.json b/assets/locales/de.jsonindex 4ebef266d7..f5f42cec21 100644--- a/assets/locales/de.json+++ b/assets/locales/de.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "Setzt die Bedingung, die eine oder zwei gewählte Kurven schon fast erfüllen, etwa horizontal, parallel, tangential oder gleich. Damit räumen Sie eine frei gezeichnete Skizze Beziehung für Beziehung auf.","help.sketch.constraint.coincident": "Legt einen Punkt auf einen anderen Punkt, eine Kurve oder eine Skizzenachse. Damit schließen Sie Lücken in einem Profil oder setzen einen Punkt auf eine Linie.","help.sketch.constraint.collinear": "Legt zwei Linien auf eine gemeinsame Gerade. Damit richten Sie unterbrochene Kanten aus, etwa die beiden Seiten einer Kerbe.",- "help.sketch.constraint.concentric": "Gibt zwei Kreisen oder Bögen denselben Mittelpunkt. Für Ringe, Senkungen und abgesetzte Wellen.",+ "help.sketch.constraint.concentric": "Gibt zwei Kreisen oder Bögen denselben Mittelpunkt oder zentriert einen Kreis oder Bogen auf einem Skizzenpunkt, auch dem Ursprung. Die Auswahlreihenfolge ist beliebig.","help.sketch.constraint.curvature": "Lässt zwei Kurven, die sich an einem Endpunkt treffen, mit gleicher Krümmung ineinander übergehen (G2). Wo ein tangentialer Übergang nicht glatt genug ist, etwa an Sichtflächen.","help.sketch.constraint.equal": "Macht Linien gleich lang oder Kreise und Bögen gleich groß im Radius. So steuert ein Maß mehrere gleiche Elemente.","help.sketch.constraint.fix": "Fixiert Punkte oder Kurven an ihrer Stelle oder löst sie wieder. Für Geometrie, die sich beim Ziehen oder Lösen der Skizze nicht bewegen darf.",diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 80966c2f4d..fb1c10e394 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "Applies the constraint that one or two picked curves nearly have already, such as horizontal, parallel, tangent or equal. Use it to tidy a hand-drawn sketch one relation at a time.","help.sketch.constraint.coincident": "Makes a point lie on another point, a curve or a sketch axis. Use it to close gaps in a profile or to put a point on a line.","help.sketch.constraint.collinear": "Makes two lines lie on one straight line. Use it to line up interrupted edges, such as both sides of a notch.",- "help.sketch.constraint.concentric": "Gives two circles or arcs the same centre. Use it for rings, counterbores and shafts with shoulders.",+ "help.sketch.constraint.concentric": "Gives two circles or arcs the same centre, or centres a circle or arc on a sketch point, including the origin. Pick either pair in either order.","help.sketch.constraint.curvature": "Makes two curves that meet at an end point continue with the same curvature (G2). Use it where a tangent join is not smooth enough, for example on visible surfaces.","help.sketch.constraint.equal": "Makes lines the same length, or circles and arcs the same radius. Use it so that one dimension drives several matching features.","help.sketch.constraint.fix": "Fixes points or curves where they are, or frees them again. Use it for geometry that must not move when you drag or solve the sketch.",diff --git a/assets/locales/he.json b/assets/locales/he.jsonindex e6739c43b9..dd672950c7 100644--- a/assets/locales/he.json+++ b/assets/locales/he.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "מחיל את האילוץ שעקומה אחת או שתיים שנבחרו כמעט מקיימות, כמו אופקי, מקביל, משיק או שווה. מתאים לסידור סקיצה שנוצרה ביד, יחס אחד בכל פעם.","help.sketch.constraint.coincident": "גורם לנקודה להתלכד עם נקודה אחרת, עם עקומה או עם ציר הסקיצה. מתאים לסגירת פערים בפרופיל או להנחת נקודה על ישר.","help.sketch.constraint.collinear": "גורם לשני ישרים לשכב על ישר אחד. מתאים ליישור קצוות מקוטעים, כמו שני צדי מגרעת.",- "help.sketch.constraint.concentric": "נותן לשני מעגלים או קשתות אותו מרכז. מתאים לטבעות, לשקעי ברגים ולצירים עם מדרגות.",+ "help.sketch.constraint.concentric": "מעניק לשני מעגלים או קשתות מרכז משותף, או ממקם את מרכזו של מעגל או קשת בנקודה בסקיצה, כולל הראשית. אפשר לבחור את שני הפריטים בכל סדר.","help.sketch.constraint.curvature": "גורם לשתי עקומות שנפגשות בנקודת קצה להמשיך באותה עקמומיות (G2). מתאים כשחיבור משיק אינו חלק מספיק, למשל על משטחים גלויים.","help.sketch.constraint.equal": "גורם לישרים להיות באותו אורך, ולמעגלים ולקשתות באותו רדיוס. מתאים כדי שמידה אחת תניע כמה מאפיינים תואמים.","help.sketch.constraint.fix": "מקבע נקודות או עקומות במקומן, או משחרר אותן שוב. מתאים לגאומטריה שאסור שתזוז בגרירה או בפתרון הסקיצה.",diff --git a/assets/locales/ja.json b/assets/locales/ja.jsonindex 2e834f4507..6ce84bb6b5 100644--- a/assets/locales/ja.json+++ b/assets/locales/ja.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "選んだ1〜2本の曲線がほぼ満たしている拘束(水平、平行、正接、等長など)を適用します。手描きのスケッチを1つずつ整えるときに使います。","help.sketch.constraint.coincident": "点を、別の点、曲線、スケッチ軸の上に載せます。輪郭の隙間を閉じたり、点を直線上に置いたりするときに使います。","help.sketch.constraint.collinear": "2本の直線を同一直線上に揃えます。切り欠きの両側など、途切れたエッジを揃えるときに使います。",- "help.sketch.constraint.concentric": "2つの円または円弧の中心を揃えます。リング、座ぐり、段付きシャフトに使います。",+ "help.sketch.constraint.concentric": "2つの円または円弧の中心を揃えるか、円または円弧の中心をスケッチ点(原点を含む)に一致させます。選択する順序は問いません。","help.sketch.constraint.curvature": "端点で接する2本の曲線を、同じ曲率で続けます (G2)。正接では滑らかさが足りない、見える面などに使います。","help.sketch.constraint.equal": "直線を同じ長さに、円や円弧を同じ半径にします。1つの寸法で複数の同じ形状を制御するときに使います。","help.sketch.constraint.fix": "点や曲線を現在の位置に固定、または固定を解除します。ドラッグやスケッチの解決で動いてはいけないジオメトリに使います。",diff --git a/assets/locales/vi.json b/assets/locales/vi.jsonindex ab3552bfec..b0e2f8a0d2 100644--- a/assets/locales/vi.json+++ b/assets/locales/vi.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "Áp dụng ràng buộc mà một hoặc hai đường cong đã chọn gần như đã thỏa, như nằm ngang, song song, tiếp tuyến hay bằng nhau. Dùng để chỉnh lại phác thảo vẽ tay từng quan hệ một.","help.sketch.constraint.coincident": "Làm một điểm trùng với điểm khác, nằm trên một đường cong hoặc trục phác thảo. Dùng để đóng khe hở trong biên dạng hoặc đặt điểm lên đường thẳng.","help.sketch.constraint.collinear": "Làm hai đường thẳng nằm trên cùng một đường thẳng. Dùng để căn thẳng hàng các cạnh bị ngắt quãng, như hai bên của một khe khuyết.",- "help.sketch.constraint.concentric": "Cho hai đường tròn hoặc cung cùng một tâm. Dùng cho vòng, lỗ khoét bậc và trục có vai.",+ "help.sketch.constraint.concentric": "Cho hai đường tròn hoặc cung cùng một tâm, hoặc đặt tâm của đường tròn hay cung tại một điểm phác thảo, kể cả gốc tọa độ. Chọn cặp đối tượng theo thứ tự bất kỳ.","help.sketch.constraint.curvature": "Làm hai đường cong gặp nhau tại đầu mút tiếp tục với cùng độ cong (G2). Dùng khi nối tiếp tuyến chưa đủ mượt, chẳng hạn trên các bề mặt nhìn thấy.","help.sketch.constraint.equal": "Làm các đường thẳng bằng chiều dài, hoặc các đường tròn và cung bằng bán kính. Dùng để một kích thước điều khiển nhiều chi tiết giống nhau.","help.sketch.constraint.fix": "Cố định điểm hoặc đường cong tại chỗ, hoặc bỏ cố định chúng. Dùng cho hình học không được di chuyển khi bạn kéo hoặc giải phác thảo.",diff --git a/assets/locales/zh.json b/assets/locales/zh.jsonindex 8d6d079ddf..e4ebfdf79e 100644--- a/assets/locales/zh.json+++ b/assets/locales/zh.json@@ -1557,7 +1557,7 @@"help.sketch.constrainer": "应用所选的一两条曲线已近乎满足的约束,例如水平、平行、相切或相等。用于逐个关系地整理手绘草图。","help.sketch.constraint.coincident": "使一个点位于另一个点、曲线或草图轴上。用于闭合轮廓中的间隙,或把点放到直线上。","help.sketch.constraint.collinear": "使两条直线位于同一条直线上。用于对齐被打断的边,例如缺口的两侧。",- "help.sketch.constraint.concentric": "使两个圆或圆弧具有相同的圆心。用于圆环、沉孔和带台阶的轴。",+ "help.sketch.constraint.concentric": "使两个圆或圆弧具有相同的圆心,也可将圆或圆弧的圆心约束到草图点(包括原点)。两者的选择顺序不限。","help.sketch.constraint.curvature": "使在端点相接的两条曲线以相同的曲率延续 (G2)。用于相切连接不够平滑的地方,例如可见曲面。","help.sketch.constraint.equal": "使直线长度相等,或使圆和圆弧半径相等。用于让一个尺寸同时驱动多个相同的特征。","help.sketch.constraint.fix": "把点或曲线固定在当前位置,或再次解除固定。用于拖动或解算草图时不得移动的几何体。",diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rsindex ae94a70e38..120c21a37f 100644--- a/crates/engine/src/cmd/sketch.rs+++ b/crates/engine/src/cmd/sketch.rs@@ -174,7 +174,7 @@ pub static COMMANDS: &[CommandSpec] = &[.at("SKETCH", "CONSTRAINTS").icon("c_concentric").enabled(in_sketch)- .params(concat!("a, b: circles/arcs", model_operand_doc!())),+ .params(concat!("a, b: two circles/arcs, or a circle/arc and a sketch point (including origin), in either order; the point and the curve's centre become coincident", model_operand_doc!())),CommandSpec::new("sketch.constraint.collinear", "Collinear", c_collinear).at("SKETCH", "CONSTRAINTS").icon("c_collinear")@@ -2454,11 +2454,21 @@ fn c_perpendicular(s: &mut Session, p: &Value) -> Result<Value> {})}fn c_concentric(s: &mut Session, p: &Value) -> Result<Value> {- let p = &super::sketch_project::project_operands(s, p, "sketch.constraint.concentric", &["a", "b"])?;- constrain(s, p, "sketch.constraint.concentric", |sk| {- two_curves(sk, p, "sketch.constraint.concentric")- .and_then(|ab| two_different("sketch.constraint.concentric", ab))- .map(|(a, b)| ConstraintKind::Concentric { a, b })+ let cmd = "sketch.constraint.concentric";+ let p = &super::sketch_project::project_operands(s, p, cmd, &["a", "b"])?;+ constrain(s, p, cmd, |sk| {+ let centre = |key: &str| {+ let curve = sk.curves.get(sk.curve_index(p.get(key)?.as_str()?)?)?;+ match curve.kind {+ CurveKind::Circle { c, .. } | CurveKind::Arc { c, .. } => Some(c),+ _ => None,+ }+ };+ let point = |key: &str| sk.resolve_point(p.get(key)?.as_str()?);+ if let Some((p, q)) = centre("a").zip(point("b")).or_else(|| centre("b").zip(point("a"))) {+ return Ok(ConstraintKind::Coincident { p, q });+ }+ two_curves(sk, p, cmd).and_then(|ab| two_different(cmd, ab)).map(|(a, b)| ConstraintKind::Concentric { a, b })})}fn c_collinear(s: &mut Session, p: &Value) -> Result<Value> {diff --git a/crates/engine/src/cmd/sketch_constraints_tests.rs b/crates/engine/src/cmd/sketch_constraints_tests.rsindex c9f8eda30a..ca3409bdd2 100644--- a/crates/engine/src/cmd/sketch_constraints_tests.rs+++ b/crates/engine/src/cmd/sketch_constraints_tests.rs@@ -25,6 +25,59 @@ fn sketch(s: &Session) -> solidcraft_sketch::Sketch {s.model.state().sketch(s.active_sketch.unwrap()).unwrap().sketch.clone()}+#[test]+fn concentric_centres_a_circle_or_arc_on_a_point_in_either_order() {+ for arc in [false, true] {+ for origin in [false, true] {+ for reverse in [false, true] {+ let mut s = new_sketch();+ let made = if arc {+ run(&mut s, "sketch.arc.center_point", json!({"center": [20, 10], "start": [25, 10], "end": [20, 15]}))+ } else {+ run(&mut s, "sketch.circle.center", json!({"center": [20, 10], "radius": 5}))+ };+ let curve = ids(&made["curves"])[0].clone();+ let (point, expected) = if origin {+ ("origin", Vec2::new(0.0, 0.0))+ } else {+ run(&mut s, "sketch.point", json!({"point": [-7, 4], "id": "target"}));+ run(&mut s, "sketch.constraint.fix", json!({"entity": "target"}));+ ("target", Vec2::new(-7.0, 4.0))+ };+ let before = s.doc.to_json();+ let undo = s.undo.len();+ let params = if reverse { json!({"a": point, "b": curve}) } else { json!({"a": curve, "b": point}) };+ let result = run(&mut s, "sketch.constraint.concentric", params);+ let sk = sketch(&s);+ let index = sk.curve_index(&curve).unwrap();+ assert!(sk.center(index).unwrap().dist(expected) < 1e-6, "arc={arc}, origin={origin}, reverse={reverse}");+ assert!((sk.radius(index).unwrap() - 5.0).abs() < 1e-6);+ assert!(matches!(+ sk.constraints.iter().find(|c| c.id == result["constraint"].as_str().unwrap()).unwrap().kind,+ ConstraintKind::Coincident { .. }+ ));+ assert_eq!(s.undo.len(), undo + 1);+ run(&mut s, "edit.undo", json!({}));+ assert_eq!(s.doc.to_json(), before);+ }+ }+ }+}++#[test]+fn concentric_rejects_invalid_point_pairs_without_changing_the_sketch() {+ let mut s = new_sketch();+ run(&mut s, "sketch.circle.center", json!({"center": [20, 10], "radius": 5, "id": "circle"}));+ run(&mut s, "sketch.line", json!({"points": [[10, 10], [20, 20]], "ids": ["line"]}));+ let before = s.doc.to_json();+ let undo = s.undo.len();+ for (a, b) in [("line", "origin"), ("origin", "line"), ("origin", "circle.center"), ("circle", "circle.center"), ("circle", "missing")] {+ assert!(s.execute("sketch.constraint.concentric", &json!({"a": a, "b": b})).is_err(), "{a}, {b}");+ assert_eq!(s.doc.to_json(), before);+ assert_eq!(s.undo.len(), undo);+ }+}+#[test]fn redundant_dimensions_are_refused_driven_ones_measure() {let mut s = new_sketch();diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rsindex 5bb306ce05..2b47d3f032 100644--- a/crates/ui-egui/src/context_menu.rs+++ b/crates/ui-egui/src/context_menu.rs@@ -1323,6 +1323,9 @@ fn sketch_entity_items(app: &SolveApp) -> Vec<Item> {c.push(cmd(app, "sketch.constraint.equal", "Equal").with(ab.clone()));c.push(cmd(app, "sketch.constraint.tangent", "Tangent").with(ab));}+ if r == 1 && p == 1 && n == 2 {+ c.push(cmd(app, "sketch.constraint.concentric", "Concentric").with(json!({ "a": picked[0], "b": picked[1] })));+ }if l == 1 && r == 1 && n == 2 {c.push(cmd(app, "sketch.constraint.tangent", "Tangent").with(json!({ "a": picked[0], "b": picked[1] })));}diff --git a/crates/ui-egui/src/sketch_centre_align_ui_tests.rs b/crates/ui-egui/src/sketch_centre_align_ui_tests.rsindex 7ec95215f9..4714c107b1 100644--- a/crates/ui-egui/src/sketch_centre_align_ui_tests.rs+++ b/crates/ui-egui/src/sketch_centre_align_ui_tests.rs@@ -27,6 +27,56 @@ fn point(h: &Harness, id: &str) -> Vec2 {sk.point(sk.resolve_point(id).unwrap()).unwrap()}+#[test]+fn concentric_accepts_a_circle_and_point_before_or_after_starting_the_tool() {+ for preselect in [false, true] {+ for reverse in [false, true] {+ for origin in [false, true] {+ let mut h = Harness::new();+ h.app.preferences.look_at_anim = false;+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.app.run("sketch.circle.center", json!({"center": [30, 20], "radius": 8, "id": "c1"})).unwrap();+ let target = if origin {+ [0, 0]+ } else {+ h.app.run("sketch.point", json!({"point": [-10, -15], "id": "target"})).unwrap();+ h.app.run("sketch.constraint.fix", json!({"entity": "target"})).unwrap();+ [-10, -15]+ };+ h.app.cam.distance = 200.0;+ h.settle();+ let before = h.app.session.doc.to_json();+ if !preselect {+ h.step(&json!({"start": "sketch.constraint.concentric"})).unwrap();+ }+ let picks = if reverse { [target, [38, 20]] } else { [[38, 20], target] };+ for (index, xy) in picks.into_iter().enumerate() {+ h.step(&json!({"click": {"sketch": xy}, "shift": preselect && index == 1})).unwrap();+ }+ if preselect {+ h.step(&json!({"start": "sketch.constraint.concentric"})).unwrap();+ assert!(h.app.session.selection.is_empty(), "the preselected pair was consumed");+ }+ h.step(&json!({"expect": {"errors": 0}})).unwrap();+ let expected = Vec2::new(f64::from(target[0]), f64::from(target[1]));+ assert!(point(&h, "c1.center").dist(expected) < 1e-6, "preselect={preselect}, reverse={reverse}, origin={origin}");+ h.app.run("edit.undo", json!({})).unwrap();+ assert_eq!(h.app.session.doc.to_json(), before);+ }+ }+ }+}++#[test]+fn the_context_menu_offers_concentric_for_a_circle_and_the_origin() {+ let mut h = square_with_circle();+ h.app.session.selection = vec![SketchCurve { id: "c1".into(), sketch: None }, SketchPoint { id: "origin".into() }];+ let items = context_menu::items(&h.app, &Target::Viewport);+ let item = items.iter().find(|i| i.id == "sketch.constraint.concentric").expect("the menu offers Concentric");+ context_menu::run_item(&mut h.app, item, egui::Pos2::ZERO);+ assert!(point(&h, "c1.center").len() < 1e-6);+}+#[test]fn selecting_the_centre_and_an_edge_preselects_the_alignment() {let h = square_with_circle();diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rsindex 3758653f12..7b134c477e 100644--- a/crates/ui-egui/src/tools.rs+++ b/crates/ui-egui/src/tools.rs@@ -740,6 +740,11 @@ pub(crate) fn constraint_preselection(}("sketch.constraint.horizontal_vertical", _) => crate::selection::alignment_points(selection).map(|points| json!({"points": points})),("sketch.constraint.coincident", [_, _]) => crate::selection::coincident_operands(selection),+ ("sketch.constraint.concentric", [SketchCurve { id: a, .. }, SketchPoint { id: b }] | [SketchPoint { id: a }, SketchCurve { id: b, .. }])+ if a != b =>+ {+ Some(json!({"a":a,"b":b}))+ }("sketch.constraint.midpoint",[SketchPoint { id: point }, SketchCurve { id: line, .. }] | [SketchCurve { id: line, .. }, SketchPoint { id: point }],diff --git a/docs/book/src/guide/sketching.md b/docs/book/src/guide/sketching.mdindex 98ee944de9..ad72fc1f0b 100644--- a/docs/book/src/guide/sketching.md+++ b/docs/book/src/guide/sketching.md@@ -325,6 +325,9 @@ aligned, horizontal, vertical, point-to-line, line-to-circle, point-to-circle, cradius, diameter, arc length and angle dimensions. For an arc's length, click the arc and then one of its end points. Each is a parameter(`d1`, `d2`, …), so it can hold an expression.+**Concentric** accepts two circles or arcs, or a circle or arc and a sketch point (including the+origin). Preselect the pair and choose Concentric, or start the tool and pick both, in either order.+Press D, click what you want to measure and type the value: as soon as the click settles thedimension (one line, circle or arc, or the second point or line of a distance or angle), itsvalue box takes the keyboard with the measured value selected, so typing replaces it. Numbers,