SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
fix(ui): expose Redefine Sketch Plane in History menus (#8024)
Inguss4d6664e4cafb
diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 606f5da7cd..a0fcf1450d 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -382,6 +382,23 @@ pub(crate) fn message_button(app: &SolveApp, ui: &mut egui::Ui, id: u64) {}}+/// Reuse the Browser action so both History layouts edit the same sketch attachment.+pub(crate) fn sketch_plane_button(app: &mut SolveApp, ui: &mut egui::Ui, id: u64) {+ if !matches!(app.session.doc.feature(id).map(|feature| &feature.kind), Some(FeatureKind::Sketch { .. })) {+ return;+ }+ let Some(item) =+ crate::context_menu::items(app, &crate::context_menu::Target::Sketch { id }).into_iter().find(|item| item.id == "ui.redefineSketch")+ else {+ return;+ };+ let response = crate::context_menu::button_enabled(ui, &item.label, &item.icon, item.enabled);+ if response.clicked() {+ crate::context_menu::run_item(app, &item, response.rect.center());+ ui.close();+ }+}+/// Shift+click on a feature: select the features from the anchor (the last feature clicked, or/// the last selected one) to this one. `order` is the timeline as drawn this frame, taken before/// drawing so the range never mixes two orders. Ctrl as well adds the range to the selection.@@ -625,6 +642,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {edit = Some(*id);ui.close();}+ sketch_plane_button(app, ui, *id);if let Some(sk) = sketch_of&& crate::context_menu::button(ui, crate::i18n::tr_label("Edit Profile Sketch"), "sketch").clicked(){@@ -765,6 +783,7 @@ fn find_in_browser(app: &mut SolveApp, id: u64) {#[cfg(test)]mod tests {use serde_json::json;+ use solidcraft_engine::doc::{FeatureKind, PlaneRef};use crate::scenario::Harness;@@ -910,6 +929,53 @@ mod tests {h}+ #[test]+ fn sketch_context_menu_redefines_the_plane_in_both_timelines() {+ for left in [false, true] {+ let mut h = two_boxes(left);+ let sketch = h.app.run("sketch.create", json!({"plane":"XY","name":"Profile"})).unwrap()["sketch"].as_u64().unwrap();+ h.app.run("sketch.rectangle.two_point", json!({"p0":[1,1],"p1":[8,6]})).unwrap();+ h.app.finish_sketch();+ h.settle();+ let before = h.app.session.doc.to_json();+ let raw = serde_json::to_value(h.app.session.doc.sketch(sketch).unwrap()).unwrap();+ let marker = h.app.session.doc.marker;+ let undo = h.app.session.undo.len();+ let item = crate::context_menu::items(&h.app, &crate::context_menu::Target::Sketch { id: sketch })+ .into_iter()+ .find(|item| item.id == "ui.redefineSketch")+ .unwrap();+ h.step(&json!({"click":{"handle":"timeline:First"},"button":"right"})).unwrap();+ assert!(h.widget(&item.label).is_none(), "a body feature has no sketch plane");+ h.step(&json!({"key":"Escape"})).unwrap();+ for apply in [false, true] {+ h.step(&json!({"click":{"handle":"timeline:Profile"},"button":"right"})).unwrap();+ h.step(&json!({"widget":item.label})).unwrap();+ assert_eq!(h.app.tree.redefine, Some(sketch));+ assert_eq!(h.app.session.doc.to_json(), before, "opening the menu changes no geometry");+ h.step(&json!({"widget":"Use XZ plane"})).unwrap();+ h.settle();+ h.step(&json!({"click":{"handle":if apply { "dialog:ok" } else { "dialog:cancel" }}})).unwrap();+ assert!(h.app.tree.redefine.is_none());+ assert_eq!(h.app.session.doc.marker, marker);+ assert_eq!(serde_json::to_value(h.app.session.doc.sketch(sketch).unwrap()).unwrap(), raw);+ if apply {+ assert!(matches!(&h.app.session.doc.feature(sketch).unwrap().kind,+ FeatureKind::Sketch { plane: PlaneRef::Origin { name }, .. } if name == "XZ"));+ assert_eq!(h.app.session.undo.len(), undo + 1);+ let after = h.app.session.doc.to_json();+ h.app.run("edit.undo", json!({})).unwrap();+ assert_eq!(h.app.session.doc.to_json(), before);+ h.app.run("edit.redo", json!({})).unwrap();+ assert_eq!(h.app.session.doc.to_json(), after);+ } else {+ assert_eq!(h.app.session.doc.to_json(), before);+ assert_eq!(h.app.session.undo.len(), undo);+ }+ }+ }+ }+/// A timeline wider than the window scrolls with a plain mouse wheel (#3356).#[test]fn the_mouse_wheel_scrolls_a_long_timeline() {diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex 13c741b239..d62c35febd 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -1449,6 +1449,7 @@ fn feature_row(app: &mut SolveApp, ui: &mut egui::Ui, rows: &mut Rows, index: usedit = true;ui.close();}+ crate::timeline::sketch_plane_button(app, ui, id);if let Some(sketch) = sketch&& crate::context_menu::button(ui, "Edit Profile Sketch", "sketch").clicked(){