SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: the Line tool can switch to a tangent arc and back without changing tool (#9489) (#9553)
HiroKenEz8f259d5b8336
diff --git a/assets/locales/pending/line-hover-tangent-arc.json b/assets/locales/pending/line-hover-tangent-arc.jsonnew file mode 100644index 0000000000..c1f89edb7e--- /dev/null+++ b/assets/locales/pending/line-hover-tangent-arc.json@@ -0,0 +1,42 @@+{+ "en": {+ "prefs.line_hover_tangent_arc": "Rest on a line's last point to switch to a tangent arc",+ "prefs.line_hover_tangent_arc_note": "In the Line tool, once a segment is drawn, move away from the chain's last point, come back and hold the pointer still on it: the next click ends a tangent arc, and the same gesture goes back to lines. Off: resting there does nothing.",+ "ui.line_arc_hint": "Tangent arc: click the arc's end. Rest on the last point again for lines; right-click or Esc to finish"+ },+ "ja": {+ "prefs.line_hover_tangent_arc": "線の最後の点で止めると接線円弧に切り替える",+ "prefs.line_hover_tangent_arc_note": "線ツールで線分を描いたあと、連続線の最後の点から一度離れて戻り、その点の上でポインターを止めると、次のクリックで接線円弧の終点を指定します。同じ操作で線に戻ります。オフ: 止めても何も起こりません。",+ "ui.line_arc_hint": "接線円弧: 円弧の終点をクリックします。線に戻るには最後の点で再び止めます。右クリックまたは Esc で終了します"+ },+ "zh": {+ "prefs.line_hover_tangent_arc": "停留在直线的最后一点上以切换到相切圆弧",+ "prefs.line_hover_tangent_arc_note": "在直线工具中,画好一段后,先离开连续线的最后一点,再回到该点并让指针保持不动:下一次单击将确定相切圆弧的终点,同样的操作可切回直线。关闭:停留在该点不起作用。",+ "ui.line_arc_hint": "相切圆弧:单击圆弧的终点。再次停留在最后一点可切回直线;右键单击或按 Esc 结束"+ },+ "de": {+ "prefs.line_hover_tangent_arc": "Auf dem letzten Linienpunkt verweilen, um zum Tangentialbogen zu wechseln",+ "prefs.line_hover_tangent_arc_note": "Im Linienwerkzeug: Nach einem Segment vom letzten Punkt der Kette wegbewegen, zurückkehren und den Zeiger still darauf halten. Der nächste Klick beendet dann einen Tangentialbogen, und dieselbe Geste wechselt zurück zu Linien. Aus: Das Verweilen bewirkt nichts.",+ "ui.line_arc_hint": "Tangentialbogen: Ende des Bogens anklicken. Für Linien erneut auf dem letzten Punkt verweilen; Rechtsklick oder Esc beendet"+ },+ "ko": {+ "prefs.line_hover_tangent_arc": "선의 마지막 점에 머무르면 접선 호로 전환",+ "prefs.line_hover_tangent_arc_note": "선 도구에서 선분을 그린 뒤 체인의 마지막 점에서 벗어났다가 돌아와 포인터를 그 위에 멈추면, 다음 클릭으로 접선 호의 끝점을 지정합니다. 같은 동작으로 선으로 돌아갑니다. 끔: 머물러도 아무 일도 일어나지 않습니다.",+ "ui.line_arc_hint": "접선 호: 호의 끝점을 클릭합니다. 선으로 돌아가려면 마지막 점에 다시 머무르고, 끝내려면 오른쪽 클릭 또는 Esc를 누릅니다"+ },+ "ar": {+ "prefs.line_hover_tangent_arc": "التوقف عند آخر نقطة في الخط للتبديل إلى قوس مماسي",+ "prefs.line_hover_tangent_arc_note": "في أداة الخط، بعد رسم قطعة، ابتعد عن آخر نقطة في السلسلة ثم عد إليها وأبقِ المؤشر ثابتًا عليها: تحدد النقرة التالية نهاية قوس مماسي، والحركة نفسها تعيدك إلى الخطوط. عند الإيقاف: لا يحدث شيء عند التوقف هناك.",+ "ui.line_arc_hint": "قوس مماسي: انقر نهاية القوس. توقف عند آخر نقطة مرة أخرى للعودة إلى الخطوط؛ انقر بالزر الأيمن أو اضغط Esc للإنهاء"+ },+ "he": {+ "prefs.line_hover_tangent_arc": "השהיה על הנקודה האחרונה של קו עוברת לקשת משיקה",+ "prefs.line_hover_tangent_arc_note": "בכלי הקו, אחרי ציור מקטע, התרחקו מהנקודה האחרונה של השרשרת, חזרו אליה והחזיקו את הסמן עליה ללא תנועה: הלחיצה הבאה תסיים קשת משיקה, ואותה מחווה מחזירה לקווים. כבוי: השהיה שם אינה עושה דבר.",+ "ui.line_arc_hint": "קשת משיקה: לחצו על קצה הקשת. השהו שוב על הנקודה האחרונה כדי לחזור לקווים; לחיצה ימנית או Esc לסיום"+ },+ "vi": {+ "prefs.line_hover_tangent_arc": "Dừng trên điểm cuối của đường để chuyển sang cung tiếp tuyến",+ "prefs.line_hover_tangent_arc_note": "Trong công cụ Đường, sau khi vẽ một đoạn, hãy rời điểm cuối của chuỗi, quay lại và giữ yên con trỏ trên đó: lần nhấp tiếp theo sẽ kết thúc một cung tiếp tuyến, và cùng thao tác đó sẽ quay lại đường thẳng. Tắt: dừng ở đó không có tác dụng.",+ "ui.line_arc_hint": "Cung tiếp tuyến: nhấp vào điểm cuối của cung. Dừng lại trên điểm cuối cùng để quay lại đường thẳng; nhấp chuột phải hoặc Esc để kết thúc"+ }+}diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rsindex 434545b7c8..cf228ea4a3 100644--- a/crates/engine/src/cmd/mod.rs+++ b/crates/engine/src/cmd/mod.rs@@ -46,6 +46,7 @@ pub use join_pieces::{Addition, addition};pub use sketch::dimension_roles;pub(crate) use sketch::face::face_pick_form;pub use sketch_construction::{ConstructionLine, construction_line_choice, construction_line_mode, construction_line_solutions};+pub use sketch_create::tangent_arc_preview;pub use sketch_import::drawing_import_command;pub use sketch_modify::{extend_arc_preview, extend_preview, trim_piece};pub use view_dxf::sketch::exportable as view_dxf_exportable;diff --git a/crates/engine/src/cmd/sketch_create.rs b/crates/engine/src/cmd/sketch_create.rsindex 39758b08f5..05ceba21cc 100644--- a/crates/engine/src/cmd/sketch_create.rs+++ b/crates/engine/src/cmd/sketch_create.rs@@ -37,7 +37,7 @@ pub static COMMANDS: &[CommandSpec] = &[.enabled(in_sketch).params(concat!("mid: [x,y], point ref or snap (\"mid:<line>\", \"on:<curve>:x,y\", model vertex/edge); end: [x,y]; construction?", created_doc!())),CommandSpec::new("sketch.arc.tangent", "Tangent Arc", arc_tangent).at("SKETCH", "CREATE").icon("arc_tangent").enabled(in_sketch).params(concat!(- "start: end point of a line or arc (\"l1.end\"), end: [x,y]; curve?: the curve to be tangent to (default: the one ending at start)",+ "start: end point of a line or arc (\"l1.end\"), end: [x,y] or an existing point's id (\"l2.start\": the arc ends on that point); curve?: the curve to be tangent to (default: the one ending at start)",created_doc!())),CommandSpec::new("sketch.circle.two_tangent", "2-Tangent Circle", circle_tan_tan)@@ -819,10 +819,51 @@ pub(super) fn leaving_dir(sk: &Sketch, ci: usize, pi: usize) -> Option<Vec2> {}}+/// The centre of the arc that leaves `start` in direction `dir` and ends at `end`, and whether it+/// runs counter-clockwise. `None` straight ahead (or back), where no arc does.+fn tangent_arc_centre(dir: Vec2, start: Vec2, end: Vec2) -> Option<(Vec2, bool)> {+ let n = dir.perp();+ let d = end - start;+ let den = 2.0 * n.dot(d);+ if den.abs() < 1e-9 * d.len().max(1e-9) || d.len() < 1e-9 {+ return None;+ }+ Some((start + n * (d.len2() / den), den > 0.0))+}++/// The arc `sketch.arc.tangent` would draw from point `start` on `curve` to `end`, alone in a+/// sketch of its own for a preview. `None` where the command would refuse.+pub fn tangent_arc_preview(sk: &Sketch, curve: &str, start: &str, end: Vec2) -> Option<Sketch> {+ let pi = sk.resolve_point(start)?;+ let s0 = sk.point(pi)?;+ let (center, ccw) = tangent_arc_centre(leaving_dir(sk, sk.curve_index(curve)?, pi)?, s0, end)?;+ if !center.is_finite() {+ return None;+ }+ let mut out = Sketch::new();+ if ccw {+ out.add_arc(center, s0, end, [None; 3], None).ok()?;+ } else {+ out.add_arc(center, end, s0, [None; 3], None).ok()?;+ out.curves.first_mut()?.reversed = true;+ }+ Some(out)+}+fn arc_tangent(s: &mut Session, p: &Value) -> Result<Value> {let cmd = "sketch.arc.tangent";- let end = req_vec2(cmd, p, "end")?;+ // An id ends the arc on that point, so a chain can close; coordinates make a new point.+ let end_ref = p.get("end").and_then(Value::as_str);+ let at = if end_ref.is_some() { None } else { Some(req_vec2(cmd, p, "end")?) };let (out, info) = edit(s, p, cmd, false, |sk, doc| {+ let (end, end_point) = match (end_ref, at) {+ (Some(r), _) => {+ let q = sk.resolve_point(r).ok_or_else(|| bad(cmd, format!("unknown sketch point `{r}`")))?;+ (sk.point(q).ok_or_else(|| bad(cmd, format!("unknown sketch point `{r}`")))?, Some(q))+ }+ (None, Some(at)) => (at, None),+ (None, None) => return Err(bad(cmd, "missing `end`")),+ };let st = req_parg(sk, doc, p, "start", cmd)?;let picked = st.idx().ok_or_else(|| bad(cmd, "`start` must be the end point of a line or arc"))?;// The picked point, then any other point at the same place: a trimmed arc's end is its own@@ -848,17 +889,11 @@ fn arc_tangent(s: &mut Session, p: &Value) -> Result<Value> {};let t = leaving_dir(sk, ci, pi).ok_or_else(|| bad(cmd, "`start` is not an end of that curve"))?;let s0 = st.pos();- let n = t.perp();- let d = end - s0;- let den = 2.0 * n.dot(d);- if den.abs() < 1e-9 * d.len().max(1e-9) || d.len() < 1e-9 {- return Err(bad(cmd, "the end is straight ahead: draw a line instead"));- }- let center = s0 + n * (d.len2() / den);- let a = if den > 0.0 {- sk.add_arc(center, s0, end, [None, Some(pi), None], None)?+ let (center, ccw) = tangent_arc_centre(t, s0, end).ok_or_else(|| bad(cmd, "the end is straight ahead: draw a line instead"))?;+ let a = if ccw {+ sk.add_arc(center, s0, end, [None, Some(pi), end_point], None)?} else {- let a = sk.add_arc(center, end, s0, [None, None, Some(pi)], None)?;+ let a = sk.add_arc(center, end, s0, [None, end_point, Some(pi)], None)?;if let Some(c) = sk.curves.get_mut(a) {c.reversed = true;}diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rsindex 5537cf25ae..bdd89943c0 100644--- a/crates/engine/src/cmd/sketch_modify_tests.rs+++ b/crates/engine/src/cmd/sketch_modify_tests.rs@@ -3503,3 +3503,45 @@ fn corner_tools_refuse_all_spatial_curves_with_an_unsupported_message() {}}}++/// `sketch.arc.tangent` ends on an existing point when `end` names it, so a chain can close, and+/// makes a new point for coordinates as before (#9489). The preview is the arc the command draws.+#[test]+fn a_tangent_arc_can_end_on_an_existing_point() {+ let mut s = new_sketch();+ let far = ids(&run(&mut s, "sketch.line", json!({"points": [[20, 20], [40, 20]], "connect": false, "infer": false}))["curves"])[0].clone();+ let line = ids(&run(&mut s, "sketch.line", json!({"points": [[0, 0], [10, 0]], "connect": false, "infer": false}))["curves"])[0].clone();+ let start = format!("{line}.end");+ let target = format!("{far}.start");+ let sk = sketch(&s);+ let preview = crate::cmd::tangent_arc_preview(&sk, &line, &start, Vec2::new(20.0, 20.0)).expect("an arc");+ assert_eq!(preview.curves.len(), 1);+ assert!(preview.center(0).unwrap().dist(Vec2::new(10.0, 12.5)) < 1e-9, "{:?}", preview.center(0));+ assert!(crate::cmd::tangent_arc_preview(&sk, &line, &start, Vec2::new(30.0, 0.0)).is_none(), "straight ahead there is no arc");++ let points = sk.points.len();+ let r = run(&mut s, "sketch.arc.tangent", json!({"start": start, "curve": line, "end": target}));+ let arc = ids(&r["curves"])[0].clone();+ let sk = sketch(&s);+ assert_eq!(sk.resolve_point(&format!("{arc}.end")), sk.resolve_point(&format!("{far}.start")), "the arc ends on that point");+ assert_eq!(sk.resolve_point(&format!("{arc}.start")), sk.resolve_point(&format!("{line}.end")));+ assert_eq!(sk.points.len(), points + 1, "only the arc's centre is new");+ let ai = sk.curve_index(&arc).unwrap();+ assert!(sk.center(ai).unwrap().dist(Vec2::new(10.0, 12.5)) < 1e-6, "{:?}", sk.center(ai));+ assert!(close(sk.radius(ai).unwrap(), 12.5));++ // Clockwise: the arc is stored the other way round, and its end is still the named point.+ let down = ids(&run(&mut s, "sketch.line", json!({"points": [[0, -50], [10, -50]], "connect": false, "infer": false}))["curves"])[0].clone();+ let mark = ids(&run(&mut s, "sketch.line", json!({"points": [[20, -70], [40, -70]], "connect": false, "infer": false}))["curves"])[0].clone();+ let r = run(&mut s, "sketch.arc.tangent", json!({"start": format!("{down}.end"), "curve": down, "end": format!("{mark}.start")}));+ let arc = ids(&r["curves"])[0].clone();+ let sk = sketch(&s);+ assert_eq!(sk.resolve_point(&format!("{arc}.end")), sk.resolve_point(&format!("{mark}.start")));+ assert_eq!(sk.resolve_point(&format!("{arc}.start")), sk.resolve_point(&format!("{down}.end")));++ // A name that is no point, and the arc's own start, are refused and change nothing.+ let before = s.doc.to_json();+ assert!(s.execute("sketch.arc.tangent", &json!({"start": format!("{down}.end"), "curve": down, "end": "nowhere"})).is_err());+ assert!(s.execute("sketch.arc.tangent", &json!({"start": format!("{down}.end"), "curve": down, "end": format!("{down}.end")})).is_err());+ assert_eq!(s.doc.to_json(), before);+}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 6b9fb23470..d997055090 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -255,6 +255,7 @@ mod sketch_edit_tests;mod sketch_families;#[cfg(test)]mod sketch_guidance_ui_tests;+pub(crate) mod sketch_line_arc;pub mod sketch_modify_ui;#[cfg(test)]mod sketch_modify_ui_tests;diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex ec6b022a0c..b16a125147 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1379,6 +1379,10 @@ preference_settings! {/// release and end there (#7247); clicks still draw a chain. Off (the default): a drag is a/// click that moved on the way, placing a point where it is let go (#2448).line_drag_draws_one: bool = false, PAGE_SKETCH => check_id("prefs.line_drag_draws_one");+ /// In the Line tool, leaving the chain's last point and resting back on it switches to a+ /// tangent arc, and the same again back to lines (#9489). Off (the default): resting there+ /// does nothing, and tangent arcs are the Arc tool's.+ line_hover_tangent_arc: bool = false, PAGE_SKETCH => check_id("prefs.line_hover_tangent_arc");/// Include hidden geometry and a small pointer neighbourhood in Select Other.select_other_hidden: bool = true, PAGE_SKETCH => check_id("prefs.select_other_hidden");/// When true: Shift+click adds without removing; Primary toggles.@@ -5504,6 +5508,7 @@ mod tests {("sketch_tracking_points", json!(false), PAGE_SKETCH),("sketch_align_points", json!(true), PAGE_SKETCH),("sketch_recent_snap", json!(true), PAGE_SKETCH),+ ("line_hover_tangent_arc", json!(true), PAGE_SKETCH),("msaa", json!(8), PAGE_GRAPHICS),("single_surface_analysis", json!(false), PAGE_GRAPHICS),];diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rsindex 28df8185a5..7655ac01f9 100644--- a/crates/ui-egui/src/prefs/sketch.rs+++ b/crates/ui-egui/src/prefs/sketch.rs@@ -42,6 +42,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {));let line_drag = setting::line_drag_draws_one(app, ui).on_hover_text(app.tr("prefs.line_drag_draws_one_note"));crate::scenario::publish_target("prefs:line_drag_draws_one", line_drag.rect);+ let line_arc = setting::line_hover_tangent_arc(app, ui).on_hover_text(app.tr("prefs.line_hover_tangent_arc_note"));+ crate::scenario::publish_target("prefs:line_hover_tangent_arc", line_arc.rect);ui_kit::settings_block_hint(ui, app.tr("prefs.hold_stop_snapping"), app.tr("prefs.snap_drawing_note"), t.space_24 * 8.0 + t.space_8, |ui| {let combo = &mut app.preferences.suppress_sketch_snap;ui_kit::settings_control_width(ui, t.space_24 * 7.0 + t.space_12, |ui| {diff --git a/crates/ui-egui/src/sketch_line_arc.rs b/crates/ui-egui/src/sketch_line_arc.rsnew file mode 100644index 0000000000..4ee31e69be--- /dev/null+++ b/crates/ui-egui/src/sketch_line_arc.rs@@ -0,0 +1,187 @@+//! The Line tool's switch to tangent arcs and back (#9489), with Preferences › Sketch asking for+//! it: leave the chain's last point, come back and hold the pointer still on it. While switched+//! the tool is `sketch.arc.tangent`, so the arc is that command's and whatever asks which tool is+//! out gets the true answer; [`LineChain`] is what makes it part of the chain.++use egui::{Pos2, Stroke};+use serde_json::{Value, json};+use solidcraft_engine::geom::Vec2;+use solidcraft_engine::sketch::Sketch;++use crate::SolveApp;+use crate::tools::Tool;+use crate::viewport::Proj;++const LINE: &str = "sketch.line";+const TANGENT_ARC: &str = "sketch.arc.tangent";+/// How long the pointer rests on the point before the mode switches (seconds).+const REST_SECONDS: f64 = 0.35;+/// How near the point counts as on it (screen points).+const ON_POINT: f32 = 8.0;+/// How far the pointer must go from the point first (screen points). A click leaves the pointer on+/// the point it placed, and a pause there to think must not switch anything.+const AWAY: f32 = 20.0;+/// How far a resting pointer may drift, as a hand does (screen points).+const STILL: f32 = 2.0;++/// Where a Line tool's chain has got to.+#[derive(Clone, Debug, Default)]+pub struct LineChain {+ /// The curve the chain's last point ends. `None` until the chain has drawn one.+ curve: Option<String>,+ /// The pointer has been away from that point since it was placed or the mode last switched.+ left: bool,+ /// Where the pointer came to rest on the point, and when (the frame clock).+ rest: Option<(Pos2, f64)>,+ /// Just switched back to lines: says so until the pointer leaves.+ back_to_lines: bool,+}++impl LineChain {+ /// Curve `id` now ends the chain, with the pointer still on its end.+ pub fn placed(&mut self, id: &str) {+ *self = LineChain { curve: Some(id.to_string()), ..LineChain::default() };+ }+}++/// Whether the tool is a Line tool's chain drawing tangent arcs, not the Tangent Arc tool itself.+pub fn in_arc_mode(t: &Tool) -> bool {+ t.cmd == TANGENT_ARC && t.chain.curve.is_some()+}++/// Whether the tool has a chain to switch: a segment drawn, and nothing typed for the next one.+fn can_switch(t: &Tool) -> bool {+ (t.cmd == LINE || in_arc_mode(t)) && t.chain.curve.is_some() && t.pts.len() == 1 && !t.dims.iter().any(|b| b.locked)+}++/// Per frame, with `pointer` free over the view (nothing held, no camera move): notes where it has+/// been against the chain's last point, and switches after a rest there.+pub fn follow_pointer(app: &mut SolveApp, ctx: &egui::Context, proj: &Proj, pointer: Option<Pos2>) {+ if !app.preferences.line_hover_tangent_arc || !app.tool.as_ref().is_some_and(can_switch) {+ return;+ }+ if crate::sketch3d::active(app) || app.dialog.is_some() || crate::dim_view::editing() {+ return;+ }+ let screen = {+ let state = app.session.world_state();+ let plane = app.session.active_sketch.and_then(|s| state.sketch(s)).map(|ss| ss.plane);+ let last = app.tool.as_ref().and_then(|t| t.pts.first()).map(|p| p.0);+ plane.zip(last).and_then(|(plane, last)| proj.to_screen(plane.to_world(last)))+ };+ let now = ctx.input(|i| i.time);+ let Some(chain) = app.tool.as_mut().map(|t| &mut t.chain) else { return };+ let (Some(p), Some(point)) = (pointer, screen) else {+ chain.rest = None;+ return;+ };+ let off = p.distance(point);+ if off >= AWAY {+ chain.left = true;+ chain.back_to_lines = false;+ }+ if off > ON_POINT || !chain.left {+ chain.rest = None;+ return;+ }+ match chain.rest {+ Some((at, since)) if at.distance(p) <= STILL => {+ if now - since >= REST_SECONDS {+ switch(app);+ } else {+ ctx.request_repaint_after(std::time::Duration::from_secs_f64(REST_SECONDS - (now - since) + 0.01));+ }+ }+ _ => {+ chain.rest = Some((p, now));+ ctx.request_repaint_after(std::time::Duration::from_secs_f64(REST_SECONDS + 0.01));+ }+ }+}++/// Lines to tangent arcs, or back. The chain's point and curve go across; the pointer has to leave+/// the point before it can switch again.+fn switch(app: &mut SolveApp) {+ let Some(old) = app.tool.as_ref() else { return };+ let to_arc = old.cmd == LINE;+ let next = if to_arc { crate::sketch_tools::tool_for(TANGENT_ARC) } else { Tool::for_command(LINE) };+ let Some(mut next) = next else { return };+ next.pts = old.pts.clone();+ next.hover = old.hover.clone();+ next.chain = LineChain { curve: old.chain.curve.clone(), back_to_lines: !to_arc, ..LineChain::default() };+ app.tool = Some(next);+ let hint = if to_arc { app.tr("ui.line_arc_hint").to_string() } else { crate::tools::hint(LINE) };+ app.set_status(hint, false);+}++/// Right-click or Esc while drawing tangent arcs: the chain ends as a line chain does, and the Line+/// tool stays out. False when the tool isn't that.+pub fn finish(app: &mut SolveApp) -> bool {+ if !app.tool.as_ref().is_some_and(in_arc_mode) {+ return false;+ }+ app.tool = Tool::for_command(LINE);+ app.set_status(crate::tools::hint(LINE), false);+ true+}++/// A click while drawing tangent arcs: the arc, by the tangent arc command, tangent to the chain's+/// last curve, its end the chain's new last point.+pub fn place_arc(app: &mut SolveApp, tool: &mut Tool, end: &(Vec2, Option<String>)) {+ let (Some(start), Some(curve)) = (tool.pts.first().and_then(|p| p.1.clone()), tool.chain.curve.clone()) else { return };+ // On an existing point the arc ends on that point, so an outline closes. The other snaps+ // (a midpoint, a place on a curve) name no point: their coordinates.+ let on_point = |id: &&String| {+ let state = app.session.world_state();+ app.session.active_sketch.and_then(|s| state.sketch(s)).is_some_and(|ss| ss.sketch.resolve_point(id).is_some())+ };+ let to = end.1.as_ref().filter(on_point).map_or_else(|| json!([end.0.x, end.0.y]), |id| json!(id));+ // A failure (the end straight ahead) has said why in the status line; the chain stays as it is.+ let made = crate::tools::draw(app, tool, json!({"start": start, "curve": curve, "end": to}));+ if let Some(id) = made.as_ref().ok().and_then(|v| v["curves"].get(0)).and_then(Value::as_str) {+ tool.pts = vec![(end.0, Some(format!("{id}.end")))];+ tool.chain.placed(id);+ }+}++/// The arc a click would make with the pointer at `hover`, for the preview.+pub fn preview_arc(sketch: &Sketch, t: &Tool, hover: Vec2) -> Option<Sketch> {+ let start = t.pts.first()?.1.as_deref()?;+ solidcraft_engine::cmd::tangent_arc_preview(sketch, t.chain.curve.as_deref()?, start, hover)+}++/// What the cursor says the next click makes (command, icon): while drawing tangent arcs, and just+/// after switching back to lines.+fn shown_mode(t: &Tool) -> Option<(&'static str, &'static str)> {+ if in_arc_mode(t) {+ Some((TANGENT_ARC, "arc_tangent"))+ } else if t.cmd == LINE && t.chain.back_to_lines {+ Some((LINE, "line"))+ } else {+ None+ }+}++/// The words next to the cursor, in the interface language.+pub(crate) fn shown_label(t: &Tool) -> Option<&'static str> {+ shown_mode(t).map(|(command, _)| crate::i18n::tr_label(crate::command_label(command)))+}++/// The label next to the cursor (below the point's coordinates).+pub fn paint_mode(app: &SolveApp, ui: &egui::Ui, painter: &egui::Painter, proj: &Proj) {+ let Some((command, icon)) = app.tool.as_ref().and_then(shown_mode) else { return };+ let Some(pointer) = ui.input(|i| i.pointer.hover_pos()).filter(|p| proj.rect.contains(*p)) else { return };+ let tk = crate::theme::Tokens::view();+ let Some(label) = app.tool.as_ref().and_then(shown_label) else { return };+ let galley = painter.layout_no_wrap(label.to_string(), egui::FontId::proportional(tk.font_small), tk.text);+ let side = galley.size().y.max(14.0);+ let at = pointer + egui::vec2(16.0, 40.0);+ let icon_rect = egui::Rect::from_min_size(at, egui::vec2(side, side));+ let text_at = at + egui::vec2(side + 4.0, (side - galley.size().y) * 0.5);+ let chip = egui::Rect::from_min_max(at, at + egui::vec2(side + 4.0 + galley.size().x, side)).expand(3.0);+ painter.rect_filled(chip, tk.radius_sm, tk.panel);+ painter.rect_stroke(chip, tk.radius_sm, Stroke::new(1.0, tk.sketch_accent), egui::StrokeKind::Inside);+ crate::icons::paint_icon(painter, icon_rect, icon, 1.0);+ painter.galley(text_at, galley, tk.text);+ crate::scenario::publish_count("line_arc_mode_chip", if command == TANGENT_ARC { 1.0 } else { 2.0 });+}diff --git a/crates/ui-egui/src/sketch_moving_click_tests.rs b/crates/ui-egui/src/sketch_moving_click_tests.rsindex 221a8b0613..c36b72a388 100644--- a/crates/ui-egui/src/sketch_moving_click_tests.rs+++ b/crates/ui-egui/src/sketch_moving_click_tests.rs@@ -184,3 +184,320 @@ fn the_line_drag_preference_saves_and_follows_the_sketch_page() {control(&mut h.app, &json!({"button": "cancel"})).unwrap();assert!(h.app.preferences.line_drag_draws_one);}++// ---- The Line tool's switch to tangent arcs and back (#9489) ----++/// The Line tool in a sketch with one segment drawn, (-20, 0) to (0, 0), the pointer on its end.+fn chain_with_a_line(on: bool) -> Harness {+ let mut h = harness("sketch.line");+ h.app.preferences.line_hover_tangent_arc = on;+ click_at(&mut h, [-20.0, 0.0]);+ click_at(&mut h, [0.0, 0.0]);+ assert_eq!(curves(&h), 1, "{:?}", h.app.status);+ h+}++fn click_at(h: &mut Harness, at: [f64; 2]) {+ h.step(&json!({"move":{"sketch":at}})).unwrap();+ h.frames(2);+ h.step(&json!({"click":{"sketch":at}})).unwrap();+ h.frames(2);+}++fn tool(h: &Harness) -> Option<&'static str> {+ h.app.tool.as_ref().map(|t| t.cmd)+}++/// Move off the point, back onto it, and rest there for `frames` frames at 60 Hz.+fn leave_and_rest(h: &mut Harness, on: [f64; 2], frames: usize) {+ h.step(&json!({"move":{"sketch":[on[0] + 15.0, on[1] + 15.0]}})).unwrap();+ h.frames(2);+ h.step(&json!({"move":{"sketch":on}})).unwrap();+ h.frames(frames);+}++/// A rest long enough for the switch: about half a second (it takes 0.35 s).+const REST: usize = 30;++fn sketch(h: &Harness) -> solidcraft_engine::sketch::Sketch {+ let sid = h.app.session.active_sketch.unwrap();+ h.app.session.model.state().sketch(sid).unwrap().sketch.clone()+}++/// The arc last drawn: centre, radius and where it starts and ends as drawn.+fn last_arc(+ sk: &solidcraft_engine::sketch::Sketch,+) -> (solidcraft_engine::geom::Vec2, f64, solidcraft_engine::geom::Vec2, solidcraft_engine::geom::Vec2) {+ let (index, curve) = sk.curves.iter().enumerate().rfind(|(_, c)| matches!(c.kind, CurveKind::Arc { .. })).expect("an arc");+ let CurveKind::Arc { c, a, b } = curve.kind else { panic!("not an arc: {curve:?}") };+ let centre = sk.point(c).unwrap();+ // As drawn: a clockwise arc is stored the other way round.+ let (from, to) = if curve.reversed { (b, a) } else { (a, b) };+ let (start, end) = (sk.point(from).unwrap(), sk.point(to).unwrap());+ assert!(index > 0, "the arc follows a line");+ (centre, centre.dist(start), start, end)+}++#[test]+fn off_by_default_resting_on_the_last_point_does_nothing() {+ assert!(!crate::prefs::Prefs::default().line_hover_tangent_arc, "off by default");+ let mut h = chain_with_a_line(false);+ leave_and_rest(&mut h, [0.0, 0.0], REST * 2);+ assert_eq!(tool(&h), Some("sketch.line"), "the tool stays the Line tool");+ assert_eq!(crate::scenario::count_of("line_arc_mode_chip"), None, "and nothing shows at the cursor");+ // The next click is a line, as ever.+ click_at(&mut h, [0.0, 20.0]);+ assert_eq!(curves(&h), 2);+ assert!(sketch(&h).curves.iter().all(|c| matches!(c.kind, CurveKind::Line { .. })));+}++#[test]+fn a_rest_on_the_last_point_makes_the_next_click_a_tangent_arc_and_back_to_a_line() {+ let mut h = chain_with_a_line(true);+ leave_and_rest(&mut h, [0.0, 0.0], REST);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"), "{:?}", h.app.status);+ assert_eq!(crate::scenario::count_of("line_arc_mode_chip"), Some(1.0), "the cursor says Tangent Arc");+ assert_eq!(h.app.tool.as_ref().and_then(crate::sketch_line_arc::shown_label), Some("Tangent Arc"), "in words, not a message id");++ // The line runs along +X into (0, 0): the tangent arc to (10, 10) has its centre on the+ // normal there, (0, 10), at radius 10, and leaves running along +X.+ click_at(&mut h, [10.0, 10.0]);+ assert_eq!(curves(&h), 2, "{:?}", h.app.status);+ let sk = sketch(&h);+ let (centre, radius, start, end) = last_arc(&sk);+ assert!(centre.dist(solidcraft_engine::geom::Vec2::new(0.0, 10.0)) < 1e-6, "centre {centre:?}");+ assert!((radius - 10.0).abs() < 1e-6, "radius {radius}");+ assert!(start.dist(solidcraft_engine::geom::Vec2::ZERO) < 1e-6 && end.dist(solidcraft_engine::geom::Vec2::new(10.0, 10.0)) < 1e-6);+ let (line, arc) = (sk.curves.first().unwrap(), sk.curves.get(1).unwrap());+ let shared = sk.resolve_point(&format!("{}.end", line.id)) == sk.resolve_point(&format!("{}.start", arc.id));+ assert!(shared, "the arc starts on the line's own end");+ assert!(+ sk.constraints.iter().any(|c| matches!(c.kind, solidcraft_engine::sketch::ConstraintKind::Tangent { a: 0, b: 1 })),+ "tangent to the line: {:?}",+ sk.constraints+ );+ assert_eq!(tool(&h), Some("sketch.arc.tangent"), "it keeps drawing arcs until switched back");++ // The arc's end is the chain's point; the same gesture goes back to lines.+ leave_and_rest(&mut h, [10.0, 10.0], REST);+ assert_eq!(tool(&h), Some("sketch.line"), "{:?}", h.app.status);+ assert_eq!(crate::scenario::count_of("line_arc_mode_chip"), Some(2.0), "the cursor says Line");+ assert_eq!(h.app.tool.as_ref().and_then(crate::sketch_line_arc::shown_label), Some("Line"));+ click_at(&mut h, [10.0, 30.0]);+ assert_eq!(curves(&h), 3, "{:?}", h.app.status);+ let sk = sketch(&h);+ let (arc, line) = (sk.curves.get(1).unwrap(), sk.curves.get(2).unwrap());+ assert!(matches!(line.kind, CurveKind::Line { .. }));+ let shared = sk.resolve_point(&format!("{}.end", arc.id)) == sk.resolve_point(&format!("{}.start", line.id));+ assert!(shared, "the line starts on the arc's end");+ // And the chain goes on from there as lines.+ click_at(&mut h, [30.0, 30.0]);+ assert_eq!(curves(&h), 4);+ assert_eq!(tool(&h), Some("sketch.line"));+}++#[test]+fn a_rounded_corner_outline_closes_in_one_line_session() {+ let mut h = harness("sketch.line");+ h.app.preferences.line_hover_tangent_arc = true;+ click_at(&mut h, [-20.0, -20.0]);+ click_at(&mut h, [10.0, -20.0]);+ leave_and_rest(&mut h, [10.0, -20.0], REST);+ click_at(&mut h, [20.0, -10.0]);+ leave_and_rest(&mut h, [20.0, -10.0], REST);+ click_at(&mut h, [20.0, 20.0]);+ leave_and_rest(&mut h, [20.0, 20.0], REST);+ click_at(&mut h, [10.0, 30.0]);+ leave_and_rest(&mut h, [10.0, 30.0], REST);+ click_at(&mut h, [-20.0, 30.0]);+ leave_and_rest(&mut h, [-20.0, 30.0], REST);+ click_at(&mut h, [-30.0, 20.0]);+ leave_and_rest(&mut h, [-30.0, 20.0], REST);+ click_at(&mut h, [-30.0, -10.0]);+ leave_and_rest(&mut h, [-30.0, -10.0], REST);+ // The last arc ends on the first line's start: the outline is closed.+ click_at(&mut h, [-20.0, -20.0]);+ let sk = sketch(&h);+ assert_eq!(sk.curves.len(), 8, "{:?}", h.app.status);+ let tangents = sk.constraints.iter().filter(|c| matches!(c.kind, solidcraft_engine::sketch::ConstraintKind::Tangent { .. })).count();+ assert!(tangents >= 4, "every arc is tangent to the line before it: {tangents}");+ let first = sk.resolve_point(&format!("{}.start", sk.curves[0].id));+ let last = sk.resolve_point(&format!("{}.end", sk.curves[7].id));+ assert_eq!(first, last, "the last arc ends on the first point");+}++#[test]+fn a_pointer_that_never_left_or_keeps_moving_or_rests_elsewhere_does_not_switch() {+ // A pause straight after the click, on the point it placed.+ let mut h = chain_with_a_line(true);+ h.frames(REST * 3);+ assert_eq!(tool(&h), Some("sketch.line"), "a pause on the placed point switches nothing");++ // A little jitter there isn't leaving it either.+ h.step(&json!({"move":{"sketch":[0.5, 0.5]}})).unwrap();+ h.frames(REST * 2);+ assert_eq!(tool(&h), Some("sketch.line"), "a small wobble is not leaving");++ // Resting somewhere else.+ h.step(&json!({"move":{"sketch":[20.0, 20.0]}})).unwrap();+ h.frames(REST * 2);+ assert_eq!(tool(&h), Some("sketch.line"), "a rest elsewhere");+ h.step(&json!({"move":{"sketch":[-20.0, 0.0]}})).unwrap();+ h.frames(REST * 2);+ assert_eq!(tool(&h), Some("sketch.line"), "a rest on the line's other end");++ // Over the point, never still: each move restarts the wait.+ let p = h.call("ui.at", json!({"sketch":[0.0, 0.0]}))["result"].clone();+ let (x, y) = (p[0].as_f64().unwrap(), p[1].as_f64().unwrap());+ for i in 0..80 {+ let d = if i % 2 == 0 { 3.0 } else { -3.0 };+ h.call("ui.move", json!({"x": x + d, "y": y}));+ h.frames(1);+ }+ assert_eq!(tool(&h), Some("sketch.line"), "a moving pointer never switches");++ // Too short a rest.+ leave_and_rest(&mut h, [0.0, 0.0], 5);+ assert_eq!(tool(&h), Some("sketch.line"), "a tenth of a second is not a rest");++ // Before any segment there is no chain to switch.+ let mut h = harness("sketch.line");+ h.app.preferences.line_hover_tangent_arc = true;+ click_at(&mut h, [-20.0, 0.0]);+ leave_and_rest(&mut h, [-20.0, 0.0], REST * 2);+ assert_eq!(tool(&h), Some("sketch.line"), "the first point alone switches nothing");++ // Nor is the Tangent Arc tool itself switched by resting on its start.+ let mut h = harness("sketch.line");+ h.app.preferences.line_hover_tangent_arc = true;+ click_at(&mut h, [-20.0, 0.0]);+ click_at(&mut h, [0.0, 0.0]);+ h.step(&json!({"key":"Escape"})).unwrap();+ h.step(&json!({"start":"sketch.arc.tangent"})).unwrap();+ click_at(&mut h, [0.0, 0.0]);+ leave_and_rest(&mut h, [0.0, 0.0], REST * 2);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"));+ assert!(h.app.tool.as_ref().is_some_and(|t| !crate::sketch_line_arc::in_arc_mode(t)), "that tool is no chain");+}++#[test]+fn staying_on_the_point_after_a_switch_does_not_switch_back() {+ let mut h = chain_with_a_line(true);+ leave_and_rest(&mut h, [0.0, 0.0], REST);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"));+ h.frames(REST * 4);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"), "the pointer has to leave first");+}++#[test]+fn esc_and_right_click_end_a_chain_drawing_arcs_as_they_end_a_line_chain() {+ for right_click in [false, true] {+ let mut h = chain_with_a_line(true);+ leave_and_rest(&mut h, [0.0, 0.0], REST);+ click_at(&mut h, [10.0, 10.0]);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"));+ if right_click {+ let p = h.call("ui.at", json!({"sketch":[20.0, 20.0]}))["result"].clone();+ h.call("ui.click", json!({"x":p[0],"y":p[1],"button":"right"}));+ } else {+ h.step(&json!({"key":"Escape"})).unwrap();+ }+ h.frames(2);+ // The chain has ended and the Line tool is out, with no point placed.+ let t = h.app.tool.as_ref().expect("the Line tool stays out");+ assert_eq!((t.cmd, t.pts.len()), ("sketch.line", 0), "right click: {right_click}");+ // A click starts a new chain: a separate line, and a rest needs a segment again.+ click_at(&mut h, [30.0, 0.0]);+ click_at(&mut h, [40.0, 0.0]);+ assert_eq!(curves(&h), 3);+ // Esc twice leaves the tool, as ever.+ h.step(&json!({"key":"Escape"})).unwrap();+ h.step(&json!({"key":"Escape"})).unwrap();+ h.frames(2);+ assert_eq!(tool(&h), None);+ }+}++#[test]+fn undo_takes_back_one_arc_as_it_takes_back_one_segment() {+ let mut h = chain_with_a_line(true);+ let undo_before = h.app.session.undo.len();+ leave_and_rest(&mut h, [0.0, 0.0], REST);+ assert_eq!(h.app.session.undo.len(), undo_before, "switching changes nothing in the design");+ click_at(&mut h, [10.0, 10.0]);+ assert_eq!(curves(&h), 2);+ assert_eq!(h.app.session.undo.len(), undo_before + 1, "the arc is one undo step");+ h.app.run("edit.undo", json!({})).unwrap();+ h.frames(2);+ assert_eq!(curves(&h), 1, "only the arc goes");+ assert_eq!(sketch(&h).curves.first().map(|c| matches!(c.kind, CurveKind::Line { .. })), Some(true));+ // As with a line undone mid-chain, the chain's point went with it: the next click is refused+ // and changes nothing, and Esc ends the chain, leaving the Line tool ready for a new one.+ click_at(&mut h, [20.0, 20.0]);+ assert_eq!(curves(&h), 1, "{:?}", h.app.status);+ h.step(&json!({"key":"Escape"})).unwrap();+ h.frames(2);+ assert_eq!(h.app.tool.as_ref().map(|t| (t.cmd, t.pts.len())), Some(("sketch.line", 0)));+ click_at(&mut h, [30.0, 0.0]);+ click_at(&mut h, [40.0, 0.0]);+ assert_eq!(curves(&h), 2, "{:?}", h.app.status);+}++/// The preference saves, and the Sketch page's checkbox, Restore Defaults and Cancel treat it as+/// the page's own.+#[test]+fn the_tangent_arc_preference_saves_and_follows_the_sketch_page() {+ use crate::prefs::control;+ let mut h = Harness::new();+ h.call("ui.prefs", json!({"open": "Sketch"}));+ h.frames(4);+ crate::prefs::reveal_preference(&mut h, "prefs:line_hover_tangent_arc");+ h.step(&json!({"click":{"handle":"prefs:line_hover_tangent_arc"}})).unwrap();+ h.frames(2);+ assert!(h.app.preferences.line_hover_tangent_arc, "the checkbox turns it on");+ control(&mut h.app, &json!({"button": "apply"})).unwrap();+ let mut other = crate::SolveApp::new(solidcraft_engine::Session::default(), Default::default());+ other.load_prefs(&h.app.prefs());+ assert!(other.preferences.line_hover_tangent_arc, "saved");+ control(&mut h.app, &json!({"button": "defaults"})).unwrap();+ assert!(!h.app.preferences.line_hover_tangent_arc);+ control(&mut h.app, &json!({"button": "cancel"})).unwrap();+ assert!(h.app.preferences.line_hover_tangent_arc);+}++#[test]+fn arcs_follow_one_another_each_tangent_to_the_last_and_a_pause_after_one_switches_nothing() {+ let mut h = chain_with_a_line(true);+ leave_and_rest(&mut h, [0.0, 0.0], REST);+ click_at(&mut h, [10.0, 10.0]);+ // The pointer is on the arc's end, where it was clicked: thinking there switches nothing.+ h.frames(REST * 3);+ assert_eq!(tool(&h), Some("sketch.arc.tangent"), "a pause on the placed point switches nothing");+ // The first arc arrives at (10, 10) running along +Y, so the next one, to (20, 20), turns the+ // other way about (20, 10) at radius 10: an S.+ click_at(&mut h, [20.0, 20.0]);+ assert_eq!(curves(&h), 3, "{:?}", h.app.status);+ let sk = sketch(&h);+ let (centre, radius, start, end) = last_arc(&sk);+ assert!(centre.dist(solidcraft_engine::geom::Vec2::new(20.0, 10.0)) < 1e-6, "centre {centre:?}");+ assert!((radius - 10.0).abs() < 1e-6, "radius {radius}");+ assert!(+ start.dist(solidcraft_engine::geom::Vec2::new(10.0, 10.0)) < 1e-6 && end.dist(solidcraft_engine::geom::Vec2::new(20.0, 20.0)) < 1e-6,+ "from {start:?} to {end:?}"+ );+ assert!(+ sk.constraints.iter().any(|c| matches!(c.kind, solidcraft_engine::sketch::ConstraintKind::Tangent { a: 1, b: 2 })),+ "tangent to the arc before it: {:?}",+ sk.constraints+ );+ // After a clockwise arc the chain still goes on from its drawn end, as a line.+ leave_and_rest(&mut h, [20.0, 20.0], REST);+ assert_eq!(tool(&h), Some("sketch.line"), "{:?}", h.app.status);+ click_at(&mut h, [20.0, 40.0]);+ assert_eq!(curves(&h), 4, "{:?}", h.app.status);+ let sk = sketch(&h);+ let CurveKind::Line { a: line_start, .. } = sk.curves[3].kind else { panic!("a line: {:?}", sk.curves[3]) };+ let CurveKind::Arc { a: arc_end, .. } = sk.curves[2].kind else { panic!("an arc: {:?}", sk.curves[2]) };+ let joined = line_start == arc_end || sk.point(line_start).unwrap().dist(sk.point(arc_end).unwrap()) < 1e-6;+ assert!(joined, "the line starts where the arc ends");+}diff --git a/crates/ui-egui/src/sketch_tools.rs b/crates/ui-egui/src/sketch_tools.rsindex cf07dd5f2c..5d0a21cced 100644--- a/crates/ui-egui/src/sketch_tools.rs+++ b/crates/ui-egui/src/sketch_tools.rs@@ -776,6 +776,7 @@ pub fn tool_for(id: &str) -> Option<Tool> {dims_focus: false,arc_turn: 0.0,lined: Vec::new(),+ chain: Default::default(),})}@@ -1246,6 +1247,10 @@ pub(crate) fn place_point(app: &mut SolveApp, tool: &mut Tool, p: (Vec2, Option<}return;}+ if crate::sketch_line_arc::in_arc_mode(tool) {+ crate::sketch_line_arc::place_arc(app, tool, &p);+ return;+ }let Some(Mode::Points(n)) = mode(tool.cmd) else { return };if let Err(error) = crate::sketch_dims::validate(app, tool) {app.set_status(error, true);@@ -1466,6 +1471,13 @@ pub fn preview(app: &SolveApp, t: &Tool, painter: &egui::Painter, proj: &Proj) {crate::tools::paint_sketch_path(&[ss.plane.to_world(first.0), hw], mode, painter, proj, faint);}crate::tools::paint_sketch_path(&[ss.plane.to_world(last.0), hw], mode, painter, proj, faint);+ } else if crate::sketch_line_arc::in_arc_mode(t) {+ // The Line tool switched to tangent arcs: the arc a click makes, or (straight ahead,+ // where there is none) only a faint guide.+ match crate::sketch_line_arc::preview_arc(&ss.sketch, t, *h) {+ Some(arc) => crate::tools::paint_preview_curve(arc, &ss.plane, painter, proj, stroke, mode),+ None => crate::tools::paint_sketch_path(&[ss.plane.to_world(last.0), hw], mode, painter, proj, faint),+ }} else {crate::tools::paint_sketch_path(&[ss.plane.to_world(last.0), hw], mode, painter, proj, stroke);}diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rsindex 8ef1480385..74d0378819 100644--- a/crates/ui-egui/src/tools.rs+++ b/crates/ui-egui/src/tools.rs@@ -97,6 +97,9 @@ pub struct Tool {/// Where each point was placed and the sketch points the snap lined it up with (#7828):/// constrained to them once the shape is made.pub lined: Vec<(Vec2, Vec<crate::sketch_tools::Lined>)>,+ /// The Line tool's chain, which a rest on its last point switches to tangent arcs and back+ /// (#9489).+ pub chain: crate::sketch_line_arc::LineChain,}impl Tool {@@ -149,6 +152,7 @@ impl Tool {dims_focus: false,arc_turn: 0.0,lined: Vec::new(),+ chain: Default::default(),})}}@@ -518,6 +522,10 @@ pub fn place(app: &mut SolveApp, p: (Vec2, Option<String>)) {tool.pts.push(p);let before = crate::sketch_tools::point_ids(app);if tool.cmd == "sketch.line" {+ // A new chain's first point: nothing drawn yet to go on tangent from.+ if tool.pts.len() == 1 {+ tool.chain = Default::default();+ }if tool.pts.len() >= 2 {let (a, b) = (tool.pts[tool.pts.len() - 2].clone(), tool.pts[tool.pts.len() - 1].clone());let angled = crate::sketch_dims::has_locked(&tool, "Angle");@@ -543,6 +551,7 @@ pub fn place(app: &mut SolveApp, p: (Vec2, Option<String>)) {tool.pts[last].1 = Some(format!("{id}.end"));// The chain needs only its current endpoint, even after many segments.tool.pts = vec![tool.pts[last].clone()];+ tool.chain.placed(id);}crate::sketch_dims::reset(&mut tool);} else {@@ -870,6 +879,9 @@ pub fn finish(app: &mut SolveApp) {if crate::sketch3d::finish(app) {return;}+ if crate::sketch_line_arc::finish(app) {+ return;+ }if let Some(mut t) = app.tool.take_if(|t| t.kind == Kind::Ext) {if crate::sketch_tools::finish(app, &mut t) {app.tool = Some(t);diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex b2dd0697b6..fe253139c6 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -4407,6 +4407,21 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {let held_mods = crate::tool_modifiers::Held::from_modifiers(mods);let (add, allow_toggle) = crate::tool_modifiers::selection_click(held_mods, app.preferences.selection_shift_add_only);crate::sketch_text::set_one_letter(mods.shift);+ // Resting on the Line tool's last point switches lines and tangent arcs (#9489): only a free+ // pointer, nothing held or under way. Not `inside`: on that point the pointer is between the+ // new segment's value boxes, which take it from the view (as a shape being dragged out does).+ let free_pointer = ui.is_enabled()+ && !primary_down+ && !secondary_down+ && !middle+ && !held+ && primary_nav.is_none()+ && mode.is_none()+ && mods.is_none()+ && !app.viewport.tool_click+ && app.viewport.draw_drag.is_none();+ let resting = hover.filter(|p| free_pointer && rect.contains(*p) && !axes.contains(*p) && !crate::shell::covered(app, *p));+ crate::sketch_line_arc::follow_pointer(app, ui.ctx(), &proj, resting);if let Some(p) = hover.filter(|_| inside) {if app.tool.is_some() {crate::tools::on_hover(app, &proj, p, mods.shift);@@ -4897,6 +4912,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {}crate::canvas::show(app, ui, &painter, &proj);crate::sketch_tools::show(app, ui, &painter, &proj);+ crate::sketch_line_arc::paint_mode(app, ui, &painter, &proj);crate::design_properties::overlay(app, &painter, &proj);crate::sketch_dims::show(app, ui, &proj);crate::select_other::show(app, ui.ctx());diff --git a/docs/book/src/guide/sketching.md b/docs/book/src/guide/sketching.mdindex 396a46bb10..e96736a857 100644--- a/docs/book/src/guide/sketching.md+++ b/docs/book/src/guide/sketching.md@@ -68,6 +68,13 @@ ends the chain. To draw one separate line with a press, a drag and the release iwhere you let go, snapping and lining up as clicks do, and ends there; clicks still draw achain, and a drag shorter than about 24 points is still a click.+To round corners without changing tool, turn on **Preferences › Sketch › Rest on a line's last+point to switch to a tangent arc**. With a segment drawn, move the pointer away from the chain's+last point, bring it back and hold it still for about a third of a second: a label next to the+pointer says Tangent Arc, and the next click ends an arc tangent to the last segment. The same+gesture goes back to lines. Arcs and lines join into one chain, each click is one undo step, and a+right-click or Esc ends the chain as usual.+Tools with several variants (line and midpoint line; two-point, three-point, centre and roundedrectangle; the circle, arc, slot, polygon and spline variants) share one toolbar button with adrop-down. The button and the family's shortcut start the variant you picked last, so adiff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex b1122d20b5..155d3a3f44 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -447,6 +447,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own- `language` (`en`, `ar`, `ja`, `de`, `fr`, `he`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md))- `length_decimals`- `line_drag_draws_one` (default false: in the Line tool, a press, a drag and the release draw one line from the press to the release and end there, snapping as clicks do; clicks still chain, and a drag under 24 points is a click; off, a drag places a point where it is let go, #7247)+- `line_hover_tangent_arc` (default false: in the Line tool, after a segment, moving away from the chain's last point and resting back on it for about a third of a second makes the next click a tangent arc, and the same again goes back to lines; off, resting there does nothing, #9489)- `logo_accent` (bool, default false: the application bar's logo in shades of the theme's accent instead of the theme's logo colours)- `look_at_anim`- `look_at_speed`