SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Ribbon: keep the SKETCH tab shown outside a sketch (#7904) (#7906)
Lars Jansen67d5051792c6
diff --git a/assets/locales/pending/sketch-tab-always.json b/assets/locales/pending/sketch-tab-always.jsonnew file mode 100644index 0000000000..7a073a1fdd--- /dev/null+++ b/assets/locales/pending/sketch-tab-always.json@@ -0,0 +1,38 @@+{+ "en": {+ "prefs.sketch_tab_always": "Keep the Sketch tab shown",+ "prefs.sketch_tab_always_note": "The Sketch tab stays in the ribbon, right after Model, while no sketch is open. Its drawing tools then start a sketch on the selected plane or face, or on the plane you pick next, with the tool ready in it."+ },+ "ja": {+ "prefs.sketch_tab_always": "スケッチ タブを常に表示",+ "prefs.sketch_tab_always_note": "スケッチを開いていないときも、スケッチ タブをリボンのモデルのすぐ後に表示します。そこにある作図ツールは、選択した平面または面に、なければ次に選ぶ平面にスケッチを開始し、そのスケッチでツールをすぐ使える状態にします。"+ },+ "zh": {+ "prefs.sketch_tab_always": "始终显示草图选项卡",+ "prefs.sketch_tab_always_note": "未打开草图时,草图选项卡也保留在功能区中紧随模型之后。其中的绘图工具会先在所选平面或面上(否则在接下来选取的平面上)创建草图,并在其中准备好该工具。"+ },+ "ar": {+ "prefs.sketch_tab_always": "إبقاء تبويب الرسم ظاهرًا",+ "prefs.sketch_tab_always_note": "يبقى تبويب الرسم في الشريط بعد تبويب النموذج مباشرة حتى عندما لا يكون أي رسم مفتوحًا. عندها تبدأ أدوات الرسم فيه رسمًا على المستوي أو الوجه المحدد، أو على المستوي الذي تختاره بعد ذلك، وتكون الأداة جاهزة فيه."+ },+ "he": {+ "prefs.sketch_tab_always": "השארת לשונית הסקיצה מוצגת",+ "prefs.sketch_tab_always_note": "לשונית הסקיצה נשארת ברצועה, מיד אחרי מודל, גם כשאין סקיצה פתוחה. כלי השרטוט בה מתחילים אז סקיצה על המישור או הפאה שנבחרו, או על המישור שתבחרו בהמשך, והכלי מוכן בה."+ },+ "vi": {+ "prefs.sketch_tab_always": "Luôn hiện thẻ Bản phác",+ "prefs.sketch_tab_always_note": "Thẻ Bản phác vẫn nằm trên thanh công cụ, ngay sau Mô hình, khi không có bản phác nào đang mở. Khi đó các công cụ vẽ của nó bắt đầu một bản phác trên mặt phẳng hoặc mặt đã chọn, hoặc trên mặt phẳng bạn chọn tiếp theo, với công cụ sẵn sàng trong đó."+ },+ "de": {+ "prefs.sketch_tab_always": "Registerkarte Skizze immer zeigen",+ "prefs.sketch_tab_always_note": "Die Registerkarte Skizze bleibt im Menüband direkt nach Modell, auch wenn keine Skizze offen ist. Ihre Zeichenwerkzeuge beginnen dann eine Skizze auf der ausgewählten Ebene oder Fläche oder auf der Ebene, die Sie als Nächstes wählen, und das Werkzeug ist darin bereit."+ },+ "ko": {+ "prefs.sketch_tab_always": "스케치 탭 항상 표시",+ "prefs.sketch_tab_always_note": "스케치가 열려 있지 않을 때도 스케치 탭이 리본에서 모델 바로 다음에 남아 있습니다. 그 그리기 도구는 선택한 평면이나 면, 또는 다음에 고르는 평면에서 스케치를 시작하고 그 안에서 도구를 바로 쓸 수 있게 합니다."+ },+ "nl": {+ "prefs.sketch_tab_always": "Schets-tab altijd tonen",+ "prefs.sketch_tab_always_note": "De Schets-tab blijft in het lint staan, direct na Model, ook als er geen schets open is. Zijn tekentools beginnen dan een schets op het geselecteerde vlak, of op het vlak dat je daarna kiest, met de tool daarin klaar voor gebruik."+ }+}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex f43e7b14ae..a520941d2b 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1286,6 +1286,20 @@ impl SolveApp {}return;}+ // A drawing tool on the SKETCH tab kept shown outside a sketch (#7904) starts Create+ // Sketch, on the selected plane or planar face or else on the plane picked next, and then+ // the tool, as the tool's shortcut does outside a sketch (`keymap::press`).+ if workspace::starts_a_sketch(self, id)+ && let Some(then) = solidcraft_engine::find_command(id).map(|c| c.id)+ {+ self.start("sketch.create");+ if let Some(d) = self.dialog.as_mut().filter(|d| matches!(d.kind, dialogs::Kind::Sketch)) {+ d.then_start = Some(then);+ }+ // The ribbon stays on SKETCH while the plane is picked, not on Create Sketch's MODEL.+ self.ui.tab = "SKETCH".into();+ return;+ }// A disabled command starts nothing, however it was reached. The toolbar greys its// button, but a shortcut, the command palette and the control channel all land here.// Its reason goes to the status line, so the refusal is never silent.diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 81989d3688..6815f0627b 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -844,6 +844,9 @@ preference_settings! {navigation_bar: crate::navigation_bar::NavigationBar = Default::default(), PAGE_INTERFACE;/// Show command names beneath ribbon icons, independently of workspace layout.ribbon_labels: bool = true, PAGE_INTERFACE;+ /// Keep the SKETCH tab in the ribbon, right after MODEL, while no sketch is open; its drawing+ /// tools then start a sketch first (#7904).+ sketch_tab_always: bool = false, PAGE_INTERFACE => check_id("prefs.sketch_tab_always");/// Where a dialog's OK and Cancel sit: under its inputs (the default) or in its title row (#6708).dialog_buttons: crate::ui_kit::DialogButtons = Default::default(), PAGE_INTERFACE;/// Interface scale (1 = 100 %).@@ -4254,6 +4257,7 @@ mod tests {("ui_font", json!("test font"), PAGE_INTERFACE),("layout", json!("compact"), PAGE_INTERFACE),("ribbon_labels", json!(false), PAGE_INTERFACE),+ ("sketch_tab_always", json!(true), PAGE_INTERFACE),("dialog_buttons", json!("top"), PAGE_INTERFACE),("timeline_left", json!(true), PAGE_INTERFACE),("timeline_under_browser", json!(true), PAGE_INTERFACE),diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rsindex 930012bb05..b7b616f99a 100644--- a/crates/ui-egui/src/prefs/interface.rs+++ b/crates/ui-egui/src/prefs/interface.rs@@ -73,6 +73,11 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {app.preferences.ribbon_labels = selected == 0;}});+ // The SKETCH tab outside a sketch too (#7904).+ ui_kit::row(ui, "", |ui| {+ let check = setting::sketch_tab_always(app, ui).on_hover_text(app.tr("prefs.sketch_tab_always_note"));+ crate::scenario::publish_target("prefs:sketch_tab_always", check.rect);+ });// Where every feature dialog puts its OK and Cancel (#6708).ui_kit::row(ui, app.tr("prefs.dialog_buttons"), |ui| {let placements = [crate::ui_kit::DialogButtons::Bottom, crate::ui_kit::DialogButtons::Top];diff --git a/crates/ui-egui/src/render_workspace.rs b/crates/ui-egui/src/render_workspace.rsindex f6f5c4f0e7..91c75560e7 100644--- a/crates/ui-egui/src/render_workspace.rs+++ b/crates/ui-egui/src/render_workspace.rs@@ -1814,7 +1814,13 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {}pub(crate) fn interactive_command_info(app: &SolveApp, command: &solidcraft_engine::CommandSpec) -> solidcraft_engine::CommandInfo {- ribbon::command_info(app, command)+ let mut info = ribbon::command_info(app, command);+ // A drawing tool on the SKETCH tab kept shown outside a sketch starts one (#7904).+ if crate::workspace::starts_a_sketch(app, command.id) {+ info.enabled = true;+ info.disabled_reason = None;+ }+ info}pub(crate) fn start_interactive(app: &mut SolveApp, id: &str) -> bool {ribbon::start(app, id)diff --git a/crates/ui-egui/src/sketch_shortcut_tests.rs b/crates/ui-egui/src/sketch_shortcut_tests.rsindex 2b2fce9547..1b9c2557fb 100644--- a/crates/ui-egui/src/sketch_shortcut_tests.rs+++ b/crates/ui-egui/src/sketch_shortcut_tests.rs@@ -333,3 +333,57 @@ fn a_feature_started_while_the_marker_rolls_back_waits_for_it() {let items = h.app.dialog.as_ref().and_then(|d| d.inputs.first()).map(|i| i.items.clone()).unwrap_or_default();assert_eq!(items, vec![Sel::Profile { sketch, index: 0 }], "Extrude did not open once the marker was back");}++/// The SKETCH tab kept shown (#7904): right after MODEL with no sketch open, its drawing and+/// reference tools look enabled and start a sketch first (on the selected plane, else on the plane+/// picked next) with the tool ready; tools that need a sketch's geometry stay disabled. Off, as by+/// default, the tab waits for a sketch.+#[test]+fn the_kept_sketch_tab_sits_after_model_and_its_tools_start_a_sketch() {+ let mut h = Harness::new();+ assert!(!crate::workspace::visible_tabs(&h.app).contains(&"SKETCH"), "off by default");+ h.call("ui.prefs", json!({"sketch_tab_always": true}));+ assert_eq!(crate::workspace::visible_tabs(&h.app)[..2], ["MODEL", "SKETCH"]);+ let info = |h: &Harness, id: &str| crate::render_workspace::interactive_command_info(&h.app, solidcraft_engine::find_command(id).unwrap());+ assert!(info(&h, "sketch.line").enabled && info(&h, "sketch.project").enabled);+ assert!(!info(&h, "sketch.dimension").enabled && !info(&h, "sketch.trim").enabled && !info(&h, "sketch.finish").enabled);++ // A plane selected first: the sketch opens on it and the tool is out.+ h.app.session.selection = vec![Sel::Plane { name: "XZ".into() }];+ h.settle();+ h.step(&json!({"click":{"handle":"tab:SKETCH"}})).unwrap();+ h.step(&json!({"click":{"handle":"button:sketch.line"}})).unwrap();+ h.settle();+ assert!(normal(&h).y.abs() > 0.999, "on XZ: {:?}", normal(&h));+ assert_eq!(tool(&h), Some("sketch.line"));+ assert!(h.app.dialog.is_none());+ assert_eq!(crate::workspace::visible_tabs(&h.app)[..2], ["MODEL", "SKETCH"], "the same place while sketching");+ h.app.start("sketch.finish");+ h.settle();+ assert!(h.app.session.active_sketch.is_none());++ // Nothing selected, in a fresh window (the view still looks at XZ): Create Sketch asks for+ // the plane, then the tool starts.+ let mut h = Harness::new();+ h.call("ui.prefs", json!({"sketch_tab_always": true}));+ h.settle();+ h.step(&json!({"click":{"handle":"tab:SKETCH"}})).unwrap();+ h.step(&json!({"click":{"handle":"button:sketch.circle.center"}})).unwrap();+ h.settle();+ assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Sketch)));+ assert_eq!(h.app.ui.tab, "SKETCH", "the ribbon stays where the click was");+ h.step(&json!({"click":{"plane":"XY"}})).unwrap();+ h.settle();+ assert!(normal(&h).z.abs() > 0.999, "{:?}", normal(&h));+ assert_eq!(tool(&h), Some("sketch.circle.center"));+ h.app.start("sketch.finish");+ h.settle();++ // Off again: the tab goes, and a drawing tool outside a sketch is refused as before.+ h.call("ui.prefs", json!({"sketch_tab_always": false}));+ h.settle();+ assert!(!crate::workspace::visible_tabs(&h.app).contains(&"SKETCH"));+ assert!(!info(&h, "sketch.line").enabled);+ h.app.start("sketch.line");+ assert!(h.app.dialog.is_none() && tool(&h).is_none());+}diff --git a/crates/ui-egui/src/workspace.rs b/crates/ui-egui/src/workspace.rsindex 76b1a21859..ef59be8631 100644--- a/crates/ui-egui/src/workspace.rs+++ b/crates/ui-egui/src/workspace.rs@@ -600,7 +600,11 @@ pub fn visible_tabs(app: &crate::SolveApp) -> Vec<&'static str> {return Vec::new();}let mut tabs = TABS.to_vec();- if app.session.active_sketch.is_some() {+ if app.preferences.sketch_tab_always {+ // Right after MODEL, whether a sketch is open or not (#7904).+ let at = tabs.iter().position(|t| *t == "MODEL").map_or(0, |i| i + 1);+ tabs.insert(at, "SKETCH");+ } else if app.session.active_sketch.is_some() {tabs.push("SKETCH");}// Always reachable, as before the ribbon redesign: a sheet-metal part starts from an@@ -611,6 +615,17 @@ pub fn visible_tabs(app: &crate::SolveApp) -> Vec<&'static str> {tabs}+/// With the SKETCH tab kept shown (#7904) and no sketch open: whether `id` is one of the tools in+/// its CREATE or REFERENCE sections, which then start a sketch first (Create Sketch, then the+/// tool). Tools that work on a sketch's geometry (modify, pattern, constrain) wait for one.+pub fn starts_a_sketch(app: &crate::SolveApp, id: &str) -> bool {+ app.preferences.sketch_tab_always+ && app.session.active_sketch.is_none()+ && solidcraft_engine::find_command(id)+ .and_then(destination)+ .is_some_and(|(tab, panel)| tab == "SKETCH" && matches!(panel, "CREATE" | "REFERENCE"))+}+/// Select contextual tabs on entry (or a different sheet body or frame member), allowing the/// other tabs to remain usable for the rest of that context. Sketch takes precedence over sheet/// metal, and sheet metal over weldments.diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex ea5ba01bb2..c6bb0ac293 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -350,6 +350,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own- `placement_handles` (default false: handles on the preview of a Rest, Boss or Snap Fit that move it across the model and turn it)- `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle)- `sketch_exit_view` (`keep` (default: the view stays where it is when a sketch ends), `previous` (back to the view from before the sketch), `unless_rotated` (back unless the sketch view was turned))+- `sketch_tab_always` (default false: the SKETCH tab stays in the ribbon right after MODEL while no sketch is open; a tool in its CREATE or REFERENCE section then opens Create Sketch, on the selected plane or planar face or else on the plane picked next, and starts in the new sketch, #7904)- `smooth_wheel_zoom` (default true)- `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field)- `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them)diff --git a/docs/ribbon-layout.md b/docs/ribbon-layout.mdindex 03703b49c7..b9d3b7ec07 100644--- a/docs/ribbon-layout.md+++ b/docs/ribbon-layout.md@@ -2,7 +2,7 @@The UI layout in `crates/ui-egui/src/workspace.rs` maps the original engine registry placements into ribbon sections. `docs/features.md` continues to document registry placements; command registrations and ids are unchanged.-Always shown, in order: MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW, SHEET METAL, WELDMENTS. SKETCH appears during sketch editing. SHEET METAL is reachable in every document, so a sheet-metal part can start from a sketch or a solid; it takes the contextual style and selects itself when the selected body (or the last body of the active component) has evaluated sheet-metal data. WELDMENTS is reachable in every document too, since a frame starts from a sketch of its lines; it selects itself when that body is a frame member, keeping the ordinary tab look (sheet metal comes first). Entering a context selects its tab; the other tabs remain available. RENDER belongs to the Render workspace.+Always shown, in order: MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW, SHEET METAL, WELDMENTS. SKETCH appears during sketch editing; with Preferences › Interface › **Keep the Sketch tab shown** (`sketch_tab_always`, #7904) it stays right after MODEL all the time, and outside a sketch the tools in its CREATE and REFERENCE sections open Create Sketch first and then start in the new sketch. SHEET METAL is reachable in every document, so a sheet-metal part can start from a sketch or a solid; it takes the contextual style and selects itself when the selected body (or the last body of the active component) has evaluated sheet-metal data. WELDMENTS is reachable in every document too, since a frame starts from a sketch of its lines; it selects itself when that body is a frame member, keeping the ordinary tab look (sheet metal comes first). Entering a context selects its tab; the other tabs remain available. RENDER belongs to the Render workspace.**Bold command ids are default promoted buttons.** Every listed command remains in the section menu. Saved user pins can add buttons, as before.