Skip to content

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

Editing an Extrude or Revolve shows its sketch (#5336) (#5443)

raykholo7af97e372940
diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rs
index 263872d39d..d072715b58 100644
--- a/crates/engine/src/cmd/browser.rs
+++ b/crates/engine/src/cmd/browser.rs
@@ -1422,6 +1422,38 @@ mod tests {
assert_eq!(s.doc.named_views.len(), 2);
}
+ #[test]
+ fn the_sketch_of_an_edited_feature_is_shown_without_changing_visibility() {
+ for (command, params) in [("solid.extrude", json!({"distance": 5})), ("solid.revolve", json!({"axis": "y"}))] {
+ let mut s = Session::default();
+ let sketch = run(&mut s, "sketch.create", json!({"plane": "XY"}))["sketch"].as_u64().unwrap();
+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [2, 0], "p1": [4, 3]}));
+ run(&mut s, "sketch.finish", json!({}));
+ // Another sketch between them: the marker of the edit is not on the edited one's sketch.
+ run(&mut s, "sketch.create", json!({"plane": "XZ"}));
+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [2, 0], "p1": [4, 3]}));
+ run(&mut s, "sketch.finish", json!({}));
+ let mut params = params;
+ params["sketch"] = json!(sketch);
+ run(&mut s, command, params);
+ run(&mut s, "timeline.roll_to", json!({"position": 2}));
+ for explicitly in [None, Some(true), Some(false)] {
+ if let Some(visible) = explicitly {
+ run(&mut s, "browser.visibility", json!({"items": [sketch], "visible": visible}));
+ }
+ let before = crate::view::sketch_shown(&s, sketch);
+ assert_eq!(before, explicitly == Some(true), "{command} {explicitly:?}");
+ let visibility = s.visibility.clone();
+ s.feature_edit_sketch = Some(sketch);
+ assert!(crate::view::sketch_shown(&s, sketch), "{command} {explicitly:?}");
+ assert!(crate::view::sketch_shown(&s.scratch(), sketch), "{command} {explicitly:?}");
+ s.feature_edit_sketch = None;
+ assert_eq!(crate::view::sketch_shown(&s, sketch), before, "{command} {explicitly:?}");
+ assert_eq!(s.visibility, visibility);
+ }
+ }
+ }
+
#[test]
fn helper_sketches_hide_and_show() {
let mut s = Session::default();
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index ffd8c13bd7..ccad896596 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -265,6 +265,8 @@ pub struct Session {
pub active_sketch: Option<u64>,
/// The design as it was when the open sketch was entered, for Cancel Sketch.
pub(crate) sketch_entry: Option<SketchEntry>,
+ /// Sketch temporarily shown while editing a feature that consumes it. View state only.
+ pub feature_edit_sketch: Option<u64>,
pub selection: Vec<Sel>,
pub path: Option<String>,
/// One-shot display-only notification during doc.open, before authoritative evaluation.
@@ -452,6 +454,7 @@ impl Session {
redo: Vec::new(),
active_sketch: None,
sketch_entry: None,
+ feature_edit_sketch: None,
selection: Vec::new(),
path: None,
open_preview: None,
@@ -1109,6 +1112,7 @@ impl Session {
redo: Vec::new(),
active_sketch: self.active_sketch,
sketch_entry: None,
+ feature_edit_sketch: self.feature_edit_sketch,
selection: self.selection.clone(),
path: None,
open_preview: None,
diff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rs
index b8a8a53e87..21c024c58d 100644
--- a/crates/engine/src/view.rs
+++ b/crates/engine/src/view.rs
@@ -644,7 +644,7 @@ impl SectionIndex {
/// ones used by a feature unless shown on their own, retain their stored visibility.
pub fn sketch_shown(s: &Session, id: u64) -> bool {
let v = &s.visibility;
- if s.active_sketch == Some(id) {
+ if s.active_sketch == Some(id) || s.feature_edit_sketch == Some(id) {
return true;
}
if !sketch_component_visible(s, id) || s.feature_folder_hidden(id, "sketches") {
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index b84ba89455..5095318f64 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -2455,10 +2455,21 @@ fn picked_side(app: &SolveApp, d: &Dialog, first: &Sel) -> Option<usize> {
Some(crate::smart_extrude::picked_direction(crate::smart_extrude::view_ray(&app.cam, at), normal, false))
}
+/// Show the sketch of the Extrude or Revolve the open dialog edits, and only while it is open:
+/// whichever way the dialog closed (OK, Cancel, another tool, another design), the sketch
+/// returns to its own visibility.
+pub(crate) fn sync_feature_edit_sketch(app: &mut SolveApp) {
+ app.session.feature_edit_sketch = app.dialog.as_ref().and_then(|d| d.editing).and_then(|(id, _)| match &app.session.doc.feature(id)?.kind {
+ FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. } => Some(**sketch),
+ _ => None,
+ });
+}
+
/// Show the active dialog (if any), docked flush to an edge of the viewport just below the axis
/// view, sized to its content. The right edge is its place, except while a sketch is open: the
/// Sketch Palette keeps the right there, and the dialog takes the left so both stay on screen.
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
+ sync_feature_edit_sketch(app);
if app.tree.redefine.is_none() {
app.viewport.dialog_rect = None;
}
@@ -2770,6 +2781,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
app.applying = None;
}
if !keep || cancel {
+ app.session.feature_edit_sketch = None;
crate::dialogs_motion::closed(app, &mut d, applied);
if let Kind::Text(k) = &mut d.kind {
crate::sketch_text::closed(app, k, applied);
@@ -2799,6 +2811,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
/// Close the dialog without applying it (Esc, Cancel). An edit puts the timeline marker back.
pub fn cancel(app: &mut SolveApp) {
+ app.session.feature_edit_sketch = None;
app.applying = None;
if let Some(mut d) = app.dialog.take() {
crate::dialogs_motion::closed(app, &mut d, false);
@@ -5362,6 +5375,55 @@ mod refused_ok_tests {
h
}
+ /// A sketch, a second sketch after it, and `command` made from the first; the edit dialog
+ /// of that feature open, so the history marker sits on the second sketch.
+ fn edit_dialog(command: &str, params: Value) -> (Harness, u64) {
+ let mut h = Harness::new();
+ let mut sketches = Vec::new();
+ for plane in ["XY", "XZ"] {
+ let created = h.app.run("sketch.create", json!({"plane": plane})).unwrap();
+ sketches.push(created["sketch"].as_u64().unwrap());
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [2, 0], "p1": [4, 3]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ }
+ let mut params = params;
+ params["sketch"] = json!(sketches[0]);
+ h.app.run(command, params).unwrap();
+ let feature = h.app.session.doc.features.last().unwrap().id;
+ assert!(!solidcraft_engine::view::sketch_shown(&h.app.session, sketches[0]));
+ h.app.edit_feature(feature);
+ h.frames(1);
+ assert_eq!(h.app.session.feature_edit_sketch, Some(sketches[0]), "{command}");
+ assert!(solidcraft_engine::view::sketch_shown(&h.app.session, sketches[0]), "{command}");
+ (h, sketches[0])
+ }
+
+ #[test]
+ fn editing_shows_the_sketch_until_the_dialog_closes() {
+ let closes: [(&str, fn(&mut Harness)); 5] = [
+ ("OK", |h| steps(h, &[json!({"key": "Enter"})])),
+ ("Esc", |h| steps(h, &[json!({"key": "Escape"})])),
+ ("Cancel", |h| cancel(&mut h.app)),
+ ("another tool", |h| steps(h, &[json!({"start": "solid.box"})])),
+ ("new design", |h| {
+ h.app.run("file.new", json!({})).unwrap();
+ }),
+ ];
+ for (command, params) in [("solid.extrude", json!({"distance": 5})), ("solid.revolve", json!({"axis": "y"}))] {
+ for (how, close) in closes {
+ let (mut h, sketch) = edit_dialog(command, params.clone());
+ close(&mut h);
+ h.frames(1);
+ assert!(h.app.dialog.as_ref().is_none_or(|d| d.editing.is_none()), "{command} {how}");
+ assert_eq!(h.app.session.feature_edit_sketch, None, "{command} {how}");
+ // A new design has no such sketch; in the edited one it is hidden again.
+ if h.app.session.doc.feature(sketch).is_some() {
+ assert!(!solidcraft_engine::view::sketch_shown(&h.app.session, sketch), "{command} {how}");
+ }
+ }
+ }
+ }
+
fn set_depth(h: &mut Harness, depth: &str) {
steps(h, &[json!({"click": {"handle": "dialog:Depth"}}), json!({"key": "A", "cmd": true}), json!({"text": depth})]);
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 06471e11d9..4dc32fcf5c 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1810,6 +1810,8 @@ impl SolveApp {
if floating || left_timeline || !show_timeline {
self.shell.history = None;
}
+ // The model draws next: a dialog the toolbar closed last frame no longer shows its sketch.
+ dialogs::sync_feature_edit_sketch(self);
let full = ui.available_rect_before_wrap();
if floating {
let cards = shell::Cards::new(full, self.ui.layout, toolbar::ribbon_height(self.preferences.ribbon_labels));