Skip to content

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

Ribbon: New Sketch on the Sheet Metal tab again; tests for entering and leaving sketches (#3946)

bherbruck4098ff9dc801
diff --git a/crates/ui-egui/src/workspace.rs b/crates/ui-egui/src/workspace.rs
index 3e9915170f..ebeb8428e8 100644
--- a/crates/ui-egui/src/workspace.rs
+++ b/crates/ui-egui/src/workspace.rs
@@ -245,6 +245,8 @@ pub const SECTIONS: &[Section] = &[
// Sketch dimensions are driven by parameters, so they are one click away while sketching.
Section { tab: "SKETCH", panel: "CONFIGURE", promoted: 2, ids: CONFIGURE },
Section { tab: "SKETCH", panel: "FINISH SKETCH", promoted: 1, ids: &["sketch.finish"] },
+ // New Sketch leads the tab, as on MODEL: a sheet part starts from a sketch (#3250).
+ Section { tab: "SHEET METAL", panel: "SKETCH", promoted: 1, ids: &["sketch.create"] },
Section {
tab: "SHEET METAL",
panel: "CREATE",
@@ -631,6 +633,7 @@ mod tests {
("INSERT", "FILES", "component.insert_design"),
("ASSEMBLE", "COMPONENTS", "component.insert_design"),
("SHEET METAL", "CREATE", "sheet.convert"),
+ ("SHEET METAL", "SKETCH", "sketch.create"),
("SKETCH", "REFERENCE", "canvas.insert"),
] {
assert!(layout(tab, panel, &specs).unwrap().0.iter().any(|c| c.id == id));
@@ -848,4 +851,101 @@ mod tests {
}
assert_eq!(h.app.session.world_state().bodies.len(), 2, "the STEP file's body is inserted");
}
+
+ /// Every way into a sketch (New Sketch on the ribbon then a plane, a double-click in the
+ /// timeline or the browser, Edit Sketch in the browser's menu) opens the SKETCH tab and looks
+ /// at the sketch; Finish Sketch (palette or ribbon) lands on MODEL with the earlier view back
+ /// and the sketch still listed, as before the ribbon redesign.
+ #[test]
+ fn entering_and_finishing_a_sketch_keeps_the_tab_view_and_history() {
+ let iso = json!({"camera": {"yaw_deg": -45, "pitch_deg": 35}});
+ let top = json!({"camera": {"yaw_deg": 0, "pitch_deg": 90}});
+ let expect = |h: &mut crate::scenario::Harness, e: &serde_json::Value, what: &str| {
+ h.frames(3);
+ crate::scenario::check(h, e).unwrap_or_else(|err| panic!("{what}: {err}"));
+ };
+ let mut h = crate::scenario::Harness::new();
+ h.call("ui.view", json!({"view": "iso"}));
+ h.frames(3);
+ h.step(&json!({"click": {"handle": "button:sketch.create"}})).unwrap();
+ h.step(&json!({"click": {"plane": "XY"}})).unwrap();
+ expect(&mut h, &top, "New Sketch on XY");
+ assert_eq!(h.app.ui.tab, "SKETCH");
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap();
+ h.step(&json!({"click": {"handle": "sketch_palette:finish"}})).unwrap();
+ expect(&mut h, &json!({"sketching": false, "errors": 0}), "Finish");
+ expect(&mut h, &iso, "Finish puts the view back");
+ assert_eq!(h.app.ui.tab, "MODEL");
+ assert!(crate::scenario::handle_at("timeline:Sketch1").is_some() && crate::scenario::handle_at("row:Sketch1").is_some());
+
+ let entries = [
+ ("timeline double-click", vec![json!({"click": {"handle": "timeline:Sketch1"}, "double": true})]),
+ ("browser double-click", vec![json!({"click": {"handle": "row:Sketch1"}, "double": true})]),
+ (
+ "browser Edit Sketch",
+ vec![json!({"click": {"handle": "row:Sketch1"}, "button": "right"}), json!({"click": {"handle": "menu:ui.editSketch"}})],
+ ),
+ ];
+ for (how, steps) in entries {
+ for s in steps {
+ h.frames(3);
+ h.step(&s).unwrap_or_else(|e| panic!("{how}: {e}"));
+ }
+ expect(&mut h, &json!({"sketching": true}), how);
+ expect(&mut h, &top, how);
+ assert_eq!(h.app.ui.tab, "SKETCH", "{how}");
+ h.step(&json!({"click": {"handle": "button:sketch.finish"}})).unwrap();
+ expect(&mut h, &json!({"sketching": false}), how);
+ expect(&mut h, &iso, how);
+ assert_eq!(h.app.ui.tab, "MODEL", "{how}");
+ }
+ }
+
+ /// Escape and Enter, pressed one at a time, never leave a sketch (#1804); Undo right after
+ /// Finish reopens it, and a second Undo removes it and leaves the SKETCH tab.
+ #[test]
+ fn keys_keep_a_sketch_open_and_undo_after_finish_reopens_it() {
+ let mut h = crate::scenario::Harness::new();
+ h.frames(3);
+ h.step(&json!({"start": "sketch.create"})).unwrap();
+ h.step(&json!({"click": {"plane": "XY"}})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap();
+ for key in [json!({"key": "Escape"}), json!({"key": "Escape"}), json!({"key": "Enter"}), json!({"key": "Enter", "cmd": true})] {
+ h.step(&key).unwrap();
+ // Well apart, so two presses are never a quick double press.
+ h.frames(60);
+ assert!(h.app.session.active_sketch.is_some(), "{key}");
+ assert_eq!(h.app.ui.tab, "SKETCH", "{key}");
+ }
+ h.step(&json!({"click": {"handle": "sketch_palette:finish"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"key": "Z", "cmd": true})).unwrap();
+ h.frames(2);
+ assert!(h.app.session.active_sketch.is_some(), "Undo after Finish reopens the sketch");
+ assert_eq!(h.app.ui.tab, "SKETCH");
+ h.step(&json!({"key": "Z", "cmd": true})).unwrap();
+ h.frames(2);
+ assert!(h.app.session.active_sketch.is_none());
+ assert_eq!(h.app.ui.tab, "MODEL");
+ }
+
+ /// New Sketch is on the SHEET METAL tab, as it was before the ribbon redesign, and a sketch
+ /// started there stays on its tab until it opens.
+ #[test]
+ fn new_sketch_starts_from_the_sheet_metal_tab() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.run("sheet.flange", json!({"name": "Sheet", "body_name": "Sheet"})).unwrap();
+ h.frames(3);
+ assert_eq!(h.app.ui.tab, "SHEET METAL");
+ h.step(&json!({"click": {"handle": "button:sketch.create"}})).unwrap();
+ h.frames(2);
+ assert_eq!(h.app.ui.tab, "SHEET METAL", "New Sketch is on this tab, so it stays");
+ h.step(&json!({"click": {"plane": "XZ"}})).unwrap();
+ h.frames(2);
+ assert!(h.app.session.active_sketch.is_some());
+ assert_eq!(h.app.ui.tab, "SKETCH");
+ }
}
diff --git a/docs/ribbon-layout.md b/docs/ribbon-layout.md
index 40e765e027..2a42cb7fd5 100644
--- a/docs/ribbon-layout.md
+++ b/docs/ribbon-layout.md
@@ -45,6 +45,7 @@ Always shown, in order: MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW,
| SKETCH | CONSTRAIN | **`sketch.dimension`**, **`sketch.constraint.horizontal_vertical`**, **`sketch.constraint.coincident`**, **`sketch.constraint.tangent`**, **`sketch.constraint.equal`**, **`sketch.constraint.parallel`**, **`sketch.constraint.perpendicular`**, `sketch.construction`, `sketch.constrainer`, `sketch.constraint.fix`, `sketch.constraint.midpoint`, `sketch.constraint.concentric`, `sketch.constraint.collinear`, `sketch.constraint.symmetry`, `sketch.constraint.curvature`, `sketch.constraint.polygon`, `sketch.auto_constrain`, `sketch.auto_constrain_from_datum` |
| SKETCH | REFERENCE | **`sketch.project`**, `sketch.intersect`, `sketch.include_3d`, `sketch.project_to_surface`, `sketch.intersection_curve`, `sketch.spun_profile`, `sketch.isoparametric_curve`, `sketch.fit_curves_to_section`, `sketch.insert_dxf`, `sketch.insert_svg`, `canvas.insert` |
| SKETCH | FINISH SKETCH | **`sketch.finish`**, `sketch.finish_auto_constrain` |
+| SHEET METAL | SKETCH | **`sketch.create`** |
| SHEET METAL | CREATE | **`sheet.flange`**, **`sheet.hem`**, **`sheet.fold`**, **`sheet.perforate`**, `sheet.convert` |
| SHEET METAL | FLAT | **`sheet.unfold`**, **`sheet.refold`**, **`sheet.flat_pattern`** |
| SHEET METAL | OUTPUT | **`sheet.export_dxf`**, **`sheet.export_bend_table`** |
@@ -66,6 +67,7 @@ Explicit command-id lists override the default placement mapping. Shared command
| RENDER / IMAGE | RENDER / IMAGE | `render.start` |
| RENDER / SCENE | RENDER / SCENE | `render.scene` |
| SHEET METAL / CREATE | MODEL / MODIFY | `sheet.convert` |
+| SHEET METAL / CREATE | SHEET METAL / SKETCH | `sketch.create` |
| SHEET METAL / CREATE | SHEET METAL / CREATE | `sheet.flange`, `sheet.perforate`, `sheet.hem`, `sheet.fold` |
| SHEET METAL / CREATE | SHEET METAL / FLAT | `sheet.flat_pattern` |
| SHEET METAL / MODIFY | MANAGE / RULES | `sheet.manage_rules` |